提交 99e22d69 authored 作者: Anthony Minessale's avatar Anthony Minessale

refactor earlier junk from this eve and add ken's propagate variable thing

set this sometime before an origination (bridge etc).

<action application="set" data="propagate_vars=my_cool_var1,my_cool_var2,foo,bar"/>

and they should be cloned over to the new channel when it's substantiated



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3101 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 80f91a58
...@@ -73,6 +73,8 @@ struct switch_loadable_module_interface { ...@@ -73,6 +73,8 @@ struct switch_loadable_module_interface {
const switch_speech_interface_t *speech_interface; const switch_speech_interface_t *speech_interface;
/*! the table of directory interfaces the module has implmented */ /*! the table of directory interfaces the module has implmented */
const switch_directory_interface_t *directory_interface; const switch_directory_interface_t *directory_interface;
/*! the table of chat interfaces the module has implmented */
const switch_chat_interface_t *chat_interface;
}; };
/*! /*!
...@@ -163,6 +165,13 @@ SWITCH_DECLARE(switch_speech_interface_t *) switch_loadable_module_get_speech_in ...@@ -163,6 +165,13 @@ SWITCH_DECLARE(switch_speech_interface_t *) switch_loadable_module_get_speech_in
*/ */
SWITCH_DECLARE(switch_directory_interface_t *) switch_loadable_module_get_directory_interface(char *name); SWITCH_DECLARE(switch_directory_interface_t *) switch_loadable_module_get_directory_interface(char *name);
/*!
\brief Retrieve the chat interface by it's registered name
\param name the name of the chat interface
\return the desired chat interface
*/
SWITCH_DECLARE(switch_chat_interface_t *) switch_loadable_module_get_chat_interface(char *name);
/*! /*!
\brief Retrieve the list of loaded codecs into an array \brief Retrieve the list of loaded codecs into an array
......
...@@ -366,6 +366,14 @@ struct switch_speech_handle { ...@@ -366,6 +366,14 @@ struct switch_speech_handle {
}; };
/*! \brief Abstract interface to a chat module */
struct switch_chat_interface {
/*! the name of the interface */
const char *interface_name;
/*! function to open the directory interface */
switch_status_t (*chat_send)(char *from, char *to, char *subject, char *body, char *hint);
const struct switch_chat_interface *next;
};
/*! \brief Abstract interface to a directory module */ /*! \brief Abstract interface to a directory module */
struct switch_directory_interface { struct switch_directory_interface {
......
...@@ -780,6 +780,7 @@ typedef struct switch_api_interface switch_api_interface_t; ...@@ -780,6 +780,7 @@ typedef struct switch_api_interface switch_api_interface_t;
typedef struct switch_file_interface switch_file_interface_t; typedef struct switch_file_interface switch_file_interface_t;
typedef struct switch_speech_interface switch_speech_interface_t; typedef struct switch_speech_interface switch_speech_interface_t;
typedef struct switch_directory_interface switch_directory_interface_t; typedef struct switch_directory_interface switch_directory_interface_t;
typedef struct switch_chat_interface switch_chat_interface_t;
typedef struct switch_core_port_allocator switch_core_port_allocator_t; typedef struct switch_core_port_allocator switch_core_port_allocator_t;
typedef struct switch_media_bug switch_media_bug_t; typedef struct switch_media_bug switch_media_bug_t;
typedef void (*switch_media_bug_callback_t)(switch_media_bug_t *, void *, switch_abc_type_t); typedef void (*switch_media_bug_callback_t)(switch_media_bug_t *, void *, switch_abc_type_t);
......
...@@ -34,11 +34,11 @@ ...@@ -34,11 +34,11 @@
#define DL_CAND_WAIT 10000000 #define DL_CAND_WAIT 10000000
#define DL_CAND_INITIAL_WAIT 2000000 #define DL_CAND_INITIAL_WAIT 2000000
#define JINGLE_KEY 1
#define DL_EVENT_LOGIN_SUCCESS "dingaling::login_success" #define DL_EVENT_LOGIN_SUCCESS "dingaling::login_success"
#define DL_EVENT_LOGIN_FAILURE "dingaling::login_failure" #define DL_EVENT_LOGIN_FAILURE "dingaling::login_failure"
#define DL_EVENT_CONNECTED "dingaling::connected" #define DL_EVENT_CONNECTED "dingaling::connected"
#define MDL_CHAT_NAME "jingle"
static const char modname[] = "mod_dingaling"; static const char modname[] = "mod_dingaling";
...@@ -235,9 +235,6 @@ static void pres_event_handler(switch_event_t *event) ...@@ -235,9 +235,6 @@ static void pres_event_handler(switch_event_t *event)
switch_core_db_t *db; switch_core_db_t *db;
char *p; char *p;
if (event->key == JINGLE_KEY) {
return;
}
if (status && !strcasecmp(status, "n/a")) { if (status && !strcasecmp(status, "n/a")) {
status = show; status = show;
...@@ -295,11 +292,8 @@ static void pres_event_handler(switch_event_t *event) ...@@ -295,11 +292,8 @@ static void pres_event_handler(switch_event_t *event)
switch_safe_free(sql); switch_safe_free(sql);
} }
static void chat_event_handler(switch_event_t *event) static switch_status_t chat_send(char *from, char *to, char *subject, char *body, char *hint)
{ {
char *from = switch_event_get_header(event, "from");
char *to = switch_event_get_header(event, "to");
char *body = switch_event_get_body(event);
char *user, *host, *f_user, *f_host = NULL; char *user, *host, *f_user, *f_host = NULL;
struct mdl_profile *profile = NULL; struct mdl_profile *profile = NULL;
...@@ -318,13 +312,14 @@ static void chat_event_handler(switch_event_t *event) ...@@ -318,13 +312,14 @@ static void chat_event_handler(switch_event_t *event)
ldl_handle_send_msg(profile->handle, from, to, NULL, body); ldl_handle_send_msg(profile->handle, from, to, NULL, body);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile %s\n", f_host ? f_host : "NULL"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile %s\n", f_host ? f_host : "NULL");
return; return SWITCH_STATUS_FALSE;
} }
switch_safe_free(f_host); switch_safe_free(f_host);
free(user); free(user);
} }
return SWITCH_STATUS_SUCCESS;
} }
...@@ -339,9 +334,6 @@ static void roster_event_handler(switch_event_t *event) ...@@ -339,9 +334,6 @@ static void roster_event_handler(switch_event_t *event)
char *sql; char *sql;
switch_core_db_t *db; switch_core_db_t *db;
if (event->key == JINGLE_KEY) {
return;
}
if (status && !strcasecmp(status, "n/a")) { if (status && !strcasecmp(status, "n/a")) {
status = show; status = show;
...@@ -1252,7 +1244,10 @@ static switch_api_interface_t login_api_interface = { ...@@ -1252,7 +1244,10 @@ static switch_api_interface_t login_api_interface = {
/*.next */ &logout_api_interface /*.next */ &logout_api_interface
}; };
static const switch_chat_interface_t channel_chat_interface = {
/*.name */ MDL_CHAT_NAME,
/*.chat_send */ chat_send,
};
static const switch_loadable_module_interface_t channel_module_interface = { static const switch_loadable_module_interface_t channel_module_interface = {
/*.module_name */ modname, /*.module_name */ modname,
...@@ -1261,7 +1256,12 @@ static const switch_loadable_module_interface_t channel_module_interface = { ...@@ -1261,7 +1256,12 @@ static const switch_loadable_module_interface_t channel_module_interface = {
/*.dialplan_interface */ NULL, /*.dialplan_interface */ NULL,
/*.codec_interface */ NULL, /*.codec_interface */ NULL,
/*.application_interface */ NULL, /*.application_interface */ NULL,
/*.api_interface */ &login_api_interface /*.api_interface */ &login_api_interface,
/*.file_interface */ NULL,
/*.speech_interface */ NULL,
/*.directory_interface */ NULL,
/*.chat_interface */ &channel_chat_interface
}; };
...@@ -1427,11 +1427,6 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod ...@@ -1427,11 +1427,6 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
if (switch_event_bind((char *) modname, SWITCH_EVENT_MESSAGE, SWITCH_EVENT_SUBCLASS_ANY, chat_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
/* connect my internal structure to the blank pointer passed to me */ /* connect my internal structure to the blank pointer passed to me */
*module_interface = &channel_module_interface; *module_interface = &channel_module_interface;
...@@ -1828,50 +1823,55 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi ...@@ -1828,50 +1823,55 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
break; break;
case LDL_SIGNAL_ROSTER: case LDL_SIGNAL_ROSTER:
if (switch_event_create(&event, SWITCH_EVENT_ROSTER) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_ROSTER) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "jingle"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_NAME);
//event->key = JINGLE_KEY; switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", from);
switch_event_fire(&event); switch_event_fire(&event);
} }
break; break;
case LDL_SIGNAL_PRESENCE_IN: case LDL_SIGNAL_PRESENCE_IN:
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "jingle"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_NAME);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", from); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", from);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "%s", subject); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "%s", subject);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "show", "%s", msg); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "show", "%s", msg);
//event->key = JINGLE_KEY;
switch_event_fire(&event); switch_event_fire(&event);
} }
break; break;
case LDL_SIGNAL_PRESENCE_OUT: case LDL_SIGNAL_PRESENCE_OUT:
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "jingle"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_NAME);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", from); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", from);
//event->key = JINGLE_KEY;
switch_event_fire(&event); switch_event_fire(&event);
} }
break; break;
case LDL_SIGNAL_MSG: case LDL_SIGNAL_MSG: {
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) { switch_chat_interface_t *ci;
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "jingle"); char *proto = MDL_CHAT_NAME;
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login); char *pproto = NULL;
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", from);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "to", "%s", to);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "subject", "%s", subject);
event->key = JINGLE_KEY;
if (msg) {
switch_event_add_body(event, msg);
}
if (profile->auto_reply) { if (profile->auto_reply) {
ldl_handle_send_msg(handle, (profile->user_flags & LDL_FLAG_COMPONENT) ? to : profile->login, from, "", profile->auto_reply); ldl_handle_send_msg(handle, (profile->user_flags & LDL_FLAG_COMPONENT) ? to : profile->login, from, "", profile->auto_reply);
} }
switch_event_fire(&event); if (strchr(to, '+')) {
pproto = strdup(to);
if ((to = strchr(pproto, '+'))) {
*to++ = '\0';
}
proto = pproto;
} }
if ((ci = switch_loadable_module_get_chat_interface(proto))) {
ci->chat_send(from, to, subject, msg, "");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invaid Chat Interface [%s]!\n", proto);
}
switch_safe_free(pproto);
}
break; break;
case LDL_SIGNAL_LOGIN_SUCCESS: case LDL_SIGNAL_LOGIN_SUCCESS:
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, DL_EVENT_LOGIN_SUCCESS) == SWITCH_STATUS_SUCCESS) { if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, DL_EVENT_LOGIN_SUCCESS) == SWITCH_STATUS_SUCCESS) {
...@@ -1971,7 +1971,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi ...@@ -1971,7 +1971,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
} }
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "jingle"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_NAME);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->login);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", from); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", from);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "to", "%s", to); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "to", "%s", to);
......
...@@ -1375,11 +1375,31 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_outgoing_channel(switch_core ...@@ -1375,11 +1375,31 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_outgoing_channel(switch_core
} }
if (channel && peer_channel) { if (channel && peer_channel) {
char *propagate_vars;
/* A comma (,) separated list of variable names that should ne propagated from originator to originatee */
if ((propagate_vars = switch_channel_get_variable(channel, "propagate_vars"))) {
char *cptmp = switch_core_session_strdup(session, propagate_vars);
int argc;
char *argv[256];
if ((argc = switch_separate_string(cptmp, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
int x;
for (x = 0; x < argc; x++) {
char *val;
if ((val = switch_channel_get_variable(channel, argv[x]))) {
switch_channel_set_variable(peer_channel, argv[x], val);
}
}
}
}
if (profile) { if (profile) {
if ((cloned_profile = switch_caller_profile_clone(*new_session, profile)) != 0) { if ((cloned_profile = switch_caller_profile_clone(*new_session, profile)) != 0) {
switch_channel_set_originator_caller_profile(peer_channel, cloned_profile); switch_channel_set_originator_caller_profile(peer_channel, cloned_profile);
} }
} }
if (peer_profile) { if (peer_profile) {
if (session && (cloned_profile = switch_caller_profile_clone(session, peer_profile)) != 0) { if (session && (cloned_profile = switch_caller_profile_clone(session, peer_profile)) != 0) {
switch_channel_set_originatee_caller_profile(channel, cloned_profile); switch_channel_set_originatee_caller_profile(channel, cloned_profile);
......
...@@ -52,6 +52,7 @@ struct switch_loadable_module_container { ...@@ -52,6 +52,7 @@ struct switch_loadable_module_container {
switch_hash_t *file_hash; switch_hash_t *file_hash;
switch_hash_t *speech_hash; switch_hash_t *speech_hash;
switch_hash_t *directory_hash; switch_hash_t *directory_hash;
switch_hash_t *chat_hash;
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
}; };
...@@ -230,6 +231,20 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable ...@@ -230,6 +231,20 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
switch_core_hash_insert(loadable_modules.directory_hash, (char *) ptr->interface_name, (void *) ptr); switch_core_hash_insert(loadable_modules.directory_hash, (char *) ptr->interface_name, (void *) ptr);
} }
} }
if (new_module->module_interface->chat_interface) {
const switch_chat_interface_t *ptr;
for (ptr = new_module->module_interface->chat_interface; ptr; ptr = ptr->next) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Chat interface '%s'\n", ptr->interface_name);
if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "chat");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "name", "%s", ptr->interface_name);
switch_event_fire(&event);
}
switch_core_hash_insert(loadable_modules.chat_hash, (char *) ptr->interface_name, (void *) ptr);
}
}
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
...@@ -476,6 +491,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init() ...@@ -476,6 +491,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init()
switch_core_hash_init(&loadable_modules.file_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.speech_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.directory_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.dialplan_hash, loadable_modules.pool); switch_core_hash_init(&loadable_modules.dialplan_hash, loadable_modules.pool);
if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) { if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
...@@ -637,6 +653,11 @@ SWITCH_DECLARE(switch_directory_interface_t *) switch_loadable_module_get_direct ...@@ -637,6 +653,11 @@ SWITCH_DECLARE(switch_directory_interface_t *) switch_loadable_module_get_direct
return switch_core_hash_find(loadable_modules.directory_hash, name); return switch_core_hash_find(loadable_modules.directory_hash, name);
} }
SWITCH_DECLARE(switch_chat_interface_t *) switch_loadable_module_get_chat_interface(char *name)
{
return switch_core_hash_find(loadable_modules.chat_hash, name);
}
SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool_t *pool, const switch_codec_implementation_t **array, SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool_t *pool, const switch_codec_implementation_t **array,
int arraylen) int arraylen)
{ {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论