[asterisk-commits] branch mogorman/asterisk-xmpp r8705 - /team/mogorman/asterisk-xmpp/res/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Jan 26 00:04:57 MST 2006


Author: mogorman
Date: Thu Jan 26 01:04:57 2006
New Revision: 8705

URL: http://svn.digium.com/view/asterisk?rev=8705&view=rev
Log:
white space fixes

Modified:
    team/mogorman/asterisk-xmpp/res/res_xmpp.c

Modified: team/mogorman/asterisk-xmpp/res/res_xmpp.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/res_xmpp.c?rev=8705&r1=8704&r2=8705&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/res_xmpp.c (original)
+++ team/mogorman/asterisk-xmpp/res/res_xmpp.c Thu Jan 26 01:04:57 2006
@@ -88,7 +88,6 @@
 static int axi_register_transport2(void *udata,ikspak *pak);
 static void axi_increment_mid(char *mid);
 static int axi_filter_roster(void *udata,ikspak *pak);
-unsigned char * base64_encode(const unsigned char *in, size_t len);
 static void axi_handle_discovery(struct axi_master *asterisk, ikspak *pak);
 
 static char debug_usage[] =
@@ -126,7 +125,8 @@
  * \param obj is the structure we will delete.
  * \return void.
  */
-static void axi_master_destroy(struct axi_master *obj){
+static void axi_master_destroy(struct axi_master *obj)
+{
 	ASTOBJ_CONTAINER_DESTROYALL(&obj->buddies,axi_buddy_destroy);
 	ASTOBJ_CONTAINER_DESTROY(&obj->buddies);
 
@@ -172,34 +172,6 @@
 			break;
 	}
 	return (1 << x);
-}
-
-unsigned char * base64_encode(const unsigned char *in, size_t len)
-{
-	static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-	char *res,*tmp;
-	tmp = malloc((len/3+1)*4 +1);
-	res = tmp;
-	for(; len >= 3;len = len -3){
-		*tmp++ = alphabet[in[0] >> 2];
-		*tmp++ = alphabet[((in[0] << 4) & 0x30) | (in[1] >> 4)];
-		*tmp++ = alphabet[((in[1] << 2) & 0x3c) | (in[2] >> 6)];
-		*tmp++ = alphabet[in[2] & 0x3f];
-		in += 3;
-	}
-	if (len > 0){
-		unsigned char fragment;
-		
-		*tmp++ = alphabet[in[0] >> 2];
-		fragment = (in[0] << 4) & 0x30;
-		if (len > 1)
-			fragment |= in[1] >> 4;
-		*tmp++ = alphabet[fragment];
-		*tmp++ = (len < 2) ? '=' : alphabet[(in[1] << 2) & 0x3c];
-		*tmp++ = '=';
-	}
-	*tmp = '\0';
-	return res;
 }
 
 static int axi_status_exec(struct ast_channel *chan, void *data)
@@ -224,24 +196,21 @@
 				}	
 			}
 		}
-	}else{
+	} else {
 		ast_log(LOG_ERROR, "Out of memory\n");
 		return -1;
 	}
-	if(strchr(screenname,'@')) /*real xmpp id */
-	{
+	if(strchr(screenname,'@')) { /*real xmpp id */
 			ASTOBJ_CONTAINER_TRAVERSE2(&asterisk->buddies,1,1,{
 			ASTOBJ_RDLOCK(iterator1);
 			{
-				if(!strcasecmp(iterator1->user,screenname))
-				{
+				if(!strcasecmp(iterator1->user,screenname)) {
 					stat=iterator1->status;
 				}
 			}
 			ASTOBJ_UNLOCK(iterator1);
 			});
-	}
-	else{			/* just a label*/
+	} else {			/* just a label*/
 		buddy=ASTOBJ_CONTAINER_FIND(&asterisk->buddies,screenname);
 		stat=buddy->status;
 	}
@@ -270,7 +239,7 @@
 				}	
 			}
 		}
-	}else{
+	} else {
 		ast_log(LOG_ERROR, "Out of memory\n");
 		return -1;
 	}
