[Freeswitch-svn] [commit] r11319 - in freeswitch/trunk/src: . include mod/applications/mod_conference mod/applications/mod_dptools mod/endpoints/mod_dingaling mod/endpoints/mod_sofia

FreeSWITCH SVN anthm at freeswitch.org
Tue Jan 20 12:49:47 PST 2009


Author: anthm
Date: Tue Jan 20 14:49:47 2009
New Revision: 11319

Log:
add chat interface EXTRAGUY-00

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

Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Tue Jan 20 14:49:47 2009
@@ -1707,6 +1707,8 @@
 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);
 ///\}
 
 /*!

Modified: freeswitch/trunk/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/trunk/src/include/switch_module_interfaces.h	(original)
+++ freeswitch/trunk/src/include/switch_module_interfaces.h	Tue Jan 20 14:49:47 2009
@@ -442,7 +442,8 @@
 	/*! 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;

Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	Tue Jan 20 14:49:47 2009
@@ -372,7 +372,9 @@
 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 @@
 						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 @@
 	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 @@
 		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 @@
 
 
 	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 @@
 
 	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;

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Tue Jan 20 14:49:47 2009
@@ -1069,16 +1069,11 @@
 
 	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_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 @@
 	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 @@
 		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);

Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Tue Jan 20 14:49:47 2009
@@ -506,7 +506,8 @@
 	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 @@
 
 		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 @@
 					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);

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	Tue Jan 20 14:49:47 2009
@@ -624,7 +624,8 @@
 
 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);

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	Tue Jan 20 14:49:47 2009
@@ -49,7 +49,8 @@
 	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 @@
 					}
 				}
 			} 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);

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Tue Jan 20 14:49:47 2009
@@ -1503,6 +1503,24 @@
 	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 @@
 	return ret;
 }
 
+
+
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/trunk/src/switch_loadable_module.c
==============================================================================
--- freeswitch/trunk/src/switch_loadable_module.c	(original)
+++ freeswitch/trunk/src/switch_loadable_module.c	Tue Jan 20 14:49:47 2009
@@ -1353,13 +1353,9 @@
 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);



More information about the Freeswitch-svn mailing list