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  * $Id: qdecoder.h 655 2012-12-07 22:12:44Z seungyoung.kim $
29  ******************************************************************************/
30 
31 /**
32  * qDecoder Header file
33  *
34  * @file qdecoder.h
35  */
36 
37 #ifndef _QDECODER_H
38 #define _QDECODER_H
39 
40 #define _Q_PRGNAME  "qdecoder"
41 #define _Q_VERSION  "12.0.8"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #include <stdio.h>
48 #include <stdbool.h>
49 #include <time.h>
50 
51 /*
52  * Types and definitions
53  */
54 
55 typedef struct qentry_s qentry_t;
56 typedef struct qentobj_s qentobj_t;
57 
58 typedef enum {
59     Q_CGI_ALL    = 0,
60     Q_CGI_COOKIE = 0x01,
61     Q_CGI_POST   = 0x02,
62     Q_CGI_GET    = 0x04
63 } Q_CGI_T;
64 
65 /*
66  * qcgireq.c
67  */
68 extern qentry_t *qcgireq_setoption(qentry_t *request, bool filemode,
69                                    const char *basepath, int clearold);
70 extern qentry_t *qcgireq_parse(qentry_t *request, Q_CGI_T method);
71 extern char *qcgireq_getquery(Q_CGI_T method);
72 
73 /*
74  * qcgires.c
75  */
76 extern bool qcgires_setcookie(qentry_t *request, const char *name,
77                               const char *value, int expire, const char *path,
78                               const char *domain, bool secure);
79 extern bool qcgires_removecookie(qentry_t *request, const char *name,
80                                  const char *path, const char *domain,
81                                  bool secure);
82 
83 extern bool qcgires_setcontenttype(qentry_t *request, const char *mimetype);
84 extern const char *qcgires_getcontenttype(qentry_t *request);
85 extern bool qcgires_redirect(qentry_t *request, const char *uri);
86 extern int qcgires_download(qentry_t *request, const char *filepath,
87                             const char *mimetype);
88 extern void qcgires_error(qentry_t *request, char *format, ...);
89 
90 /*
91  * qcgisess.c
92  */
93 extern qentry_t  *qcgisess_init(qentry_t *request, const char *dirpath);
94 extern bool qcgisess_settimeout(qentry_t *session, time_t seconds);
95 extern const char *qcgisess_getid(qentry_t *session);
96 extern time_t qcgisess_getcreated(qentry_t *session);
97 extern bool qcgisess_save(qentry_t *session);
98 extern bool qcgisess_destroy(qentry_t *session);
99 
100 /*
101  * qentry.c - Linked-List Table
102  */
103 
104 /* public functions */
105 extern qentry_t *qEntry(void);
106 
107 /* qentry container */
108 struct qentry_s {
109     /* public functions */
110     bool (*put) (qentry_t *entry, const char *name, const void *data,
111                  size_t size, bool replace);
112     bool (*putstr) (qentry_t *entry, const char *name, const char *str,
113                     bool replace);
114     bool (*putstrf) (qentry_t *entry, bool replace, const char *name,
115                      const char *format, ...);
116     bool (*putint) (qentry_t *entry, const char *name, int num, bool replace);
117 
118     void *(*get) (qentry_t *entry, const char *name, size_t *size, bool newmem);
119     void *(*getlast) (qentry_t *entry, const char *name, size_t *size,
120                       bool newmem);
121     char *(*getstr) (qentry_t *entry, const char *name, bool newmem);
122     char *(*getstrf) (qentry_t *entry, bool newmem, const char *namefmt, ...);
123     char *(*getstrlast) (qentry_t *entry, const char *name, bool newmem);
124 
125     int (*getint) (qentry_t *entry, const char *name);
126     int (*getintlast) (qentry_t *entry, const char *name);
127 
128     void *(*caseget) (qentry_t *entry, const char *name, size_t *size,
129                       bool newmem);
130     char *(*casegetstr) (qentry_t *entry, const char *name, bool newmem);
131     int (*casegetint) (qentry_t *entry, const char *name);
132 
133     bool (*getnext) (qentry_t *entry, qentobj_t *obj, const char *name,
134                      bool newmem);
135 
136     int (*size) (qentry_t *entry);
137     int (*remove) (qentry_t *entry, const char *name);
138     bool (*truncate) (qentry_t *entry);
139     bool (*reverse) (qentry_t *entry);
140 
141     bool (*save) (qentry_t *entry, const char *filepath);
142     int (*load) (qentry_t *entry, const char *filepath);
143 
144     bool (*print) (qentry_t *entry, FILE *out, bool print_data);
145     bool (*free) (qentry_t *entry);
146 
147     /* private variables */
148     int num;            /*!< number of objects */
149     qentobj_t *first;   /*!< first object pointer */
150     qentobj_t *last;    /*!< last object pointer */
151 };
152 
153 /* qentry object */
154 struct qentobj_s {
155     char *name;          /*!< object name */
156     void *data;          /*!< data object */
157     size_t size;         /*!< object size */
158     qentobj_t *next;     /*!< link pointer */
159 };
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif /*_QDECODER_H */
166