提交 1be5b1ff authored 作者: Anthony Minessale's avatar Anthony Minessale

general improvements

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5078 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 9d5d2519
......@@ -818,6 +818,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(switch_hash_t * hash);
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(switch_hash_t * hash, const char *key, const void *data);
/*!
\brief Insert data into a hash
\param hash the hash to add data to
\param key the name of the key to add the data to
\param data the data to add
\param mutex optional mutex to lock
\return SWITCH_STATUS_SUCCESS if the data is added
\note the string key must be a constant or a dynamic string
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(switch_hash_t * hash, const char *key, const void *data, switch_mutex_t *mutex);
/*!
\brief Insert data into a hash with dynamicly allocated key name
\param hash the hash to add data to
......@@ -827,6 +838,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(switch_hash_t * hash, co
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_dup(switch_hash_t * hash, const char *key, const void *data);
/*!
\brief Insert data into a hash with dynamicly allocated key name
\param hash the hash to add data to
\param key the name of the key to add the data to
\param data the data to add
\param mutex optional mutex to lock
\return SWITCH_STATUS_SUCCESS if the data is added
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_dup_locked(switch_hash_t * hash, const char *key, const void *data, switch_mutex_t *mutex);
/*!
\brief Delete data from a hash based on desired key
\param hash the hash to delete from
......@@ -835,6 +856,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_dup(switch_hash_t * hash
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(switch_hash_t * hash, const char *key);
/*!
\brief Delete data from a hash based on desired key
\param hash the hash to delete from
\param key the key from which to delete the data
\param mutex optional mutex to lock
\return SWITCH_STATUS_SUCCESS if the data is deleted
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(switch_hash_t * hash, const char *key, switch_mutex_t *mutex);
/*!
\brief Retrieve data from a given hash
\param hash the hash to retrieve from
......@@ -842,6 +872,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(switch_hash_t * hash, co
\return a pointer to the data held in the key
*/
SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash_t * hash, const char *key);
/*!
\brief Retrieve data from a given hash
\param hash the hash to retrieve from
\param key the key to retrieve
\param mutex optional mutex to lock
\return a pointer to the data held in the key
*/
SWITCH_DECLARE(void *) switch_core_hash_find_locked(switch_hash_t * hash, const char *key, switch_mutex_t *mutex);
///\}
///\defgroup timer Timer Functions
......
......@@ -228,15 +228,24 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_
*/
SWITCH_DECLARE(switch_status_t) switch_api_execute(char *cmd, char *arg, switch_core_session_t *session, switch_stream_handle_t *stream);
/*!
\brief Load a module
\param dir the directory where the module resides
\param fname the file name of the module
\param runtime option to start the runtime thread if it exists
\param err pointer to error message
\return the status
*/
SWITCH_DECLARE(switch_status_t) switch_loadable_module_load_module(char *dir, char *fname, switch_bool_t runtime, const char **err);
/*!
\brief Unoad a module
\param dir the directory where the module resides
\param fname the file name of the module
\param err pointer to error message
\return the status
*/
SWITCH_DECLARE(switch_status_t) switch_loadable_module_load_module(char *dir, char *fname, switch_bool_t runtime);
SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir, char *fname, const char **err);
/* Prototypes of module interface functions */
......
......@@ -420,6 +420,7 @@ typedef enum {
SWITCH_STATUS_MORE_DATA - Need More Data
SWITCH_STATUS_NOTFOUND - Not Found
SWITCH_STATUS_UNLOAD - Unload
SWITCH_STATUS_NOUNLOAD - Never Unload
</pre>
*/
typedef enum {
......@@ -438,7 +439,8 @@ typedef enum {
SWITCH_STATUS_SOCKERR,
SWITCH_STATUS_MORE_DATA,
SWITCH_STATUS_NOTFOUND,
SWITCH_STATUS_UNLOAD
SWITCH_STATUS_UNLOAD,
SWITCH_STATUS_NOUNLOAD
} switch_status_t;
......@@ -816,6 +818,7 @@ typedef enum {
SWITCH_EVENT_NOTALK - Not Talking Detected
SWITCH_EVENT_SESSION_CRASH - Session Crashed
SWITCH_EVENT_MODULE_LOAD - Module was loaded
SWITCH_EVENT_MODULE_UNLOAD - Module was unloaded
SWITCH_EVENT_DTMF - DTMF was sent
SWITCH_EVENT_MESSAGE - A Basic Message
SWITCH_EVENT_PRESENCE_IN - Presence in
......@@ -863,6 +866,7 @@ typedef enum {
SWITCH_EVENT_NOTALK,
SWITCH_EVENT_SESSION_CRASH,
SWITCH_EVENT_MODULE_LOAD,
SWITCH_EVENT_MODULE_UNLOAD,
SWITCH_EVENT_DTMF,
SWITCH_EVENT_MESSAGE,
SWITCH_EVENT_PRESENCE_IN,
......
......@@ -46,6 +46,7 @@ static switch_api_interface_t show_api_interface;
static switch_api_interface_t pause_api_interface;
static switch_api_interface_t transfer_api_interface;
static switch_api_interface_t load_api_interface;
static switch_api_interface_t unload_api_interface;
static switch_api_interface_t reload_api_interface;
static switch_api_interface_t kill_api_interface;
static switch_api_interface_t originate_api_interface;
......@@ -150,6 +151,7 @@ static switch_status_t ctl_function(char *data, switch_core_session_t *session,
static switch_status_t load_function(char *mod, switch_core_session_t *session, switch_stream_handle_t *stream)
{
const char *err;
if (session) {
return SWITCH_STATUS_FALSE;
......@@ -160,10 +162,32 @@ static switch_status_t load_function(char *mod, switch_core_session_t *session,
return SWITCH_STATUS_SUCCESS;
}
if (switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
if (switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod, SWITCH_TRUE, &err) == SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "OK\n");
} else {
stream->write_function(stream, "ERROR\n");
stream->write_function(stream, "ERROR [%s]\n", err);
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unload_function(char *mod, switch_core_session_t *session, switch_stream_handle_t *stream)
{
const char *err;
if (session) {
return SWITCH_STATUS_FALSE;
}
if (switch_strlen_zero(mod)) {
stream->write_function(stream, "USAGE: %s\n", unload_api_interface.syntax);
return SWITCH_STATUS_SUCCESS;
}
if (switch_loadable_module_unload_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod, &err) == SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "OK\n");
} else {
stream->write_function(stream, "ERROR [%s]\n", err);
}
return SWITCH_STATUS_SUCCESS;
......@@ -1221,12 +1245,20 @@ static switch_api_interface_t load_api_interface = {
/*.next */ &transfer_api_interface
};
static switch_api_interface_t unload_api_interface = {
/*.interface_name */ "unload",
/*.desc */ "Unoad Module",
/*.function */ unload_function,
/*.syntax */ "<mod_name>",
/*.next */ &load_api_interface
};
static switch_api_interface_t reload_api_interface = {
/*.interface_name */ "reloadxml",
/*.desc */ "Reload XML",
/*.function */ reload_function,
/*.syntax */ "",
/*.next */ &load_api_interface,
/*.next */ &unload_api_interface,
};
......@@ -1263,7 +1295,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
*module_interface = &mod_commands_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_NOUNLOAD;
}
/* For Emacs:
......
......@@ -1565,11 +1565,14 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
#endif
#ifdef SWITCH_HAVE_ODBC
return profile->master_odbc ? 1 : 0;
#else
return 1;
if (profile->odbc_dsn) {
return profile->master_odbc ? 1 : 0;
}
#endif
return profile->master_db ? 1: 0;
}
void sofia_glue_sql_close(sofia_profile_t *profile)
......
......@@ -57,19 +57,83 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_dup(switch_hash_t * hash
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_dup_locked(switch_hash_t * hash, const char *key, const void *data, switch_mutex_t *mutex)
{
if (mutex) {
switch_mutex_lock(mutex);
}
apr_hash_set(hash, switch_core_strdup(apr_hash_pool_get(hash), key), APR_HASH_KEY_STRING, data);
if (mutex) {
switch_mutex_unlock(mutex);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(switch_hash_t * hash, const char *key, const void *data)
{
apr_hash_set(hash, key, APR_HASH_KEY_STRING, data);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(switch_hash_t * hash, const char *key, const void *data, switch_mutex_t *mutex)
{
if (mutex) {
switch_mutex_lock(mutex);
}
apr_hash_set(hash, key, APR_HASH_KEY_STRING, data);
if (mutex) {
switch_mutex_unlock(mutex);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(switch_hash_t * hash, const char *key)
{
apr_hash_set(hash, key, APR_HASH_KEY_STRING, NULL);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(switch_hash_t * hash, const char *key, switch_mutex_t *mutex)
{
if (mutex) {
switch_mutex_lock(mutex);
}
apr_hash_set(hash, key, APR_HASH_KEY_STRING, NULL);
if (mutex) {
switch_mutex_unlock(mutex);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash_t * hash, const char *key)
{
return apr_hash_get(hash, key, APR_HASH_KEY_STRING);
}
SWITCH_DECLARE(void *) switch_core_hash_find_locked(switch_hash_t * hash, const char *key, switch_mutex_t *mutex)
{
void *val;
if (mutex) {
switch_mutex_lock(mutex);
}
val = apr_hash_get(hash, key, APR_HASH_KEY_STRING);
if (mutex) {
switch_mutex_unlock(mutex);
}
return val;
}
......@@ -121,6 +121,7 @@ static char *EVENT_NAMES[] = {
"NOTALK",
"SESSION_CRASH",
"MODULE_LOAD",
"MODULE_UNLOAD",
"DTMF",
"MESSAGE",
"PRESENCE_IN",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论