#include <apr_general.h>
#include <apr_portable.h>
-typedef apr_os_thread_t switch_thread_id_t;
-#define switch_thread_self apr_os_thread_current
-
#ifdef HAVE_MLOCKALL
#include <sys/mman.h>
#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.
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 */
\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
\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
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;
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:
{
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;
}
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);
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);
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 {
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) {
default:
break;
}
+
+ end_lock:
+
switch_mutex_unlock(tech_pvt->sofia_mutex);
end:
int remote_port;
int got_bye;
int hold_laps;
+ switch_thread_id_t locker;
};
struct callback_t {
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)) {
}
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;
}
}
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)
/* 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);
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;
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;
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);
}
}
}
+ message->_file = NULL;
+ message->_func = NULL;
+ message->_line = 0;
+
+
switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
switch_core_session_rwunlock(session);
#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);