[sr-dev] git:master: core, parser: moved ser_mem[r]mem() functions from parser to ut .c

Juha Heinanen jh at tutpro.com
Wed Apr 9 19:31:41 CEST 2014


Module: sip-router
Branch: master
Commit: 5ab74a287014087dbf6f95f96eeea55deb174f35
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5ab74a287014087dbf6f95f96eeea55deb174f35

Author: Juha Heinanen <jh at tutpro.com>
Committer: Juha Heinanen <jh at tutpro.com>
Date:   Wed Apr  9 20:30:23 2014 +0300

core, parser: moved ser_mem[r]mem() functions from parser to ut.c

---

 parser/sdp/sdp_helpr_funcs.c |   62 ------------------------------------------
 ut.c                         |   62 ++++++++++++++++++++++++++++++++++++++++++
 ut.h                         |   15 ++++++++++
 3 files changed, 77 insertions(+), 62 deletions(-)

diff --git a/parser/sdp/sdp_helpr_funcs.c b/parser/sdp/sdp_helpr_funcs.c
index a9eb315..64868c1 100644
--- a/parser/sdp/sdp_helpr_funcs.c
+++ b/parser/sdp/sdp_helpr_funcs.c
@@ -67,68 +67,6 @@ static struct {
 	(_x==_t[0]||_x==_t[7]||_x==_t[1]||_x==_t[2]||_x==_t[3]||_x==_t[4]\
 	||_x==_t[5]||_x==_t[6])
 
-/*
- * ser_memmem() returns the location of the first occurrence of data
- * pattern b2 of size len2 in memory block b1 of size len1 or
- * NULL if none is found. Obtained from NetBSD.
- */
-static void * ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2)
-{
-	/* Initialize search pointer */
-	char *sp = (char *) b1;
-
-	/* Initialize pattern pointer */
-	char *pp = (char *) b2;
-
-	/* Initialize end of search address space pointer */
-	char *eos = sp + len1 - len2;
-
-	/* Sanity check */
-	if(!(b1 && b2 && len1 && len2))
-		return NULL;
-
-	while (sp <= eos) {
-		if (*sp == *pp)
-			if (memcmp(sp, pp, len2) == 0)
-				return sp;
-
-			sp++;
-	}
-
-	return NULL;
-}
-
-/*
- * ser_memrmem() returns the location of the last occurrence of data
- * pattern b2 of size len2 in memory block b1 of size len1 or
- * NULL if none is found.
- */
-static void * ser_memrmem(const void *b1, const void *b2, size_t len1, size_t len2)
-{
-	/* Initialize search pointer */
-	char *sp = (char *) b1 + len1 - len2;
-
-	/* Initialize pattern pointer */
-	char *pp = (char *) b2;
-
-	/* Initialize end of search address space pointer */
-	char *eos = (char *) b1;
-
-	/* Sanity check */
-	if(!(b1 && b2 && len1 && len2))
-		return NULL;
-
-	while (sp >= eos) {
-		if (*sp == *pp)
-			if (memcmp(sp, pp, len2) == 0)
-				return sp;
-
-			sp--;
-	}
-
-	return NULL;
-}
-
 int get_mixed_part_delimiter(str* body, str *mp_delimiter)
 {
 	static unsigned int boun[16] = {
diff --git a/ut.c b/ut.c
index 7dd7373..7079c70 100644
--- a/ut.c
+++ b/ut.c
@@ -297,3 +297,65 @@ char *str_search(str *text, str *needle)
 
     return NULL;
 }
+
+/*
+ * ser_memmem() returns the location of the first occurrence of data
+ * pattern b2 of size len2 in memory block b1 of size len1 or
+ * NULL if none is found. Obtained from NetBSD.
+ */
+void * ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2)
+{
+	/* Initialize search pointer */
+	char *sp = (char *) b1;
+
+	/* Initialize pattern pointer */
+	char *pp = (char *) b2;
+
+	/* Initialize end of search address space pointer */
+	char *eos = sp + len1 - len2;
+
+	/* Sanity check */
+	if(!(b1 && b2 && len1 && len2))
+		return NULL;
+
+	while (sp <= eos) {
+		if (*sp == *pp)
+			if (memcmp(sp, pp, len2) == 0)
+				return sp;
+
+			sp++;
+	}
+
+	return NULL;
+}
+
+/*
+ * ser_memrmem() returns the location of the last occurrence of data
+ * pattern b2 of size len2 in memory block b1 of size len1 or
+ * NULL if none is found.
+ */
+void * ser_memrmem(const void *b1, const void *b2, size_t len1, size_t len2)
+{
+	/* Initialize search pointer */
+	char *sp = (char *) b1 + len1 - len2;
+
+	/* Initialize pattern pointer */
+	char *pp = (char *) b2;
+
+	/* Initialize end of search address space pointer */
+	char *eos = (char *) b1;
+
+	/* Sanity check */
+	if(!(b1 && b2 && len1 && len2))
+		return NULL;
+
+	while (sp >= eos) {
+		if (*sp == *pp)
+			if (memcmp(sp, pp, len2) == 0)
+				return sp;
+
+			sp--;
+	}
+
+	return NULL;
+}
diff --git a/ut.h b/ut.h
index 8f04736..aa7f33c 100644
--- a/ut.h
+++ b/ut.h
@@ -902,4 +902,19 @@ char* get_abs_pathname(str* base, str* file);
  * search for needle in text
  */
 char *str_search(str *text, str *needle);
+
+/*
+ * ser_memmem() returns the location of the first occurrence of data
+ * pattern b2 of size len2 in memory block b1 of size len1 or
+ * NULL if none is found. Obtained from NetBSD.
+ */
+void * ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2);
+
+/*
+ * ser_memrmem() returns the location of the last occurrence of data
+ * pattern b2 of size len2 in memory block b1 of size len1 or
+ * NULL if none is found.
+ */
+void * ser_memrmem(const void *b1, const void *b2, size_t len1, size_t len2);
+
 #endif




More information about the sr-dev mailing list