فهرست منبع

pua_reginfo: clang format code files

Daniel-Constantin Mierla 3 سال پیش
والد
کامیت
e2df1d91de

+ 210 - 165
src/modules/pua_reginfo/notify.c

@@ -16,8 +16,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -66,23 +66,24 @@
 
 extern sruid_t _reginfo_sruid;
 
-int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str callid,
-		int cseq, int expires, int event, str contact_uri) {
+int process_contact(udomain_t *domain, urecord_t **ul_record, str aor,
+		str callid, int cseq, int expires, int event, str contact_uri)
+{
 	str no_str = {0, 0};
 	static str no_ua = str_init("n/a");
 	static ucontact_info_t ci;
-	ucontact_t * ul_contact;
+	ucontact_t *ul_contact;
 	int ret;
 
 	pua_reginfo_update_self_op(1);
-	if (*ul_record == NULL) {
+	if(*ul_record == NULL) {
 		switch(event) {
 			case EVENT_REGISTERED:
 			case EVENT_CREATED:
 			case EVENT_REFRESHED:
 				/* In case, no record exists and new one should be created,
-				   create a new entry for this user in the usrloc-DB */
-				if (ul.insert_urecord(domain, &aor, ul_record) < 0) {
+				 * create a new entry for this user in the usrloc-DB */
+				if(ul.insert_urecord(domain, &aor, ul_record) < 0) {
 					LM_ERR("failed to insert new user-record\n");
 					ret = RESULT_ERROR;
 					goto done;
@@ -90,14 +91,14 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
 				break;
 			default:
 				/* No entry in usrloc and the contact is expired, deleted, unregistered, whatever:
-                                   We do not need to do anything. */
+				 * We do not need to do anything. */
 				ret = RESULT_NO_CONTACTS;
 				goto done;
 		}
 	}
-	
+
 	/* Make sure, no crap is in the structure: */
-	memset( &ci, 0, sizeof(ucontact_info_t));	
+	memset(&ci, 0, sizeof(ucontact_info_t));
 	/* Get callid of the message */
 	ci.callid = &callid;
 	/* Get CSeq number of the message */
@@ -118,23 +119,26 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
 	}
 
 	/* Now we start looking for the contact: */
-	if (((*ul_record)->contacts == 0)
-		|| (ul.get_ucontact(*ul_record, &contact_uri, &callid, &no_str, cseq+1, &ul_contact) != 0)) {
-		if (ul.insert_ucontact(*ul_record, &contact_uri, &ci, &ul_contact) < 0) {
+	if(((*ul_record)->contacts == 0)
+			|| (ul.get_ucontact(*ul_record, &contact_uri, &callid, &no_str,
+						cseq + 1, &ul_contact)
+					!= 0)) {
+		if(ul.insert_ucontact(*ul_record, &contact_uri, &ci, &ul_contact) < 0) {
 			LM_ERR("failed to insert new contact\n");
 			ret = RESULT_ERROR;
 			goto done;
 		}
 	} else {
-		if (ul.update_ucontact(*ul_record, ul_contact, &ci) < 0) {
+		if(ul.update_ucontact(*ul_record, ul_contact, &ci) < 0) {
 			LM_ERR("failed to update contact\n");
 			ret = RESULT_ERROR;
 			goto done;
 		}
 	}
 	ul_contact = (*ul_record)->contacts;
-	while (ul_contact) {
-		if (VALID_CONTACT(ul_contact, time(0))) return RESULT_CONTACTS_FOUND;
+	while(ul_contact) {
+		if(VALID_CONTACT(ul_contact, time(0)))
+			return RESULT_CONTACTS_FOUND;
 		ul_contact = ul_contact->next;
 	}
 
@@ -144,40 +148,45 @@ done:
 	return ret;
 }
 
-xmlNodePtr xmlGetNodeByName(xmlNodePtr parent, const char *name) {
+xmlNodePtr xmlGetNodeByName(xmlNodePtr parent, const char *name)
+{
 	xmlNodePtr cur = parent;
 	xmlNodePtr match = NULL;
-	while (cur) {
-		if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0)
+	while(cur) {
+		if(xmlStrcasecmp(cur->name, (unsigned char *)name) == 0)
 			return cur;
 		match = xmlGetNodeByName(cur->children, name);
-		if (match)
+		if(match)
 			return match;
 		cur = cur->next;
 	}
 	return NULL;
 }
 
-char * xmlGetAttrContentByName(xmlNodePtr node, const char *name) {
+char *xmlGetAttrContentByName(xmlNodePtr node, const char *name)
+{
 	xmlAttrPtr attr = node->properties;
-	while (attr) {
-		if (xmlStrcasecmp(attr->name, (unsigned char*)name) == 0)
-			return (char*)xmlNodeGetContent(attr->children);
+	while(attr) {
+		if(xmlStrcasecmp(attr->name, (unsigned char *)name) == 0)
+			return (char *)xmlNodeGetContent(attr->children);
 		attr = attr->next;
 	}
 	return NULL;
 }
 
-int reginfo_parse_state(char * s) {
-	if (s == NULL) {
+int reginfo_parse_state(char *s)
+{
+	if(s == NULL) {
 		return STATE_UNKNOWN;
 	}
-	switch (strlen(s)) {
+	switch(strlen(s)) {
 		case 6:
-			if (strncmp(s, "active", 6) ==  0) return STATE_ACTIVE;
+			if(strncmp(s, "active", 6) == 0)
+				return STATE_ACTIVE;
 			break;
 		case 10:
-			if (strncmp(s, "terminated", 10) ==  0) return STATE_TERMINATED;
+			if(strncmp(s, "terminated", 10) == 0)
+				return STATE_TERMINATED;
 			break;
 		default:
 			LM_ERR("Unknown State %s\n", s);
@@ -187,24 +196,31 @@ int reginfo_parse_state(char * s) {
 	return STATE_UNKNOWN;
 }
 
-int reginfo_parse_event(char * s) {
-	if (s == NULL) {
+int reginfo_parse_event(char *s)
+{
+	if(s == NULL) {
 		return EVENT_UNKNOWN;
 	}
-	switch (strlen(s)) {
+	switch(strlen(s)) {
 		case 7:
-			if (strncmp(s, "created", 7) ==  0) return EVENT_CREATED;
-			if (strncmp(s, "expired", 7) ==  0) return EVENT_EXPIRED;
+			if(strncmp(s, "created", 7) == 0)
+				return EVENT_CREATED;
+			if(strncmp(s, "expired", 7) == 0)
+				return EVENT_EXPIRED;
 			break;
 		case 9:
-			if (strncmp(s, "refreshed", 9) ==  0) return EVENT_CREATED;
+			if(strncmp(s, "refreshed", 9) == 0)
+				return EVENT_CREATED;
 			break;
 		case 10:
-			if (strncmp(s, "registered", 10) ==  0) return EVENT_REGISTERED;
-			if (strncmp(s, "terminated", 10) ==  0) return EVENT_TERMINATED;
+			if(strncmp(s, "registered", 10) == 0)
+				return EVENT_REGISTERED;
+			if(strncmp(s, "terminated", 10) == 0)
+				return EVENT_TERMINATED;
 			break;
 		case 12:
-			if (strncmp(s, "unregistered", 12) ==  0) return EVENT_UNREGISTERED;
+			if(strncmp(s, "unregistered", 12) == 0)
+				return EVENT_UNREGISTERED;
 			break;
 		default:
 			LM_ERR("Unknown Event %s\n", s);
@@ -214,9 +230,11 @@ int reginfo_parse_event(char * s) {
 	return EVENT_UNKNOWN;
 }
 
-int process_body(str notify_body, udomain_t * domain) {
-	xmlDocPtr doc= NULL;
-	xmlNodePtr doc_root = NULL, registrations = NULL, contacts = NULL, uris = NULL, params = NULL;
+int process_body(str notify_body, udomain_t *domain)
+{
+	xmlDocPtr doc = NULL;
+	xmlNodePtr doc_root = NULL, registrations = NULL, contacts = NULL,
+			   uris = NULL, params = NULL;
 	char uri[MAX_URI_SIZE];
 	str aor_key = {0, 0};
 	str aor = {0, 0};
@@ -225,15 +243,15 @@ int process_body(str notify_body, udomain_t * domain) {
 	str contact_uri = {0, 0};
 	str contact_params = {0, 0};
 	str param = {0, 0};
-	str received = {0,0};
-	str path = {0,0};
+	str received = {0, 0};
+	str path = {0, 0};
 	str user_agent = {0, 0};
 	int state, event, expires, result, final_result = RESULT_ERROR;
-	char * expires_char,  * cseq_char;
+	char *expires_char, *cseq_char;
 	int cseq = 0;
 	int len;
-	urecord_t * ul_record = NULL;
-	ucontact_t * ul_contact = NULL;
+	urecord_t *ul_record = NULL;
+	ucontact_t *ul_contact = NULL;
 	struct sip_uri parsed_aor;
 
 	/* Temporary */
@@ -241,9 +259,9 @@ int process_body(str notify_body, udomain_t * domain) {
 
 	uri[0] = '\0';
 	doc = xmlParseMemory(notify_body.s, notify_body.len);
-	if(doc== NULL)  {
+	if(doc == NULL) {
 		LM_ERR("Error while parsing the xml body message, Body is:\n%.*s\n",
-			notify_body.len, notify_body.s);
+				notify_body.len, notify_body.s);
 		return -1;
 	}
 	doc_root = xmlGetNodeByName(doc->children, "reginfo");
@@ -252,136 +270,140 @@ int process_body(str notify_body, udomain_t * domain) {
 		goto error;
 	}
 	registrations = doc_root->children;
-	while (registrations) {
+	while(registrations) {
 		/* Only process registration sub-items */
-		if (xmlStrcasecmp(registrations->name, BAD_CAST "registration") != 0)
+		if(xmlStrcasecmp(registrations->name, BAD_CAST "registration") != 0)
 			goto next_registration;
-		state = reginfo_parse_state(xmlGetAttrContentByName(registrations, "state"));
-		if (state == STATE_UNKNOWN) {
-			LM_ERR("No state for this contact!\n");		
+		state = reginfo_parse_state(
+				xmlGetAttrContentByName(registrations, "state"));
+		if(state == STATE_UNKNOWN) {
+			LM_ERR("No state for this contact!\n");
 			goto next_registration;
 		}
 		aor.s = xmlGetAttrContentByName(registrations, "aor");
-		if (aor.s == NULL) {
-			LM_ERR("No AOR for this contact!\n");		
+		if(aor.s == NULL) {
+			LM_ERR("No AOR for this contact!\n");
 			goto next_registration;
 		}
 		aor.len = strlen(aor.s);
 		LM_DBG("AOR %.*s has state \"%d\"\n", aor.len, aor.s, state);
 
 		/* Get username part of the AOR, search for @ in the AOR. */
-		if (parse_uri(aor.s, aor.len, &parsed_aor) < 0) {
-			LM_ERR("failed to parse Address of Record (%.*s)\n",
-				aor.len, aor.s);
+		if(parse_uri(aor.s, aor.len, &parsed_aor) < 0) {
+			LM_ERR("failed to parse Address of Record (%.*s)\n", aor.len,
+					aor.s);
 			goto next_registration;
 		}
 
-		if (reginfo_use_domain) {
+		if(reginfo_use_domain) {
 			aor_key.s = uri;
 		} else {
 			aor_key.s = parsed_aor.user.s;
 		}
 		aor_key.len = strlen(aor_key.s);
-		/* Now let's lock that domain for this AOR: */		
+		/* Now let's lock that domain for this AOR: */
 		ul.lock_udomain(domain, &aor_key);
 		/* and retrieve the user-record for this user: */
 		result = ul.get_urecord(domain, &aor_key, &ul_record);
-		if (result < 0) {
+		if(result < 0) {
 			ul.unlock_udomain(domain, &aor_key);
-			LM_ERR("failed to query usrloc (AOR %.*s)\n",
-				aor_key.len, aor_key.s);
+			LM_ERR("failed to query usrloc (AOR %.*s)\n", aor_key.len,
+					aor_key.s);
 			goto next_registration;
 		}
 		/* If no contacts found, then set the ul_record to NULL */
-		if (result != 0) ul_record = NULL;
+		if(result != 0)
+			ul_record = NULL;
 
 		/* If the state is terminated, we just can delete all bindings */
-		if (state == STATE_TERMINATED) {
-			if (ul_record) {
+		if(state == STATE_TERMINATED) {
+			if(ul_record) {
 				ul_contact = ul_record->contacts;
 				while(ul_contact) {
-					if (mem_only) {
+					if(mem_only) {
 						ul_contact->flags |= FL_MEM;
 					} else {
 						ul_contact->flags &= ~FL_MEM;
 					}
 					ul_contact = ul_contact->next;
 				}
-				
-				if (ul.delete_urecord(domain, &aor_key, ul_record) < 0) {
+
+				if(ul.delete_urecord(domain, &aor_key, ul_record) < 0) {
 					LM_ERR("failed to remove record from usrloc\n");
-				} 
+				}
 
 				/* Record deleted, and should not be used anymore */
 				ul_record = NULL;
-				
-				
+
+
 				/* If already a registration with contacts was found, then keep that result.
 				   otherwise the result is now "No contacts found" */
-				if (final_result != RESULT_CONTACTS_FOUND) final_result = RESULT_NO_CONTACTS;
+				if(final_result != RESULT_CONTACTS_FOUND)
+					final_result = RESULT_NO_CONTACTS;
 			}
-		/* Otherwise, process the content */
+			/* Otherwise, process the content */
 		} else {
 			/* Now lets process the Contact's from this Registration: */
 			contacts = registrations->children;
-			while (contacts) {
-				if (xmlStrcasecmp(contacts->name, BAD_CAST "contact") != 0)
+			while(contacts) {
+				if(xmlStrcasecmp(contacts->name, BAD_CAST "contact") != 0)
 					goto next_contact;
 				callid.len = 0;
 				callid.s = xmlGetAttrContentByName(contacts, "callid");
 				// If no CallID present, try the "id"-field instead:
-				if (callid.s == NULL)
+				if(callid.s == NULL)
 					callid.s = xmlGetAttrContentByName(contacts, "id");
 				callid.len = strlen(callid.s);
 				LM_DBG("Got Call-ID \"%.*s\"\n", callid.len, callid.s);
 				received.s = xmlGetAttrContentByName(contacts, "received");
-				if (received.s == NULL) {
-                    LM_DBG("No received for this contact!\n");
+				if(received.s == NULL) {
+					LM_DBG("No received for this contact!\n");
 					received.len = 0;
-                } else {
+				} else {
 					received.len = strlen(received.s);
 				}
 
-				path.s = xmlGetAttrContentByName(contacts, "path");	
-				if (path.s == NULL) {
-                    LM_DBG("No path for this contact!\n");
+				path.s = xmlGetAttrContentByName(contacts, "path");
+				if(path.s == NULL) {
+					LM_DBG("No path for this contact!\n");
 					path.len = 0;
-                } else {
+				} else {
 					path.len = strlen(path.s);
 				}
 
 				user_agent.s = xmlGetAttrContentByName(contacts, "user_agent");
-				if (user_agent.s == NULL) {
-                    LM_DBG("No user_agent for this contact!\n");
+				if(user_agent.s == NULL) {
+					LM_DBG("No user_agent for this contact!\n");
 					user_agent.len = 0;
-                } else {
+				} else {
 					user_agent.len = strlen(user_agent.s);
 				}
-				event = reginfo_parse_event(xmlGetAttrContentByName(contacts, "event"));
-				if (event == EVENT_UNKNOWN) {
-					LM_ERR("No event for this contact!\n");		
+				event = reginfo_parse_event(
+						xmlGetAttrContentByName(contacts, "event"));
+				if(event == EVENT_UNKNOWN) {
+					LM_ERR("No event for this contact!\n");
 					goto next_contact;
 				}
 				expires_char = xmlGetAttrContentByName(contacts, "expires");
-				if (expires_char == NULL) {
-					LM_ERR("No expires for this contact!\n");		
+				if(expires_char == NULL) {
+					LM_ERR("No expires for this contact!\n");
 					goto next_contact;
 				}
 				expires = atoi(expires_char);
-				if (expires < 0) {
-					LM_ERR("No valid expires for this contact!\n");		
+				if(expires < 0) {
+					LM_ERR("No valid expires for this contact!\n");
 					goto next_contact;
 				}
-				LM_DBG("%.*s: Event \"%d\", expires %d\n",
-					callid.len, callid.s, event, expires);
+				LM_DBG("%.*s: Event \"%d\", expires %d\n", callid.len, callid.s,
+						event, expires);
 
 				cseq_char = xmlGetAttrContentByName(contacts, "cseq");
-				if (cseq_char == NULL) {
-					LM_DBG("No cseq for this contact!\n");		
+				if(cseq_char == NULL) {
+					LM_DBG("No cseq for this contact!\n");
 				} else {
 					cseq = atoi(cseq_char);
-					if (cseq < 0) {
-						LM_WARN("No valid cseq for this contact!\n");		
+					if(cseq < 0) {
+						LM_WARN("No valid cseq for this contact!\n");
 					}
 				}
 
@@ -391,122 +413,145 @@ int process_body(str notify_body, udomain_t * domain) {
 				params = contacts->children;
 				contact_params.len = 0;
 				len = 0;
-				while (params) {
-					if (xmlStrcasecmp(params->name, BAD_CAST "unknown-param") != 0)
+				while(params) {
+					if(xmlStrcasecmp(params->name, BAD_CAST "unknown-param")
+							!= 0)
 						goto next_param;
-					len += 1 /* ; */ + strlen(xmlGetAttrContentByName(params, "name"));
-					param.s = (char*)xmlNodeGetContent(params);
+					len += 1 /* ; */
+						   + strlen(xmlGetAttrContentByName(params, "name"));
+					param.s = (char *)xmlNodeGetContent(params);
 					param.len = strlen(param.s);
-					if (param.len > 0)
+					if(param.len > 0)
 						len += 1 /* = */ + param.len;
-next_param:
+				next_param:
 					params = params->next;
 				}
 				LM_DBG("Calculated length for params: %i\n", len);
 
-				if (len > 0) {
+				if(len > 0) {
 					len += 1;
-					if (contact_params.s) pkg_free(contact_params.s);
+					if(contact_params.s)
+						pkg_free(contact_params.s);
 					contact_params.s = pkg_malloc(len);
 					params = contacts->children;
 					contact_params.len = 0;
-					while (params) {
-						if (xmlStrcasecmp(params->name, BAD_CAST "unknown-param") != 0)
+					while(params) {
+						if(xmlStrcasecmp(params->name, BAD_CAST "unknown-param")
+								!= 0)
 							goto next_param2;
-						contact_params.len += snprintf(contact_params.s + contact_params.len, len - contact_params.len, ";%s", xmlGetAttrContentByName(params, "name"));
-						param.s = (char*)xmlNodeGetContent(params);
+						contact_params.len += snprintf(
+								contact_params.s + contact_params.len,
+								len - contact_params.len, ";%s",
+								xmlGetAttrContentByName(params, "name"));
+						param.s = (char *)xmlNodeGetContent(params);
 						param.len = strlen(param.s);
-						if (param.len > 0)
-							contact_params.len += snprintf(contact_params.s + contact_params.len, len - contact_params.len, "=%.*s", param.len, param.s);
+						if(param.len > 0)
+							contact_params.len += snprintf(
+									contact_params.s + contact_params.len,
+									len - contact_params.len, "=%.*s",
+									param.len, param.s);
+
+						LM_DBG("Contact params are: %.*s\n", contact_params.len,
+								contact_params.s);
 
-						LM_DBG("Contact params are: %.*s\n", contact_params.len, contact_params.s);
-			
-next_param2:
+					next_param2:
 						params = params->next;
 					}
-					LM_DBG("Contact params are: %.*s\n", contact_params.len, contact_params.s);
+					LM_DBG("Contact params are: %.*s\n", contact_params.len,
+							contact_params.s);
 				}
 
 				/* Now lets process the URI's from this Contact: */
 				uris = contacts->children;
-				while (uris) {
-					if (xmlStrcasecmp(uris->name, BAD_CAST "uri") != 0)
+				while(uris) {
+					if(xmlStrcasecmp(uris->name, BAD_CAST "uri") != 0)
 						goto next_uri;
-					contact_uri.s = (char*)xmlNodeGetContent(uris);	
-					if (contact_uri.s == NULL) {
-						LM_ERR("No URI for this contact!\n");		
+					contact_uri.s = (char *)xmlNodeGetContent(uris);
+					if(contact_uri.s == NULL) {
+						LM_ERR("No URI for this contact!\n");
 						goto next_registration;
 					}
 					contact_uri.len = strlen(contact_uri.s);
-					if (contact_params.len > 0) {
-						if (contact.s) pkg_free(contact.s);
-						contact.s = (char*)pkg_malloc(contact_uri.len + contact_params.len + 1);
-						contact.len = snprintf(contact.s, contact_uri.len + contact_params.len + 1, "%.*s%.*s", contact_uri.len, contact_uri.s, contact_params.len, contact_params.s);
-						LM_DBG("Contact: %.*s\n",
-							contact.len, contact.s);
+					if(contact_params.len > 0) {
+						if(contact.s)
+							pkg_free(contact.s);
+						contact.s = (char *)pkg_malloc(
+								contact_uri.len + contact_params.len + 1);
+						contact.len = snprintf(contact.s,
+								contact_uri.len + contact_params.len + 1,
+								"%.*s%.*s", contact_uri.len, contact_uri.s,
+								contact_params.len, contact_params.s);
+						LM_DBG("Contact: %.*s\n", contact.len, contact.s);
 
 						/* Add to Usrloc: */
-						result = process_contact(domain, &ul_record, aor_key, callid, cseq, expires, event, contact);
+						result = process_contact(domain, &ul_record, aor_key,
+								callid, cseq, expires, event, contact);
 					} else {
-						LM_DBG("Contact: %.*s\n",
-							contact_uri.len, contact_uri.s);
+						LM_DBG("Contact: %.*s\n", contact_uri.len,
+								contact_uri.s);
 
 						/* Add to Usrloc: */
-						result = process_contact(domain, &ul_record, aor_key, callid, cseq, expires, event, contact_uri);
+						result = process_contact(domain, &ul_record, aor_key,
+								callid, cseq, expires, event, contact_uri);
 					}
-				
+
 					/* Process the result */
-					if (final_result != RESULT_CONTACTS_FOUND) final_result = result;
-next_uri:
+					if(final_result != RESULT_CONTACTS_FOUND)
+						final_result = result;
+				next_uri:
 					uris = uris->next;
 				}
-next_contact:
+			next_contact:
 				contacts = contacts->next;
 			}
 		}
-next_registration:
-		if (ul_record) ul.release_urecord(ul_record);
+	next_registration:
+		if(ul_record)
+			ul.release_urecord(ul_record);
 		/* Unlock the domain for this AOR: */
-		if (aor_key.len > 0)
+		if(aor_key.len > 0)
 			ul.unlock_udomain(domain, &aor_key);
 
 		registrations = registrations->next;
 	}
 error:
-	if (contact.s) pkg_free(contact.s);
-	if (contact_params.s) pkg_free(contact_params.s);
+	if(contact.s)
+		pkg_free(contact.s);
+	if(contact_params.s)
+		pkg_free(contact_params.s);
 	/* Free the XML-Document */
 
-    	if(doc) xmlFreeDoc(doc);
+	if(doc)
+		xmlFreeDoc(doc);
 	return final_result;
 }
 
-int reginfo_handle_notify(struct sip_msg* msg, char* domain, char* s2) {
- 	str body;
+int reginfo_handle_notify(struct sip_msg *msg, char *domain, char *s2)
+{
+	str body;
 	int result = 1;
 
-  	/* If not done yet, parse the whole message now: */
-  	if (parse_headers(msg, HDR_EOH_F, 0) == -1) {
-  		LM_ERR("Error parsing headers\n");
-  		return -1;
-  	}
-	if (get_content_length(msg) == 0) {
-   		LM_DBG("Content length = 0\n");
+	/* If not done yet, parse the whole message now: */
+	if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
+		LM_ERR("Error parsing headers\n");
+		return -1;
+	}
+	if(get_content_length(msg) == 0) {
+		LM_DBG("Content length = 0\n");
 		/* No Body? Then there is no published information available, which is ok. */
-   		return 1;
-   	} else {
-   		body.s=get_body(msg);
-   		if (body.s== NULL) {
-   			LM_ERR("cannot extract body from msg\n");
-   			return -1;
-   		}
-   		body.len = get_content_length(msg);
-   	}
+		return 1;
+	} else {
+		body.s = get_body(msg);
+		if(body.s == NULL) {
+			LM_ERR("cannot extract body from msg\n");
+			return -1;
+		}
+		body.len = get_content_length(msg);
+	}
 
 	LM_DBG("Body is %.*s\n", body.len, body.s);
-	
-	result = process_body(body, (udomain_t*)domain);
+
+	result = process_body(body, (udomain_t *)domain);
 
 	return result;
 }
-

+ 3 - 3
src/modules/pua_reginfo/notify.h

@@ -16,8 +16,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -26,6 +26,6 @@
 
 #include "../../core/parser/msg_parser.h"
 
-int reginfo_handle_notify(struct sip_msg*, char*, char*);
+int reginfo_handle_notify(struct sip_msg *, char *, char *);
 
 #endif

+ 50 - 48
src/modules/pua_reginfo/pua_reginfo.c

@@ -16,8 +16,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -35,7 +35,7 @@
 MODULE_VERSION
 
 usrloc_api_t ul; /*!< Structure containing pointers to usrloc functions*/
-pua_api_t pua; /*!< Structure containing pointers to PUA functions*/
+pua_api_t pua;	 /*!< Structure containing pointers to PUA functions*/
 
 /* Default domain to be added, if none provided. */
 str default_domain = {NULL, 0};
@@ -49,38 +49,41 @@ sruid_t _reginfo_sruid;
 int reginfo_use_domain = 0;
 
 /** Fixup functions */
-static int domain_fixup(void** param, int param_no);
+static int domain_fixup(void **param, int param_no);
 
 /** module functions */
 static int mod_init(void);
 
 /* Commands */
 static cmd_export_t cmds[] = {
-	{"reginfo_subscribe", (cmd_function)reginfo_subscribe, 1, fixup_subscribe, 0, REQUEST_ROUTE|ONREPLY_ROUTE}, 	
-	{"reginfo_subscribe", (cmd_function)reginfo_subscribe2, 2, fixup_subscribe, 0, REQUEST_ROUTE|ONREPLY_ROUTE}, 	
-	{"reginfo_handle_notify", (cmd_function)reginfo_handle_notify, 1, domain_fixup, 0, REQUEST_ROUTE}, 	
-	{0, 0, 0, 0, 0, 0} 
+	{"reginfo_subscribe", (cmd_function)reginfo_subscribe, 1,
+			fixup_subscribe, 0, REQUEST_ROUTE | ONREPLY_ROUTE},
+	{"reginfo_subscribe", (cmd_function)reginfo_subscribe2, 2,
+			fixup_subscribe, 0, REQUEST_ROUTE | ONREPLY_ROUTE},
+	{"reginfo_handle_notify", (cmd_function)reginfo_handle_notify, 1,
+			domain_fixup, 0, REQUEST_ROUTE},
+	{0, 0, 0, 0, 0, 0}
 };
 
-static param_export_t params[]={
- 	{"default_domain", PARAM_STR, &default_domain},
+static param_export_t params[] = {
+	{"default_domain", PARAM_STR, &default_domain},
 	{"outbound_proxy", PARAM_STR, &outbound_proxy},
 	{"server_address", PARAM_STR, &server_address},
 	{"publish_reginfo", INT_PARAM, &publish_reginfo},
 	{0, 0, 0}
 };
 
-struct module_exports exports= {
-	"pua_reginfo",		/* module name */
-	DEFAULT_DLFLAGS,	/* dlopen flags */
-	cmds,				/* exported functions */
-	params,				/* exported parameters */
-	0,					/* RPC method exports */
-	0,					/* exported pseudo-variables */
-	0,					/* response handling function */
-	mod_init,			/* module initialization function */
-	0,					/* per-child init function */
-	0					/* module destroy function */
+struct module_exports exports = {
+	"pua_reginfo",	 /* module name */
+	DEFAULT_DLFLAGS, /* dlopen flags */
+	cmds,			 /* exported functions */
+	params,			 /* exported parameters */
+	0,				 /* RPC method exports */
+	0,				 /* exported pseudo-variables */
+	0,				 /* response handling function */
+	mod_init,		 /* module initialization function */
+	0,				 /* per-child init function */
+	0				 /* module destroy function */
 };
 
 /**
@@ -91,29 +94,29 @@ static int mod_init(void)
 	bind_pua_t bind_pua;
 	bind_usrloc_t bind_usrloc;
 
-	if (publish_reginfo == 1) {
-    /* Verify the default domain: */
-    if(!default_domain.s || default_domain.len<=0) {
-      LM_ERR("default domain parameter not set\n");
-      return -1;
-    }
+	if(publish_reginfo == 1) {
+		/* Verify the default domain: */
+		if(!default_domain.s || default_domain.len <= 0) {
+			LM_ERR("default domain parameter not set\n");
+			return -1;
+		}
 	}
 
-	if(!server_address.s || server_address.len<=0) {
+	if(!server_address.s || server_address.len <= 0) {
 		LM_ERR("server_address parameter not set\n");
 		return -1;
 	}
 
-	if(!outbound_proxy.s || outbound_proxy.len<=0)
+	if(!outbound_proxy.s || outbound_proxy.len <= 0)
 		LM_DBG("No outbound proxy set\n");
-        
+
 	/* Bind to PUA: */
-	bind_pua= (bind_pua_t)find_export("bind_pua", 1,0);
-	if (!bind_pua) {
+	bind_pua = (bind_pua_t)find_export("bind_pua", 1, 0);
+	if(!bind_pua) {
 		LM_ERR("Can't bind pua\n");
 		return -1;
-	}	
-	if (bind_pua(&pua) < 0) {
+	}
+	if(bind_pua(&pua) < 0) {
 		LM_ERR("Can't bind pua\n");
 		return -1;
 	}
@@ -129,38 +132,38 @@ static int mod_init(void)
 
 	/* Bind to URSLOC: */
 	bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
-	if (!bind_usrloc) {
+	if(!bind_usrloc) {
 		LM_ERR("Can't bind usrloc\n");
 		return -1;
 	}
-	if (bind_usrloc(&ul) < 0) {
+	if(bind_usrloc(&ul) < 0) {
 		LM_ERR("Can't bind usrloc\n");
 		return -1;
 	}
-	if (publish_reginfo == 1) {
+	if(publish_reginfo == 1) {
 		if(ul.register_ulcb == NULL) {
 			LM_ERR("Could not import ul_register_ulcb\n");
 			return -1;
 		}
-		if(ul.register_ulcb(UL_CONTACT_INSERT, reginfo_usrloc_cb , 0)< 0) {
+		if(ul.register_ulcb(UL_CONTACT_INSERT, reginfo_usrloc_cb, 0) < 0) {
 			LM_ERR("can not register callback for insert\n");
 			return -1;
 		}
-		if(ul.register_ulcb(UL_CONTACT_EXPIRE, reginfo_usrloc_cb, 0)< 0) {	
+		if(ul.register_ulcb(UL_CONTACT_EXPIRE, reginfo_usrloc_cb, 0) < 0) {
 			LM_ERR("can not register callback for expire\n");
 			return -1;
 		}
-		if(ul.register_ulcb(UL_CONTACT_UPDATE, reginfo_usrloc_cb, 0)< 0) {	
+		if(ul.register_ulcb(UL_CONTACT_UPDATE, reginfo_usrloc_cb, 0) < 0) {
 			LM_ERR("can not register callback for update\n");
 			return -1;
 		}
-		if(ul.register_ulcb(UL_CONTACT_DELETE, reginfo_usrloc_cb, 0)< 0) {	
+		if(ul.register_ulcb(UL_CONTACT_DELETE, reginfo_usrloc_cb, 0) < 0) {
 			LM_ERR("can not register callback for delete\n");
 			return -1;
 		}
 	}
 
-	if(sruid_init(&_reginfo_sruid, (char)'-', "regi", SRUID_INC)<0)
+	if(sruid_init(&_reginfo_sruid, (char)'-', "regi", SRUID_INC) < 0)
 		return -1;
 
 	/*
@@ -174,18 +177,17 @@ static int mod_init(void)
 /*! \brief
  * Convert char* parameter to udomain_t* pointer
  */
-static int domain_fixup(void** param, int param_no)
+static int domain_fixup(void **param, int param_no)
 {
-	udomain_t* d;
+	udomain_t *d;
 
-	if (param_no == 1) {
-		if (ul.register_udomain((char*)*param, &d) < 0) {
+	if(param_no == 1) {
+		if(ul.register_udomain((char *)*param, &d) < 0) {
 			LM_ERR("failed to register domain\n");
 			return E_UNSPEC;
 		}
 
-		*param = (void*)d;
+		*param = (void *)d;
 	}
 	return 0;
 }
-

+ 1 - 1
src/modules/pua_reginfo/pua_reginfo.h

@@ -32,7 +32,7 @@ extern str outbound_proxy;
 extern str server_address;
 
 extern usrloc_api_t ul; /*!< Structure containing pointers to usrloc functions*/
-extern pua_api_t pua; /*!< Structure containing pointers to PUA functions*/
+extern pua_api_t pua;	/*!< Structure containing pointers to PUA functions*/
 
 extern int reginfo_use_domain;
 

+ 32 - 28
src/modules/pua_reginfo/subscribe.c

@@ -16,8 +16,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -28,13 +28,14 @@
 #include "../pua/pua.h"
 #include "pua_reginfo.h"
 
-int reginfo_subscribe_real(struct sip_msg* msg, pv_elem_t* uri, int expires) {
+int reginfo_subscribe_real(struct sip_msg *msg, pv_elem_t *uri, int expires)
+{
 	str uri_str = {0, 0};
 	char uri_buf[512];
 	int uri_buf_len = 512;
 	subs_info_t subs;
-	
-	if (pv_printf(msg, uri, uri_buf, &uri_buf_len) < 0) {
+
+	if(pv_printf(msg, uri, uri_buf, &uri_buf_len) < 0) {
 		LM_ERR("cannot print uri into the format\n");
 		return -1;
 	}
@@ -46,57 +47,60 @@ int reginfo_subscribe_real(struct sip_msg* msg, pv_elem_t* uri, int expires) {
 	memset(&subs, 0, sizeof(subs_info_t));
 
 	subs.remote_target = &uri_str;
-	subs.pres_uri= &uri_str;
-	subs.watcher_uri= &server_address;
+	subs.pres_uri = &uri_str;
+	subs.watcher_uri = &server_address;
 	subs.expires = expires;
 
-	subs.source_flag= REGINFO_SUBSCRIBE;
-	subs.event= REGINFO_EVENT;
-	subs.contact= &server_address;
-	
+	subs.source_flag = REGINFO_SUBSCRIBE;
+	subs.event = REGINFO_EVENT;
+	subs.contact = &server_address;
+
 	if(outbound_proxy.s && outbound_proxy.len)
-		subs.outbound_proxy= &outbound_proxy;
+		subs.outbound_proxy = &outbound_proxy;
 
-	subs.flag|= UPDATE_TYPE;
+	subs.flag |= UPDATE_TYPE;
 
-	if(pua.send_subscribe(&subs)< 0) {
+	if(pua.send_subscribe(&subs) < 0) {
 		LM_ERR("while sending subscribe\n");
-	}	
+	}
 
 	return 1;
 }
 
-int reginfo_subscribe(struct sip_msg* msg, char* uri, char* s2) {
-	return reginfo_subscribe_real(msg, (pv_elem_t*)uri, 3600);
+int reginfo_subscribe(struct sip_msg *msg, char *uri, char *s2)
+{
+	return reginfo_subscribe_real(msg, (pv_elem_t *)uri, 3600);
 }
 
-int reginfo_subscribe2(struct sip_msg* msg, char* uri, char* param2) {
+int reginfo_subscribe2(struct sip_msg *msg, char *uri, char *param2)
+{
 	int expires;
 	if(fixup_get_ivalue(msg, (gparam_p)param2, &expires) != 0) {
 		LM_ERR("No expires provided!\n");
 		return -1;
 	}
-	return reginfo_subscribe_real(msg, (pv_elem_t*)uri, expires);
+	return reginfo_subscribe_real(msg, (pv_elem_t *)uri, expires);
 }
 
-int fixup_subscribe(void** param, int param_no) {
+int fixup_subscribe(void **param, int param_no)
+{
 	pv_elem_t *model;
 	str s;
-	if (param_no == 1) {
+	if(param_no == 1) {
 		if(*param) {
-			s.s = (char*)(*param);
+			s.s = (char *)(*param);
 			s.len = strlen(s.s);
-			if(pv_parse_format(&s, &model)<0) {
-				LM_ERR("wrong format[%s]\n",(char*)(*param));
+			if(pv_parse_format(&s, &model) < 0) {
+				LM_ERR("wrong format[%s]\n", (char *)(*param));
 				return E_UNSPEC;
 			}
-			*param = (void*)model;
+			*param = (void *)model;
 			return 1;
 		}
 		LM_ERR("null format\n");
 		return E_UNSPEC;
-	} else if (param_no == 2) {
+	} else if(param_no == 2) {
 		return fixup_igp_igp(param, param_no);
-	} else return 1;
+	} else
+		return 1;
 }
-

+ 5 - 5
src/modules/pua_reginfo/subscribe.h

@@ -16,8 +16,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -26,8 +26,8 @@
 
 #include "../../core/parser/msg_parser.h"
 
-int reginfo_subscribe(struct sip_msg*, char*, char*);
-int reginfo_subscribe2(struct sip_msg*, char*, char*);
-int fixup_subscribe(void** param, int param_no);
+int reginfo_subscribe(struct sip_msg *, char *, char *);
+int reginfo_subscribe2(struct sip_msg *, char *, char *);
+int fixup_subscribe(void **param, int param_no);
 
 #endif

+ 106 - 70
src/modules/pua_reginfo/usrloc_cb.c

@@ -56,27 +56,28 @@ void pua_reginfo_update_self_op(int v)
 	_pua_reginfo_self_op = v;
 }
 
-str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
-	xmlDocPtr  doc = NULL;
+str *build_reginfo_full(urecord_t *record, str uri, ucontact_t *c, int type)
+{
+	xmlDocPtr doc = NULL;
 	xmlNodePtr root_node = NULL;
 	xmlNodePtr registration_node = NULL;
 	xmlNodePtr contact_node = NULL;
 	xmlNodePtr uri_node = NULL;
-	str * body= NULL;
-	ucontact_t * ptr;
+	str *body = NULL;
+	ucontact_t *ptr;
 	char buf[512];
 	int reg_active = 0;
 	time_t cur_time = time(0);
 
 	/* create the XML-Body */
 	doc = xmlNewDoc(BAD_CAST "1.0");
-	if(doc==0) {
+	if(doc == 0) {
 		LM_ERR("Unable to create XML-Doc\n");
 		return NULL;
 	}
 
 	root_node = xmlNewNode(NULL, BAD_CAST "reginfo");
-	if(root_node==0) {
+	if(root_node == 0) {
 		LM_ERR("Unable to create reginfo-XML-Element\n");
 		xmlFreeDoc(doc);
 		return NULL;
@@ -84,15 +85,17 @@ str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
 	/* This is our Root-Element: */
 	xmlDocSetRootElement(doc, root_node);
 
-	xmlNewProp(root_node, BAD_CAST "xmlns",	BAD_CAST "urn:ietf:params:xml:ns:reginfo");
+	xmlNewProp(root_node, BAD_CAST "xmlns",
+			BAD_CAST "urn:ietf:params:xml:ns:reginfo");
 
 	/* we set the version to 0 but it should be set to the correct value in the pua module */
 	xmlNewProp(root_node, BAD_CAST "version", BAD_CAST "0");
-	xmlNewProp(root_node, BAD_CAST "state", BAD_CAST "full" );
+	xmlNewProp(root_node, BAD_CAST "state", BAD_CAST "full");
 
 	/* Registration Node */
-	registration_node =xmlNewChild(root_node, NULL, BAD_CAST "registration", NULL) ;
-	if( registration_node ==NULL) {
+	registration_node =
+			xmlNewChild(root_node, NULL, BAD_CAST "registration", NULL);
+	if(registration_node == NULL) {
 		LM_ERR("while adding child\n");
 		goto error;
 	}
@@ -102,17 +105,18 @@ str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
 	snprintf(buf, sizeof(buf), "%p", record);
 	xmlNewProp(registration_node, BAD_CAST "id", BAD_CAST buf);
 
-	LM_DBG("Updated Contact %.*s[%.*s]\n", c->c.len, c->c.s,
-		c->ruid.len, c->ruid.s);
+	LM_DBG("Updated Contact %.*s[%.*s]\n", c->c.len, c->c.s, c->ruid.len,
+			c->ruid.s);
 
 	ptr = record->contacts;
-	while (ptr) {
-		if (VALID_CONTACT(ptr, cur_time)) {
-			LM_DBG("Contact %.*s[%.*s]\n", ptr->c.len, ptr->c.s,
-				ptr->ruid.len, ptr->ruid.s);
+	while(ptr) {
+		if(VALID_CONTACT(ptr, cur_time)) {
+			LM_DBG("Contact %.*s[%.*s]\n", ptr->c.len, ptr->c.s, ptr->ruid.len,
+					ptr->ruid.s);
 			/* Contact-Node */
-			contact_node =xmlNewChild(registration_node, NULL, BAD_CAST "contact", NULL) ;
-			if( contact_node ==NULL) {
+			contact_node = xmlNewChild(
+					registration_node, NULL, BAD_CAST "contact", NULL);
+			if(contact_node == NULL) {
 				LM_ERR("while adding child\n");
 				goto error;
 			}
@@ -120,32 +124,46 @@ str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
 			snprintf(buf, sizeof(buf), "%p", ptr);
 			xmlNewProp(contact_node, BAD_CAST "id", BAD_CAST buf);
 			/* Check, if this is the modified contact: */
-			if ((c->ruid.len == ptr->ruid.len) &&
-				!memcmp(c->ruid.s, ptr->ruid.s, c->ruid.len))
-			{
-				if ((type & UL_CONTACT_INSERT) || (type & UL_CONTACT_UPDATE)) {
+			if((c->ruid.len == ptr->ruid.len)
+					&& !memcmp(c->ruid.s, ptr->ruid.s, c->ruid.len)) {
+				if((type & UL_CONTACT_INSERT) || (type & UL_CONTACT_UPDATE)) {
 					reg_active = 1;
-					xmlNewProp(contact_node, BAD_CAST "state", BAD_CAST "active");
+					xmlNewProp(
+							contact_node, BAD_CAST "state", BAD_CAST "active");
 				} else
-					xmlNewProp(contact_node, BAD_CAST "state", BAD_CAST "terminated");
-				if (type & UL_CONTACT_INSERT) xmlNewProp(contact_node, BAD_CAST "event", BAD_CAST "created");
-				else if (type & UL_CONTACT_UPDATE) xmlNewProp(contact_node, BAD_CAST "event", BAD_CAST "refreshed");
-				else if (type & UL_CONTACT_EXPIRE) xmlNewProp(contact_node, BAD_CAST "event", BAD_CAST "expired");
-				else if (type & UL_CONTACT_DELETE) xmlNewProp(contact_node, BAD_CAST "event", BAD_CAST "unregistered");
-				else xmlNewProp(contact_node, BAD_CAST "event", BAD_CAST "unknown");
+					xmlNewProp(contact_node, BAD_CAST "state",
+							BAD_CAST "terminated");
+				if(type & UL_CONTACT_INSERT)
+					xmlNewProp(
+							contact_node, BAD_CAST "event", BAD_CAST "created");
+				else if(type & UL_CONTACT_UPDATE)
+					xmlNewProp(contact_node, BAD_CAST "event",
+							BAD_CAST "refreshed");
+				else if(type & UL_CONTACT_EXPIRE)
+					xmlNewProp(
+							contact_node, BAD_CAST "event", BAD_CAST "expired");
+				else if(type & UL_CONTACT_DELETE)
+					xmlNewProp(contact_node, BAD_CAST "event",
+							BAD_CAST "unregistered");
+				else
+					xmlNewProp(
+							contact_node, BAD_CAST "event", BAD_CAST "unknown");
 				memset(buf, 0, sizeof(buf));
-				snprintf(buf, sizeof(buf), "%i", (int)(ptr->expires-cur_time));
+				snprintf(
+						buf, sizeof(buf), "%i", (int)(ptr->expires - cur_time));
 				xmlNewProp(contact_node, BAD_CAST "expires", BAD_CAST buf);
 			} else {
 				reg_active = 1;
 				xmlNewProp(contact_node, BAD_CAST "state", BAD_CAST "active");
-				xmlNewProp(contact_node, BAD_CAST "event", BAD_CAST "registered");
+				xmlNewProp(
+						contact_node, BAD_CAST "event", BAD_CAST "registered");
 				memset(buf, 0, sizeof(buf));
-				snprintf(buf, sizeof(buf), "%i", (int)(ptr->expires-cur_time));
+				snprintf(
+						buf, sizeof(buf), "%i", (int)(ptr->expires - cur_time));
 				xmlNewProp(contact_node, BAD_CAST "expires", BAD_CAST buf);
 			}
-			if (ptr->q != Q_UNSPECIFIED) {
-				float q = (float)ptr->q/1000;
+			if(ptr->q != Q_UNSPECIFIED) {
+				float q = (float)ptr->q / 1000;
 				memset(buf, 0, sizeof(buf));
 				snprintf(buf, sizeof(buf), "%.3f", q);
 				xmlNewProp(contact_node, BAD_CAST "q", BAD_CAST buf);
@@ -162,8 +180,9 @@ str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
 
 			/* received Attribute */
 			memset(buf, 0, sizeof(buf));
-	                snprintf(buf, sizeof(buf), "%.*s", ptr->received.len, ptr->received.s);
-         	       	xmlNewProp(contact_node, BAD_CAST "received", BAD_CAST buf);
+			snprintf(buf, sizeof(buf), "%.*s", ptr->received.len,
+					ptr->received.s);
+			xmlNewProp(contact_node, BAD_CAST "received", BAD_CAST buf);
 
 			/* path Attribute */
 			memset(buf, 0, sizeof(buf));
@@ -172,13 +191,15 @@ str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
 
 			/* user_agent Attribute */
 			memset(buf, 0, sizeof(buf));
-			snprintf(buf, sizeof(buf), "%.*s", ptr->user_agent.len, ptr->user_agent.s);
+			snprintf(buf, sizeof(buf), "%.*s", ptr->user_agent.len,
+					ptr->user_agent.s);
 			xmlNewProp(contact_node, BAD_CAST "user_agent", BAD_CAST buf);
 
 			/* URI-Node */
 			memset(buf, 0, sizeof(buf));
 			snprintf(buf, sizeof(buf), "%.*s", ptr->c.len, ptr->c.s);
-			uri_node = xmlNewChild(contact_node, NULL, BAD_CAST "uri", BAD_CAST buf) ;
+			uri_node = xmlNewChild(
+					contact_node, NULL, BAD_CAST "uri", BAD_CAST buf);
 			if(uri_node == NULL) {
 				LM_ERR("while adding child\n");
 				goto error;
@@ -188,14 +209,14 @@ str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
 	}
 
 	/* add registration state (at least one active contact): */
-	if (reg_active==0)
+	if(reg_active == 0)
 		xmlNewProp(registration_node, BAD_CAST "state", BAD_CAST "terminated");
 	else
 		xmlNewProp(registration_node, BAD_CAST "state", BAD_CAST "active");
 
 
 	/* create the body */
-	body = (str*)pkg_malloc(sizeof(str));
+	body = (str *)pkg_malloc(sizeof(str));
 	if(body == NULL) {
 		LM_ERR("while allocating memory\n");
 		return NULL;
@@ -203,7 +224,8 @@ str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
 	memset(body, 0, sizeof(str));
 
 	/* Write the XML into the body */
-	xmlDocDumpFormatMemory(doc,(unsigned char**)(void*)&body->s,&body->len,1);
+	xmlDocDumpFormatMemory(
+			doc, (unsigned char **)(void *)&body->s, &body->len, 1);
 
 	/*free the document */
 	xmlFreeDoc(doc);
@@ -212,24 +234,27 @@ str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
 	return body;
 error:
 	if(body) {
-		if(body->s) xmlFree(body->s);
+		if(body->s)
+			xmlFree(body->s);
 		pkg_free(body);
 	}
-	if(doc) xmlFreeDoc(doc);
+	if(doc)
+		xmlFreeDoc(doc);
 	return NULL;
 }
 
-void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) {
-	str* body= NULL;
+void reginfo_usrloc_cb(ucontact_t *c, int type, void *param)
+{
+	str *body = NULL;
 	publ_info_t publ;
 	str content_type;
-	udomain_t * domain;
-	urecord_t * record = NULL;
+	udomain_t *domain;
+	urecord_t *record = NULL;
 	int res;
 	str uri = {NULL, 0};
 	str user = {NULL, 0};
 
-	char* at = NULL;
+	char *at = NULL;
 	char id_buf[512];
 	int id_buf_len;
 
@@ -243,11 +268,16 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) {
 	content_type.len = 23;
 
 	/* Debug Output: */
-	LM_DBG("AOR: %.*s (%.*s)\n", c->aor->len, c->aor->s, c->domain->len, c->domain->s);
-	if(type & UL_CONTACT_INSERT) LM_DBG("type= UL_CONTACT_INSERT\n");
-	else if(type & UL_CONTACT_UPDATE) LM_DBG("type= UL_CONTACT_UPDATE\n");
-	else if(type & UL_CONTACT_EXPIRE) LM_DBG("type= UL_CONTACT_EXPIRE\n");
-	else if(type & UL_CONTACT_DELETE) LM_DBG("type= UL_CONTACT_DELETE\n");
+	LM_DBG("AOR: %.*s (%.*s)\n", c->aor->len, c->aor->s, c->domain->len,
+			c->domain->s);
+	if(type & UL_CONTACT_INSERT)
+		LM_DBG("type= UL_CONTACT_INSERT\n");
+	else if(type & UL_CONTACT_UPDATE)
+		LM_DBG("type= UL_CONTACT_UPDATE\n");
+	else if(type & UL_CONTACT_EXPIRE)
+		LM_DBG("type= UL_CONTACT_EXPIRE\n");
+	else if(type & UL_CONTACT_DELETE)
+		LM_DBG("type= UL_CONTACT_DELETE\n");
 	else {
 		LM_ERR("Unknown Type %i\n", type);
 		return;
@@ -265,33 +295,37 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) {
 
 	/* Get the URecord for this AOR */
 	res = ul.get_urecord(domain, &user, &record);
-	if (res > 0) {
-		LM_ERR("' %.*s (%.*s)' Not found in usrloc\n", c->aor->len, c->aor->s, c->domain->len, c->domain->s);
+	if(res > 0) {
+		LM_ERR("' %.*s (%.*s)' Not found in usrloc\n", c->aor->len, c->aor->s,
+				c->domain->len, c->domain->s);
 		return;
 	}
 
 	/* Create AOR to be published */
 	/* Search for @ in the AOR. In case no domain was provided, we will add the "default domain" */
 	at = memchr(record->aor.s, '@', record->aor.len);
-	if (!at) {
+	if(!at) {
 		uri.len = record->aor.len + default_domain.len + 6;
-		uri.s = (char*)pkg_malloc(sizeof(char) * uri.len);
+		uri.s = (char *)pkg_malloc(sizeof(char) * uri.len);
 		if(uri.s == NULL) {
 			LM_ERR("Error allocating memory for URI!\n");
 			goto error;
 		}
-		if (record->aor.len > 0)
-			uri.len = snprintf(uri.s, uri.len, "sip:%.*s@%.*s", record->aor.len, record->aor.s, default_domain.len, default_domain.s);
+		if(record->aor.len > 0)
+			uri.len = snprintf(uri.s, uri.len, "sip:%.*s@%.*s", record->aor.len,
+					record->aor.s, default_domain.len, default_domain.s);
 		else
-			uri.len = snprintf(uri.s, uri.len, "sip:%.*s", default_domain.len, default_domain.s);
+			uri.len = snprintf(uri.s, uri.len, "sip:%.*s", default_domain.len,
+					default_domain.s);
 	} else {
 		uri.len = record->aor.len + 6;
-		uri.s = (char*)pkg_malloc(sizeof(char) * uri.len);
+		uri.s = (char *)pkg_malloc(sizeof(char) * uri.len);
 		if(uri.s == NULL) {
 			LM_ERR("Error allocating memory for URI!\n");
 			goto error;
 		}
-		uri.len = snprintf(uri.s, uri.len, "sip:%.*s", record->aor.len, record->aor.s);
+		uri.len = snprintf(
+				uri.s, uri.len, "sip:%.*s", record->aor.len, record->aor.s);
 	}
 
 	/* Build the XML-Body: */
@@ -310,8 +344,7 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) {
 	publ.pres_uri = &uri;
 	publ.body = body;
 	id_buf_len = snprintf(id_buf, sizeof(id_buf), "REGINFO_PUBLISH.%.*s@%.*s",
-		c->aor->len, c->aor->s,
-		c->domain->len, c->domain->s);
+			c->aor->len, c->aor->s, c->domain->len, c->domain->s);
 	publ.id.s = id_buf;
 	publ.id.len = id_buf_len;
 	publ.content_type = content_type;
@@ -319,24 +352,27 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) {
 
 	/* make UPDATE_TYPE, as if this "publish dialog" is not found
 	   by pua it will fallback to INSERT_TYPE anyway */
-	publ.flag|= UPDATE_TYPE;
+	publ.flag |= UPDATE_TYPE;
 	publ.source_flag |= REGINFO_PUBLISH;
 	publ.event |= REGINFO_EVENT;
-	publ.extra_headers= NULL;
+	publ.extra_headers = NULL;
 
 	if(outbound_proxy.s && outbound_proxy.len)
-		publ.outbound_proxy= &outbound_proxy;
+		publ.outbound_proxy = &outbound_proxy;
 
 	if(pua.send_publish(&publ) < 0) {
 		LM_ERR("Error while sending publish\n");
 	}
 error:
-	if (uri.s) pkg_free(uri.s);
+	if(uri.s)
+		pkg_free(uri.s);
 	if(body) {
-		if(body->s) xmlFree(body->s);
+		if(body->s)
+			xmlFree(body->s);
 		pkg_free(body);
 	}
-	if(record) ul.release_urecord(record);
+	if(record)
+		ul.release_urecord(record);
 
 	return;
 }

+ 3 - 3
src/modules/pua_reginfo/usrloc_cb.h

@@ -16,8 +16,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -26,7 +26,7 @@
 
 #include "../usrloc/usrloc.h"
 
-void reginfo_usrloc_cb(ucontact_t* c, int type, void* param);
+void reginfo_usrloc_cb(ucontact_t *c, int type, void *param);
 void pua_reginfo_update_self_op(int v);
 
 #endif