diff --git a/src/modules/sanity/doc/sanity_admin.xml b/src/modules/sanity/doc/sanity_admin.xml index a8a57d88d9a..b5ec247b649 100644 --- a/src/modules/sanity/doc/sanity_admin.xml +++ b/src/modules/sanity/doc/sanity_admin.xml @@ -44,7 +44,7 @@ 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. @@ -59,31 +59,31 @@ - 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. - 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. 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. - 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. - 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 parameter proxy_require. @@ -111,7 +111,7 @@ - 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 returns success for other schemes. @@ -195,7 +195,8 @@ modparam("sanity", "uri_checks", 3) <varname>proxy_require</varname> (string) 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 a proxy require header will be compared with the tokens from this list. diff --git a/src/modules/sanity/sanity.c b/src/modules/sanity/sanity.c index 55a8051a985..4264c2c1905 100644 --- a/src/modules/sanity/sanity.c +++ b/src/modules/sanity/sanity.c @@ -162,10 +162,10 @@ int str2valid_uint(str* _number, unsigned int* _result) { 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; - strl *parsed_list, *pl; + str_list_t *parsed_list, *pl; char *comma; /* make a copy because we trim it */ @@ -178,40 +178,40 @@ strl* parse_str_list(str* _string) { LM_DBG("list is empty\n"); return NULL; } - parsed_list = pkg_malloc(sizeof(strl)); + parsed_list = pkg_malloc(sizeof(str_list_t)); if (parsed_list == NULL) { LM_ERR("OUT OF MEMORY for initial list element\n"); 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); pl = parsed_list; while (comma != NULL) { - pl->next = pkg_malloc(sizeof(strl)); + pl->next = pkg_malloc(sizeof(str_list_t)); if (pl->next == NULL) { LM_ERR("OUT OF MEMORY for further list element\n"); 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; - 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; } /* 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) { cur = _list; @@ -224,7 +224,7 @@ void free_str_list(strl *_list) { } int parse_proxyrequire(struct hdr_field* _h) { - strl *pr_l; + str_list_t *pr_l; if (_h->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 */ int check_proxy_require(sip_msg_t* msg) { - strl *r_pr, *l_pr; + str_list_t *r_pr, *l_pr; char *u; int u_len; @@ -692,20 +692,20 @@ int check_proxy_require(sip_msg_t* msg) { l_pr = proxyrequire_list; while (l_pr != NULL) { 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 */ - 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; } l_pr = l_pr->next; } if (l_pr == NULL) { 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); if (u == NULL) { LM_ERR("failed to allocate memory for" @@ -713,9 +713,9 @@ int check_proxy_require(sip_msg_t* msg) { } else { 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); add_lump_rpl(msg, u, u_len, LUMP_RPL_HDR); } diff --git a/src/modules/sanity/sanity.h b/src/modules/sanity/sanity.h index fda0767b51c..339548edf42 100644 --- a/src/modules/sanity/sanity.h +++ b/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*/ 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 */ int check_via1_header(sip_msg_t* msg); diff --git a/src/modules/sanity/sanity_mod.c b/src/modules/sanity/sanity_mod.c index d4e3a3d62ea..3f813bb021b 100644 --- a/src/modules/sanity/sanity_mod.c +++ b/src/modules/sanity/sanity_mod.c @@ -41,7 +41,7 @@ int default_uri_checks = SANITY_DEFAULT_URI_CHECKS; int _sanity_drop = 1; int ksr_sanity_noreply = 0; -strl* proxyrequire_list = NULL; +str_list_t* proxyrequire_list = NULL; sl_api_t slb; @@ -98,7 +98,7 @@ struct module_exports exports = { * initialize module */ static int mod_init(void) { - strl* ptr; + str_list_t* ptr; LM_DBG("sanity initializing\n"); @@ -116,8 +116,8 @@ static int mod_init(void) { proxyrequire_list = ptr; 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; } diff --git a/src/modules/sanity/sanity_mod.h b/src/modules/sanity/sanity_mod.h index 3a7f89a05e1..2d9e12ff141 100644 --- a/src/modules/sanity/sanity_mod.h +++ b/src/modules/sanity/sanity_mod.h @@ -25,7 +25,8 @@ #define MOD_SANITY_CHK_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" #define SANITY_RURI_SIP_VERSION (1<<0) @@ -73,15 +74,8 @@ #define SANITY_CHECK_ERROR -1 #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 strl* proxyrequire_list; +extern str_list_t* proxyrequire_list; extern sl_api_t slb;