From 770f9167b68d6260ce6ee24a392791c7cbc318c9 Mon Sep 17 00:00:00 2001 From: Laurent Debacker Date: Wed, 9 Sep 2015 08:27:36 +0200 Subject: [PATCH 1/2] Update functions.c Remove leading empty lines in http response, in order to return the first non-empty one. --- modules/utils/functions.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/utils/functions.c b/modules/utils/functions.c index e049056c373..707e6905b19 100644 --- a/modules/utils/functions.c +++ b/modules/utils/functions.c @@ -199,8 +199,13 @@ int http_query(struct sip_msg* _m, char* _url, char* _dst, char* _post, char* _h curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &download_size); LM_DBG("http_query download size: %u\n", (unsigned int)download_size); - /* search for line feed */ + /* search for line feed and remove initial empty lines*/ at = memchr(stream.buf, (char)10, download_size); + while (at == stream.buf) { + stream.buf += 1 ; + download_size -= 1 ; + at = memchr(stream.buf, (char)10, download_size); + } if (at == NULL) { /* not found: use whole stream */ at = stream.buf + (unsigned int)download_size; From 118ef4336ce0af71796ff19020ddcfdc9b2f0914 Mon Sep 17 00:00:00 2001 From: Laurent Debacker Date: Wed, 9 Sep 2015 09:38:23 +0200 Subject: [PATCH 2/2] Update: functions.c utils: http_query now ignores leading empty lines - http_query() ignore leading empty lines when parsing http response, to avoid returning an empty line. --- modules/utils/functions.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/utils/functions.c b/modules/utils/functions.c index 707e6905b19..d930b40ee45 100644 --- a/modules/utils/functions.c +++ b/modules/utils/functions.c @@ -86,6 +86,8 @@ int http_query(struct sip_msg* _m, char* _url, char* _dst, char* _post, char* _h pv_value_t val; double download_size; struct curl_slist *chunk = NULL; + double size; + char *head; memset(&stream, 0, sizeof(http_res_stream_t)); @@ -200,18 +202,20 @@ int http_query(struct sip_msg* _m, char* _url, char* _dst, char* _post, char* _h LM_DBG("http_query download size: %u\n", (unsigned int)download_size); /* search for line feed and remove initial empty lines*/ - at = memchr(stream.buf, (char)10, download_size); - while (at == stream.buf) { - stream.buf += 1 ; - download_size -= 1 ; - at = memchr(stream.buf, (char)10, download_size); + head = stream.buf; + size = download_size; + at = memchr(head, (char)10, size); + while (at == head) { + head += 1 ; + size -= 1 ; + at = memchr(head, (char)10, size); } if (at == NULL) { /* not found: use whole stream */ - at = stream.buf + (unsigned int)download_size; + at = head + (unsigned int)size; } - val.rs.s = stream.buf; - val.rs.len = at - stream.buf; + val.rs.s = head; + val.rs.len = at - head; LM_DBG("http_query result: %.*s\n", val.rs.len, val.rs.s); val.flags = PV_VAL_STR; dst = (pv_spec_t *)_dst;