Module: kamailio
Branch: master
Commit: de925d64cb9348d693e2e77d6cb3db0d87e38734
URL:
https://github.com/kamailio/kamailio/commit/de925d64cb9348d693e2e77d6cb3db0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-09-17T22:23:38+02:00
utils: option to tream leading and trailing whitespaces
- new parameter http_response_trim to control it; default is 0 - don't
trimi (backward compatible); set to 1 for enabling trimming
- based on the request of PR GH#321
---
Modified: modules/utils/functions.c
Modified: modules/utils/utils.c
---
Diff:
https://github.com/kamailio/kamailio/commit/de925d64cb9348d693e2e77d6cb3db0…
Patch:
https://github.com/kamailio/kamailio/commit/de925d64cb9348d693e2e77d6cb3db0…
---
diff --git a/modules/utils/functions.c b/modules/utils/functions.c
index e049056..4231150 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 8e4c1a2..08334b6 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}
};