From 98fefef56b775e11c5fba67edbac958c8a7cb3b4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 28 Sep 2008 21:36:39 +0000 Subject: [PATCH] append -1 .. -N postfix after any X-headers as vars that have the same name git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9703 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/sofia.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 489162ff08..48f3585a37 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -3836,10 +3836,22 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ } } else if (!strncasecmp(un->un_name, "X-", 2) || !strncasecmp(un->un_name, "P-", 2)) { if (!switch_strlen_zero(un->un_value)) { - char *new_name; - if ((new_name = switch_mprintf("%s%s", SOFIA_SIP_HEADER_PREFIX, un->un_name))) { + char new_name[512] = ""; + int reps = 0; + for(;;) { + char postfix[25] = ""; + if (reps > 0) { + switch_snprintf(postfix, sizeof(postfix), "-%d", reps); + } + reps++; + switch_snprintf(new_name, sizeof(new_name), "%s%s%s", SOFIA_SIP_HEADER_PREFIX, un->un_name, postfix); + + if (switch_channel_get_variable(channel, new_name)) { + continue; + } + switch_channel_set_variable(channel, new_name, un->un_value); - free(new_name); + break; } } }