diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 2ac5981c1e..77e676c26e 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -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 ) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 923230209b..1a8afe3b12 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -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, '@')) { diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index bd39146039..c42f7a83a8 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -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, diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 9f5e673a8c..cb709d12b8 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -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) { diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index c261b2bd42..0a65752bba 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -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; diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index d84d764efb..daacf9efa6 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -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"))) { diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 9190f9107f..c7e2a15163 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -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) { diff --git a/src/switch_utils.c b/src/switch_utils.c index 842977acf9..fa30b714a7 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -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: