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,
*to++ = '\0';
}
proto = pproto;
+ got_proto++;
}
hint = from;
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);
}
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;
}
}
/* 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)),
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);
*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);
}
}
} 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) {
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;
}
+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)
{