Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 38021) +++ channels/chan_sip.c (working copy) @@ -10876,9 +10876,14 @@ static int func_header_read(struct ast_channel *chan, char *function, char *data, char *buf, size_t len) { struct sip_pvt *p; - const char *content; - - if (!data) { + const char *content = NULL; + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(header); + AST_APP_ARG(number); + ); + int i, number, start = 0; + + if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "This function requires a header name.\n"); return -1; } @@ -10890,6 +10895,11 @@ return -1; } + AST_STANDARD_APP_ARGS(args, data); + sscanf(args.number, "%d", &number); + if (number < 1) + number = 1; + p = chan->tech_pvt; /* If there is no private structure, this channel is no longer alive */ @@ -10898,7 +10908,8 @@ return -1; } - content = get_header(&p->initreq, data); + for (i = 0; i < number; i++) + content = __get_header(&p->initreq, args.header, &start); if (ast_strlen_zero(content)) { ast_channel_unlock(chan); @@ -10914,7 +10925,11 @@ static struct ast_custom_function sip_header_function = { .name = "SIP_HEADER", .synopsis = "Gets or sets the specified SIP header", - .syntax = "SIP_HEADER()", + .syntax = "SIP_HEADER([,])", + .desc = +"Since there are several headers (such as Via) which can occur multiple\n" +"times, SIP_HEADER takes an optional second argument to specify which\n" +"header with that name to retrieve. Headers start at offset 1.\n", .read = func_header_read, };