add function http_parse_url_params

pull/10/head
yuqing 2016-06-06 20:49:34 +08:00
parent a6d00af752
commit 372a02d9d4
3 changed files with 37 additions and 15 deletions

View File

@ -1,9 +1,10 @@
Version 1.28 2016-05-19
Version 1.28 2016-06-06
* id generator support extra bits
* change inet_aton to inet_pton
* connect by ip and connection pool support ipv6
* id generator in php extension support multi instance
* add function http_parse_url_params
Version 1.27 2016-04-15
* add function fd_set_cloexec

View File

@ -339,30 +339,20 @@ int http_parse_query(char *url, KeyValuePair *params, const int max_count)
return pCurrent - params;
}
int http_parse_query_ex(char *url, const int url_len,
int *uri_len, KeyValuePairEx *params, const int max_count)
int http_parse_url_params(char *param_str, const int param_len,
KeyValuePairEx *params, const int max_count)
{
KeyValuePairEx *pCurrent;
KeyValuePairEx *pEnd;
char *pParamStart;
char *p;
char *pStrEnd;
char *pKeyEnd;
char *pValueEnd;
pParamStart = (char *)memchr(url, '?', url_len);
if (pParamStart == NULL)
{
*uri_len = url_len;
return 0;
}
*uri_len = pParamStart - url;
pStrEnd = url + url_len;
pStrEnd = param_str + param_len;
pEnd = params + max_count;
pCurrent = params;
p = pParamStart + 1;
p = param_str;
while (p < pStrEnd)
{
if (pCurrent >= pEnd)
@ -405,3 +395,22 @@ int http_parse_query_ex(char *url, const int url_len,
return pCurrent - params;
}
int http_parse_query_ex(char *url, const int url_len,
int *uri_len, KeyValuePairEx *params, const int max_count)
{
char *pParamStart;
int param_len;
pParamStart = (char *)memchr(url, '?', url_len);
if (pParamStart == NULL)
{
*uri_len = url_len;
return 0;
}
*uri_len = pParamStart - url;
param_len = url_len - (*uri_len + 1);
return http_parse_url_params(pParamStart + 1, param_len,
params, max_count);
}

View File

@ -77,6 +77,18 @@ return: param count
int http_parse_query_ex(char *url, const int url_len,
int *uri_len, KeyValuePairEx *params, const int max_count);
/**
parse url params
params:
param_str: the url params to parse, the params be modified after parse
param_len: the length of url params
params: params array to store param and it's value
max_count: max param count
return: param count
**/
int http_parse_url_params(char *param_str, const int param_len,
KeyValuePairEx *params, const int max_count);
#ifdef __cplusplus
}
#endif