version 1.2, 2012/03/15 01:59:37
|
version 1.3, 2012/09/20 14:19:45
|
Line 47 SUCH DAMAGE.
|
Line 47 SUCH DAMAGE.
|
|
|
|
|
/* |
/* |
|
* www_URLInit() - Init URL structure and free old one |
|
* |
|
* @url = Input URL |
|
* return: -1 error or 0 ok |
|
*/ |
|
inline int |
|
www_URLInit(struct tagIOURL * __restrict url) |
|
{ |
|
if (!url) |
|
return -1; |
|
else |
|
memset(url, 0, sizeof(struct tagIOURL)); |
|
|
|
AIT_INIT_VAL2(&url->url_tech, string); |
|
AIT_INIT_VAL2(&url->url_user, string); |
|
AIT_INIT_VAL2(&url->url_pass, string); |
|
AIT_INIT_VAL2(&url->url_host, string); |
|
AIT_INIT_VAL2(&url->url_port, string); |
|
AIT_INIT_VAL2(&url->url_path, string); |
|
AIT_INIT_VAL2(&url->url_args, string); |
|
return 0; |
|
} |
|
|
|
/* |
* www_URLGet() - Parse and get data from input URL |
* www_URLGet() - Parse and get data from input URL |
* |
* |
* @csURL = Input URL line |
* @csURL = Input URL line |
Line 55 SUCH DAMAGE.
|
Line 79 SUCH DAMAGE.
|
* -1 error:: can`t read; >0 ok, up bits for known elements |
* -1 error:: can`t read; >0 ok, up bits for known elements |
*/ |
*/ |
int |
int |
www_URLGet(const char *csURL, struct tagIOURL *url) | www_URLGet(const char *csURL, struct tagIOURL * __restrict url) |
{ |
{ |
char *pos, *at, *cl, *sl; |
char *pos, *at, *cl, *sl; |
int ret = 0; |
int ret = 0; |
Line 63 www_URLGet(const char *csURL, struct tagIOURL *url)
|
Line 87 www_URLGet(const char *csURL, struct tagIOURL *url)
|
if (!url) |
if (!url) |
return -1; |
return -1; |
else |
else |
memset(url, 0, sizeof(*url)); | www_URLInit(url); |
|
|
strlcpy((char*) url->url_line, csURL, BUFSIZ); | AIT_SET_STR(&url->url_line, csURL); |
| /* unescape URL */ |
| www_unescape(AIT_GET_STR(&url->url_line)); |
/* Tech */ |
/* Tech */ |
if (!(pos = strstr((char*) url->url_line, "://"))) { | if (!(pos = strstr(AIT_GET_STR(&url->url_line), "://"))) { |
url->url_path.vallen = strlen((char*) url->url_line); | AIT_SET_LIKE(&url->url_path, string, |
url->url_path.value = (char*) url->url_line; | AIT_LEN(&url->url_line), AIT_ADDR(&url->url_line)); |
return ret; |
return ret; |
} else { |
} else { |
url->url_tech.value = (char*) url->url_line; | AIT_SET_LIKE(&url->url_tech, string, |
url->url_tech.vallen = pos - (char*) url->url_line; | pos - AIT_GET_STR(&url->url_line), AIT_ADDR(&url->url_line)); |
if (url->url_tech.vallen) | if (AIT_LEN(&url->url_tech)) |
ret |= 1; |
ret |= 1; |
|
|
*pos = 0; |
*pos = 0; |
pos += 3; | pos += 3; /* :// */ |
} |
} |
|
|
/* User */ |
/* User */ |
Line 88 www_URLGet(const char *csURL, struct tagIOURL *url)
|
Line 114 www_URLGet(const char *csURL, struct tagIOURL *url)
|
if ((cl = strchr(pos, ':'))) { |
if ((cl = strchr(pos, ':'))) { |
*cl++ = 0; |
*cl++ = 0; |
|
|
url->url_pass.value = cl; | AIT_SET_LIKE(&url->url_pass, string, at - cl - 1, cl); |
url->url_pass.vallen = at - cl - 1; | if (AIT_LEN(&url->url_pass)) |
if (url->url_pass.vallen) | |
ret |= 4; |
ret |= 4; |
} else |
} else |
cl = at; |
cl = at; |
|
|
url->url_user.value = pos; | AIT_SET_LIKE(&url->url_user, string, cl - pos - 1, pos); |
url->url_user.vallen = cl - pos - 1; | if (AIT_LEN(&url->url_user)) |
if (url->url_user.vallen) | |
ret |= 2; |
ret |= 2; |
|
|
pos = at; |
pos = at; |
Line 112 www_URLGet(const char *csURL, struct tagIOURL *url)
|
Line 136 www_URLGet(const char *csURL, struct tagIOURL *url)
|
if ((cl = strchr(pos, ':'))) { |
if ((cl = strchr(pos, ':'))) { |
*cl++ = 0; |
*cl++ = 0; |
|
|
url->url_port.value = cl; | AIT_SET_LIKE(&url->url_port, string, sl - cl - 1, cl); |
url->url_port.vallen = sl - cl - 1; | if (AIT_LEN(&url->url_port)) |
if (url->url_port.vallen) | |
ret |= 16; |
ret |= 16; |
} else |
} else |
cl = sl; |
cl = sl; |
|
|
url->url_host.value = pos; | AIT_SET_LIKE(&url->url_host, string, cl - pos - 1, pos); |
url->url_host.vallen = cl - pos - 1; | if (AIT_LEN(&url->url_host)) |
if (url->url_host.vallen) | |
ret |= 8; |
ret |= 8; |
|
|
pos = sl; |
pos = sl; |
Line 130 www_URLGet(const char *csURL, struct tagIOURL *url)
|
Line 152 www_URLGet(const char *csURL, struct tagIOURL *url)
|
if ((at = strchr(pos, '?'))) { |
if ((at = strchr(pos, '?'))) { |
*at++ = 0; |
*at++ = 0; |
|
|
url->url_args.value = at; | AIT_SET_LIKE(&url->url_args, string, strlen(at), at); |
url->url_args.vallen = strlen(at); | if (AIT_LEN(&url->url_args)) |
if (url->url_args.vallen) | |
ret |= 64; |
ret |= 64; |
} else |
} else |
at = pos + strlen(pos) + 1; |
at = pos + strlen(pos) + 1; |
|
|
/* Path */ |
/* Path */ |
url->url_path.value = pos; | AIT_SET_LIKE(&url->url_path, string, at - pos - 1, pos); |
url->url_path.vallen = at - pos - 1; | if (AIT_LEN(&url->url_path)) |
if (url->url_path.vallen) | |
ret |= 32; |
ret |= 32; |
|
|
pos = at + strlen(at); |
pos = at + strlen(at); |
|
|
/* Reserved */ |
/* Reserved */ |
url->url_reserved = pos; | url->url_reserved = (u_char*) pos; |
if (*pos) |
if (*pos) |
ret |= 128; |
ret |= 128; |
|
|
Line 157 www_URLGet(const char *csURL, struct tagIOURL *url)
|
Line 177 www_URLGet(const char *csURL, struct tagIOURL *url)
|
* www_URLGetFile() - Get file from parsed URL |
* www_URLGetFile() - Get file from parsed URL |
* |
* |
* @url = Input parsed URL |
* @url = Input parsed URL |
* @psValue = Return filename, if not specified file in url path, replace with / | * @value = Return filename, if not specified file in url path, replace with / |
* @valLen = Size of psValue array | * return: -1 error, 0 filename from path, 1 filename or 2 not specified filename |
* return: -1 error:: can`t read; 0 ok | |
*/ |
*/ |
int |
int |
www_URLGetFile(struct tagIOURL *url, char * __restrict psValue, int valLen) | www_URLGetFile(struct tagIOURL * __restrict url, ait_val_t * __restrict value) |
{ |
{ |
char *pos, *psBuf; |
char *pos, *psBuf; |
|
int ret = 0; |
|
|
if (!url || !psValue || !valLen) | if (!url || !value) |
return -1; |
return -1; |
|
|
psBuf = strdup(url->url_path.value); | psBuf = io_strdup(AIT_GET_STR(&url->url_path)); |
if (!psBuf) { |
if (!psBuf) { |
LOGERR; | www_SetErr(io_GetErrno(), "%s", io_GetError()); |
return -1; |
return -1; |
} | } else |
| AIT_FREE_VAL(value); |
|
|
pos = strrchr(psBuf, '/'); |
pos = strrchr(psBuf, '/'); |
if (!pos) { |
if (!pos) { |
/* whole string is filename */ |
/* whole string is filename */ |
strlcpy(psValue, psBuf, valLen); | pos = psBuf; |
| ret = 1; |
free(psBuf); | } else |
return 1; | |
} else { | |
*pos++ = 0; |
*pos++ = 0; |
| /* If not specified file in path, default replace to / */ |
strlcpy(psValue, pos, valLen); | if (!*pos) { |
free(psBuf); | pos = "/"; |
| ret = 2; |
} |
} |
|
|
/* If not specified file in path, default replace to / */ | AIT_SET_STR(value, pos); |
if (!*psValue) | io_free(psBuf); |
strlcpy(psValue, "/", valLen); | return ret; |
return 0; | } |
| |
| /* |
| * www_URLFree() - URL free structure |
| * |
| * @url = Input parsed URL |
| * return: none |
| */ |
| inline void |
| www_URLFree(struct tagIOURL * __restrict url) |
| { |
| AIT_FREE_VAL(&url->url_tech); |
| AIT_FREE_VAL(&url->url_user); |
| AIT_FREE_VAL(&url->url_pass); |
| AIT_FREE_VAL(&url->url_host); |
| AIT_FREE_VAL(&url->url_port); |
| AIT_FREE_VAL(&url->url_path); |
| AIT_FREE_VAL(&url->url_args); |
| url->url_reserved = NULL; |
| |
| AIT_FREE_VAL(&url->url_line); |
} |
} |
|
|
/* |
/* |