[asterisk-commits] bweschke: branch bweschke/originate_w_jabber r95372 - in /team/bweschke/origi...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Dec 29 19:00:23 CST 2007


Author: bweschke
Date: Sat Dec 29 19:00:22 2007
New Revision: 95372

URL: http://svn.digium.com/view/asterisk?view=rev&rev=95372
Log:
 Seems to be working now for the first side of the channel going through ast_request_and_dial on the originate manager action. Going to do some more testing now to confirm.


Modified:
    team/bweschke/originate_w_jabber/include/asterisk/jabber.h
    team/bweschke/originate_w_jabber/main/channel.c
    team/bweschke/originate_w_jabber/main/pbx.c
    team/bweschke/originate_w_jabber/res/res_jabber.c

Modified: team/bweschke/originate_w_jabber/include/asterisk/jabber.h
URL: http://svn.digium.com/view/asterisk/team/bweschke/originate_w_jabber/include/asterisk/jabber.h?view=diff&rev=95372&r1=95371&r2=95372
==============================================================================
--- team/bweschke/originate_w_jabber/include/asterisk/jabber.h (original)
+++ team/bweschke/originate_w_jabber/include/asterisk/jabber.h Sat Dec 29 19:00:22 2007
@@ -198,4 +198,6 @@
 struct aji_client *ast_aji_get_client(const char *name);
 struct aji_client_container *ast_aji_get_clients(void);
 
+void ast_install_aji_functions(int(*send_chat_ptr)(const char *, const char *, const char *));
+void ast_uninstall_aji_functions(void);
 #endif

Modified: team/bweschke/originate_w_jabber/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/originate_w_jabber/main/channel.c?view=diff&rev=95372&r1=95371&r2=95372
==============================================================================
--- team/bweschke/originate_w_jabber/main/channel.c (original)
+++ team/bweschke/originate_w_jabber/main/channel.c Sat Dec 29 19:00:22 2007
@@ -69,6 +69,7 @@
 #include "asterisk/sha1.h"
 #include "asterisk/threadstorage.h"
 #include "asterisk/slinfactory.h"
+#include "asterisk/jabber.h"
 
 struct channel_spy_trans {
 	int last_format;
@@ -194,6 +195,8 @@
 	}
 	return var;
 }
+
+static int (*ast_aji_send_chat_ptr)(const char *, const char *, const char *) = NULL;
 
 static int show_channeltypes(int fd, int argc, char *argv[])
 {
@@ -3106,13 +3109,33 @@
 	}
 }
 
