rendered paste bodystruct sofia_profile {
int debug;
char *name;
char *dbname;
char *dialplan;
char *context;
char *extrtpip;
char *rtpip;
char *sipip;
char *extsipip;
char *username;
char *url;
char *sipdomain;
char *timer_name;
int sip_port;
char *codec_string;
char *codec_order[SWITCH_MAX_CODECS];
int codec_order_last;
int running;
int codec_ms;
int dtmf_duration;
unsigned int flags;
unsigned int pflags;
uint32_t max_calls;
nua_t *nua;
switch_memory_pool_t *pool;
su_root_t *s_root;
sip_alias_node_t *aliases;
switch_payload_t te;
uint32_t codec_flags;
switch_mutex_t *ireg_mutex;
switch_mutex_t *oreg_mutex;
outbound_reg_t *registrations;
};
struct private_object {
sofia_private_t sofia_private;
uint32_t flags;
switch_core_session_t *session;
switch_frame_t read_frame;
const switch_codec_implementation_t *codecs[SWITCH_MAX_CODECS];
int num_codecs;
switch_codec_t read_codec;
switch_codec_t write_codec;
uint32_t codec_index;
uint32_t codec_ms;
switch_caller_profile_t *caller_profile;
int32_t timestamp_send;
int32_t timestamp_recv;
switch_rtp_t *rtp_session;
int ssrc;
switch_time_t last_read;
sofia_profile_t *profile;
char *local_sdp_audio_ip;
switch_port_t local_sdp_audio_port;
char *remote_sdp_audio_ip;
switch_port_t remote_sdp_audio_port;
char *adv_sdp_audio_ip;
switch_port_t adv_sdp_audio_port;
char *from_uri;
char *to_uri;
char *from_address;
char *to_address;
char *callid;
char *far_end_contact;
char *contact_url;
char *rm_encoding;
char *remote_sdp_str;
char *local_sdp_str;
char *dest;
char *key;
unsigned long rm_rate;
switch_payload_t pt;
switch_mutex_t *flag_mutex;
switch_payload_t te;
nua_handle_t *nh;
su_home_t *home;
sip_contact_t *contact;
};
static switch_status_t config_sofia(int reload)
{
char *cf = "sofia.conf";
switch_xml_t cfg, xml = NULL, xprofile, param, settings, profiles, registration, registrations;
switch_status_t status = SWITCH_STATUS_SUCCESS;
sofia_profile_t *profile = NULL;
char url[512] = "";
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
status = SWITCH_STATUS_FALSE;
goto done;
}
if ((profiles = switch_xml_child(cfg, "profiles"))) {
for (xprofile = switch_xml_child(profiles, "profile"); xprofile; xprofile = xprofile->next) {
if (!(settings = switch_xml_child(xprofile, "settings"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Settings, check the new config!\n", cf);
} else {
char *xprofilename = (char *) switch_xml_attr_soft(xprofile, "name");
switch_memory_pool_t *pool = NULL;
/* Setup the pool */
if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
goto done;
}
if (!(profile = (sofia_profile_t *) switch_core_alloc(pool, sizeof(*profile)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
goto done;
}
if (!xprofilename) {
xprofilename = "unnamed";
}
profile->pool = pool;
profile->name = switch_core_strdup(profile->pool, xprofilename);
snprintf(url, sizeof(url), "sofia_reg_%s", xprofilename);
profile->dbname = switch_core_strdup(profile->pool, url);
profile->dtmf_duration = 100;
profile->codec_ms = 20;
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "debug")) {
profile->debug = atoi(val);
.....
} else if (!strcasecmp(var, "ext-rtp-ip")) {
profile->extrtpip = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "rtp-ip")) {
profile->rtpip = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "sip-ip")) {
profile->sipip = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "sip-domain")) {
profile->sipdomain = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "rtp-timer-name")) {
profile->timer_name = switch_core_strdup(profile->pool, val);
.....
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
{
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
}
memset(&globals, 0, sizeof(globals));
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
if (switch_event_bind((char *) modname, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_TERM;
}
su_init();
switch_core_hash_init(&globals.profile_hash, module_pool);
switch_mutex_init(&globals.hash_mutex, SWITCH_MUTEX_NESTED, module_pool);
config_sofia(0);
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &sofia_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}