end:
- if (sub_state == nua_substate_terminated && sofia_private && sofia_private != &mod_sofia_globals.destroy_private &&
- sofia_private != &mod_sofia_globals.keep_private) {
- sofia_private->destroy_nh = 1;
- sofia_private->destroy_me = 1;
- }
-
+ return;
}
void sofia_handle_sip_i_bye(switch_core_session_t *session, int status,
switch_channel_hangup(channel, cause);
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS_MSG(de->data->e_msg),
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)), TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
-
+
switch_safe_free(extra_headers);
- if (sofia_private) {
- sofia_private->destroy_me = 1;
- sofia_private->destroy_nh = 1;
- }
#endif
}
tech_pvt->got_bye = 1;
+ sofia_private->got_bye = 1;
+
switch_channel_set_variable(channel, "sip_hangup_disposition", "recv_bye");
return;
}
if (check_destroy) {
- if (nh && ((sofia_private && sofia_private->destroy_nh) || !nua_handle_magic(nh))) {
+ if (0 && nh && ((sofia_private && sofia_private->destroy_nh) || !nua_handle_magic(nh))) {
+
+ printf("FUCKER2\n");
+
if (sofia_private) {
nua_handle_bind(nh, NULL);
}
+
nua_handle_destroy(nh);
nh = NULL;
}
}
- if (sofia_private && sofia_private->destroy_me) {
- if (tech_pvt) {
- tech_pvt->sofia_private = NULL;
- }
-
- if (nh) {
- nua_handle_bind(nh, NULL);
- }
- sofia_private->destroy_me = 12;
- sofia_private_free(sofia_private);
-
- }
-
if (gateway) {
sofia_reg_release_gateway(gateway);
}
sofia_dispatch_event_t *de = *dep;
nua_handle_t *nh = de->nh;
nua_t *nua = de->nua;
-
+ sofia_private_t *sofia_private = nua_handle_magic(de->nh);
+
*dep = NULL;
+ sofia_private = nua_handle_magic(nh);
+
+ //printf("QUEUE EVENT %s\n", nua_event_name(de->data->e_event));
+
+
our_sofia_event_callback(de->data->e_event, de->data->e_status, de->data->e_phrase, de->nua, de->profile,
- de->nh, nua_handle_magic(de->nh), de->sip, de, (tagi_t *) de->data->e_tags);
+ nh, sofia_private, de->sip, de, (tagi_t *) de->data->e_tags);
- nua_destroy_event(de->event);
- su_free(nh->nh_home, de);
+ //printf("/QUEUE EVENT %s\n", nua_event_name(de->data->e_event));
+ nua_destroy_event(de->event);
+ su_free(nh->nh_home, de);
nua_handle_unref(nh);
nua_stack_unref(nua);
}
{
sofia_dispatch_event_t *de;
+ //printf("EVENT %s\n", nua_event_name(event));
+
+
+
+ if (event == nua_i_terminated) {
+ if (sofia_private && sofia_private->nh) {
+ nua_handle_bind(nh, NULL);
+ nua_handle_destroy(sofia_private->nh);
+ }
+
+ return;
+ }
+
+
de = su_alloc(nh->nh_home, sizeof(*de));
memset(de, 0, sizeof(*de));
nua_save_event(nua, de->event);
de->nh = nua_handle_ref(nh);
- de->nh = nh;
de->data = nua_event_data(de->event);
de->sip = sip_object(de->data->e_msg);
de->profile = profile;
de->nua = nua_stack_ref(nua);
+
+ if (event == nua_i_state) {
+ int ss_state = nua_callstate_init;
+ tl_gets(tags, NUTAG_CALLSTATE_REF(ss_state), TAG_END());
+
+ //printf("state [%s][%d]\n", nua_callstate_name(ss_state), status);
+
+ if (ss_state == nua_callstate_terminated || ss_state == nua_callstate_terminating) {
+ sofia_process_dispatch_event(&de);
+ return;
+ }
+ }
+
+
+
+
+
if (event == nua_i_invite && !sofia_private) {
if (!(sofia_private = su_alloc(nh->nh_home, sizeof(*sofia_private)))) {
abort();
}
memset(sofia_private, 0, sizeof(*sofia_private));
- sofia_private->is_call++;
+ sofia_private->is_call = 2;
sofia_private->de = de;
+ sofia_private->nh = nua_handle_ref(nh);
nua_handle_bind(nh, sofia_private);
return;
}
}
}
-
sofia_queue_message(de);
}
if (sofia_private && !zstr(sofia_private->gateway_name)) {
gateway = sofia_reg_find_gateway(sofia_private->gateway_name);
- sofia_private->destroy_me = 1;
}
if (gateway) {
goto done;
}
}
-
- if (sofia_private) {
- sofia_private->destroy_me = 1;
- }
}
if (session) {
switch_channel_hangup(channel, cause);
}
-
- if (ss_state == nua_callstate_terminated) {
- if (tech_pvt->sofia_private) {
- tech_pvt->sofia_private = NULL;
- }
-
- nua_handle_unref(tech_pvt->nh);
- tech_pvt->nh = NULL;
-
- if (nh) {
- nua_handle_bind(nh, NULL);
- nua_handle_destroy(nh);
- }
- }
-
break;
}
switch_mutex_unlock(tech_pvt->profile->flag_mutex);
}
- nua_handle_bind(nh, NULL);
- sofia_private_free(sofia_private);
switch_core_session_destroy(&session);
nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
return;
NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END());
if (attach) {
if (!gateway_ptr->sofia_private) {
- gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
- switch_assert(gateway_ptr->sofia_private);
+ if (!(gateway_ptr->sofia_private = su_alloc(gateway_ptr->nh->nh_home, sizeof(*gateway_ptr->sofia_private)))) {
+ abort();
+ }
}
memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END());
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "subscribing to [%s] on gateway [%s]\n", gw_sub_ptr->event, gateway_ptr->name);
- gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
- switch_assert(gateway_ptr->sofia_private);
+ if (!(gateway_ptr->sofia_private = su_alloc(gateway_ptr->sub_nh->nh_home, sizeof(*gateway_ptr->sofia_private)))) {
+ abort();
+ }
memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
gateway_ptr->sofia_private->gateway = gateway_ptr;
if (gateway_ptr->ping && !gateway_ptr->pinging && (now >= gateway_ptr->ping && (ostate == REG_STATE_NOREG || ostate == REG_STATE_REGED)) &&
!gateway_ptr->deleted) {
nua_handle_t *nh = nua_handle(profile->nua, NULL, NUTAG_URL(gateway_ptr->register_url), TAG_END());
- sofia_private_t *pvt;
register_host = sofia_glue_get_register_host(gateway_ptr->register_proxy);
switch_safe_free(register_host);
- pvt = malloc(sizeof(*pvt));
- switch_assert(pvt);
- memset(pvt, 0, sizeof(*pvt));
- pvt->destroy_nh = 1;
- pvt->destroy_me = 1;
- switch_copy_string(pvt->gateway_name, gateway_ptr->name, sizeof(pvt->gateway_name));
- nua_handle_bind(nh, pvt);
+ nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
gateway_ptr->pinging = 1;
nua_options(nh,