[asterisk-commits] mogorman: trunk r39248 - /trunk/res/res_jabber.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Aug 7 15:03:51 MST 2006


Author: mogorman
Date: Mon Aug  7 17:03:50 2006
New Revision: 39248

URL: http://svn.digium.com/view/asterisk?rev=39248&view=rev
Log:
This patch allows for a user to send messages and 
monitor a jabber connection over manager.
patches from 7673 and 7666 with minor changes.

Modified:
    trunk/res/res_jabber.c

Modified: trunk/res/res_jabber.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_jabber.c?rev=39248&r1=39247&r2=39248&view=diff
==============================================================================
--- trunk/res/res_jabber.c (original)
+++ trunk/res/res_jabber.c Mon Aug  7 17:03:50 2006
@@ -50,10 +50,12 @@
 #include "asterisk/module.h"
 #include "asterisk/astobj.h"
 #include "asterisk/astdb.h"
+#include "asterisk/manager.h"
 
 #define JABBER_CONFIG "jabber.conf"
 
 /*-- Forward declarations */
+static int manager_jabber_send( struct mansession *s, struct message *m );
 static int aji_highest_bit(int number);
 static void aji_buddy_destroy(struct aji_buddy *obj);
 static void aji_client_destroy(struct aji_client *obj);
@@ -419,6 +421,7 @@
 static void aji_log_hook(void *data, const char *xmpp, size_t size, int is_incoming)
 {
 	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
+	manager_event(EVENT_FLAG_USER, "JabberEvent", "Account: %s\r\n Packet: %s", client->name, xmpp);
 
 	if (client->debug == 1) {
 		if (is_incoming)
@@ -2209,6 +2212,55 @@
 	return &clients;
 }
 
+static char mandescr_jabber_send[] =
+"Description: Sends a message to a Jabber Client.\n"
+"Variables: \n"
+"  Jabber:	Client or transport Asterisk uses to connect to JABBER.\n"
+"  ScreenName:	User Name to message.\n"
+"  Message:	Message to be sent to the buddy\n";
+
+/*! \brief  Send a Jabber Message via call from the Manager */
+static int manager_jabber_send( struct mansession *s, struct message *m )
+{
+	struct aji_client *client = NULL;
+	char *id = astman_get_header(m,"ActionID");
+	char *jabber = astman_get_header(m,"Jabber");
+	char *screenname = astman_get_header(m,"ScreenName");
+	char *message = astman_get_header(m,"Message");
+
+	if (ast_strlen_zero(jabber)) {
+		astman_send_error(s, m, "No transport specified");
+		return 0;
+	}
+	if (ast_strlen_zero(screenname)) {
+		astman_send_error(s, m, "No ScreenName specified");
+		return 0;
+	}
+	if (ast_strlen_zero(message)) {
+		astman_send_error(s, m, "No Message specified");
+		return 0;
+	}
+
+	astman_send_ack(s, m, "Attempting to send Jabber Message");
+	client = ast_aji_get_client(jabber);
+	if (!client) {
+		astman_send_error(s, m, "Could not find Sender");
+		return 0;
+	}	
+	if (strchr(screenname, '@') && message){
+		ast_aji_send(client, screenname, message);	
+		if (!ast_strlen_zero(id))
+			astman_append(s, "ActionID: %s\r\n",id);
+		astman_append(s, "Response: Success\r\n");
+		return 0;
+	}
+	if (!ast_strlen_zero(id))
+		astman_append(s, "ActionID: %s\r\n",id);
+	astman_append(s, "Response: Failure\r\n");
+	return 0;
+}
+
+
 static void aji_reload()
 {
 	ASTOBJ_CONTAINER_MARKALL(&clients);
@@ -2232,7 +2284,7 @@
 {
 	ast_cli_unregister_multiple(aji_cli, sizeof(aji_cli) / sizeof(aji_cli[0]));
 	ast_unregister_application(app_ajisend);
-
+	ast_manager_unregister("JabberSend");
 	ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
 		ASTOBJ_RDLOCK(iterator);
 		if (option_verbose > 2)
@@ -2254,6 +2306,8 @@
 {
 	ASTOBJ_CONTAINER_INIT(&clients);
 	aji_reload();
+	ast_manager_register2("JabberSend", EVENT_FLAG_SYSTEM, manager_jabber_send,
+			"Sends a message to a Jabber Client", mandescr_jabber_send);
 	ast_register_application(app_ajisend, aji_send_exec, ajisend_synopsis, ajisend_descrip);
 	ast_register_application(app_ajistatus, aji_status_exec, ajistatus_synopsis, ajistatus_descrip);
 	ast_cli_register_multiple(aji_cli, sizeof(aji_cli) / sizeof(aji_cli[0]));



More information about the asterisk-commits mailing list