+static int send_xmpp_progress(const char *jabberclient, const char *origjid, const char *chandata, const char *xmppcid, const char *progressmsg)
+{
+	char *chatmsg = NULL;
+	
+	if (!(chatmsg = ast_calloc(1, 512))) 
+		return 0;
+
+	snprintf(chatmsg, 511, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<click2call><action>progress</action><callid>%s</callid><message>%s: %s</message></click2call>\n", xmppcid, chandata, progressmsg);
+
+	ast_aji_send_chat_ptr(jabberclient, origjid, chatmsg);
+
+	ast_free(chatmsg);
+	
+	return 1;
+}
+
 struct ast_channel *__ast_request_and_dial(const char *type, int format, void *data, int timeout, int *outstate, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)
 {
 	int dummy_outstate;
 	int cause = 0;
 	struct ast_channel *chan;
 	int res = 0;
-	
+	int xmppsignaling = 0;
+	const char *origjid;
+	const char *xmppcid;
+	const char *xmppclient;	
+
 	if (outstate)
 		*outstate = 0;
 	else
@@ -3151,20 +3174,45 @@
 		ast_cdr_init(chan->cdr, chan);
 		ast_cdr_start(chan->cdr);
 	}
+
+        if (!ast_strlen_zero(pbx_builtin_getvar_helper(chan, "orig_jabberclient"))) {
+                if (option_debug > 2)
+                        ast_log(LOG_DEBUG, "This request and dial wants XMPP call progress signaling.\n");
+		if (ast_aji_send_chat_ptr && !ast_strlen_zero(pbx_builtin_getvar_helper(chan, "orig_origjid")) && !ast_strlen_zero(pbx_builtin_getvar_helper(chan, "orig_callid"))) {
+		xmppsignaling = 1;
+		
+		xmppclient = pbx_builtin_getvar_helper(chan, "orig_jabberclient");
+		origjid = pbx_builtin_getvar_helper(chan, "orig_origjid");
+		xmppcid = pbx_builtin_getvar_helper(chan, "orig_callid");
+		if (!send_xmpp_progress(xmppclient, origjid, (char *)data, xmppcid, "channel start"))
+			ast_log(LOG_WARNING, "Problem sending XMPP message");
+		} else {
+			ast_log(LOG_WARNING, "XMPP call progress was requested on a request and dial, but not all required parameters are set for it.\n"); 
+		}
+        }
+
 	if (ast_call(chan, data, 0)) {	/* ast_call failed... */
 		ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
 	} else {
 		res = 1;	/* mark success in case chan->_state is already AST_STATE_UP */
+		
 		while (timeout && chan->_state != AST_STATE_UP) {
 			struct ast_frame *f;
 			res = ast_waitfor(chan, timeout);
-			if (res <= 0) /* error, timeout, or done */
+			if (res <= 0) {/* error, timeout, or done */
+				if (xmppsignaling)
+					if (!send_xmpp_progress(xmppclient, origjid, (char *)data, xmppcid, "channel error/timeout"))
+						ast_log(LOG_WARNING, "Problem sending XMPP message");
 				break;
-			if (timeout > -1)
+			}
+			if (timeout > -1) 
 				timeout = res;
 			f = ast_read(chan);
 			if (!f) {
 				*outstate = AST_CONTROL_HANGUP;
+				if (xmppsignaling)
+					if (!send_xmpp_progress(xmppclient, origjid, (char *)data, xmppcid, "channel hangup"))
+						ast_log(LOG_WARNING, "Problem sending XMPP message");
 				res = 0;
 				break;
 			}
@@ -3172,11 +3220,25 @@
 				switch (f->subclass) {
 				case AST_CONTROL_RINGING:	/* record but keep going */
 					*outstate = f->subclass;
+					if (xmppsignaling)
+						if (!send_xmpp_progress(xmppclient, origjid, (char *)data, xmppcid, "channel ringing"))
+							ast_log(LOG_WARNING, "Problem sending XMPP message");
 					break;
 
 				case AST_CONTROL_BUSY:
+					if (xmppsignaling)
+						if (!send_xmpp_progress(xmppclient, origjid, (char *)data, xmppcid, "channel busy"))
+							ast_log(LOG_WARNING, "Problem sending XMPP message");
+					break;
 				case AST_CONTROL_CONGESTION:
+					if (xmppsignaling)
+						if (!send_xmpp_progress(xmppclient, origjid, (char *)data, xmppcid, "channel congestion"))
+							ast_log(LOG_WARNING, "Problem sending XMPP message");
+					break;
 				case AST_CONTROL_ANSWER:
+					if (xmppsignaling)
+						if (!send_xmpp_progress(xmppclient, origjid, (char *)data, xmppcid, "channel answered"))
+							ast_log(LOG_WARNING, "Problem sending XMPP message");
 					*outstate = f->subclass;
 					timeout = 0;		/* trick to force exit from the while() */
 					break;
@@ -4621,6 +4683,17 @@
 	return group;
 }
 
+
+void ast_install_aji_functions(int(*send_chat_ptr)(const char *, const char *, const char *))
+{
+	ast_aji_send_chat_ptr = send_chat_ptr;
+}
+
+void ast_uninstall_aji_functions(void)
+{
+	ast_aji_send_chat_ptr = NULL;
+}
+
 static int (*ast_moh_start_ptr)(struct ast_channel *, const char *, const char *) = NULL;
 static void (*ast_moh_stop_ptr)(struct ast_channel *) = NULL;
 static void (*ast_moh_cleanup_ptr)(struct ast_channel *) = NULL;
@@ -4703,8 +4776,11 @@
 {
 	struct ast_variable *cur;
 
-	for (cur = vars; cur; cur = cur->next)
+	for (cur = vars; cur; cur = cur->next) {
 		pbx_builtin_setvar_helper(chan, cur->name, cur->value);	
+		if (option_debug > 2)
+			ast_log(LOG_DEBUG, "ast_set_variables - name: %s - value: %s\n", cur->name, cur->value);
+	}
 }
 
 static void copy_data_from_queue(struct ast_channel_spy_queue *queue, short *buf, unsigned int samples)

Modified: team/bweschke/originate_w_jabber/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/originate_w_jabber/main/pbx.c?view=diff&rev=95372&r1=95371&r2=95372
==============================================================================
--- team/bweschke/originate_w_jabber/main/pbx.c (original)
+++ team/bweschke/originate_w_jabber/main/pbx.c Sat Dec 29 19:00:22 2007
@@ -4904,11 +4904,6 @@
 	int res;
 	struct ast_frame *f;
 	struct ast_app *app;
-
-	if (!ast_strlen_zero(pbx_builtin_getvar_helper(chan, "orig_jabberclient"))) {
-		if (option_debug > 2) 
-			ast_log(LOG_DEBUG, "This asynchronous originate wants XMPP call progress signaling.\n");
-	}
 
 	while (timeout && (chan->_state != AST_STATE_UP)) {
 		res = ast_waitfor(chan, timeout);

Modified: team/bweschke/originate_w_jabber/res/res_jabber.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/originate_w_jabber/res/res_jabber.c?view=diff&rev=95372&r1=95371&r2=95372
==============================================================================
--- team/bweschke/originate_w_jabber/res/res_jabber.c (original)
+++ team/bweschke/originate_w_jabber/res/res_jabber.c Sat Dec 29 19:00:22 2007
@@ -1816,6 +1816,26 @@
 			iks_delete(message_packet);
 	} else
 		ast_log(LOG_WARNING, "JABBER: Not connected can't send\n");
+	return 1;
+}
+
+/*!
+ * \brief Callback routine for jabber messaging outside of res_jabber itself
+ * \param client the configured XMPP client we use to connect to a XMPP server
+ * \param the JID address of where to send the chat to
+ * \param message
+ * \return 1.
+ */ 
+static int ast_aji_cb_send_chat(const char *client, const char *origjid, const char *message)
+{
+	struct aji_client *ajiclient = ast_aji_get_client(client);
+	int err = 0;
+
+	if (ajiclient)
+		err = ast_aji_send_chat(ajiclient, origjid, message);
+	else
+		ast_log(LOG_WARNING, "Couldn't get the request jabber client, %s\n", client);
+
 	return 1;
 }
 
@@ -2918,7 +2938,7 @@
 /*! \brief Unload the jabber module */
 static int unload_module(void)
 {
-
+	ast_uninstall_aji_functions();
 	ast_cli_unregister_multiple(aji_cli, sizeof(aji_cli) / sizeof(struct ast_cli_entry));
 	ast_unregister_application(app_ajisend);
 	ast_unregister_application(app_ajistatus);
@@ -2951,7 +2971,8 @@
 	ast_register_application(app_ajistatus, aji_status_exec, ajistatus_synopsis, ajistatus_descrip);
 	ast_cli_register_multiple(aji_cli, sizeof(aji_cli) / sizeof(struct ast_cli_entry));
 	ast_custom_function_register(&jabberstatus_function);
-
+	ast_install_aji_functions(ast_aji_cb_send_chat);
+	
 	return 0;
 }
 




More information about the asterisk-commits mailing list