]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix uri nonsense and backwards stristr
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 15 Nov 2007 16:22:18 +0000 (16:22 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 15 Nov 2007 16:22:18 +0000 (16:22 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6274 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_utils.h
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia_glue.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/switch_utils.c
src/switch_xml.cpp

index b60ef2171c1601b6958afb27446acc8ec83897ab..6949d1d3ae679ad85d329ad1e014462c9f075b88 100644 (file)
@@ -301,7 +301,7 @@ SWITCH_DECLARE(unsigned int) switch_separate_string(char *buf, char delim, char
 SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str);
 SWITCH_DECLARE(char *) switch_strip_spaces(const char *str);
 SWITCH_DECLARE(char *) switch_separate_paren_args(char *str);
-SWITCH_DECLARE(const char *) switch_stristr(const char *str, const char *instr);
+SWITCH_DECLARE(const char *) switch_stristr(const char *instr, const char *str);
 SWITCH_DECLARE(switch_bool_t) switch_is_lan_addr(const char *ip);
 SWITCH_DECLARE(char *) switch_replace_char(char *str, char from, char to, switch_bool_t dup);
 SWITCH_DECLARE(switch_bool_t) switch_ast2regex(char *pat, char *rbuf, size_t len);
index ef2c488c0d1372dd551554338521d59f1555ad5a..5f853e71538a2a3d658a3aa9adf4f212a54371c9 100644 (file)
@@ -1337,7 +1337,7 @@ SWITCH_STANDARD_APP(audio_bridge_function)
                   if the variable continue_on_fail is set it can be:
                   'true' to continue on all failures.
                   'false' to not continue.
-                  A list of codes either names or numbers eg "user_busy,normal_temporary_failure"
+                  A list of codes either names or numbers eg "user_busy,normal_temporary_failure,603"
                */
                if (continue_on_fail) {
                        const char *cause_str;
@@ -1346,7 +1346,7 @@ SWITCH_STANDARD_APP(audio_bridge_function)
                        cause_str = switch_channel_cause2str(cause);
                        snprintf(cause_num, sizeof(cause_num), "%u", cause);
 
-                       if (switch_true(continue_on_fail) || switch_stristr(cause_str, continue_on_fail) || strstr(cause_str, cause_num)) {
+                       if (switch_true(continue_on_fail) || switch_stristr(cause_str, continue_on_fail) || strstr(cause_num, continue_on_fail)) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Continue on fail [%s]:  Cause: %s\n", continue_on_fail, cause_str);
                                return;
                        }
index 00d4c0a2d4b216c22a7ebcf387352056662b2450..a0dd73a71735dd0daec38e4b3069b9e7f71e8954 100644 (file)
@@ -481,6 +481,7 @@ char *sofia_glue_get_url_from_contact(char *buf, uint8_t to_dup);
 void sofia_presence_set_hash_key(char *hash_key, int32_t len, sip_t const *sip);
 void sofia_glue_sql_close(sofia_profile_t *profile);
 int sofia_glue_init_sql(sofia_profile_t *profile);
+char *sofia_overcome_sip_uri_weakness(switch_core_session_t *session, const char *uri, const char *transport);
 switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
                                                                                          switch_bool_t master,
                                                                                          switch_mutex_t *mutex,
index 0bbb2cce477572296216735df716be19e87b6532..8b9070c869efb51192b93bdc79e158c510f01c69 100644 (file)
@@ -470,6 +470,34 @@ switch_status_t sofia_glue_tech_choose_video_port(private_object_t *tech_pvt)
        return SWITCH_STATUS_SUCCESS;
 }
 
+char *sofia_overcome_sip_uri_weakness(switch_core_session_t *session, const char *uri, const char *transport)
+{
+       char *stripped = switch_core_session_strdup(session, uri);
+       char *new_uri = NULL;
+
+       stripped = sofia_glue_get_url_from_contact(stripped, 0);
+       if (transport && strcasecmp(transport, "udp")) {
+               if (switch_stristr("port=", stripped)) {
+                       new_uri = switch_core_session_sprintf(session, "<%s>", stripped);
+               } else {
+                       if (strchr(stripped, ';')) {
+                               new_uri = switch_core_session_sprintf(session, "<%s&transport=%s>", stripped, transport);
+                       } else {
+                               new_uri = switch_core_session_sprintf(session, "<%s;transport=%s>", stripped, transport);
+                       }
+               }
+       } else {
+               char *p;
+               if ((p = strrchr(stripped, ';'))) {
+                       *p = '\0';
+               }
+               new_uri = stripped;
+       }
+
+       return new_uri;
+}
+
+
 switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
 {
        char *rpid = NULL;
@@ -562,7 +590,6 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
                sofia_private_t *sofia_private;
                char *invite_contact = NULL, *to_str, *use_from_str, *from_str, *url_str;
                const char *transport = "udp", *t_var;
-               char *d_contact = NULL;
 
                if (switch_strlen_zero(tech_pvt->dest)) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "URL Error! [%s]\n", tech_pvt->dest);
@@ -586,7 +613,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
                } else {
                        use_from_str = tech_pvt->from_str;
                }
-
+               
                if (switch_stristr("port=tcp", url)) {
                        transport = "tcp";
                } else {
@@ -595,33 +622,13 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
                                        transport = t_var;
                                }
                        }
