Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 166508) +++ channels/chan_sip.c (working copy) @@ -22008,7 +22008,7 @@ 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"); @@ -22022,13 +22022,18 @@ 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"); } Index: include/asterisk/app.h =================================================================== --- include/asterisk/app.h (revision 166508) +++ include/asterisk/app.h (working copy) @@ -480,6 +480,9 @@ /*! \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); + #if defined(__cplusplus) || defined(c_plusplus) } #endif Index: main/app.c =================================================================== --- main/app.c (revision 166508) +++ main/app.c (working copy) @@ -1775,3 +1775,16 @@ 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; +} +