@@ -302,17 +271,14 @@
 
 	while( tmp ) {
 			if (!strcasecmp(action, tmp->action)) {
-					if (tmp->func(asterisk,user, message, type))
-					{
+					if (tmp->func(asterisk,user, message, type)) {
 						return -1;
 					}
-			}
-			else{
+			} else {
 				tmp = tmp->next;
 			}
 	}
 	return 0;
-	
 }
 
 static int axi_act_hook(void *udata, int type, iks * node)
@@ -322,13 +288,13 @@
 	pak=iks_packet(node);
 
 	iks_filter_packet (asterisk->f,pak);
-	switch(type){
+	switch(type) {
 		case IKS_NODE_START:
-			if(asterisk->usetls &&!iks_is_secure(asterisk->p)){
+			if(asterisk->usetls &&!iks_is_secure(asterisk->p)) {
 				iks_start_tls(asterisk->p);
 				break;
 			}
-			if(!asterisk->usesasl){
+			if(!asterisk->usesasl) {
 				iks *auth;
 				iks_filter_add_rule (asterisk->f, axi_client_connect, asterisk, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,IKS_RULE_ID,asterisk->mid, IKS_RULE_DONE);
 
@@ -344,19 +310,20 @@
 		{
 			int features=0;
 			iks *auth;
-			if(!strcmp("stream:features",iks_name(node))){
+			if(!strcmp("stream:features",iks_name(node))) {
 				features= iks_stream_features(node);
-				if(asterisk->usesasl){
-					if(asterisk->usetls && !iks_is_secure(asterisk->p)) break;
-					if(asterisk->authorized){
-						if(features & IKS_STREAM_BIND){
+				if(asterisk->usesasl) {
+					if(asterisk->usetls && !iks_is_secure(asterisk->p))
+						break;
+					if(asterisk->authorized) {
+						if(features & IKS_STREAM_BIND) {
 							iks_filter_add_rule (asterisk->f, axi_client_connect, asterisk, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_DONE);
 							auth = iks_make_resource_bind(asterisk->jid);
 							axi_increment_mid(asterisk->mid);
 							iks_send(asterisk->p,auth);
 							iks_delete(auth);
 						}
-						if(features & IKS_STREAM_SESSION){
+						if(features & IKS_STREAM_SESSION) {
 							iks_filter_add_rule (asterisk->f, axi_client_connect, asterisk, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "auth", IKS_RULE_DONE);
 							auth =iks_make_session();
 							iks_insert_attrib(auth,"id","auth");
@@ -364,13 +331,12 @@
 							iks_send(asterisk->p,auth);
 							iks_delete(auth);
 						}
-					}
-					else{
+					} else {
 						features=axi_highest_bit(features);
 						if(features == IKS_STREAM_SASL_MD5)
 							iks_start_sasl (asterisk->p, IKS_SASL_DIGEST_MD5, asterisk->jid->user, asterisk->password);
-						else{
-							if(features == IKS_STREAM_SASL_PLAIN){
+						else {
+							if(features == IKS_STREAM_SASL_PLAIN) {
 								iks *x;
 								x = iks_new ("auth");
 								iks_insert_attrib (x, "xmlns", IKS_NS_XMPP_SASL);
@@ -379,7 +345,8 @@
 								char *base64;
 								iks_insert_attrib (x, "mechanism", "PLAIN");
 								sprintf (s, "%c%s%c%s", 0, asterisk->jid->user, 0, asterisk->password);
-								base64 = base64_encode (s, len);
+								ast_base64encode(base64,s,len,((len/3+1)*4 +1));
+
 								iks_insert_cdata (x, base64, 0);
 								iks_free (base64);
 								iks_free (s);
@@ -389,13 +356,14 @@
 						}
 					}
 				}
-			}else if (!strcmp("failure",iks_name(node))){
+			} else if (!strcmp("failure",iks_name(node))) {
 				  ast_verbose("ENCRYPTION FAILURE");
-			} else if (!strcmp("success",iks_name(node))){
+			} else if (!strcmp("success",iks_name(node))) {
 				asterisk->authorized=1;
 				iks_send_header(asterisk->p,asterisk->jid->server);
 			}
-			switch(pak->type){
+			
+			switch(pak->type) {
 				case IKS_PAK_NONE:
 					ast_verbose(VERBOSE_PREFIX_3 "XMPP: I Don't know what to do with you NONE\n");
 					break;
@@ -431,9 +399,8 @@
 			break;
 		}
 	}
-	if (node){
+	if (node)
 	 	iks_delete(node);
-	}
 	if(asterisk)
 		ASTOBJ_UNREF(asterisk, axi_master_destroy);
 	return IKS_OK;
@@ -467,7 +434,7 @@
 {
 	if(pak->subtype==IKS_TYPE_GET) {
 		ast_verbose("this is it %s\n",iks_string(asterisk->stack,pak->query));
-		if(iks_find_with_attrib(pak->x,"query","xmlns","http://jabber.org/protocol/disco#info")){
+		if(iks_find_with_attrib(pak->x,"query","xmlns","http://jabber.org/protocol/disco#info")) {
 			axi_handle_discovery(asterisk,pak);
 		}
 	}
@@ -527,7 +494,7 @@
 			ASTOBJ_UNLOCK(iterator);
 		});
 
-	if(buddy){
+	if(buddy) {
 		agent=buddy->name;
 		channel=buddy->channel;
 		buddy->status=(pak->show==0?6:pak->show);
@@ -564,13 +531,12 @@
 {
 	int res=0;
 	iks *message_packet;
-	if(asterisk->state==AXI_CONNECTED){
+	if(asterisk->state==AXI_CONNECTED) {
 		message_packet=iks_make_msg(IKS_TYPE_CHAT, address, message);
 		iks_insert_attrib(message_packet,"from",asterisk->jid->full);
 		res =iks_send(asterisk->p,message_packet);
 	 	iks_delete(message_packet);
-	}
-	else
+	} else
 		ast_verbose("We arent connected dont send\n");
 	return 1;
 }
@@ -644,19 +610,19 @@
 {
 	int res=0;
 	struct axi_master *asterisk = ASTOBJ_REF((struct axi_master *) data);
-	while (res == IKS_OK){
+	while (res == IKS_OK) {
 		res =iks_recv(asterisk->p,1);
 		printf("res = %d\n",res);
-		if(res==IKS_HOOK){
+		if(res==IKS_HOOK) {
 			ast_verbose("HOOK!!!!");
 			break;
 		}
-		if(res==IKS_NET_TLSFAIL){
+		if(res==IKS_NET_TLSFAIL) {
 			ast_verbose("FAILURE TLS");
 			break;
 		}
 		asterisk->timeout--;
-		if(asterisk->timeout == 0 && asterisk->state !=AXI_CONNECTED){
+		if(asterisk->timeout == 0 && asterisk->state !=AXI_CONNECTED) {
 			res = -1;
 			ast_verbose("Network Timeout");
 		}
@@ -695,9 +661,9 @@
 	asterisk =ASTOBJ_REF((struct axi_master *) udata);
 	ASTOBJ_CONTAINER_TRAVERSE(&asterisk->buddies,1, {
 		ASTOBJ_RDLOCK(iterator);
-		if(iterator->btype==AXI_TRANS ){
+		if(iterator->btype==AXI_TRANS ) {
 			buddy=iterator;
-			}
+		}
 		ASTOBJ_UNLOCK(iterator);
 	});
 	iks_filter_remove_hook(asterisk->f,axi_register_transport);
@@ -753,7 +719,7 @@
 	iks_delete(regquery);
 	iks_delete(reguser);
 	iks_delete(regpass);
-	if(asterisk){
+	if(asterisk) {
 		ASTOBJ_UNREF(asterisk,axi_master_destroy);
 	}
 	return IKS_FILTER_EAT;
@@ -791,17 +757,15 @@
 			iks_delete(removequery);
 			iks_delete(removeitem);
 			delete = ASTOBJ_CONTAINER_FIND_UNLINK(&asterisk->buddies,iterator->name);
-			if(delete)
-			{
+			if(delete) {
 				ASTOBJ_UNREF(delete,axi_buddy_destroy);
 			}
 			break;
 		case AXI_REGISTER:
 			ast_verbose("REGISTER THIS USER %s\n",iterator->name);
-			if(iterator->btype==AXI_USER){ /*if it is not a transport */
+			if(iterator->btype==AXI_USER) { /*if it is not a transport */
 				res =iks_send(asterisk->p,iks_make_s10n(IKS_TYPE_SUBSCRIBE,iterator->name,"Greetings I am the Asterisk Open Source PBX and I want to subscribe to your presence\n"));
-			}
-			else{
+			} else {
 				iks_filter_add_rule(asterisk->f,axi_register_transport,asterisk,
 						IKS_RULE_TYPE,IKS_PAK_IQ,IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,IKS_RULE_NS,
 						"http://jabber.org/protocol/disco#items",IKS_RULE_DONE);
@@ -833,17 +797,15 @@
 		ASTOBJ_RDLOCK(iterator);
 		x = iks_child(pak->query);
 		flag=0;
-		while(x){
-			if(iks_strcmp(iks_name(x), "item") == 0){
-				if(strlen(iterator->pass)!=0){
-					if(!strcasecmp(iterator->host,iks_find_attrib(x,"jid"))){
+		while(x) {
+			if(iks_strcmp(iks_name(x), "item") == 0) {
+				if(strlen(iterator->pass)!=0) {
+					if(!strcasecmp(iterator->host,iks_find_attrib(x,"jid"))) {
 						iterator->on_roster=AXI_DONOTHING;
 						flag=1;
 					}
-				}
-				else{
-					if(!strcasecmp(iterator->name,iks_find_attrib(x,"jid")))
-					{
+				} else {
+					if(!strcasecmp(iterator->name,iks_find_attrib(x,"jid"))) {
 						flag=1;
 						iterator->on_roster=AXI_DONOTHING;
 					}
@@ -867,19 +829,18 @@
 		if(iks_strcmp(iks_name(x), "item") == 0){
 			ASTOBJ_CONTAINER_TRAVERSE(&asterisk->buddies,1, {
 				ASTOBJ_RDLOCK(iterator);
-				if(strlen(iterator->pass)!=0){
+				if(strlen(iterator->pass)!=0) {
 					if(!strcasecmp(iterator->host,iks_find_attrib(x,"jid")))
 						flag=1;
-				}
-				else{
+				} else {
 					if(!strcasecmp(iterator->name,iks_find_attrib(x,"jid")))
 						flag=1;
 				}
 				ASTOBJ_UNLOCK(iterator);
 			});
 			
-			if(!flag){
-				if(asterisk->pruneregister==1||asterisk->pruneregister==3){
+			if(!flag) {
+				if(asterisk->pruneregister==1||asterisk->pruneregister==3) {
 					buddy = (struct axi_buddy *)malloc(sizeof(struct axi_buddy));
 					if(!buddy)
 						ast_log(LOG_WARNING, "Out of memory\n");
@@ -890,7 +851,7 @@
 					ast_copy_string(buddy->user, iks_find_attrib(x,"jid"),sizeof(buddy->user));
 					buddy->on_roster=AXI_PRUNE;
 					ASTOBJ_UNLOCK(buddy);
-					if(buddy){
+					if(buddy) {
 						ASTOBJ_CONTAINER_LINK(&asterisk->buddies,buddy);
 						ASTOBJ_UNREF(buddy, axi_buddy_destroy);
 					}
@@ -901,7 +862,7 @@
 	}
 	
 	iks_delete(x);
-	axi_pruneregister(asterisk);
+//	axi_pruneregister(asterisk);
 	iks_filter_remove_hook(asterisk->f,axi_filter_roster);
 	return IKS_FILTER_EAT;
 }
@@ -915,14 +876,14 @@
 	memset(asterisk,0,sizeof(struct axi_master));
 	asterisk =ASTOBJ_REF((struct axi_master *) udata);
 	
-	if(asterisk->state==AXI_DISCONNECTED){
+	if(asterisk->state==AXI_DISCONNECTED) {
 		asterisk->state=AXI_CONNECTING;
 		asterisk->jid =(iks_find_cdata(pak->query,"jid"))?iks_id_new(iks_parser_stack(asterisk->p),iks_find_cdata(pak->query,"jid")):asterisk->jid;
 		ast_verbose("HELLO %s anddd %s\n",asterisk->jid->full,iks_find_cdata(pak->query,"jid"));
 		iks_filter_remove_hook(asterisk->f,axi_client_connect);
 	}
 
-	if(asterisk->state == AXI_CONNECTING){
+	if(asterisk->state == AXI_CONNECTING) {
 		iks_filter_add_rule(asterisk->f, axi_filter_roster, asterisk, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "roster", IKS_RULE_DONE);
 		roster = iks_make_iq(IKS_TYPE_GET,IKS_NS_ROSTER);
 		asterisk->state=AXI_CONNECTED;
@@ -972,7 +933,7 @@
 					break;
 			
 	};
-	if(asterisk){
+	if(asterisk) {
 		ASTOBJ_UNREF(asterisk,axi_master_destroy);
 	}
 	return IKS_FILTER_EAT;
@@ -990,14 +951,13 @@
 		iks_filter_delete(asterisk->f);
 	
 	iks_set_log_hook(asterisk->p,axi_log_hook);
-	if(!strchr(asterisk->user,'/')){
+	if(!strchr(asterisk->user,'/')) {
 		ast_verbose("blah blaah!\n");
 		resource = (char *)malloc(strlen(asterisk->user) + 9); /*+ 9 for asterisk / */
 		sprintf(resource,"%s/asterisk",asterisk->user);
 		asterisk->jid = iks_id_new(iks_parser_stack(asterisk->p),resource);
 		free(resource);
-	}
-	else{
+	} else {
 		ast_verbose("ssddblah blaah!\n");
 		asterisk->jid = iks_id_new(iks_parser_stack(asterisk->p),asterisk->user);
 	}
@@ -1027,7 +987,7 @@
 
 int ast_axi_disconnect(struct axi_master *asterisk)
 {
-	if(asterisk){
+	if(asterisk) {
 		ast_verbose(VERBOSE_PREFIX_3"DISCO!\n");
 		iks_disconnect(asterisk->p);
 		iks_parser_delete(asterisk->p);
@@ -1059,13 +1019,11 @@
 
 	ast_verbose(VERBOSE_PREFIX_3 "XMPP: Debugging Enabled for %s %s %s %s %s.\n",argv[0],argv[1],argv[2],argv[3],argv[4]);
 	temp = ASTOBJ_CONTAINER_FIND(&masters, argv[4]);
-	if(temp)
-	{
+	if(temp) {
 		temp->debug=1;
 		ast_verbose(VERBOSE_PREFIX_3 "XMPP: Debugging Enabled for %s %s %s %s %s.\n",argv[0],argv[1],argv[2],argv[3],argv[4]);
 		ASTOBJ_UNREF(temp,axi_master_destroy);
-	}
-	else
+	} else
 		ast_verbose(VERBOSE_PREFIX_3 "XMPP: %s not found.\n",argv[4]);
 
 	return RESULT_SUCCESS;
@@ -1079,13 +1037,11 @@
 	ast_verbose(VERBOSE_PREFIX_3 "XMPP: Debugging Disabled for %s %s %s %s %s.\n",argv[0],argv[1],argv[2],argv[3],argv[4]);
 
 	temp = ASTOBJ_CONTAINER_FIND(&masters, argv[5]);
-	if(temp)
-	{
+	if(temp) {
 		temp->debug=0;
 		ast_verbose(VERBOSE_PREFIX_3 "XMPP: Debugging Disabled for %s %s %s %s %s.\n",argv[0],argv[1],argv[2],argv[3],argv[4]);
 		ASTOBJ_UNREF(temp,axi_master_destroy);
-	}
-	else
+	} else
 		ast_verbose(VERBOSE_PREFIX_3 "XMPP: %s not found.\n",argv[5]);
 
 	return RESULT_SUCCESS;
@@ -1276,7 +1232,7 @@
 			asterisk->pruneregister = (ast_false(var->value))?asterisk->pruneregister++:asterisk->pruneregister--;
 		if(!strcasecmp(var->name,"noautoregister"))
 			asterisk->pruneregister = (ast_false(var->value))?asterisk->pruneregister+2:asterisk->pruneregister-2;
-		if(!strcasecmp(var->name,"buddy")||!strcasecmp(var->name,"transport")){
+		if(!strcasecmp(var->name,"buddy")||!strcasecmp(var->name,"transport")) {
 			buddy= malloc(sizeof(struct axi_buddy));
 			memset(buddy,0,sizeof(struct axi_buddy));
 			ASTOBJ_INIT(buddy);
@@ -1300,20 +1256,15 @@
 	if(!buddy)
 		ast_log(LOG_WARNING, "Out of memory\n");
 	server=label;
-	if((buddyname = strchr(label,',')))
-	{
+	if((buddyname = strchr(label,','))) {
 		*buddyname='\0';
 		buddyname++;
-		if(buddyname && buddyname[0] !='\0')
-		{
-			if((user = strchr(buddyname,',')))
-			{
+		if(buddyname && buddyname[0] !='\0') {
+			if((user = strchr(buddyname,','))) {
 				*user='\0';
 				user++;
-				if(user && user[0] !='\0')
-				{
-					if((pass = strchr(user,',')))
-					{
+				if(user && user[0] !='\0') {
+					if((pass = strchr(user,','))) {
 						*pass='\0';
 						pass++;
 						ast_copy_string(buddy->pass,user,sizeof(buddy->pass));
@@ -1334,8 +1285,7 @@
 	char *channel=NULL;
 	if(!buddy)
 		ast_log(LOG_WARNING, "Out of memory\n");
-	if((channel = strchr(label,',')))
-	{
+	if((channel = strchr(label,','))) {
 		*channel='\0';
 		channel++;
 		ast_copy_string(buddy->channel,channel,sizeof(buddy->channel));
@@ -1354,17 +1304,17 @@
 	struct axi_master *asterisk;
 
 	cfg = ast_config_load(XMPP_CONFIG);
-	if(!cfg){
+	if(!cfg) {
 		ast_log(LOG_WARNING, "No such configuration file %s\n", XMPP_CONFIG);
 		return 0;
 	}
 
 	cat = ast_category_browse(cfg,NULL);
 	
-	while(cat){
-		if(strcasecmp(cat, "general")){
+	while(cat) {
+		if(strcasecmp(cat, "general")) {
 			utype = ast_variable_retrieve(cfg, cat, "type");
-			if(utype){
+			if(utype) {
 				var =ast_variable_browse(cfg, cat);
 				asterisk = (struct axi_master *) malloc(sizeof(struct axi_master));
 				memset(asterisk,0,sizeof(struct axi_master));
@@ -1375,8 +1325,7 @@
 				ASTOBJ_CONTAINER_LINK(&masters,asterisk);
 				ASTOBJ_UNREF(asterisk,axi_master_destroy);
 			}
-		}
-		else{
+		} else {
 			if(ast_variable_retrieve(cfg,"general","debug"))
 				debug = (ast_false(ast_variable_retrieve(cfg,"general","debug")))?0:1;
 			if(ast_variable_retrieve(cfg,"general","noautoprune"))
@@ -1418,7 +1367,7 @@
 
 	if(!axi_load_config())
 		return 0;
-	else{
+	else {
 
 		ASTOBJ_CONTAINER_TRAVERSE2(&masters,1,1, {
 		ASTOBJ_RDLOCK(iterator1);



More information about the asterisk-commits mailing list