]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Rename sofia_glue_get_user_host to switch_split_user_domain
authorMathieu Parent <math.parent@gmail.com>
Tue, 1 Jun 2010 23:09:54 +0000 (01:09 +0200)
committerMathieu Parent <math.parent@gmail.com>
Tue, 1 Jun 2010 23:09:54 +0000 (01:09 +0200)
and move to switch_utils. To allow use by other modules.

src/include/switch_utils.h
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/mod/endpoints/mod_sofia/sofia_reg.c
src/switch_utils.c

index 2ac5981c1e3f913d0b394c46fbe571e9150c5644..77e676c26e014e9148b3d3affcb41b12d19fef75 100644 (file)
@@ -640,6 +640,16 @@ SWITCH_DECLARE(int) switch_inet_pton(int af, const char *src, void *dst);
 
 SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val);
 
+/*!
+  \brief Split a user@domain string as user and domain
+  \param in the input string
+  \param user the string to put the user into
+  \param domain the string to put the domain into
+  \return 1 if successfull
+  \note Extended formats protocol:user@domain:port (Example: sip:toto@example.org)
+*/
+int switch_split_user_domain(char *in, char **user, char **domain);
+
 /* malloc or DIE macros */
 #ifdef NDEBUG
 #define switch_malloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr )
index 923230209bcab3bb36760bbcdc8417e6f9d7ee56..1a8afe3b12b0d4bf8ea1e34b00240899b0b8af7d 100644 (file)
@@ -3750,7 +3750,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
        switch_channel_set_variable_printf(nchannel, "sip_local_network_addr", "%s", profile->extsipip ? profile->extsipip : profile->sipip);
        switch_channel_set_variable(nchannel, "sip_profile_name", profile_name);
 
-       sofia_glue_get_user_host(switch_core_session_strdup(nsession, tech_pvt->dest), NULL, &tech_pvt->remote_ip);
+       switch_split_user_domain(switch_core_session_strdup(nsession, tech_pvt->dest), NULL, &tech_pvt->remote_ip);
 
        if (dest_to) {
                if (strchr(dest_to, '@')) {
index bd39146039db7ee83fc6cedb5c86f0cd658a8b24..c42f7a83a826ce67bb6d3c2d79d2ad70ff1bb26d 100644 (file)
@@ -824,7 +824,6 @@ switch_status_t sofia_glue_ext_address_lookup(sofia_profile_t *profile, private_
                                                                                          const char *sourceip, switch_memory_pool_t *pool);
 
 void sofia_glue_pass_sdp(private_object_t *tech_pvt, char *sdp);
-int sofia_glue_get_user_host(char *in, char **user, char **host);
 switch_call_cause_t sofia_glue_sip_cause_to_freeswitch(int status);
 void sofia_glue_do_xfer_invite(switch_core_session_t *session);
 uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip,
index 9f5e673a8c1a7ee8a10aaaf9ecd103efa15dbcca..cb709d12b889de508febf32601380f155205646e 100644 (file)
@@ -1038,7 +1038,7 @@ void event_handler(switch_event_t *event)
                if ((mwi_account = switch_event_get_header_nil(event, "orig-mwi-account"))) {
                        dup_mwi_account = strdup(mwi_account);
                        switch_assert(dup_mwi_account != NULL);
-                       sofia_glue_get_user_host(dup_mwi_account, &mwi_user, &mwi_host);
+                       switch_split_user_domain(dup_mwi_account, &mwi_user, &mwi_host);
                }
 
                if (!mwi_user) {
index c261b2bd425305e91ac19d854a395e722eb6f97d..0a65752bba778ba66f275d10ab4689d31f1d71c4 100644 (file)
@@ -5252,49 +5252,6 @@ char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex
        return ret;
 }
 
-int sofia_glue_get_user_host(char *in, char **user, char **host)
-{
-       char *p = NULL, *h = NULL, *u = in;
-
-       if (!in) {
-               return 0;
-       }
-
-       /* First isolate the host part from the user part */
-       if ((h = strchr(u, '@'))) {
-               *h++ = '\0';
-       }
-
-       /* Clean out the user part of its protocol prefix (if any) */
-       if ((p = strchr(u, ':'))) {
-               *p++ = '\0';
-               u = p;
-       }
-
-       /* Clean out the host part of any suffix */
-       if (h) {
-               if ((p = strchr(h, ':'))) {
-                       *p = '\0';
-               }
-
-               if ((p = strchr(h, ';'))) {
-                       *p = '\0';
-               }
-
-               if ((p = strchr(h, ' '))) {
-                       *p = '\0';
-               }
-       }
-       if (user) {
-               *user = u;
-       }
-       if (host) {
-               *host = h;
-       }
-
-       return 1;
-}
-
 const char *sofia_glue_strip_proto(const char *uri)
 {
        char *p;
index d84d764efb987cdd5dabe6c683a53ba399eee4b7..daacf9efa662393707b2ec6b63af4c21e523b4a8 100644 (file)
@@ -304,7 +304,7 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
 
        dup_account = strdup(account);
        switch_assert(dup_account != NULL);
-       sofia_glue_get_user_host(dup_account, &user, &host);
+       switch_split_user_domain(dup_account, &user, &host);
 
 
        if ((pname = switch_event_get_header(event, "sofia-profile"))) {
index 9190f9107f8e1096a3fdf2c23fc72ea1fb7c9a03..c7e2a15163e58b9398aeb1bb8d08f1597cbdab82 100644 (file)
@@ -1071,7 +1071,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
        if (v_event && *v_event && (mwi_account = switch_event_get_header(*v_event, "mwi-account"))) {
                dup_mwi_account = strdup(mwi_account);
                switch_assert(dup_mwi_account != NULL);
-               sofia_glue_get_user_host(dup_mwi_account, &mwi_user, &mwi_host);
+               switch_split_user_domain(dup_mwi_account, &mwi_user, &mwi_host);
        }
 
        if (!mwi_user) {
index 842977acf988448ee89249a4a320c028e97cd475..fa30b714a7a7439a031dbe7e36115af9926336d7 100644 (file)
@@ -2349,6 +2349,49 @@ SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val)
 
 }
 
+int switch_split_user_domain(char *in, char **user, char **domain)
+{
+       char *p = NULL, *h = NULL, *u = in;
+
+       if (!in) {
+               return 0;
+       }
+
+       /* First isolate the host part from the user part */
+       if ((h = strchr(u, '@'))) {
+               *h++ = '\0';
+       }
+
+       /* Clean out the user part of its protocol prefix (if any) */
+       if ((p = strchr(u, ':'))) {
+               *p++ = '\0';
+               u = p;
+       }
+
+       /* Clean out the host part of any suffix */
+       if (h) {
+               if ((p = strchr(h, ':'))) {
+                       *p = '\0';
+               }
+
+               if ((p = strchr(h, ';'))) {
+                       *p = '\0';
+               }
+
+               if ((p = strchr(h, ' '))) {
+                       *p = '\0';
+               }
+       }
+       if (user) {
+               *user = u;
+       }
+       if (domain) {
+               *domain = h;
+       }
+
+       return 1;
+}
+
 
 /* For Emacs:
  * Local Variables: