[asterisk-commits] kharwell: branch kharwell/pimp_sip_diversion r386619 - /team/kharwell/pimp_si...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 26 13:24:54 CDT 2013


Author: kharwell
Date: Fri Apr 26 13:24:50 2013
New Revision: 386619

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386619
Log:
addressed review findings

Modified:
    team/kharwell/pimp_sip_diversion/res/res_sip_diversion.c

Modified: team/kharwell/pimp_sip_diversion/res/res_sip_diversion.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_diversion/res/res_sip_diversion.c?view=diff&rev=386619&r1=386618&r2=386619
==============================================================================
--- team/kharwell/pimp_sip_diversion/res/res_sip_diversion.c (original)
+++ team/kharwell/pimp_sip_diversion/res/res_sip_diversion.c Fri Apr 26 13:24:50 2013
@@ -63,7 +63,7 @@
 	{ AST_REDIRECTING_REASON_SEND_TO_VM, "send_to_vm"},
 };
 
-static const char *reason_code_to_str(struct ast_party_redirecting_reason *reason)
+static const char *reason_code_to_str(const struct ast_party_redirecting_reason *reason)
 {
 	int code = reason->code;
 
@@ -99,7 +99,6 @@
 	static const pj_str_t from_name = { "From", 4 };
 
 	pjsip_generic_string_hdr *hdr;
-	pjsip_fromto_hdr *parsed;
 	pj_str_t value;
 	int size;
 
@@ -110,10 +109,8 @@
 	pj_strdup_with_null(rdata->tp_info.pool, &value, &hdr->hvalue);
 
 	/* parse as a fromto header */
-	parsed = pjsip_parse_hdr(rdata->tp_info.pool, &from_name, value.ptr,
-				 pj_strlen(&value), &size);
-
-	return parsed ? parsed : NULL;
+	return pjsip_parse_hdr(rdata->tp_info.pool, &from_name, value.ptr,
+			       pj_strlen(&value), &size);
 }
 
 static void set_redirecting_value(char **dst, const pj_str_t *src)
@@ -226,7 +223,7 @@
 		return;
 	}
 
-	/* use the diversion header info if there is one. if not one then use the 
+	/* use the diversion header info if there is one. if not one then use the
            session caller id info. if that doesn't exist use info from the To hdr*/
 	if (!(div_hdr = get_diversion_header(rdata)) && !session->id.number.valid) {
 		div_hdr = PJSIP_MSG_TO_HDR(rdata->msg_info.msg);
@@ -238,15 +235,6 @@
 			(pjsip_name_addr*)PJSIP_MSG_FROM_HDR(rdata->msg_info.msg)->uri);
 }
 
-#define param_add(pool,list,pname,pvalue) \
-	do { \
-	    pjsip_param *param; \
-	    param = PJ_POOL_ALLOC_T(pool, pjsip_param); \
-	    param->name = pj_str(pname); \
-	    param->value = pj_str(pvalue); \
-	    pj_list_insert_before(&list, param); \
-	} while (0)
-
 /*!
  * \internal
  * \brief Adds diversion header information to an outbound SIP message
@@ -259,9 +247,14 @@
 	pjsip_fromto_hdr *hdr;
 	pjsip_name_addr *name_addr;
 	pjsip_sip_uri *uri;
+	pjsip_param *param;
 
 	struct ast_party_id *id = &data->from;
 	pjsip_uri *base = PJSIP_MSG_FROM_HDR(tdata->msg)->uri;
+
+	if (!id->number.valid || ast_strlen_zero(id->number.str)) {
+		return;
+	}
 
 	hdr = pjsip_from_hdr_create(tdata->pool);
 	hdr->type = PJSIP_H_OTHER;
@@ -271,15 +264,13 @@
 	name_addr = pjsip_uri_clone(tdata->pool, base);
 	uri = pjsip_uri_get_uri(name_addr->uri);
 
-	if (!id->number.valid || ast_strlen_zero(id->number.str)) {
-		return;
-	}
-
 	pj_strdup2(tdata->pool, &name_addr->display, id->name.str);
 	pj_strdup2(tdata->pool, &uri->user, id->number.str);
 
-	param_add(tdata->pool, hdr->other_param, "reason",
-		  (char*)reason_code_to_str(&data->reason));
+	param = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param);
+	param->name = pj_str("reason");
+	param->value = pj_str((char*)reason_code_to_str(&data->reason));
+	pj_list_insert_before(&hdr->other_param, param);
 
 	hdr->uri = (pjsip_uri *) name_addr;
 	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);
@@ -320,7 +311,7 @@
 	struct pjsip_status_line status = tdata->msg->line.status;
 
 	/* add to 302 and 181 */
-	if (((status.code >= 300) && (status.code < 400)) || (status.code == 181)) {
+	if (PJSIP_IS_STATUS_IN_CLASS(status.code, 300) || (status.code == 181)) {
 		get_redirecting_add_diversion(session, tdata);
 	}
 }




More information about the asterisk-commits mailing list