--- libaitwww/src/aitwww.c 2012/07/31 23:08:40 1.3.4.3 +++ libaitwww/src/aitwww.c 2013/05/30 09:25:35 1.5 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitwww.c,v 1.3.4.3 2012/07/31 23:08:40 misho Exp $ +* $Id: aitwww.c,v 1.5 2013/05/30 09:25:35 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -55,21 +55,21 @@ char www_Error[STRSIZ]; #pragma GCC visibility pop // www_GetErrno() Get error code of last operation -inline int +int www_GetErrno() { return www_Errno; } // www_GetError() Get error text of last operation -inline const char * +const char * www_GetError() { return www_Error; } // www_SetErr() Set error to variables for internal use!!! -inline void +void www_SetErr(int eno, char *estr, ...) { va_list lst; @@ -130,9 +130,9 @@ www_initCGI(void) } /* allocated space for post data */ - str = io_malloc(ctlen + 1); + str = e_malloc(ctlen + 1); if (!str) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); return NULL; } else memset(str, 0, ctlen + 1); @@ -145,7 +145,7 @@ www_initCGI(void) else if (!www_cmp(s, "multipart/form-data")) cgi = www_parseMultiPart(str, ctlen, s); - io_free(str); + e_free(str); } else { /* Unknown method */ www_SetErr(EFAULT, "Unknown request method"); @@ -170,14 +170,14 @@ www_closeCGI(cgi_t ** __restrict cgi) return; while ((t = SLIST_FIRST(*cgi))) { - io_freeVar(&t->cgi_name); - io_freeVar(&t->cgi_value); + ait_freeVar(&t->cgi_name); + ait_freeVar(&t->cgi_value); SLIST_REMOVE_HEAD(*cgi, cgi_node); - io_free(t); + e_free(t); } - io_free(*cgi); + e_free(*cgi); *cgi = NULL; } @@ -199,21 +199,21 @@ www_parseQuery(const char *str) return NULL; } - cgi = io_malloc(sizeof(cgi_t)); + cgi = e_malloc(sizeof(cgi_t)); if (!cgi) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); return NULL; } else { memset(cgi, 0, sizeof(cgi_t)); SLIST_INIT(cgi); } - base = wrk = io_strdup(str); + base = wrk = e_strdup(str); while (*wrk) { - t = io_malloc(sizeof(struct tagCGI)); + t = e_malloc(sizeof(struct tagCGI)); if (!t) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); www_closeCGI(&cgi); return NULL; } else @@ -232,7 +232,7 @@ www_parseQuery(const char *str) old = t; } - io_free(base); + e_free(base); return cgi; } @@ -243,7 +243,7 @@ www_parseQuery(const char *str) * @name = Name of cgi variable * return: NULL not found or !=NULL value */ -inline const char * +const char * www_getValue(cgi_t * __restrict cgi, const char *name) { struct tagCGI *t; @@ -292,25 +292,25 @@ www_addValue(cgi_t * __restrict cgi, const char *name, } /* add new one */ - tmp = io_malloc(sizeof(struct tagCGI)); + tmp = e_malloc(sizeof(struct tagCGI)); if (!tmp) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); return -1; } else memset(tmp, 0, sizeof(struct tagCGI)); - tmp->cgi_name = io_allocVar(); + tmp->cgi_name = ait_allocVar(); if (!tmp->cgi_name) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); - io_free(tmp); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); + e_free(tmp); return -1; } else AIT_SET_STR(tmp->cgi_name, name); - tmp->cgi_value = io_allocVar(); + tmp->cgi_value = ait_allocVar(); if (!tmp->cgi_name) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); - io_freeVar(&tmp->cgi_name); - io_free(tmp); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); + ait_freeVar(&tmp->cgi_name); + e_free(tmp); return -1; } else AIT_SET_STR(tmp->cgi_value, value); @@ -344,9 +344,9 @@ www_delPair(cgi_t * __restrict cgi, const char *name) if (t->cgi_name && !strcmp(name, AIT_GET_STR(t->cgi_name))) { SLIST_REMOVE(cgi, t, tagCGI, cgi_node); - io_freeVar(&t->cgi_name); - io_freeVar(&t->cgi_value); - io_free(t); + ait_freeVar(&t->cgi_name); + ait_freeVar(&t->cgi_value); + e_free(t); return 1; } @@ -361,7 +361,7 @@ www_delPair(cgi_t * __restrict cgi, const char *name) * @arg = Optional argument pass through callback * return: -1 error or >-1 number of elements */ -inline int +int www_listPairs(cgi_t * __restrict cgi, list_cb_t func, void *arg) { register int ret = 0; @@ -388,7 +388,7 @@ www_listPairs(cgi_t * __restrict cgi, list_cb_t func, * @output = file handle * return: <1 error or >0 writed bytes */ -inline int +int www_header(FILE *output) { FILE *f = output ? output : stdout; @@ -408,9 +408,9 @@ quotStr(const char *str, const char **end) if (*str != '"') { n = strspn(str, "!#$%&'*+-.0123456789?ABCDEFGHIJKLMNOPQRSTUVWXYZ" "^_`abcdefghijklmnopqrstuvwxyz{|}~"); - s = io_allocVar(); + s = ait_allocVar(); if (!s) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); return NULL; } else { AIT_SET_STRSIZ(s, n + 1); @@ -426,9 +426,9 @@ quotStr(const char *str, const char **end) else len = e - str; - s = io_allocVar(); + s = ait_allocVar(); if (!s) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); return NULL; } else { AIT_SET_STRSIZ(s, len + 1); @@ -466,15 +466,15 @@ addAttr(const char **ct) if (!(eq = strchr(c, '='))) return NULL; - a = io_malloc(sizeof(struct tagCGI)); + a = e_malloc(sizeof(struct tagCGI)); if (!a) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); return NULL; } - a->cgi_name = io_allocVar(); + a->cgi_name = ait_allocVar(); if (!a->cgi_name) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); - io_free(a); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); + e_free(a); return NULL; } @@ -482,8 +482,8 @@ addAttr(const char **ct) AIT_SET_STR(a->cgi_name, c); a->cgi_value = quotStr(eq, &c); if (!a->cgi_value) { - io_freeVar(&a->cgi_name); - io_free(a); + ait_freeVar(&a->cgi_name); + e_free(a); return NULL; } @@ -515,9 +515,9 @@ www_parseMultiPart(const char *str, int ctlen, const c return NULL; } - cgi = io_malloc(sizeof(cgi_t)); + cgi = e_malloc(sizeof(cgi_t)); if (!cgi) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); return NULL; } else { memset(cgi, 0, sizeof(cgi_t)); @@ -546,9 +546,9 @@ www_parseMultiPart(const char *str, int ctlen, const c continue; } - t = io_malloc(sizeof(struct tagCGI)); + t = e_malloc(sizeof(struct tagCGI)); if (!t) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); mime_close(&mime); www_closeCGI(&cgi); return NULL; @@ -557,11 +557,11 @@ www_parseMultiPart(const char *str, int ctlen, const c AIT_COPY_VAL(t->cgi_name, www_getAttribute(attr, "name")); len = mime_calcRawSize(m); - t->cgi_value = io_allocVar(); + t->cgi_value = ait_allocVar(); if (!t->cgi_value) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); - io_freeVar(&t->cgi_name); - io_free(t); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); + ait_freeVar(&t->cgi_name); + e_free(t); mime_close(&mime); www_closeCGI(&cgi); return NULL; @@ -589,7 +589,7 @@ www_parseMultiPart(const char *str, int ctlen, const c * @ct = Content type * return: NULL error or !=NULL attributes */ -inline cgi_t * +cgi_t * www_parseAttributes(const char **ct) { struct tagCGI *t, *old = NULL; @@ -600,9 +600,9 @@ www_parseAttributes(const char **ct) return NULL; } - attr = io_malloc(sizeof(cgi_t)); + attr = e_malloc(sizeof(cgi_t)); if (!attr) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); return NULL; } else { memset(attr, 0, sizeof(cgi_t)); @@ -628,7 +628,7 @@ www_parseAttributes(const char **ct) * @name = Name of attribute variable * return: NULL not found or !=NULL value */ -inline ait_val_t * +ait_val_t * www_getAttribute(cgi_t * __restrict cgi, const char *name) { struct tagCGI *t;