From 827f655dac2bc438e3fae3b1573324b8a503e024 Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Tue, 23 Dec 2008 20:56:10 +0000 Subject: [PATCH] Merged revisions 166696 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ........ r166696 | tilghman | 2008-12-23 14:47:08 -0600 (Tue, 23 Dec 2008) | 7 lines Allow semicolons and extended characters in user-specified SIP headers. (closes issue #14110) Reported by: gork Patches: 20081222__bug14110__2.diff.txt uploaded by Corydon76 (license 14) Tested by: gork, putnopvut ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@166698 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_sip.c | 13 +++++++++---- include/asterisk/app.h | 3 +++ main/app.c | 13 +++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 3f5ca017d0..a960f9612c 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -22682,7 +22682,7 @@ static int sip_addheader(struct ast_channel *chan, void *data) int no = 0; int ok = FALSE; char varbuf[30]; - char *inbuf = data; + char *inbuf = data, *subbuf; if (ast_strlen_zero(inbuf)) { ast_log(LOG_WARNING, "This application requires the argument: Header\n"); @@ -22696,13 +22696,18 @@ static int sip_addheader(struct ast_channel *chan, void *data) snprintf(varbuf, sizeof(varbuf), "__SIPADDHEADER%.2d", no); /* Compare without the leading underscores */ - if( (pbx_builtin_getvar_helper(chan, (const char *) varbuf + 2) == (const char *) NULL) ) + if ((pbx_builtin_getvar_helper(chan, (const char *) varbuf + 2) == (const char *) NULL)) { ok = TRUE; + } } if (ok) { - pbx_builtin_setvar_helper (chan, varbuf, inbuf); - if (sipdebug) + size_t len = strlen(inbuf); + subbuf = alloca(len + 1); + ast_get_encoded_str(inbuf, subbuf, len + 1); + pbx_builtin_setvar_helper(chan, varbuf, subbuf); + if (sipdebug) { ast_debug(1, "SIP Header added \"%s\" as %s\n", inbuf, varbuf); + } } else { ast_log(LOG_WARNING, "Too many SIP headers added, max 50\n"); } diff --git a/include/asterisk/app.h b/include/asterisk/app.h index 4d1bcc3ae4..1e8e09cb71 100644 --- a/include/asterisk/app.h +++ b/include/asterisk/app.h @@ -488,6 +488,9 @@ int ast_record_review(struct ast_channel *chan, const char *playfile, const char /*! \brief Decode an encoded control or extended ASCII character */ int ast_get_encoded_char(const char *stream, char *result, size_t *consumed); +/*! \brief Decode a string which may contain multiple encoded control or extended ASCII characters */ +int ast_get_encoded_str(const char *stream, char *result, size_t result_size); + /*! \brief Common routine for child processes, to close all fds prior to exec(2) */ void ast_close_fds_above_n(int n); diff --git a/main/app.c b/main/app.c index 414c6c18d4..aecbffaf22 100644 --- a/main/app.c +++ b/main/app.c @@ -1820,6 +1820,19 @@ int ast_get_encoded_char(const char *stream, char *result, size_t *consumed) return 0; } +int ast_get_encoded_str(const char *stream, char *result, size_t result_size) +{ + char *cur = result; + size_t consumed; + + while (cur < result + result_size - 1 && !ast_get_encoded_char(stream, cur, &consumed)) { + cur++; + stream += consumed; + } + *cur = '\0'; + return 0; +} + void ast_close_fds_above_n(int n) { int x, null;