http_parse_query set both lengths of key and name

pull/2/head
yuqing 2014-08-11 16:23:27 +08:00
parent 8725ebd997
commit 93598b1862
4 changed files with 20 additions and 15 deletions

View File

@ -1,5 +1,5 @@
Version 1.06 2014-08-10
Version 1.06 2014-08-11
* update source code from FastDFS V5.02
* add function short2buff and buff2short
* add object memory pool (fast_mblock.h and fast_mblock.c)
@ -21,6 +21,7 @@ Version 1.06 2014-08-10
* replace INT64_PRINTF_FORMAT with PRId64
* support OS Darwin
* socket send and recv ignore erno EINTR
* http_parse_query set both lengths of key and name
Version 1.05 2012-07-08
* update source code from FastDFS V3.09

View File

@ -136,6 +136,8 @@ typedef struct
{
char *key;
char *value;
int key_len;
int value_len;
} KeyValuePair;
typedef struct

View File

@ -275,8 +275,8 @@ int http_parse_query(char *url, KeyValuePair *params, const int max_count)
KeyValuePair *pEnd;
char *pParamStart;
char *p;
char *pStrEnd;
int value_len;
char *pKeyEnd;
char *pValueEnd;
pParamStart = strchr(url, '?');
if (pParamStart == NULL)
@ -297,32 +297,34 @@ int http_parse_query(char *url, KeyValuePair *params, const int max_count)
}
pCurrent->key = p;
pStrEnd = strchr(p, '&');
if (pStrEnd == NULL)
pValueEnd = strchr(p, '&');
if (pValueEnd == NULL)
{
pValueEnd = p + strlen(p);
p = NULL;
}
else
{
*pStrEnd = '\0';
p = pStrEnd + 1;
*pValueEnd = '\0';
p = pValueEnd + 1;
}
pStrEnd = strchr(pCurrent->key, '=');
if (pStrEnd == NULL)
pKeyEnd = strchr(pCurrent->key, '=');
if (pKeyEnd == NULL) //no =
{
continue;
}
*pStrEnd = '\0';
pCurrent->value = pStrEnd + 1;
if (*pCurrent->key == '\0')
*pKeyEnd = '\0';
pCurrent->key_len = (int)(pKeyEnd - pCurrent->key);
if (pCurrent->key_len == 0) //empty key
{
continue;
}
urldecode(pCurrent->value, strlen(pCurrent->value), \
pCurrent->value, &value_len);
pCurrent->value = pKeyEnd + 1;
urldecode(pCurrent->value, (int)(pValueEnd - pCurrent->value),
pCurrent->value, &pCurrent->value_len);
pCurrent++;
}

View File

@ -57,7 +57,7 @@ int get_url_content(const char *url, const int connect_timeout, \
/**
parse url
params:
url: the url to parse
url: the url to parse, the url be modified after parse
params: params array to store param and it's value
max_count: max param count
return: param count