]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add chat interface EXTRAGUY-00
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 20 Jan 2009 20:49:47 +0000 (20:49 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 20 Jan 2009 20:49:47 +0000 (20:49 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11319 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_core.h
src/include/switch_module_interfaces.h
src/mod/applications/mod_conference/mod_conference.c
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia_presence.c
src/switch_core.c
src/switch_loadable_module.c

index f36c067a85d8c7f3df0728c74e90f2999e475110..bf6d40d6aa53d2c80e606338a497dfc918f008bb 100644 (file)
@@ -1707,6 +1707,8 @@ 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);
 ///\}
 
 /*!
index cee2cfbf4d7d0188ecf586e7f6075c7ddcd65399..c85a50e6810772b0d3334180cf924ceec62cd4db 100644 (file)
@@ -442,7 +442,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) (char *proto, char *from, char *to, char *subject, char *body, char *hint);
+       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_thread_rwlock_t *rwlock;
        int refs;
        switch_mutex_t *reflock;
index 6b557fc77906bcffe98f5d109b28ddb7ff52925c..cdfd0456d9b06cbaa0f0b6c3490bd19f6c88264e 100644 (file)
@@ -372,7 +372,9 @@ 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_memory_pool_t *pool);
-static switch_status_t chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint);
+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 void launch_conference_record_thread(conference_obj_t *conference, char *path);
 
 typedef switch_status_t (*conf_api_args_cmd_t) (conference_obj_t *, switch_stream_handle_t *, int, char **);
@@ -1907,7 +1909,7 @@ static void conference_loop_output(conference_member_t *member)
                                                freeme = switch_mprintf("%s+%s@%s", CONF_CHAT_PROTO, member->conference->name, member->conference->domain);
                                                to = freeme;
                                        }
-                                       chat_send(proto, from, to, subject, body, hint);
+                                       chat_send(proto, from, to, subject, body, NULL, hint);
                                        switch_safe_free(freeme);
                                }
                        }
@@ -4957,10 +4959,10 @@ 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(char *proto, char *from, char *to, char *subject, char *body, char *hint)
+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)
 {
        char name[512] = "", *p, *lbuf = NULL;
-       switch_chat_interface_t *ci;
        conference_obj_t *conference = NULL;
        switch_stream_handle_t stream = { 0 };
 
@@ -4972,12 +4974,6 @@ static switch_status_t chat_send(char *proto, char *from, char *to, char *subjec
                return SWITCH_STATUS_SUCCESS;
        }
 
-       if (!(ci = switch_loadable_module_get_chat_interface(proto))) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
-               return SWITCH_STATUS_FALSE;
-       }
-
-
        if ((p = strchr(to, '@'))) {
                switch_copy_string(name, to, ++p - to);
        } else {
@@ -4986,7 +4982,7 @@ static switch_status_t chat_send(char *proto, char *from, char *to, char *subjec
 
 
        if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, name))) {
-               ci->chat_send(CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", "Conference not active.", NULL);
+               switch_core_chat_send(proto, CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", "Conference not active.", NULL, NULL);
                return SWITCH_STATUS_FALSE;
        }
 
@@ -5014,7 +5010,7 @@ static switch_status_t chat_send(char *proto, char *from, char *to, char *subjec
 
        switch_safe_free(lbuf);
        
-       ci->chat_send(CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", stream.data, NULL);
+       switch_core_chat_send(proto, CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", stream.data, NULL, NULL);
        switch_safe_free(stream.data);
 
        return SWITCH_STATUS_SUCCESS;
index a195b72792c461eeac9cfd990b48855b67581f4b..f3b15a214695d7d469bfbb112bedcafdecffc451 100644 (file)
@@ -1069,16 +1069,11 @@ SWITCH_STANDARD_API(chat_api_function)
 
        if (!switch_strlen_zero(cmd) && (lbuf = strdup(cmd))
                && (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
-               switch_chat_interface_t *ci;
-
-               if ((ci = switch_loadable_module_get_chat_interface(argv[0]))) {
-                       if (ci->chat_send("dp", argv[1], argv[2], "", argv[3], "") == SWITCH_STATUS_SUCCESS) {
-                               stream->write_function(stream, "Sent");
-                       } else {
-                               stream->write_function(stream, "Error! Message Not Sent");
-                       }
+               
+               if (switch_core_chat_send(argv[0], "dp", argv[1], argv[2], "", argv[3], NULL, "") == SWITCH_STATUS_SUCCESS) {
+                       stream->write_function(stream, "Sent");
                } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", argv[0]);
+                       stream->write_function(stream, "Error! Message Not Sent");
                }
        } else {
                stream->write_function(stream, "Invalid");
@@ -2438,7 +2433,8 @@ SWITCH_STANDARD_APP(wait_for_silence_function)
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", WAIT_FOR_SILENCE_SYNTAX);
 }
 
-static switch_status_t event_chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint)
+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)
 {
        switch_event_t *event;
 
@@ -2466,14 +2462,14 @@ static switch_status_t event_chat_send(char *proto, char *from, char *to, char *
        return SWITCH_STATUS_MEMERR;
 }
 
-static switch_status_t api_chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint)
+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)
 {
        if (to) { 
                const char *v;
                switch_stream_handle_t stream = { 0 };
                char *cmd, *arg;
-               switch_chat_interface_t *ci;
-
+               
                if (!(v = switch_core_get_variable(to))) {
                        v = to;
                }
@@ -2490,8 +2486,8 @@ static switch_status_t api_chat_send(char *proto, char *from, char *to, char *su
                SWITCH_STANDARD_STREAM(stream);
                switch_api_execute(cmd, arg, NULL, &stream);
 
-               if (proto && (ci = switch_loadable_module_get_chat_interface(proto))) {
-                       ci->chat_send("api", to, hint && strchr(hint, '/') ? hint : from, "text/plain", (char *) stream.data, NULL);
+               if (proto) {
+                       switch_core_chat_send(proto, "api", to, hint && strchr(hint, '/') ? hint : from, "text/plain", (char *) stream.data, NULL, NULL);
                }
 
                switch_safe_free(stream.data);
index 7f1f614f4b60330f5dcd0f20d7d3b7e143fbd234..450d6833af64425373fdd88f84fecd89a56112dc 100644 (file)
@@ -506,7 +506,8 @@ static void pres_event_handler(switch_event_t *event)
        switch_safe_free(sql);
 }
 
-static switch_status_t chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint)
+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);
 {
        char *user, *host, *f_user = NULL, *ffrom = NULL, *f_host = NULL, *f_resource = NULL;
        mdl_profile_t *profile = NULL;
@@ -2459,10 +2460,9 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
 
                switch (dl_signal) {
                case LDL_SIGNAL_MSG:{
-                               switch_chat_interface_t *ci;
-                               char *proto = MDL_CHAT_PROTO;
-                               char *pproto = NULL, *ffrom = NULL;
-                               char *hint;
+                       char *proto = MDL_CHAT_PROTO;
+                       char *pproto = NULL, *ffrom = NULL;
+                       char *hint;
 #ifdef AUTO_REPLY
                                if (profile->auto_reply) {
                                        ldl_handle_send_msg(handle,
@@ -2489,11 +2489,8 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
                                        from = ffrom;
                                }
 
-                               if ((ci = switch_loadable_module_get_chat_interface(proto))) {
-                                       ci->chat_send(MDL_CHAT_PROTO, from, to, subject, switch_str_nil(msg), hint);
-                               } else {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
-                               }
+
+                               switch_core_chat_send(proto, MDL_CHAT_PROTO, from, to, subject, switch_str_nil(msg), NULL, hint);
 
                                switch_safe_free(pproto);
                                switch_safe_free(ffrom);
index 1ee2d1f86a268b1694586bc3ea200684ecfc26bd..e896e2640cbcb869991229b39e3e9dd761c70366 100644 (file)
@@ -624,7 +624,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(char *proto, char *from, char *to, char *subject, char *body, char *hint);
+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);
 void sofia_glue_tech_absorb_sdp(private_object_t *tech_pvt);
 switch_status_t sofia_glue_tech_media(private_object_t *tech_pvt, const char *r_sdp);
 char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const char *host, char *val, switch_size_t len);
index 8253b8c66fb7347a83ec6838115fa89232b7a2a1..be2267b694d182a09d978b1010d9b640a6a41dab 100644 (file)
@@ -49,7 +49,8 @@ struct presence_helper {
        char last_uuid[512];
 };
 
-switch_status_t sofia_presence_chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint)
+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)
 {
        char buf[256];
        char *prof = NULL, *user = NULL, *host = NULL;
@@ -2003,12 +2004,7 @@ void sofia_presence_handle_sip_i_message(int status,
                                        }
                                }
                        } else {
-                               switch_chat_interface_t *ci;
-                               if ((ci = switch_loadable_module_get_chat_interface(proto))) {
-                                       ci->chat_send(SOFIA_CHAT_PROTO, from_addr, to_addr, "", msg, full_from);
-                               } else {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
-                               }
+                               switch_core_chat_send(proto, SOFIA_CHAT_PROTO, from_addr, to_addr, "", msg, NULL, full_from);
                        }
                        switch_safe_free(to_addr);
                        switch_safe_free(from_addr);
index 2926a42a881adc073cd6a1ad26f84423e8ca01cc..ba86212a43cef254caa8781fc08802678eaa38ed 100644 (file)
@@ -1503,6 +1503,24 @@ 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;
@@ -1594,6 +1612,8 @@ SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait)
        return ret;
 }
 
+
+
 /* For Emacs:
  * Local Variables:
  * mode:c
index 2e141625aff51f77e442850667294a0bd7475b59..fdbba42b5a39cfa6fbf976a8a8e50fd79a2c621b 100644 (file)
@@ -1353,13 +1353,9 @@ HASH_FUNC(file)
 HASH_FUNC(speech)
 HASH_FUNC(asr)
 HASH_FUNC(directory)
+HASH_FUNC(chat)
 
 
-SWITCH_DECLARE(switch_chat_interface_t *) switch_loadable_module_get_chat_interface(const char *name)
-{
-    return switch_core_hash_find_locked(loadable_modules.chat_hash, name, loadable_modules.mutex);
-}
-
 SWITCH_DECLARE(switch_say_interface_t *) switch_loadable_module_get_say_interface(const char *name)
 {
     return switch_core_hash_find_locked(loadable_modules.say_hash, name, loadable_modules.mutex);