Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utils module: http_request modification #321

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions modules/utils/functions.c
Expand Up @@ -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));

Expand Down Expand Up @@ -199,14 +201,21 @@ 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 */
at = memchr(stream.buf, (char)10, download_size);
/* search for line feed and remove initial empty lines*/
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;
Expand Down