[asterisk-commits] mmichelson: branch mmichelson/caller_id r384816 - /team/mmichelson/caller_id/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 5 11:52:59 CDT 2013


Author: mmichelson
Date: Fri Apr  5 11:52:56 2013
New Revision: 384816

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384816
Log:
Add privacy information on outbound P-Asserted-Identity and Remote-Party-ID.


Modified:
    team/mmichelson/caller_id/res/res_sip_caller_id.c

Modified: team/mmichelson/caller_id/res/res_sip_caller_id.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/caller_id/res/res_sip_caller_id.c?view=diff&rev=384816&r1=384815&r2=384816
==============================================================================
--- team/mmichelson/caller_id/res/res_sip_caller_id.c (original)
+++ team/mmichelson/caller_id/res/res_sip_caller_id.c Fri Apr  5 11:52:56 2013
@@ -308,6 +308,28 @@
 	return id_hdr;
 }
 
+static void add_privacy_header(pjsip_tx_data *tdata, struct ast_party_id *id)
+{
+	static const pj_str_t pj_privacy_name = { "Privacy", 7 };
+	static const pj_str_t pj_privacy_value = { "id", 2 };
+	pjsip_hdr *old_privacy;
+
+	old_privacy = pjsip_msg_find_hdr_by_name(tdata->msg, &pj_privacy_name, NULL);
+
+	if ((id->name.presentation & AST_PRES_RESTRICTION) == AST_PRES_RESTRICTED ||
+			(id->name.presentation & AST_PRES_RESTRICTION) == AST_PRES_RESTRICTED) {
+		if (!old_privacy) {
+			pjsip_generic_string_hdr *privacy_hdr = pjsip_generic_string_hdr_create(
+					tdata->pool, &pj_privacy_name, &pj_privacy_value);
+			pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)privacy_hdr);
+		}
+	} else {
+		if (old_privacy) {
+			pj_list_erase(old_privacy);
+		}
+	}
+}
+
 static void add_pai_header(pjsip_tx_data *tdata, struct ast_party_id *id)
 {
 	static const pj_str_t pj_pai_name = { "P-Asserted-Identity", 19 };
@@ -324,6 +346,7 @@
 	old_pai = pjsip_msg_find_hdr_by_name(tdata->msg, &pj_pai_name, NULL);
 	if (old_pai) {
 		modify_id_header(tdata->pool, old_pai, id);
+		add_privacy_header(tdata, id);
 		return;
 	}
 
@@ -331,8 +354,56 @@
 	if (!pai_hdr) {
 		return;
 	}
+	add_privacy_header(tdata, id);
 
 	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)pai_hdr);
+}
+
+static void add_privacy_params(pjsip_tx_data *tdata, pjsip_fromto_hdr *hdr, struct ast_party_id *id)
+{
+	static const pj_str_t privacy_str = { "privacy", 7 };
+	static const pj_str_t screen_str = { "screen", 6 };
+	static const pj_str_t privacy_full_str = { "full", 4 };
+	static const pj_str_t privacy_off_str = { "off", 3 };
+	static const pj_str_t screen_yes_str = { "yes", 3 };
+	static const pj_str_t screen_no_str = { "no", 2 };
+	pjsip_param *old_privacy;
+	pjsip_param *old_screen;
+	pjsip_param *privacy;
+	pjsip_param *screen;
+
+	old_privacy = pjsip_param_find(&hdr->other_param, &privacy_str);
+	old_screen = pjsip_param_find(&hdr->other_param, &screen_str);
+
+	if (!old_privacy) {
+		privacy = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param);
+		privacy->name = privacy_str;
+		pj_list_insert_before(&hdr->other_param, privacy);
+	} else {
+		privacy = old_privacy;
+	}
+
+	if (!old_screen) {
+		screen = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param);
+		screen->name = screen_str;
+		pj_list_insert_before(&hdr->other_param, screen);
+	} else {
+		screen = old_screen;
+	}
+
+	if ((id->name.presentation & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED &&
+			(id->name.presentation & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED) {
+		privacy->value = privacy_off_str;
+	} else {
+		privacy->value = privacy_full_str;
+	}
+
+	if ((id->name.presentation & AST_PRES_NUMBER_TYPE) == AST_PRES_USER_NUMBER_PASSED_SCREEN &&
+			(id->number.presentation & AST_PRES_NUMBER_TYPE) == AST_PRES_USER_NUMBER_PASSED_SCREEN) {
+		screen->value = screen_yes_str;
+	} else {
+		screen->value = screen_no_str;
+	}
 }
 
 static void add_rpid_header(pjsip_tx_data *tdata, struct ast_party_id *id)
@@ -351,6 +422,7 @@
 	old_rpid = pjsip_msg_find_hdr_by_name(tdata->msg, &pj_rpid_name, NULL);
 	if (old_rpid) {
 		modify_id_header(tdata->pool, old_rpid, id);
+		add_privacy_params(tdata, old_rpid, id);
 		return;
 	}
 
@@ -358,6 +430,7 @@
 	if (!rpid_hdr) {
 		return;
 	}
+	add_privacy_params(tdata, rpid_hdr, id);
 	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)rpid_hdr);
 }
 




More information about the asterisk-commits mailing list