Parcourir la source

sanity: Use str_list implementation from core

* Remove redundant str_list implementation.
* Improve docs
Bastian Triller il y a 3 ans
Parent
commit
acafe70708

+ 9 - 8
src/modules/sanity/doc/sanity_admin.xml

@@ -44,7 +44,7 @@
 		<listitem>
 		<listitem>
 			<para>
 			<para>
 			required headers - (4) -checks if the minimum set of required headers
 			required headers - (4) -checks if the minimum set of required headers
-			to, from, cseq, callid and via is present in the request.
+			To, From, CSeq, Call-ID and Via is present in the request.
 			</para>
 			</para>
 		</listitem>
 		</listitem>
 		<listitem>
 		<listitem>
@@ -59,31 +59,31 @@
 		</listitem>
 		</listitem>
 		<listitem>
 		<listitem>
 			<para>
 			<para>
-			Cseq method - (32) - checks if the method from the Cseq header is equal
+			Cseq method - (32) - checks if the method from the CSeq header is equal
 			to the request method.
 			to the request method.
 			</para>
 			</para>
 		</listitem>
 		</listitem>
 		<listitem>
 		<listitem>
 			<para>
 			<para>
-			Cseq value - (64) - checks if the number in the Cseq header is a valid
+			Cseq value - (64) - checks if the number in the CSeq header is a valid
 			unsigned integer.
 			unsigned integer.
 			</para>
 			</para>
 		</listitem>
 		</listitem>
 		<listitem>
 		<listitem>
 			<para>
 			<para>
 			content length - (128) - checks if the size of the body matches with the
 			content length - (128) - checks if the size of the body matches with the
-			value from the content length header.
+			value from the Content-Length header.
 			</para>
 			</para>
 		</listitem>
 		</listitem>
 		<listitem>
 		<listitem>
 			<para>
 			<para>
-			expires value - (256) - checks if the value of the expires header is a
+			expires value - (256) - checks if the value of the Expires header is a
 			valid unsigned integer.
 			valid unsigned integer.
 			</para>
 			</para>
 		</listitem>
 		</listitem>
 		<listitem>
 		<listitem>
 			<para>
 			<para>
-			proxy require - (512) - checks if all items of the proxy require header
+			proxy require - (512) - checks if all items of the Proxy-Require header
 			are present in the list of the extensions from the module
 			are present in the list of the extensions from the module
 			parameter proxy_require.
 			parameter proxy_require.
 			</para>
 			</para>
@@ -111,7 +111,7 @@
 		</listitem>
 		</listitem>
 		<listitem>
 		<listitem>
 			<para>
 			<para>
-			authorization header (8192) - checks if the Authorization is valid
+			Authorization header (8192) - checks if the Authorization header is valid
 			if the scheme is "digest" (see "digest credentials" above), always
 			if the scheme is "digest" (see "digest credentials" above), always
 			returns success for other schemes.
 			returns success for other schemes.
 			</para>
 			</para>
@@ -195,7 +195,8 @@ modparam("sanity", "uri_checks", 3)
 	<title><varname>proxy_require</varname> (string)</title>
 	<title><varname>proxy_require</varname> (string)</title>
 	<para>
 	<para>
 		This parameter sets the list of supported SIP extensions for this &kamailio;.
 		This parameter sets the list of supported SIP extensions for this &kamailio;.
-		The value is expected as a comma separated list of extensions.
+		The value is expected as a comma separated list
+		(leading and trailing whitespaces are stripped from each token) of extensions.
 		This list is separated into single tokens. Each token from
 		This list is separated into single tokens. Each token from
 		a proxy require header will be compared with the tokens from this
 		a proxy require header will be compared with the tokens from this
 		list.
 		list.

+ 30 - 30
src/modules/sanity/sanity.c

@@ -162,10 +162,10 @@ int str2valid_uint(str* _number, unsigned int* _result) {
 	return 0;
 	return 0;
 }
 }
 
 
