From 2449f8591261b207c091f9a44ce6cf40bdb71ab6 Mon Sep 17 00:00:00 2001 From: Federico Cabiddu Date: Tue, 17 May 2016 14:06:56 +0200 Subject: [PATCH] http_async_client: workaround for dealing with HTTP Via format in replies --- modules/http_async_client/async_http.c | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/modules/http_async_client/async_http.c b/modules/http_async_client/async_http.c index d1e9f6e3755..24dc8ba727e 100644 --- a/modules/http_async_client/async_http.c +++ b/modules/http_async_client/async_http.c @@ -94,6 +94,26 @@ int async_http_init_sockets(async_http_worker_t *worker) return 0; } +static inline char *strfindcasestrz(str *haystack, char *needlez) +{ + int i,j; + str needle; + + needle.s = needlez; + needle.len = strlen(needlez); + for(i=0;ilen-needle.len;i++) { + for(j=0;js[i+j]==needle.s[j]) || + ( isalpha((int)haystack->s[i+j]) + && ((haystack->s[i+j])^(needle.s[j]))==0x20 )) ) + break; + } + if (j==needle.len) + return haystack->s+i; + } + return 0; +} + void async_http_cb(struct http_m_reply *reply, void *param) { async_query_t *aq; @@ -101,6 +121,7 @@ void async_http_cb(struct http_m_reply *reply, void *param) unsigned int tindex; unsigned int tlabel; struct cell *t = NULL; + char *p; sip_msg_t *fmsg; if (reply->result != NULL) { @@ -119,6 +140,18 @@ void async_http_cb(struct http_m_reply *reply, void *param) ah_error.len = strlen(ah_error.s); } else { /* success */ + + /* check for HTTP Via header + * - HTTP Via format is different that SIP Via + * - workaround: replace with Hia to be ignored by SIP parser + */ + if((p=strfindcasestrz(reply->result, "\nVia:"))!=NULL) + { + p++; + *p = 'H'; + LM_DBG("replaced HTTP Via with Hia [[\n%.*s]]\n", reply->result->len, reply->result->s); + } + ah_reply->buf = reply->result->s; ah_reply->len = reply->result->len;