-
Notifications
You must be signed in to change notification settings - Fork 1
/
green-serv.c
70 lines (59 loc) · 1.88 KB
/
green-serv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*Defined GREENSERV in order to initalize global in this file*/
#define GREENSERV 1
#include "config.h"
#include "db.h"
#include "models/scope.h"
#include "helpers/json.h"
#include "flags.h"
#include "models/comment.h"
#include "models/marker.h"
#include "models/heatmap.h"
#include "models/report.h"
#include "network/net.h"
#include <unistd.h>
#include <string.h>
/* Check for flags. */
void parseArgs(int argc, const char * argv[], struct gs_scope * campaign, MYSQL * conn){
int i;
for(i=0; i < argc; ++i){
if ( strncasecmp(argv[i], SCOPE_ID_SHORT, strlen(SCOPE_ID_SHORT)) == 0 || strncasecmp(argv[i], SCOPE_ID_LONG, strlen(SCOPE_ID_LONG)) == 0)
if ( argc >= i+1 )
db_getScopeById(atol(argv[++i]), campaign,conn);
}
}
int green_serv(int argc, const char* argv[]) {
MYSQL * conn;
struct gs_scope campaign;
/*You must initialize the library on the main thread.
*the only time threaded_db should be undef-ed is if you're
*unit testing and don't want a threaded environment for some
*weird reason.
*/
#ifdef THREADED_DB
BOOT_LOG_STR("Initializing MySQL Library.","");
mysql_library_init(0, NULL, NULL);
#endif
conn = _getMySQLConnection();
if(!conn){
fprintf(stderr, "%s\n", "Could not connect to mySQL");
return 1;
}
/* Setup Campaign for all querying. */
db_getScopeById(CAMPAIGN_ID, &campaign, conn);
parseArgs(argc,argv,&campaign,conn);
mysql_close(conn);
/* Set global campaign id for this Server instance */
_shared_campaign_id = campaign.id;
(void)_shared_campaign_id; /*http://stackoverflow.com/a/394568/1808164*/
/*What a silly cast we have to make...*/
BOOT_LOG_STR("Running Network Interface:", "");
run_network((void*(*)(void*))&doNetWork);
BOOT_LOG_STR("Finished Network Interface.","");
/*Clean Up database connection*/
mysql_library_end();
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
return 0;
}
#undef BOOT_LOG_STR