瀏覽代碼

core: parser/sdp - function to find sdp line with start EoL check option

Daniel-Constantin Mierla 1 年之前
父節點
當前提交
368661cc15
共有 2 個文件被更改,包括 18 次插入5 次删除
  1. 17 5
      src/core/parser/sdp/sdp_helpr_funcs.c
  2. 1 0
      src/core/parser/sdp/sdp_helpr_funcs.h

+ 17 - 5
src/core/parser/sdp/sdp_helpr_funcs.c

@@ -733,9 +733,10 @@ int extract_sess_version(str *oline, str *sess_version)
 
 /*
  * Auxiliary for some functions.
+ * - smode: if 1, pstart is pointing inside msg body
  * Returns pointer to first character of found line, or NULL if no such line.
  */
-char *find_sdp_line(char *pstart, char *plimit, char linechar)
+char *find_sdp_line_start(char *pstart, char *plimit, char linechar, int smode)
 {
 	static char linehead[3] = "x=";
 	char *cp, *cp1;
@@ -749,11 +750,14 @@ char *find_sdp_line(char *pstart, char *plimit, char linechar)
 		if(cp1 == NULL)
 			return NULL;
 		/*
-		 * As it is body, we assume it has previous line and we can
-		 * lookup previous character.
+		 * smode==1 means it is msg body, thus it has previous line and it can
+		 * lookup previous character even when cp1==pstart.
 		 */
-		if(cp1[-1] == '\n' || cp1[-1] == '\r')
-			return cp1;
+		if(cp1 > pstart || smode == 1) {
+			if(cp1[-1] == '\n' || cp1[-1] == '\r') {
+				return cp1;
+			}
+		}
 		/*
 		 * Having such data, but not at line beginning.
 		 * Skip them and reiterate. ser_memmem() will find next
@@ -765,6 +769,14 @@ char *find_sdp_line(char *pstart, char *plimit, char linechar)
 	}
 }
 
+/*
+ * Auxiliary for some functions - expect pstart to point inside SIP message body.
+ * Returns pointer to first character of found line, or NULL if no such line.
+ */
+char *find_sdp_line(char *pstart, char *plimit, char linechar)
+{
+	return find_sdp_line_start(pstart, plimit, linechar, 1);
+}
 
 /* This function assumes pstart points to a line of requested type. */
 char *find_next_sdp_line(

+ 1 - 0
src/core/parser/sdp/sdp_helpr_funcs.h

@@ -65,6 +65,7 @@ int extract_accept_wrapped_types(str *body, str *accept_wrapped_types);
 int extract_max_size(str *body, str *max_size);
 int extract_path(str *body, str *path);
 
+char *find_sdp_line_start(char *pstart, char *plimit, char linechar, int smode);
 char *find_sdp_line(char *p, char *plimit, char linechar);
 char *find_next_sdp_line(char *p, char *plimit, char linechar, char *defptr);