-Wed Jul 18 21:45:15 CDT 2012
+Wed Aug 15 22:51:21 CDT 2012
if (request->sip_multipart) {
mp = request->sip_multipart;
} else {
- mp = msg_multipart_parse(msg_home(msg),
+ mp = msg_multipart_parse(nua_handle_home(nh),
request->sip_content_type,
(sip_payload_t *)request->sip_payload);
request->sip_multipart = mp;
mpp->mp_payload && mpp->mp_payload->pl_data &&
su_casenmatch(mpp->mp_content_type->c_type, "application/sdp", 15)) {
- request->sip_content_type = msg_content_type_dup(msg_home(msg), mpp->mp_content_type);
+ request->sip_content_type = msg_content_type_dup(nua_handle_home(nh), mpp->mp_content_type);
if (request->sip_content_length) {
request->sip_content_length->l_length = mpp->mp_payload->pl_len;
}
- request->sip_payload->pl_data = su_strdup(msg_home(msg), mpp->mp_payload->pl_data);
+ request->sip_payload->pl_data = su_strdup(nua_handle_home(nh), mpp->mp_payload->pl_data);
request->sip_payload->pl_len = mpp->mp_payload->pl_len;
sdp++;
SSF_READ_TRANSCODE = (1 << 5),
SSF_WRITE_TRANSCODE = (1 << 6),
SSF_READ_CODEC_RESET = (1 << 7),
- SSF_WRITE_CODEC_RESET = (1 << 8)
+ SSF_WRITE_CODEC_RESET = (1 << 8),
+ SSF_DESTROYABLE = (1 << 9)
} switch_session_flag_t;
gateway_ptr = sofia_reg_find_gateway(gateway_name);
}
+ if (!tech_pvt) {
+ return SWITCH_STATUS_SUCCESS;
+ }
+
switch_mutex_lock(tech_pvt->sofia_mutex);
rec = sofia_test_flag(tech_pvt, TFLAG_RECOVERING);
int save;
switch_core_session_t *session;
switch_memory_pool_t *pool;
+ struct sofia_dispatch_event_s *next;
} sofia_dispatch_event_t;
struct sofia_private {
int is_call;
int is_static;
sofia_dispatch_event_t *de;
+ sofia_dispatch_event_t *deq;
};
#define set_param(ptr,val) if (ptr) {free(ptr) ; ptr = NULL;} if (val) {ptr = strdup(val);}
int locked = 0;
int check_destroy = 1;
- if (sofia_private && sofia_private->is_call && sofia_private->de) {
- sofia_dispatch_event_t *qde = sofia_private->de;
- sofia_private->de = NULL;
+ if (sofia_private && sofia_private->is_call) {
+ sofia_dispatch_event_t *qde = NULL;
- if (event == nua_i_cancel) {
- nua_destroy_event(qde->event);
- su_free(nh->nh_home, qde);
- } else {
+ switch_mutex_lock(profile->flag_mutex);
+ if (sofia_private->de) {
+ qde = sofia_private->de;
+ sofia_private->de = NULL;
+ }
+ switch_mutex_unlock(profile->flag_mutex);
+
+ if (qde) {
sofia_process_dispatch_event(&qde);
}
}
+ if (sofia_private && (sofia_private->destroy_me == 12)) {
+ return;
+ }
+
profile->last_sip_event = switch_time_now();
/* sofia_private will be == &mod_sofia_globals.keep_private whenever a request is done with a new handle that has to be
void sofia_process_dispatch_event(sofia_dispatch_event_t **dep)
{
- sofia_dispatch_event_t *de = *dep;
+ sofia_dispatch_event_t *de = *dep, *deq = NULL;
nua_handle_t *nh = de->nh;
nua_t *nua = de->nua;
sofia_profile_t *profile = de->profile;
-
+ sofia_private_t *sofia_private = nua_handle_magic(de->nh);
*dep = NULL;
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);
+ de->nh, sofia_private, de->sip, de, (tagi_t *) de->data->e_tags);
nua_destroy_event(de->event);
su_free(nh->nh_home, de);
switch_mutex_lock(profile->flag_mutex);
profile->queued_events--;
+ if (sofia_private && sofia_private->is_call && sofia_private->deq) {
+ deq = sofia_private->deq;
+ sofia_private->deq = NULL;
+ }
switch_mutex_unlock(profile->flag_mutex);
+
+ if (deq) {
+ for (;;) {
+ switch_mutex_lock(profile->flag_mutex);
+ if ((de = deq)) {
+ deq = deq->next;
+ de->next = NULL;
+ }
+ switch_mutex_unlock(profile->flag_mutex);
+
+ if (!de) {
+ break;
+ }
+
+ our_sofia_event_callback(de->data->e_event, de->data->e_status, de->data->e_phrase, de->nua, de->profile,
+ de->nh, sofia_private, de->sip, de, (tagi_t *) de->data->e_tags);
+
+ nua_destroy_event(de->event);
+ su_free(nh->nh_home, de);
+ nua_handle_unref(nh);
+ nua_stack_unref(nua);
+
+ }
+ }
+
nua_handle_unref(nh);
nua_stack_unref(nua);
return;
}
-
-
switch_mutex_lock(profile->flag_mutex);
profile->queued_events++;
switch_mutex_unlock(profile->flag_mutex);
memset(sofia_private, 0, sizeof(*sofia_private));
sofia_private->is_call++;
sofia_private->is_static++;
+ switch_mutex_lock(profile->flag_mutex);
sofia_private->de = de;
+ switch_mutex_unlock(profile->flag_mutex);
nua_handle_bind(nh, sofia_private);
return;
}
if (sofia_private && sofia_private != &mod_sofia_globals.destroy_private && sofia_private != &mod_sofia_globals.keep_private) {
switch_core_session_t *session;
- if (!zstr(sofia_private->uuid)) {
+ if (zstr(sofia_private->uuid)) {
+ if (sofia_private->is_call && !sofia_private->de) {
+ sofia_dispatch_event_t *dep;
+
+ switch_mutex_lock(profile->flag_mutex);
+
+ if (!sofia_private->deq) {
+ sofia_private->deq = de;
+ } else {
+ for (dep = sofia_private->deq; dep && dep->next; dep = dep->next);
+ dep->next = de;
+ }
+
+ switch_mutex_unlock(profile->flag_mutex);
+ return;
+ }
+ } else {
if ((session = switch_core_session_locate(sofia_private->uuid))) {
if (switch_core_session_running(session)) {
switch_core_session_queue_signal_data(session, de);
}
}
}
-
+
sofia_queue_message(de);
switch_os_yield();
}
}
}
- if (sofia_private) {
- sofia_private->destroy_me = 1;
- }
+ // if (sofia_private) {
+ //sofia_private->destroy_me = 1;
+ //}
}
if (session) {
profile->ib_calls++;
+
if (sess_count >= sess_max || !sofia_test_pflag(profile, PFLAG_RUNNING)) {
nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
goto fail;
nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
goto fail;
}
-
- if (!(tech_pvt = (private_object_t *) switch_core_session_alloc(session, sizeof(private_object_t)))) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
- nua_respond(nh, SIP_503_SERVICE_UNAVAILABLE, TAG_END());
- switch_core_session_destroy(&session);
- goto fail;
- }
-
+
+ tech_pvt = (private_object_t *) switch_core_session_alloc(session, sizeof(private_object_t));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_mutex_init(&tech_pvt->sofia_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
}
switch_copy_string(tech_pvt->sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid));
+ if (switch_core_session_running(session) || switch_core_session_started(session)) {
+ return;
+ }
+
if (sip && switch_core_session_thread_launch(session) == SWITCH_STATUS_SUCCESS) {
const char *dialog_from_user = "", *dialog_from_host = "", *to_user = "", *to_host = "", *contact_user = "", *contact_host = "";
const char *user_agent = "", *call_id = "";
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting NAT mode based on %s\n", is_nat);
switch_channel_set_variable(channel, "sip_nat_detected", "true");
}
+
return;
}
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());
+ if (!switch_core_session_running(session)) {
+ 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;
fail:
while (switch_queue_trypop(channel->dtmf_log_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_safe_free(pop);
}
- switch_core_hash_destroy(&channel->private_hash);
+
+ if (channel->private_hash) {
+ switch_core_hash_destroy(&channel->private_hash);
+ }
+
if (channel->app_flag_hash) {
switch_core_hash_destroy(&channel->app_flag_hash);
}
+
switch_mutex_lock(channel->profile_mutex);
switch_event_destroy(&channel->variables);
switch_event_destroy(&channel->api_list);
#ifdef DEBUG_ALLOC
if (memory > 500)
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Session Allocate %s %d\n",
- apr_pool_tag(session->pool, NULL), (int) memory);
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p %p Session Allocate %s %d\n",
+ (void *) session->pool, (void *) session, apr_pool_tag(session->pool, NULL), (int) memory);
#endif
ptr = apr_palloc(session->pool, memory);
#endif
#ifdef DEBUG_ALLOC
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Perm Allocate %s %d\n",
- apr_pool_tag(memory_manager.memory_pool, NULL), (int) memory);
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Perm Allocate %s %d\n",
+ (void *)memory_manager.memory_pool, apr_pool_tag(memory_manager.memory_pool, NULL), (int) memory);
#endif
ptr = apr_palloc(memory_manager.memory_pool, memory);
switch_assert(duped != NULL);
#ifdef DEBUG_ALLOC
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Perm Allocate %s %d\n",
- apr_pool_tag(memory_manager.memory_pool, NULL), (int) len);
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Perm Allocate %s %d\n",
+ (void *) memory_manager.memory_pool, apr_pool_tag(memory_manager.memory_pool, NULL), (int) len);
#endif
#ifdef LOCK_MORE
#ifdef DEBUG_ALLOC
len = strlen(todup);
if (len > 500)
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Sess Strdup Allocate %s %ld\n",
- apr_pool_tag(session->pool, NULL), strlen(todup));
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p %p Sess Strdup Allocate %s %ld\n",
+ (void *) session->pool, (void *)session, apr_pool_tag(session->pool, NULL), strlen(todup));
#endif
duped = apr_pstrdup(session->pool, todup);
#ifdef DEBUG_ALLOC
if (len > 500)
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Core Strdup Allocate %s %d\n",
- apr_pool_tag(pool, NULL), (int)len);
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Core Strdup Allocate %s %d\n",
+ (void *) pool, apr_pool_tag(pool, NULL), (int)len);
#endif
duped = apr_pstrmemdup(pool, todup, len);
apr_pool_tag(*pool, tmp);
#ifdef DEBUG_ALLOC2
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "New Pool %s\n", apr_pool_tag(*pool, NULL));
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p New Pool %s\n", (void *) *pool, apr_pool_tag(*pool, NULL));
#endif
switch_assert(pool != NULL);
#ifdef DEBUG_ALLOC2
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Free Pool %s\n", apr_pool_tag(*pool, NULL));
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Free Pool %s\n", (void *) *pool, apr_pool_tag(*pool, NULL));
#endif
#ifdef INSTANTLY_DESTROY_POOLS
#ifdef DEBUG_ALLOC
if (memory > 500)
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Core Allocate %s %d\n",
- apr_pool_tag(pool, NULL), (int) memory);
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Core Allocate %s %d\n",
+ (void *) pool, apr_pool_tag(pool, NULL), (int) memory);
/*switch_assert(memory < 20000); */
#endif
#ifdef USE_MEM_LOCK
switch_mutex_lock(memory_manager.mem_lock);
#endif
+
+#ifdef DEBUG_ALLOC
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%p DESTROY POOL\n", (void *) pop);
+#endif
apr_pool_destroy(pop);
#ifdef USE_MEM_LOCK
switch_mutex_unlock(memory_manager.mem_lock);
#endif
#else
apr_pool_mutex_set(pop, NULL);
+#ifdef DEBUG_ALLOC
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%p DESTROY POOL\n", (void *) pop);
+#endif
apr_pool_clear(pop);
if (switch_queue_trypush(memory_manager.pool_recycle_queue, pop) != SWITCH_STATUS_SUCCESS) {
#ifdef USE_MEM_LOCK
switch_mutex_lock(memory_manager.mem_lock);
+#endif
+#ifdef DEBUG_ALLOC
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%p DESTROY POOL\n", (void *) pop);
#endif
apr_pool_destroy(pop);
#ifdef USE_MEM_LOCK
switch_endpoint_interface_t *endpoint_interface = (*session)->endpoint_interface;
int i;
+ if (switch_core_session_running(*session) && !switch_test_flag((*session), SSF_DESTROYABLE)) {
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(*session), SWITCH_LOG_ERROR,
+ "Cowardly ignoring an attempt to call destroy on a running session.\n");
+ }
+
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(*session), SWITCH_LOG_NOTICE, "Close Channel %s [%s]\n",
switch_channel_get_name((*session)->channel), switch_channel_state_name(switch_channel_get_state((*session)->channel)));
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Session %" SWITCH_SIZE_T_FMT " (%s) Ended\n",
session->id, switch_channel_get_name(session->channel));
+
+ switch_set_flag(session, SSF_DESTROYABLE);
switch_core_session_destroy(&session);
return NULL;
}
switch_threadattr_detach_set(thd_attr, 1);
if (switch_test_flag(session, SSF_THREAD_RUNNING) || switch_test_flag(session, SSF_THREAD_STARTED)) {
+ status = SWITCH_STATUS_INUSE;
goto end;
}
const switch_state_handler_table_t *driver_state_handler = NULL;
const switch_state_handler_table_t *application_state_handler = NULL;
int silly = 0;
- uint32_t new_loops = 60000;
+ uint32_t new_loops = 5000;
/*
Life of the channel. you have channel and pool in your session