[svn-commits] branch group/asterisk-xmpp r26018 - in /team/group/asterisk-xmpp: configs/ in...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue May 9 04:41:50 MST 2006


Author: russell
Date: Tue May  9 06:41:49 2006
New Revision: 26018

URL: http://svn.digium.com/view/asterisk?rev=26018&view=rev
Log:
begin converting some things to use flags - the autoprune and autoregister vals

Modified:
    team/group/asterisk-xmpp/configs/jabber.conf.sample
    team/group/asterisk-xmpp/include/asterisk/jabber.h
    team/group/asterisk-xmpp/res/res_jabber.c

Modified: team/group/asterisk-xmpp/configs/jabber.conf.sample
URL: http://svn.digium.com/view/asterisk/team/group/asterisk-xmpp/configs/jabber.conf.sample?rev=26018&r1=26017&r2=26018&view=diff
==============================================================================
--- team/group/asterisk-xmpp/configs/jabber.conf.sample (original)
+++ team/group/asterisk-xmpp/configs/jabber.conf.sample Tue May  9 06:41:49 2006
@@ -1,7 +1,7 @@
 [general]
 debug=yes
-;noautoprune=yes
-;noautoregister=yes
+;autoprune=yes
+;autoregister=yes
 
 ;[asterisk]
 ;type=client

Modified: team/group/asterisk-xmpp/include/asterisk/jabber.h
URL: http://svn.digium.com/view/asterisk/team/group/asterisk-xmpp/include/asterisk/jabber.h?rev=26018&r1=26017&r2=26018&view=diff
==============================================================================
--- team/group/asterisk-xmpp/include/asterisk/jabber.h (original)
+++ team/group/asterisk-xmpp/include/asterisk/jabber.h Tue May  9 06:41:49 2006
@@ -29,10 +29,9 @@
 	AJI_CONNECTED
 };
 
