From 52909f3faa9628b098913ac6a09de11d18d0313f Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Sat, 21 Apr 2007 18:56:49 +0000 Subject: [PATCH] - Hack to deal with Asterisks broken Alert-Info headers (Asterisk does include Alert-Info header without '<>') --- ChangeLog | 2 ++ src/sip_utils.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- src/siproxd.c | 5 +++++ src/siproxd.h | 1 + 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 961160d..cddda7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 0.6.0 ===== + 21-Apr-2007: - Hack to deal with Asterisks broken Alert-Info headers + (Asterisk does include Alert-Info header without '<>') 19-Feb-2007: - Increased RTP buffer size 13-Oct-2006: - Various fixes due to a code review by Andrew Jones 05-Oct-2006: - route_determine_nexthop(): don't remove header diff --git a/src/sip_utils.c b/src/sip_utils.c index 8627780..43b3887 100644 --- a/src/sip_utils.c +++ b/src/sip_utils.c @@ -1097,6 +1097,51 @@ int sip_find_direction(sip_ticket_t *ticket, int *urlidx) { } - +/* + * SIP_FIXUP_ALERT_INFO + * + * Asterisk Hack. + * Asterisk seems to include broken Alert-Info headers (without <>) + * that cause parsing to fail (libosip2). + * This function does try to guess if we have such a broken SIP + * message and does simply remove the offending Alert-Info header. + * + * RETURNS + * STS_SUCCESS on success + */ +int sip_fixup_asterisk(char *buff, int *buflen) { + char *alert_info_ptr=NULL; + /* + * Check for Asterisk UA string + * User-Agent: Asterisk PBX + */ + if (strstr(buff, "\r\nUser-Agent: Asterisk PBX\r\n")==NULL) + return STS_SUCCESS; + + DEBUGC(DBCLASS_SIP, "sip_fixup_alert_info: SIP message is from Asterisk"); + /* + * Look form Alert-Info: header + */ + alert_info_ptr=strstr(buff, "\r\nAlert-Info: "); + if (alert_info_ptr) { + char *eol_ptr=NULL; + DEBUGC(DBCLASS_SIP, "sip_fixup_alert_info: Asterisk message " + "with Alert-Info found"); + eol_ptr=strstr((alert_info_ptr+2), "\r\n"); + if (eol_ptr) { + int i; + // cut the Alert-Info header from the message + // (actually move the rest of the message up) + DEBUGC(DBCLASS_SIP, "sip_fixup_alert_info: removed malformed " + "Alert-Info header"); + for (i=0; i<(*buflen - (eol_ptr - buff)); i++) { + alert_info_ptr[i]=eol_ptr[i]; + } /* for */ + + *buflen=strlen(buff); + } /* if */ + } + return STS_SUCCESS; +} diff --git a/src/siproxd.c b/src/siproxd.c index 3b1cd06..0efb122 100644 --- a/src/siproxd.c +++ b/src/siproxd.c @@ -318,6 +318,11 @@ int main (int argc, char *argv[]) continue; /* there are no resources to free */ } + /* + * Hacks to fix-up some broken headers + */ + sts=sip_fixup_asterisk(buff, &buflen); + /* * init sip_msg */ diff --git a/src/siproxd.h b/src/siproxd.h index 26552d0..84e6576 100644 --- a/src/siproxd.h +++ b/src/siproxd.h @@ -175,6 +175,7 @@ int sip_calculate_branch_id (sip_ticket_t *ticket, char *id); /*X*/ int sip_find_outbound_proxy(sip_ticket_t *ticket, struct in_addr *addr, int *port); /*X*/ int sip_find_direction(sip_ticket_t *ticket, int *urlidx); /*X*/ +int sip_fixup_asterisk(char *buff, int *buflen); /*X*/ /* readconf.c */ int read_config(char *name, int search); /*X*/