-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
69 lines (55 loc) · 1.53 KB
/
main.cpp
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
/* MongoDB REST over HTTP interface
*
* Copyright 2011 Alex Chamberlain
* Licensed under the MIT licence with no-advertise clause. See LICENCE.
*
*/
#include <cstring>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <iostream>
#include <memory>
#include <algorithm>
#include "mongoose.h"
#include "response.h"
#include "persistent_data.h"
#include "request_handler.h"
static void *event_handler(enum mg_event event,
struct mg_connection *conn,
const struct mg_request_info *request_info) {
void * processed = (void*) 1;
if (event == MG_NEW_REQUEST) {
response r(conn);
request_handler(conn, request_info, r);
r.send();
} else {
processed = NULL;
}
return processed;
}
static const char *options[] = {
//"document_root", "html",
"listening_ports", "8081,8082s",
"ssl_certificate", "ssl_cert.pem",
"num_threads", "1",
NULL
};
int main(void) {
struct mg_context *ctx;
persistent_data pd;
// Initialize random number generator. It will be used later on for
// the session identifier creation.
srand((unsigned) time(0));
// Setup and start Mongoose
ctx = mg_start(&event_handler, static_cast<void*>(&pd), options);
//assert(ctx != NULL);
// Wait until enter is pressed, then exit
printf("MongoDB REST server started on ports %s, press enter to quit.\n",
mg_get_option(ctx, "listening_ports"));
getchar();
mg_stop(ctx);
printf("%s\n", "MongoDB REST server stopped.");
return EXIT_SUCCESS;
}