-/* parses the given comma seperated string into a string list */
-strl* parse_str_list(str* _string) {
+/* parses the given comma separated string into a string list */
+str_list_t* parse_str_list(str* _string) {
 	str input;
 	str input;
-	strl *parsed_list, *pl;
+	str_list_t *parsed_list, *pl;
 	char *comma;
 	char *comma;
 
 
 	/* make a copy because we trim it */
 	/* make a copy because we trim it */
@@ -178,40 +178,40 @@ strl* parse_str_list(str* _string) {
 		LM_DBG("list is empty\n");
 		LM_DBG("list is empty\n");
 		return NULL;
 		return NULL;
 	}
 	}
-	parsed_list = pkg_malloc(sizeof(strl));
+	parsed_list = pkg_malloc(sizeof(str_list_t));
 	if (parsed_list == NULL) {
 	if (parsed_list == NULL) {
 		LM_ERR("OUT OF MEMORY for initial list element\n");
 		LM_ERR("OUT OF MEMORY for initial list element\n");
 		return NULL;
 		return NULL;
 	}
 	}
-	memset(parsed_list, 0, sizeof(strl));
-	parsed_list->string.s = input.s;
-	parsed_list->string.len = input.len;
+	memset(parsed_list, 0, sizeof(str_list_t));
+	parsed_list->s.s = input.s;
+	parsed_list->s.len = input.len;
 
 
 	comma = q_memchr(input.s, ',', input.len);
 	comma = q_memchr(input.s, ',', input.len);
 	pl = parsed_list;
 	pl = parsed_list;
 	while (comma != NULL) {
 	while (comma != NULL) {
-		pl->next = pkg_malloc(sizeof(strl));
+		pl->next = pkg_malloc(sizeof(str_list_t));
 		if (pl->next == NULL) {
 		if (pl->next == NULL) {
 			LM_ERR("OUT OF MEMORY for further list element\n");
 			LM_ERR("OUT OF MEMORY for further list element\n");
 			return parsed_list;
 			return parsed_list;
 		}
 		}
-		memset(pl->next, 0, sizeof(strl));
-		pl->next->string.s = comma + 1;
-		pl->next->string.len = pl->string.len
-			- (pl->next->string.s - pl->string.s);
-		pl->string.len = comma - pl->string.s;
-		trim_trailing(&(pl->string));
+		memset(pl->next, 0, sizeof(str_list_t));
+		pl->next->s.s = comma + 1;
+		pl->next->s.len = pl->s.len
+			- (pl->next->s.s - pl->s.s);
+		pl->s.len = comma - pl->s.s;
+		trim_trailing(&(pl->s));
 		pl = pl->next;
 		pl = pl->next;
-		trim_leading(&(pl->string));
-		comma = q_memchr(pl->string.s, ',', pl->string.len);
+		trim_leading(&(pl->s));
+		comma = q_memchr(pl->s.s, ',', pl->s.len);
 	}
 	}
 
 
 	return parsed_list;
 	return parsed_list;
 }
 }
 
 
 /* free the elements of the linked str list */
 /* free the elements of the linked str list */