-enum aji_prune_register {
-	AJI_DONOTHING=0,
-	AJI_PRUNE=1,
-	AJI_REGISTER=2
+enum {
+	AJI_AUTOPRUNE = (1 << 0),
+	AJI_AUTOREGISTER = (1 << 1)
 };
 
 enum aji_btype {
@@ -64,7 +63,7 @@
 	char channel[160];
 	struct aji_resource *resources;
 	enum aji_btype btype;
-	enum aji_prune_register on_roster;
+	unsigned int flags;
 };
 
 struct aji_buddy_container {
@@ -95,10 +94,10 @@
 	int forcessl;
 	int usesasl;
 	int keepalive;
-	int pruneregister;
 	int allowguest;
 	int timeout;
 	int authorized;
+	unsigned int flags;
 	enum aji_type component;
 	struct aji_buddy_container buddies;
 	void *jingle;

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=26018&r1=26017&r2=26018&view=diff
==============================================================================
--- team/group/asterisk-xmpp/res/res_jabber.c (original)
+++ team/group/asterisk-xmpp/res/res_jabber.c Tue May  9 06:41:49 2006
@@ -73,7 +73,7 @@
 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,int pruneregister,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);
@@ -138,6 +138,9 @@
 "	      If not in roster variable will = 7\n";
 
 struct aji_client_container clients;
+
+/*! Global flags, initialized to default values */
+static struct ast_flags globalflags = { AJI_AUTOPRUNE | AJI_AUTOREGISTER };
 
 /*!
  * \brief Deletes the aji_client data structure.
@@ -1412,36 +1415,32 @@
 	if(client && removeiq && removequery && removeitem && send) {
 		ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1, {
 		ASTOBJ_RDLOCK(iterator);
-		switch(iterator->on_roster)
-		{
-			case AJI_DONOTHING:
-				break;
-			case AJI_PRUNE:
-				res =iks_send(client->p,iks_make_s10n(IKS_TYPE_UNSUBSCRIBE,iterator->name,"GoodBye your status is no longer needed by Asterisk the Open Source PBX so I am no longer subscribing to your presence.\n"));
-				res =iks_send(client->p,iks_make_s10n(IKS_TYPE_UNSUBSCRIBED,iterator->name,"GoodBye you are no longer in the asterisk config file so I am removing your access to my presence.\n"));
-	
-				iks_insert_attrib(removeiq,"from",client->jid->full);
-				iks_insert_attrib(removeiq,"type","set");
-				iks_insert_attrib(removequery,"xmlns","jabber:iq:roster");
-				iks_insert_attrib(removeitem,"jid",iterator->name);
-				iks_insert_attrib(removeitem,"subscription","remove");
-				iks_insert_node(removeiq,removequery);
-				iks_insert_node(removequery,removeitem);
-				res =iks_send(client->p, removeiq);
-				break;
-			case AJI_REGISTER:
-				if(iterator->btype==AJI_USER) { /*if it is not a transport */
-					res =iks_send(client->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 {
-					iks_filter_add_rule(client->f,aji_register_transport,client,
-							IKS_RULE_TYPE,IKS_PAK_IQ,IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,IKS_RULE_NS,
-							"http://jabber.org/protocol/disco#items",IKS_RULE_DONE);
-					iks_insert_attrib(send,"to",iterator->host);
-					iks_insert_attrib(send,"from",client->jid->full);
-					res =iks_send(client->p,send);
-				}
-				iterator->on_roster=AJI_DONOTHING;
-				break;
+		/* For an aji_buddy, both AUTOPRUNE and AUTOREGISTER will never
+		 * be enabled at the same time */
+		if (ast_test_flag(iterator, AJI_AUTOPRUNE)) {
+			res =iks_send(client->p,iks_make_s10n(IKS_TYPE_UNSUBSCRIBE,iterator->name,"GoodBye your status is no longer needed by Asterisk the Open Source PBX so I am no longer subscribing to your presence.\n"));
+			res =iks_send(client->p,iks_make_s10n(IKS_TYPE_UNSUBSCRIBED,iterator->name,"GoodBye you are no longer in the asterisk config file so I am removing your access to my presence.\n"));
+
+			iks_insert_attrib(removeiq,"from",client->jid->full);
+			iks_insert_attrib(removeiq,"type","set");
+			iks_insert_attrib(removequery,"xmlns","jabber:iq:roster");
+			iks_insert_attrib(removeitem,"jid",iterator->name);
+			iks_insert_attrib(removeitem,"subscription","remove");
+			iks_insert_node(removeiq,removequery);
+			iks_insert_node(removequery,removeitem);
+			res =iks_send(client->p, removeiq);
+		} else if (ast_test_flag(iterator, AJI_AUTOREGISTER)) {
+			if(iterator->btype==AJI_USER) { /*if it is not a transport */
+				res =iks_send(client->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 {
+				iks_filter_add_rule(client->f,aji_register_transport,client,
+						IKS_RULE_TYPE,IKS_PAK_IQ,IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,IKS_RULE_NS,
+						"http://jabber.org/protocol/disco#items",IKS_RULE_DONE);
+				iks_insert_attrib(send,"to",iterator->host);
+				iks_insert_attrib(send,"from",client->jid->full);
+				res =iks_send(client->p,send);
+			}
+			ast_clear_flag(iterator, AJI_AUTOREGISTER);
 		}
 		ASTOBJ_UNLOCK(iterator);
 		});
@@ -1479,13 +1478,13 @@
 			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=AJI_DONOTHING;
+						ast_clear_flag(iterator, AJI_AUTOPRUNE | AJI_AUTOREGISTER);
 						flag=1;
 					}
 				} else {
 					if(!strcasecmp(iterator->name,iks_find_attrib(x,"jid"))) {
 						flag=1;
-						iterator->on_roster=AJI_DONOTHING;
+						ast_clear_flag(iterator, AJI_AUTOPRUNE | AJI_AUTOREGISTER);
 					}
 				}
 
@@ -1493,9 +1492,8 @@
 			x = iks_next(x);
 		}
 		
-		if(!flag)
-			if(client->pruneregister>=2)
-				iterator->on_roster=AJI_REGISTER;
+		if (!flag)
+			ast_copy_flags(iterator, client, AJI_AUTOREGISTER);
 		if(x)
 			iks_delete(x);
 		
