diff --git a/modules/utils/functions.c b/modules/utils/functions.c index e049056c373..42311509418 100644 --- a/modules/utils/functions.c +++ b/modules/utils/functions.c @@ -36,6 +36,7 @@ #include "../../pvar.h" #include "../../route_struct.h" #include "../../ut.h" +#include "../../trim.h" #include "../../mem/mem.h" #include "../../parser/msg_parser.h" #include "../../lvalue.h" @@ -43,6 +44,8 @@ #include "utils.h" +extern int http_response_trim; + /* * curl write function that saves received data as zero terminated * to stream. Returns the amount of data taken care of. @@ -86,6 +89,7 @@ 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; + str hres; memset(&stream, 0, sizeof(http_res_stream_t)); @@ -199,14 +203,20 @@ 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); + hres.s = stream.buf; + hres.len = download_size; + if(http_response_trim) { + trim(&hres); + } /* search for line feed */ - at = memchr(stream.buf, (char)10, download_size); + at = memchr(hres.s, (char)10, hres.len); if (at == NULL) { /* not found: use whole stream */ - at = stream.buf + (unsigned int)download_size; + val.rs = hres; + } else { + val.rs.s = hres.s; + val.rs.len = at - hres.s; } - val.rs.s = stream.buf; - val.rs.len = at - stream.buf; LM_DBG("http_query result: %.*s\n", val.rs.len, val.rs.s); val.flags = PV_VAL_STR; dst = (pv_spec_t *)_dst; diff --git a/modules/utils/utils.c b/modules/utils/utils.c index 8e4c1a21cc2..08334b6bf76 100644 --- a/modules/utils/utils.c +++ b/modules/utils/utils.c @@ -58,6 +58,7 @@ MODULE_VERSION /* Module parameter variables */ int http_query_timeout = 4; +int http_response_trim = 0; static int forward_active = 0; static int mp_max_id = 0; static char* mp_switch = ""; @@ -122,6 +123,7 @@ static param_export_t params[] = { {"pres_db_url", PARAM_STR, &pres_db_url}, {"xcap_table", PARAM_STR, &xcap_table}, {"http_query_timeout", INT_PARAM, &http_query_timeout}, + {"http_response_trim", INT_PARAM, &http_response_trim}, {"forward_active", INT_PARAM, &forward_active}, {0, 0, 0} };