Skip to content

Commit

Permalink
Merge branch 'reports'
Browse files Browse the repository at this point in the history
  • Loading branch information
EdgeCaseBerg committed Nov 11, 2013
2 parents 407f31d + e268e20 commit b8ae532
Show file tree
Hide file tree
Showing 15 changed files with 571 additions and 27 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ markerC.o: src/controllers/markers.c router.o strmap.o marker.o
heatmapC.o: src/controllers/heatmaps.c router.o strmap.o heatmap.o
$(CC) $(gflags) -c src/controllers/heatmaps.c -o obj/heatmapC.o

network.o: src/network/net.c router.o heartbeatC.o commentC.o markerC.o heatmapC.o
reportsC.o: src/controllers/reports.c router.o strmap.o report.o sha256.o
$(CC) $(gflags) -c src/controllers/reports.c -o obj/reportsC.o

network.o: src/network/net.c router.o heartbeatC.o commentC.o markerC.o heatmapC.o reportsC.o
$(CC) $(gflags) -c src/network/net.c -o obj/network.o

router.o: src/network/router.c strmap.o
Expand Down Expand Up @@ -111,8 +114,8 @@ test-heartbeat: tests/unit/heartbeat-test.c json.o decimal.o
test-router: tests/unit/router-test.c router.o strmap.o
$(CC) $(gflags) tests/unit/router-test.c obj/router.o obj/strmap.o -o tests/bin/router.out

test-network: tests/unit/network-test.c router.o strmap.o network.o commentC.o markerC.o heartbeatC.o db.o comment.o report.o marker.o scope.o heatmap.o
$(CC) $(mysqlflags) $(gflags) tests/unit/network-test.c $(unittestobj) obj/router.o obj/network.o obj/strmap.o obj/commentC.o obj/markerC.o obj/heartbeatC.o -o tests/bin/network.out -lpthread $(mysqllibs) -lcrypto
test-network: tests/unit/network-test.c router.o strmap.o network.o commentC.o markerC.o heartbeatC.o db.o comment.o report.o marker.o scope.o heatmap.o heatmapC.o reportsC.o
$(CC) $(mysqlflags) $(gflags) tests/unit/network-test.c $(unittestobj) obj/router.o obj/network.o obj/strmap.o obj/commentC.o obj/markerC.o obj/heartbeatC.o obj/heatmapC.o obj/reportsC.o -o tests/bin/network.out -lpthread $(mysqllibs) -lcrypto

