From c217d45cf0b66060b4d273f08ebc2bbb4e7ead04 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 5 Nov 2008 00:20:30 +0000 Subject: [PATCH] update git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10244 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/private/switch_core_pvt.h | 3 -- src/include/switch_apr.h | 10 ++++++ src/include/switch_core.h | 15 +++++++-- src/include/switch_types.h | 3 +- src/mod/endpoints/mod_sofia/mod_sofia.c | 25 +++++++++----- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 13 ++++++-- src/switch_apr.c | 5 +++ src/switch_core_hash.c | 4 +-- src/switch_core_session.c | 44 ++++++++++++++++++++++++- src/switch_loadable_module.c | 24 +++++++------- 11 files changed, 114 insertions(+), 33 deletions(-) diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index b19c65e956..542899f3cf 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -52,9 +52,6 @@ #include #include -typedef apr_os_thread_t switch_thread_id_t; -#define switch_thread_self apr_os_thread_current - #ifdef HAVE_MLOCKALL #include diff --git a/src/include/switch_apr.h b/src/include/switch_apr.h index 75cc0a09c8..a35b1d2810 100644 --- a/src/include/switch_apr.h +++ b/src/include/switch_apr.h @@ -40,6 +40,16 @@ #define SWITCH_APR_H SWITCH_BEGIN_EXTERN_C + +#ifdef WIN32 +typedef HANDLE switch_thread_id_t; +#else +typedef pthread_t switch_thread_id_t; +#endif + +SWITCH_DECLARE(switch_thread_id_t) switch_thread_self(void); + + /* The pieces of apr we allow ppl to pass around between modules we typedef into our namespace and wrap all the functions any other apr code should be as hidden as possible. diff --git a/src/include/switch_core.h b/src/include/switch_core.h index edcddac529..25d06c647b 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -89,6 +89,9 @@ struct switch_core_session_message { switch_size_t pointer_reply_size; /*! message flags */ switch_core_session_message_flag_t flags; + const char *_file; + const char *_func; + int _line; }; /*! \brief A generic object to pass as a thread's session object to allow mutiple arguements and a pool */ @@ -777,7 +780,11 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(_In_z_ \param message the message to recieve \return the status returned by the message handler */ -SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(_In_ switch_core_session_t *session, _In_ switch_core_session_message_t *message); +SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(_In_ switch_core_session_t *session, + _In_ switch_core_session_message_t *message, + const char *file, const char *func, int line); +#define switch_core_session_receive_message(_session, _message) switch_core_session_perform_receive_message(_session, _message, \ + __FILE__, __SWITCH_FUNC__, __LINE__) /*! \brief Queue an event on a given session @@ -927,7 +934,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(_In_ switch_core_s \param pool the pool to use for the new hash \return SWITCH_STATUS_SUCCESS if the hash is created */ -SWITCH_DECLARE(switch_status_t) switch_core_hash_init(_Out_ switch_hash_t **hash, _In_ switch_memory_pool_t *pool); +SWITCH_DECLARE(switch_status_t) switch_core_hash_init_case(_Out_ switch_hash_t **hash, _In_ switch_memory_pool_t *pool, switch_bool_t case_sensitive); +#define switch_core_hash_init(_hash, _pool) switch_core_hash_init_case(_hash, _pool, SWITCH_TRUE); +#define switch_core_hash_init_nocase(_hash, _pool) switch_core_hash_init_case(_hash, _pool, SWITCH_FALSE); + + /*! \brief Destroy an existing hash table diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 7adb22add8..34e05da683 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -565,7 +565,8 @@ typedef enum { SWITCH_MESSAGE_INDICATE_DEFLECT, SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ, SWITCH_MESSAGE_INDICATE_DISPLAY, - SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY + SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY, + SWITCH_MESSAGE_INVALID } switch_core_session_message_types_t; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 0093301575..8da4f5bea1 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -868,9 +868,15 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi default: break; } - + /* ones that do need to lock sofia mutex */ switch_mutex_lock(tech_pvt->sofia_mutex); + + if (switch_channel_get_state(channel) >= CS_HANGUP || !tech_pvt) { + status = SWITCH_STATUS_FALSE; + goto end_lock; + } + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ: { @@ -958,7 +964,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); status = SWITCH_STATUS_FALSE; - goto end; + goto end_lock; } send_invite = 0; } @@ -968,7 +974,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi sofia_glue_tech_prepare_codecs(tech_pvt); if ((status = sofia_glue_tech_choose_port(tech_pvt, 0)) != SWITCH_STATUS_SUCCESS) { switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - goto end; + goto end_lock; } } sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 1); @@ -1098,7 +1104,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi msg->message_id = SWITCH_MESSAGE_INDICATE_REDIRECT; msg->string_arg = p; switch_core_session_receive_message(session, msg); - goto end; + goto end_lock; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Responding with %d [%s]\n", code, reason); @@ -1152,7 +1158,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi sofia_glue_tech_patch_sdp(tech_pvt); if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) { status = SWITCH_STATUS_FALSE; - goto end; + goto end_lock; } } } else { @@ -1165,18 +1171,16 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi sofia_glue_tech_prepare_codecs(tech_pvt); if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); - //switch_mutex_lock(tech_pvt->sofia_mutex); //nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); - //switch_mutex_unlock(tech_pvt->sofia_mutex); status = SWITCH_STATUS_FALSE; - goto end; + goto end_lock; } } } if ((status = sofia_glue_tech_choose_port(tech_pvt, 0)) != SWITCH_STATUS_SUCCESS) { switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - goto end; + goto end_lock; } sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0); if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) { @@ -1212,6 +1216,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi default: break; } + + end_lock: + switch_mutex_unlock(tech_pvt->sofia_mutex); end: diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 80bc933aa3..6484959343 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -504,6 +504,7 @@ struct private_object { int remote_port; int got_bye; int hold_laps; + switch_thread_id_t locker; }; struct callback_t { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 314e0a9223..7a26b85c1c 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -170,6 +170,7 @@ void sofia_event_callback(nua_event_t event, switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; sofia_gateway_t *gateway = NULL; + int locked = 0; if (sofia_private && sofia_private != &mod_sofia_globals.destroy_private && sofia_private != &mod_sofia_globals.keep_private) { if ((gateway = sofia_private->gateway)) { @@ -203,12 +204,15 @@ void sofia_event_callback(nua_event_t event, } if (session) { - switch_mutex_lock(tech_pvt->sofia_mutex); - if (channel && switch_channel_get_state(channel) >= CS_HANGUP) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is already hungup.\n"); goto done; } + + if (tech_pvt) { + switch_mutex_lock(tech_pvt->sofia_mutex); + locked = 1; + } } else if (sofia_private && sofia_private->is_call) { sofia_private->destroy_me = 22; } @@ -360,9 +364,12 @@ void sofia_event_callback(nua_event_t event, } if (session) { - switch_mutex_unlock(tech_pvt->sofia_mutex); switch_core_session_rwunlock(session); } + + if (tech_pvt && locked) { + switch_mutex_unlock(tech_pvt->sofia_mutex); + } } void event_handler(switch_event_t *event) diff --git a/src/switch_apr.c b/src/switch_apr.c index f2c644779d..4583d7a556 100644 --- a/src/switch_apr.c +++ b/src/switch_apr.c @@ -69,6 +69,11 @@ /* Memory Pools */ +SWITCH_DECLARE(switch_thread_id_t) switch_thread_self(void) +{ + return apr_os_thread_current(); +} + SWITCH_DECLARE(void) switch_pool_clear(switch_memory_pool_t *p) { apr_pool_clear(p); diff --git a/src/switch_core_hash.c b/src/switch_core_hash.c index 8f4b353985..007d50363e 100644 --- a/src/switch_core_hash.c +++ b/src/switch_core_hash.c @@ -41,14 +41,14 @@ struct switch_hash { Hash table; }; -SWITCH_DECLARE(switch_status_t) switch_core_hash_init(switch_hash_t **hash, switch_memory_pool_t *pool) +SWITCH_DECLARE(switch_status_t) switch_core_hash_init_case(switch_hash_t **hash, switch_memory_pool_t *pool, switch_bool_t case_sensitive) { switch_hash_t *newhash; newhash = switch_core_alloc(pool, sizeof(*newhash)); switch_assert(newhash); - sqlite3HashInit(&newhash->table, SQLITE_HASH_BINARY, 1); + sqlite3HashInit(&newhash->table, case_sensitive ? SQLITE_HASH_BINARY : SQLITE_HASH_STRING, 1); *hash = newhash; return SWITCH_STATUS_SUCCESS; diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 6475af16b0..275a54b759 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -413,7 +413,33 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_ return cause; } -SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_session_t *session, switch_core_session_message_t *message) +static const char *message_names[] = { + "SWITCH_MESSAGE_REDIRECT_AUDIO", + "SWITCH_MESSAGE_TRANSMIT_TEXT", + "SWITCH_MESSAGE_INDICATE_ANSWER", + "SWITCH_MESSAGE_INDICATE_PROGRESS", + "SWITCH_MESSAGE_INDICATE_BRIDGE", + "SWITCH_MESSAGE_INDICATE_UNBRIDGE", + "SWITCH_MESSAGE_INDICATE_TRANSFER", + "SWITCH_MESSAGE_INDICATE_RINGING", + "SWITCH_MESSAGE_INDICATE_MEDIA", + "SWITCH_MESSAGE_INDICATE_NOMEDIA", + "SWITCH_MESSAGE_INDICATE_HOLD", + "SWITCH_MESSAGE_INDICATE_UNHOLD", + "SWITCH_MESSAGE_INDICATE_REDIRECT", + "SWITCH_MESSAGE_INDICATE_RESPOND", + "SWITCH_MESSAGE_INDICATE_BROADCAST", + "SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT", + "SWITCH_MESSAGE_INDICATE_DEFLECT", + "SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ", + "SWITCH_MESSAGE_INDICATE_DISPLAY", + "SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY", + "SWITCH_MESSAGE_INVALID" +}; + +SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(switch_core_session_t *session, + switch_core_session_message_t *message, + const char *file, const char *func, int line) { switch_io_event_hook_receive_message_t *ptr; switch_status_t status = SWITCH_STATUS_SUCCESS; @@ -428,6 +454,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_ return status; } + message->_file = file; + message->_func = func; + message->_line = line; + + if (message->message_id > SWITCH_MESSAGE_INVALID) { + message->message_id = SWITCH_MESSAGE_INVALID; + } + + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, "%s receive message [%s]\n", + switch_channel_get_name(session->channel), message_names[message->message_id]); + if (session->endpoint_interface->io_routines->receive_message) { status = session->endpoint_interface->io_routines->receive_message(session, message); } @@ -440,6 +477,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_ } } + message->_file = NULL; + message->_func = NULL; + message->_line = 0; + + switch_core_session_kill_channel(session, SWITCH_SIG_BREAK); switch_core_session_rwunlock(session); diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 43401881e9..bf611aab7f 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -1020,19 +1020,19 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init() #endif switch_core_hash_init(&loadable_modules.module_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.endpoint_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.codec_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.timer_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.application_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.api_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.endpoint_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.codec_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.timer_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.application_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.api_hash, loadable_modules.pool); switch_core_hash_init(&loadable_modules.file_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.speech_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.asr_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.directory_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.chat_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.say_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.management_hash, loadable_modules.pool); - switch_core_hash_init(&loadable_modules.dialplan_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.speech_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.asr_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.directory_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.chat_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.say_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.management_hash, loadable_modules.pool); + switch_core_hash_init_nocase(&loadable_modules.dialplan_hash, loadable_modules.pool); switch_mutex_init(&loadable_modules.mutex, SWITCH_MUTEX_NESTED, loadable_modules.pool); switch_loadable_module_load_module("", "CORE_SOFTTIMER_MODULE", SWITCH_FALSE, &err);