Module: sip-router Branch: master Commit: 46d67e70cc3077942802333d49aaef57d2e6d5d5 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=46d67e70...
Author: pd peter.dunkley@crocodile-rcs.com Committer: pd peter.dunkley@crocodile-rcs.com Date: Wed Oct 19 11:30:51 2011 +0100
modules_k/textops: added is_privacy() to the exported textops API
- For use in app_lua
---
modules_k/textops/api.c | 17 +++++++ modules_k/textops/api.h | 2 + modules_k/textops/textops.c | 103 +----------------------------------------- modules_k/textops/textops.h | 2 + 4 files changed, 24 insertions(+), 100 deletions(-)
diff --git a/modules_k/textops/api.c b/modules_k/textops/api.c index 3180d09..0adf7b5 100644 --- a/modules_k/textops/api.c +++ b/modules_k/textops/api.c @@ -100,6 +100,22 @@ int search_api(struct sip_msg *msg, str *regex){ return retval; } + +int is_privacy_api(struct sip_msg *msg, str* privacy_type){ + int retval; + void **param=pkg_malloc(sizeof(void*)); + *param=pkg_malloc(privacy_type->len+1); + memcpy(*param,privacy_type->s,privacy_type->len); + memset(*param+privacy_type->len,0,1); + + fixup_privacy(param, 1); + retval = is_privacy_f(msg, *param, NULL); + + pkg_free(param); + + return retval; +} + /* * Function to load the textops api. */ @@ -112,5 +128,6 @@ int bind_textops(textops_api_t *tob){ tob->remove_hf=remove_hf_api; tob->search_append=search_append_api; tob->search=search_api; + tob->is_privacy=is_privacy_api; return 0; } diff --git a/modules_k/textops/api.h b/modules_k/textops/api.h index a2b72c4..00ec57a 100644 --- a/modules_k/textops/api.h +++ b/modules_k/textops/api.h @@ -33,6 +33,7 @@ typedef int (*append_hf_t)(struct sip_msg*, str*); typedef int (*remove_hf_t)(struct sip_msg*, str*); typedef int (*search_append_t)(struct sip_msg*, str*, str*); typedef int (*search_t)(struct sip_msg*, str*); +typedef int (*is_privacy_t)(struct sip_msg*, str*);
/* * Struct with the textops api. @@ -42,6 +43,7 @@ typedef struct textops_binds { remove_hf_t remove_hf; // Remove a header with the specified name from the message. search_append_t search_append; // Append a str after a match of the specified regex. search_t search; // Check if the regex matches a part of the message. + is_privacy_t is_privacy; } textops_api_t;
typedef int (*bind_textops_f)(textops_api_t*); diff --git a/modules_k/textops/textops.c b/modules_k/textops/textops.c index d66631f..8d2a2a7 100644 --- a/modules_k/textops/textops.c +++ b/modules_k/textops/textops.c @@ -123,9 +123,6 @@ static int set_body_f(struct sip_msg* msg, char*, char *); static int set_rpl_body_f(struct sip_msg* msg, char*, char *); static int is_method_f(struct sip_msg* msg, char* , char *); static int has_body_f(struct sip_msg *msg, char *type, char *str2 ); -static int is_privacy_f(struct sip_msg *msg, char *privacy, char *str2 ); -static int in_list_f(struct sip_msg* _msg, char* _subject, char* _list, - char* _sep); static int cmp_str_f(struct sip_msg *msg, char *str1, char *str2 ); static int cmp_istr_f(struct sip_msg *msg, char *str1, char *str2 ); static int starts_with_f(struct sip_msg *msg, char *str1, char *str2 ); @@ -138,9 +135,6 @@ static int free_hname_fixup(void** param, int param_no); static int fixup_method(void** param, int param_no); static int add_header_fixup(void** param, int param_no); static int fixup_body_type(void** param, int param_no); -static int fixup_privacy(void** param, int param_no); -static int fixup_in_list(void** param, int param_no); -static int fixup_free_in_list(void** param, int param_no); int fixup_regexpNL_none(void** param, int param_no);
static int mod_init(void); @@ -246,9 +240,6 @@ static cmd_export_t cmds[]={ {"is_privacy", (cmd_function)is_privacy_f, 1, fixup_privacy, 0, ANY_ROUTE}, - {"in_list", (cmd_function)in_list_f, 3, fixup_in_list, - fixup_free_in_list, - ANY_ROUTE}, {"cmp_str", (cmd_function)cmp_str_f, 2, fixup_spve_spve, 0, ANY_ROUTE}, @@ -1757,7 +1748,7 @@ static int fixup_method(void** param, int param_no) /* * Convert char* privacy value to corresponding bit value */ -static int fixup_privacy(void** param, int param_no) +int fixup_privacy(void** param, int param_no) { str p; unsigned int val; @@ -1779,42 +1770,6 @@ static int fixup_privacy(void** param, int param_no) return 0; }
-/* - * Fix in_list params: subject and list (strings that may contain pvars), - * separator (string) - */ -static int fixup_in_list(void** param, int param_no) -{ - if ((param_no == 1) || (param_no == 2)) return fixup_spve_null(param, 1); - - if (param_no == 3) { - if ((strlen((char *)*param) != 1) || (*((char *)(*param)) == 0)) { - LM_ERR("invalid separator parameter\n"); - return -1; - } - return 0; - } - - LM_ERR("invalid parameter number <%d>\n", param_no); - return -1; -} - -/* - * Free in_list params - */ -static int fixup_free_in_list(void** param, int param_no) -{ - if ((param_no == 1) || (param_no == 2)) { - LM_WARN("free function has not been defined for spve\n"); - return 0; - } - - if (param_no == 3) return 0; - - LM_ERR("invalid parameter number <%d>\n", param_no); - return -1; -} - static int add_header_fixup(void** param, int param_no) { if(param_no==1) @@ -1896,7 +1851,8 @@ static int has_body_f(struct sip_msg *msg, char *type, char *str2 ) return 1; }
-static int is_privacy_f(struct sip_msg *msg, char *_privacy, char *str2 ) + +int is_privacy_f(struct sip_msg *msg, char *_privacy, char *str2 ) { if (parse_privacy(msg) == -1) return -1; @@ -1905,59 +1861,6 @@ static int is_privacy_f(struct sip_msg *msg, char *_privacy, char *str2 )
}
-/* - * Checks if subject is found in list - */ -int in_list_f(struct sip_msg* _m, char* _subject, char* _list, char* _sep) -{ - str subject, list; - int sep; - char *at, *past, *s; - - if (fixup_get_svalue(_m, (gparam_p)_subject, &subject) != 0) { - LM_ERR("cannot get subject value\n"); - return -1; - } else { - if (subject.len == 0) { - LM_ERR("subject cannot be empty string\n"); - return -1; - } - } - - if (fixup_get_svalue(_m, (gparam_p)_list, &list) != 0) { - LM_ERR("cannot get list value\n"); - return -1; - } else { - if (list.len == 0) return -1; - } - - sep = _sep[0]; - - at = list.s; - past = list.s + list.len; - - while (at < past) { - s = index(at, sep); - if (s == NULL) { - if ((subject.len == (past - at)) && - strncmp(at, subject.s, subject.len) == 0) { - return 1; - } else { - return -1; - } - } else { - if ((subject.len == (s - at)) && - strncmp(at, subject.s, subject.len) == 0) { - return 1; - } else { - at = s + 1; - } - } - } - - return -1; -} - static int cmp_str_f(struct sip_msg *msg, char *str1, char *str2 ) { str s1; diff --git a/modules_k/textops/textops.h b/modules_k/textops/textops.h index 39168f4..d0855a5 100644 --- a/modules_k/textops/textops.h +++ b/modules_k/textops/textops.h @@ -30,7 +30,9 @@ int search_f(struct sip_msg*, char*, char*); int search_append_f(struct sip_msg*, char*, char*); int remove_hf_f(struct sip_msg* msg, char* str_hf, char* foo); int add_hf_helper(struct sip_msg* msg, str *str1, str *str2, gparam_p hfval, int mode, gparam_p hfanc); +int is_privacy_f(struct sip_msg *msg, char *privacy, char *str2 );
int fixup_regexp_none(void** param, int param_no); int fixup_free_regexp_none(void** param, int param_no); +int fixup_privacy(void** param, int param_no); #endif /*TEXTOPS_H_*/