diff libsip/primary_parse.c @ 45:f1cf80c7e243

libsip/primary_parse.c: fully trim leading and trailing spaces
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 06 Sep 2022 15:15:42 -0800
parents 30572642e853
children
line wrap: on
line diff
--- a/libsip/primary_parse.c	Mon Sep 05 10:37:36 2022 -0800
+++ b/libsip/primary_parse.c	Tue Sep 06 15:15:42 2022 -0800
@@ -84,11 +84,23 @@
 		return(1);
 }
 
+static void
+trim_trailing_spaces(sp)
+	char *sp;
+{
+	char *ep;
+
+	ep = index(sp, '\0');
+	while (ep > sp && isspace(ep[-1]))
+		ep--;
+	*ep = '\0';
+}
+
 parse_incoming_sip_msg(msg)
 	struct sip_pkt_rx *msg;
 {
 	char *msg_end = msg->pkt_buffer + msg->pkt_length;
-	char *cp, *endp, *nextp;
+	char *cp, *endp, *nextp, *sp;
 	unsigned hdr_cnt;
 	int rc;
 
@@ -132,9 +144,7 @@
 				return(-1);
 		} else
 			return(-1);
-		while (cp < endp && isspace(*cp))
-			cp++;
-		msg->hdr_fields[hdr_cnt++].field_value = cp;
+		sp = cp;
 		cp = nextp;
 		while (cp < msg_end && (*cp == ' ' || *cp == '\t')) {
 			rc = find_crlf(cp, msg_end, &endp, &nextp);
@@ -143,6 +153,10 @@
 			cp = nextp;
 		}
 		*endp = '\0';
+		while (isspace(*sp))
+			sp++;
+		trim_trailing_spaces(sp);
+		msg->hdr_fields[hdr_cnt++].field_value = sp;
 	}
 	msg->num_hdr_fields = hdr_cnt;
 	msg->msg_body = nextp;