[asterisk-commits] trunk r26919 - /trunk/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu May 11 07:55:35 MST 2006


Author: rizzo
Date: Thu May 11 09:55:34 2006
New Revision: 26919

URL: http://svn.digium.com/view/asterisk?rev=26919&view=rev
Log:
simplify determine_firstline_parts


Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=26919&r1=26918&r2=26919&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Thu May 11 09:55:34 2006
@@ -4970,50 +4970,41 @@
 }
 
 /*! \brief Parse first line of incoming SIP request */
-static int determine_firstline_parts( struct sip_request *req ) 
-{
-	char *e, *cmd;
-	int len;
-  
-	cmd = ast_skip_blanks(req->header[0]);
-	if (!*cmd)
+static int determine_firstline_parts(struct sip_request *req) 
+{
+	char *e = ast_skip_blanks(req->header[0]);	/* there shouldn't be any */
+
+	if (!*e)
 		return -1;
-	req->rlPart1 = cmd;
-	e = ast_skip_nonblanks(cmd);
-	/* Get the command */
+	req->rlPart1 = e;	/* method or protocol */
+	e = ast_skip_nonblanks(e);
 	if (*e)
 		*e++ = '\0';
+	/* Get URI or status code */
 	e = ast_skip_blanks(e);
 	if ( !*e )
 		return -1;
-
-	if ( !strcasecmp(cmd, "SIP/2.0") ) {
-		/* We have a response */
+	ast_trim_blanks(e);
+
+	if (!strcasecmp(req->rlPart1, "SIP/2.0") ) { /* We have a response */
+		if (strlen(e) < 3)	/* status code is 3 digits */
+			return -1;
 		req->rlPart2 = e;
-		len = strlen( req->rlPart2 );
-		if ( len < 2 ) { 
+	} else { /* We have a request */
+		if ( *e == '<' ) { /* XXX the spec says it must not be in <> ! */
+			ast_log(LOG_WARNING, "bogus uri in <> %s\n", e);
+			e++;
+			if (!*e)
+				return -1; 
+		}
+		req->rlPart2 = e;	/* URI */
+		e = ast_skip_nonblanks(e);
+		if (*e)
+			*e++ = '\0';
+		e = ast_skip_blanks(e);
+		if (strcasecmp(e, "SIP/2.0") ) {
+			ast_log(LOG_WARNING, "Bad request protocol %s\n", e);
 			return -1;
-		}
-		ast_trim_blanks(e);
-	} else {
-		/* We have a request */
-		if ( *e == '<' ) { 
-			e++;
-			if ( !*e ) { 
-				return -1; 
-			}  
-		}
-		req->rlPart2 = e;	/* URI */
-		if ( ( e= strrchr( req->rlPart2, 'S' ) ) == NULL ) {
-			return -1;
-		}
-		/* XXX maybe trim_blanks() ? */
-		while( isspace( *(--e) ) )
-			;
-		if ( *e == '>' ) {
-			*e = '\0';
-		} else {
-			*(++e)= '\0';
 		}
 	}
 	return 1;



More information about the asterisk-commits mailing list