add support for global nameseace in chat interface to bind to unhandled messages
This commit is contained in:
parent
d0308aaea2
commit
6dd1264d08
|
@ -2876,6 +2876,8 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
|||
char *proto = MDL_CHAT_PROTO;
|
||||
char *pproto = NULL, *ffrom = NULL;
|
||||
char *hint;
|
||||
int got_proto = 0;
|
||||
|
||||
#ifdef AUTO_REPLY
|
||||
if (profile->auto_reply) {
|
||||
ldl_handle_send_msg(handle,
|
||||
|
@ -2890,6 +2892,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
|||
*to++ = '\0';
|
||||
}
|
||||
proto = pproto;
|
||||
got_proto++;
|
||||
}
|
||||
|
||||
hint = from;
|
||||
|
@ -2902,10 +2905,14 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
|||
from = ffrom;
|
||||
}
|
||||
|
||||
if (strcasecmp(proto, MDL_CHAT_PROTO)) { /* yes no ! on purpose */
|
||||
if (strcasecmp(proto, MDL_CHAT_PROTO)) { /* yes no ! on purpose */
|
||||
switch_core_chat_send(proto, MDL_CHAT_PROTO, from, to, subject, switch_str_nil(msg), NULL, hint);
|
||||
}
|
||||
|
||||
if (!got_proto) {
|
||||
switch_core_chat_send("GLOBAL", MDL_CHAT_PROTO, from, to, subject, switch_str_nil(msg), NULL, hint);
|
||||
}
|
||||
|
||||
switch_safe_free(pproto);
|
||||
switch_safe_free(ffrom);
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ switch_status_t sofia_presence_chat_send(const char *proto, const char *from, co
|
|||
|
||||
if (!prof || !(profile = sofia_glue_find_profile(prof))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
"Chat proto [%s]\nfrom [%s]\nto [%s]\n%s\nInvalid Profile %s\n", proto, from, to,
|
||||
"Chat proto [%s]\nfrom [%s]\nto [%s]\n%s\nInvalid Profile %s\n", proto, from, to,
|
||||
body ? body : "[no body]", prof ? prof : "NULL");
|
||||
goto end;
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ switch_status_t sofia_presence_chat_send(const char *proto, const char *from, co
|
|||
}
|
||||
|
||||
/* if this cries, add contact here too, change the 1 to 0 and omit the safe_free */
|
||||
|
||||
|
||||
msg_nh = nua_handle(profile->nua, NULL,
|
||||
TAG_IF(dst->route_uri, NUTAG_PROXY(dst->route_uri)),
|
||||
TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
|
||||
|
@ -2891,6 +2891,7 @@ void sofia_presence_handle_sip_i_message(int status,
|
|||
char *p;
|
||||
char *full_from;
|
||||
char proto[512] = SOFIA_CHAT_PROTO;
|
||||
int got_proto = 0;
|
||||
|
||||
full_from = sip_header_as_string(nh->nh_home, (void *) sip->sip_from);
|
||||
|
||||
|
@ -2904,11 +2905,12 @@ void sofia_presence_handle_sip_i_message(int status,
|
|||
*p = '@';
|
||||
}
|
||||
}
|
||||
got_proto++;
|
||||
} else {
|
||||
to_addr = switch_mprintf("%s@%s", to_user, to_host);
|
||||
}
|
||||
|
||||
from_addr = switch_mprintf("%s@%s", from_user, from_host);
|
||||
from_addr = switch_mprintf("%s/%s@%s", profile->name, from_user, from_host);
|
||||
|
||||
if (sofia_test_pflag(profile, PFLAG_IN_DIALOG_CHAT)) {
|
||||
sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
|
||||
|
@ -2932,8 +2934,15 @@ void sofia_presence_handle_sip_i_message(int status,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
switch_core_chat_send(proto, SOFIA_CHAT_PROTO, from_addr, to_addr, "", msg, NULL, full_from);
|
||||
if (strcasecmp(proto, SOFIA_CHAT_PROTO)) {
|
||||
switch_core_chat_send(proto, SOFIA_CHAT_PROTO, from_addr, to_addr, "", msg, NULL, full_from);
|
||||
}
|
||||
}
|
||||
|
||||
if (!got_proto) {
|
||||
switch_core_chat_send("GLOBAL", SOFIA_CHAT_PROTO, from_addr, to_addr, "", msg, NULL, full_from);
|
||||
}
|
||||
|
||||
switch_safe_free(to_addr);
|
||||
switch_safe_free(from_addr);
|
||||
if (full_from) {
|
||||
|
|
|
@ -2191,24 +2191,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
|
|||
return switch_test_flag((&runtime), SCF_RESTART) ? SWITCH_STATUS_RESTART : SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *name, const char *proto, const char *from, const char *to,
|
||||
const char *subject, const char *body, const char *type, const char *hint)
|
||||
{
|
||||
switch_chat_interface_t *ci;
|
||||
switch_status_t status;
|
||||
|
||||
if (!name || !(ci = switch_loadable_module_get_chat_interface(name)) || !ci->chat_send) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", name);
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
status = ci->chat_send(proto, from, to, subject, body, type, hint);
|
||||
|
||||
UNPROTECT_INTERFACE(ci);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_management_exec(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
|
||||
{
|
||||
const switch_management_interface_t *ptr;
|
||||
|
|
|
@ -468,6 +468,46 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
|
|||
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *name, const char *proto, const char *from, const char *to,
|
||||
const char *subject, const char *body, const char *type, const char *hint)
|
||||
{
|
||||
switch_chat_interface_t *ci;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
switch_hash_index_t *hi;
|
||||
const void *var;
|
||||
void *val;
|
||||
|
||||
if (!name) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
if (!strcasecmp(name, "GLOBAL")) {
|
||||
switch_mutex_lock(loadable_modules.mutex);
|
||||
for (hi = switch_hash_first(NULL, loadable_modules.chat_hash); hi; hi = switch_hash_next(hi)) {
|
||||
switch_hash_this(hi, &var, NULL, &val);
|
||||
|
||||
if ((ci = (switch_chat_interface_t *) val)) {
|
||||
if (ci->chat_send && !strncasecmp(ci->interface_name, "GLOBAL_", 7)) {
|
||||
if ((status = ci->chat_send(proto, from, to, subject, body, type, hint)) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Chat Interface Error [%s]!\n", name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
switch_mutex_unlock(loadable_modules.mutex);
|
||||
} else {
|
||||
if (!(ci = switch_loadable_module_get_chat_interface(name)) || !ci->chat_send) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid chat interface [%s]!\n", name);
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
status = ci->chat_send(proto, from, to, subject, body, type, hint);
|
||||
UNPROTECT_INTERFACE(ci);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t *old_module)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue