diff --git a/HISTORY b/HISTORY index e4ed46d..16bac36 100644 --- a/HISTORY +++ b/HISTORY @@ -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 diff --git a/src/http_func.c b/src/http_func.c index 5ea4934..721a562 100644 --- a/src/http_func.c +++ b/src/http_func.c @@ -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); +} + diff --git a/src/http_func.h b/src/http_func.h index ae20b09..8625a3a 100644 --- a/src/http_func.h +++ b/src/http_func.h @@ -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