[svn-commits] mmichelson: branch mmichelson/issue14220 r169193 - /team/mmichelson/issue1422...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Jan 17 16:16:00 CST 2009


Author: mmichelson
Date: Sat Jan 17 16:16:00 2009
New Revision: 169193

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=169193
Log:
Add a REQ_OFFSET macro to avoid making people use pointer math to get
a string from a sip_request


Modified:
    team/mmichelson/issue14220/channels/chan_sip.c

Modified: team/mmichelson/issue14220/channels/chan_sip.c
URL: http://svn.digium.com/svn-view/asterisk/team/mmichelson/issue14220/channels/chan_sip.c?view=diff&rev=169193&r1=169192&r2=169193
==============================================================================
--- team/mmichelson/issue14220/channels/chan_sip.c (original)
+++ team/mmichelson/issue14220/channels/chan_sip.c Sat Jan 17 16:16:00 2009
@@ -1206,6 +1206,8 @@
 	AST_LIST_ENTRY(sip_request) next;
 };
 
+#define REQ_OFFSET(req,offset) ((req)->data->str + (req)->offset)
+
 /*! \brief structure used in transfers */
 struct sip_dual {
 	struct ast_channel *chan1;	/*!< First channel involved */
@@ -3780,7 +3782,7 @@
 		struct sip_request tmp = { .rlPart1 = 0, };
 		parse_copy(&tmp, req);
 		append_history(p, reliable ? "TxRespRel" : "TxResp", "%s / %s - %s", tmp.data->str, get_header(&tmp, "CSeq"), 
-			(tmp.method == SIP_RESPONSE || tmp.method == SIP_UNKNOWN) ? tmp.data->str + tmp.rlPart2 : sip_methods[tmp.method].text);
+			(tmp.method == SIP_RESPONSE || tmp.method == SIP_UNKNOWN) ? REQ_OFFSET(&tmp, rlPart2) : sip_methods[tmp.method].text);
 		ast_free(tmp.data);
 	}
 	res = (reliable) ?
@@ -6241,7 +6243,7 @@
 	int len = strlen(name);
 
 	while (*start < req->sdp_end) {
-		const char *r = get_body_by_line(req->data->str + req->line[(*start)++], name, len, '=');
+		const char *r = get_body_by_line(REQ_OFFSET(req, line[(*start)++]), name, len, '=');
 		if (r[0] != '\0')
 			return r;
 	}
@@ -6265,7 +6267,7 @@
 	char *r;
 
 	for (x = 0; x < req->lines; x++) {
-		r = get_body_by_line(req->data->str + req->line[x], name, len, delimiter);
+		r = get_body_by_line(REQ_OFFSET(req, line[x]), name, len, delimiter);
 		if (r[0] != '\0')
 			return r;
 	}
@@ -6328,7 +6330,7 @@
 	for (pass = 0; name && pass < 2;pass++) {
 		int x, len = strlen(name);
 		for (x = *start; x < req->headers; x++) {
-			char *header = req->data->str + req->header[x];
+			char *header = REQ_OFFSET(req, header[x]);
 			if (!strncasecmp(header, name, len)) {
 				char *r = header + len;	/* skip name */
 				if (sip_cfg.pedanticsipchecking)
@@ -7239,7 +7241,7 @@
 	   sdp part and the end boundry if it exists */
 
 	for (x = 0; x < (req->lines); x++) {
-		char *line = req->data->str + req->line[x];
+		char *line = REQ_OFFSET(req, line[x]);
 		if (!strncasecmp(line, boundary, strlen(boundary))){
 			if (found_application_sdp && found_end_of_headers) {
 				req->sdp_end = x-1;
@@ -8437,14 +8439,14 @@
 	}
 	
 	if (sipmethod == SIP_CANCEL)
-		c = p->initreq.data->str + p->initreq.rlPart2;	/* Use original URI */
+		c = REQ_OFFSET(&p->initreq, rlPart2);	/* Use original URI */
 	else if (sipmethod == SIP_ACK) {
 		/* Use URI from Contact: in 200 OK (if INVITE) 
 		(we only have the contacturi on INVITEs) */
 		if (!ast_strlen_zero(p->okcontacturi))
 			c = is_strict ? p->route->hop : p->okcontacturi;
  		else
- 			c = p->initreq.data->str + p->initreq.rlPart2;
+ 			c = REQ_OFFSET(&p->initreq, rlPart2);
 	} else if (!ast_strlen_zero(p->okcontacturi)) 
 		c = is_strict ? p->route->hop : p->okcontacturi; /* Use for BYE or REINVITE */
 	else if (!ast_strlen_zero(p->uri)) 
@@ -12066,7 +12068,7 @@
 
 	/* Find the request URI */
 	if (req->rlPart2)
-		ast_copy_string(tmp, req->data->str + req->rlPart2, sizeof(tmp));
+		ast_copy_string(tmp, REQ_OFFSET(req, rlPart2), sizeof(tmp));
 	
 	if (sip_cfg.pedanticsipchecking)
 		ast_uri_decode(tmp);
@@ -13008,7 +13010,7 @@
 	if (y < 0)
 		y = 0;
 	for (x = 0; x < req->lines; x++) {
-		char *line = req->data->str + req->line[x];
+		char *line = REQ_OFFSET(req, line[x]);
 		strncat(buf, line, y); /* safe */
 		y -= strlen(line) + 1;
 		if (y < 0)
@@ -18465,8 +18467,8 @@
 		/* If pedantic is on, we need to check the tags. If they're different, this is
 	   	in fact a forked call through a SIP proxy somewhere. */
 		int different;
-		char *initial_rlPart2 = p->initreq.data->str + p->initreq.rlPart2;
-		char *this_rlPart2 = req->data->str + req->rlPart2;
+		char *initial_rlPart2 = REQ_OFFSET(&p->initreq, rlPart2);
+		char *this_rlPart2 = REQ_OFFSET(req, rlPart2);
 		if (sip_cfg.pedanticsipchecking)
 			different = sip_uri_cmp(initial_rlPart2, this_rlPart2);
 		else
@@ -20280,8 +20282,8 @@
 	}
 	/* Get the command XXX */
 
-	cmd = req->data->str + req->rlPart1;
-	e = req->data->str + req->rlPart2;
+	cmd = REQ_OFFSET(req, rlPart1);
+	e = REQ_OFFSET(req, rlPart2);
 
 	/* Save useragent of the client */
 	useragent = get_header(req, "User-Agent");
@@ -20628,7 +20630,7 @@
 		ast_str_reset(req->data); /* nulling this out is NOT a good idea here. */
 		return 1;
 	}
-	req->method = find_sip_method(req->data->str + req->rlPart1);
+	req->method = find_sip_method(REQ_OFFSET(req, rlPart1));
 
 	if (req->debug)
 		ast_verbose("--- (%d headers %d lines)%s ---\n", req->headers, req->lines, (req->headers + req->lines == 0) ? " Nat keepalive" : "");
@@ -20668,7 +20670,7 @@
 	p->recv = *sin;
 
 	if (p->do_history) /* This is a request or response, note what it was for */
-		append_history(p, "Rx", "%s / %s / %s", req->data->str, get_header(req, "CSeq"), req->data->str + req->rlPart2);
+		append_history(p, "Rx", "%s / %s / %s", req->data->str, get_header(req, "CSeq"), REQ_OFFSET(req, rlPart2));
 
 	if (!lockretry) {
 		if (!queue_request(p, req)) {




More information about the svn-commits mailing list