瀏覽代碼

presence_xml: clang format the code

Daniel-Constantin Mierla 6 年之前
父節點
當前提交
4197b52f31

+ 65 - 73
src/modules/presence_xml/add_events.c

@@ -43,93 +43,89 @@ extern int disable_winfo;
 extern int disable_bla;
 extern int disable_xcapdiff;
 
-static str pu_415_rpl  = str_init("Unsupported media type");
+static str pu_415_rpl = str_init("Unsupported media type");
 
 int xml_add_events(void)
 {
 	pres_ev_t event;
-	
-	if (!disable_presence) {
+
+	if(!disable_presence) {
 		/* constructing presence event */
 		memset(&event, 0, sizeof(pres_ev_t));
-		event.name.s= "presence";
-		event.name.len= 8;
-
-		event.content_type.s= "application/pidf+xml";
-		event.content_type.len= 20;
-
-		event.type= PUBL_TYPE;
-		event.req_auth= 1;
-		event.apply_auth_nbody= pres_apply_auth;
-		event.get_auth_status= pres_watcher_allowed;
-		event.agg_nbody= pres_agg_nbody;
-		event.evs_publ_handl= xml_publ_handl;
-		event.free_body= free_xml_body;
-		event.default_expires= 3600;
-		event.get_rules_doc= pres_get_rules_doc;
-		event.get_pidf_doc= pres_get_pidf_doc;
-		if(pres_add_event(&event)< 0)
-		{
+		event.name.s = "presence";
+		event.name.len = 8;
+
+		event.content_type.s = "application/pidf+xml";
+		event.content_type.len = 20;
+
+		event.type = PUBL_TYPE;
+		event.req_auth = 1;
+		event.apply_auth_nbody = pres_apply_auth;
+		event.get_auth_status = pres_watcher_allowed;
+		event.agg_nbody = pres_agg_nbody;
+		event.evs_publ_handl = xml_publ_handl;
+		event.free_body = free_xml_body;
+		event.default_expires = 3600;
+		event.get_rules_doc = pres_get_rules_doc;
+		event.get_pidf_doc = pres_get_pidf_doc;
+		if(pres_add_event(&event) < 0) {
 			LM_ERR("while adding event presence\n");
 			return -1;
-		}		
+		}
 		LM_DBG("added 'presence' event to presence module\n");
 	}
 
-	if (!disable_winfo) {
+	if(!disable_winfo) {
 		/* constructing presence.winfo event */
 		memset(&event, 0, sizeof(pres_ev_t));
-		event.name.s= "presence.winfo";
-		event.name.len= 14;
+		event.name.s = "presence.winfo";
+		event.name.len = 14;
 
-		event.content_type.s= "application/watcherinfo+xml";
-		event.content_type.len= 27;
-		event.type= WINFO_TYPE;
-		event.free_body= free_xml_body;
-		event.default_expires= 3600;
+		event.content_type.s = "application/watcherinfo+xml";
+		event.content_type.len = 27;
+		event.type = WINFO_TYPE;
+		event.free_body = free_xml_body;
+		event.default_expires = 3600;
 
-		if(pres_add_event(&event)< 0)
-		{
+		if(pres_add_event(&event) < 0) {
 			LM_ERR("while adding event presence.winfo\n");
 			return -1;
 		}
 		LM_DBG("added 'presence.winfo' event to presence module\n");
 	}
-	
-	if (!disable_bla) {
+
+	if(!disable_bla) {
 		/* constructing bla event */
 		memset(&event, 0, sizeof(pres_ev_t));
-		event.name.s= "dialog;sla";
-		event.name.len= 10;
-
-		event.etag_not_new= 1;
-		event.evs_publ_handl= xml_publ_handl;
-		event.content_type.s= "application/dialog-info+xml";
-		event.content_type.len= 27;
-		event.type= PUBL_TYPE;
-		event.free_body= free_xml_body;
-		event.default_expires= 3600;
-		if(pres_add_event(&event)< 0)
-		{
+		event.name.s = "dialog;sla";
+		event.name.len = 10;
+
+		event.etag_not_new = 1;
+		event.evs_publ_handl = xml_publ_handl;
+		event.content_type.s = "application/dialog-info+xml";
+		event.content_type.len = 27;
+		event.type = PUBL_TYPE;
+		event.free_body = free_xml_body;
+		event.default_expires = 3600;
+		if(pres_add_event(&event) < 0) {
 			LM_ERR("while adding event dialog;sla\n");
 			return -1;
 		}
 		LM_DBG("added 'dialog;sla' event to presence module\n");
 	}
-	
-	if (!disable_xcapdiff) {
+
+	if(!disable_xcapdiff) {
 		/* constructing xcap-diff event */
 		memset(&event, 0, sizeof(pres_ev_t));
-		event.name.s= "xcap-diff";
-		event.name.len= 9;
+		event.name.s = "xcap-diff";
+		event.name.len = 9;
 
-		event.content_type.s= "application/xcap-diff+xml";
-		event.content_type.len= 25;
+		event.content_type.s = "application/xcap-diff+xml";
+		event.content_type.len = 25;
 
-		event.type= PUBL_TYPE;
-		event.default_expires= 3600;
-		if(pres_add_event(&event)< 0)
-		{
+		event.type = PUBL_TYPE;
+		event.default_expires = 3600;
+		if(pres_add_event(&event) < 0) {
 			LM_ERR("while adding event xcap-diff\n");
 			return -1;
 		}
@@ -141,29 +137,26 @@ int xml_add_events(void)
 /*
  * in event specific publish handling - only check is good body format
  */
-int	xml_publ_handl(struct sip_msg* msg)
-{	
-	str body= {0, 0};
-	xmlDocPtr doc= NULL;
+int xml_publ_handl(struct sip_msg *msg)
+{
+	str body = {0, 0};
+	xmlDocPtr doc = NULL;
 
-	if ( get_content_length(msg) == 0 )
+	if(get_content_length(msg) == 0)
 		return 1;
-	
-	body.s=get_body(msg);
-	if (body.s== NULL) 
-	{
+
+	body.s = get_body(msg);
+	if(body.s == NULL) {
 		LM_ERR("cannot extract body from msg\n");
 		goto error;
 	}
 	/* content-length (if present) must be already parsed */
 
-	body.len = get_content_length( msg );
-	doc= xmlParseMemory( body.s, body.len );
-	if(doc== NULL)
-	{
+	body.len = get_content_length(msg);
+	doc = xmlParseMemory(body.s, body.len);
+	if(doc == NULL) {
 		LM_ERR("bad body format\n");
-		if(slb.freply(msg, 415, &pu_415_rpl) < 0)
-		{
+		if(slb.freply(msg, 415, &pu_415_rpl) < 0) {
 			LM_ERR("while sending '415 Unsupported media type' reply\n");
 		}
 		goto error;
@@ -178,5 +171,4 @@ error:
 	xmlCleanupParser();
 	xmlMemoryDump();
 	return -1;
-
-}	
+}

+ 1 - 1
src/modules/presence_xml/add_events.h

@@ -30,6 +30,6 @@
 #define _XML_ADD_EV_H_
 
 int xml_add_events(void);
-int	xml_publ_handl(struct sip_msg* msg);
+int xml_publ_handl(struct sip_msg *msg);
 
 #endif

+ 10 - 7
src/modules/presence_xml/api.h

@@ -25,23 +25,26 @@
 #define PXML_API_H
 #include "../../core/str.h"
 
-typedef int (*pres_check_basic_t)(struct sip_msg*, str presentity_uri, str status);
-typedef int (*pres_check_activities_t)(struct sip_msg*, str presentity_uri, str activity);
+typedef int (*pres_check_basic_t)(
+		struct sip_msg *, str presentity_uri, str status);
+typedef int (*pres_check_activities_t)(
+		struct sip_msg *, str presentity_uri, str activity);
 
-typedef struct presence_xml_binds {
+typedef struct presence_xml_binds
+{
 	pres_check_basic_t pres_check_basic;
 	pres_check_activities_t pres_check_activities;
 } presence_xml_api_t;
 
-typedef int (*bind_presence_xml_f)(presence_xml_api_t*);
+typedef int (*bind_presence_xml_f)(presence_xml_api_t *);
 
-int bind_presence_xml(struct presence_xml_binds*);
+int bind_presence_xml(struct presence_xml_binds *);
 
 inline static int presence_xml_load_api(presence_xml_api_t *pxb)
 {
 	bind_presence_xml_f bind_presence_xml_exports;
-	if (!(bind_presence_xml_exports = (bind_presence_xml_f)find_export("bind_presence_xml", 1, 0)))
-	{
+	if(!(bind_presence_xml_exports = (bind_presence_xml_f)find_export(
+				 "bind_presence_xml", 1, 0))) {
 		LM_ERR("Failed to import bind_presence_xml\n");
 		return -1;
 	}

+ 264 - 315
src/modules/presence_xml/notify_body.c

@@ -40,22 +40,24 @@
 
 extern int force_dummy_presence;
 
-str* offline_nbody(str* body);
-str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n);
-str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node);
+str *offline_nbody(str *body);
+str *agregate_xmls(str *pres_user, str *pres_domain, str **body_array, int n);
+str *get_final_notify_body(
+		subs_t *subs, str *notify_body, xmlNodePtr rule_node);
 
-void free_xml_body(char* body)
+void free_xml_body(char *body)
 {
-	if(body== NULL)
+	if(body == NULL)
 		return;
 
 	xmlFree(body);
-	body= NULL;
+	body = NULL;
 }
 
 #define PRESENCE_EMPTY_BODY_SIZE 1024
 
-#define PRESENCE_EMPTY_BODY  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
+#define PRESENCE_EMPTY_BODY \
+	"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
 <presence xmlns=\"urn:ietf:params:xml:ns:pidf\" xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" xmlns:c=\"urn:ietf:params:xml:ns:pidf:cipid\" entity=\"%.*s\"> \
 <tuple xmlns=\"urn:ietf:params:xml:ns:pidf\" id=\"615293b33c62dec073e05d9421e9f48b\">\
 <status>\
@@ -69,46 +71,48 @@ void free_xml_body(char* body)
 </dm:person>\
 </presence>"
 
-str* pres_agg_nbody_empty(str* pres_user, str* pres_domain)
+str *pres_agg_nbody_empty(str *pres_user, str *pres_domain)
 {
-	str* n_body= NULL;
+	str *n_body = NULL;
 
-	str* body_array;
-	char* body;
+	str *body_array;
+	char *body;
 
 	LM_DBG("creating empty presence for [pres_user]=%.*s [pres_domain]= %.*s\n",
 			pres_user->len, pres_user->s, pres_domain->len, pres_domain->s);
 
-	if(pres_user->len+sizeof(PRESENCE_EMPTY_BODY)
+	if(pres_user->len + sizeof(PRESENCE_EMPTY_BODY)
 			>= PRESENCE_EMPTY_BODY_SIZE - 1) {
 		LM_ERR("insufficient buffer to add user (its len is: %d)\n",
 				pres_user->len);
 		return NULL;
 	}
-	body_array = (str*)pkg_malloc(sizeof(str));
-	if(body_array==NULL) {
+	body_array = (str *)pkg_malloc(sizeof(str));
+	if(body_array == NULL) {
 		LM_ERR("no more pkg\n");
 		return NULL;
 	}
 
-	body = (char*)pkg_malloc(PRESENCE_EMPTY_BODY_SIZE);
-	if(body_array==NULL) {
+	body = (char *)pkg_malloc(PRESENCE_EMPTY_BODY_SIZE);
+	if(body_array == NULL) {
 		LM_ERR("no more pkg\n");
 		pkg_free(body_array);
 		return NULL;
 	}
-	snprintf(body, PRESENCE_EMPTY_BODY_SIZE, PRESENCE_EMPTY_BODY, pres_user->len, pres_user->s);
+	snprintf(body, PRESENCE_EMPTY_BODY_SIZE, PRESENCE_EMPTY_BODY,
+			pres_user->len, pres_user->s);
 	body_array->s = body;
 	body_array->len = strlen(body);
 
 
-	n_body= agregate_xmls(pres_user, pres_domain, &body_array, 1);
+	n_body = agregate_xmls(pres_user, pres_domain, &body_array, 1);
 	LM_DBG("[n_body]=%p\n", n_body);
 	if(n_body) {
 		LM_DBG("[*n_body]=%.*s\n", n_body->len, n_body->s);
 	}
-	if(n_body== NULL) {
-		LM_ERR("while aggregating body for: %.*s\n", pres_user->len, pres_user->s);
+	if(n_body == NULL) {
+		LM_ERR("while aggregating body for: %.*s\n", pres_user->len,
+				pres_user->s);
 	}
 
 	pkg_free(body);
@@ -121,82 +125,75 @@ str* pres_agg_nbody_empty(str* pres_user, str* pres_domain)
 	return n_body;
 }
 
-str* pres_agg_nbody(str* pres_user, str* pres_domain, str** body_array, int n, int off_index)
+str *pres_agg_nbody(str *pres_user, str *pres_domain, str **body_array, int n,
+		int off_index)
 {
-	str* n_body= NULL;
-	str* body= NULL;
+	str *n_body = NULL;
+	str *body = NULL;
 
-	if(body_array== NULL && (!force_dummy_presence))
+	if(body_array == NULL && (!force_dummy_presence))
 		return NULL;
 
-	if(body_array== NULL)
+	if(body_array == NULL)
 		return pres_agg_nbody_empty(pres_user, pres_domain);
 
-	if(off_index>= 0)
-	{
-		body= body_array[off_index];
-		body_array[off_index]= offline_nbody(body);
+	if(off_index >= 0) {
+		body = body_array[off_index];
+		body_array[off_index] = offline_nbody(body);
 
-		if(body_array[off_index]== NULL || body_array[off_index]->s== NULL)
-		{
+		if(body_array[off_index] == NULL || body_array[off_index]->s == NULL) {
 			LM_ERR("while constructing offline body\n");
 			return NULL;
 		}
 	}
-	LM_DBG("[user]=%.*s  [domain]= %.*s\n",
-			pres_user->len, pres_user->s, pres_domain->len, pres_domain->s);
-	n_body= agregate_xmls(pres_user, pres_domain, body_array, n);
-	if(n_body== NULL && n!= 0)
-	{
+	LM_DBG("[user]=%.*s  [domain]= %.*s\n", pres_user->len, pres_user->s,
+			pres_domain->len, pres_domain->s);
+	n_body = agregate_xmls(pres_user, pres_domain, body_array, n);
+	if(n_body == NULL && n != 0) {
 		LM_ERR("while aggregating body\n");
 	}
 
-	if(off_index>= 0)
-	{
+	if(off_index >= 0) {
 		xmlFree(body_array[off_index]->s);
 		pkg_free(body_array[off_index]);
-		body_array[off_index]= body;
+		body_array[off_index] = body;
 	}
 
 	xmlCleanupParser();
-    xmlMemoryDump();
+	xmlMemoryDump();
 
 	return n_body;
-}	
+}
 
-int pres_apply_auth(str* notify_body, subs_t* subs, str** final_nbody)
+int pres_apply_auth(str *notify_body, subs_t *subs, str **final_nbody)
 {
-	xmlDocPtr doc= NULL;
-	xmlNodePtr node= NULL;
-	str* n_body= NULL;
-	
-	*final_nbody= NULL;
+	xmlDocPtr doc = NULL;
+	xmlNodePtr node = NULL;
+	str *n_body = NULL;
+
+	*final_nbody = NULL;
 	if(force_active)
 		return 0;
 
-	if(subs->auth_rules_doc== NULL)
-	{
+	if(subs->auth_rules_doc == NULL) {
 		LM_ERR("NULL rules doc\n");
 		return -1;
 	}
-	doc= xmlParseMemory(subs->auth_rules_doc->s, subs->auth_rules_doc->len);
-	if(doc== NULL)
-	{
+	doc = xmlParseMemory(subs->auth_rules_doc->s, subs->auth_rules_doc->len);
+	if(doc == NULL) {
 		LM_ERR("parsing xml doc\n");
 		return -1;
 	}
-	
-	node= get_rule_node(subs, doc);
-	if(node== NULL)
-	{
+
+	node = get_rule_node(subs, doc);
+	if(node == NULL) {
 		LM_DBG("The subscriber didn't match the conditions\n");
 		xmlFreeDoc(doc);
 		return 0;
 	}
-	
-	n_body= get_final_notify_body(subs, notify_body, node);
-	if(n_body== NULL)
-	{
+
+	n_body = get_final_notify_body(subs, notify_body, node);
+	if(n_body == NULL) {
 		LM_ERR("in function get_final_notify_body\n");
 		xmlFreeDoc(doc);
 		return -1;
@@ -204,112 +201,103 @@ int pres_apply_auth(str* notify_body, subs_t* subs, str** final_nbody)
 
 	xmlFreeDoc(doc);
 	xmlCleanupParser();
-    xmlMemoryDump();
+	xmlMemoryDump();
 
-	*final_nbody= n_body;
+	*final_nbody = n_body;
 	return 1;
+}
 
-}	
-
-str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node)
+str *get_final_notify_body(subs_t *subs, str *notify_body, xmlNodePtr rule_node)
 {
 	xmlNodePtr transf_node = NULL, node = NULL, dont_provide = NULL;
 	xmlNodePtr doc_root = NULL, doc_node = NULL, provide_node = NULL;
 	xmlNodePtr all_node = NULL;
-	xmlDocPtr doc= NULL;
-#define KSR_FNB_NAME_SIZE	24
+	xmlDocPtr doc = NULL;
+#define KSR_FNB_NAME_SIZE 24
 	char name[KSR_FNB_NAME_SIZE];
 	int name_len;
 	char service_uri_scheme[16];
-	int i= 0, found = 0;
-	str* new_body = NULL;
-    char* class_cont = NULL, *occurence_ID= NULL, *service_uri= NULL;
-	char* deviceID = NULL;
-	char* content = NULL;
-	char all_name[KSR_FNB_NAME_SIZE+8];
+	int i = 0, found = 0;
+	str *new_body = NULL;
+	char *class_cont = NULL, *occurence_ID = NULL, *service_uri = NULL;
+	char *deviceID = NULL;
+	char *content = NULL;
+	char all_name[KSR_FNB_NAME_SIZE + 8];
 
 	doc = xmlParseMemory(notify_body->s, notify_body->len);
-	if(doc== NULL) 
-	{
+	if(doc == NULL) {
 		LM_ERR("while parsing the xml body message\n");
 		goto error;
 	}
-	doc_root = xmlDocGetNodeByName(doc,"presence", NULL);
-	if(doc_root == NULL)
-	{
+	doc_root = xmlDocGetNodeByName(doc, "presence", NULL);
+	if(doc_root == NULL) {
 		LM_ERR("while extracting the presence node\n");
 		goto error;
 	}
 
 	strcpy(all_name, "all-");
 
-	new_body = (str*)pkg_malloc(sizeof(str));
-	if(new_body == NULL)
-	{
+	new_body = (str *)pkg_malloc(sizeof(str));
+	if(new_body == NULL) {
 		LM_ERR("while allocating memory\n");
 		return NULL;
 	}
 	memset(new_body, 0, sizeof(str));
 
 	transf_node = xmlNodeGetChildByName(rule_node, "transformations");
-	if(transf_node == NULL)
-	{
+	if(transf_node == NULL) {
 		LM_DBG("transformations node not found\n");
 		goto done;
 	}
-	
-	for(node = transf_node->children; node; node = node->next )
-	{
-		if(xmlStrcasecmp(node->name, (unsigned char*)"text")== 0)
+
+	for(node = transf_node->children; node; node = node->next) {
+		if(xmlStrcasecmp(node->name, (unsigned char *)"text") == 0)
 			continue;
 
 		/* handle 'provide-xyz' nodes */
-		name_len = strlen((char*)(node->name));
-		if(name_len<9) {
+		name_len = strlen((char *)(node->name));
+		if(name_len < 9) {
 			continue;
 		}
 		LM_DBG("transf_node->name:%s\n", node->name);
 
 		/* skip 'provide-' (e.g., provide-services) */
-		if(name_len-8>KSR_FNB_NAME_SIZE-1) {
-			LM_INFO("unsupported handling of: %s\n", (char*)node->name);
+		if(name_len - 8 > KSR_FNB_NAME_SIZE - 1) {
+			LM_INFO("unsupported handling of: %s\n", (char *)node->name);
 			continue;
 		}
-		strcpy((char*)name, (char*)(node->name + 8));
-		strcpy(all_name+4, name);
-		
-		if(xmlStrcasecmp((unsigned char*)name,(unsigned char*)"services") == 0)
+		strcpy((char *)name, (char *)(node->name + 8));
+		strcpy(all_name + 4, name);
+
+		if(xmlStrcasecmp((unsigned char *)name, (unsigned char *)"services")
+				== 0)
 			strcpy(name, "tuple");
-		if(strncmp((char*)name,"person", 6) == 0)
+		if(strncmp((char *)name, "person", 6) == 0)
 			name[6] = '\0';
 
 		doc_node = xmlNodeGetNodeByName(doc_root, name, NULL);
 		if(doc_node == NULL)
 			continue;
-		LM_DBG("searched doc_node->name:%s\n",name);
-	
-		content = (char*)xmlNodeGetContent(node);
-		if(content)
-		{
+		LM_DBG("searched doc_node->name:%s\n", name);
+
+		content = (char *)xmlNodeGetContent(node);
+		if(content) {
 			LM_DBG("content = %s\n", content);
-		
-			if(xmlStrcasecmp((unsigned char*)content,
-					(unsigned char*) "FALSE") == 0)
-			{
+
+			if(xmlStrcasecmp((unsigned char *)content, (unsigned char *)"FALSE")
+					== 0) {
 				LM_DBG("found content false\n");
-				while( doc_node )
-				{
-					xmlUnlinkNode(doc_node);	
+				while(doc_node) {
+					xmlUnlinkNode(doc_node);
 					xmlFreeNode(doc_node);
 					doc_node = xmlNodeGetChildByName(doc_root, name);
 				}
 				xmlFree(content);
 				continue;
 			}
-		
-			if(xmlStrcasecmp((unsigned char*)content,
-					(unsigned char*) "TRUE") == 0)
-			{
+
+			if(xmlStrcasecmp((unsigned char *)content, (unsigned char *)"TRUE")
+					== 0) {
 				LM_DBG("found content true\n");
 				xmlFree(content);
 				continue;
@@ -317,30 +305,25 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
 			xmlFree(content);
 		}
 
-		while (doc_node )
-		{
-			if (xmlStrcasecmp(doc_node->name,(unsigned char*)"text")==0)
-			{
+		while(doc_node) {
+			if(xmlStrcasecmp(doc_node->name, (unsigned char *)"text") == 0) {
 				doc_node = doc_node->next;
 				continue;
 			}
 
-			if (xmlStrcasecmp(doc_node->name,(unsigned char*)name)!=0)
-			{
+			if(xmlStrcasecmp(doc_node->name, (unsigned char *)name) != 0) {
 				break;
 			}
-			all_node = xmlNodeGetChildByName(node, all_name) ;
-		
-			if( all_node )
-			{
+			all_node = xmlNodeGetChildByName(node, all_name);
+
+			if(all_node) {
 				LM_DBG("must provide all\n");
 				doc_node = doc_node->next;
 				continue;
 			}
 
 			found = 0;
-			class_cont = xmlNodeGetNodeContentByName(doc_node, "class", 
-					NULL);
+			class_cont = xmlNodeGetNodeContentByName(doc_node, "class", NULL);
 			if(class_cont == NULL)
 				LM_DBG("no class tag found\n");
 			else
@@ -353,25 +336,22 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
 				LM_DBG("found id = %s\n", occurence_ID);
 
 
-			deviceID = xmlNodeGetNodeContentByName(doc_node, "deviceID",
-					NULL);	
-			if(deviceID== NULL)
+			deviceID = xmlNodeGetNodeContentByName(doc_node, "deviceID", NULL);
+			if(deviceID == NULL)
 				LM_DBG("no deviceID found\n");
 			else
-				LM_DBG("found deviceID = %s\n",	deviceID);
+				LM_DBG("found deviceID = %s\n", deviceID);
 
 
-			service_uri = xmlNodeGetNodeContentByName(doc_node, "contact",
-					NULL);	
+			service_uri =
+					xmlNodeGetNodeContentByName(doc_node, "contact", NULL);
 			if(service_uri == NULL)
 				LM_DBG("no service_uri found\n");
 			else
 				LM_DBG("found service_uri = %s\n", service_uri);
 			i = 0;
-			if(service_uri!= NULL)
-			{
-				while(service_uri[i]!= ':')
-				{
+			if(service_uri != NULL) {
+				while(service_uri[i] != ':') {
 					service_uri_scheme[i] = service_uri[i];
 					i++;
 				}
@@ -380,23 +360,23 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
 			}
 
 			provide_node = node->children;
-				
-			while ( provide_node!= NULL )
-			{
-				if(xmlStrcasecmp(provide_node->name,(unsigned char*) "text")==0)
-				{
-					provide_node = 	provide_node->next;
+
+			while(provide_node != NULL) {
+				if(xmlStrcasecmp(provide_node->name, (unsigned char *)"text")
+						== 0) {
+					provide_node = provide_node->next;
 					continue;
 				}
 
-				if(xmlStrcasecmp(provide_node->name,(unsigned char*)"class")== 0
-						&& class_cont )
-				{
-					content = (char*)xmlNodeGetContent(provide_node);
+				if(xmlStrcasecmp(provide_node->name, (unsigned char *)"class")
+								== 0
+						&& class_cont) {
+					content = (char *)xmlNodeGetContent(provide_node);
 
-					if(content&& xmlStrcasecmp((unsigned char*)content,
-								(unsigned char*)class_cont) == 0)
-					{
+					if(content
+							&& xmlStrcasecmp((unsigned char *)content,
+									   (unsigned char *)class_cont)
+									   == 0) {
 						found = 1;
 						LM_DBG("found class= %s", class_cont);
 						xmlFree(content);
@@ -405,14 +385,16 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
 					if(content)
 						xmlFree(content);
 				}
-				if(xmlStrcasecmp(provide_node->name,
-							(unsigned char*) "deviceID")==0&&deviceID )
-				{
-					content = (char*)xmlNodeGetContent(provide_node);
-
-					if(content && xmlStrcasecmp ((unsigned char*)content,
-								(unsigned char*)deviceID) == 0)
-					{
+				if(xmlStrcasecmp(
+						   provide_node->name, (unsigned char *)"deviceID")
+								== 0
+						&& deviceID) {
+					content = (char *)xmlNodeGetContent(provide_node);
+
+					if(content
+							&& xmlStrcasecmp((unsigned char *)content,
+									   (unsigned char *)deviceID)
+									   == 0) {
 						found = 1;
 						LM_DBG("found deviceID= %s", deviceID);
 						xmlFree(content);
@@ -420,15 +402,16 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
 					}
 					if(content)
 						xmlFree(content);
-
 				}
-				if(xmlStrcasecmp(provide_node->name,
-							(unsigned char*)"occurence-id")== 0&& occurence_ID)
-				{
-					content = (char*)xmlNodeGetContent(provide_node);
-					if(content && xmlStrcasecmp ((unsigned char*)content,
-								(unsigned char*)occurence_ID) == 0)
-					{
+				if(xmlStrcasecmp(
+						   provide_node->name, (unsigned char *)"occurence-id")
+								== 0
+						&& occurence_ID) {
+					content = (char *)xmlNodeGetContent(provide_node);
+					if(content
+							&& xmlStrcasecmp((unsigned char *)content,
+									   (unsigned char *)occurence_ID)
+									   == 0) {
 						found = 1;
 						LM_DBG("found occurenceID= %s\n", occurence_ID);
 						xmlFree(content);
@@ -436,15 +419,16 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
 					}
 					if(content)
 						xmlFree(content);
-
 				}
-				if(xmlStrcasecmp(provide_node->name,
-							(unsigned char*)"service-uri")== 0 && service_uri)
-				{
-					content = (char*)xmlNodeGetContent(provide_node);
-					if(content&& xmlStrcasecmp ((unsigned char*)content,
-								(unsigned char*)service_uri) == 0)
-					{
+				if(xmlStrcasecmp(
+						   provide_node->name, (unsigned char *)"service-uri")
+								== 0
+						&& service_uri) {
+					content = (char *)xmlNodeGetContent(provide_node);
+					if(content
+							&& xmlStrcasecmp((unsigned char *)content,
+									   (unsigned char *)service_uri)
+									   == 0) {
 						found = 1;
 						LM_DBG("found service_uri= %s", service_uri);
 						xmlFree(content);
@@ -452,49 +436,46 @@ str* get_final_notify_body( subs_t *subs, str* notify_body, xmlNodePtr rule_node
 					}
 					if(content)
 						xmlFree(content);
-
 				}
-			
+
 				if(xmlStrcasecmp(provide_node->name,
-						(unsigned char*)"service-uri-scheme")==0&& i)
-				{
-					content = (char*)xmlNodeGetContent(provide_node);
-					LM_DBG("service_uri_scheme=%s\n",content);
-					if(content && xmlStrcasecmp((unsigned char*)content,
-								(unsigned char*)service_uri_scheme) == 0)
-					{
+						   (unsigned char *)"service-uri-scheme")
+								== 0
+						&& i) {
+					content = (char *)xmlNodeGetContent(provide_node);
+					LM_DBG("service_uri_scheme=%s\n", content);
+					if(content
+							&& xmlStrcasecmp((unsigned char *)content,
+									   (unsigned char *)service_uri_scheme)
+									   == 0) {
 						found = 1;
-						LM_DBG("found service_uri_scheme= %s", service_uri_scheme);
+						LM_DBG("found service_uri_scheme= %s",
+								service_uri_scheme);
 						xmlFree(content);
 						break;
-					}	
+					}
 					if(content)
 						xmlFree(content);
-
 				}
 
 				provide_node = provide_node->next;
 			}
-			
-			if(found == 0)
-			{
+
+			if(found == 0) {
 				LM_DBG("delete node: %s\n", doc_node->name);
 				dont_provide = doc_node;
 				doc_node = doc_node->next;
-				xmlUnlinkNode(dont_provide);	
+				xmlUnlinkNode(dont_provide);
 				xmlFreeNode(dont_provide);
-			}	
-			else
+			} else
 				doc_node = doc_node->next;
-	
 		}
 	}
 
 done:
-	xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&new_body->s,
-			&new_body->len, 1);
-	LM_DBG("body = \n%.*s\n", new_body->len,
-			new_body->s);
+	xmlDocDumpFormatMemory(
+			doc, (xmlChar **)(void *)&new_body->s, &new_body->len, 1);
+	LM_DBG("body = \n%.*s\n", new_body->len, new_body->s);
 
 	xmlFreeDoc(doc);
 
@@ -508,49 +489,45 @@ done:
 	return new_body;
 
 error:
-    if(doc) {
+	if(doc) {
 		xmlFreeDoc(doc);
 	}
 	return NULL;
-}	
+}
 
-str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n)
+str *agregate_xmls(str *pres_user, str *pres_domain, str **body_array, int n)
 {
-	int i, j= 0, append ;
-	xmlNodePtr p_root= NULL, new_p_root= NULL ;
-	xmlDocPtr* xml_array ;
+	int i, j = 0, append;
+	xmlNodePtr p_root = NULL, new_p_root = NULL;
+	xmlDocPtr *xml_array;
 	xmlNodePtr node = NULL;
-	xmlNodePtr add_node = NULL ;
-	str *body= NULL;
-	char* id= NULL, *tuple_id = NULL;
+	xmlNodePtr add_node = NULL;
+	str *body = NULL;
+	char *id = NULL, *tuple_id = NULL;
+
+	xml_array = (xmlDocPtr *)pkg_malloc((n + 2) * sizeof(xmlDocPtr));
+	if(xml_array == NULL) {
 
-	xml_array = (xmlDocPtr*)pkg_malloc( (n+2)*sizeof(xmlDocPtr));
-	if(xml_array== NULL)
-	{
-	
 		LM_ERR("while allocating memory");
 		return NULL;
 	}
-	memset(xml_array, 0, (n+2)*sizeof(xmlDocPtr)) ;
+	memset(xml_array, 0, (n + 2) * sizeof(xmlDocPtr));
 
-	for(i=0; i<n; i++)
-	{
-		if(body_array[i] == NULL )
+	for(i = 0; i < n; i++) {
+		if(body_array[i] == NULL)
 			continue;
 
 		xml_array[j] = NULL;
-		xml_array[j] = xmlParseMemory( body_array[i]->s, body_array[i]->len );
-		
-		if( xml_array[j]== NULL)
-		{
+		xml_array[j] = xmlParseMemory(body_array[i]->s, body_array[i]->len);
+
+		if(xml_array[j] == NULL) {
 			LM_ERR("while parsing xml body message\n");
 			goto error;
 		}
 		j++;
+	}
 
-	} 
-
-	if(j== 0)  /* no body */
+	if(j == 0) /* no body */
 	{
 		if(xml_array)
 			pkg_free(xml_array);
@@ -558,49 +535,41 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n)
 	}
 
 	j--;
-	p_root = xmlDocGetNodeByName( xml_array[j], "presence", NULL);
-	if(p_root ==NULL)
-	{
+	p_root = xmlDocGetNodeByName(xml_array[j], "presence", NULL);
+	if(p_root == NULL) {
 		LM_ERR("while getting the xml_tree root\n");
 		goto error;
 	}
 
-	for(i= j-1; i>=0; i--)
-	{
-		new_p_root= xmlDocGetNodeByName( xml_array[i], "presence", NULL);
-		if(new_p_root ==NULL)
-		{
+	for(i = j - 1; i >= 0; i--) {
+		new_p_root = xmlDocGetNodeByName(xml_array[i], "presence", NULL);
+		if(new_p_root == NULL) {
 			LM_ERR("while getting the xml_tree root\n");
 			goto error;
 		}
 
-		append= 1;
-		node= xmlNodeGetChildByName(new_p_root, "tuple");
-		if(node != NULL)
-		{
-			tuple_id= xmlNodeGetAttrContentByName(node, "id");
-			if(tuple_id== NULL)
-			{
+		append = 1;
+		node = xmlNodeGetChildByName(new_p_root, "tuple");
+		if(node != NULL) {
+			tuple_id = xmlNodeGetAttrContentByName(node, "id");
+			if(tuple_id == NULL) {
 				LM_ERR("while extracting tuple id\n");
 				goto error;
 			}
-			for (node = p_root->children; node!=NULL; node = node->next)
-			{		
-				if( xmlStrcasecmp(node->name,(unsigned char*)"text")==0)
+			for(node = p_root->children; node != NULL; node = node->next) {
+				if(xmlStrcasecmp(node->name, (unsigned char *)"text") == 0)
 					continue;
-			
-				if( xmlStrcasecmp(node->name,(unsigned char*)"tuple")==0)
-				{
+
+				if(xmlStrcasecmp(node->name, (unsigned char *)"tuple") == 0) {
 					id = xmlNodeGetAttrContentByName(node, "id");
-					if(id== NULL)
-					{
+					if(id == NULL) {
 						LM_ERR("while extracting tuple id\n");
 						goto error;
 					}
-				
-					if(xmlStrcasecmp((unsigned char*)tuple_id,
-								(unsigned char*)id )== 0)
-					{
+
+					if(xmlStrcasecmp(
+							   (unsigned char *)tuple_id, (unsigned char *)id)
+							== 0) {
 						append = 0;
 						xmlFree(id);
 						break;
@@ -609,58 +578,49 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n)
 				}
 			}
 			xmlFree(tuple_id);
-			tuple_id= NULL;
+			tuple_id = NULL;
 		}
 
-		if(append) 
-		{	
-			for(node= new_p_root->children; node; node= node->next)
-			{	
-				add_node= xmlCopyNode(node, 1);
-				if(add_node== NULL)
-				{
+		if(append) {
+			for(node = new_p_root->children; node; node = node->next) {
+				add_node = xmlCopyNode(node, 1);
+				if(add_node == NULL) {
 					LM_ERR("while copying node\n");
 					goto error;
 				}
-				if(xmlAddChild(p_root, add_node)== NULL)
-				{
+				if(xmlAddChild(p_root, add_node) == NULL) {
 					LM_ERR("while adding child\n");
 					goto error;
 				}
-								
 			}
 		}
 	}
 
-	body = (str*)pkg_malloc(sizeof(str));
-	if(body == NULL)
-	{
+	body = (str *)pkg_malloc(sizeof(str));
+	if(body == NULL) {
 		ERR_MEM(PKG_MEM_STR);
 	}
 
-	xmlDocDumpFormatMemory(xml_array[j],(xmlChar**)(void*)&body->s, 
-			&body->len, 1);	
+	xmlDocDumpFormatMemory(
+			xml_array[j], (xmlChar **)(void *)&body->s, &body->len, 1);
 
-  	for(i=0; i<=j; i++)
-	{
-		if(xml_array[i]!=NULL)
-			xmlFreeDoc( xml_array[i]);
+	for(i = 0; i <= j; i++) {
+		if(xml_array[i] != NULL)
+			xmlFreeDoc(xml_array[i]);
 	}
-	if(xml_array!=NULL)
+	if(xml_array != NULL)
 		pkg_free(xml_array);
-    
+
 	xmlCleanupParser();
-    xmlMemoryDump();
+	xmlMemoryDump();
 
 	return body;
 
 error:
-	if(xml_array!=NULL)
-	{
-		for(i=0; i<=j; i++)
-		{
-			if(xml_array[i]!=NULL)
-				xmlFreeDoc( xml_array[i]);
+	if(xml_array != NULL) {
+		for(i = 0; i <= j; i++) {
+			if(xml_array[i] != NULL)
+				xmlFreeDoc(xml_array[i]);
 		}
 		pkg_free(xml_array);
 	}
@@ -672,84 +632,75 @@ error:
 	return NULL;
 }
 
-str* offline_nbody(str* body)
+str *offline_nbody(str *body)
 {
-	xmlDocPtr doc= NULL;
-	xmlDocPtr new_doc= NULL;
-	xmlNodePtr node, tuple_node= NULL, status_node;
+	xmlDocPtr doc = NULL;
+	xmlDocPtr new_doc = NULL;
+	xmlNodePtr node, tuple_node = NULL, status_node;
 	xmlNodePtr root_node, add_node, pres_node;
-	str* new_body;
+	str *new_body;
 
-	doc= xmlParseMemory(body->s, body->len);
-	if(doc==  NULL)
-	{
+	doc = xmlParseMemory(body->s, body->len);
+	if(doc == NULL) {
 		LM_ERR("while parsing xml memory\n");
 		return NULL;
 	}
-	node= xmlDocGetNodeByName(doc, "basic", NULL);
-	if(node== NULL)
-	{
+	node = xmlDocGetNodeByName(doc, "basic", NULL);
+	if(node == NULL) {
 		LM_ERR("while extracting basic node\n");
 		goto error;
 	}
-	xmlNodeSetContent(node, (const unsigned char*)"closed");
+	xmlNodeSetContent(node, (const unsigned char *)"closed");
 
-	tuple_node= xmlDocGetNodeByName(doc, "tuple", NULL);
-	if(tuple_node== NULL)
-	{
+	tuple_node = xmlDocGetNodeByName(doc, "tuple", NULL);
+	if(tuple_node == NULL) {
 		LM_ERR("while extracting tuple node\n");
 		goto error;
 	}
-	status_node= xmlDocGetNodeByName(doc, "status", NULL);
-	if(status_node== NULL)
-	{
+	status_node = xmlDocGetNodeByName(doc, "status", NULL);
+	if(status_node == NULL) {
 		LM_ERR("while extracting tuple node\n");
 		goto error;
 	}
 
-	pres_node= xmlDocGetNodeByName(doc, "presence", NULL);
-	if(node== NULL)
-	{
+	pres_node = xmlDocGetNodeByName(doc, "presence", NULL);
+	if(node == NULL) {
 		LM_ERR("while extracting presence node\n");
 		goto error;
 	}
 
-    new_doc = xmlNewDoc(BAD_CAST "1.0");
-    if(new_doc==0)
+	new_doc = xmlNewDoc(BAD_CAST "1.0");
+	if(new_doc == 0)
 		goto error;
-	root_node= xmlCopyNode(pres_node, 2);
-	if(root_node== NULL)
-	{
+	root_node = xmlCopyNode(pres_node, 2);
+	if(root_node == NULL) {
 		LM_ERR("while copying node\n");
 		goto error;
 	}
-    xmlDocSetRootElement(new_doc, root_node);
+	xmlDocSetRootElement(new_doc, root_node);
 
-	tuple_node= xmlCopyNode(tuple_node, 2);
-	if(tuple_node== NULL)
-	{
+	tuple_node = xmlCopyNode(tuple_node, 2);
+	if(tuple_node == NULL) {
 		LM_ERR("while copying node\n");
 		goto error;
 	}
 	xmlAddChild(root_node, tuple_node);
 
-	add_node= xmlCopyNode(status_node, 1);
-	if(add_node== NULL)
-	{
+	add_node = xmlCopyNode(status_node, 1);
+	if(add_node == NULL) {
 		LM_ERR("while copying node\n");
 		goto error;
 	}
 	xmlAddChild(tuple_node, add_node);
 
-	new_body = (str*)pkg_malloc(sizeof(str));
-	if(new_body == NULL)
-	{
+	new_body = (str *)pkg_malloc(sizeof(str));
+	if(new_body == NULL) {
 		ERR_MEM(PKG_MEM_STR);
 	}
 	memset(new_body, 0, sizeof(str));
 
-	xmlDocDumpFormatMemory(new_doc,(xmlChar**)(void*)&new_body->s,
-		&new_body->len, 1);
+	xmlDocDumpFormatMemory(
+			new_doc, (xmlChar **)(void *)&new_body->s, &new_body->len, 1);
 
 	xmlFreeDoc(doc);
 	xmlFreeDoc(new_doc);
@@ -764,6 +715,4 @@ error:
 	if(new_doc)
 		xmlFreeDoc(new_doc);
 	return NULL;
-
-}		
-
+}

+ 4 - 4
src/modules/presence_xml/notify_body.h

@@ -31,9 +31,9 @@
 #ifndef _NBODY_H_
 #define _NBODY_H_
 
-str* pres_agg_nbody(str* pres_user, str* pres_domain, str** body_array,
-		int n, int off_index);
-int pres_apply_auth(str* notify_body, subs_t* subs, str** final_nbody);
-void free_xml_body(char* body);
+str *pres_agg_nbody(str *pres_user, str *pres_domain, str **body_array, int n,
+		int off_index);
+int pres_apply_auth(str *notify_body, subs_t *subs, str **final_nbody);
+void free_xml_body(char *body);
 
 #endif

+ 51 - 54
src/modules/presence_xml/pidf.c

@@ -33,14 +33,15 @@
  * _XOPEN_SOURCE creates conflict in header definitions in Solaris
  */
 #ifndef __OS_solaris
-	#define _XOPEN_SOURCE 600          /* glibc2 on linux, bsd */
-	#define _BSD_SOURCE 1				/* needed on linux to "fix" the effect
+#define _XOPEN_SOURCE 600 /* glibc2 on linux, bsd */
+#define _BSD_SOURCE \
+	1					  /* needed on linux to "fix" the effect
 										  of the above define on
 										  features.h/unistd.h syscall() */
-	#define _DEFAULT_SOURCE 1         /* _BSD_SOURCE is deprecated */
-   #define _DARWIN_C_SOURCE 1
+#define _DEFAULT_SOURCE 1 /* _BSD_SOURCE is deprecated */
+#define _DARWIN_C_SOURCE 1
 #else
-	#define _XOPEN_SOURCE_EXTENDED 1   /* solaris */
+#define _XOPEN_SOURCE_EXTENDED 1 /* solaris */
 #endif
 
 #include <time.h>
@@ -57,8 +58,8 @@
 xmlAttrPtr xmlNodeGetAttrByName(xmlNodePtr node, const char *name)
 {
 	xmlAttrPtr attr = node->properties;
-	while (attr) {
-		if (xmlStrcasecmp(attr->name, (unsigned char*)name) == 0)
+	while(attr) {
+		if(xmlStrcasecmp(attr->name, (unsigned char *)name) == 0)
 			return attr;
 		attr = attr->next;
 	}
@@ -68,8 +69,8 @@ xmlAttrPtr xmlNodeGetAttrByName(xmlNodePtr node, const char *name)
 char *xmlNodeGetAttrContentByName(xmlNodePtr node, const char *name)
 {
 	xmlAttrPtr attr = xmlNodeGetAttrByName(node, name);
-	if (attr)
-		return (char*)xmlNodeGetContent(attr->children);
+	if(attr)
+		return (char *)xmlNodeGetContent(attr->children);
 	else
 		return NULL;
 }
@@ -77,39 +78,42 @@ char *xmlNodeGetAttrContentByName(xmlNodePtr node, const char *name)
 xmlNodePtr xmlNodeGetChildByName(xmlNodePtr node, const char *name)
 {
 	xmlNodePtr cur = node->children;
-	while (cur) {
-		if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0)
+	while(cur) {
+		if(xmlStrcasecmp(cur->name, (unsigned char *)name) == 0)
 			return cur;
 		cur = cur->next;
 	}
 	return NULL;
 }
 
-xmlNodePtr xmlNodeGetNodeByName(xmlNodePtr node, const char *name,
-															const char *ns)
+xmlNodePtr xmlNodeGetNodeByName(
+		xmlNodePtr node, const char *name, const char *ns)
 {
 	xmlNodePtr cur = node;
-	while (cur) {
+	while(cur) {
 		xmlNodePtr match = NULL;
-		if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0) {
-			if (!ns || (cur->ns && xmlStrcasecmp(cur->ns->prefix,
-							(unsigned char*)ns) == 0))
+		if(xmlStrcasecmp(cur->name, (unsigned char *)name) == 0) {
+			if(!ns
+					|| (cur->ns
+							   && xmlStrcasecmp(
+										  cur->ns->prefix, (unsigned char *)ns)
+										  == 0))
 				return cur;
 		}
 		match = xmlNodeGetNodeByName(cur->children, name, ns);
-		if (match)
+		if(match)
 			return match;
 		cur = cur->next;
 	}
 	return NULL;
 }
 
-char *xmlNodeGetNodeContentByName(xmlNodePtr root, const char *name,
-		const char *ns)
+char *xmlNodeGetNodeContentByName(
+		xmlNodePtr root, const char *name, const char *ns)
 {
 	xmlNodePtr node = xmlNodeGetNodeByName(root, name, ns);
-	if (node)
-		return (char*)xmlNodeGetContent(node->children);
+	if(node)
+		return (char *)xmlNodeGetContent(node->children);
 	else
 		return NULL;
 }
@@ -120,65 +124,60 @@ xmlNodePtr xmlDocGetNodeByName(xmlDocPtr doc, const char *name, const char *ns)
 	return xmlNodeGetNodeByName(cur, name, ns);
 }
 
-char *xmlDocGetNodeContentByName(xmlDocPtr doc, const char *name, 
-		const char *ns)
+char *xmlDocGetNodeContentByName(
+		xmlDocPtr doc, const char *name, const char *ns)
 {
 	xmlNodePtr node = xmlDocGetNodeByName(doc, name, ns);
-	if (node)
-		return (char*)xmlNodeGetContent(node->children);
+	if(node)
+		return (char *)xmlNodeGetContent(node->children);
 	else
 		return NULL;
 }
 
-time_t xml_parse_dateTime(char* xml_time_str)
+time_t xml_parse_dateTime(char *xml_time_str)
 {
 	struct tm tm;
-	char * p;
+	char *p;
 	int h, m;
 	char h1, h2, m1, m2;
-	int sign= 1;
-	signed int timezone_diff= 0;
+	int sign = 1;
+	signed int timezone_diff = 0;
 
-	p= strptime(xml_time_str, "%F", &tm);
-	if(p== NULL)
-	{
+	p = strptime(xml_time_str, "%F", &tm);
+	if(p == NULL) {
 		printf("error: failed to parse time\n");
 		return 0;
 	}
 	p++;
-	p= strptime(p, "%T", &tm);
-	if(p== NULL)
-	{
+	p = strptime(p, "%T", &tm);
+	if(p == NULL) {
 		printf("error: failed to parse time\n");
 		return 0;
 	}
-	
-	if(*p== '\0')
+
+	if(*p == '\0')
 		goto done;
 
-	if(*p== '.')
-	{
+	if(*p == '.') {
 		p++;
 		/* read the fractionar part of the seconds*/
-		while(*p!= '\0' && *p>= '0' && *p<= '9')
-		{
+		while(*p != '\0' && *p >= '0' && *p <= '9') {
 			p++;
 		}
 	}
 
-	if(*p== '\0')
+	if(*p == '\0')
 		goto done;
 
-	
+
 	/* read time zone */
 
-	if(*p== 'Z')
-	{
+	if(*p == 'Z') {
 		goto done;
 	}
 
-	if(*p== '+')
-		sign= -1;
+	if(*p == '+')
+		sign = -1;
 
 	p++;
 
@@ -186,13 +185,11 @@ time_t xml_parse_dateTime(char* xml_time_str)
 		printf("error: failed to parse time\n");
 		return 0;
 	}
-	h= (h1- '0')*10+ h2- '0';
-	m= (m1- '0')*10+ m2- '0';
+	h = (h1 - '0') * 10 + h2 - '0';
+	m = (m1 - '0') * 10 + m2 - '0';
 
-	timezone_diff= sign* ((m+ h* 60)* 60);
+	timezone_diff = sign * ((m + h * 60) * 60);
 
 done:
-	return (mktime(&tm) + timezone_diff);	
+	return (mktime(&tm) + timezone_diff);
 }
-
-

+ 6 - 6
src/modules/presence_xml/pidf.h

@@ -34,15 +34,15 @@
 #include "../../core/str.h"
 #include <libxml/parser.h>
 
-xmlNodePtr xmlNodeGetNodeByName(xmlNodePtr node, const char *name,
-															const char *ns);
+xmlNodePtr xmlNodeGetNodeByName(
+		xmlNodePtr node, const char *name, const char *ns);
 xmlNodePtr xmlDocGetNodeByName(xmlDocPtr doc, const char *name, const char *ns);
 xmlNodePtr xmlNodeGetChildByName(xmlNodePtr node, const char *name);
 
-char *xmlNodeGetNodeContentByName(xmlNodePtr root, const char *name,
-		const char *ns);
+char *xmlNodeGetNodeContentByName(
+		xmlNodePtr root, const char *name, const char *ns);
 char *xmlNodeGetAttrContentByName(xmlNodePtr node, const char *name);
 
-time_t xml_parse_dateTime(char* xml_time_str);
+time_t xml_parse_dateTime(char *xml_time_str);
 
-#endif 
+#endif

+ 38 - 52
src/modules/presence_xml/pres_check.c

@@ -40,56 +40,49 @@ int presxml_check_basic(struct sip_msg *msg, str presentity_uri, str status)
 	xmlNodePtr tuple = NULL, basicNode = NULL;
 	char *basicVal = NULL;
 
-	if (parse_uri(presentity_uri.s, presentity_uri.len, &parsed_uri) < 0)
-	{
+	if(parse_uri(presentity_uri.s, presentity_uri.len, &parsed_uri) < 0) {
 		LM_ERR("bad uri: %.*s\n", presentity_uri.len, presentity_uri.s);
 		return -1;
 	}
 
 	ev = pres_contains_event(&event, NULL);
-	if (ev == NULL)
-	{
+	if(ev == NULL) {
 		LM_ERR("event presence is not registered\n");
 		return -1;
 	}
 
 	presentity = pres_get_presentity(presentity_uri, ev, NULL, NULL);
 
-	if (presentity == NULL || presentity->len <= 0 || presentity->s == NULL)
-	{
-		LM_DBG("cannot get presentity for %.*s\n", presentity_uri.len, presentity_uri.s);
+	if(presentity == NULL || presentity->len <= 0 || presentity->s == NULL) {
+		LM_DBG("cannot get presentity for %.*s\n", presentity_uri.len,
+				presentity_uri.s);
 		return -1;
 	}
 
-	if ((xmlDoc = xmlParseMemory(presentity->s, presentity->len)) == NULL)
-	{
+	if((xmlDoc = xmlParseMemory(presentity->s, presentity->len)) == NULL) {
 		LM_ERR("while parsing XML memory\n");
 		goto error;
 	}
 
-	if ((tuple = xmlDocGetNodeByName(xmlDoc, "tuple", NULL)) == NULL)
-	{
+	if((tuple = xmlDocGetNodeByName(xmlDoc, "tuple", NULL)) == NULL) {
 		LM_ERR("unable to extract 'tuple'\n");
 		goto error;
 	}
 
-	while (tuple != NULL)
-	{
-		if (xmlStrcasecmp(tuple->name, (unsigned char *) "tuple") == 0)
-		{
-			if ((basicNode = xmlNodeGetNodeByName(tuple, "basic", NULL)) == NULL)
-			{
+	while(tuple != NULL) {
+		if(xmlStrcasecmp(tuple->name, (unsigned char *)"tuple") == 0) {
+			if((basicNode = xmlNodeGetNodeByName(tuple, "basic", NULL))
+					== NULL) {
 				LM_ERR("while extracting 'basic' node\n");
 				goto error;
 			}
 
-			if ((basicVal = (char *) xmlNodeGetContent(basicNode)) == NULL)
-			{
+			if((basicVal = (char *)xmlNodeGetContent(basicNode)) == NULL) {
 				LM_ERR("while getting 'basic' content\n");
 				goto error;
 			}
 
-			if (strncasecmp(basicVal, status.s, status.len) == 0)
+			if(strncasecmp(basicVal, status.s, status.len) == 0)
 				retval = 1;
 
 			xmlFree(basicVal);
@@ -97,13 +90,14 @@ int presxml_check_basic(struct sip_msg *msg, str presentity_uri, str status)
 		tuple = tuple->next;
 	}
 error:
-	if (xmlDoc != NULL)
+	if(xmlDoc != NULL)
 		xmlFreeDoc(xmlDoc);
 	pres_free_presentity(presentity, ev);
 	return retval;
 }
 
-int presxml_check_activities(struct sip_msg *msg, str presentity_uri, str activity)
+int presxml_check_activities(
+		struct sip_msg *msg, str presentity_uri, str activity)
 {
 	str *presentity = NULL;
 	struct sip_uri parsed_uri;
@@ -114,83 +108,75 @@ int presxml_check_activities(struct sip_msg *msg, str presentity_uri, str activi
 	xmlDocPtr xmlDoc = NULL;
 	xmlNodePtr person = NULL, activitiesNode = NULL, activityNode = NULL;
 
-	if (parse_uri(presentity_uri.s, presentity_uri.len, &parsed_uri) < 0)
-	{
+	if(parse_uri(presentity_uri.s, presentity_uri.len, &parsed_uri) < 0) {
 		LM_ERR("bad uri: %.*s\n", presentity_uri.len, presentity_uri.s);
 		return -1;
 	}
 
 	ev = pres_contains_event(&event, NULL);
-	if (ev == NULL)
-	{
+	if(ev == NULL) {
 		LM_ERR("event presence is not registered\n");
 		return -1;
 	}
 
-	if ((nodeName = pkg_malloc(activity.len + 1)) == NULL)
-	{
+	if((nodeName = pkg_malloc(activity.len + 1)) == NULL) {
 		LM_ERR("cannot pkg_malloc for nodeName\n");
-		return -1;		
+		return -1;
 	}
 	memcpy(nodeName, activity.s, activity.len);
 	nodeName[activity.len] = '\0';
 
 	presentity = pres_get_presentity(presentity_uri, ev, NULL, NULL);
 
-	if (presentity == NULL || presentity->len <= 0 || presentity->s == NULL)
-	{
-		LM_DBG("cannot get presentity for %.*s\n", presentity_uri.len, presentity_uri.s);
+	if(presentity == NULL || presentity->len <= 0 || presentity->s == NULL) {
+		LM_DBG("cannot get presentity for %.*s\n", presentity_uri.len,
+				presentity_uri.s);
 		goto error;
 	}
 
-	if ((xmlDoc = xmlParseMemory(presentity->s, presentity->len)) == NULL)
-	{
+	if((xmlDoc = xmlParseMemory(presentity->s, presentity->len)) == NULL) {
 		LM_ERR("while parsing XML memory\n");
 		goto error;
 	}
 
-	if ((person = xmlDocGetNodeByName(xmlDoc, "person", NULL)) == NULL)
-	{
+	if((person = xmlDocGetNodeByName(xmlDoc, "person", NULL)) == NULL) {
 		LM_DBG("unable to extract 'person'\n");
 		retval = -2;
 		goto error;
 	}
 
-	while (person != NULL)
-	{
-		if (xmlStrcasecmp(person->name, (unsigned char *) "person") == 0)
-		{
-			if ((activitiesNode = xmlNodeGetNodeByName(person, "activities", NULL)) == NULL)
-			{
+	while(person != NULL) {
+		if(xmlStrcasecmp(person->name, (unsigned char *)"person") == 0) {
+			if((activitiesNode =
+							   xmlNodeGetNodeByName(person, "activities", NULL))
+					== NULL) {
 				LM_DBG("unable to extract 'activities' node\n");
-				if (retval <= 0)
-				{
+				if(retval <= 0) {
 					retval = -2;
 				}
 				break;
 			}
 
-			if (activitiesNode->children == NULL)
-			{
+			if(activitiesNode->children == NULL) {
 				LM_DBG("activities node has no children\n");
-				if (retval <= 0)
-				{
+				if(retval <= 0) {
 					retval = -2;
 				}
 				break;
 			}
 
-			if ((activityNode = xmlNodeGetNodeByName(activitiesNode, nodeName, NULL)) != NULL)
-			{
+			if((activityNode = xmlNodeGetNodeByName(
+						activitiesNode, nodeName, NULL))
+					!= NULL) {
 				retval = 1;
 			}
 		}
 		person = person->next;
 	}
 error:
-	if (nodeName != NULL)
+	if(nodeName != NULL)
 		pkg_free(nodeName);
-	if (xmlDoc != NULL)
+	if(xmlDoc != NULL)
 		xmlFreeDoc(xmlDoc);
 	if(presentity != NULL)
 		pres_free_presentity(presentity, ev);

+ 3 - 2
src/modules/presence_xml/pres_check.h

@@ -28,8 +28,9 @@
 #include "../presence/bind_presence.h"
 #include "../presence/event_list.h"
 
-int presxml_check_basic(struct sip_msg* msg, str presentity_uri, str status);
-int presxml_check_activities(struct sip_msg* msg, str presentity_uri, str activity);
+int presxml_check_basic(struct sip_msg *msg, str presentity_uri, str status);
+int presxml_check_activities(
+		struct sip_msg *msg, str presentity_uri, str activity);
 extern contains_event_t pres_contains_event;
 extern pres_get_presentity_t pres_get_presentity;
 extern pres_free_presentity_t pres_free_presentity;

+ 120 - 135
src/modules/presence_xml/presence_xml.c

@@ -64,14 +64,16 @@ MODULE_VERSION
 static int mod_init(void);
 static int child_init(int);
 static void destroy(void);
-static int pxml_add_xcap_server( modparam_t type, void* val);
+static int pxml_add_xcap_server(modparam_t type, void *val);
 static int shm_copy_xcap_list(void);
-static void free_xs_list(xcap_serv_t* xs_list, int mem_type);
-static int xcap_doc_updated(int doc_type, str xid, char* doc);
+static void free_xs_list(xcap_serv_t *xs_list, int mem_type);
+static int xcap_doc_updated(int doc_type, str xid, char *doc);
 
 static int fixup_presxml_check(void **param, int param_no);
-static int w_presxml_check_basic(sip_msg_t *msg, char *presentity_uri, char *status);
-static int w_presxml_check_activities(sip_msg_t *msg, char *presentity_uri, char *activities);
+static int w_presxml_check_basic(
+		sip_msg_t *msg, char *presentity_uri, char *status);
+static int w_presxml_check_activities(
+		sip_msg_t *msg, char *presentity_uri, char *activities);
 
 /** module variables ***/
 add_event_t pres_add_event;
@@ -83,16 +85,16 @@ pres_get_presentity_t pres_get_presentity;
 pres_free_presentity_t pres_free_presentity;
 
 /* Module parameter variables */
-str xcap_table= str_init("xcap");
+str xcap_table = str_init("xcap");
 static str presxml_db_url = str_init(DEFAULT_DB_URL);
-int force_active= 0;
+int force_active = 0;
 int force_dummy_presence = 0;
-int integrated_xcap_server= 0;
-xcap_serv_t* xs_list= NULL;
+int integrated_xcap_server = 0;
+xcap_serv_t *xs_list = NULL;
 int disable_presence = 0;
-int disable_winfo    = 0;
-int disable_bla      = 1;
-int passive_mode     = 0;
+int disable_winfo = 0;
+int disable_bla = 1;
+int passive_mode = 0;
 int disable_xcapdiff = 0;
 str xcapauth_userdel_reason = str_init("probation");
 
@@ -107,6 +109,7 @@ db_func_t pxml_dbf;
 
 xcapGetNewDoc_t xcap_GetNewDoc;
 
+/* clang-format off */
 static cmd_export_t cmds[]={
 	{ "pres_check_basic",		(cmd_function)w_presxml_check_basic, 2,
 		fixup_presxml_check, 0, ANY_ROUTE},
@@ -116,7 +119,9 @@ static cmd_export_t cmds[]={
 		0, 0, 0},
 	{ 0, 0, 0, 0, 0, 0}
 };
+/* clang-format on */
 
+/* clang-format off */
 static param_export_t params[]={
 	{ "db_url",		PARAM_STR, &presxml_db_url},
 	{ "xcap_table",		PARAM_STR, &xcap_table},
@@ -132,9 +137,10 @@ static param_export_t params[]={
 	{ "force_dummy_presence",       INT_PARAM, &force_dummy_presence },
 	{ 0, 0, 0}
 };
-
+/* clang-format on */
 
 /** module exports */
+/* clang-format off */
 struct module_exports exports= {
 	"presence_xml",		/* module name */
 	DEFAULT_DLFLAGS,	/* dlopen flags */
@@ -147,6 +153,7 @@ struct module_exports exports= {
 	child_init,			/* per-child init function */
 	destroy				/* module destroy function */
 };
+/* clang-format on */
 
 /**
  * init module function
@@ -156,108 +163,97 @@ static int mod_init(void)
 	bind_presence_t bind_presence;
 	presence_api_t pres;
 
-	if(passive_mode==1)
+	if(passive_mode == 1)
 		return 0;
 
 	LM_DBG("db_url=%s (len=%d addr=%p)\n", ZSW(presxml_db_url.s),
 			presxml_db_url.len, presxml_db_url.s);
 
 	/* bind the SL API */
-	if (sl_load_api(&slb)!=0) {
+	if(sl_load_api(&slb) != 0) {
 		LM_ERR("cannot bind to SL API\n");
 		return -1;
 	}
 
-	bind_presence= (bind_presence_t)find_export("bind_presence", 1,0);
-	if (!bind_presence)
-	{
+	bind_presence = (bind_presence_t)find_export("bind_presence", 1, 0);
+	if(!bind_presence) {
 		LM_ERR("Can't bind presence\n");
 		return -1;
 	}
-	if (bind_presence(&pres) < 0)
-	{
+	if(bind_presence(&pres) < 0) {
 		LM_ERR("Can't bind to presence module\n");
 		return -1;
 	}
 
-	pres_get_sphere= pres.get_sphere;
-	pres_add_event= pres.add_event;
-	pres_update_watchers= pres.update_watchers_status;
-	pres_contains_event= pres.contains_event;
-	pres_get_presentity= pres.get_presentity;
-	pres_free_presentity= pres.free_presentity;
-	if (pres_add_event == NULL || pres_update_watchers== NULL)
-	{
+	pres_get_sphere = pres.get_sphere;
+	pres_add_event = pres.add_event;
+	pres_update_watchers = pres.update_watchers_status;
+	pres_contains_event = pres.contains_event;
+	pres_get_presentity = pres.get_presentity;
+	pres_free_presentity = pres.free_presentity;
+	if(pres_add_event == NULL || pres_update_watchers == NULL) {
 		LM_ERR("Can't import add_event\n");
 		return -1;
 	}
-	if(xml_add_events()< 0)
-	{
+	if(xml_add_events() < 0) {
 		LM_ERR("adding xml events\n");
 		return -1;
 	}
 
-	if(force_active== 0)
-	{
+	if(force_active == 0) {
 		/* binding to mysql module  */
-		if (db_bind_mod(&presxml_db_url, &pxml_dbf))
-		{
+		if(db_bind_mod(&presxml_db_url, &pxml_dbf)) {
 			LM_ERR("Database module not found\n");
 			return -1;
 		}
 
-		if (!DB_CAPABILITY(pxml_dbf, DB_CAP_ALL)) {
+		if(!DB_CAPABILITY(pxml_dbf, DB_CAP_ALL)) {
 			LM_ERR("Database module does not implement all functions"
-					" needed by the module\n");
+				   " needed by the module\n");
 			return -1;
 		}
 
 		pxml_db = pxml_dbf.init(&presxml_db_url);
-		if (!pxml_db)
-		{
+		if(!pxml_db) {
 			LM_ERR("while connecting to database\n");
 			return -1;
 		}
 
-		if(db_check_table_version(&pxml_dbf, pxml_db, &xcap_table, S_TABLE_VERSION) < 0) {
+		if(db_check_table_version(
+				   &pxml_dbf, pxml_db, &xcap_table, S_TABLE_VERSION)
+				< 0) {
 			DB_TABLE_VERSION_ERROR(xcap_table);
 			goto dberror;
 		}
-		if(!integrated_xcap_server )
-		{
+		if(!integrated_xcap_server) {
 			xcap_api_t xcap_api;
 			bind_xcap_t bind_xcap;
 
 			/* bind xcap */
-			bind_xcap= (bind_xcap_t)find_export("bind_xcap", 1, 0);
-			if (!bind_xcap)
-			{
+			bind_xcap = (bind_xcap_t)find_export("bind_xcap", 1, 0);
+			if(!bind_xcap) {
 				LM_ERR("Can't bind xcap_client\n");
 				goto dberror;
 			}
 
-			if (bind_xcap(&xcap_api) < 0)
-			{
+			if(bind_xcap(&xcap_api) < 0) {
 				LM_ERR("Can't bind xcap_api\n");
 				goto dberror;
 			}
-			xcap_GetNewDoc= xcap_api.getNewDoc;
-			if(xcap_GetNewDoc== NULL)
-			{
+			xcap_GetNewDoc = xcap_api.getNewDoc;
+			if(xcap_GetNewDoc == NULL) {
 				LM_ERR("can't import getNewDoc from xcap_client module\n");
 				goto dberror;
 			}
 
-			if(xcap_api.register_xcb(PRES_RULES, xcap_doc_updated)< 0)
-			{
+			if(xcap_api.register_xcb(PRES_RULES, xcap_doc_updated) < 0) {
 				LM_ERR("registering xcap callback function\n");
 				goto dberror;
 			}
 		}
 	}
 
-	if(shm_copy_xcap_list()< 0)
-	{
+	if(shm_copy_xcap_list() < 0) {
 		LM_ERR("copying xcap server list in share memory\n");
 		return -1;
 	}
@@ -278,30 +274,27 @@ static int child_init(int rank)
 {
 	LM_DBG("[%d]  pid [%d]\n", rank, getpid());
 
-	if(passive_mode==1)
+	if(passive_mode == 1)
 		return 0;
 
-	if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN)
+	if(rank == PROC_INIT || rank == PROC_MAIN || rank == PROC_TCP_MAIN)
 		return 0; /* do nothing for the main process */
 
-	if(force_active== 0)
-	{
+	if(force_active == 0) {
 		if(pxml_db)
 			return 0;
 		pxml_db = pxml_dbf.init(&presxml_db_url);
-		if (pxml_db== NULL)
-		{
+		if(pxml_db == NULL) {
 			LM_ERR("while connecting database\n");
 			return -1;
 		}
-		if (pxml_dbf.use_table(pxml_db, &xcap_table) < 0)
-		{
+		if(pxml_dbf.use_table(pxml_db, &xcap_table) < 0) {
 			LM_ERR("in use_table SQL operation\n");
 			return -1;
 		}
 	}
 
-	LM_DBG("child %d: Database connection opened successfully\n",rank);
+	LM_DBG("child %d: Database connection opened successfully\n", rank);
 
 	return 0;
 }
@@ -314,65 +307,61 @@ static void destroy(void)
 
 	free_xs_list(xs_list, SHM_MEM_TYPE);
 
-	return ;
+	return;
 }
 
-static int pxml_add_xcap_server( modparam_t type, void* val)
+static int pxml_add_xcap_server(modparam_t type, void *val)
 {
-	xcap_serv_t* xs;
+	xcap_serv_t *xs;
 	int size;
-	char* serv_addr= (char*)val;
-	char* sep= NULL;
-	unsigned int port= 80;
+	char *serv_addr = (char *)val;
+	char *sep = NULL;
+	unsigned int port = 80;
 	str serv_addr_str;
 
-	serv_addr_str.s= serv_addr;
-	serv_addr_str.len= strlen(serv_addr);
+	serv_addr_str.s = serv_addr;
+	serv_addr_str.len = strlen(serv_addr);
 
-	sep= strchr(serv_addr, ':');
-	if(sep)
-	{
-		char* sep2= NULL;
+	sep = strchr(serv_addr, ':');
+	if(sep) {
+		char *sep2 = NULL;
 		str port_str;
 
-		sep2= strchr(sep+ 1, ':');
+		sep2 = strchr(sep + 1, ':');
 		if(sep2)
-			sep= sep2;
+			sep = sep2;
 
 
-		port_str.s= sep+ 1;
-		port_str.len= serv_addr_str.len- (port_str.s- serv_addr);
+		port_str.s = sep + 1;
+		port_str.len = serv_addr_str.len - (port_str.s - serv_addr);
 
-		if(str2int(&port_str, &port)< 0)
-		{
+		if(str2int(&port_str, &port) < 0) {
 			LM_ERR("while converting string to int\n");
 			goto error;
 		}
-		if(port< 1 || port> 65535)
-		{
+		if(port < 1 || port > 65535) {
 			LM_ERR("wrong port number\n");
 			goto error;
 		}
 		*sep = '\0';
-		serv_addr_str.len= sep- serv_addr;
+		serv_addr_str.len = sep - serv_addr;
 	}
 
-	size= sizeof(xcap_serv_t)+ (serv_addr_str.len+ 1)* sizeof(char);
-	xs= (xcap_serv_t*)pkg_malloc(size);
-	if(xs== NULL)
-	{
+	size = sizeof(xcap_serv_t) + (serv_addr_str.len + 1) * sizeof(char);
+	xs = (xcap_serv_t *)pkg_malloc(size);
+	if(xs == NULL) {
 		ERR_MEM(PKG_MEM_STR);
 	}
 	memset(xs, 0, size);
-	size= sizeof(xcap_serv_t);
+	size = sizeof(xcap_serv_t);
 
-	xs->addr= (char*)xs+ size;
+	xs->addr = (char *)xs + size;
 	strcpy(xs->addr, serv_addr);
 
-	xs->port= port;
+	xs->port = port;
 	/* check for duplicates */
-	xs->next= xs_list;
-	xs_list= xs;
+	xs->next = xs_list;
+	xs_list = xs;
 	return 0;
 
 error:
@@ -382,41 +371,37 @@ error:
 
 static int shm_copy_xcap_list(void)
 {
-	xcap_serv_t* xs, *shm_xs, *prev_xs;
+	xcap_serv_t *xs, *shm_xs, *prev_xs;
 	int size;
 
-	xs= xs_list;
-	if(xs== NULL)
-	{
-		if(force_active== 0 && !integrated_xcap_server)
-		{
+	xs = xs_list;
+	if(xs == NULL) {
+		if(force_active == 0 && !integrated_xcap_server) {
 			LM_ERR("no xcap_server parameter set\n");
 			return -1;
 		}
 		return 0;
 	}
-	xs_list= NULL;
-	size= sizeof(xcap_serv_t);
-
-	while(xs)
-	{
-		size+= (strlen(xs->addr)+ 1)* sizeof(char);
-		shm_xs= (xcap_serv_t*)shm_malloc(size);
-		if(shm_xs== NULL)
-		{
+	xs_list = NULL;
+	size = sizeof(xcap_serv_t);
+
+	while(xs) {
+		size += (strlen(xs->addr) + 1) * sizeof(char);
+		shm_xs = (xcap_serv_t *)shm_malloc(size);
+		if(shm_xs == NULL) {
 			ERR_MEM(SHARE_MEM);
 		}
 		memset(shm_xs, 0, size);
-		size= sizeof(xcap_serv_t);
+		size = sizeof(xcap_serv_t);
 
-		shm_xs->addr= (char*)shm_xs+ size;
+		shm_xs->addr = (char *)shm_xs + size;
 		strcpy(shm_xs->addr, xs->addr);
-		shm_xs->port= xs->port;
-		shm_xs->next= xs_list;
-		xs_list= shm_xs;
+		shm_xs->port = xs->port;
+		shm_xs->next = xs_list;
+		xs_list = shm_xs;
 
-		prev_xs= xs;
-		xs= xs->next;
+		prev_xs = xs;
+		xs = xs->next;
 
 		pkg_free(prev_xs);
 	}
@@ -427,43 +412,40 @@ error:
 	return -1;
 }
 
-static void free_xs_list(xcap_serv_t* xsl, int mem_type)
+static void free_xs_list(xcap_serv_t *xsl, int mem_type)
 {
-	xcap_serv_t* xs, *prev_xs;
+	xcap_serv_t *xs, *prev_xs;
 
-	xs= xsl;
+	xs = xsl;
 
-	while(xs)
-	{
-		prev_xs= xs;
-		xs= xs->next;
+	while(xs) {
+		prev_xs = xs;
+		xs = xs->next;
 		if(mem_type & SHM_MEM_TYPE)
 			shm_free(prev_xs);
 		else
 			pkg_free(prev_xs);
 	}
-	xsl= NULL;
+	xsl = NULL;
 }
 
-static int xcap_doc_updated(int doc_type, str xid, char* doc)
+static int xcap_doc_updated(int doc_type, str xid, char *doc)
 {
 	pres_ev_t ev;
 	str rules_doc;
 
 	/* call updating watchers */
-	ev.name.s= "presence";
-	ev.name.len= PRES_LEN;
+	ev.name.s = "presence";
+	ev.name.len = PRES_LEN;
 
-	rules_doc.s= doc;
-	rules_doc.len= strlen(doc);
+	rules_doc.s = doc;
+	rules_doc.len = strlen(doc);
 
-	if(pres_update_watchers(xid, &ev, &rules_doc)< 0)
-	{
+	if(pres_update_watchers(xid, &ev, &rules_doc) < 0) {
 		LM_ERR("updating watchers in presence\n");
 		return -1;
 	}
 	return 0;
-
 }
 
 int bind_presence_xml(struct presence_xml_binds *pxb)
@@ -489,7 +471,8 @@ static int fixup_presxml_check(void **param, int param_no)
 	return 0;
 }
 
-static int w_presxml_check_basic(sip_msg_t *msg, char *presentity_uri, char *status)
+static int w_presxml_check_basic(
+		sip_msg_t *msg, char *presentity_uri, char *status)
 {
 	str uri, basic;
 
@@ -508,13 +491,14 @@ static int w_presxml_check_basic(sip_msg_t *msg, char *presentity_uri, char *sta
 
 static int ki_presxml_check_basic(sip_msg_t *msg, str *pres_uri, str *status)
 {
-	if(pres_uri==NULL || status==NULL) {
+	if(pres_uri == NULL || status == NULL) {
 		return -1;
 	}
 	return presxml_check_basic(msg, *pres_uri, *status);
 }
 
-static int w_presxml_check_activities(sip_msg_t *msg, char *presentity_uri, char *activity)
+static int w_presxml_check_activities(
+		sip_msg_t *msg, char *presentity_uri, char *activity)
 {
 	str uri, act;
 
@@ -531,9 +515,10 @@ static int w_presxml_check_activities(sip_msg_t *msg, char *presentity_uri, char
 	return presxml_check_activities(msg, uri, act);
 }
 
-static int ki_presxml_check_activities(sip_msg_t *msg, str *pres_uri, str *activity)
+static int ki_presxml_check_activities(
+		sip_msg_t *msg, str *pres_uri, str *activity)
 {
-	if(pres_uri==NULL || activity==NULL) {
+	if(pres_uri == NULL || activity == NULL) {
 		return -1;
 	}
 	return presxml_check_activities(msg, *pres_uri, *activity);

+ 3 - 3
src/modules/presence_xml/presence_xml.h

@@ -37,9 +37,9 @@
 
 typedef struct xcap_serv
 {
-	char* addr;
+	char *addr;
 	unsigned int port;
-	struct xcap_serv* next;
+	struct xcap_serv *next;
 } xcap_serv_t;
 
 extern sl_api_t slb;
@@ -51,7 +51,7 @@ extern db_func_t pxml_dbf;
 extern int force_active;
 extern int pidf_manipulation;
 extern int integrated_xcap_server;
-extern xcap_serv_t* xs_list;
+extern xcap_serv_t *xs_list;
 extern xcapGetNewDoc_t xcap_GetNewDoc;
 extern pres_get_sphere_t pres_get_sphere;
 

+ 213 - 286
src/modules/presence_xml/xcap_auth.c

@@ -44,111 +44,89 @@
 
 extern str xcapauth_userdel_reason;
 
-int http_get_rules_doc(str user, str domain, str* rules_doc);
+int http_get_rules_doc(str user, str domain, str *rules_doc);
 
-int pres_watcher_allowed(subs_t* subs)
+int pres_watcher_allowed(subs_t *subs)
 {
-	xmlDocPtr xcap_tree= NULL;
-	xmlNodePtr node= NULL,  actions_node = NULL;
+	xmlDocPtr xcap_tree = NULL;
+	xmlNodePtr node = NULL, actions_node = NULL;
 	xmlNodePtr sub_handling_node = NULL;
-	char* sub_handling = NULL;
+	char *sub_handling = NULL;
 	int ret = 0;
 
 	/* if force_active set status to active*/
-	if(force_active)
-	{
-		subs->status= ACTIVE_STATUS;
-		subs->reason.s= NULL;
-		subs->reason.len= 0;
+	if(force_active) {
+		subs->status = ACTIVE_STATUS;
+		subs->reason.s = NULL;
+		subs->reason.len = 0;
 		return 0;
 	}
 
-	if(subs->auth_rules_doc== NULL)
-	{
-		subs->status= PENDING_STATUS;
-		subs->reason.s= NULL;
-		subs->reason.len= 0;
+	if(subs->auth_rules_doc == NULL) {
+		subs->status = PENDING_STATUS;
+		subs->reason.s = NULL;
+		subs->reason.len = 0;
 		return 0;
 	}
 
-	xcap_tree= xmlParseMemory(subs->auth_rules_doc->s,
-			subs->auth_rules_doc->len);
-	if(xcap_tree== NULL)
-	{
+	xcap_tree =
+			xmlParseMemory(subs->auth_rules_doc->s, subs->auth_rules_doc->len);
+	if(xcap_tree == NULL) {
 		LM_ERR("parsing xml memory\n");
 		return -1;
 	}
 
-	node= get_rule_node(subs, xcap_tree);
-	if(node== NULL)
-	{
+	node = get_rule_node(subs, xcap_tree);
+	if(node == NULL) {
 		/* if no rule node was found and the previous state was active -> set the
 		 * state to terminated with reason xcapauth_userdel_reason (default "probation") */
-		if(subs->status != PENDING_STATUS)
-		{
-			subs->status= TERMINATED_STATUS;
-			subs->reason= xcapauth_userdel_reason;
+		if(subs->status != PENDING_STATUS) {
+			subs->status = TERMINATED_STATUS;
+			subs->reason = xcapauth_userdel_reason;
 		}
 		goto done;
 	}
 
-	subs->status= PENDING_STATUS;
-	subs->reason.s= NULL;
-	subs->reason.len= 0;
+	subs->status = PENDING_STATUS;
+	subs->reason.s = NULL;
+	subs->reason.len = 0;
 
 	/* process actions */
 	actions_node = xmlNodeGetChildByName(node, "actions");
-	if(actions_node == NULL)
-	{
+	if(actions_node == NULL) {
 		LM_DBG("actions_node NULL\n");
 		goto done;
 	}
-	LM_DBG("actions_node->name= %s\n",
-			actions_node->name);
-			
+	LM_DBG("actions_node->name= %s\n", actions_node->name);
+
 	sub_handling_node = xmlNodeGetChildByName(actions_node, "sub-handling");
-	if(sub_handling_node== NULL)
-	{
+	if(sub_handling_node == NULL) {
 		LM_DBG("sub_handling_node NULL\n");
 		goto done;
 	}
-	sub_handling = (char*)xmlNodeGetContent(sub_handling_node);
-		LM_DBG("sub_handling_node->name= %s\n",
-			sub_handling_node->name);
-	LM_DBG("sub_handling_node->content= %s\n",
-			sub_handling);
-	
-	if(sub_handling== NULL)
-	{
+	sub_handling = (char *)xmlNodeGetContent(sub_handling_node);
+	LM_DBG("sub_handling_node->name= %s\n", sub_handling_node->name);
+	LM_DBG("sub_handling_node->content= %s\n", sub_handling);
+
+	if(sub_handling == NULL) {
 		LM_ERR("Couldn't get sub-handling content\n");
 		ret = -1;
 		goto done;
 	}
-	if( strncmp((char*)sub_handling, "block",5 )==0)
-	{	
-		subs->status = TERMINATED_STATUS;;
-		subs->reason.s= "rejected";
+	if(strncmp((char *)sub_handling, "block", 5) == 0) {
+		subs->status = TERMINATED_STATUS;
+		;
+		subs->reason.s = "rejected";
 		subs->reason.len = 8;
-	}
-	else	
-	if( strncmp((char*)sub_handling, "confirm",7 )==0)
-	{	
+	} else if(strncmp((char *)sub_handling, "confirm", 7) == 0) {
 		subs->status = PENDING_STATUS;
-	}
-	else
-	if( strncmp((char*)sub_handling , "polite-block",12 )==0)
-	{	
+	} else if(strncmp((char *)sub_handling, "polite-block", 12) == 0) {
 		subs->status = ACTIVE_STATUS;
-		subs->reason.s= "polite-block";
+		subs->reason.s = "polite-block";
 		subs->reason.len = 12;
-	}
-	else
-	if( strncmp((char*)sub_handling , "allow",5 )==0)
-	{
+	} else if(strncmp((char *)sub_handling, "allow", 5) == 0) {
 		subs->status = ACTIVE_STATUS;
-	}
-	else
-	{
+	} else {
 		LM_ERR("unknown subscription handling action\n");
 		ret = -1;
 	}
@@ -160,132 +138,114 @@ done:
 	return ret;
 }
 
-xmlNodePtr get_rule_node(subs_t* subs, xmlDocPtr xcap_tree )
+xmlNodePtr get_rule_node(subs_t *subs, xmlDocPtr xcap_tree)
 {
-	str w_uri= {0, 0};
-	char* id = NULL, *domain = NULL, *time_cont= NULL;
+	str w_uri = {0, 0};
+	char *id = NULL, *domain = NULL, *time_cont = NULL;
 	int apply_rule = -1;
-	xmlNodePtr ruleset_node = NULL, node1= NULL, node2= NULL;
+	xmlNodePtr ruleset_node = NULL, node1 = NULL, node2 = NULL;
 	xmlNodePtr cond_node = NULL, except_node = NULL;
 	xmlNodePtr identity_node = NULL, sphere_node = NULL;
 	xmlNodePtr iden_child;
 	xmlNodePtr validity_node, time_node;
 	time_t t_init, t_fin, t;
-	int valid= 0;
+	int valid = 0;
 
 
 	uandd_to_uri(subs->watcher_user, subs->watcher_domain, &w_uri);
-	if(w_uri.s == NULL)
-	{
+	if(w_uri.s == NULL) {
 		LM_ERR("while creating uri\n");
 		return NULL;
 	}
 	ruleset_node = xmlDocGetNodeByName(xcap_tree, "ruleset", NULL);
-	if(ruleset_node == NULL)
-	{
+	if(ruleset_node == NULL) {
 		LM_DBG("ruleset_node NULL\n");
 		goto error;
-
-	}	
-	for(node1 = ruleset_node->children ; node1; node1 = node1->next)
-	{
-		if(xmlStrcasecmp(node1->name, (unsigned char*)"text")==0 )
-				continue;
+	}
+	for(node1 = ruleset_node->children; node1; node1 = node1->next) {
+		if(xmlStrcasecmp(node1->name, (unsigned char *)"text") == 0)
+			continue;
 
 		/* process conditions */
 		LM_DBG("node1->name= %s\n", node1->name);
 
 		cond_node = xmlNodeGetChildByName(node1, "conditions");
-		if(cond_node == NULL)
-		{	
+		if(cond_node == NULL) {
 			LM_DBG("cond node NULL\n");
 			goto error;
 		}
 		LM_DBG("cond_node->name= %s\n", cond_node->name);
 
 		validity_node = xmlNodeGetChildByName(cond_node, "validity");
-		if(validity_node !=NULL)
-		{
+		if(validity_node != NULL) {
 			LM_DBG("found validity tag\n");
-		
-			t= time(NULL);
-		
+
+			t = time(NULL);
+
 			/* search all from-until pair */
-			for(time_node= validity_node->children; time_node;
-					time_node= time_node->next)
-			{
-				if(xmlStrcasecmp(time_node->name, (unsigned char*)"from")!= 0)
-				{
+			for(time_node = validity_node->children; time_node;
+					time_node = time_node->next) {
+				if(xmlStrcasecmp(time_node->name, (unsigned char *)"from")
+						!= 0) {
 					continue;
 				}
-				time_cont= (char*)xmlNodeGetContent(time_node);
-				t_init= xml_parse_dateTime(time_cont);
+				time_cont = (char *)xmlNodeGetContent(time_node);
+				t_init = xml_parse_dateTime(time_cont);
 				xmlFree(time_cont);
-				if(t_init< 0)
-				{
+				if(t_init < 0) {
 					LM_ERR("failed to parse xml dateTime\n");
 					goto error;
 				}
 
-				if(t< t_init)
-				{
+				if(t < t_init) {
 					LM_DBG("the lower time limit is not respected\n");
 					continue;
 				}
-				
-				time_node= time_node->next;
-				while(1)
-				{
-					if(time_node== NULL)
-					{	
+
+				time_node = time_node->next;
+				while(1) {
+					if(time_node == NULL) {
 						LM_ERR("bad formatted xml doc:until child not found in"
-								" validity pair\n");
+							   " validity pair\n");
 						goto error;
 					}
-					if( xmlStrcasecmp(time_node->name, 
-								(unsigned char*)"until")== 0)
+					if(xmlStrcasecmp(time_node->name, (unsigned char *)"until")
+							== 0)
 						break;
-					time_node= time_node->next;
+					time_node = time_node->next;
 				}
-				
-				time_cont= (char*)xmlNodeGetContent(time_node);
-				t_fin= xml_parse_dateTime(time_cont);
+
+				time_cont = (char *)xmlNodeGetContent(time_node);
+				t_fin = xml_parse_dateTime(time_cont);
 				xmlFree(time_cont);
 
-				if(t_fin< 0)
-				{
+				if(t_fin < 0) {
 					LM_ERR("failed to parse xml dateTime\n");
 					goto error;
 				}
-			
-				if(t <= t_fin)
-				{
+
+				if(t <= t_fin) {
 					LM_DBG("the rule is active at this time\n");
-					valid= 1;
+					valid = 1;
 				}
-			
 			}
-		
-			if(!valid)
-			{
+
+			if(!valid) {
 				LM_DBG("the rule is not active at this time\n");
 				continue;
 			}
+		}
 
-		}	
-	
 		sphere_node = xmlNodeGetChildByName(cond_node, "sphere");
-		if(sphere_node!= NULL)
-		{
+		if(sphere_node != NULL) {
 			/* check to see if matches presentity current sphere */
 			/* ask presence for sphere information */
-			
-			char* sphere= pres_get_sphere(&subs->pres_uri);
-			if(sphere)
-			{
-				char* attr= (char*)xmlNodeGetContent(sphere_node);
-				if(xmlStrcasecmp((unsigned char*)attr, (unsigned char*)sphere)!= 0)
-				{
+
+			char *sphere = pres_get_sphere(&subs->pres_uri);
+			if(sphere) {
+				char *attr = (char *)xmlNodeGetContent(sphere_node);
+				if(xmlStrcasecmp((unsigned char *)attr, (unsigned char *)sphere)
+						!= 0) {
 					LM_DBG("sphere condition not respected\n");
 					pkg_free(sphere);
 					xmlFree(attr);
@@ -293,129 +253,114 @@ xmlNodePtr get_rule_node(subs_t* subs, xmlDocPtr xcap_tree )
 				}
 				pkg_free(sphere);
 				xmlFree(attr);
-	
 			}
-				
+
 			/* if the user has not define a sphere -> 
 			 *						consider the condition true*/
 		}
 
 		identity_node = xmlNodeGetChildByName(cond_node, "identity");
-		if(identity_node == NULL)
-		{
+		if(identity_node == NULL) {
 			LM_WARN("didn't find identity tag\n");
 			continue;
-		}	
-		
-		iden_child= xmlNodeGetChildByName(identity_node, "one");
-		if(iden_child)	
-		{
-			for(node2 = identity_node->children; node2; node2 = node2->next)
-			{
-				if(xmlStrcasecmp(node2->name, (unsigned char*)"one")!= 0)
+		}
+
+		iden_child = xmlNodeGetChildByName(identity_node, "one");
+		if(iden_child) {
+			for(node2 = identity_node->children; node2; node2 = node2->next) {
+				if(xmlStrcasecmp(node2->name, (unsigned char *)"one") != 0)
 					continue;
-				
-				id = xmlNodeGetAttrContentByName(node2, "id");	
-				if(id== NULL)
-				{
+
+				id = xmlNodeGetAttrContentByName(node2, "id");
+				if(id == NULL) {
 					LM_ERR("while extracting attribute\n");
 					goto error;
 				}
-				if((strlen(id)== w_uri.len && 
-							(strncmp(id, w_uri.s, w_uri.len)==0)))	
-				{
+				if((strlen(id) == w_uri.len
+						   && (strncmp(id, w_uri.s, w_uri.len) == 0))) {
 					apply_rule = 1;
 					xmlFree(id);
 					break;
 				}
 				xmlFree(id);
 			}
-		}	
+		}
 
 		/* search for many node*/
-		iden_child= xmlNodeGetChildByName(identity_node, "many");
-		if(iden_child)	
-		{
+		iden_child = xmlNodeGetChildByName(identity_node, "many");
+		if(iden_child) {
 			domain = NULL;
-			for(node2 = identity_node->children; node2; node2 = node2->next)
-			{
-				if(xmlStrcasecmp(node2->name, (unsigned char*)"many")!= 0)
+			for(node2 = identity_node->children; node2; node2 = node2->next) {
+				if(xmlStrcasecmp(node2->name, (unsigned char *)"many") != 0)
 					continue;
-	
+
 				domain = xmlNodeGetAttrContentByName(node2, "domain");
-				if(domain == NULL)
-				{	
+				if(domain == NULL) {
 					LM_DBG("No domain attribute to many\n");
-				}
-				else	
-				{
+				} else {
 					LM_DBG("<many domain= %s>\n", domain);
-					if((strlen(domain)!= subs->from_domain.len && 
-								strncmp(domain, subs->from_domain.s,
-									subs->from_domain.len) ))
-					{
+					if((strlen(domain) != subs->from_domain.len
+							   && strncmp(domain, subs->from_domain.s,
+										  subs->from_domain.len))) {
 						xmlFree(domain);
 						continue;
-					}	
+					}
 				}
 				xmlFree(domain);
 				apply_rule = 1;
-				if(node2->children == NULL)       /* there is no exception */
+				if(node2->children == NULL) /* there is no exception */
 					break;
 
 				for(except_node = node2->children; except_node;
-						except_node= except_node->next)
-				{
-					if(xmlStrcasecmp(except_node->name, (unsigned char*)"except"))
+						except_node = except_node->next) {
+					if(xmlStrcasecmp(
+							   except_node->name, (unsigned char *)"except"))
 						continue;
 
-					id = xmlNodeGetAttrContentByName(except_node, "id");	
-					if(id!=NULL)
-					{
-						if((strlen(id)- 1== w_uri.len && 
-								(strncmp(id, w_uri.s, w_uri.len)==0)))	
-						{
+					id = xmlNodeGetAttrContentByName(except_node, "id");
+					if(id != NULL) {
+						if((strlen(id) - 1 == w_uri.len
+								   && (strncmp(id, w_uri.s, w_uri.len) == 0))) {
 							xmlFree(id);
 							apply_rule = 0;
 							break;
 						}
 						xmlFree(id);
-					}	
-					else
-					{
+					} else {
 						domain = NULL;
-						domain = xmlNodeGetAttrContentByName(except_node, "domain");
-						if(domain!=NULL)
-						{
-							LM_DBG("Found except domain= %s\n- strlen(domain)= %d\n",
+						domain = xmlNodeGetAttrContentByName(
+								except_node, "domain");
+						if(domain != NULL) {
+							LM_DBG("Found except domain= %s\n- strlen(domain)= "
+								   "%d\n",
 									domain, (int)strlen(domain));
-							if(strlen(domain)==subs->from_domain.len &&
-								(strncmp(domain,subs->from_domain.s , subs->from_domain.len)==0))	
-							{
+							if(strlen(domain) == subs->from_domain.len
+									&& (strncmp(domain, subs->from_domain.s,
+												subs->from_domain.len)
+											   == 0)) {
 								LM_DBG("except domain match\n");
 								xmlFree(domain);
 								apply_rule = 0;
 								break;
 							}
 							xmlFree(domain);
-						}	
-
-					}	
+						}
+					}
 				}
-				if(apply_rule== 1)  /* if a match was found no need to keep searching*/
+				if(apply_rule
+						== 1) /* if a match was found no need to keep searching*/
 					break;
-
-			}		
+			}
 		}
-		if(apply_rule ==1)
+		if(apply_rule == 1)
 			break;
 	}
 
 	LM_DBG("apply_rule= %d\n", apply_rule);
-	if(w_uri.s!=NULL)
+	if(w_uri.s != NULL)
 		pkg_free(w_uri.s);
 
-	if( !apply_rule || !node1)
+	if(!apply_rule || !node1)
 		return NULL;
 
 	return node1;
@@ -424,11 +369,11 @@ error:
 	if(w_uri.s)
 		pkg_free(w_uri.s);
 	return NULL;
-}	
+}
 
-int pres_get_rules_doc(str* user, str* domain, str** rules_doc)
+int pres_get_rules_doc(str *user, str *domain, str **rules_doc)
 {
-	
+
 	return get_rules_doc(user, domain, NULL, PRES_RULES, rules_doc);
 }
 
@@ -437,7 +382,8 @@ int pres_get_pidf_doc(str *user, str *domain, str *file_uri, str **rules_doc)
 	return get_rules_doc(user, domain, file_uri, PIDF_MANIPULATION, rules_doc);
 }
 
-int get_rules_doc(str* user, str* domain, str *file_uri, int type, str** rules_doc)
+int get_rules_doc(
+		str *user, str *domain, str *file_uri, int type, str **rules_doc)
 {
 	db_key_t query_cols[3];
 	db_val_t query_vals[3];
@@ -447,135 +393,119 @@ int get_rules_doc(str* user, str* domain, str *file_uri, int type, str** rules_d
 	db_row_t *row;
 	db_val_t *row_vals;
 	str body;
-	str* doc= NULL;
-	int n_result_cols= 0, xcap_doc_col;
+	str *doc = NULL;
+	int n_result_cols = 0, xcap_doc_col;
 	static str tmp1 = str_init("doc_type");
 	static str tmp2 = str_init("doc_uri");
 	static str tmp3 = str_init("username");
 	static str tmp4 = str_init("domain");
 	static str tmp5 = str_init("doc");
 
-	if(force_active)
-	{
-		*rules_doc= NULL;
+	if(force_active) {
+		*rules_doc = NULL;
 		return 0;
 	}
-	LM_DBG("[user]= %.*s\t[domain]= %.*s", 
-			user->len, user->s,	domain->len, domain->s);
+	LM_DBG("[user]= %.*s\t[domain]= %.*s", user->len, user->s, domain->len,
+			domain->s);
 
 	/* first search in database */
 	query_cols[n_query_cols] = &tmp1;
 	query_vals[n_query_cols].type = DB1_INT;
 	query_vals[n_query_cols].nul = 0;
-	query_vals[n_query_cols].val.int_val= type;
+	query_vals[n_query_cols].val.int_val = type;
 	n_query_cols++;
 
-	if (file_uri != NULL)
-	{
+	if(file_uri != NULL) {
 		query_cols[n_query_cols] = &tmp2;
 		query_vals[n_query_cols].type = DB1_STR;
 		query_vals[n_query_cols].nul = 0;
 		query_vals[n_query_cols].val.str_val = *file_uri;
 		n_query_cols++;
-	}
-	else if (user != NULL && domain != NULL)
-	{
+	} else if(user != NULL && domain != NULL) {
 		query_cols[n_query_cols] = &tmp3;
 		query_vals[n_query_cols].type = DB1_STR;
 		query_vals[n_query_cols].nul = 0;
 		query_vals[n_query_cols].val.str_val = *user;
 		n_query_cols++;
-	
+
 		query_cols[n_query_cols] = &tmp4;
 		query_vals[n_query_cols].type = DB1_STR;
 		query_vals[n_query_cols].nul = 0;
 		query_vals[n_query_cols].val.str_val = *domain;
 		n_query_cols++;
-	}
-	else
-	{
+	} else {
 		LM_ERR("Need to specify file uri _OR_ username and domain\n");
 		return -1;
 	}
-	
-	result_cols[xcap_doc_col= n_result_cols++] = &tmp5;
-	
-	if (pxml_dbf.use_table(pxml_db, &xcap_table) < 0) 
-	{
+
+	result_cols[xcap_doc_col = n_result_cols++] = &tmp5;
+
+	if(pxml_dbf.use_table(pxml_db, &xcap_table) < 0) {
 		LM_ERR("in use_table-[table]= %.*s\n", xcap_table.len, xcap_table.s);
 		return -1;
 	}
 
-	if( pxml_dbf.query(pxml_db, query_cols, 0 , query_vals, result_cols, 
-				n_query_cols, 1, 0, &result)<0)
-	{
+	if(pxml_dbf.query(pxml_db, query_cols, 0, query_vals, result_cols,
+			   n_query_cols, 1, 0, &result)
+			< 0) {
 		LM_ERR("while querying table xcap for [user]=%.*s\t[domain]= %.*s\n",
-				user->len, user->s,	domain->len, domain->s);
+				user->len, user->s, domain->len, domain->s);
 		if(result)
 			pxml_dbf.free_result(pxml_db, result);
 		return -1;
 	}
-	if(result== NULL)
+	if(result == NULL)
 		return -1;
 
-	if(result->n<= 0)
-	{
+	if(result->n <= 0) {
 		LM_DBG("No document found in db table for [user]=%.*s"
-			"\t[domain]= %.*s\t[doc_type]= %d\n",user->len, user->s,
-			domain->len, domain->s, type);
-		
-		if (!integrated_xcap_server && type != PRES_RULES)
-		{
+			   "\t[domain]= %.*s\t[doc_type]= %d\n",
+				user->len, user->s, domain->len, domain->s, type);
+
+		if(!integrated_xcap_server && type != PRES_RULES) {
 			LM_WARN("Cannot retrieve non pres-rules documents from"
-				"external XCAP server\n");
-		}
-		else if(!integrated_xcap_server)
-		{
-			if(http_get_rules_doc(*user, *domain, &body)< 0)
-			{
-				LM_ERR("sending http GET request to xcap server\n");		
+					"external XCAP server\n");
+		} else if(!integrated_xcap_server) {
+			if(http_get_rules_doc(*user, *domain, &body) < 0) {
+				LM_ERR("sending http GET request to xcap server\n");
 				goto error;
 			}
 			if(body.s && body.len)
-				goto done; 
+				goto done;
 		}
 		pxml_dbf.free_result(pxml_db, result);
 		return 0;
-	}	
-	
+	}
+
 	row = &result->rows[xcap_doc_col];
 	row_vals = ROW_VALUES(row);
 
-	body.s = (char*)row_vals[0].val.string_val;
-	if(body.s== NULL)
-	{
+	body.s = (char *)row_vals[0].val.string_val;
+	if(body.s == NULL) {
 		LM_ERR("Xcap doc NULL\n");
 		goto error;
-	}	
+	}
 	body.len = strlen(body.s);
-	if(body.len== 0)
-	{
+	if(body.len == 0) {
 		LM_ERR("Xcap doc empty\n");
 		goto error;
-	}			
-	LM_DBG("xcap document:\n%.*s", body.len,body.s);
+	}
+	LM_DBG("xcap document:\n%.*s", body.len, body.s);
 
 done:
-	doc= (str*)pkg_malloc(sizeof(str));
-	if(doc== NULL)
-	{
+	doc = (str *)pkg_malloc(sizeof(str));
+	if(doc == NULL) {
 		ERR_MEM(PKG_MEM_STR);
 	}
-	doc->s= (char*)pkg_malloc(body.len* sizeof(char));
-	if(doc->s== NULL)
-	{
+	doc->s = (char *)pkg_malloc(body.len * sizeof(char));
+	if(doc->s == NULL) {
 		pkg_free(doc);
 		ERR_MEM(PKG_MEM_STR);
 	}
 	memcpy(doc->s, body.s, body.len);
-	doc->len= body.len;
+	doc->len = body.len;
 
-	*rules_doc= doc;
+	*rules_doc = doc;
 
 	if(result)
 		pxml_dbf.free_result(pxml_db, result);
@@ -587,51 +517,48 @@ error:
 		pxml_dbf.free_result(pxml_db, result);
 
 	return -1;
-
 }
 
-int http_get_rules_doc(str user, str domain, str* rules_doc)
+int http_get_rules_doc(str user, str domain, str *rules_doc)
 {
 	str uri;
 	xcap_doc_sel_t doc_sel;
-	char* doc= NULL;
-	xcap_serv_t* xs;
+	char *doc = NULL;
+	xcap_serv_t *xs;
 	xcap_get_req_t req;
 
 	memset(&req, 0, sizeof(xcap_get_req_t));
-	if(uandd_to_uri(user, domain, &uri)< 0)
-	{
+	if(uandd_to_uri(user, domain, &uri) < 0) {
 		LM_ERR("constructing uri\n");
 		goto error;
 	}
 
-	doc_sel.auid.s= "pres-rules";
-	doc_sel.auid.len= strlen("pres-rules");
-	doc_sel.doc_type= PRES_RULES;
-	doc_sel.type= USERS_TYPE;
-	doc_sel.xid= uri;
-	doc_sel.filename.s= "index";
-	doc_sel.filename.len= 5;
+	doc_sel.auid.s = "pres-rules";
+	doc_sel.auid.len = strlen("pres-rules");
+	doc_sel.doc_type = PRES_RULES;
+	doc_sel.type = USERS_TYPE;
+	doc_sel.xid = uri;
+	doc_sel.filename.s = "index";
+	doc_sel.filename.len = 5;
 
 	/* need the whole document so the node selector is NULL */
 	/* don't know which is the authoritative server for the user
 	 * so send request to all in the list */
-	req.doc_sel= doc_sel;
-
-	xs= xs_list;
-	while(xs)
-	{
-		req.xcap_root= xs->addr;
-		req.port= xs->port;
-		doc= xcap_GetNewDoc(req, user, domain);
-		if(doc!=NULL)
+	req.doc_sel = doc_sel;
+
+	xs = xs_list;
+	while(xs) {
+		req.xcap_root = xs->addr;
+		req.port = xs->port;
+		doc = xcap_GetNewDoc(req, user, domain);
+		if(doc != NULL)
 			break;
 		xs = xs->next;
 	}
 
-	rules_doc->s= doc;
-	rules_doc->len= doc?strlen(doc):0;
-	
+	rules_doc->s = doc;
+	rules_doc->len = doc ? strlen(doc) : 0;
+
 	return 0;
 
 error:

+ 5 - 4
src/modules/presence_xml/xcap_auth.h

@@ -35,11 +35,12 @@
 #include "../presence/subscribe.h"
 #include "../xcap_client/xcap_callbacks.h"
 
-int pres_watcher_allowed(subs_t* subs);
+int pres_watcher_allowed(subs_t *subs);
 
-xmlNodePtr get_rule_node(subs_t* subs, xmlDocPtr xcap_tree );
-int get_rules_doc(str* user, str* domain, str *file_uri, int type, str** rules_doc);
-int pres_get_rules_doc(str* user, str* domain, str** rules_doc);
+xmlNodePtr get_rule_node(subs_t *subs, xmlDocPtr xcap_tree);
+int get_rules_doc(
+		str *user, str *domain, str *file_uri, int type, str **rules_doc);
+int pres_get_rules_doc(str *user, str *domain, str **rules_doc);
 int pres_get_pidf_doc(str *user, str *domain, str *file_uri, str **rules_doc);
 
 #endif