--- libaitwww/src/tools.c 2012/03/10 00:26:49 1.2 +++ libaitwww/src/tools.c 2012/07/31 23:08:40 1.2.6.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tools.c,v 1.2 2012/03/10 00:26:49 misho Exp $ +* $Id: tools.c,v 1.2.6.3 2012/07/31 23:08:40 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -44,9 +44,15 @@ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF TH SUCH DAMAGE. */ #include "global.h" -#include "tools.h" +/* + * www_cmp() - Compare two string + * + * @ct = content text from www + * @s = string + * return: 0 are equal or !0 are different + */ int www_cmp(const char *ct, const char *s) { @@ -54,12 +60,12 @@ www_cmp(const char *ct, const char *s) assert(ct && s); - while (isspace(*ct)) + while (isspace((int) *ct)) ct++; if (!(sc = strchr(ct, ';'))) sc = strchr(ct, '\x0'); - while (isspace(*(sc - 1))) + while (isspace((int) *(sc - 1))) sc--; if (strlen(s) != sc - ct) @@ -67,6 +73,13 @@ www_cmp(const char *ct, const char *s) return strncasecmp(ct, s, sc - ct); } +/* + * www_cmptype() - Compare context type + * + * @ct = content text from www + * @type = content type + * return: 0 are equal or !0 are different + */ int www_cmptype(const char *ct, const char *type) { @@ -74,7 +87,7 @@ www_cmptype(const char *ct, const char *type) assert(ct && type); - while (isspace(*ct)) + while (isspace((int) *ct)) ct++; if (!(sl = strchr(ct, '/'))) @@ -85,33 +98,45 @@ www_cmptype(const char *ct, const char *type) return strncasecmp(ct, type, sl - ct); } -char * +/* + * www_getpair() - Get AV pair from WWW query string + * + * @str = query string + * @delim = delimiter + * return: NULL error or AV pair, must be io_free() after use! + */ +ait_val_t * www_getpair(char ** __restrict str, const char *delim) { - char *tr, *s = NULL; + char *tr; int cx; + ait_val_t *s; assert(str && *str && delim); - cx = strcspn(*str, delim); - tr = *str + cx; - - s = malloc(cx + 1); + s = io_allocVar(); if (!s) { - LOGERR; + www_SetErr(io_GetErrno(), "%s", io_GetError()); return NULL; - } else { - strncpy(s, *str, cx); - s[cx] = 0; } - *str = tr; - if (**str) - (*str)++; + cx = strcspn(*str, delim); + tr = *str + cx; + if (*tr) + *tr++ = 0; + AIT_SET_STR(s, *str); + + *str = tr; return s; } +/* + * www_x2c() - Hex from string to digit + * + * @str = string + * return: digit + */ inline char www_x2c(const char *str) { @@ -126,6 +151,12 @@ www_x2c(const char *str) return digit; } +/* + * www_unescape() - Unescape/decode WWW query string to host string + * + * @str = string + * return: none + */ inline void www_unescape(char * __restrict str) {