http_parse_query set both lengths of key and name
parent
8725ebd997
commit
93598b1862
3
HISTORY
3
HISTORY
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
Version 1.06 2014-08-10
|
Version 1.06 2014-08-11
|
||||||
* update source code from FastDFS V5.02
|
* update source code from FastDFS V5.02
|
||||||
* add function short2buff and buff2short
|
* add function short2buff and buff2short
|
||||||
* add object memory pool (fast_mblock.h and fast_mblock.c)
|
* 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
|
* replace INT64_PRINTF_FORMAT with PRId64
|
||||||
* support OS Darwin
|
* support OS Darwin
|
||||||
* socket send and recv ignore erno EINTR
|
* socket send and recv ignore erno EINTR
|
||||||
|
* http_parse_query set both lengths of key and name
|
||||||
|
|
||||||
Version 1.05 2012-07-08
|
Version 1.05 2012-07-08
|
||||||
* update source code from FastDFS V3.09
|
* update source code from FastDFS V3.09
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,8 @@ typedef struct
|
||||||
{
|
{
|
||||||
char *key;
|
char *key;
|
||||||
char *value;
|
char *value;
|
||||||
|
int key_len;
|
||||||
|
int value_len;
|
||||||
} KeyValuePair;
|
} KeyValuePair;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
|
||||||
|
|
@ -275,8 +275,8 @@ int http_parse_query(char *url, KeyValuePair *params, const int max_count)
|
||||||
KeyValuePair *pEnd;
|
KeyValuePair *pEnd;
|
||||||
char *pParamStart;
|
char *pParamStart;
|
||||||
char *p;
|
char *p;
|
||||||
char *pStrEnd;
|
char *pKeyEnd;
|
||||||
int value_len;
|
char *pValueEnd;
|
||||||
|
|
||||||
pParamStart = strchr(url, '?');
|
pParamStart = strchr(url, '?');
|
||||||
if (pParamStart == NULL)
|
if (pParamStart == NULL)
|
||||||
|
|
@ -297,32 +297,34 @@ int http_parse_query(char *url, KeyValuePair *params, const int max_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
pCurrent->key = p;
|
pCurrent->key = p;
|
||||||
pStrEnd = strchr(p, '&');
|
pValueEnd = strchr(p, '&');
|
||||||
if (pStrEnd == NULL)
|
if (pValueEnd == NULL)
|
||||||
{
|
{
|
||||||
|
pValueEnd = p + strlen(p);
|
||||||
p = NULL;
|
p = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*pStrEnd = '\0';
|
*pValueEnd = '\0';
|
||||||
p = pStrEnd + 1;
|
p = pValueEnd + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pStrEnd = strchr(pCurrent->key, '=');
|
pKeyEnd = strchr(pCurrent->key, '=');
|
||||||
if (pStrEnd == NULL)
|
if (pKeyEnd == NULL) //no =
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pStrEnd = '\0';
|
*pKeyEnd = '\0';
|
||||||
pCurrent->value = pStrEnd + 1;
|
pCurrent->key_len = (int)(pKeyEnd - pCurrent->key);
|
||||||
if (*pCurrent->key == '\0')
|
if (pCurrent->key_len == 0) //empty key
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
urldecode(pCurrent->value, strlen(pCurrent->value), \
|
pCurrent->value = pKeyEnd + 1;
|
||||||
pCurrent->value, &value_len);
|
urldecode(pCurrent->value, (int)(pValueEnd - pCurrent->value),
|
||||||
|
pCurrent->value, &pCurrent->value_len);
|
||||||
pCurrent++;
|
pCurrent++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ int get_url_content(const char *url, const int connect_timeout, \
|
||||||
/**
|
/**
|
||||||
parse url
|
parse url
|
||||||
params:
|
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
|
params: params array to store param and it's value
|
||||||
max_count: max param count
|
max_count: max param count
|
||||||
return: param count
|
return: param count
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue