mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-29 22:54:18 +00:00
convert chat interface to use events instead of a bunch of args
This commit is contained in:
1 parent
b4b99c410d
commit
9125a96c6d
10 files changed
+273
-104
No files matched your search
@@ -489,11 +489,25 @@ static void pres_event_handler(switch_event_t *event)
|
||||
switch_safe_free(sql);
|
||||
}
|
||||
|
||||
static switch_status_t chat_send(const char *proto, const char *from, const char *to, const char *subject,
|
||||
const char *body, const char *type, const char *hint)
|
||||
static switch_status_t chat_send(switch_event_t *message_event)
|
||||
{
|
||||
char *user, *host, *f_user = NULL, *ffrom = NULL, *f_host = NULL, *f_resource = NULL;
|
||||
mdl_profile_t *profile = NULL;
|
||||
const char *proto;
|
||||
const char *from;
|
||||
const char *to;
|
||||
const char *subject;
|
||||
const char *body;
|
||||
const char *type;
|
||||
const char *hint;
|
||||
|
||||
proto = switch_event_get_header(message_event, "proto");
|
||||
from = switch_event_get_header(message_event, "from");
|
||||
to = switch_event_get_header(message_event, "to");
|
||||
subject = switch_event_get_header(message_event, "subject");
|
||||
body = switch_event_get_body(message_event);
|
||||
type = switch_event_get_header(message_event, "type");
|
||||
hint = switch_event_get_header(message_event, "hint");
|
||||
|
||||
switch_assert(proto != NULL);
|
||||
|
||||
@@ -2876,8 +2890,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;
|
||||
|
||||
switch_event_t *event;
|
||||
char *from_user, *from_host;
|
||||
#ifdef AUTO_REPLY
|
||||
if (profile->auto_reply) {
|
||||
ldl_handle_send_msg(handle,
|
||||
@@ -2892,7 +2906,6 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
||||
*to++ = '\0';
|
||||
}
|
||||
proto = pproto;
|
||||
got_proto++;
|
||||
}
|
||||
|
||||
hint = from;
|
||||
@@ -2905,13 +2918,40 @@ 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 */
|
||||
switch_core_chat_send(proto, MDL_CHAT_PROTO, from, to, subject, switch_str_nil(msg), NULL, hint);
|
||||
from_user = strdup(from);
|
||||
if ((from_host = strchr(from_user, '@'))) {
|
||||
*from_host++ = '\0';
|
||||
}
|
||||
|
||||
if (!got_proto) {
|
||||
switch_core_chat_send("GLOBAL", MDL_CHAT_PROTO, from, to, subject, switch_str_nil(msg), NULL, hint);
|
||||
|
||||
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", from);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_user", from_user);
|
||||
if (from_host) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_host", from_host);
|
||||
}
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to", to);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", subject);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "normal");
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", hint);
|
||||
|
||||
if (msg) {
|
||||
switch_event_add_body(event, "%s", msg);
|
||||
}
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
|
||||
switch_safe_free(from_user);
|
||||
|
||||
if (strcasecmp(proto, MDL_CHAT_PROTO)) { /* yes no ! on purpose */
|
||||
switch_core_chat_send(proto, event);
|
||||
}
|
||||
|
||||
switch_core_chat_send("GLOBAL", event);
|
||||
|
||||
switch_event_destroy(&event);
|
||||
|
||||
switch_safe_free(pproto);
|
||||
switch_safe_free(ffrom);
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
#include "skypopen.h"
|
||||
#define MDL_CHAT_PROTO "skype"
|
||||
#define SKYPE_CHAT_PROTO "skype"
|
||||
|
||||
#ifdef WIN32
|
||||
/***************/
|
||||
@@ -1858,14 +1858,30 @@ static switch_status_t load_config(int reload_type)
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
static switch_status_t chat_send(const char *proto, const char *from, const char *to, const char *subject, const char *body, const char *type,
|
||||
const char *hint)
|
||||
static switch_status_t chat_send(switch_event_t *message_event)
|
||||
|
||||
{
|
||||
char *user = NULL, *host, *f_user = NULL, *f_host = NULL, *f_resource = NULL;
|
||||
private_t *tech_pvt = NULL;
|
||||
int i = 0, found = 0, tried = 0;
|
||||
char skype_msg[1024];
|
||||
|
||||
const char *proto;
|
||||
const char *from;
|
||||
const char *to;
|
||||
const char *subject;
|
||||
const char *body;
|
||||
//const char *type;
|
||||
const char *hint;
|
||||
|
||||
proto = switch_event_get_header(message_event, "proto");
|
||||
from = switch_event_get_header(message_event, "from");
|
||||
to = switch_event_get_header(message_event, "to");
|
||||
subject = switch_event_get_header(message_event, "subject");
|
||||
body = switch_event_get_body(message_event);
|
||||
//type = switch_event_get_header(message_event, "type");
|
||||
hint = switch_event_get_header(message_event, "hint");
|
||||
|
||||
switch_assert(proto != NULL);
|
||||
|
||||
DEBUGA_SKYPE("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", SKYPOPEN_P_LOG, proto, from, to, subject, body, type,
|
||||
@@ -1998,7 +2014,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_skypopen_load)
|
||||
SWITCH_ADD_API(commands_api_interface, "skypopen", "Skypopen interface commands", skypopen_function, SKYPOPEN_SYNTAX);
|
||||
SWITCH_ADD_API(commands_api_interface, "skypopen_chat", "Skypopen_chat interface remote_skypename TEXT", skypopen_chat_function,
|
||||
SKYPOPEN_CHAT_SYNTAX);
|
||||
SWITCH_ADD_CHAT(chat_interface, MDL_CHAT_PROTO, chat_send);
|
||||
SWITCH_ADD_CHAT(chat_interface, SKYPE_CHAT_PROTO, chat_send);
|
||||
|
||||
if (switch_event_reserve_subclass(MY_EVENT_INCOMING_CHATMESSAGE) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!\n");
|
||||
@@ -2944,7 +2960,7 @@ int incoming_chatmessage(private_t *tech_pvt, int which)
|
||||
session = switch_core_session_locate(tech_pvt->session_uuid_str);
|
||||
}
|
||||
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SKYPE_CHAT_PROTO);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", tech_pvt->name);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", tech_pvt->chatmessages[which].from_dispname);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", tech_pvt->chatmessages[which].from_handle);
|
||||
@@ -2971,7 +2987,7 @@ int incoming_chatmessage(private_t *tech_pvt, int which)
|
||||
if (!event_sent_to_esl) {
|
||||
|
||||
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SKYPE_CHAT_PROTO);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", tech_pvt->name);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", tech_pvt->chatmessages[which].from_dispname);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", tech_pvt->chatmessages[which].from_handle);
|
||||
@@ -2997,6 +3013,33 @@ int incoming_chatmessage(private_t *tech_pvt, int which)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static switch_status_t compat_chat_send(const char *proto, const char *from, const char *to,
|
||||
const char *subject, const char *body, const char *type, const char *hint)
|
||||
{
|
||||
switch_event_t *message_event;
|
||||
switch_status_t status;
|
||||
|
||||
if (switch_event_create(&message_event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "proto", proto);
|
||||
switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "from", from);
|
||||
switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "to", to);
|
||||
switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "subject", subject);
|
||||
switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "type", type);
|
||||
switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "hint", hint);
|
||||
|
||||
if (body) {
|
||||
switch_event_add_body(message_event, "%s", body);
|
||||
}
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
|
||||
status = chat_send(message_event);
|
||||
switch_event_destroy(&message_event);
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_API(skypopen_chat_function)
|
||||
{
|
||||
@@ -3037,11 +3080,11 @@ SWITCH_STANDARD_API(skypopen_chat_function)
|
||||
goto end;
|
||||
} else {
|
||||
|
||||
NOTICA("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=NULL, hint=%s)\n", SKYPOPEN_P_LOG, MDL_CHAT_PROTO, tech_pvt->skype_user,
|
||||
NOTICA("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=NULL, hint=%s)\n", SKYPOPEN_P_LOG, SKYPE_CHAT_PROTO, tech_pvt->skype_user,
|
||||
argv[1], "SIMPLE MESSAGE", switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), tech_pvt->name);
|
||||
|
||||
chat_send(MDL_CHAT_PROTO, tech_pvt->skype_user, argv[1], "SIMPLE MESSAGE",
|
||||
switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), NULL, tech_pvt->name);
|
||||
compat_chat_send(SKYPE_CHAT_PROTO, tech_pvt->skype_user, argv[1], "SIMPLE MESSAGE",
|
||||
switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), NULL, tech_pvt->name);
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1986,6 +1986,8 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
|
||||
number = tech_pvt->caller_profile->destination_number;
|
||||
}
|
||||
|
||||
printf("WTF [%s][%s]\n", name, number);
|
||||
|
||||
if (!sofia_test_flag(tech_pvt, TFLAG_UPDATING_DISPLAY)) {
|
||||
if (zstr(tech_pvt->last_sent_callee_id_name) || strcmp(tech_pvt->last_sent_callee_id_name, name) ||
|
||||
zstr(tech_pvt->last_sent_callee_id_number) || strcmp(tech_pvt->last_sent_callee_id_number, number)) {
|
||||
|
||||
@@ -872,8 +872,8 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
|
||||
|
||||
void launch_sofia_profile_thread(sofia_profile_t *profile);
|
||||
|
||||
switch_status_t sofia_presence_chat_send(const char *proto, const char *from, const char *to, const char *subject,
|
||||
const char *body, const char *type, const char *hint);
|
||||
switch_status_t sofia_presence_chat_send(switch_event_t *message_event);
|
||||
|
||||
void sofia_glue_tech_absorb_sdp(private_object_t *tech_pvt);
|
||||
|
||||
/*
|
||||
|
||||
@@ -72,8 +72,8 @@ struct presence_helper {
|
||||
char last_uuid[512];
|
||||
};
|
||||
|
||||
switch_status_t sofia_presence_chat_send(const char *proto, const char *from, const char *to, const char *subject,
|
||||
const char *body, const char *type, const char *hint)
|
||||
switch_status_t sofia_presence_chat_send(switch_event_t *message_event)
|
||||
|
||||
{
|
||||
char *prof = NULL, *user = NULL, *host = NULL;
|
||||
sofia_profile_t *profile = NULL;
|
||||
@@ -93,6 +93,22 @@ switch_status_t sofia_presence_chat_send(const char *proto, const char *from, co
|
||||
char *dup_dest = NULL;
|
||||
char *p = NULL;
|
||||
char *remote_host = NULL;
|
||||
const char *proto;
|
||||
const char *from;
|
||||
const char *to;
|
||||
//const char *subject;
|
||||
const char *body;
|
||||
const char *type;
|
||||
const char *hint;
|
||||
|
||||
proto = switch_event_get_header(message_event, "proto");
|
||||
from = switch_event_get_header(message_event, "from");
|
||||
to = switch_event_get_header(message_event, "to");
|
||||
//subject = switch_event_get_header(message_event, "subject");
|
||||
body = switch_event_get_body(message_event);
|
||||
type = switch_event_get_header(message_event, "type");
|
||||
hint = switch_event_get_header(message_event, "hint");
|
||||
|
||||
|
||||
if (!to) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing To: header.\n");
|
||||
@@ -2891,7 +2907,6 @@ 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);
|
||||
|
||||
@@ -2905,7 +2920,6 @@ void sofia_presence_handle_sip_i_message(int status,
|
||||
*p = '@';
|
||||
}
|
||||
}
|
||||
got_proto++;
|
||||
} else {
|
||||
to_addr = switch_mprintf("%s@%s", to_user, to_host);
|
||||
}
|
||||
@@ -2916,35 +2930,35 @@ void sofia_presence_handle_sip_i_message(int status,
|
||||
sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
|
||||
}
|
||||
|
||||
if (sofia_test_pflag(profile, PFLAG_IN_DIALOG_CHAT) && (tech_pvt = (private_object_t *) switch_core_hash_find(profile->chat_hash, hash_key))) {
|
||||
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", from_addr);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", full_from);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to", to_addr);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", "SIMPLE MESSAGE");
|
||||
if (msg) {
|
||||
switch_event_add_body(event, "%s", msg);
|
||||
}
|
||||
|
||||
if (switch_core_session_queue_event(tech_pvt->session, &event) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true");
|
||||
switch_event_fire(&event);
|
||||
}
|
||||
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", from_addr);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_user", from_user);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_host", from_host);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to", to_addr);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", "SIMPLE MESSAGE");
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "normal");
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", full_from);
|
||||
|
||||
if (msg) {
|
||||
switch_event_add_body(event, "%s", msg);
|
||||
}
|
||||
} else {
|
||||
if (strcasecmp(proto, SOFIA_CHAT_PROTO)) {
|
||||
switch_core_chat_send(proto, SOFIA_CHAT_PROTO, from_addr, to_addr, "", msg, NULL, full_from);
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
if (!got_proto) {
|
||||
switch_core_chat_send("GLOBAL", SOFIA_CHAT_PROTO, from_addr, to_addr, "", msg, NULL, full_from);
|
||||
|
||||
if (sofia_test_pflag(profile, PFLAG_IN_DIALOG_CHAT) && (tech_pvt = (private_object_t *) switch_core_hash_find(profile->chat_hash, hash_key))) {
|
||||
switch_core_session_queue_event(tech_pvt->session, &event);
|
||||
} else {
|
||||
switch_core_chat_send(proto, event);
|
||||
switch_core_chat_send("GLOBAL", event);
|
||||
switch_event_destroy(&event);
|
||||
}
|
||||
|
||||
switch_safe_free(to_addr);
|
||||
switch_safe_free(from_addr);
|
||||
|
||||
if (full_from) {
|
||||
su_free(nh->nh_home, full_from);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user