-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
60 lines (50 loc) · 1.2 KB
/
main.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
/*
* main.c
*
* Use libcgic to parse a GET request
* and construct an extRequest struct.
* Pass the struct to the curl functions
* and print the result of the remote
* HTTP action to cgiOut (stdout).
*/
#ifdef USE_FASTCGI
#include <fcgi_stdio.h>
#else
#include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "cgic/cgic.h"
#include "jsonptunnel.h"
/*
* The main entrypoint function.
* libcgic takes care of an actual
* main().
*/
int cgiMain(void) {
/* This struct will contain everything about the request. */
struct extRequest req;
/* Attempt to load the request with the right information */
if(!initReq(&req)) {
freeReq(&req);
return EXIT_FAILURE;
}
/*
* Print the passed variables and arguments.
* For debugging purposes - maybe this should be an extParam?
*/
//printParams(&req);
/*
* Requests the URL with curl and appends the extCallback
* function to the end of the output.
*/
if(!doPostReq(&req)) {
freeReq(&req);
exitStatus(500, "There was an error fetching the remote data.");
return EXIT_FAILURE;
}
/* Free all the strings malloced inside of req */
freeReq(&req);
/* Clean exit */
return EXIT_SUCCESS;
}