mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-16 00:41:41 +00:00
retool the sofia outbound registration syntax and dialstring syntax for said registrations ***ATTENTION*** syntax has heavily changed and the former syntax removed completely
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4669 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
52edc31e90
commit
31656e019d
@ -1,18 +1,23 @@
|
|||||||
<configuration name="sofia.conf" description="sofia Endpoint">
|
<configuration name="sofia.conf" description="sofia Endpoint">
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile name="$${domain}">
|
<profile name="$${domain}">
|
||||||
<registrations>
|
<!-- Outbound Registrations -->
|
||||||
<!-- <registration name="asterlink">
|
<gateways>
|
||||||
<param name="register-scheme" value="Digest"/>
|
<gateway name="asterlink.com">
|
||||||
<param name="register-realm" value=""/>
|
<!--/// account username *required* ///-->
|
||||||
<param name="register-username" value="1001"/>
|
<param name="username" value="cluecon"/>
|
||||||
<param name="register-password" value="nhy65tgb"/>
|
<!--/// auth realm: *optional* same as gateway name, if blank ///-->
|
||||||
<param name="register-from" value="sip:1001@208.64.200.40"/>
|
<!--<param name="realm" value="asterlink.com"/>-->
|
||||||
<param name="register-to" value="sip:1001@conference.freeswitch.org"/>
|
<!--/// account password *required* ///-->
|
||||||
<param name="register-proxy" value="sip:conference.freeswitch.org:5060"/>
|
<param name="password" value="2007"/>
|
||||||
<param name="register-frequency" value="20"/>
|
<!--/// extension for inbound calls: *optional* same as username, if blank ///-->
|
||||||
</registration> -->
|
<!--<param name="extension" value="cluecon"/>-->
|
||||||
</registrations>
|
<!--/// proxy host: *optional* same as realm, if blank ///-->
|
||||||
|
<!--<param name="proxy" value="asterlink.com"/>-->
|
||||||
|
<!--/// expire in seconds: *optional* 3600, if blank ///-->
|
||||||
|
<param name="expire-seconds" value="60"/>
|
||||||
|
</gateway>
|
||||||
|
</gateways>
|
||||||
<settings>
|
<settings>
|
||||||
<param name="debug" value="1"/>
|
<param name="debug" value="1"/>
|
||||||
<param name="rfc2833-pt" value="101"/>
|
<param name="rfc2833-pt" value="101"/>
|
||||||
|
@ -51,7 +51,7 @@ typedef struct sofia_profile sofia_profile_t;
|
|||||||
|
|
||||||
struct sofia_private {
|
struct sofia_private {
|
||||||
char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
|
char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
|
||||||
outbound_reg_t *oreg;
|
outbound_reg_t *gateway;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct sofia_private sofia_private_t;
|
typedef struct sofia_private sofia_private_t;
|
||||||
@ -68,6 +68,7 @@ typedef struct private_object private_object_t;
|
|||||||
#define SOFIA_CHAT_PROTO "sip"
|
#define SOFIA_CHAT_PROTO "sip"
|
||||||
#define SOFIA_SIP_HEADER_PREFIX "sip_h_"
|
#define SOFIA_SIP_HEADER_PREFIX "sip_h_"
|
||||||
#define SOFIA_SIP_HEADER_PREFIX_T "~sip_h_"
|
#define SOFIA_SIP_HEADER_PREFIX_T "~sip_h_"
|
||||||
|
#define SOFIA_DEFAULT_PORT "5060"
|
||||||
|
|
||||||
#include <sofia-sip/nua.h>
|
#include <sofia-sip/nua.h>
|
||||||
#include <sofia-sip/sip_status.h>
|
#include <sofia-sip/sip_status.h>
|
||||||
@ -180,6 +181,7 @@ typedef enum {
|
|||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
switch_hash_t *profile_hash;
|
switch_hash_t *profile_hash;
|
||||||
|
switch_hash_t *gateway_hash;
|
||||||
switch_mutex_t *hash_mutex;
|
switch_mutex_t *hash_mutex;
|
||||||
uint32_t callid;
|
uint32_t callid;
|
||||||
int32_t running;
|
int32_t running;
|
||||||
@ -210,6 +212,7 @@ struct outbound_reg {
|
|||||||
char *register_username;
|
char *register_username;
|
||||||
char *register_password;
|
char *register_password;
|
||||||
char *register_from;
|
char *register_from;
|
||||||
|
char *register_contact;
|
||||||
char *register_to;
|
char *register_to;
|
||||||
char *register_proxy;
|
char *register_proxy;
|
||||||
char *expires_str;
|
char *expires_str;
|
||||||
@ -255,8 +258,8 @@ struct sofia_profile {
|
|||||||
switch_payload_t cng_pt;
|
switch_payload_t cng_pt;
|
||||||
uint32_t codec_flags;
|
uint32_t codec_flags;
|
||||||
switch_mutex_t *ireg_mutex;
|
switch_mutex_t *ireg_mutex;
|
||||||
switch_mutex_t *oreg_mutex;
|
switch_mutex_t *gateway_mutex;
|
||||||
outbound_reg_t *registrations;
|
outbound_reg_t *gateways;
|
||||||
su_home_t *home;
|
su_home_t *home;
|
||||||
switch_hash_t *profile_hash;
|
switch_hash_t *profile_hash;
|
||||||
switch_hash_t *chat_hash;
|
switch_hash_t *chat_hash;
|
||||||
@ -441,6 +444,42 @@ typedef enum {
|
|||||||
} auth_res_t;
|
} auth_res_t;
|
||||||
|
|
||||||
|
|
||||||
|
static sofia_profile_t *find_profile(char *key)
|
||||||
|
{
|
||||||
|
static sofia_profile_t *profile;
|
||||||
|
|
||||||
|
switch_mutex_lock(globals.hash_mutex);
|
||||||
|
profile = (sofia_profile_t *) switch_core_hash_find(globals.profile_hash, key);
|
||||||
|
switch_mutex_unlock(globals.hash_mutex);
|
||||||
|
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add_profile(char *key, sofia_profile_t *profile)
|
||||||
|
{
|
||||||
|
switch_mutex_lock(globals.hash_mutex);
|
||||||
|
switch_core_hash_insert(globals.profile_hash, key, profile);
|
||||||
|
switch_mutex_unlock(globals.hash_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static outbound_reg_t *find_gateway(char *key)
|
||||||
|
{
|
||||||
|
outbound_reg_t *gateway;
|
||||||
|
|
||||||
|
switch_mutex_lock(globals.hash_mutex);
|
||||||
|
gateway = (outbound_reg_t *) switch_core_hash_find(globals.gateway_hash, key);
|
||||||
|
switch_mutex_unlock(globals.hash_mutex);
|
||||||
|
|
||||||
|
return gateway;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add_gateway(char *key, outbound_reg_t *gateway)
|
||||||
|
{
|
||||||
|
switch_mutex_lock(globals.hash_mutex);
|
||||||
|
switch_core_hash_insert(globals.gateway_hash, key, gateway);
|
||||||
|
switch_mutex_unlock(globals.hash_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
static char *get_url_from_contact(char *buf, uint8_t to_dup)
|
static char *get_url_from_contact(char *buf, uint8_t to_dup)
|
||||||
{
|
{
|
||||||
char *url = NULL, *e;
|
char *url = NULL, *e;
|
||||||
@ -804,7 +843,6 @@ static void tech_set_codecs(private_object_t *tech_pvt)
|
|||||||
{
|
{
|
||||||
switch_channel_t *channel;
|
switch_channel_t *channel;
|
||||||
char *abs, *codec_string = NULL;
|
char *abs, *codec_string = NULL;
|
||||||
char *csdyn = NULL;
|
|
||||||
char *ocodec = NULL;
|
char *ocodec = NULL;
|
||||||
|
|
||||||
if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
|
if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
|
||||||
@ -834,9 +872,7 @@ static void tech_set_codecs(private_object_t *tech_pvt)
|
|||||||
if (!codec_string || (tech_pvt->profile->pflags & PFLAG_DISABLE_TRANSCODING)) {
|
if (!codec_string || (tech_pvt->profile->pflags & PFLAG_DISABLE_TRANSCODING)) {
|
||||||
codec_string = ocodec;
|
codec_string = ocodec;
|
||||||
} else {
|
} else {
|
||||||
if ((csdyn = switch_mprintf("%s,%s", ocodec, codec_string))) {
|
if (!(codec_string = switch_core_session_sprintf(tech_pvt->session, "%s,%s", ocodec, codec_string))) {
|
||||||
codec_string = csdyn;
|
|
||||||
} else {
|
|
||||||
codec_string = ocodec;
|
codec_string = ocodec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -845,20 +881,18 @@ static void tech_set_codecs(private_object_t *tech_pvt)
|
|||||||
|
|
||||||
if (codec_string) {
|
if (codec_string) {
|
||||||
char *tmp_codec_string;
|
char *tmp_codec_string;
|
||||||
if ((tmp_codec_string = strdup(codec_string))) {
|
if ((tmp_codec_string = switch_core_session_strdup(tech_pvt->session, codec_string))) {
|
||||||
tech_pvt->codec_order_last = switch_separate_string(tmp_codec_string, ',', tech_pvt->codec_order, SWITCH_MAX_CODECS);
|
tech_pvt->codec_order_last = switch_separate_string(tmp_codec_string, ',', tech_pvt->codec_order, SWITCH_MAX_CODECS);
|
||||||
tech_pvt->num_codecs = switch_loadable_module_get_codecs_sorted(tech_pvt->codecs,
|
tech_pvt->num_codecs = switch_loadable_module_get_codecs_sorted(tech_pvt->codecs,
|
||||||
SWITCH_MAX_CODECS,
|
SWITCH_MAX_CODECS,
|
||||||
tech_pvt->codec_order,
|
tech_pvt->codec_order,
|
||||||
tech_pvt->codec_order_last);
|
tech_pvt->codec_order_last);
|
||||||
free(tmp_codec_string);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tech_pvt->num_codecs = switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), tech_pvt->codecs,
|
tech_pvt->num_codecs = switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), tech_pvt->codecs,
|
||||||
sizeof(tech_pvt->codecs) / sizeof(tech_pvt->codecs[0]));
|
sizeof(tech_pvt->codecs) / sizeof(tech_pvt->codecs[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_safe_free(csdyn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1024,10 +1058,13 @@ static switch_status_t do_invite(switch_core_session_t *session)
|
|||||||
char *extra_headers = NULL;
|
char *extra_headers = NULL;
|
||||||
const void *vvar;
|
const void *vvar;
|
||||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||||
|
char *rep;
|
||||||
|
|
||||||
channel = switch_core_session_get_channel(session);
|
channel = switch_core_session_get_channel(session);
|
||||||
assert(channel != NULL);
|
assert(channel != NULL);
|
||||||
|
|
||||||
|
rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER);
|
||||||
|
|
||||||
tech_pvt = (private_object_t *) switch_core_session_get_private(session);
|
tech_pvt = (private_object_t *) switch_core_session_get_private(session);
|
||||||
assert(tech_pvt != NULL);
|
assert(tech_pvt != NULL);
|
||||||
|
|
||||||
@ -1037,13 +1074,21 @@ static switch_status_t do_invite(switch_core_session_t *session)
|
|||||||
cid_num = (char *) caller_profile->caller_id_number;
|
cid_num = (char *) caller_profile->caller_id_number;
|
||||||
tech_set_codecs(tech_pvt);
|
tech_set_codecs(tech_pvt);
|
||||||
|
|
||||||
if ((tech_pvt->from_str = switch_mprintf("\"%s\" <sip:%s@%s>",
|
if (!tech_pvt->from_str) {
|
||||||
|
tech_pvt->from_str = switch_core_session_sprintf(tech_pvt->session, "\"%s\" <sip:%s@%s>",
|
||||||
cid_name,
|
cid_name,
|
||||||
cid_num,
|
cid_num,
|
||||||
tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip
|
tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip);
|
||||||
))) {
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tech_pvt->from_str) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char *rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER);
|
|
||||||
|
|
||||||
if ((alertbuf = switch_channel_get_variable(channel, "alert_info"))) {
|
if ((alertbuf = switch_channel_get_variable(channel, "alert_info"))) {
|
||||||
snprintf(alert_info, sizeof(alert_info) - 1, "Alert-Info: %s", alertbuf);
|
snprintf(alert_info, sizeof(alert_info) - 1, "Alert-Info: %s", alertbuf);
|
||||||
@ -1153,12 +1198,8 @@ static switch_status_t do_invite(switch_core_session_t *session)
|
|||||||
TAG_END());
|
TAG_END());
|
||||||
|
|
||||||
switch_safe_free(stream.data);
|
switch_safe_free(stream.data);
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
|
||||||
} else {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1181,7 +1222,7 @@ static void do_xfer_invite(switch_core_session_t *session)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ((tech_pvt->from_str = switch_mprintf("\"%s\" <sip:%s@%s>",
|
if ((tech_pvt->from_str = switch_core_session_sprintf(session, "\"%s\" <sip:%s@%s>",
|
||||||
(char *) caller_profile->caller_id_name,
|
(char *) caller_profile->caller_id_name,
|
||||||
(char *) caller_profile->caller_id_number,
|
(char *) caller_profile->caller_id_number,
|
||||||
tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip
|
tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip
|
||||||
@ -1427,10 +1468,6 @@ static switch_status_t sofia_on_hangup(switch_core_session_t *session)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tech_pvt->from_str) {
|
|
||||||
switch_safe_free(tech_pvt->from_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
|
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
|
||||||
|
|
||||||
if (tech_pvt->home) {
|
if (tech_pvt->home) {
|
||||||
@ -2334,7 +2371,21 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
|
|||||||
data = switch_core_session_strdup(nsession, outbound_profile->destination_number);
|
data = switch_core_session_strdup(nsession, outbound_profile->destination_number);
|
||||||
profile_name = data;
|
profile_name = data;
|
||||||
|
|
||||||
if (!(dest = strchr(profile_name, '/'))) {
|
if (!strncasecmp(profile_name, "gateway", 7)) {
|
||||||
|
char *gw;
|
||||||
|
outbound_reg_t *gateway_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
if (!(gw = strchr(profile_name, '/'))) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
|
||||||
|
terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
|
||||||
|
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
*gw++ = '\0';
|
||||||
|
|
||||||
|
if (!(dest = strchr(gw, '/'))) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
|
||||||
terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
|
terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
|
||||||
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
|
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
|
||||||
@ -2343,7 +2394,30 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
|
|||||||
|
|
||||||
*dest++ = '\0';
|
*dest++ = '\0';
|
||||||
|
|
||||||
if (!(profile = (sofia_profile_t *) switch_core_hash_find(globals.profile_hash, profile_name))) {
|
if (!(gateway_ptr = find_gateway(gw))) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Gateway\n");
|
||||||
|
terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
|
||||||
|
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
profile = gateway_ptr->profile;
|
||||||
|
tech_pvt->from_str = switch_core_session_strdup(nsession, gateway_ptr->register_from);
|
||||||
|
if (!strchr(dest, '@')) {
|
||||||
|
tech_pvt->dest = switch_core_session_sprintf(nsession, "sip:%s@%s", dest, gateway_ptr->register_proxy + 4);
|
||||||
|
} else {
|
||||||
|
tech_pvt->dest = switch_core_session_sprintf(nsession, "sip:%s", dest);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!(dest = strchr(profile_name, '/'))) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
|
||||||
|
terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
|
||||||
|
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
*dest++ = '\0';
|
||||||
|
|
||||||
|
if (!(profile = find_profile(profile_name))) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n");
|
||||||
terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
|
terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
|
||||||
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
|
||||||
@ -2386,6 +2460,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
|
|||||||
tech_pvt->dest = switch_core_session_alloc(nsession, strlen(dest) + 5);
|
tech_pvt->dest = switch_core_session_alloc(nsession, strlen(dest) + 5);
|
||||||
snprintf(tech_pvt->dest, strlen(dest) + 5, "sip:%s", dest);
|
snprintf(tech_pvt->dest, strlen(dest) + 5, "sip:%s", dest);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!tech_pvt->dest_to) {
|
if (!tech_pvt->dest_to) {
|
||||||
tech_pvt->dest_to = tech_pvt->dest;
|
tech_pvt->dest_to = tech_pvt->dest;
|
||||||
@ -3058,7 +3133,7 @@ static void sip_i_state(int status,
|
|||||||
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED_3PCC");
|
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED_3PCC");
|
||||||
|
|
||||||
if (tech_choose_port(tech_pvt) != SWITCH_STATUS_SUCCESS) {
|
if (tech_choose_port(tech_pvt) != SWITCH_STATUS_SUCCESS) {
|
||||||
return;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
|
set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
|
||||||
@ -3353,7 +3428,7 @@ static uint8_t handle_register(nua_t *nua,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!port) {
|
if (!port) {
|
||||||
port = "5060";
|
port = SOFIA_DEFAULT_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact->m_url->url_params) {
|
if (contact->m_url->url_params) {
|
||||||
@ -3785,7 +3860,7 @@ static void sip_i_subscribe(int status,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!port) {
|
if (!port) {
|
||||||
port = "5060";
|
port = SOFIA_DEFAULT_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contact->m_url->url_params) {
|
if (contact->m_url->url_params) {
|
||||||
@ -4399,7 +4474,7 @@ static const char * _url_set_chanvars(switch_core_session_t *session, url_t *url
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!port) {
|
if (!port) {
|
||||||
port = "5060";
|
port = SOFIA_DEFAULT_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_channel_set_variable(channel, port_var, port);
|
switch_channel_set_variable(channel, port_var, port);
|
||||||
@ -4708,12 +4783,28 @@ static void sip_r_register(int status,
|
|||||||
sip_t const *sip,
|
sip_t const *sip,
|
||||||
tagi_t tags[])
|
tagi_t tags[])
|
||||||
{
|
{
|
||||||
if (sofia_private && sofia_private->oreg) {
|
if (sofia_private && sofia_private->gateway) {
|
||||||
if (status == 200) {
|
switch (status) {
|
||||||
sofia_private->oreg->state = REG_STATE_REGISTER;
|
case 200:
|
||||||
} else {
|
if (sip && sip->sip_contact && sip->sip_contact->m_expires) {
|
||||||
sofia_private->oreg->state = REG_STATE_FAILED;
|
char *new_expires = (char *) sip->sip_contact->m_expires;
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "received %d on register!\n", status);
|
int expi = atoi(new_expires);
|
||||||
|
|
||||||
|
if (expi != sofia_private->gateway->freq) {
|
||||||
|
sofia_private->gateway->freq = expi;
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
|
||||||
|
"Changing expire time to %d by request of proxy %s\n", expi, sofia_private->gateway->register_proxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
sofia_private->gateway->state = REG_STATE_REGISTER;
|
||||||
|
break;
|
||||||
|
case 100:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sofia_private->gateway->state = REG_STATE_FAILED;
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Registration Failed with status %d\n", status);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4727,7 +4818,7 @@ static void sip_r_challenge(int status,
|
|||||||
sip_t const *sip,
|
sip_t const *sip,
|
||||||
tagi_t tags[])
|
tagi_t tags[])
|
||||||
{
|
{
|
||||||
outbound_reg_t *oreg = NULL;
|
outbound_reg_t *gateway = NULL;
|
||||||
sip_www_authenticate_t const *authenticate = NULL;
|
sip_www_authenticate_t const *authenticate = NULL;
|
||||||
char const *realm = NULL;
|
char const *realm = NULL;
|
||||||
char *p = NULL, *duprealm = NULL, *qrealm = NULL;
|
char *p = NULL, *duprealm = NULL, *qrealm = NULL;
|
||||||
@ -4770,7 +4861,7 @@ static void sip_r_challenge(int status,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (profile) {
|
if (profile) {
|
||||||
outbound_reg_t *oregp;
|
outbound_reg_t *gateway_ptr;
|
||||||
|
|
||||||
if ((duprealm = strdup(realm))) {
|
if ((duprealm = strdup(realm))) {
|
||||||
qrealm = duprealm;
|
qrealm = duprealm;
|
||||||
@ -4783,13 +4874,28 @@ static void sip_r_challenge(int status,
|
|||||||
*p = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
for (oregp = profile->registrations; oregp; oregp = oregp->next) {
|
if (sip->sip_from) {
|
||||||
if (scheme && qrealm && !strcasecmp(oregp->register_scheme, scheme) && !strcasecmp(oregp->register_realm, qrealm)) {
|
char *from_key = switch_mprintf("sip:%s@%s",
|
||||||
oreg = oregp;
|
(char *) sip->sip_from->a_url->url_user,
|
||||||
|
(char *) sip->sip_from->a_url->url_host);
|
||||||
|
|
||||||
|
if (!(gateway = find_gateway(from_key))) {
|
||||||
|
gateway = find_gateway(qrealm);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_safe_free(from_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gateway) {
|
||||||
|
for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
|
||||||
|
if (scheme && qrealm && !strcasecmp(gateway_ptr->register_scheme, scheme) && !strcasecmp(gateway_ptr->register_realm, qrealm)) {
|
||||||
|
gateway = gateway_ptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!oreg) {
|
}
|
||||||
|
|
||||||
|
if (!gateway) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Match for Scheme [%s] Realm [%s]\n", scheme, qrealm);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Match for Scheme [%s] Realm [%s]\n", scheme, qrealm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -4801,8 +4907,8 @@ static void sip_r_challenge(int status,
|
|||||||
}
|
}
|
||||||
|
|
||||||
snprintf(authentication, sizeof(authentication), "%s:%s:%s:%s", scheme, realm,
|
snprintf(authentication, sizeof(authentication), "%s:%s:%s:%s", scheme, realm,
|
||||||
oreg->register_username,
|
gateway->register_username,
|
||||||
oreg->register_password);
|
gateway->register_password);
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Authenticating '%s' with '%s'.\n",
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Authenticating '%s' with '%s'.\n",
|
||||||
profile->username, authentication);
|
profile->username, authentication);
|
||||||
@ -4815,7 +4921,7 @@ static void sip_r_challenge(int status,
|
|||||||
SIPTAG_WWW_AUTHENTICATE_REF(authenticate),
|
SIPTAG_WWW_AUTHENTICATE_REF(authenticate),
|
||||||
TAG_END());
|
TAG_END());
|
||||||
|
|
||||||
nua_authenticate(nh, SIPTAG_EXPIRES_STR(oreg->expires_str), NUTAG_AUTH(authentication), TAG_END());
|
nua_authenticate(nh, SIPTAG_EXPIRES_STR(gateway->expires_str), NUTAG_AUTH(authentication), TAG_END());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4974,73 +5080,73 @@ static void event_callback(nua_event_t event,
|
|||||||
|
|
||||||
static void unreg(sofia_profile_t *profile)
|
static void unreg(sofia_profile_t *profile)
|
||||||
{
|
{
|
||||||
outbound_reg_t *oregp;
|
outbound_reg_t *gateway_ptr;
|
||||||
for (oregp = profile->registrations; oregp; oregp = oregp->next) {
|
for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
|
||||||
if (oregp->sofia_private) {
|
if (gateway_ptr->sofia_private) {
|
||||||
free(oregp->sofia_private);
|
free(gateway_ptr->sofia_private);
|
||||||
nua_handle_bind(oregp->nh, NULL);
|
nua_handle_bind(gateway_ptr->nh, NULL);
|
||||||
oregp->sofia_private = NULL;
|
gateway_ptr->sofia_private = NULL;
|
||||||
}
|
}
|
||||||
nua_handle_destroy(oregp->nh);
|
nua_handle_destroy(gateway_ptr->nh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_oreg(sofia_profile_t *profile, time_t now)
|
static void check_gateway(sofia_profile_t *profile, time_t now)
|
||||||
{
|
{
|
||||||
outbound_reg_t *oregp;
|
outbound_reg_t *gateway_ptr;
|
||||||
for (oregp = profile->registrations; oregp; oregp = oregp->next) {
|
for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
|
||||||
int ss_state = nua_callstate_authenticating;
|
int ss_state = nua_callstate_authenticating;
|
||||||
reg_state_t ostate = oregp->state;
|
reg_state_t ostate = gateway_ptr->state;
|
||||||
|
|
||||||
switch(ostate) {
|
switch(ostate) {
|
||||||
case REG_STATE_REGISTER:
|
case REG_STATE_REGISTER:
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registered %s\n", oregp->name);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registered %s\n", gateway_ptr->name);
|
||||||
oregp->expires = now + oregp->freq;
|
gateway_ptr->expires = now + gateway_ptr->freq;
|
||||||
oregp->state = REG_STATE_REGED;
|
gateway_ptr->state = REG_STATE_REGED;
|
||||||
break;
|
break;
|
||||||
case REG_STATE_UNREGED:
|
case REG_STATE_UNREGED:
|
||||||
if ((oregp->nh = nua_handle(oregp->profile->nua, NULL,
|
if ((gateway_ptr->nh = nua_handle(gateway_ptr->profile->nua, NULL,
|
||||||
NUTAG_URL(oregp->register_proxy),
|
NUTAG_URL(gateway_ptr->register_proxy),
|
||||||
SIPTAG_TO_STR(oregp->register_to),
|
SIPTAG_TO_STR(gateway_ptr->register_to),
|
||||||
NUTAG_CALLSTATE_REF(ss_state),
|
NUTAG_CALLSTATE_REF(ss_state),
|
||||||
SIPTAG_FROM_STR(oregp->register_from), TAG_END()))) {
|
SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END()))) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registering %s\n", oregp->name);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registering %s\n", gateway_ptr->name);
|
||||||
|
|
||||||
if (!(oregp->sofia_private = malloc(sizeof(*oregp->sofia_private)))) {
|
if (!(gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private)))) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
memset(oregp->sofia_private, 0, sizeof(*oregp->sofia_private));
|
memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
|
||||||
|
|
||||||
oregp->sofia_private->oreg = oregp;
|
gateway_ptr->sofia_private->gateway = gateway_ptr;
|
||||||
nua_handle_bind(oregp->nh, oregp->sofia_private);
|
nua_handle_bind(gateway_ptr->nh, gateway_ptr->sofia_private);
|
||||||
|
|
||||||
nua_register(oregp->nh,
|
nua_register(gateway_ptr->nh,
|
||||||
SIPTAG_FROM_STR(oregp->register_from),
|
SIPTAG_FROM_STR(gateway_ptr->register_from),
|
||||||
SIPTAG_CONTACT_STR(oregp->register_from),
|
SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
|
||||||
SIPTAG_EXPIRES_STR(oregp->expires_str),
|
SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
|
||||||
NUTAG_REGISTRAR(oregp->register_proxy),
|
NUTAG_REGISTRAR(gateway_ptr->register_proxy),
|
||||||
NUTAG_OUTBOUND("no-options-keepalive"),
|
NUTAG_OUTBOUND("no-options-keepalive"),
|
||||||
NUTAG_OUTBOUND("no-validate"),
|
NUTAG_OUTBOUND("no-validate"),
|
||||||
NUTAG_KEEPALIVE(0),
|
NUTAG_KEEPALIVE(0),
|
||||||
TAG_NULL());
|
TAG_NULL());
|
||||||
oregp->retry = now + 10;
|
gateway_ptr->retry = now + 10;
|
||||||
oregp->state = REG_STATE_TRYING;
|
gateway_ptr->state = REG_STATE_TRYING;
|
||||||
} else {
|
} else {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error registering %s\n", oregp->name);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error registering %s\n", gateway_ptr->name);
|
||||||
oregp->state = REG_STATE_FAILED;
|
gateway_ptr->state = REG_STATE_FAILED;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REG_STATE_TRYING:
|
case REG_STATE_TRYING:
|
||||||
if (oregp->retry && now >= oregp->retry) {
|
if (gateway_ptr->retry && now >= gateway_ptr->retry) {
|
||||||
oregp->state = REG_STATE_UNREGED;
|
gateway_ptr->state = REG_STATE_UNREGED;
|
||||||
oregp->retry = 0;
|
gateway_ptr->retry = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (oregp->expires && now >= oregp->expires) {
|
if (gateway_ptr->expires && now >= gateway_ptr->expires) {
|
||||||
oregp->state = REG_STATE_UNREGED;
|
gateway_ptr->state = REG_STATE_UNREGED;
|
||||||
oregp->expires = 0;
|
gateway_ptr->expires = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -5049,14 +5155,14 @@ static void check_oreg(sofia_profile_t *profile, time_t now)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define IREG_SECONDS 30
|
#define IREG_SECONDS 30
|
||||||
#define OREG_SECONDS 1
|
#define GATEWAY_SECONDS 1
|
||||||
static void *SWITCH_THREAD_FUNC profile_thread_run(switch_thread_t *thread, void *obj)
|
static void *SWITCH_THREAD_FUNC profile_thread_run(switch_thread_t *thread, void *obj)
|
||||||
{
|
{
|
||||||
sofia_profile_t *profile = (sofia_profile_t *) obj;
|
sofia_profile_t *profile = (sofia_profile_t *) obj;
|
||||||
switch_memory_pool_t *pool;
|
switch_memory_pool_t *pool;
|
||||||
sip_alias_node_t *node;
|
sip_alias_node_t *node;
|
||||||
uint32_t ireg_loops = 0;
|
uint32_t ireg_loops = 0;
|
||||||
uint32_t oreg_loops = 0;
|
uint32_t gateway_loops = 0;
|
||||||
switch_core_db_t *db;
|
switch_core_db_t *db;
|
||||||
switch_event_t *s_event;
|
switch_event_t *s_event;
|
||||||
|
|
||||||
@ -5122,10 +5228,10 @@ static void *SWITCH_THREAD_FUNC profile_thread_run(switch_thread_t *thread, void
|
|||||||
|
|
||||||
|
|
||||||
switch_mutex_init(&profile->ireg_mutex, SWITCH_MUTEX_NESTED, profile->pool);
|
switch_mutex_init(&profile->ireg_mutex, SWITCH_MUTEX_NESTED, profile->pool);
|
||||||
switch_mutex_init(&profile->oreg_mutex, SWITCH_MUTEX_NESTED, profile->pool);
|
switch_mutex_init(&profile->gateway_mutex, SWITCH_MUTEX_NESTED, profile->pool);
|
||||||
|
|
||||||
ireg_loops = IREG_SECONDS;
|
ireg_loops = IREG_SECONDS;
|
||||||
oreg_loops = OREG_SECONDS;
|
gateway_loops = GATEWAY_SECONDS;
|
||||||
|
|
||||||
if (switch_event_create(&s_event, SWITCH_EVENT_PUBLISH) == SWITCH_STATUS_SUCCESS) {
|
if (switch_event_create(&s_event, SWITCH_EVENT_PUBLISH) == SWITCH_STATUS_SUCCESS) {
|
||||||
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "service", "_sip._udp");
|
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "service", "_sip._udp");
|
||||||
@ -5145,27 +5251,21 @@ static void *SWITCH_THREAD_FUNC profile_thread_run(switch_thread_t *thread, void
|
|||||||
switch_event_fire(&s_event);
|
switch_event_fire(&s_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
add_profile(profile->name, profile);
|
||||||
switch_mutex_lock(globals.hash_mutex);
|
|
||||||
switch_core_hash_insert(globals.profile_hash, profile->name, profile);
|
|
||||||
switch_mutex_unlock(globals.hash_mutex);
|
|
||||||
|
|
||||||
if (profile->pflags & PFLAG_PRESENCE) {
|
if (profile->pflags & PFLAG_PRESENCE) {
|
||||||
establish_presence(profile);
|
establish_presence(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while(globals.running == 1) {
|
while(globals.running == 1) {
|
||||||
if (++ireg_loops >= IREG_SECONDS) {
|
if (++ireg_loops >= IREG_SECONDS) {
|
||||||
check_expire(db, profile, time(NULL));
|
check_expire(db, profile, time(NULL));
|
||||||
ireg_loops = 0;
|
ireg_loops = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++oreg_loops >= OREG_SECONDS) {
|
if (++gateway_loops >= GATEWAY_SECONDS) {
|
||||||
check_oreg(profile, time(NULL));
|
check_gateway(profile, time(NULL));
|
||||||
oreg_loops = 0;
|
gateway_loops = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
su_root_step(profile->s_root, 1000);
|
su_root_step(profile->s_root, 1000);
|
||||||
@ -5208,7 +5308,7 @@ static void launch_profile_thread(sofia_profile_t *profile)
|
|||||||
static switch_status_t config_sofia(int reload)
|
static switch_status_t config_sofia(int reload)
|
||||||
{
|
{
|
||||||
char *cf = "sofia.conf";
|
char *cf = "sofia.conf";
|
||||||
switch_xml_t cfg, xml = NULL, xprofile, param, settings, profiles, registration, registrations;
|
switch_xml_t cfg, xml = NULL, xprofile, param, settings, profiles, gateway_tag, gateways_tag;
|
||||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||||
sofia_profile_t *profile = NULL;
|
sofia_profile_t *profile = NULL;
|
||||||
char url[512] = "";
|
char url[512] = "";
|
||||||
@ -5419,7 +5519,7 @@ static switch_status_t config_sofia(int reload)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!profile->sip_port) {
|
if (!profile->sip_port) {
|
||||||
profile->sip_port = 5060;
|
profile->sip_port = atoi(SOFIA_DEFAULT_PORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!profile->dialplan) {
|
if (!profile->dialplan) {
|
||||||
@ -5438,79 +5538,118 @@ static switch_status_t config_sofia(int reload)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (profile) {
|
if (profile) {
|
||||||
if ((registrations = switch_xml_child(xprofile, "registrations"))) {
|
if ((gateways_tag = switch_xml_child(xprofile, "registrations"))) {
|
||||||
for (registration = switch_xml_child(registrations, "registration"); registration; registration = registration->next) {
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
|
||||||
char *name = (char *) switch_xml_attr_soft(registration, "name");
|
"The <registrations> syntax has been discontinued, please see the new syntax in the default configuration examples\n");
|
||||||
outbound_reg_t *oreg;
|
}
|
||||||
|
|
||||||
|
if ((gateways_tag = switch_xml_child(xprofile, "gateways"))) {
|
||||||
|
for (gateway_tag = switch_xml_child(gateways_tag, "gateway"); gateway_tag; gateway_tag = gateway_tag->next) {
|
||||||
|
char *name = (char *) switch_xml_attr_soft(gateway_tag, "name");
|
||||||
|
outbound_reg_t *gateway;
|
||||||
|
|
||||||
if (switch_strlen_zero(name)) {
|
if (switch_strlen_zero(name)) {
|
||||||
name = "anonymous";
|
name = "anonymous";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((oreg = switch_core_alloc(profile->pool, sizeof(*oreg)))) {
|
if ((gateway = switch_core_alloc(profile->pool, sizeof(*gateway)))) {
|
||||||
oreg->pool = profile->pool;
|
gateway->pool = profile->pool;
|
||||||
oreg->profile = profile;
|
gateway->profile = profile;
|
||||||
oreg->name = switch_core_strdup(oreg->pool, name);
|
gateway->name = switch_core_strdup(gateway->pool, name);
|
||||||
oreg->freq = 0;
|
gateway->freq = 0;
|
||||||
|
char *scheme = "Digest",
|
||||||
|
*realm = NULL,
|
||||||
|
*username = NULL,
|
||||||
|
*password = NULL,
|
||||||
|
*extension = NULL,
|
||||||
|
*proxy = NULL,
|
||||||
|
*expire_seconds = "3600";
|
||||||
|
|
||||||
for (param = switch_xml_child(registration, "param"); param; param = param->next) {
|
for (param = switch_xml_child(gateway_tag, "param"); param; param = param->next) {
|
||||||
char *var = (char *) switch_xml_attr_soft(param, "name");
|
char *var = (char *) switch_xml_attr_soft(param, "name");
|
||||||
char *val = (char *) switch_xml_attr_soft(param, "value");
|
char *val = (char *) switch_xml_attr_soft(param, "value");
|
||||||
|
|
||||||
if (!strcmp(var, "register-scheme")) {
|
if (!strcmp(var, "scheme")) {
|
||||||
oreg->register_scheme = switch_core_strdup(oreg->pool, val);
|
scheme = val;
|
||||||
} else if (!strcmp(var, "register-realm")) {
|
} else if (!strcmp(var, "realm")) {
|
||||||
oreg->register_realm = switch_core_strdup(oreg->pool, val);
|
realm = val;
|
||||||
} else if (!strcmp(var, "register-username")) {
|
} else if (!strcmp(var, "username")) {
|
||||||
oreg->register_username = switch_core_strdup(oreg->pool, val);
|
username = val;
|
||||||
} else if (!strcmp(var, "register-password")) {
|
} else if (!strcmp(var, "password")) {
|
||||||
oreg->register_password = switch_core_strdup(oreg->pool, val);
|
password = val;
|
||||||
} else if (!strcmp(var, "register-from")) {
|
} else if (!strcmp(var, "extension")) {
|
||||||
oreg->register_from = switch_core_strdup(oreg->pool, val);
|
extension = val;
|
||||||
} else if (!strcmp(var, "register-to")) {
|
} else if (!strcmp(var, "proxy")) {
|
||||||
oreg->register_to = switch_core_strdup(oreg->pool, val);
|
proxy = val;
|
||||||
} else if (!strcmp(var, "register-proxy")) {
|
} else if (!strcmp(var, "expire-seconds")) {
|
||||||
oreg->register_proxy = switch_core_strdup(oreg->pool, val);
|
expire_seconds = val;
|
||||||
} else if (!strcmp(var, "register-frequency")) {
|
|
||||||
oreg->expires_str = switch_core_strdup(oreg->pool, val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (switch_strlen_zero(oreg->register_scheme)) {
|
|
||||||
oreg->register_scheme = switch_core_strdup(oreg->pool, "Digest");
|
|
||||||
}
|
|
||||||
if (switch_strlen_zero(oreg->register_realm)) {
|
|
||||||
oreg->register_realm = switch_core_strdup(oreg->pool, "freeswitch.org");
|
|
||||||
}
|
|
||||||
if (switch_strlen_zero(oreg->register_username)) {
|
|
||||||
oreg->register_username = switch_core_strdup(oreg->pool, "freeswitch");
|
|
||||||
}
|
|
||||||
if (switch_strlen_zero(oreg->register_password)) {
|
|
||||||
oreg->register_password = switch_core_strdup(oreg->pool, "works");
|
|
||||||
}
|
|
||||||
if (switch_strlen_zero(oreg->register_from)) {
|
|
||||||
oreg->register_from = switch_core_strdup(oreg->pool, "FreeSWITCH <sip:freeswitch@freeswitch.org>");
|
|
||||||
}
|
|
||||||
if (switch_strlen_zero(oreg->register_to)) {
|
|
||||||
oreg->register_to = switch_core_strdup(oreg->pool, "sip:freeswitch@freeswitch.org");
|
|
||||||
}
|
|
||||||
if (switch_strlen_zero(oreg->register_proxy)) {
|
|
||||||
oreg->register_proxy = switch_core_strdup(oreg->pool, "sip:freeswitch@freeswitch.org");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (switch_strlen_zero(oreg->expires_str)) {
|
if (switch_strlen_zero(realm)) {
|
||||||
oreg->expires_str = switch_core_strdup(oreg->pool, "300");
|
realm = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((oreg->freq = atoi(oreg->expires_str)) < 5) {
|
if (switch_strlen_zero(username)) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Freq: %d. Setting Register-Frequency to 5\n", oreg->freq);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: username param is REQUIRED!\n");
|
||||||
oreg->freq = 5;
|
switch_xml_free(xml);
|
||||||
|
goto skip;
|
||||||
}
|
}
|
||||||
oreg->freq -= 2;
|
|
||||||
|
|
||||||
oreg->next = profile->registrations;
|
|
||||||
profile->registrations = oreg;
|
|
||||||
|
|
||||||
|
if (switch_strlen_zero(password)) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: password param is REQUIRED!\n");
|
||||||
|
switch_xml_free(xml);
|
||||||
|
goto skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (switch_strlen_zero(extension)) {
|
||||||
|
extension = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (switch_strlen_zero(proxy)) {
|
||||||
|
proxy = realm;
|
||||||
|
}
|
||||||
|
|
||||||
|
gateway->register_scheme = switch_core_strdup(gateway->pool, scheme);
|
||||||
|
gateway->register_realm = switch_core_strdup(gateway->pool, realm);
|
||||||
|
gateway->register_username = switch_core_strdup(gateway->pool, username);
|
||||||
|
gateway->register_password = switch_core_strdup(gateway->pool, password);
|
||||||
|
gateway->register_from = switch_core_sprintf(gateway->pool, "sip:%s@%s", extension, realm);
|
||||||
|
gateway->register_contact = switch_core_sprintf(gateway->pool,
|
||||||
|
"sip:%s@%s:%d", extension, profile->sipip, profile->sip_port);
|
||||||
|
|
||||||
|
if (!strncasecmp(proxy, "sip:", 4)) {
|
||||||
|
gateway->register_proxy = switch_core_strdup(gateway->pool, proxy);
|
||||||
|
gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy + 4);
|
||||||
|
} else {
|
||||||
|
gateway->register_proxy = switch_core_sprintf(gateway->pool, "sip:%s", proxy);
|
||||||
|
gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
gateway->expires_str = switch_core_strdup(gateway->pool, expire_seconds);
|
||||||
|
|
||||||
|
if ((gateway->freq = atoi(gateway->expires_str)) < 5) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
|
||||||
|
"Invalid Freq: %d. Setting Register-Frequency to 3600\n", gateway->freq);
|
||||||
|
gateway->freq = 3600;
|
||||||
|
}
|
||||||
|
gateway->freq -= 2;
|
||||||
|
|
||||||
|
gateway->next = profile->gateways;
|
||||||
|
profile->gateways = gateway;
|
||||||
|
|
||||||
|
if (find_gateway(gateway->name)) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate gateway '%s'\n", gateway->name);
|
||||||
|
} else if (find_gateway(gateway->register_from)) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate uri '%s'\n", gateway->register_from);
|
||||||
|
} else {
|
||||||
|
add_gateway(gateway->name, gateway);
|
||||||
|
add_gateway(gateway->register_from, gateway);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
skip:
|
||||||
|
assert(gateway_tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5552,7 +5691,7 @@ static void event_handler(switch_event_t *event)
|
|||||||
rpid = "unknown";
|
rpid = "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!profile_name || !(profile = (sofia_profile_t *) switch_core_hash_find(globals.profile_hash, profile_name))) {
|
if (!profile_name || !(profile = find_profile(profile_name))) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -5602,7 +5741,7 @@ static switch_status_t chat_send(char *proto, char *from, char *to, char *subjec
|
|||||||
*host++ = '\0';
|
*host++ = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!host || !(profile = (sofia_profile_t *) switch_core_hash_find(globals.profile_hash, host))) {
|
if (!host || !(profile = find_profile(host))) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Chat proto [%s]\nfrom [%s]\nto [%s]\n%s\nInvalid Profile %s\n",
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Chat proto [%s]\nfrom [%s]\nto [%s]\n%s\nInvalid Profile %s\n",
|
||||||
proto,
|
proto,
|
||||||
from,
|
from,
|
||||||
@ -5671,6 +5810,7 @@ static void cancel_presence(void)
|
|||||||
void *val;
|
void *val;
|
||||||
|
|
||||||
if ((sql = switch_mprintf("select 0,'unavailable','unavailable',* from sip_subscriptions where event='presence'"))) {
|
if ((sql = switch_mprintf("select 0,'unavailable','unavailable',* from sip_subscriptions where event='presence'"))) {
|
||||||
|
switch_mutex_lock(globals.hash_mutex);
|
||||||
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||||
switch_hash_this(hi, NULL, NULL, &val);
|
switch_hash_this(hi, NULL, NULL, &val);
|
||||||
profile = (sofia_profile_t *) val;
|
profile = (sofia_profile_t *) val;
|
||||||
@ -5689,7 +5829,7 @@ static void cancel_presence(void)
|
|||||||
}
|
}
|
||||||
switch_safe_free(sql);
|
switch_safe_free(sql);
|
||||||
}
|
}
|
||||||
|
switch_mutex_unlock(globals.hash_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void establish_presence(sofia_profile_t *profile)
|
static void establish_presence(sofia_profile_t *profile)
|
||||||
@ -5805,6 +5945,7 @@ static void pres_event_handler(switch_event_t *event)
|
|||||||
sql = switch_mprintf("select 1,'%q','%q',* from sip_subscriptions where event='presence'", status, rpid);
|
sql = switch_mprintf("select 1,'%q','%q',* from sip_subscriptions where event='presence'", status, rpid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch_mutex_lock(globals.hash_mutex);
|
||||||
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||||
switch_hash_this(hi, NULL, NULL, &val);
|
switch_hash_this(hi, NULL, NULL, &val);
|
||||||
profile = (sofia_profile_t *) val;
|
profile = (sofia_profile_t *) val;
|
||||||
@ -5824,6 +5965,7 @@ static void pres_event_handler(switch_event_t *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
switch_mutex_unlock(globals.hash_mutex);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -5875,7 +6017,7 @@ static void pres_event_handler(switch_event_t *event)
|
|||||||
|
|
||||||
if (euser && host &&
|
if (euser && host &&
|
||||||
(sql = switch_mprintf("select user,host,status,rpid,'' from sip_registrations where user='%q' and host='%q'", euser, host)) &&
|
(sql = switch_mprintf("select user,host,status,rpid,'' from sip_registrations where user='%q' and host='%q'", euser, host)) &&
|
||||||
(profile = (sofia_profile_t *) switch_core_hash_find(globals.profile_hash, host))) {
|
(profile = find_profile(host))) {
|
||||||
if (!(db = switch_core_db_open_file(profile->dbname))) {
|
if (!(db = switch_core_db_open_file(profile->dbname))) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
|
||||||
switch_safe_free(user);
|
switch_safe_free(user);
|
||||||
@ -5904,6 +6046,7 @@ static void pres_event_handler(switch_event_t *event)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch_mutex_lock(globals.hash_mutex);
|
||||||
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||||
switch_hash_this(hi, NULL, NULL, &val);
|
switch_hash_this(hi, NULL, NULL, &val);
|
||||||
profile = (sofia_profile_t *) val;
|
profile = (sofia_profile_t *) val;
|
||||||
@ -5923,6 +6066,7 @@ static void pres_event_handler(switch_event_t *event)
|
|||||||
switch_core_db_close(db);
|
switch_core_db_close(db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch_mutex_unlock(globals.hash_mutex);
|
||||||
|
|
||||||
switch_safe_free(sql);
|
switch_safe_free(sql);
|
||||||
switch_safe_free(user);
|
switch_safe_free(user);
|
||||||
@ -5958,6 +6102,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
|
|||||||
su_log_redirect(tport_log, logger, NULL);
|
su_log_redirect(tport_log, logger, NULL);
|
||||||
|
|
||||||
switch_core_hash_init(&globals.profile_hash, module_pool);
|
switch_core_hash_init(&globals.profile_hash, module_pool);
|
||||||
|
switch_core_hash_init(&globals.gateway_hash, module_pool);
|
||||||
switch_mutex_init(&globals.hash_mutex, SWITCH_MUTEX_NESTED, module_pool);
|
switch_mutex_init(&globals.hash_mutex, SWITCH_MUTEX_NESTED, module_pool);
|
||||||
|
|
||||||
config_sofia(0);
|
config_sofia(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user