1 /******************************************************************************
2 * qDecoder - http://www.qdecoder.org
3 *
4 * Copyright (c) 2000-2012 Seungyoung Kim.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 ******************************************************************************/
28
29 #ifdef ENABLE_FASTCGI
30 #include "fcgi_stdio.h"
31 #else
32 #include <stdio.h>
33 #endif
34 #include <stdlib.h>
35 #include <stdbool.h>
36 #include "qdecoder.h"
37
main(void)38 int main(void)
39 {
40 #ifdef ENABLE_FASTCGI
41 while(FCGI_Accept() >= 0) {
42 #endif
43 qentry_t *req = qcgireq_parse(NULL, 0);
44
45 // fetch queries
46 time_t expire = (time_t)req->getint(req, "expire");
47 char *mode = req->getstr(req, "mode", false);
48 char *name = req->getstr(req, "name", false);
49 char *value = req->getstr(req, "value", false);
50
51 // start session.
52 qentry_t *sess = qcgisess_init(req, NULL);
53
54 // Mose case, you don't need to set timeout. this is just example
55 if (expire > 0) qcgisess_settimeout(sess, expire);
56
57 if (mode) {
58 switch (mode[0]) {
59 case 's': // set
60 req->putstr(sess, name, value, true);
61 break;
62 case 'r': // remove
63 req->remove(sess, name);
64 break;
65 case 'd': // destroy
66 qcgisess_destroy(sess);
67 qcgires_setcontenttype(req, "text/plain");
68 printf("Session destroyed.\n");
69 #ifdef ENABLE_FASTCGI
70 continue;
71 #else
72 return 0;
73 #endif
74 case 'v': // view
75 default:
76 break;
77 }
78 }
79 // screen out
80 qcgires_setcontenttype(req, "text/plain");
81 req->print(sess, stdout, true);
82
83 // save session & free allocated memories
84 qcgisess_save(sess);
85 sess->free(sess);
86 req->free(req);
87 #ifdef ENABLE_FASTCGI
88 }
89 #endif
90 return 0;
91 }
92