mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-07-14 19:16:59 +00:00
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 *proto = MDL_CHAT_PROTO;
|
||||||
char *pproto = NULL, *ffrom = NULL;
|
char *pproto = NULL, *ffrom = NULL;
|
||||||
char *hint;
|
char *hint;
|
||||||
|
int got_proto = 0;
|
||||||
|
|
||||||
#ifdef AUTO_REPLY
|
#ifdef AUTO_REPLY
|
||||||
if (profile->auto_reply) {
|
if (profile->auto_reply) {
|
||||||
ldl_handle_send_msg(handle,
|
ldl_handle_send_msg(handle,
|
||||||
@ -2890,6 +2892,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
|||||||
*to++ = '\0';
|
*to++ = '\0';
|
||||||
}
|
}
|
||||||
proto = pproto;
|
proto = pproto;
|
||||||
|
got_proto++;
|
||||||
}
|
}
|
||||||
|
|
||||||
hint = from;
|
hint = from;
|
||||||
@ -2902,10 +2905,14 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
|||||||
from = ffrom;
|
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);
|
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(pproto);
|
||||||
switch_safe_free(ffrom);
|
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))) {
|
if (!prof || !(profile = sofia_glue_find_profile(prof))) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
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");
|
body ? body : "[no body]", prof ? prof : "NULL");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -2891,6 +2891,7 @@ void sofia_presence_handle_sip_i_message(int status,
|
|||||||
char *p;
|
char *p;
|
||||||
char *full_from;
|
char *full_from;
|
||||||
char proto[512] = SOFIA_CHAT_PROTO;
|
char proto[512] = SOFIA_CHAT_PROTO;
|
||||||
|
int got_proto = 0;
|
||||||
|
|
||||||
full_from = sip_header_as_string(nh->nh_home, (void *) sip->sip_from);
|
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 = '@';
|
*p = '@';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
got_proto++;
|
||||||
} else {
|
} else {
|
||||||
to_addr = switch_mprintf("%s@%s", to_user, to_host);
|
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)) {
|
if (sofia_test_pflag(profile, PFLAG_IN_DIALOG_CHAT)) {
|
||||||
sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
|
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 {
|
} 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(to_addr);
|
||||||
switch_safe_free(from_addr);
|
switch_safe_free(from_addr);
|
||||||
if (full_from) {
|
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;
|
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)
|
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;
|
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)
|
static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t *old_module)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user