diff --git a/src/include/switch_core.h b/src/include/switch_core.h index da6a2e6ada..1591cf18cc 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -2107,8 +2107,10 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string); SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait); SWITCH_DECLARE(void) switch_cond_yield(switch_interval_time_t t); SWITCH_DECLARE(void) switch_cond_next(void); -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_DECLARE(switch_status_t) switch_core_chat_send_args(const char *dest_proto, const char *proto, const char *from, const char *to, + const char *subject, const char *body, const char *type, const char *hint); +SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *dest_proto, switch_event_t *message_event); + SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_session_t *session, const char *cmds); diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index 33c4c22bac..7c666ab9f4 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -483,8 +483,8 @@ struct switch_chat_interface { /*! the name of the interface */ const char *interface_name; /*! function to open the directory interface */ - 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); + switch_status_t (*chat_send) (switch_event_t *message_event); + switch_thread_rwlock_t *rwlock; int refs; switch_mutex_t *reflock; diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index b99ee84160..53d2f3f34a 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -436,8 +436,8 @@ static switch_status_t conference_member_play_file(conference_member_t *member, static switch_status_t conference_member_say(conference_member_t *member, char *text, uint32_t leadin); static uint32_t conference_member_stop_file(conference_member_t *member, file_stop_t stop); static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_core_session_t *session, switch_memory_pool_t *pool); -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); + static void launch_conference_record_thread(conference_obj_t *conference, char *path); static void launch_conference_video_bridge_thread(conference_member_t *member_a, conference_member_t *member_b); @@ -2705,19 +2705,16 @@ static void conference_loop_output(conference_member_t *member) if (event->event_id == SWITCH_EVENT_MESSAGE) { char *from = switch_event_get_header(event, "from"); char *to = switch_event_get_header(event, "to"); - char *proto = switch_event_get_header(event, "proto"); - char *subject = switch_event_get_header(event, "subject"); - char *hint = switch_event_get_header(event, "hint"); char *body = switch_event_get_body(event); - char *p, *freeme = NULL; + char *p; if (to && from && body) { if ((p = strchr(to, '+')) && strncmp(to, CONF_CHAT_PROTO, strlen(CONF_CHAT_PROTO))) { - freeme = switch_mprintf("%s+%s@%s", CONF_CHAT_PROTO, member->conference->name, member->conference->domain); - to = freeme; + switch_event_del_header(event, "to"); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, + "to", "%s+%s@%s", CONF_CHAT_PROTO, member->conference->name, member->conference->domain); } - chat_send(proto, from, to, subject, body, NULL, hint); - switch_safe_free(freeme); + chat_send(event); } } switch_event_destroy(&event); @@ -6379,12 +6376,26 @@ static void launch_conference_record_thread(conference_obj_t *conference, char * switch_thread_create(&thread, thd_attr, conference_record_thread_run, rec, rec->pool); } -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 name[512] = "", *p, *lbuf = NULL; conference_obj_t *conference = NULL; switch_stream_handle_t stream = { 0 }; + 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 ((p = strchr(to, '+'))) { to = ++p; @@ -6401,7 +6412,7 @@ static switch_status_t chat_send(const char *proto, const char *from, const char } if (!(conference = conference_find(name))) { - switch_core_chat_send(proto, CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", "Conference not active.", NULL, NULL); + switch_core_chat_send_args(proto, CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", "Conference not active.", NULL, NULL); return SWITCH_STATUS_FALSE; } @@ -6419,7 +6430,7 @@ static switch_status_t chat_send(const char *proto, const char *from, const char switch_safe_free(lbuf); - switch_core_chat_send(proto, CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", stream.data, NULL, NULL); + switch_core_chat_send_args(proto, CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", stream.data, NULL, NULL); switch_safe_free(stream.data); return SWITCH_STATUS_SUCCESS; diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 1c8fe1262e..4d21a6d681 100755 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -1549,7 +1549,7 @@ SWITCH_STANDARD_API(chat_api_function) if (!zstr(cmd) && (lbuf = strdup(cmd)) && (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) >= 4) { - if (switch_core_chat_send(argv[0], "dp", argv[1], argv[2], "", argv[3], !zstr(argv[4]) ? argv[4] : NULL, "") == SWITCH_STATUS_SUCCESS) { + if (switch_core_chat_send_args(argv[0], "dp", argv[1], argv[2], "", argv[3], !zstr(argv[4]) ? argv[4] : NULL, "") == SWITCH_STATUS_SUCCESS) { stream->write_function(stream, "Sent"); } else { stream->write_function(stream, "Error! Message Not Sent"); @@ -3372,44 +3372,51 @@ SWITCH_STANDARD_APP(wait_for_silence_function) switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Usage: %s\n", WAIT_FOR_SILENCE_SYNTAX); } -static switch_status_t event_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 event_chat_send(switch_event_t *message_event) + { switch_event_t *event; + const char *to; - if (switch_event_create(&event, SWITCH_EVENT_RECV_MESSAGE) == SWITCH_STATUS_SUCCESS) { - if (proto) - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Proto", proto); - if (from) - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "From", from); - if (subject) - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Subject", subject); - if (hint) - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Hint", hint); - if (body) - switch_event_add_body(event, "%s", body); - if (to) { - char *v; - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "To", to); - if ((v = switch_core_get_variable_dup(to))) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Command", v); - free(v); - } + switch_event_dup(&event, message_event); + event->event_id = SWITCH_EVENT_RECV_MESSAGE; + + if ((to = switch_event_get_header(event, "to"))) { + char *v; + if ((v = switch_core_get_variable_dup(to))) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Command", v); + free(v); } - - if (switch_event_fire(&event) == SWITCH_STATUS_SUCCESS) { - return SWITCH_STATUS_SUCCESS; - } - - switch_event_destroy(&event); } + if (switch_event_fire(&event) == SWITCH_STATUS_SUCCESS) { + return SWITCH_STATUS_SUCCESS; + } + + switch_event_destroy(&event); + return SWITCH_STATUS_MEMERR; } -static switch_status_t api_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 api_chat_send(switch_event_t *message_event) { + 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) { char *v = NULL; switch_stream_handle_t stream = { 0 }; @@ -3432,7 +3439,7 @@ static switch_status_t api_chat_send(const char *proto, const char *from, const switch_api_execute(cmd, arg, NULL, &stream); if (proto) { - switch_core_chat_send(proto, "api", to, hint && strchr(hint, '/') ? hint : from, !zstr(type) ? type : NULL, (char *) stream.data, NULL, NULL); + switch_core_chat_send_args(proto, "api", to, hint && strchr(hint, '/') ? hint : from, !zstr(type) ? type : NULL, (char *) stream.data, NULL, NULL); } switch_safe_free(stream.data); diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index a0b9e7da28..a7e8537180 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -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); diff --git a/src/mod/endpoints/mod_skypopen/mod_skypopen.c b/src/mod/endpoints/mod_skypopen/mod_skypopen.c index a5d90d0c50..ddb5fe35ab 100644 --- a/src/mod/endpoints/mod_skypopen/mod_skypopen.c +++ b/src/mod/endpoints/mod_skypopen/mod_skypopen.c @@ -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 { diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 8ef3b92663..270c6c3e40 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -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)) { diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 4e8a0585bd..a0f1cac582 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -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); /* diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 33154e73ec..db7aa94a3a 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -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); } diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 4e663df6e0..6368863872 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -468,28 +468,78 @@ 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_DECLARE(switch_status_t) switch_core_chat_send_args(const char *dest_proto, 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 = switch_core_chat_send(dest_proto, message_event); + + switch_event_destroy(&message_event); + + return status; + +} + +SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *dest_proto, switch_event_t *message_event) + { switch_chat_interface_t *ci; switch_status_t status = SWITCH_STATUS_FALSE; switch_hash_index_t *hi; const void *var; void *val; - - if (!name) { + + /* + const char *proto; + const char *from; + const char *to; + const char *subject; + const char *body; + const char *type; + const char *hint; + */ + + if (!dest_proto) { return SWITCH_STATUS_FALSE; } - if (!strcasecmp(name, "GLOBAL")) { + /* + 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 (!strcasecmp(dest_proto, "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); + if ((status = ci->chat_send(message_event)) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Chat Interface Error [%s]!\n", dest_proto); break; } } @@ -497,11 +547,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *name, const ch } 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); + if (!(ci = switch_loadable_module_get_chat_interface(dest_proto)) || !ci->chat_send) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid chat interface [%s]!\n", dest_proto); return SWITCH_STATUS_FALSE; } - status = ci->chat_send(proto, from, to, subject, body, type, hint); + status = ci->chat_send(message_event); UNPROTECT_INTERFACE(ci); }