[asterisk-commits] mmichelson: branch mmichelson/issue14220 r169190 - /team/mmichelson/issue1422...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jan 17 15:12:17 CST 2009


Author: mmichelson
Date: Sat Jan 17 15:12:17 2009
New Revision: 169190

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=169190
Log:
Initial attempt at conversions of parse_request and determine_firstline_parts


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=169190&r1=169189&r2=169190
==============================================================================
--- team/mmichelson/issue14220/channels/chan_sip.c (original)
+++ team/mmichelson/issue14220/channels/chan_sip.c Sat Jan 17 15:12:17 2009
@@ -7075,33 +7075,38 @@
 */
 static int parse_request(struct sip_request *req)
 {
-	char *c = req->data->str, **dst = req->header;
+	char *c = req->data->str;
+	ptrdiff_t *dst = req->header;
 	int i = 0, lim = SIP_MAX_HEADERS - 1;
 	unsigned int skipping_headers = 0;
-
-	req->header[0] = c;
+	ptrdiff_t current_header_offset = 0;
+	char *previous_header = "";
+
+	req->header[0] = 0;
 	req->headers = -1;	/* mark that we are working on the header */
 	for (; *c; c++) {
 		if (*c == '\r') {		/* remove \r */
 			*c = '\0';
 		} else if (*c == '\n') { 	/* end of this line */
+			ptrdiff_t current_header_offset = (c + 1) - req->data->str;
+			char *previous_header = req->data->str + dst[i];
 			*c = '\0';
 			if (skipping_headers) {
 				/* check to see if this line is blank; if so, turn off
 				   the skipping flag, so the next line will be processed
 				   as a body line */
-				if (ast_strlen_zero(dst[i])) {
+				if (ast_strlen_zero(previous_header)) {
 					skipping_headers = 0;
 				}
-				dst[i] = c + 1; /* record start of next line */
+				dst[i] = current_header_offset; /* record start of next line */
 				continue;
 			}
 			if (sipdebug) {
-				ast_debug(4, "%7s %2d [%3d]: %s\n",
+				ast_debug(4, "%7s %2d [%3zu]: %s\n",
 					  req->headers < 0 ? "Header" : "Body",
-					  i, (int) strlen(dst[i]), dst[i]);
+					  i, strlen(previous_header), previous_header);
 			}
-			if (ast_strlen_zero(dst[i]) && req->headers < 0) {
+			if (ast_strlen_zero(previous_header) && req->headers < 0) {
 				req->headers = i;	/* record number of header lines */
 				dst = req->line;	/* start working on the body */
 				i = 0;
@@ -7122,9 +7127,9 @@
 					}
 				}
 			}
-			dst[i] = c + 1; /* record start of next line */
-		}
-        }
+			dst[i] = current_header_offset; /* record start of next line */
+		}
+	}
 
 	/* Check for last header or body line without CRLF. The RFC for SDP requires CRLF,
 	   but since some devices send without, we'll be generous in what we accept. However,
@@ -7132,10 +7137,11 @@
 	   we were parsing, we can't accept any more, so just ignore it.
 	*/
 	if ((i < lim) && !ast_strlen_zero(dst[i])) {
+		previous_header = req->data->str + dst[i];
 		if (sipdebug) {
-			ast_debug(4, "%7s %2d [%3d]: %s\n",
+			ast_debug(4, "%7s %2d [%3zu]: %s\n",
 				  req->headers < 0 ? "Header" : "Body",
-				  i, (int) strlen(dst[i]), dst[i]);
+				  i, strlen(previous_header), previous_header );
 		}
 		i++;
 	}
@@ -7146,7 +7152,8 @@
 	} else {			/* no body */
 		req->headers = i;
 		req->lines = 0;
-		req->line[0] = "";
+		/*XXX Should be all right...*/
+		req->line[0] = 0;
 	}
 
 	if (*c) {
@@ -9421,11 +9428,13 @@
 /*! \brief Parse first line of incoming SIP request */
 static int determine_firstline_parts(struct sip_request *req) 
 {
-	char *e = ast_skip_blanks(req->header[0]);	/* there shouldn't be any */
+	char *e = ast_skip_blanks(req->data->str);	/* there shouldn't be any */
+	char *local_rlPart1;
 
 	if (!*e)
 		return -1;
-	req->rlPart1 = e;	/* method or protocol */
+	req->rlPart1 = e - req->data->str;	/* method or protocol */
+	local_rlPart1 = e;
 	e = ast_skip_nonblanks(e);
 	if (*e)
 		*e++ = '\0';
@@ -9435,10 +9444,10 @@
 		return -1;
 	ast_trim_blanks(e);
 
-	if (!strcasecmp(req->rlPart1, "SIP/2.0") ) { /* We have a response */
+	if (!strcasecmp(local_rlPart1, "SIP/2.0") ) { /* We have a response */
 		if (strlen(e) < 3)	/* status code is 3 digits */
 			return -1;
-		req->rlPart2 = e;
+		req->rlPart2 = e - req->data->str;
 	} else { /* We have a request */
 		if ( *e == '<' ) { /* XXX the spec says it must not be in <> ! */
 			ast_debug(3, "Oops. Bogus uri in <> %s\n", e);
@@ -9446,7 +9455,7 @@
 			if (!*e)
 				return -1; 
 		}
-		req->rlPart2 = e;	/* URI */
+		req->rlPart2 = e - req->data->str;	/* URI */
 		e = ast_skip_nonblanks(e);
 		if (*e)
 			*e++ = '\0';




More information about the asterisk-commits mailing list