Index: res_jabber.c
===================================================================
--- res_jabber.c	(revision 171829)
+++ res_jabber.c	(arbetskopia)
@@ -76,6 +76,7 @@
 static void aji_client_destroy(struct aji_client *obj);
 static int aji_send_exec(struct ast_channel *chan, void *data);
 static int aji_status_exec(struct ast_channel *chan, void *data);
+static int aji_join_exec(struct ast_channel *chan, void *data);
 static int aji_is_secure(struct aji_client *client);
 #ifdef HAVE_OPENSSL
 static int aji_start_tls(struct aji_client *client);
@@ -137,10 +138,11 @@
 static char *ajisend_synopsis = "JabberSend(jabber,screenname,message)";
 
 static char *ajisend_descrip =
-"JabberSend(Jabber,ScreenName,Message)\n"
+"JabberSend(Jabber,ScreenName,Message[,IsGroup])\n"
 "  Jabber - Client or transport Asterisk uses to connect to Jabber\n" 
 "  ScreenName - XMPP/Jabber JID (Name) of recipient\n" 
-"  Message - Message to be sent to the budd (UTF8)y\n";
+"  Message - Message to be sent to the buddy (UTF8)\n"
+"  IsGroup - Set to 'true' if recipient is a groupchat\n";
 
 static char *app_ajistatus = "JabberStatus";
 
@@ -155,6 +157,15 @@
 "             If not in roster variable will be set to 7\n\n"
 "Note: This application is deprecated. Please use the JABBER_STATUS() function instead.\n";
 
+static char *app_ajijoin = "JabberJoin";
+
+static char *ajijoin_synopsis = "JabberJoin(Jabber,Room)";
+
+static char *ajijoin_descrip =
+"JabberJoin(Jabber,ScreenName,Room)\n"
+"  Jabber - Client or transport Asterisk uses to connect to Jabber\n" 
+"  Room - Room to joiny\n";
+
 struct aji_client_container clients;
 struct aji_capabilities *capabilities = NULL;
 
@@ -462,7 +473,7 @@
 /*!
  * \brief Dial plan function to send a message.
  * \param chan ast_channel
- * \param data  Data is sender|reciever|message.
+ * \param data  Data is sender|reciever|message|is_group.
  * \return 0 on success,-1 on error.
  */
 static int aji_send_exec(struct ast_channel *chan, void *data)
@@ -473,6 +484,7 @@
 		AST_APP_ARG(sender);
 		AST_APP_ARG(recipient);
 		AST_APP_ARG(message);
+		AST_APP_ARG(is_group);
 	);
 
 	if (!data) {
@@ -492,10 +504,46 @@
 		return -1;
 	}
 	if (strchr(args.recipient, '@') && !ast_strlen_zero(args.message))
-		ast_aji_send_chat(client, args.recipient, args.message);
+		ast_aji_send_chat(client, args.recipient, args.message, args.is_group);
 	return 0;
 }
 
+/*!
+ * \brief Dial plan function to join a chatroom.
+ * \param chan ast_channel
+ * \param data  Data is sender|room.
+ * \return 0 on success,-1 on error.
+ */
+static int aji_join_exec(struct ast_channel *chan, void *data)
+{
+	struct aji_client *client = NULL;
+	char *s;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(sender);
+		AST_APP_ARG(room);
+	);
+
+	if (!data) {
+		ast_log(LOG_ERROR, "Usage:  JabberJoin(<sender>,<room>)\n");
+		return 0;
+	}
+	s = ast_strdupa(data);
+
+	AST_STANDARD_APP_ARGS(args, s);
+	if (args.argc < 2) {
+		ast_log(LOG_ERROR, "JabberSend requires 3 arguments: '%s'\n", (char *) data);
+		return -1;
+	}
+
+	if (!(client = ast_aji_get_client(args.sender))) {
+		ast_log(LOG_WARNING, "Could not find sender connection: '%s'\n", args.sender);
+		return -1;
+	}
+	if (!ast_strlen_zero(args.room))
+		ast_aji_join_chat(client, args.room);
+	return 0;
+}
+
 /*! 
  * \brief Tests whether the connection is secured or not
  * \return 0 if the connection is not secured
@@ -1778,12 +1826,19 @@
  * \param message
  * \return 1.
  */
-int ast_aji_send_chat(struct aji_client *client, const char *address, const char *message)
+int ast_aji_send_chat(struct aji_client *client, const char *address, const char *message, const char *is_group)
 {
 	int res = 0;
 	iks *message_packet = NULL;
+	enum iksubtype chat_type;
+
 	if (client->state == AJI_CONNECTED) {
-		message_packet = iks_make_msg(IKS_TYPE_CHAT, address, message);
+		if (is_group) {
+			chat_type = IKS_TYPE_GROUPCHAT;
+		} else {
+			chat_type = IKS_TYPE_CHAT;
+		}
+		message_packet = iks_make_msg(chat_type, address, message);
 		if (message_packet) {
 			iks_insert_attrib(message_packet, "from", client->jid->full);
 			res = ast_aji_send(client, message_packet);
@@ -2576,7 +2631,7 @@
 	}
 
 	/* XXX Does Matt really want everyone to use his personal address for tests? */ /* XXX yes he does */
-	ast_aji_send_chat(client, "mogorman@astjab.org", "blahblah");
+	ast_aji_send_chat(client, "mogorman@astjab.org", "blahblah", "");
 	ASTOBJ_CONTAINER_TRAVERSE(&client->buddies, 1, {
 		ASTOBJ_RDLOCK(iterator);
 		ast_verbose("User: %s\n", iterator->name);
@@ -2945,8 +3000,10 @@
 "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";
+"  Message:	Message to be sent to the buddy (UTF8)\n"
+"  IsGroup:     Set to 'true' if recipient is a groupchat\n";
 
+
 /*! 
  * \brief  Send a Jabber Message via call from the Manager 
  * \param s mansession Manager session
@@ -2960,6 +3017,7 @@
 	const char *jabber = astman_get_header(m,"Jabber");
 	const char *screenname = astman_get_header(m,"ScreenName");
 	const char *message = astman_get_header(m,"Message");
+	const char *is_group = astman_get_header(m,"IsGroup");
 
 	if (ast_strlen_zero(jabber)) {
 		astman_send_error(s, m, "No transport specified");
@@ -2981,7 +3039,7 @@
 		return 0;
 	}	
 	if (strchr(screenname, '@') && message){
-		ast_aji_send_chat(client, screenname, message);	
+		ast_aji_send_chat(client, screenname, message, is_group);	
 		astman_append(s, "Response: Success\r\n");
 		if (!ast_strlen_zero(id))
 			astman_append(s, "ActionID: %s\r\n",id);
@@ -3026,6 +3084,7 @@
 	ast_cli_unregister_multiple(aji_cli, sizeof(aji_cli) / sizeof(struct ast_cli_entry));
 	ast_unregister_application(app_ajisend);
 	ast_unregister_application(app_ajistatus);
+	ast_unregister_application(app_ajijoin);
 	ast_manager_unregister("JabberSend");
 	ast_custom_function_unregister(&jabberstatus_function);
 	
@@ -3053,6 +3112,7 @@
 			"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_register_application(app_ajijoin, aji_join_exec, ajijoin_synopsis, ajijoin_descrip);
 	ast_cli_register_multiple(aji_cli, sizeof(aji_cli) / sizeof(struct ast_cli_entry));
 	ast_custom_function_register(&jabberstatus_function);
 
