[svn-commits] mmichelson: branch group/issue8824 r146801 - /team/group/issue8824/channels/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Oct 6 16:07:02 CDT 2008


Author: mmichelson
Date: Mon Oct  6 16:07:01 2008
New Revision: 146801

URL: http://svn.digium.com/view/asterisk?view=rev&rev=146801
Log:
Add better and more explicit privacy support for
the P-Asserted-Identity header.

Parsing was way off since I misread the RFC and didn't
realize that Privacy was a separate header from
P-Asserted-Identity. The privacy should be honored
better, however there is still no trust mechanic 
built into chan_sip (or the rest of Asterisk) for
that matter.

Also, on the advice of an implementer, instead of
transmitting no P-Asserted-Identity when the information
should be private, use the URI "anonymous at anonymous.invalid"


Modified:
    team/group/issue8824/channels/chan_sip.c

Modified: team/group/issue8824/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/channels/chan_sip.c?view=diff&rev=146801&r1=146800&r2=146801
==============================================================================
--- team/group/issue8824/channels/chan_sip.c (original)
+++ team/group/issue8824/channels/chan_sip.c Mon Oct  6 16:07:01 2008
@@ -8188,6 +8188,8 @@
 		add_header(req, "Remote-Party-ID", tmp);
 	} else if (!private) {
 		add_header(req, "P-Asserted-Identity", tmp);
+	} else {
+		add_header(req, "P-Asserted-Identity", "<anonymous at anonymous.invalid>");
 	}
 	return 0;
 }
@@ -11218,6 +11220,84 @@
 	}
 }
 
+/*! \brief Parse the parts of the P-Asserted-Identity header
+ * on an incoming packet. Returns 1 if a valid header is found
+ * and it is different from the current caller id.
+ */
+static int get_pai(struct sip_pvt *p, struct sip_request *req)
+{
+	char pai[256];
+	char privacy[64];
+	char *cid_num = "";
+	char *cid_name = "";
+	int callingpres = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
+	char *start = NULL, *end = NULL;
+
+	ast_copy_string(pai, get_header(req, "P-Asserted-Identity"), sizeof(pai));
+
+	if (ast_strlen_zero(pai)) {
+		return 0;
+	}
+
+	start = pai;
+	if (*start == '"') {
+		*start++ = '\0';
+		end = strchr(start, '"');
+		if (!end)
+			return 0;
+		*end++ = '\0';
+		cid_name = start;
+		start = ast_skip_blanks(end);
+	}
+	
+	if (*start != '<')
+		return 0;
+	*start++ = '\0';
+	end = strchr(start, '@');
+	if (!end)
+		return 0;
+	*end++ = '\0';
+	if (strncasecmp(start, "anonymous at anonymous.invalid", 27)) {
+		callingpres = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
+		/*XXX Assume no change in cid_num. Perhaps it should be 
+		 * blanked?
+		 */
+		cid_num = (char *)p->cid_num;
+	} else if (!strncasecmp(start, "sip:", 4)) {
+		cid_num = start + 4;
+		if (ast_is_shrinkable_phonenumber(cid_num))
+			ast_shrink_phone_number(cid_num);
+		start = end;
+
+		end = strchr(start, '>');
+		if (!end)
+			return 0;
+		*end = '\0';
+	} else {
+		return 0;
+	}
+
+	ast_copy_string(privacy, get_header(req, "Privacy"), sizeof(privacy));
+	if (!ast_strlen_zero(privacy) && strncmp(privacy, "id", 2)) {
+		callingpres = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
+	}
+
+	/* Only return true if the supplied caller id is different */
+	if (!strcasecmp(p->cid_num, cid_num) && !strcasecmp(p->cid_name, cid_name) && p->callingpres == callingpres)
+		return 0;
+
+	ast_string_field_set(p, cid_num, cid_num);
+	ast_string_field_set(p, cid_name, cid_name);
+	p->callingpres = callingpres;
+
+	if (p->owner) {
+		ast_set_callerid(p->owner, cid_num, cid_name, NULL);
+		p->owner->cid.cid_pres = callingpres;
+	}
+
+	return 1;
+}
+
 /*! \brief Get name, number and presentation from remote party id header, 
  *  returns true if a valid header was found and it was different from the
  *  current caller id.
@@ -11239,8 +11319,9 @@
 	if (!req)
 		req = &p->initreq;
 	ast_copy_string(tmp, get_header(req, "Remote-Party-ID"), sizeof(tmp));
-	if (ast_strlen_zero(tmp))
-		return 0;
+	if (ast_strlen_zero(tmp)) {
+		return get_pai(p, req);
+	}
 
 	start = tmp;
 	if (*start == '"') {




More information about the svn-commits mailing list