#Controller Tests

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ SQL to create database structure:
CREATE TABLE report (
id INT(12) NOT NULL auto_increment PRIMARY KEY,
content TEXT, -- stores 64Kb.
trace TEXT, -- stores 64Kb.
scope_id INT(12), -- this is an ancestor style query
origin CHAR(64) NOT NULL, -- sha256 hash
authorize CHAR(64) NOT NULL, -- sha256 hash
Expand Down
4 changes: 3 additions & 1 deletion headers/controllers/markers.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
#define BAD_LON_OFFSET "Longitude offset must be numeric"
#define BAD_LAT_OFFSET "Latitude offset must be numeric"
#define NO_ADDRESSED_KEY "Required key or value for addressed not present"
#define KEYS_MISSING "Could not process request due to required keys not being found in data."
#ifndef KEYS_MISSING
#define KEYS_MISSING "Could not process request due to required keys not being found in data."
#endif
#define BOTH_OFFSET_ERR "Both lonOffset and latOffset must be present if either is used"

int marker_controller(const struct http_request * request, char * stringToReturn, int strLength);
Expand Down
73 changes: 73 additions & 0 deletions headers/controllers/reports.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef __REPORTS_CONTROLLER_H__
#define __REPORTS_CONTROLLER_H__

#include "helpers/strmap.h"
#include "network/router.h"
#include "models/report.h"
#include "db.h"
#include "helpers/json.h"

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#ifndef NOMEM_ERROR
#define NOMEM_ERROR "Request could not be processed due to memory allocation failure"
#endif
#ifndef BAD_PAGE_ERR
#define BAD_PAGE_ERR "Page must be a non zero, positive integral value"
#endif
#ifndef BAD_PAGE_SINCE_ERR
#define BAD_PAGE_SINCE_ERR "Page and hash parameters are mutually exclusive"
#endif
#ifndef BAD_FORMAT_DATE_ERR
#define BAD_FORMAT_DATE_ERR "The Since datetime format could not be parsed, please use YYYY-mm-dd HH:MM format"
#endif
#ifndef HASH_ORIGIN_REQUIRED_ERR
#define HASH_ORIGIN_REQUIRED_ERR "Both hash and origin parameters are required"
#endif
#ifndef BAD_METHOD_ERR
#define BAD_METHOD_ERR "Request method not supported"
#endif
#ifndef EMPTY_MESSAGE__ERR
#define EMPTY_MESSAGE_ERR "Field message may not be empty"
#endif
#ifndef EMPTY_TRACE__ERR
#define EMPTY_TRACE_ERR "Field stackTrace may not be empty"
#endif
#ifndef EMPTY_ORIGIN__ERR
#define EMPTY_ORIGIN_ERR "Field origin may not be empty"
#endif
#ifndef KEYS_MISSING
#define KEYS_MISSING "Could not process request due to required keys not being found in data."
#endif
#ifndef REPORT_NOT_FOUND
#define REPORT_NOT_FOUND "Could not find report"
#endif
#ifndef ORIGIN_NOT_ALLOWED
#define ORIGIN_NOT_ALLOWED "You do not have permission to delete this report"
#endif


int report_controller(const struct http_request * request, char * stringToReturn, int strLength);

int report_delete(char * buffer, int buffSize, char * origin, char * hash);

int report_post(char * buffer, int buffSize, const struct http_request * request);

int report_get(char * buffer,int buffSize, char * hash, char * since, int page);

#define REPORT_PAGE_STR "{" \
"\"status_code\" : %d ,"\
"\"messages\" : ["\
"%s"\
"],"\
"\"page\" : {"\
"\"count\" : %d,"\
"\"index\" : %d,"\
"\"next\" : \"%s\","\
"\"previous\" : \"%s\""\
"}"\
"}"

#endif
11 changes: 6 additions & 5 deletions headers/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/* Gets it's own results because it's more likely we'll want more
* heatmap data than something like comments
*/
#define HEATMAP_RESULTS_PER_PAGE 50
#define HEATMAP_RESULTS_PER_PAGE 51
#define HEATMAP_RESULTS_RETURNED (HEATMAP_RESULTS_PER_PAGE-1)
#define TOSTR(x) #x
#define STRINGIFY(x) TOSTR(x)
Expand Down Expand Up @@ -66,9 +66,9 @@
#define GS_HEATMAP_FIND_MATCH "SELECT id, intensity FROM heatmap WHERE scope_id = %ld AND latitude = " DecimalFormat " AND longitude = " DecimalFormat ";"
#define GS_HEATMAP_UPDATE_BY_ID "UPDATE heatmap SET intensity = %ld WHERE id = %ld;"

#define GS_REPORT_GET_ALL "SELECT id, content, scope_id, origin, authorize, created_time FROM report WHERE scope_id = %ld ORDER BY created_time DESC LIMIT %d, " STRINGIFY(RESULTS_PER_PAGE) ";"
#define GS_REPORT_GET_BY_AUTH "SELECT id, content, scope_id, origin, authorize, created_time FROM report WHERE authorize = \"%s\";"
#define GS_REPORT_INSERT "INSERT INTO report (content, scope_id, origin, authorize) VALUES (\"%s\", %ld, \"%s\", \"%s\")"
#define GS_REPORT_GET_ALL "SELECT id, content, scope_id, origin, authorize, created_time, trace FROM report WHERE scope_id = %ld AND created_time > '%s' ORDER BY created_time DESC LIMIT %d, " STRINGIFY(RESULTS_PER_PAGE)
#define GS_REPORT_GET_BY_AUTH "SELECT id, content, scope_id, origin, authorize, created_time,trace FROM report WHERE authorize = \"%s\""
#define GS_REPORT_INSERT "INSERT INTO report (content, scope_id, origin, authorize, trace) VALUES (\"%s\", %ld, \"%s\", \"%s\", \"%s\")"
#define GS_REPORT_DELETE "DELETE FROM report WHERE origin =\"%s\" AND authorize=\"%s\""


Expand Down Expand Up @@ -152,7 +152,8 @@

int db_deleteReport(struct gs_report * gsr, MYSQL * conn);

int db_getReports(int page, long scopeId, struct gs_report * gsr, MYSQL * conn);
/*Since should be like: YYYY-MM-DD-HH:MM */
int db_getReports(int page, char* since, long scopeId, struct gs_report * gsr, MYSQL * conn);

/* Allocate enough room for marker limit sizes for gsm and gsc */
int db_getMarkerComments(int page, long scopeId, struct gs_marker * gsm, struct gs_comment * gsc, MYSQL * conn);
Expand Down
6 changes: 5 additions & 1 deletion headers/models/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
struct gs_report {
long id;
long scopeId;
char content[GS_REPORT_MAX_LENGTH+1]; /* 140 chars + \0 = 141 */
char content[GS_REPORT_MAX_LENGTH+1];
char trace[GS_REPORT_MAX_LENGTH+1];
char origin[SHA_LENGTH+1];
char authorize[SHA_LENGTH+1];
char createdTime[GS_REPORT_CREATED_TIME_LENGTH+1]; /* YYYY-MM-DD HH:MM:SS + \0 = 20*/
};

/* setOrigin, and setAuthorize both perform sha256 calculations */

/* Any functions specifically working with just gs_report: */
void gs_report_setId(long id, struct gs_report * gsr);
/* Content will be truncated to be within GS_REPORT_MAX_LENGTH characters plus a null character!*/
void gs_report_setContent(char * content, struct gs_report * gsr);
void gs_report_setStackTrace(char * trace, struct gs_report * gsr);
void gs_report_setScopeId(long ScopeId, struct gs_report * gsr);
void gs_report_setCreatedTime(char * createdTime, struct gs_report * gsr); /* Contemplate long for epoch time? */
void gs_report_setOrigin(char * origin, struct gs_report * gsr);
Expand Down
1 change: 1 addition & 0 deletions headers/network/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "controllers/heartbeat.h"
#include "controllers/markers.h"
#include "controllers/heatmaps.h"
#include "controllers/reports.h"


/*Create an HTTP Json response
Expand Down
2 changes: 1 addition & 1 deletion headers/network/router.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <stdlib.h>
#include <stdio.h>

#define MAX_URL_LENGTH 100
#define MAX_URL_LENGTH 256
struct http_request{
int method;
char url[MAX_URL_LENGTH]; /* The request URL to determine the controller */
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/markers.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ int marker_get(char * buffer,int buffSize,Decimal * latDegrees, Decimal * lonDeg
}
}

snprintf(buffer,buffSize, MARKER_PAGE_STR, 200, hybridBuffer, min(numMarkers,MARKER_RETURNED), page, nextStr,prevStr);
snprintf(buffer,buffSize, MARKER_PAGE_STR, 200, hybridBuffer, min(numMarkers,MARKER_RETURNED), page-1, nextStr,prevStr);


free(comments);
Expand Down
Loading

0 comments on commit b8ae532

Please sign in to comment.