]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 5 Nov 2008 00:20:30 +0000 (00:20 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 5 Nov 2008 00:20:30 +0000 (00:20 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10244 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/private/switch_core_pvt.h
src/include/switch_apr.h
src/include/switch_core.h
src/include/switch_types.h
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/switch_apr.c
src/switch_core_hash.c
src/switch_core_session.c
src/switch_loadable_module.c

index b19c65e956da5c35ef1c9c91206295548f2b85b4..542899f3cf43ee4745a511c075bca79e218fe9d3 100644 (file)
@@ -52,9 +52,6 @@
 #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>
index 75cc0a09c882dc144aaa6afaf9796e269a82306c..a35b1d2810700762cac60fecaa4a9074da8b1fd5 100644 (file)
 #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.
index edcddac5298be1e7c97a468f36cbde49e6a4c32d..25d06c647ba02bd78ed3ecff1dc92b82363ceb4b 100644 (file)
@@ -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
index 7adb22add8c782de9658dc45f76a505ae165ced7..34e05da683f4bf6ec44c0a00ee29795dc6d8f381 100644 (file)
@@ -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;
 
 
index 0093301575b85b243a65b35ae9479106aae65cfd..8da4f5bea102f2fbf66193412d4c0063d63ef846 100644 (file)
@@ -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:
index 80bc933aa39e09dfc0754eef3812e7dc78256914..6484959343c8873bfbdbf315cc03d6abb74a1853 100644 (file)
@@ -504,6 +504,7 @@ struct private_object {
        int remote_port;
        int got_bye;
        int hold_laps;
+       switch_thread_id_t locker;
 };
 
 struct callback_t {
index 314e0a9223835baf09c8e624d7be312c7a867bbe..7a26b85c1cae39456c16a49f339ae20fe9ebdec8 100644 (file)
@@ -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)
index f2c644779db03eebcd60f56e2705b5392cf3a910..4583d7a5565438daf324782ec2cb3cfbcbd4e33b 100644 (file)
 
 /* 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);
index 8f4b3539852d817165268ef0e62bad7db2ae24ed..007d50363e5fea03cb7944cb83a7431a87017e2f 100644 (file)
@@ -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;
index 6475af16b0ebe8686527f18be6e39e5e469f8393..275a54b759a7daeed73516f25f42fb41b64a9088 100644 (file)
@@ -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);
 
index 43401881e90ebb9b254c0b1137ce2ccee8b1734a..bf611aab7f0646ab85191fe25f61a1ca8b17f748 100644 (file)
@@ -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);