]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add parsing of user params on invite
authorRaymond Chandler <intralanman@gmail.com>
Tue, 15 Apr 2014 16:47:48 +0000 (12:47 -0400)
committerRaymond Chandler <intralanman@gmail.com>
Tue, 15 Apr 2014 17:00:11 +0000 (13:00 -0400)
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c

index a48dc1921d0cdef228c7ef064eea6dd4ceb7e226..b8c5655e57f796b0b4faf94200ed42087286af7d 100644 (file)
@@ -572,6 +572,7 @@ typedef enum {
 
 struct sofia_profile {
        int debug;
+       int parse_invite_tel_params;
        char *name;
        char *domain_name;
        char *dbname;
index 8affc3b36691c1b486cde1d754bcfb903eb7d25b..f30f2962767f6b7628aaea292a25fbd8efc6d2c9 100644 (file)
@@ -3726,6 +3726,8 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
 
                                        if (!strcasecmp(var, "debug")) {
                                                profile->debug = atoi(val);
+                                       } else if (!strcasecmp(var, "parse-invite-tel-params")) {
+                                               profile->parse_invite_tel_params = switch_true(val);
                                        } else if (!strcasecmp(var, "shutdown-on-fail")) {
                                                profile->shutdown_type = switch_core_strdup(profile->pool, val);
                                        } else if (!strcasecmp(var, "sip-trace") && switch_true(val)) {
@@ -8292,10 +8294,39 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia
 
        if (sip->sip_request->rq_url) {
                const char *req_uri = url_set_chanvars(session, sip->sip_request->rq_url, sip_req);
+               char *user = NULL;
+               if (sip->sip_request->rq_url->url_user) {
+
+                       user = switch_core_session_strdup(session, sip->sip_request->rq_url->url_user);
+                       if (profile->parse_invite_tel_params) {
+                               if (strchr(user, ';')) {
+                                       int argc1, x1 = 0;
+                                       char *argv1[32] = { 0 };
+
+                                       if ((argc1 = switch_separate_string(user, ';', argv1, (sizeof(argv1) / sizeof(argv1[0]))))) {
+                                               for (x1 = 0; x1 < argc1; x1++) {
+                                                       if (x1 == 0) {
+                                                               switch_channel_set_variable(channel, "sip_req_user", argv1[0]);
+                                                       } else {
+                                                               int argc2 = 0;
+                                                               char *argv2[2] = { 0 };
+                                                               if ((argc2 = switch_separate_string(argv1[x1], '=', argv2, (sizeof(argv2) / sizeof(argv2[0]))))) {
+                                                                       char *var_name = NULL;
+                                                                       var_name = switch_mprintf("sip_invite_%s", argv2[0]);
+                                                                       switch_channel_set_variable(channel, var_name, argv2[1]);
+                                                                       switch_safe_free( var_name );
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+
                if (sofia_test_pflag(profile, PFLAG_FULL_ID)) {
                        destination_number = req_uri;
                } else {
-                       destination_number = sip->sip_request->rq_url->url_user;
+                       destination_number = user;
                }
                if (sip->sip_request->rq_url->url_params && (sofia_glue_find_parameter(sip->sip_request->rq_url->url_params, "intercom=true"))) {
                        switch_channel_set_variable(channel, "sip_auto_answer_detected", "true");