[asterisk-commits] branch group/asterisk-xmpp r26053 - /team/group/asterisk-xmpp/res/res_jabber.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue May 9 06:51:06 MST 2006


Author: russell
Date: Tue May  9 08:51:05 2006
New Revision: 26053

URL: http://svn.digium.com/view/asterisk?rev=26053&view=rev
Log:
run this file through indent to better conform to the coding guidelines.

Just as a fun little note, indent got *really* upset with the code inside of
the uses of the ASTOBJ_TRAVERSAL macros.

Modified:
    team/group/asterisk-xmpp/res/res_jabber.c

Modified: team/group/asterisk-xmpp/res/res_jabber.c
URL: http://svn.digium.com/view/asterisk/team/group/asterisk-xmpp/res/res_jabber.c?rev=26053&r1=26052&r2=26053&view=diff
==============================================================================
--- team/group/asterisk-xmpp/res/res_jabber.c (original)
+++ team/group/asterisk-xmpp/res/res_jabber.c Tue May  9 08:51:05 2006
@@ -32,7 +32,6 @@
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
 #include "asterisk/channel.h"
 #include "asterisk/jabber.h"
 #include "asterisk/file.h"
@@ -58,8 +57,8 @@
 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 void aji_log_hook(void *data, const char *xmpp, size_t size,int is_incoming);
-static int aji_act_hook(void *data, int type, iks * node);
+static void aji_log_hook(void *data, const char *xmpp, size_t size, int is_incoming);
+static int aji_act_hook(void *data, int type, iks *node);
 static void aji_handle_iq(struct aji_client *client, iks *node);
 static void aji_handle_presence(struct aji_client *client, ikspak *pak);
 static void aji_handle_subscribe(struct aji_client *client, ikspak *pak);
@@ -67,52 +66,45 @@
 static int aji_component_initialize(struct aji_client *client);
 static int aji_client_initialize(struct aji_client *client);
 static int aji_client_connect(void *data, ikspak *pak);
-static void aji_set_presence(struct aji_client *client,char *user, int level, char *desc);
+static void aji_set_presence(struct aji_client *client, char *user, int level, char *desc);
 static int aji_do_debug(int fd, int argc, char *argv[]);
 static int aji_do_reload(int fd, int argc, char *argv[]);
 static int aji_no_debug(int fd, int argc, char *argv[]);
 static int aji_test(int fd, int argc, char *argv[]);
 static int aji_show_clients(int fd, int argc, char *argv[]);
-static int aji_create_client(char *label,struct ast_variable *var,int debug,char *utype, struct aji_client *client);
+static int aji_create_client(char *label, struct ast_variable *var, int debug, char *utype, struct aji_client *client);
 static int aji_create_buddy(char *label, struct aji_buddy *buddy);
 static int aji_create_transport(char *label, struct aji_buddy *buddy);
 static void aji_reload(void);
 static int aji_load_config(void);
 static void aji_pruneregister(struct aji_client *client);
-static int aji_register_transport(void *data,ikspak *pak);
-static int aji_register_transport2(void *data,ikspak *pak);
-static int aji_filter_roster(void *data,ikspak *pak);
-static int aji_client_info_handler(void *data,ikspak *pak);
-static int aji_dinfo_handler(void *data,ikspak *pak);
-static int aji_ditems_handler(void *data,ikspak *pak);
-static int aji_register_query_handler(void *data,ikspak *pak);
-static int aji_register_approve_handler(void *data,ikspak *pak);
+static int aji_register_transport(void *data, ikspak *pak);
+static int aji_register_transport2(void *data, ikspak *pak);
+static int aji_filter_roster(void *data, ikspak *pak);
+static int aji_client_info_handler(void *data, ikspak *pak);
+static int aji_dinfo_handler(void *data, ikspak *pak);
+static int aji_ditems_handler(void *data, ikspak *pak);
+static int aji_register_query_handler(void *data, ikspak *pak);
+static int aji_register_approve_handler(void *data, ikspak *pak);
 static int aji_reconnect(struct aji_client *client);
-static iks * jabber_make_auth (iksid *id, const char *pass, const char *sid);
-
-static char debug_usage[] =
-"Usage: JABBER debug\n"
-"	Enables dumping of JABBER packets for debugging purposes.\n";
-
-static char reload_usage[] =
-"Usage: JABBER reload\n"
-"	Enables reloading of JABBER module.\n";
-
-static char test_usage[] =
-"Usage: JABBER no debug\n"
-"	Disables dumping of JABBER packets for debugging purposes.\n";
-
-static char no_debug_usage[] =
-"Usage: JABBER test\n"
-"	Sends test massage for debugging purposes.\n";
+static iks *jabber_make_auth(iksid * id, const char *pass, const char *sid);
+
+static char debug_usage[] = "Usage: JABBER debug\n" "	Enables dumping of JABBER packets for debugging purposes.\n";
+
+static char reload_usage[] = "Usage: JABBER reload\n" "	Enables reloading of JABBER module.\n";
+
+static char test_usage[] = "Usage: JABBER no debug\n" "	Disables dumping of JABBER packets for debugging purposes.\n";
+
+static char no_debug_usage[] = "Usage: JABBER test\n" "	Sends test massage for debugging purposes.\n";
 
 static struct ast_cli_entry aji_cli[] = {
-	{{"jabber", "debug", NULL}, aji_do_debug,"Enable JABBER debugging", debug_usage},
-	{{"jabber", "reload", NULL}, aji_do_reload,"Enable JABBER debugging", reload_usage},
-	{{"jabber", "show","connected", NULL}, aji_show_clients,"Show state of clients and components",debug_usage},
-	{{"jabber", "no", "debug", NULL}, aji_no_debug,"Disable JABBER debug", no_debug_usage},
-	{{"jabber", "test", NULL}, aji_test, "Shows roster, but is genearlly used for mog's debugging.", test_usage},
-};
+	{{ "jabber", "debug", NULL}, aji_do_debug, "Enable JABBER debugging", debug_usage },
+	{{ "jabber", "reload", NULL}, aji_do_reload, "Enable JABBER debugging", reload_usage },
+	{{ "jabber", "show", "connected", NULL}, aji_show_clients, "Show state of clients and components", debug_usage },
+	{{ "jabber", "no", "debug", NULL}, aji_no_debug, "Disable JABBER debug", no_debug_usage },
+	{{ "jabber", "test", NULL}, aji_test, "Shows roster, but is genearlly used for mog's debugging.", test_usage },
+ };
+
 static const char *tdesc = "AJI - Asterisk JABBER Interface";
 
 static char *app_ajisend = "JABBERSend";
