[asterisk-commits] mmichelson: branch group/v14_colp r146806 - /team/group/v14_colp/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 6 16:16:51 CDT 2008


Author: mmichelson
Date: Mon Oct  6 16:16:51 2008
New Revision: 146806

URL: http://svn.digium.com/view/asterisk?view=rev&rev=146806
Log:
Merging 146801 of issue8824 branch


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

Modified: team/group/v14_colp/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/v14_colp/channels/chan_sip.c?view=diff&rev=146806&r1=146805&r2=146806
==============================================================================
--- team/group/v14_colp/channels/chan_sip.c (original)
+++ team/group/v14_colp/channels/chan_sip.c Mon Oct  6 16:16:51 2008
@@ -6390,6 +6390,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;
 }
@@ -9042,6 +9044,85 @@
 
 	return res;
 }
+
+/*! \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.
@@ -9063,8 +9144,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 asterisk-commits mailing list