-                       url_str = switch_core_session_sprintf(session, "%s;transport=%s", url, transport);
-               }
-               
-               d_contact = sofia_glue_get_url_from_contact(tech_pvt->invite_contact, 1);
-               
-               if (switch_stristr("port=", d_contact)) {
-                       invite_contact = switch_core_session_sprintf(session, "<%s>", d_contact);
-               } else {
-                       if (strchr(d_contact, ';')) {
-                               invite_contact = switch_core_session_sprintf(session, "<%s&transport=%s>", d_contact, transport);
-                       } else {
-                               invite_contact = switch_core_session_sprintf(session, "%s;transport=%s", d_contact, transport);
-                       }
-               }
-               
-               if (strchr(use_from_str, '>')) {
-                       from_str = switch_core_session_sprintf(session, "%s;transport=%s", use_from_str, transport);
-               } else {
-                       from_str = switch_core_session_sprintf(session, "<%s;transport=%s>", use_from_str, transport);
-               }
-
-               if (strchr(tech_pvt->dest_to, '>')) {
-                       to_str = switch_core_session_sprintf(session, "%s;transport=%s", tech_pvt->dest_to, transport);
-               } else {
-                       to_str = switch_core_session_sprintf(session, "<%s;transport=%s>", tech_pvt->dest_to, transport);
                }
 
+               url_str = sofia_overcome_sip_uri_weakness(session, url, transport);
+               invite_contact = sofia_overcome_sip_uri_weakness(session, tech_pvt->invite_contact, transport);
+               from_str = sofia_overcome_sip_uri_weakness(session, use_from_str, NULL);
+               to_str = sofia_overcome_sip_uri_weakness(session, tech_pvt->dest_to, NULL);
+               
                tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL,
                                                                  NUTAG_URL(url_str),
                                                                  SIPTAG_TO_STR(to_str),
@@ -630,7 +637,6 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
                                                                  TAG_END());
 
                switch_safe_free(d_url);
-               switch_safe_free(d_contact);
                
                if (!(sofia_private = malloc(sizeof(*sofia_private)))) {
                        abort();
index a974b981f60e5cbc4940d8ae9ba3e778c9c03ad4..fe3452cdfefe90877d56f1a739a6eb20ac0f9486 100644 (file)
@@ -155,7 +155,7 @@ char *sofia_presence_translate_rpid(char *in, char *ext)
 {
        char *r = in;
 
-       if (in && (switch_stristr(in, "null"))) {
+       if (in && (switch_stristr("null", in))) {
                in = NULL;
        }
        
index 64ccc5e1b3a9b9c1380bfc42a9e93a9879a746e5..b9069914151fd64d51637dcb62c7e3baaed1aa16 100644 (file)
@@ -334,7 +334,7 @@ SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str)
 }
 
 
-SWITCH_DECLARE(const char *) switch_stristr(const char *str, const char *instr)
+SWITCH_DECLARE(const char *) switch_stristr(const char *instr, const char *str)
 {
 /*
 ** Rev History:  16/07/97  Greg Thayer         Optimized
index eda39db479e5618de39045f31e1836e1414bee74..b7d186fcc6b599d042fdbc63b8f1e859ee0290d7 100644 (file)
@@ -1018,7 +1018,7 @@ static int preprocess(const char *cwd, const char *file, int write_fd, int rleve
                        }
                }
 
-               if ((tcmd = (char *)switch_stristr(bp, "<X-pre-process"))) {
+               if ((tcmd = (char *)switch_stristr("<X-pre-process", bp))) {
                        if ((e = strstr(tcmd, "/>"))) {
                                *e += 2;
                                *e = '\0';
@@ -1027,15 +1027,15 @@ static int preprocess(const char *cwd, const char *file, int write_fd, int rleve
                                }
                        }
                        
-                       if (!(tcmd = (char *)switch_stristr(tcmd, "cmd"))) {
+                       if (!(tcmd = (char *)switch_stristr("cmd", tcmd))) {
                                continue;
                        }
 
-                       if (!(tcmd = (char *)switch_stristr(tcmd, "="))) {
+                       if (!(tcmd = (char *)switch_stristr("=", tcmd))) {
                                continue;
                        }
 
-                       if (!(tcmd = (char *)switch_stristr(tcmd, "\""))) {
+                       if (!(tcmd = (char *)switch_stristr("\"", tcmd))) {
                                continue;
                        }
                        
@@ -1046,15 +1046,15 @@ static int preprocess(const char *cwd, const char *file, int write_fd, int rleve
                                *e++ = '\0';
                        }
 
-                       if (!(targ = (char *)switch_stristr(e, "data"))) {
+                       if (!(targ = (char *)switch_stristr("data", e))) {
                                continue;
                        }
 
-                       if (!(targ = (char *)switch_stristr(targ, "="))) {
+                       if (!(targ = (char *)switch_stristr("=", targ))) {
                                continue;
                        }
 
-                       if (!(targ = (char *)switch_stristr(targ, "\""))) {
+                       if (!(targ = (char *)switch_stristr("\"", targ))) {
                                continue;
                        }
 
@@ -1694,7 +1694,7 @@ SWITCH_DECLARE(void) switch_xml_free(switch_xml_t xml)
        }
 
        if (xml->free_path) {
-               if (!switch_stristr(xml->free_path, ".fsxml")) {
+               if (!switch_stristr(".fsxml", xml->free_path)) {
                        unlink(xml->free_path);
                }
                switch_safe_free(xml->free_path);