@@ -121,9 +113,7 @@
 
 static char *ajisend_descrip =
 "JABBERSend(JABBER,ScreenName,Message)\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";
+"  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";
 
 static char *app_ajistatus = "JABBERStatus";
 
@@ -133,9 +123,7 @@
 "JABBERStatus(JABBER,ScreenName,Variable)\n"
 "  JABBER - Client or transport Asterisk uses to connect to JABBER\n"
 "  ScreenName - User Name to retrieve status from.\n"
-"  Variable - Variable to store presence in will be 1-6.\n"
-"	      In order, Online, Chatty, Away, XAway, DND, Offline\n"
-"	      If not in roster variable will = 7\n";
+"  Variable - Variable to store presence in will be 1-6.\n" "	      In order, Online, Chatty, Away, XAway, DND, Offline\n" "	      If not in roster variable will = 7\n";
 
 struct aji_client_container clients;
 
@@ -149,7 +137,7 @@
  */
 static void aji_client_destroy(struct aji_client *obj)
 {
-	ASTOBJ_CONTAINER_DESTROYALL(&obj->buddies,aji_buddy_destroy);
+	ASTOBJ_CONTAINER_DESTROYALL(&obj->buddies, aji_buddy_destroy);
 	ASTOBJ_CONTAINER_DESTROY(&obj->buddies);
 
 	free(obj);
@@ -164,36 +152,37 @@
 static void aji_buddy_destroy(struct aji_buddy *obj)
 {
 	struct aji_resource *tmp = NULL;
-	while(tmp) {
+	while (tmp) {
 		tmp = obj->resources;
 		obj->resources = obj->resources->next;
 		free(tmp);
 	}
 	free(obj);
-	obj =NULL;
+	obj = NULL;
 }
 
 static struct aji_resource *aji_find_resource(struct aji_buddy *buddy, char *rname)
 {
 	struct aji_resource *res = NULL;
-	if(!buddy)
+	if (!buddy)
 		return res;
 	res = buddy->resources;
-	while(res) {
-		if(!strcasecmp(res->resource,rname)) {
+	while (res) {
+		if (!strcasecmp(res->resource, rname)) {
 			break;
 		}
-		res=res->next;
+		res = res->next;
 	}
 	return res;
 }
 
 static int gtalk_yuck(iks *node)
 {
-	if(iks_find_with_attrib(node,"c","node","http://www.google.com/xmpp/client/caps"))
+	if (iks_find_with_attrib(node, "c", "node", "http://www.google.com/xmpp/client/caps"))
 		return 1;
 	return 0;
 }
+
 /*!
  * \brief Detects the highest bit in a number.
  * \param Number you want to have evaluated.
@@ -211,24 +200,24 @@
 	return (1 << x);
 }
 
-static iks * jabber_make_auth (iksid *id, const char *pass, const char *sid)
+static iks *jabber_make_auth(iksid * id, const char *pass, const char *sid)
 {
 	iks *x, *y;
-	x = iks_new ("iq");
-	iks_insert_attrib (x, "type", "set");
-	y = iks_insert (x, "query");
-	iks_insert_attrib (y, "xmlns", IKS_NS_AUTH);
-	iks_insert_cdata (iks_insert (y, "username"), id->user, 0);
-	iks_insert_cdata (iks_insert (y, "resource"), id->resource, 0);
-	if(sid) {
+	x = iks_new("iq");
+	iks_insert_attrib(x, "type", "set");
+	y = iks_insert(x, "query");
+	iks_insert_attrib(y, "xmlns", IKS_NS_AUTH);
+	iks_insert_cdata(iks_insert(y, "username"), id->user, 0);
+	iks_insert_cdata(iks_insert(y, "resource"), id->resource, 0);
+	if (sid) {
 		char buf[41];
 		char sidpass[100];
-		snprintf(sidpass,sizeof(sidpass),"%s%s",sid,pass);
+		snprintf(sidpass, sizeof(sidpass), "%s%s", sid, pass);
 		ast_sha1_hash(buf, sidpass);
 		ast_verbose("\n");
-		iks_insert_cdata (iks_insert (y, "digest"), buf, 0);
+		iks_insert_cdata(iks_insert(y, "digest"), buf, 0);
 	} else {
-		iks_insert_cdata (iks_insert (y, "password"), pass, 0);
+		iks_insert_cdata(iks_insert(y, "password"), pass, 0);
 	}
 	return x;
 }
@@ -241,23 +230,23 @@
  */
 static int aji_status_exec(struct ast_channel *chan, void *data)
 {
-	struct aji_client *client=NULL;
-	struct aji_resource *r=NULL;
-	char *s=NULL,*sender=NULL,*screenname=NULL, *resource = NULL,*variable=NULL;
-	int stat=7, found = 0;
+	struct aji_client *client = NULL;
+	struct aji_resource *r = NULL;
+	char *s = NULL, *sender = NULL, *screenname = NULL, *resource = NULL, *variable = NULL;
+	int stat = 7, found = 0;
 	char status[2];
 	if (data) {
-		s = ast_strdupa((char *)data);
+		s = ast_strdupa((char *) data);
 		if (s) {
-			sender = strsep(&s,"|");
-			if(sender && (sender[0]!='\0')){
+			sender = strsep(&s, "|");
+			if (sender && (sender[0] != '\0')) {
 				screenname = strsep(&s, "|");
 				if (screenname && (screenname[0] != '\0')) {
 					variable = s;
 				} else {
 					ast_log(LOG_ERROR, "Bad arguments\n");
 					return -1;
-				}	
+				}
 			}
 		}
 	} else {
@@ -265,48 +254,46 @@
 		return -1;
 	}
 
-	resource = strsep(&screenname,"/");
-	
+	resource = strsep(&screenname, "/");
+
 	client = ast_aji_get_client(sender);
-	if(!client) {
+	if (!client) {
 		ast_log(LOG_WARNING, "Could not find Connection.\n");
 		return -1;
 	}
 
-	ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1,{
-	ASTOBJ_RDLOCK(iterator);
-	{
-			if(!strcasecmp(iterator->user,screenname)) {
-				found=1;
-				r = iterator->resources;
-				if(!r){ /* client hasnt signed on */
+	ASTOBJ_CONTAINER_TRAVERSE(&client->buddies, 1, {
+		ASTOBJ_RDLOCK(iterator); 
+		if (!strcasecmp(iterator->user, screenname)) {
+			found = 1; 
+			r = iterator->resources; 
+			if (!r) {	/* client hasnt signed on */
+				break;
+			} else {
+				if (resource) {
+					while (r) {
+						if (!strcasecmp(r->resource, resource)) {
+							stat = r->status; 
+							break;
+						}
+						r = r->next;
+					}
+					ast_log(LOG_WARNING, "Resource not found %s\n", resource);
+				} else {
+					stat = r->status; 
 					break;
-				} else {
-					if(resource) {
-						while(r) {
-							if(!strcasecmp(r->resource,resource)) {
-								stat=r->status;
-								break;
-							}
-							r=r->next;
-						}
-						ast_log(LOG_WARNING, "Resource not found %s\n",resource);
-					} else {
-						stat=r->status;
-						break;
-					}
 				}
 			}
-	}
+		}
 	ASTOBJ_UNLOCK(iterator);
 	});
 
-	if(!found) {			/* just a label*/
+	if (!found) {				/* just a label */
 		ast_log(LOG_WARNING, "Could not find Buddy in list.\n");
 		return -1;
 	}
-	sprintf(status,"%d",stat);
-	pbx_builtin_setvar_helper(chan, variable,status);
+	sprintf(status, "%d", stat);
+	pbx_builtin_setvar_helper(chan, variable, status);
 	return 0;
 }
 
@@ -317,25 +304,25 @@
  */
 static int aji_send_exec(struct ast_channel *chan, void *data)
 {
-	struct aji_client *client=NULL;
-
-	char *s=NULL,*sender=NULL,*recipiant=NULL,*message=NULL;
+	struct aji_client *client = NULL;
+
+	char *s = NULL, *sender = NULL, *recipiant = NULL, *message = NULL;
 	if (data) {
-		s = ast_strdupa((char *)data);
+		s = ast_strdupa((char *) data);
 		if (s) {
-			sender = strsep(&s,"|");
-			if(sender && (sender[0]!='\0')){
+			sender = strsep(&s, "|");
+			if (sender && (sender[0] != '\0')) {
 				recipiant = strsep(&s, "|");
 				if (recipiant && (recipiant[0] != '\0')) {
 					message = s;
 				} else {
 					ast_log(LOG_ERROR, "Bad arguments \n");
 					return -1;
-				}	
+				}
 			}
 		}
 		client = ast_aji_get_client(sender);
-		if(!client) {
+		if (!client) {
 			ast_log(LOG_WARNING, "Could not find Sender.\n");
 			return -1;
 		}
@@ -343,8 +330,8 @@
 		ast_log(LOG_ERROR, "Out of memory\n");
 		return -1;
 	}
-	if(strchr(recipiant,'@') && message)
-		ast_aji_send(client,recipiant,message);
+	if (strchr(recipiant, '@') && message)
+		ast_aji_send(client, recipiant, message);
 	return 0;
 }
 
@@ -352,14 +339,14 @@
  * \brief the debug loop.
  * \param aji_client structure, xml data as string, size of string, direction of packet, 1 for inbound 0 for outbound.
  */
-static void aji_log_hook(void *data, const char *xmpp, size_t size,int is_incoming)
+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);
 	if (client->debug == 1) {
 		if (is_incoming)
-			ast_verbose("\nJABBER: %s INCOMING: %s\n",client->name, xmpp);
+			ast_verbose("\nJABBER: %s INCOMING: %s\n", client->name, xmpp);
 		else
-			ast_verbose("\nJABBER: %s OUTGOING: %s\n",client->name, xmpp);
+			ast_verbose("\nJABBER: %s OUTGOING: %s\n", client->name, xmpp);
 
 	}
 	ASTOBJ_UNREF(client, aji_client_destroy);
@@ -377,86 +364,86 @@
 	iks *auth = NULL;
 
 	pak = iks_packet(node);
-	
-	
-	if(client->component == AJI_CLIENT) {
-		switch(type) {
-			case IKS_NODE_START:
-				if(client->usetls &&!iks_is_secure(client->p)) {
-					if (iks_has_tls())
-						iks_start_tls(client->p);
-					else
-						ast_log(LOG_ERROR, "gnuTLS not installed.\n");
-					break;
-				}
-				if(!client->usesasl) {
-					auth = jabber_make_auth(client->jid,client->password,iks_find_attrib(node,"id"));
-					if(auth) {
-						iks_insert_attrib(auth,"id",client->mid);
-						iks_insert_attrib(auth,"to",client->server);
-						ast_aji_increment_mid(client->mid);
-						iks_send(client->p,auth);
-						iks_delete(auth);
-					} else
-						ast_log(LOG_ERROR, "Out of memory.\n");
-				}
+
+
+	if (client->component == AJI_CLIENT) {
+		switch (type) {
+		case IKS_NODE_START:
+			if (client->usetls && !iks_is_secure(client->p)) {
+				if (iks_has_tls())
+					iks_start_tls(client->p);
+				else
+					ast_log(LOG_ERROR, "gnuTLS not installed.\n");
 				break;
-				
-			case IKS_NODE_NORMAL:
+			}
+			if (!client->usesasl) {
+				auth = jabber_make_auth(client->jid, client->password, iks_find_attrib(node, "id"));
+				if (auth) {
+					iks_insert_attrib(auth, "id", client->mid);
+					iks_insert_attrib(auth, "to", client->server);
+					ast_aji_increment_mid(client->mid);
+					iks_send(client->p, auth);
+					iks_delete(auth);
+				} else
+					ast_log(LOG_ERROR, "Out of memory.\n");
+			}
+			break;
+
+		case IKS_NODE_NORMAL:
 			{
-				int features=0;
-				if(!strcmp("stream:features",iks_name(node))) {
-					features= iks_stream_features(node);
-					if(client->usesasl) {
-						if(client->usetls && !iks_is_secure(client->p))
+				int features = 0;
+				if (!strcmp("stream:features", iks_name(node))) {
+					features = iks_stream_features(node);
+					if (client->usesasl) {
+						if (client->usetls && !iks_is_secure(client->p))
 							break;
-						if(client->authorized) {
-							if(features & IKS_STREAM_BIND) {
+						if (client->authorized) {
+							if (features & IKS_STREAM_BIND) {
 								auth = iks_make_resource_bind(client->jid);
-								if(auth) {
-									iks_insert_attrib(auth,"id",client->mid);
+								if (auth) {
+									iks_insert_attrib(auth, "id", client->mid);
 									ast_aji_increment_mid(client->mid);
-									iks_send(client->p,auth);
+									iks_send(client->p, auth);
 									iks_delete(auth);
 								} else {
 									ast_log(LOG_ERROR, "Out of memory.\n");
 									break;
 								}
 							}
-							if(features & IKS_STREAM_SESSION) {
-								auth =iks_make_session();
-								if(auth) {
-									iks_insert_attrib(auth,"id","auth");
+							if (features & IKS_STREAM_SESSION) {
+								auth = iks_make_session();
+								if (auth) {
+									iks_insert_attrib(auth, "id", "auth");
 									ast_aji_increment_mid(client->mid);
-									iks_send(client->p,auth);
+									iks_send(client->p, auth);
 									iks_delete(auth);
 								} else {
 									ast_log(LOG_ERROR, "Out of memory.\n");
 								}
 							}
 						} else {
-							features=aji_highest_bit(features);
-							if(features == IKS_STREAM_SASL_MD5)
-								iks_start_sasl (client->p, IKS_SASL_DIGEST_MD5, client->jid->user, client->password);
+							features = aji_highest_bit(features);
+							if (features == IKS_STREAM_SASL_MD5)
+								iks_start_sasl(client->p, IKS_SASL_DIGEST_MD5, client->jid->user, client->password);
 							else {
-								if(features == IKS_STREAM_SASL_PLAIN) {
+								if (features == IKS_STREAM_SASL_PLAIN) {
 									iks *x = NULL;
-									x = iks_new ("auth");
-									if(x) {
-										iks_insert_attrib (x, "xmlns", IKS_NS_XMPP_SASL);
-										int len = strlen (client->jid->user) + strlen (client->password) + 3;
+									x = iks_new("auth");
+									if (x) {
+										iks_insert_attrib(x, "xmlns", IKS_NS_XMPP_SASL);
+										int len = strlen(client->jid->user) + strlen(client->password) + 3;
 										/* XXX Check return values XXX */
-										char *s = ast_malloc (80+len);
+										char *s = ast_malloc(80 + len);
 										char *base64 = ast_malloc(80 + len * 2);
-										iks_insert_attrib (x, "mechanism", "PLAIN");
-										sprintf (s, "%c%s%c%s", 0, client->jid->user, 0, client->password);
-										ast_base64encode(base64, s,len, len * 2);
-										iks_insert_cdata (x, base64, 0);
-										iks_send (client->p, x);
-										iks_delete (x);
-										if(base64)
+										iks_insert_attrib(x, "mechanism", "PLAIN");
+										sprintf(s, "%c%s%c%s", 0, client->jid->user, 0, client->password);
+										ast_base64encode(base64, s, len, len * 2);
+										iks_insert_cdata(x, base64, 0);
+										iks_send(client->p, x);
+										iks_delete(x);
+										if (base64)
 											free(base64);
-										if(s)
+										if (s)
 											free(s);
 									} else {
 										ast_log(LOG_ERROR, "Out of memory.\n");
@@ -465,107 +452,113 @@
 							}
 						}
 					}
-				} else if (!strcmp("failure",iks_name(node))) {
-					  ast_log(LOG_ERROR, "JABBER: encryption failure. possible bad password.\n");
-				} else if (!strcmp("success",iks_name(node))) {
-					client->authorized=1;
-					iks_send_header(client->p,client->jid->server);
+				} else if (!strcmp("failure", iks_name(node))) {
+					ast_log(LOG_ERROR, "JABBER: encryption failure. possible bad password.\n");
+				} else if (!strcmp("success", iks_name(node))) {
+					client->authorized = 1;
+					iks_send_header(client->p, client->jid->server);
 				}
 				break;
 			}
-			case IKS_NODE_ERROR: {
-				ast_log(LOG_ERROR,"JABBER: Node Error\n");
+		case IKS_NODE_ERROR:{
+				ast_log(LOG_ERROR, "JABBER: Node Error\n");
 				ASTOBJ_UNREF(client, aji_client_destroy);
 				return IKS_HOOK;
 				break;
 			}
-			case IKS_NODE_STOP: {
-				ast_log(LOG_WARNING,"JABBER: Disconnected\n");
+		case IKS_NODE_STOP:{
+				ast_log(LOG_WARNING, "JABBER: Disconnected\n");
 				ASTOBJ_UNREF(client, aji_client_destroy);
 				return IKS_HOOK;
 				break;
 			}
 		}
-	} else if (client->state!=AJI_CONNECTED && client->component == AJI_COMPONENT){
-		switch(type) {
-			case IKS_NODE_START:{
-				char secret[160], shasum[320],*handshake;
-				switch(client->state) {
-					case AJI_DISCONNECTED:
-						sprintf(secret,"%s%s",pak->id,client->password);
-						ast_sha1_hash(shasum,secret);
+	} else if (client->state != AJI_CONNECTED && client->component == AJI_COMPONENT) {
+		switch (type) {
+		case IKS_NODE_START:{
+				char secret[160], shasum[320], *handshake;
+				switch (client->state) {
+				case AJI_DISCONNECTED:
+					sprintf(secret, "%s%s", pak->id, client->password);
+					ast_sha1_hash(shasum, secret);
+					handshake = NULL;
+					asprintf(&handshake, "<handshake>%s</handshake>", shasum);
+					if (handshake) {
+						iks_send_raw(client->p, handshake);
+						free(handshake);
 						handshake = NULL;
-						asprintf(&handshake, "<handshake>%s</handshake>",shasum);
-						if (handshake) {
-							iks_send_raw(client->p,handshake);
-							free(handshake);
-							handshake=NULL;
-						}
-						client->state=AJI_CONNECTED;
-						break;
-					case AJI_ALMOST:
-						client->state=AJI_CONNECTED;
-						break;
-					case AJI_CONNECTING:
-					case AJI_CONNECTED:
-						break;
+					}
+					client->state = AJI_CONNECTED;
+					break;
+				case AJI_ALMOST:
+					client->state = AJI_CONNECTED;
+					break;
+				case AJI_CONNECTING:
+				case AJI_CONNECTED:
+					break;
 				};
 				break;
 			}
-	
-			case IKS_NODE_NORMAL:{
+
+		case IKS_NODE_NORMAL:{
 				break;
 			}
-					     
-			case IKS_NODE_ERROR: {
-				ast_log(LOG_ERROR,"JABBER: Node Error\n");
+
+		case IKS_NODE_ERROR:{
+				ast_log(LOG_ERROR, "JABBER: Node Error\n");
 				ASTOBJ_UNREF(client, aji_client_destroy);
 				return IKS_HOOK;
 				break;
 			}
-			case IKS_NODE_STOP: {
-				ast_log(LOG_WARNING,"JABBER: Disconnected\n");
+		case IKS_NODE_STOP:{
+				ast_log(LOG_WARNING, "JABBER: Disconnected\n");
 				ASTOBJ_UNREF(client, aji_client_destroy);
 				return IKS_HOOK;
 				break;
 			}
 		}
 	}
-	
-	switch(pak->type) {
-		case IKS_PAK_NONE:
-			if(option_verbose > 30) ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Don't know what to do with you NONE\n");
-			break;
-		case IKS_PAK_MESSAGE:
-			if(option_verbose > 30) ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Don't know what to do with you MESSAGE\n");
-			break;
-		case IKS_PAK_PRESENCE:
-			aji_handle_presence(client,pak);
-			if(option_verbose > 30) ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Do know how to handle presence!!\n");
-			break;
-		case IKS_PAK_S10N:
-			aji_handle_subscribe(client,pak);
-			if(option_verbose > 30) ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Dont know S10N subscribe!!\n");
-			break;
-		case IKS_PAK_IQ:
-			if(option_verbose > 30) ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Dont have an IQ!!!\n");
-			aji_handle_iq(client,node);
-			break;
-		default:
-			if(option_verbose > 30) ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Dont know %i\n",pak->type );
-			break;
-	}
-	
-	iks_filter_packet (client->f,pak);
-	
+
+	switch (pak->type) {
+	case IKS_PAK_NONE:
+		if (option_verbose > 30)
+			ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Don't know what to do with you NONE\n");
+		break;
+	case IKS_PAK_MESSAGE:
+		if (option_verbose > 30)
+			ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Don't know what to do with you MESSAGE\n");
+		break;
+	case IKS_PAK_PRESENCE:
+		aji_handle_presence(client, pak);
+		if (option_verbose > 30)
+			ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Do know how to handle presence!!\n");
+		break;
+	case IKS_PAK_S10N:
+		aji_handle_subscribe(client, pak);
+		if (option_verbose > 30)
+			ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Dont know S10N subscribe!!\n");
+		break;
+	case IKS_PAK_IQ:
+		if (option_verbose > 30)
+			ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Dont have an IQ!!!\n");
+		aji_handle_iq(client, node);
+		break;
+	default:
+		if (option_verbose > 30)
+			ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Dont know %i\n", pak->type);
+		break;
+	}
+
+	iks_filter_packet(client->f, pak);
+
 	if (node)
-	 	iks_delete(node);
+		iks_delete(node);
 
 	ASTOBJ_UNREF(client, aji_client_destroy);
 	return IKS_OK;
 }
 
-static int aji_register_approve_handler(void *data,ikspak *pak)
+static int aji_register_approve_handler(void *data, ikspak *pak)
 {
 	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
 	iks *iq = NULL, *query = NULL, *item = NULL;
@@ -574,89 +567,89 @@
 	query = iks_new("query");
 	item = iks_new("item");
 
-	if(client && iq && query && item) {
-		if(!iks_find(pak->query, "remove")) {
+	if (client && iq && query && item) {
+		if (!iks_find(pak->query, "remove")) {
 			iks_insert_attrib(iq, "from", client->jid->full);
 			iks_insert_attrib(iq, "to", pak->from->full);
 			iks_insert_attrib(iq, "id", pak->id);
 			iks_insert_attrib(iq, "type", "result");
 			iks_insert_attrib(query, "xmlns", "jabber:iq:register");
-	
-			iks_insert_node(iq,query);
-			iks_send(client->p,iq);
+
+			iks_insert_node(iq, query);
+			iks_send(client->p, iq);
 			iks_insert_attrib(iq, "from", pak->from->full);
 			iks_insert_attrib(iq, "to", pak->from->full);
 			iks_insert_attrib(iq, "id", client->mid);
 			ast_aji_increment_mid(client->mid);
 			iks_insert_attrib(iq, "type", "set");
 			iks_insert_attrib(query, "xmlns", "jabber:iq:roster");
-			iks_insert_attrib(item, "subscription" , "none");
+			iks_insert_attrib(item, "subscription", "none");
 			iks_insert_attrib(item, "jid", client->jid->full);
-			iks_insert_node(query,item);
-			iks_send(client->p,iq);
+			iks_insert_node(query, item);
+			iks_send(client->p, iq);
 		}
 	} else {
 		ast_log(LOG_ERROR, "Out of memory.\n");
 	}
-	if(iq)
+	if (iq)
 		iks_delete(iq);
-	if(query)
+	if (query)
 		iks_delete(query);
-	if(item)
+	if (item)
 		iks_delete(item);
 	ASTOBJ_UNREF(client, aji_client_destroy);
 	return IKS_FILTER_EAT;
 }
 
-static int aji_register_query_handler(void *data,ikspak *pak)
+static int aji_register_query_handler(void *data, ikspak *pak)
 {
 	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
 	char *node = NULL;
 
 	client = (struct aji_client *) data;
-	
-	if(!(node = iks_find_attrib(pak->query,"node"))) {
+
+	if (!(node = iks_find_attrib(pak->query, "node"))) {
 		iks *iq = NULL, *query = NULL, *instructions = NULL;
-		char * explain =	"Welcome to Asterisk the Open Source PBX.\n";
+		char *explain = "Welcome to Asterisk the Open Source PBX.\n";
 		iq = iks_new("iq");
 		query = iks_new("query");
 		instructions = iks_new("instructions");
-		if(iq && query && instructions && client) {
+		if (iq && query && instructions && client) {
 			iks_insert_attrib(iq, "from", client->user);
 			iks_insert_attrib(iq, "to", pak->from->full);
 			iks_insert_attrib(iq, "id", pak->id);
 			iks_insert_attrib(iq, "type", "result");
 			iks_insert_attrib(query, "xmlns", "jabber:iq:register");
 			iks_insert_cdata(instructions, explain, 0);
-			iks_insert_node(iq,query);
-			iks_insert_node(query,instructions);
-			iks_send(client->p,iq);
+			iks_insert_node(iq, query);
+			iks_insert_node(query, instructions);
+			iks_send(client->p, iq);
 		} else {
 			ast_log(LOG_ERROR, "Out of memory.\n");
 		}
-		if(iq)
+		if (iq)
 			iks_delete(iq);
-		if(query)
+		if (query)
 			iks_delete(query);
-		if(instructions)
+		if (instructions)
 			iks_delete(instructions);
 	}
 	ASTOBJ_UNREF(client, aji_client_destroy);
 	return IKS_FILTER_EAT;
 }
 
-static int aji_ditems_handler(void *data,ikspak *pak)
+static int aji_ditems_handler(void *data, ikspak *pak)
 {
 	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
 	char *node = NULL;
 
-	if(!(node = iks_find_attrib(pak->query,"node"))) {
+	if (!(node = iks_find_attrib(pak->query, "node"))) {
 		iks *iq = NULL, *query = NULL, *item = NULL;
 		iq = iks_new("iq");
 		query = iks_new("query");
 		item = iks_new("item");
-		
-		if(iq && query && item) {
+
+		if (iq && query && item) {
 			iks_insert_attrib(iq, "from", client->user);
 			iks_insert_attrib(iq, "to", pak->from->full);
 			iks_insert_attrib(iq, "id", pak->id);
@@ -666,25 +659,25 @@
 			iks_insert_attrib(item, "name", "Million Dollar Asterisk Commands");
 			iks_insert_attrib(item, "jid", client->user);
 
-			iks_insert_node(iq,query);
-			iks_insert_node(query,item);
-			iks_send(client->p,iq);
+			iks_insert_node(iq, query);
+			iks_insert_node(query, item);
+			iks_send(client->p, iq);
 		} else {
 			ast_log(LOG_ERROR, "Out of memory.\n");
 		}
-		if(iq)
+		if (iq)
 			iks_delete(iq);
-		if(query)
+		if (query)
 			iks_delete(query);
-		if(item)
+		if (item)
 			iks_delete(item);
-		
-	} else if (!strcasecmp(node,"http://jabber.org/protocol/commands")) {
+
+	} else if (!strcasecmp(node, "http://jabber.org/protocol/commands")) {
 		iks *iq, *query, *confirm;
 		iq = iks_new("iq");
 		query = iks_new("query");
 		confirm = iks_new("item");
-		if(iq && query && confirm && client) {
+		if (iq && query && confirm && client) {
 			iks_insert_attrib(iq, "from", client->user);
 			iks_insert_attrib(iq, "to", pak->from->full);
 			iks_insert_attrib(iq, "id", pak->id);
@@ -693,46 +686,46 @@
 			iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
 			iks_insert_attrib(confirm, "node", "confirmaccount");
 			iks_insert_attrib(confirm, "name", "Confirm AIM account");
-			iks_insert_attrib(confirm, "jid","blog.astjab.org");
-		
-			iks_insert_node(iq,query);
-			iks_insert_node(query,confirm);
-			iks_send(client->p,iq);
+			iks_insert_attrib(confirm, "jid", "blog.astjab.org");
+
+			iks_insert_node(iq, query);
+			iks_insert_node(query, confirm);
+			iks_send(client->p, iq);
 		} else {
 			ast_log(LOG_ERROR, "Out of memory.\n");
 		}
-		if(iq)
+		if (iq)
 			iks_delete(iq);
-		if(query)
+		if (query)
 			iks_delete(query);
-		if(confirm)
+		if (confirm)
 			iks_delete(confirm);
 
-	} else if (!strcasecmp(node,"confirmaccount")) {
+	} else if (!strcasecmp(node, "confirmaccount")) {
 		iks *iq = NULL, *query = NULL, *feature = NULL;
 
 		iq = iks_new("iq");
 		query = iks_new("query");
 		feature = iks_new("feature");
-		
-		if(iq && query && feature && client) {
+
+		if (iq && query && feature && client) {
 			iks_insert_attrib(iq, "from", client->user);
 			iks_insert_attrib(iq, "to", pak->from->full);
 			iks_insert_attrib(iq, "id", pak->id);
 			iks_insert_attrib(iq, "type", "result");
 			iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
 			iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
-			iks_insert_node(iq,query);
-			iks_insert_node(query,feature);
+			iks_insert_node(iq, query);
+			iks_insert_node(query, feature);
 			iks_send(client->p, iq);
 		} else {
 			ast_log(LOG_ERROR, "Out of memory.\n");
 		}
-		if(iq)
+		if (iq)
 			iks_delete(iq);
-		if(query)
+		if (query)
 			iks_delete(query);
-		if(feature)
+		if (feature)
 			iks_delete(feature);
 	}
 
@@ -741,69 +734,69 @@
 
 }
 
-static int aji_client_info_handler(void *data,ikspak *pak)
+static int aji_client_info_handler(void *data, ikspak *pak)
 {
 	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
 	struct aji_buddy *buddy = NULL;
 	struct aji_resource *resource = NULL;
-	buddy = ASTOBJ_CONTAINER_FIND(&client->buddies,pak->from->partial);
-
-	resource = aji_find_resource(buddy,pak->from->resource);
-	
-	if(pak->subtype == IKS_TYPE_RESULT) {
-		if(iks_find_with_attrib(pak->query,"feature", "var", "http://www.google.com/xmpp/protocol/voice/v1")) {
+	buddy = ASTOBJ_CONTAINER_FIND(&client->buddies, pak->from->partial);
+
+	resource = aji_find_resource(buddy, pak->from->resource);
+
+	if (pak->subtype == IKS_TYPE_RESULT) {
+		if (iks_find_with_attrib(pak->query, "feature", "var", "http://www.google.com/xmpp/protocol/voice/v1")) {
 			ast_verbose("NO I AM JINGLECAPABLE!!!\n");
-			resource->jinglecapable=1;
+			resource->jinglecapable = 1;
 		} else
-			resource->jinglecapable=0;
-	} else if(pak->subtype == IKS_TYPE_GET) {
+			resource->jinglecapable = 0;
+	} else if (pak->subtype == IKS_TYPE_GET) {
 		iks *iq, *disco, *ident, *google, *query;
 		iq = iks_new("iq");
 		query = iks_new("query");
 		ident = iks_new("identity");
 		disco = iks_new("feature");
 		google = iks_new("feature");
-		if(iq && ident && disco && google) {
-			iks_insert_attrib(iq,"from",client->jid->full);
-			iks_insert_attrib(iq,"to",pak->from->full);
-			iks_insert_attrib(iq,"type","result");
-			iks_insert_attrib(iq,"id",pak->id);
-			iks_insert_attrib(query,"xmlns","xmlns='http://jabber.org/protocol/disco#info");
-			iks_insert_attrib(ident,"category","client");
-			iks_insert_attrib(ident,"type","pc");
-			iks_insert_attrib(ident,"name", "asterisk");
+		if (iq && ident && disco && google) {
+			iks_insert_attrib(iq, "from", client->jid->full);
+			iks_insert_attrib(iq, "to", pak->from->full);
+			iks_insert_attrib(iq, "type", "result");
+			iks_insert_attrib(iq, "id", pak->id);
+			iks_insert_attrib(query, "xmlns", "xmlns='http://jabber.org/protocol/disco#info");
+			iks_insert_attrib(ident, "category", "client");
+			iks_insert_attrib(ident, "type", "pc");
+			iks_insert_attrib(ident, "name", "asterisk");
 			iks_insert_attrib(disco, "var", "http://jabber.org/protocol/disco#info");
-			iks_insert_attrib(google,"var","http://www.google.com/xmpp/protocol/voice/v1");
-			iks_insert_node(iq,query);
+			iks_insert_attrib(google, "var", "http://www.google.com/xmpp/protocol/voice/v1");
+			iks_insert_node(iq, query);
 			iks_insert_node(query, ident);
 			iks_insert_node(query, disco);
 			iks_insert_node(query, google);
-			iks_send(client->p,iq);
-		} else 
-			ast_log(LOG_ERROR,"Out of Memory.\n");
-		if(iq)
+			iks_send(client->p, iq);
+		} else
+			ast_log(LOG_ERROR, "Out of Memory.\n");
+		if (iq)
 			iks_delete(iq);
-		if(query)
+		if (query)
 			iks_delete(query);
-		if(ident)
+		if (ident)
 			iks_delete(ident);
-		if(google)
+		if (google)
 			iks_delete(google);
-		if(disco)
+		if (disco)
 			iks_delete(disco);
-	} else if(pak->subtype == IKS_TYPE_ERROR) {
-		ast_log(LOG_NOTICE, "User %s does not support discovery.\n",pak->from->full);
+	} else if (pak->subtype == IKS_TYPE_ERROR) {
+		ast_log(LOG_NOTICE, "User %s does not support discovery.\n", pak->from->full);
 	}
 	ASTOBJ_UNREF(client, aji_client_destroy);
 	return IKS_FILTER_EAT;
 }
 
-static int aji_dinfo_handler(void *data,ikspak *pak)
+static int aji_dinfo_handler(void *data, ikspak *pak)
 {
 	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
 	char *node = NULL;
 
-	if(!(node = iks_find_attrib(pak->query,"node"))) {
+	if (!(node = iks_find_attrib(pak->query, "node"))) {
 		iks *iq = NULL, *query = NULL, *identity = NULL, *disco = NULL, *reg = NULL, *commands = NULL, *gateway = NULL, *version = NULL, *vcard = NULL, *search = NULL;
 
 		iq = iks_new("iq");
@@ -816,8 +809,8 @@
 		version = iks_new("feature");
 		vcard = iks_new("feature");
 		search = iks_new("feature");
-		
-		if(iq && query && identity && disco && reg && commands && gateway && version && vcard && search && client) {
+
+		if (iq && query && identity && disco && reg && commands && gateway && version && vcard && search && client) {
 			iks_insert_attrib(iq, "from", client->user);
 			iks_insert_attrib(iq, "to", pak->from->full);
 			iks_insert_attrib(iq, "id", pak->id);
@@ -833,49 +826,49 @@
 			iks_insert_attrib(version, "var", "jabber:iq:version");
 			iks_insert_attrib(vcard, "var", "vcard-temp");
 			iks_insert_attrib(search, "var", "jabber:iq:search");
-	
-			iks_insert_node(iq,query);
-			iks_insert_node(query,identity);
-			iks_insert_node(query,disco);
-			iks_insert_node(query,reg);
-			iks_insert_node(query,commands);
-			iks_insert_node(query,gateway);
-			iks_insert_node(query,version);
-			iks_insert_node(query,vcard);
-			iks_insert_node(query,search);
-			iks_send(client->p,iq);
+
+			iks_insert_node(iq, query);
+			iks_insert_node(query, identity);
+			iks_insert_node(query, disco);
+			iks_insert_node(query, reg);
+			iks_insert_node(query, commands);
+			iks_insert_node(query, gateway);
+			iks_insert_node(query, version);
+			iks_insert_node(query, vcard);
+			iks_insert_node(query, search);
+			iks_send(client->p, iq);
 		} else {
 			ast_log(LOG_ERROR, "Out of memory.\n");
 		}
-		
-		if(iq)
+
+		if (iq)
 			iks_delete(iq);
-		if(query)
+		if (query)
 			iks_delete(query);
-		if(identity)
+		if (identity)
 			iks_delete(identity);
-		if(disco)
+		if (disco)
 			iks_delete(disco);
-		if(reg)
+		if (reg)
 			iks_delete(reg);
-		if(commands)
+		if (commands)
 			iks_delete(commands);
-		if(gateway)
+		if (gateway)
 			iks_delete(gateway);
-		if(version)
+		if (version)
 			iks_delete(version);
-		if(vcard)
+		if (vcard)
 			iks_delete(vcard);
-		if(search)
+		if (search)
 			iks_delete(search);
 
-	} else if (!strcasecmp(node,"http://jabber.org/protocol/commands")) {
+	} else if (!strcasecmp(node, "http://jabber.org/protocol/commands")) {
 		iks *iq = NULL, *query = NULL, *confirm = NULL;
 		iq = iks_new("iq");
 		query = iks_new("query");
 		confirm = iks_new("item");
-		
-		if(iq && query && confirm && client) {
+
+		if (iq && query && confirm && client) {
 			iks_insert_attrib(iq, "from", client->user);
 			iks_insert_attrib(iq, "to", pak->from->full);
 			iks_insert_attrib(iq, "id", pak->id);
@@ -884,44 +877,44 @@
 			iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
 			iks_insert_attrib(confirm, "node", "confirmaccount");
 			iks_insert_attrib(confirm, "name", "Confirm AIM account");
-			iks_insert_attrib(confirm, "jid",client->user);
-			iks_insert_node(iq,query);
-			iks_insert_node(query,confirm);
-			iks_send(client->p,iq);
+			iks_insert_attrib(confirm, "jid", client->user);
+			iks_insert_node(iq, query);
+			iks_insert_node(query, confirm);
+			iks_send(client->p, iq);
 		} else {
 			ast_log(LOG_ERROR, "Out of memory.\n");
 		}
-		if(iq)
+		if (iq)
 			iks_delete(iq);
-		if(query)
+		if (query)
 			iks_delete(query);
-		if(confirm)
+		if (confirm)
 			iks_delete(confirm);
-		
-	} else if (!strcasecmp(node,"confirmaccount")) {
+
+	} else if (!strcasecmp(node, "confirmaccount")) {
 		iks *iq = NULL, *query = NULL, *feature = NULL;
 
 		iq = iks_new("iq");
 		query = iks_new("query");
 		feature = iks_new("feature");
-		if(iq && query && feature && client) {
+		if (iq && query && feature && client) {
 			iks_insert_attrib(iq, "from", client->user);
 			iks_insert_attrib(iq, "to", pak->from->full);
 			iks_insert_attrib(iq, "id", pak->id);
 			iks_insert_attrib(iq, "type", "result");
 			iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
 			iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
-			iks_insert_node(iq,query);
-			iks_insert_node(query,feature);
+			iks_insert_node(iq, query);
+			iks_insert_node(query, feature);
 			iks_send(client->p, iq);
 		} else {
 			ast_log(LOG_ERROR, "Out of memory.\n");
 		}
-		if(iq)
+		if (iq)
 			iks_delete(iq);
-		if(query)
+		if (query)
 			iks_delete(query);
-		if(feature)
+		if (feature)
 			iks_delete(feature);
 	}
 
@@ -936,7 +929,8 @@
  */
 static void aji_handle_iq(struct aji_client *client, iks *node)
 {
-	if(option_verbose > 77) ast_verbose("MWAHHAHAHA NOTHING TO SEE HERE!\n");
+	if (option_verbose > 77)
+		ast_verbose("MWAHHAHAHA NOTHING TO SEE HERE!\n");
 }
 
 /*!
@@ -948,62 +942,61 @@
 {
 	int status, priority;
 	struct aji_buddy *buddy = NULL;
-	struct aji_resource *tmp = NULL, *last= NULL, *found = NULL;
+	struct aji_resource *tmp = NULL, *last = NULL, *found = NULL;
 	char *version, *node;
 	char capabilities[100];
-	
-	buddy = ASTOBJ_CONTAINER_FIND(&client->buddies,pak->from->partial);
-	if(!buddy)
-	{
-		ast_log(LOG_WARNING, "Got presence packet from %s, somone not in our roster!!!!\n",pak->from->partial);
+

[... 1559 lines stripped ...]


More information about the asterisk-commits mailing list