[asterisk-commits] dvossel: branch dvossel/sip_uri_encode_decode r235812 - /team/dvossel/sip_uri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 21 08:56:40 CST 2009


Author: dvossel
Date: Mon Dec 21 08:56:37 2009
New Revision: 235812

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=235812
Log:
addition of SIP_PEDANTIC_DECODE macro 

Modified:
    team/dvossel/sip_uri_encode_decode/channels/chan_sip.c

Modified: team/dvossel/sip_uri_encode_decode/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/sip_uri_encode_decode/channels/chan_sip.c?view=diff&rev=235812&r1=235811&r2=235812
==============================================================================
--- team/dvossel/sip_uri_encode_decode/channels/chan_sip.c (original)
+++ team/dvossel/sip_uri_encode_decode/channels/chan_sip.c Mon Dec 21 08:56:37 2009
@@ -1222,6 +1222,13 @@
 static struct sip_settings sip_cfg;		/*!< SIP configuration data.
 					\note in the future we could have multiple of these (per domain, per device group etc) */
 
+/*!< This macro should be used everytime ast_uri_decode is dependent on 
+ *   pedantic checking to be on. */
+#define SIP_PEDANTIC_DECODE(str)	\
+	if (!ast_strlen_zero(str) && (sip_cfg.pedanticsipchecking)) {	\
+		ast_uri_decode(str);	\
+	}	\
+
 static int global_match_auth_username;		/*!< Match auth username if available instead of From: Default off. */
 
 static int global_relaxdtmf;		/*!< Relax DTMF */
@@ -13517,24 +13524,28 @@
 	enum check_auth_result res = AUTH_NOT_FOUND;
 	struct sip_peer *peer;
 	char tmp[256];
-	char *name = NULL, *c, *domain = NULL, *dummy;
+	char *name = NULL, *c, *domain = NULL;
 	char *uri2 = ast_strdupa(uri);
 
 	terminate_uri(uri2);
 
 	ast_copy_string(tmp, get_header(req, "To"), sizeof(tmp));
-	if (sip_cfg.pedanticsipchecking)
-		ast_uri_decode(tmp);
 
 	c = get_in_brackets(tmp);
 	c = remove_uri_parameters(c);
 
