Explorar o código

utils: new parameter http_response_mode to control what response part is returned

- if http_response_mode=0, only the first line is returned (like so far)
- if http_response_mode=1, all the response is returned
- default 0
Daniel-Constantin Mierla %!s(int64=10) %!d(string=hai) anos
pai
achega
7e866d62c5
Modificáronse 2 ficheiros con 12 adicións e 8 borrados
  1. 10 8
      modules/utils/functions.c
  2. 2 0
      modules/utils/utils.c

+ 10 - 8
modules/utils/functions.c

@@ -45,6 +45,7 @@
 
 
 extern int http_response_trim;
+extern int http_response_mode;
 
 /* 
  * curl write function that saves received data as zero terminated
@@ -208,14 +209,15 @@ int http_query(struct sip_msg* _m, char* _url, char* _dst, char* _post, char* _h
 		if(http_response_trim) {
 			trim(&hres);
 		}
-		/* search for line feed */
-		at = memchr(hres.s, (char)10, hres.len);
-		if (at == NULL) {
-			/* not found: use whole stream */
-			val.rs = hres;
-		} else {
-			val.rs.s = hres.s;
-			val.rs.len = at - hres.s;
+		val.rs = hres;
+		if(http_response_mode==0) {
+			/* only first line - search for line feed */
+			at = memchr(hres.s, (char)10, hres.len);
+			if (at != NULL) {
+				/* found: use first line */
+				val.rs.s = hres.s;
+				val.rs.len = at - hres.s;
+			}
 		}
 		LM_DBG("http_query result: %.*s\n", val.rs.len, val.rs.s);
 		val.flags = PV_VAL_STR;

+ 2 - 0
modules/utils/utils.c

@@ -59,6 +59,7 @@ MODULE_VERSION
 /* Module parameter variables */
 int http_query_timeout = 4;
 int http_response_trim = 0;
+int http_response_mode = 0;
 static int forward_active = 0;
 static int   mp_max_id = 0;
 static char* mp_switch = "";
@@ -124,6 +125,7 @@ static param_export_t params[] = {
     {"xcap_table", PARAM_STR, &xcap_table},
     {"http_query_timeout", INT_PARAM, &http_query_timeout},
     {"http_response_trim", INT_PARAM, &http_response_trim},
+    {"http_response_mode", INT_PARAM, &http_response_mode},
     {"forward_active", INT_PARAM, &forward_active},
     {0, 0, 0}
 };