-void free_str_list(strl *_list) {
-	strl *cur, *next;
+void free_str_list(str_list_t *_list) {
+	str_list_t *cur, *next;
 
 
 	if (_list != NULL) {
 	if (_list != NULL) {
 		cur = _list;
 		cur = _list;
@@ -224,7 +224,7 @@ void free_str_list(strl *_list) {
 }
 }
 
 
 int parse_proxyrequire(struct hdr_field* _h) {
 int parse_proxyrequire(struct hdr_field* _h) {
-	strl *pr_l;
+	str_list_t *pr_l;
 
 
 	if (_h->parsed) {
 	if (_h->parsed) {
 		return 0; /* Already parsed */
 		return 0; /* Already parsed */
@@ -664,7 +664,7 @@ int check_expires_value(sip_msg_t* msg) {
 
 
 /* check the content of the Proxy-Require header */
 /* check the content of the Proxy-Require header */
 int check_proxy_require(sip_msg_t* msg) {
 int check_proxy_require(sip_msg_t* msg) {
-	strl *r_pr, *l_pr;
+	str_list_t *r_pr, *l_pr;
 	char *u;
 	char *u;
 	int u_len;
 	int u_len;
 
 
@@ -692,20 +692,20 @@ int check_proxy_require(sip_msg_t* msg) {
 			l_pr = proxyrequire_list;
 			l_pr = proxyrequire_list;
 			while (l_pr != NULL) {
 			while (l_pr != NULL) {
 				LM_DBG("comparing r='%.*s' l='%.*s'\n",
 				LM_DBG("comparing r='%.*s' l='%.*s'\n",
-						r_pr->string.len, r_pr->string.s, l_pr->string.len,
-						l_pr->string.s);
-				if (l_pr->string.len == r_pr->string.len &&
+						r_pr->s.len, r_pr->s.s, l_pr->s.len,
+						l_pr->s.s);
+				if (l_pr->s.len == r_pr->s.len &&
 						/* FIXME tokens are case in-sensitive */
 						/* FIXME tokens are case in-sensitive */
-						memcmp(l_pr->string.s, r_pr->string.s,
-							l_pr->string.len) == 0) {
+						memcmp(l_pr->s.s, r_pr->s.s,
+							l_pr->s.len) == 0) {
 					break;
 					break;
 				}
 				}
 				l_pr = l_pr->next;
 				l_pr = l_pr->next;
 			}
 			}
 			if (l_pr == NULL) {
 			if (l_pr == NULL) {
 				LM_DBG("request contains unsupported extension: %.*s\n",
 				LM_DBG("request contains unsupported extension: %.*s\n",
-						r_pr->string.len, r_pr->string.s);
-				u_len = UNSUPPORTED_HEADER_LEN + 2 + r_pr->string.len;
+						r_pr->s.len, r_pr->s.s);
+				u_len = UNSUPPORTED_HEADER_LEN + 2 + r_pr->s.len;
 				u = pkg_malloc(u_len);
 				u = pkg_malloc(u_len);
 				if (u == NULL) {
 				if (u == NULL) {
 					LM_ERR("failed to allocate memory for"
 					LM_ERR("failed to allocate memory for"
@@ -713,9 +713,9 @@ int check_proxy_require(sip_msg_t* msg) {
 				}
 				}
 				else {
 				else {
 					memcpy(u, UNSUPPORTED_HEADER, UNSUPPORTED_HEADER_LEN);
 					memcpy(u, UNSUPPORTED_HEADER, UNSUPPORTED_HEADER_LEN);
-					memcpy(u + UNSUPPORTED_HEADER_LEN, r_pr->string.s,
-							r_pr->string.len);
-					memcpy(u + UNSUPPORTED_HEADER_LEN + r_pr->string.len,
+					memcpy(u + UNSUPPORTED_HEADER_LEN, r_pr->s.s,
+							r_pr->s.len);
+					memcpy(u + UNSUPPORTED_HEADER_LEN + r_pr->s.len,
 							CRLF, CRLF_LEN);
 							CRLF, CRLF_LEN);
 					add_lump_rpl(msg, u, u_len, LUMP_RPL_HDR);
 					add_lump_rpl(msg, u, u_len, LUMP_RPL_HDR);
 				}
 				}

+ 2 - 2
src/modules/sanity/sanity.h

@@ -36,8 +36,8 @@ int ki_sanity_reply(sip_msg_t *msg);
  * and converts it into _result. returns -1 on error and 0 on success*/
  * and converts it into _result. returns -1 on error and 0 on success*/
 int str2valid_uint(str* _number, unsigned int* _result);
 int str2valid_uint(str* _number, unsigned int* _result);
 
 
-/* parses the given comma seperated string into a string list */
-strl* parse_str_list(str* _string);
+/* parses the given comma separated string into a string list */
+str_list_t* parse_str_list(str* _string);
 
 
 /* check top Via header */
 /* check top Via header */
 int check_via1_header(sip_msg_t* msg);
 int check_via1_header(sip_msg_t* msg);

+ 4 - 4
src/modules/sanity/sanity_mod.c

@@ -41,7 +41,7 @@ int default_uri_checks = SANITY_DEFAULT_URI_CHECKS;
 int _sanity_drop = 1;
 int _sanity_drop = 1;
 int ksr_sanity_noreply = 0;
 int ksr_sanity_noreply = 0;
 
 
-strl* proxyrequire_list = NULL;
+str_list_t* proxyrequire_list = NULL;
 
 
 sl_api_t slb;
 sl_api_t slb;
 
 
@@ -98,7 +98,7 @@ struct module_exports exports = {
  * initialize module
  * initialize module
  */
  */
 static int mod_init(void) {
 static int mod_init(void) {
-	strl* ptr;
+	str_list_t* ptr;
 
 
 	LM_DBG("sanity initializing\n");
 	LM_DBG("sanity initializing\n");
 
 
@@ -116,8 +116,8 @@ static int mod_init(void) {
 	proxyrequire_list = ptr;
 	proxyrequire_list = ptr;
 
 
 	while (ptr != NULL) {
 	while (ptr != NULL) {
-		LM_DBG("string: '%.*s', next: %p\n", ptr->string.len,
-				ptr->string.s, ptr->next);
+		LM_DBG("string: '%.*s', next: %p\n", ptr->s.len,
+				ptr->s.s, ptr->next);
 		ptr = ptr->next;
 		ptr = ptr->next;
 	}
 	}
 
 

+ 3 - 9
src/modules/sanity/sanity_mod.h

@@ -25,7 +25,8 @@
 #define MOD_SANITY_CHK_H
 #define MOD_SANITY_CHK_H
 
 
 #include "../../core/str.h"
 #include "../../core/str.h"
-#include "../../modules/sl/sl.h"
+#include "../../core/str_list.h"
+#include "../sl/sl.h"
 #include "../../core/parser/msg_parser.h"
 #include "../../core/parser/msg_parser.h"
 
 
 #define SANITY_RURI_SIP_VERSION        (1<<0)
 #define SANITY_RURI_SIP_VERSION        (1<<0)
@@ -73,15 +74,8 @@
 #define SANITY_CHECK_ERROR -1
 #define SANITY_CHECK_ERROR -1
 #define SANITY_CHECK_NOT_APPLICABLE -2
 #define SANITY_CHECK_NOT_APPLICABLE -2
 
 
-struct _strlist {
-	str string;            /* the string */
-	struct _strlist* next; /* the next strlist element */
-};
-
-typedef struct _strlist strl;
-
 extern int default_checks;
 extern int default_checks;
-extern strl* proxyrequire_list;
+extern str_list_t* proxyrequire_list;
 
 
 extern sl_api_t slb;
 extern sl_api_t slb;