version 1.3.2.2, 2012/08/06 11:26:23
|
version 1.4.4.1, 2013/01/17 14:52:44
|
Line 12 terms:
|
Line 12 terms:
|
All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
|
|
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 | Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
|
|
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
Line 103 www_cmptype(const char *ct, const char *type)
|
Line 103 www_cmptype(const char *ct, const char *type)
|
* |
* |
* @str = query string |
* @str = query string |
* @delim = delimiter |
* @delim = delimiter |
* return: NULL error or AV pair, must be io_free() after use! | * return: NULL error or AV pair, must be e_free() after use! |
*/ |
*/ |
ait_val_t * |
ait_val_t * |
www_getpair(char ** __restrict str, const char *delim) |
www_getpair(char ** __restrict str, const char *delim) |
Line 114 www_getpair(char ** __restrict str, const char *delim)
|
Line 114 www_getpair(char ** __restrict str, const char *delim)
|
|
|
assert(str && *str && delim); |
assert(str && *str && delim); |
|
|
s = io_allocVar(); | s = ait_allocVar(); |
if (!s) { |
if (!s) { |
www_SetErr(io_GetErrno(), "%s", io_GetError()); | www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); |
return NULL; |
return NULL; |
} |
} |
|
|
Line 182 www_unescape(char * __restrict str)
|
Line 182 www_unescape(char * __restrict str)
|
/* |
/* |
* www_undot() - Undotted and clean WWW query filename |
* www_undot() - Undotted and clean WWW query filename |
* |
* |
* @fname = query filename | * @pname = query filename |
* @fnlen = filename length | * return: =NULL error or !=NULL allocated valid filename, after use you must call ait_freeVar() |
* return: -1 error, 0 not valid filename or >0 validated filename length | |
*/ |
*/ |
int | ait_val_t * |
www_undot(const char * __restrict fname, int fnlen) | www_undot(const char * __restrict pname) |
{ |
{ |
char *s, *s2; | char *s, *s2, *fname; |
int l; |
int l; |
|
ait_val_t *v; |
|
|
if (!fname || !fnlen) | if (!pname) |
return -1; | return NULL; |
| /* check for valid query filename */ |
| if (*pname != '/') |
| return NULL; |
|
|
|
v = ait_allocVar(); |
|
if (!v) { |
|
www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); |
|
return NULL; |
|
} else { |
|
AIT_SET_STR(v, pname + 1); |
|
fname = AIT_GET_STR(v); |
|
} |
|
|
/* collapse / sequences */ |
/* collapse / sequences */ |
if ((s = strstr(fname, "//"))) { |
if ((s = strstr(fname, "//"))) { |
s2 = s + 1; |
s2 = s + 1; |
Line 204 www_undot(const char * __restrict fname, int fnlen)
|
Line 216 www_undot(const char * __restrict fname, int fnlen)
|
|
|
/* escaped ./ and /./ sequences */ |
/* escaped ./ and /./ sequences */ |
while (!strncmp(fname, "./", 2)) |
while (!strncmp(fname, "./", 2)) |
memmove((void*) fname, fname + 2, strlen(fname + 1)); | memmove(fname, fname + 2, strlen(fname + 1)); |
while ((s = strstr(fname, "/./"))) |
while ((s = strstr(fname, "/./"))) |
memmove(s, s + 2, strlen(s + 1)); |
memmove(s, s + 2, strlen(s + 1)); |
|
|
/* alternate between removing leading ../ and removing xxx/../ */ |
/* alternate between removing leading ../ and removing xxx/../ */ |
while (42) { |
while (42) { |
while (!strncmp(fname, "../", 3)) |
while (!strncmp(fname, "../", 3)) |
memmove((void*) fname, fname + 3, strlen(fname + 2)); | memmove(fname, fname + 3, strlen(fname + 2)); |
if (!(s = strstr(fname, "/../"))) |
if (!(s = strstr(fname, "/../"))) |
break; |
break; |
for (s2 = s - 1; s2 >= fname && *s2 != '/'; --s2); |
for (s2 = s - 1; s2 >= fname && *s2 != '/'; --s2); |
Line 220 www_undot(const char * __restrict fname, int fnlen)
|
Line 232 www_undot(const char * __restrict fname, int fnlen)
|
|
|
/* elide any /.. at the end */ |
/* elide any /.. at the end */ |
while ((l = strlen(fname)) > 3 && |
while ((l = strlen(fname)) > 3 && |
!strcmp((s = (char*) fname + l - 3), "/..")) { | !strcmp((s = fname + l - 3), "/..")) { |
for (s2 = s - 1; s2 >= fname && *s2 != '/'; --s2); |
for (s2 = s - 1; s2 >= fname && *s2 != '/'; --s2); |
if (s2 < fname) |
if (s2 < fname) |
break; |
break; |
Line 228 www_undot(const char * __restrict fname, int fnlen)
|
Line 240 www_undot(const char * __restrict fname, int fnlen)
|
} |
} |
|
|
/* if filename is empry add current dir */ |
/* if filename is empry add current dir */ |
if (!*fname) | if (!*fname) { |
strlcpy((char*) fname, "./", fnlen); | AIT_FREE_VAL(v); |
| AIT_SET_STR(v, "./"); |
| fname = AIT_GET_STR(v); |
| } |
|
|
/* check for valid filename */ |
/* check for valid filename */ |
if (*fname == '/' || (fname[0] == '.' && fname[1] == '.' && |
if (*fname == '/' || (fname[0] == '.' && fname[1] == '.' && |
(!fname[2] || fname[2] == '/'))) | (!fname[2] || fname[2] == '/'))) { |
return 0; | ait_freeVar(&v); |
| return NULL; |
| } |
|
|
return strlen(fname); | return v; |
} |
} |