00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00032 #ifndef _QDECODER_H
00033 #define _QDECODER_H
00034
00035 #define _Q_VERSION "9.0.3"
00036
00037 #include <stdio.h>
00038 #include <stdbool.h>
00039 #include <time.h>
00040 #include <sys/types.h>
00041
00045 typedef struct Q_NLOBJ {
00046 char *name;
00047 void *object;
00048 int size;
00049 struct Q_NLOBJ *next;
00050 } Q_NLOBJ;
00051
00055 typedef struct {
00056 void *object;
00057 int size;
00058 } Q_OBJ;
00059
00063 typedef struct {
00064 int num;
00065 size_t size;
00066 Q_NLOBJ *first;
00067 Q_NLOBJ *last;
00068 Q_NLOBJ *next;
00069 Q_NLOBJ *cont;
00070 } Q_ENTRY;
00071
00075 typedef struct {
00076 int max;
00077 int num;
00079 int *count;
00080 int *hash;
00081 char **key;
00082 void **value;
00083 int *size;
00084 } Q_HASHTBL;
00085
00086 #define _Q_HASHARR_MAX_KEYSIZE (31+1)
00087 #define _Q_HASHARR_DEF_VALUESIZE (32)
00088
00091 typedef struct {
00092 int count;
00093 int hash;
00095 char key[_Q_HASHARR_MAX_KEYSIZE];
00096 int keylen;
00097 unsigned char keymd5[16];
00099 unsigned char value[_Q_HASHARR_DEF_VALUESIZE];
00100 int size;
00101 int link;
00102 } Q_HASHARR;
00103
00107 typedef struct {
00108 int max;
00109 int used;
00111 int head;
00112 int tail;
00114 size_t objsize;
00115 void *objarr;
00116 } Q_QUEUE;
00117
00121 typedef struct {
00122 Q_ENTRY *stack;
00123 void *final;
00124 } Q_OBSTACK;
00125
00129 typedef struct {
00130 char logbase[1024];
00131 char nameformat[256];
00133 char filename[256];
00134 char logpath[1024];
00135 FILE *fp;
00137 bool console;
00138 int rotateinterval;
00139 int nextrotate;
00140 bool flush;
00141 } Q_LOG;
00142
00143
00144 #ifdef _mysql_h
00145 #define _Q_ENABLE_MYSQL (1)
00146
00147 #define _Q_MYSQL_OPT_RECONNECT (1)
00148 #define _Q_MYSQL_OPT_CONNECT_TIMEOUT (10)
00149 #define _Q_MYSQL_OPT_READ_TIMEOUT (30)
00150 #define _Q_MYSQL_OPT_WRITE_TIMEOUT (30)
00151 #endif
00152
00156 typedef struct {
00157 bool connected;
00159 struct {
00160 char* dbtype;
00161 char* addr;
00162 int port;
00163 char* username;
00164 char* password;
00165 char* database;
00166 bool autocommit;
00167 bool fetchtype;
00168 } info;
00170
00171 #ifdef _Q_ENABLE_MYSQL
00172 MYSQL *mysql;
00173 #endif
00174 } Q_DB;
00175
00179 typedef struct {
00180 #ifdef _Q_ENABLE_MYSQL
00181 bool fetchtype;
00182 MYSQL_RES *rs;
00183 MYSQL_FIELD *fields;
00184 MYSQL_ROW row;
00185 int cols;
00186 int cursor;
00187 #endif
00188 } Q_DBRESULT;
00189
00190 #ifndef _DOXYGEN_SKIP
00191
00192
00193 #ifdef __cplusplus
00194 extern "C" {
00195 #endif
00196
00197
00198
00199
00200 extern Q_ENTRY* qCgiRequestParseOption(bool filemode, const char *basepath, int clearold);
00201 extern Q_ENTRY* qCgiRequestParse(Q_ENTRY *request);
00202 extern Q_ENTRY* qCgiRequestParseQueries(Q_ENTRY *request, const char *method);
00203 extern Q_ENTRY* qCgiRequestParseCookies(Q_ENTRY *request);
00204 extern char* qCgiRequestGetQueryString(const char *query_type);
00205
00206
00207
00208
00209 extern bool qCgiResponseSetCookie(Q_ENTRY *request, const char *name, const char *value, int expire, const char *path, const char *domain, bool secure);
00210 extern bool qCgiResponseRemoveCookie(Q_ENTRY *request, const char *name, const char *path, const char *domain, bool secure);
00211
00212 extern bool qCgiResponseSetContentType(Q_ENTRY *request, const char *mimetype);
00213 extern const char* qCgiResponseGetContentType(Q_ENTRY *request);
00214 extern bool qCgiResponseRedirect(Q_ENTRY *request, const char *uri);
00215 extern int qCgiResponseDownload(Q_ENTRY *request, const char *filepath, const char *mimetype);
00216 extern void qCgiResponseError(Q_ENTRY *request, char *format, ...);
00217
00218
00219
00220
00221 extern Q_ENTRY* qSessionInit(Q_ENTRY *request, const char *dirpath);
00222 extern bool qSessionSetTimeout(Q_ENTRY *session, time_t seconds);
00223 extern const char* qSessionGetId(Q_ENTRY *session);
00224 extern time_t qSessionGetCreated(Q_ENTRY *session);
00225 extern bool qSessionSave(Q_ENTRY *session);
00226 extern bool qSessionDestroy(Q_ENTRY *session);
00227
00228
00229
00230
00231 extern bool qHtmlPrintf(FILE *stream, int mode, const char *format, ...);
00232 extern bool qHtmlPuts(FILE *stream, int mode, char *buf);
00233 extern bool qHtmlIsEmail(const char *email);
00234 extern bool qHtmlIsUrl(const char *url);
00235
00236
00237
00238
00239 extern int qSocketOpen(const char *hostname, int port);
00240 extern bool qSocketClose(int sockfd);
00241 extern int qSocketWaitReadable(int sockfd, int timeoutms);
00242 extern int qSocketWaitWritable(int sockfd, int timeoutms);
00243 extern ssize_t qSocketRead(void *binary, int sockfd, size_t nbytes, int timeoutms);
00244 extern ssize_t qSocketGets(char *str, int sockfd, size_t nbytes, int timeoutms);
00245 extern ssize_t qSocketWrite(int sockfd, const void *binary, size_t nbytes);
00246 extern ssize_t qSocketPuts(int sockfd, const char *str);
00247 extern ssize_t qSocketPrintf(int sockfd, const char *format, ...);
00248 extern off_t qSocketSendfile(int sockfd, int fd, off_t offset, off_t nbytes);
00249 extern off_t qSocketSaveIntoFile(int fd, int sockfd, off_t nbytes, int timeoutms);
00250 extern ssize_t qSocketSaveIntoMemory(char *mem, int sockfd, size_t nbytes, int timeoutms);
00251
00252
00253
00254
00255 extern int qSemInit(const char *keyfile, int keyid, int nsems, bool ifexistdestroy);
00256 extern int qSemGetId(const char *keyfile, int keyid);
00257 extern bool qSemEnter(int semid, int semno);
00258 extern bool qSemEnterNowait(int semid, int semno);
00259 extern bool qSemEnterForce(int semid, int semno, int maxwaitms, bool *forceflag);
00260 extern bool qSemLeave(int semid, int semno);
00261 extern bool qSemCheck(int semid, int semno);
00262 extern bool qSemFree(int semid);
00263
00264
00265
00266
00267 extern int qShmInit(const char *keyfile, int keyid, size_t size, bool ifexistdestroy);
00268 extern int qShmGetId(const char *keyfile, int keyid);
00269 extern void* qShmGet(int shmid);
00270 extern bool qShmFree(int shmid);
00271
00272
00273
00274
00275 extern Q_DB* qDbInit(const char *dbtype, const char *addr, int port, const char *database, const char *username, const char *password, bool autocommit);
00276 extern bool qDbOpen(Q_DB *db);
00277 extern bool qDbClose(Q_DB *db);
00278 extern bool qDbFree(Q_DB *db);
00279 extern const char* qDbGetError(Q_DB *db, unsigned int *errorno);
00280 extern bool qDbPing(Q_DB *db);
00281 extern bool qDbGetLastConnStatus(Q_DB *db);
00282 extern bool qDbSetFetchType(Q_DB *db, bool use);
00283
00284 extern int qDbExecuteUpdate(Q_DB *db, const char *query);
00285 extern int qDbExecuteUpdatef(Q_DB *db, const char *format, ...);
00286
00287 extern Q_DBRESULT* qDbExecuteQuery(Q_DB *db, const char *query);
00288 extern Q_DBRESULT* qDbExecuteQueryf(Q_DB *db, const char *format, ...);
00289 extern bool qDbResultNext(Q_DBRESULT *result);
00290 extern bool qDbResultFree(Q_DBRESULT *result);
00291
00292 extern int qDbGetCols(Q_DBRESULT *result);
00293 extern int qDbGetRows(Q_DBRESULT *result);
00294 extern int qDbGetRow(Q_DBRESULT *result);
00295
00296 extern const char* qDbGetStr(Q_DBRESULT *result, const char *field);
00297 extern const char* qDbGetStrAt(Q_DBRESULT *result, int idx);
00298 extern int qDbGetInt(Q_DBRESULT *result, const char *field);
00299 extern int qDbGetIntAt(Q_DBRESULT *result, int idx);
00300
00301 extern bool qDbBeginTran(Q_DB *db);
00302 extern bool qDbEndTran(Q_DB *db, bool commit);
00303 extern bool qDbCommit(Q_DB *db);
00304 extern bool qDbRollback(Q_DB *db);
00305
00306
00307
00308
00309 extern Q_ENTRY* qEntryInit(void);
00310 extern const Q_NLOBJ* qEntryFirst(Q_ENTRY *entry);
00311 extern const Q_NLOBJ* qEntryNext(Q_ENTRY *entry);
00312 extern int qEntryRemove(Q_ENTRY *entry, const char *name);
00313 extern bool qEntryPut(Q_ENTRY *entry, const char *name, const void *object, int size, bool update);
00314 extern bool qEntryPutStr(Q_ENTRY *entry, const char *name, const char *str, bool update);
00315 extern bool qEntryPutStrf(Q_ENTRY *entry, const char *name, bool update, char *format, ...);
00316 extern bool qEntryPutInt(Q_ENTRY *entry, const char *name, int num, bool update);
00317 extern const void* qEntryGet(Q_ENTRY *entry, const char *name, int *size);
00318 extern const void* qEntryGetCase(Q_ENTRY *entry, const char *name, int *size);
00319 extern const void* qEntryGetNext(Q_ENTRY *entry, const char *name, int *size);
00320 extern const void* qEntryGetNextCase(Q_ENTRY *entry, const char *name, int *size);
00321 extern const void* qEntryGetLast(Q_ENTRY *entry, const char *name, int *size);
00322 extern const char* qEntryGetStr(Q_ENTRY *entry, const char *name);
00323 extern const char* qEntryGetStrCase(Q_ENTRY *entry, const char *name);
00324 extern const char* qEntryGetStrf(Q_ENTRY *entry, char *format, ...);
00325 extern const char* qEntryGetStrNext(Q_ENTRY *entry, const char *name);
00326 extern const char* qEntryGetStrNextCase(Q_ENTRY *entry, const char *name);
00327 extern const char* qEntryGetStrLast(Q_ENTRY *entry, const char *name);
00328 extern int qEntryGetInt(Q_ENTRY *entry, const char *name);
00329 extern int qEntryGetIntCase(Q_ENTRY *entry, const char *name);
00330 extern int qEntryGetIntf(Q_ENTRY *entry, char *format, ...);
00331 extern int qEntryGetIntNext(Q_ENTRY *entry, const char *name);
00332 extern int qEntryGetIntNextCase(Q_ENTRY *entry, const char *name);
00333 extern int qEntryGetIntLast(Q_ENTRY *entry, const char *name);
00334 extern int qEntryGetNum(Q_ENTRY *entry);
00335 extern int qEntryGetNo(Q_ENTRY *entry, const char *name);
00336 extern bool qEntryReverse(Q_ENTRY *entry);
00337 extern bool qEntryPrint(Q_ENTRY *entry, FILE *out, bool print_object);
00338 extern bool qEntryFree(Q_ENTRY *entry);
00339 extern bool qEntrySave(Q_ENTRY *entry, const char *filepath, char sepchar, bool encode);
00340 extern int qEntryLoad(Q_ENTRY *entry, const char *filepath, char sepchar, bool decode);
00341
00342
00343
00344
00345 extern Q_HASHTBL* qHashtblInit(int max);
00346 extern bool qHashtblFree(Q_HASHTBL *tbl);
00347 extern bool qHashtblPut(Q_HASHTBL *tbl, const char *key, const void *value, int size);
00348 extern bool qHashtblPutStr(Q_HASHTBL *tbl, const char *key, const char *value);
00349 extern bool qHashtblPutInt(Q_HASHTBL *tbl, const char *key, int value);
00350 extern void* qHashtblGet(Q_HASHTBL *tbl, const char *key, int *size);
00351 extern char* qHashtblGetStr(Q_HASHTBL *tbl, const char *key);
00352 extern int qHashtblGetInt(Q_HASHTBL *tbl, const char *key);
00353 extern const char* qHashtblGetFirstKey(Q_HASHTBL *tbl, int *idx);
00354 extern const char* qHashtblGetNextKey(Q_HASHTBL *tbl, int *idx);
00355 extern bool qHashtblRemove(Q_HASHTBL *tbl, const char *key);
00356 extern bool qHashtblPrint(Q_HASHTBL *tbl, FILE *out, bool showvalue);
00357 extern bool qHashtblStatus(Q_HASHTBL *tbl, int *used, int *max);
00358
00359
00360
00361
00362 extern size_t qHasharrSize(int max);
00363 extern int qHasharrInit(Q_HASHARR *tbl, size_t memsize);
00364 extern bool qHasharrClear(Q_HASHARR *tbl);
00365 extern bool qHasharrPut(Q_HASHARR *tbl, const char *key, const void *value, int size);
00366 extern bool qHasharrPutStr(Q_HASHARR *tbl, const char *key, const char *value);
00367 extern bool qHasharrPutInt(Q_HASHARR *tbl, const char *key, int value);
00368 extern void* qHasharrGet(Q_HASHARR *tbl, const char *key, int *size);
00369 extern char* qHasharrGetStr(Q_HASHARR *tbl, const char *key);
00370 extern int qHasharrGetInt(Q_HASHARR *tbl, const char *key);
00371 extern const char* qHasharrGetFirstKey(Q_HASHARR *tbl, int *idx);
00372 extern const char* qHasharrGetNextKey(Q_HASHARR *tbl, int *idx);
00373 extern bool qHasharrRemove(Q_HASHARR *tbl, const char *key);
00374 extern bool qHasharrPrint(Q_HASHARR *tbl, FILE *out);
00375 extern bool qHasharrStatus(Q_HASHARR *tbl, int *used, int *max);
00376
00377
00378
00379
00380 extern size_t qQueueSize(int max, size_t objsize);
00381 extern int qQueueInit(Q_QUEUE *queue, void* datamem, size_t datamemsize, size_t objsize);
00382 extern bool qQueueClear(Q_QUEUE *queue);
00383 extern bool qQueuePush(Q_QUEUE *queue, const void *object);
00384 extern bool qQueuePopFirst(Q_QUEUE *queue, void *object);
00385 extern bool qQueuePopLast(Q_QUEUE *queue, void *object);
00386 extern bool qQueueStatus(Q_QUEUE *queue, int *used, int *max);
00387
00388
00389
00390
00391 extern Q_OBSTACK* qObstackInit(void);
00392 extern bool qObstackGrow(Q_OBSTACK *obstack, const void *object, size_t size);
00393 extern bool qObstackGrowStr(Q_OBSTACK *obstack, const char *str);
00394 extern bool qObstackGrowStrf(Q_OBSTACK *obstack, const char *format, ...);
00395 extern void* qObstackFinish(Q_OBSTACK *obstack);
00396 extern void* qObstackGetFinal(Q_OBSTACK *obstack);
00397 extern size_t qObstackGetSize(Q_OBSTACK *obstack);
00398 extern int qObstackGetNum(Q_OBSTACK *obstack);
00399 extern bool qObstackFree(Q_OBSTACK *obstack);
00400
00401
00402
00403
00404 extern Q_ENTRY* qConfigParseFile(Q_ENTRY *config, const char *filepath, char sepchar);
00405 extern Q_ENTRY* qConfigParseStr(Q_ENTRY *config, const char *str, char sepchar);
00406
00407
00408
00409
00410 extern Q_LOG* qLogOpen(const char *logbase, const char *filenameformat, int rotateinterval, bool flush);
00411 extern bool qLogClose(Q_LOG *log);
00412 extern bool qLogSetConsole(Q_LOG *log, bool consoleout);
00413 extern bool qLogFlush(Q_LOG *log);
00414 extern bool qLog(Q_LOG *log, const char *format, ...);
00415
00416
00417
00418
00419 extern char* qStrTrim(char *str);
00420 extern char* qStrTrimTail(char *str);
00421 extern char* qStrUnchar(char *str, char head, char tail);
00422 extern char* qStrReplace(const char *mode, char *srcstr, const char *tokstr, const char *word);
00423 extern char* qStrCpy(char *dst, size_t dstsize, const char *src, size_t nbytes);
00424 extern char* qStrUpper(char *str);
00425 extern char* qStrLower(char *str);
00426 extern char* qStrCaseStr(const char *s1, const char *s2);
00427 extern char* qStrRev(char *str);
00428 extern char* qStrTok(char *str, const char *token, char *retstop);
00429 extern Q_ENTRY* qStrTokenizer(char *str, const char *delimiters);
00430 extern char* qStrCommaNumber(int number);
00431 extern char* qStrCatf(char *str, const char *format, ...);
00432 extern char* qStrDupBetween(const char *str, const char *start, const char *end);
00433 extern char* qStrUnique(const char *seed);
00434 extern bool qStrIsAlnum(const char *str);
00435 extern char* qStrConvEncoding(const char *fromstr, const char *fromcode, const char *tocode, float mag);
00436
00437
00438
00439
00440 extern bool qFileLock(int fd);
00441 extern bool qFileUnlock(int fd);
00442 extern bool qFileExist(const char *filepath);
00443 extern char* qFileGetName(const char *filepath);
00444 extern char* qFileGetDir(const char *filepath);
00445 extern char* qFileGetExt(const char *filepath);
00446 extern off_t qFileGetSize(const char *filepath);
00447 extern off_t qFileSend(int outfd, int infd, off_t nbytes);
00448 extern void* qFileLoad(const char *filepath, size_t *nbytes);
00449 extern void* qFileRead(FILE *fp, size_t *nbytes);
00450 extern ssize_t qFileSave(const char *filepath, const void *buf, size_t size, bool append);
00451 extern char* qFileReadLine(FILE *fp);
00452
00453
00454
00455
00456 extern Q_ENTRY* qDecodeQueryString(Q_ENTRY *entry, const char *query, char equalchar, char sepchar, int *count);
00457 extern char* qEncodeUrl(const char *str);
00458 extern char* qDecodeUrl(char *str);
00459
00460
00461
00462
00463 extern unsigned char* qHashMd5(const void *data, size_t nbytes);
00464 extern char* qHashMd5Str(const void *data, size_t nbytes);
00465 extern char* qHashMd5File(const char *filepath, size_t *nbytes);
00466 extern unsigned int qHashFnv32(unsigned int max, const void *data, size_t nbytes);
00467
00468
00469
00470
00471 extern bool qSedStr(Q_ENTRY *entry, const char *srcstr, FILE *fpout);
00472 extern bool qSedFile(Q_ENTRY *entry, const char *filepath, FILE *fpout);
00473
00474
00475
00476
00477 extern int qCountRead(const char *filepath);
00478 extern bool qCountSave(const char *filepath, int number);
00479 extern int qCountUpdate(const char *filepath, int number);
00480
00481
00482
00483
00484 extern char* qTimeGetLocalStrf(char *buf, int size, time_t utctime, const char *format);
00485 extern char* qTimeGetLocalStr(time_t utctime);
00486 extern const char* qTimeGetLocalStaticStr(time_t utctime);
00487 extern char* qTimeGetGmtStrf(char *buf, int size, time_t utctime, const char *format);
00488 extern char* qTimeGetGmtStr(time_t utctime);
00489 extern const char* qTimeGetGmtStaticStr(time_t utctime);
00490 extern time_t qTimeParseGmtStr(const char *gmtstr);
00491
00492
00493
00494
00495 extern const char* qSysGetEnv(const char *envname, const char *nullstr);
00496 extern char* qSysCmd(const char *cmd);
00497 extern const char* qDecoderVersion(void);
00498
00499 #ifdef __cplusplus
00500 }
00501 #endif
00502
00503 #endif
00504
00505 #endif