@@ -1519,7 +1517,7 @@
 			});
 			
 			if(!flag) {
-				if(client->pruneregister==1||client->pruneregister==3) {
+				if (ast_test_flag(client, AJI_AUTOPRUNE)) {
 					buddy = (struct aji_buddy *)malloc(sizeof(struct aji_buddy));
 					if(!buddy)
 						ast_log(LOG_WARNING, "Out of memory\n");
@@ -1528,7 +1526,8 @@
 					ASTOBJ_WRLOCK(buddy);
 					ast_copy_string(buddy->name, iks_find_attrib(x,"jid"), sizeof(buddy->name));
 					ast_copy_string(buddy->user, iks_find_attrib(x,"jid"),sizeof(buddy->user));
-					buddy->on_roster=AJI_PRUNE;
+					ast_clear_flag(buddy, AST_FLAGS_ALL);
+					ast_set_flag(buddy, AJI_AUTOPRUNE);
 					buddy->objflags |= ASTOBJ_FLAG_MARKED;
 					ASTOBJ_UNLOCK(buddy);
 					if(buddy) {
@@ -1808,7 +1807,7 @@
  * \param label, ast_variable, debug, pruneregister, component/client, aji_client to dump into. 
  * \return 0.
  */
-static int aji_create_client(char *label,struct ast_variable *var, int debug, int pruneregister,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)
 {
 	char *resource;
 	struct aji_buddy *buddy = NULL;
@@ -1819,7 +1818,7 @@
 	ast_copy_string(client->mid, "aaaaa",sizeof(client->mid));
 
 	client->debug = debug;
-	client->pruneregister = pruneregister;
+	ast_copy_flags(client, &globalflags, AST_FLAGS_ALL);
 	client->port=5222;
 	client->usetls=1;
 	client->forcessl=0;
@@ -1855,10 +1854,10 @@
 			client->forcessl=(ast_false(var->value))?0:1;
 		else if(!strcasecmp(var->name,"keepalive"))
 			client->keepalive=(ast_false(var->value))?0:1;
-		else if(!strcasecmp(var->name,"noautoprune"))
-			client->pruneregister = (ast_false(var->value))?client->pruneregister++:client->pruneregister--;
-		else if(!strcasecmp(var->name,"noautoregister"))
-			client->pruneregister = (ast_false(var->value))?client->pruneregister+2:client->pruneregister-2;
+		else if(!strcasecmp(var->name,"autoprune"))
+			ast_set2_flag(client, ast_true(var->value), AJI_AUTOPRUNE);
+		else if(!strcasecmp(var->name,"autoregister"))
+			ast_set2_flag(client, ast_true(var->value), AJI_AUTOREGISTER);
 		else if(!strcasecmp(var->name,"buddy")||!strcasecmp(var->name,"transport")) {
 			buddy= malloc(sizeof(struct aji_buddy));
 			memset(buddy,0,sizeof(struct aji_buddy));
@@ -1977,7 +1976,7 @@
 {
 	char *cat=NULL;
 	char *utype=NULL;
-	int debug=1, pruneregister=3;
+	int debug = 1;
 	struct ast_config *cfg=NULL;
 	struct ast_variable *var = NULL;
 	struct aji_client *client = NULL;
@@ -1993,10 +1992,10 @@
 	for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
 		if(!strcasecmp(var->name, "debug"))
 			debug = (ast_false(ast_variable_retrieve(cfg,"general","debug")))?0:1;
-		else if(!strcasecmp(var->name, "noautoprune"))
-			pruneregister = (ast_false(ast_variable_retrieve(cfg,"general","noautoprune")))?pruneregister:pruneregister-1;
-		else if(!strcasecmp(var->name, "noautoregister"))
-			pruneregister = (ast_false(ast_variable_retrieve(cfg,"general","noautoregister")))?pruneregister:pruneregister-2;
+		else if(!strcasecmp(var->name, "autoprune"))
+			ast_set2_flag(&globalflags, ast_true(var->value), AJI_AUTOPRUNE);
+		else if(!strcasecmp(var->name, "autoregister"))
+			ast_set2_flag(&globalflags, ast_true(var->value), AJI_AUTOREGISTER);
 	}
 
 	while(cat) {
@@ -2008,7 +2007,7 @@
 				memset(client,0,sizeof(struct aji_client));
 				ASTOBJ_INIT(client);
 				ASTOBJ_WRLOCK(client);
-				aji_create_client(cat, var, debug, pruneregister, utype, client);
+				aji_create_client(cat, var, debug, utype, client);
 				ASTOBJ_UNLOCK(client);
 				ASTOBJ_CONTAINER_LINK(&clients,client);
 				ASTOBJ_UNREF(client,aji_client_destroy);



More information about the svn-commits mailing list