-	if (parse_uri(c, "sip:,sips:", &name, &dummy, &domain, &dummy, &dummy, NULL)) {
+	if (parse_uri(c, "sip:,sips:", &name, NULL, &domain, NULL, NULL, NULL)) {
 		ast_log(LOG_NOTICE, "Invalid to address: '%s' from %s (missing sip:) trying to use anyway...\n", c, ast_inet_ntoa(sin->sin_addr));
 		return -1;
 	}
 
-	if (!AST_LIST_EMPTY(&domain_list)) {
+	SIP_PEDANTIC_DECODE(name);
+	SIP_PEDANTIC_DECODE(domain);
+
+	/*! \todo XXX here too we interpret a missing @domain as a name-only
+	 * URI, whereas the RFC says this is a domain-only uri.
+	 */
+	if (!ast_strlen_zero(domain) && !AST_LIST_EMPTY(&domain_list)) {
 		if (!check_sip_domain(domain, NULL, 0)) {
 			transmit_response(p, "404 Not found (unknown domain)", &p->initreq);
 			return AUTH_UNKNOWN_DOMAIN;
@@ -14016,7 +14027,7 @@
 */
 static int get_destination(struct sip_pvt *p, struct sip_request *oreq)
 {
-	char tmp[256] = "", *uri, *a, *dummy;
+	char tmp[256] = "", *uri, *a;
 	char tmpf[256] = "", *from = NULL;
 	struct sip_request *req;
 	char *decoded_uri;
@@ -14029,15 +14040,15 @@
 	if (req->rlPart2)
 		ast_copy_string(tmp, REQ_OFFSET_TO_STR(req, rlPart2), sizeof(tmp));
 	
-	if (sip_cfg.pedanticsipchecking)
-		ast_uri_decode(tmp);
-
 	uri = get_in_brackets(tmp);
 
-	if (parse_uri(uri, "sip:,sips", &uri, &dummy, &a, &dummy, &dummy, NULL)) {
+	if (parse_uri(uri, "sip:,sips", &uri, NULL, &a, NULL, NULL, NULL)) {
 		ast_log(LOG_WARNING, "Not a SIP header (%s)?\n", uri);
 		return -1;
 	}
+
+	SIP_PEDANTIC_DECODE(a);
+	SIP_PEDANTIC_DECODE(uri);
 
 	ast_string_field_set(p, domain, a);
 
@@ -14047,16 +14058,15 @@
         */
 	ast_copy_string(tmpf, get_header(req, "From"), sizeof(tmpf));
 	if (!ast_strlen_zero(tmpf)) {
-		if (sip_cfg.pedanticsipchecking)
-			ast_uri_decode(tmpf);
 		from = get_in_brackets(tmpf);
-	}
-
-	if (!ast_strlen_zero(from)) {
-		if (parse_uri(from, "sip:,sips", &from, &dummy, &a, &dummy, &dummy, NULL)) {
+		if (parse_uri(from, "sip:,sips", &from, NULL, &a, NULL, NULL, NULL)) {
 			ast_log(LOG_WARNING, "Not a SIP header (%s)?\n", from);
 			return -1;
 		}
+
+		SIP_PEDANTIC_DECODE(from);
+		SIP_PEDANTIC_DECODE(a);
+
 		ast_string_field_set(p, fromdomain, a);
 	}
 
@@ -14231,9 +14241,6 @@
 	}
 	h_refer_to = ast_strdupa(p_refer_to);
 	refer_to = get_in_brackets(h_refer_to);
-	if (sip_cfg.pedanticsipchecking)
-		ast_uri_decode(refer_to);
-
 	if (!strncasecmp(refer_to, "sip:", 4)) {
 		refer_to += 4;			/* Skip sip: */
 	} else if (!strncasecmp(refer_to, "sips:", 5)) {
@@ -14258,8 +14265,6 @@
 	if (!ast_strlen_zero(p_referred_by)) {
 		char *lessthan;
 		h_referred_by = ast_strdupa(p_referred_by);
-		if (sip_cfg.pedanticsipchecking)
-			ast_uri_decode(h_referred_by);
 
 		/* Store referrer's caller ID name */
 		ast_copy_string(referdata->referred_by_name, h_referred_by, sizeof(referdata->referred_by_name));
@@ -14268,6 +14273,7 @@
 		}
 
 		referred_by_uri = get_in_brackets(h_referred_by);
+
 		if (!strncasecmp(referred_by_uri, "sip:", 4)) {
 			referred_by_uri += 4;		/* Skip sip: */
 		} else if (!strncasecmp(referred_by_uri, "sips:", 5)) {
@@ -14285,7 +14291,6 @@
 		/* This is an attended transfer */
 		referdata->attendedtransfer = 1;
 		ast_copy_string(referdata->replaces_callid, ptr+9, sizeof(referdata->replaces_callid));
-		ast_uri_decode(referdata->replaces_callid);
 		if ((ptr = strchr(referdata->replaces_callid, ';'))) 	/* Find options */ {
 			*ptr++ = '\0';
 		}
@@ -14303,6 +14308,7 @@
 				*to = '\0';
 			if ((to = strchr(ptr, ';')))
 				*to = '\0';
+			ast_uri_decode(ptr);
 			ast_copy_string(referdata->replaces_callid_totag, ptr, sizeof(referdata->replaces_callid_totag));
 		}
 		
@@ -14312,6 +14318,7 @@
 				*to = '\0';
 			if ((to = strchr(ptr, ';')))
 				*to = '\0';
+			ast_uri_decode(ptr);
 			ast_copy_string(referdata->replaces_callid_fromtag, ptr, sizeof(referdata->replaces_callid_fromtag));
 		}
 		
@@ -14332,19 +14339,26 @@
 		if ((ptr = strchr(domain, ':')))	/* Remove :port */
 			*ptr = '\0';
 		
+		SIP_PEDANTIC_DECODE(domain);
+		SIP_PEDANTIC_DECODE(urioption);
+
 		/* Save the domain for the dial plan */
 		ast_copy_string(referdata->refer_to_domain, domain, sizeof(referdata->refer_to_domain));
-		if (urioption)
+		if (urioption) {
 			ast_copy_string(referdata->refer_to_urioption, urioption, sizeof(referdata->refer_to_urioption));
+		}
 	}
 
 	if ((ptr = strchr(refer_to, ';'))) 	/* Remove options */
 		*ptr = '\0';
+
+	SIP_PEDANTIC_DECODE(refer_to);
 	ast_copy_string(referdata->refer_to, refer_to, sizeof(referdata->refer_to));
 	
 	if (referred_by_uri) {
 		if ((ptr = strchr(referred_by_uri, ';'))) 	/* Remove options */
 			*ptr = '\0';
+		SIP_PEDANTIC_DECODE(referred_by_uri);
 		ast_copy_string(referdata->referred_by, referred_by_uri, sizeof(referdata->referred_by));
 	} else {
 		referdata->referred_by[0] = '\0';
@@ -14383,7 +14397,7 @@
  */
 static int get_also_info(struct sip_pvt *p, struct sip_request *oreq)
 {
-	char tmp[256] = "", *c, *a, *dummy;
+	char tmp[256] = "", *c, *a;
 	struct sip_request *req = oreq ? oreq : &p->initreq;
 	struct sip_refer *referdata = NULL;
 	const char *transfer_context = NULL;
@@ -14396,13 +14410,13 @@
 	ast_copy_string(tmp, get_header(req, "Also"), sizeof(tmp));
 	c = get_in_brackets(tmp);
 
-	if (sip_cfg.pedanticsipchecking)
-		ast_uri_decode(c);
-
-	if (parse_uri(c, "sip:,sips", &c, &dummy, &a, &dummy, &dummy, NULL)) {
+	if (parse_uri(c, "sip:,sips", &c, NULL, &a, NULL, NULL, NULL)) {
 		ast_log(LOG_WARNING, "Huh?  Not a SIP header in Also: transfer (%s)?\n", c);
 		return -1;
 	}
+	
+	SIP_PEDANTIC_DECODE(c);
+	SIP_PEDANTIC_DECODE(a);
 
 	if (!ast_strlen_zero(a)) {
 		ast_copy_string(referdata->refer_to_domain, a, sizeof(referdata->refer_to_domain));
@@ -14762,15 +14776,14 @@
 	terminate_uri(uri2);	/* trim extra stuff */
 
 	ast_copy_string(from, get_header(req, "From"), sizeof(from));
-	if (sip_cfg.pedanticsipchecking)
-		ast_uri_decode(from);
 	/* XXX here tries to map the username for invite things */
 	memset(calleridname, 0, sizeof(calleridname));
 	get_calleridname(from, calleridname, sizeof(calleridname));
+
+	SIP_PEDANTIC_DECODE(calleridname);
 	if (calleridname[0])
 		ast_string_field_set(p, cid_name, calleridname);
 
-	of = get_in_brackets(from);
 	if (ast_strlen_zero(p->exten)) {
 		char *t = uri2;
 		if (!strncasecmp(t, "sip:", 4))
@@ -14781,9 +14794,13 @@
 		t = strchr(p->exten, '@');
 		if (t)
 			*t = '\0';
+
 		if (ast_strlen_zero(p->our_contact))
 			build_contact(p);
 	}
+
+	of = get_in_brackets(from);
+
 	/* save the URI part of the From header */
 	ast_string_field_set(p, from, of);
 
@@ -14791,6 +14808,9 @@
 	if (parse_uri(of, "sip:,sips:", &of, &dummy, &domain, &dummy, &dummy, NULL)) {
 		ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
 	}
+
+	SIP_PEDANTIC_DECODE(of);
+	SIP_PEDANTIC_DECODE(domain);
 
 	if (ast_strlen_zero(of)) {
 		/* XXX note: the original code considered a missing @host
@@ -20746,7 +20766,6 @@
 			ast_debug(3, "INVITE part of call transfer. Replaces [%s]\n", p_replaces);
 		/* Create a buffer we can manipulate */
 		replace_id = ast_strdupa(p_replaces);
-		ast_uri_decode(replace_id);
 
 		if (!p->refer && !sip_refer_allocate(p)) {
 			transmit_response_reliable(p, "500 Server Internal Error", req);
@@ -20777,6 +20796,10 @@
 				fromtag = strsep(&fromtag, "&"); /* trim what ? */
 			}
 		}
+
+		ast_uri_decode(fromtag);
+		ast_uri_decode(totag);
+		ast_uri_decode(replace_id);
 
 		if (sipdebug)
 			ast_debug(4, "Invite/replaces: Will use Replace-Call-ID : %s Fromtag: %s Totag: %s\n",




More information about the asterisk-commits mailing list