1 #ifndef __FILTERS_H
2 #define __FILTERS_H
3 #include "c_icap/access.h"
4 #include "c_icap/acl.h"
5 #include "c_icap/header.h"
6 #include "c_icap/txt_format.h"
7 #include "c_icap/ci_regex.h"
8 
9 enum srv_cf_action_operation {CF_AC_NONE, CF_AC_BLOCK, CF_AC_ALLOW, CF_AC_ADD_HEADER, CF_AC_REPLACE};
10 
11 //typedef ci_list_t;
12 typedef struct srv_cf_user_filter{
13     char *name;
14     ci_list_t *data; /* list of srv_cf_user_filter_data_t elements*/
15 } srv_cf_user_filter_t;
16 
17 enum srv_cf_operator {CF_OP_LESS, CF_OP_GREATER, CF_OP_EQUAL};
18 typedef struct srv_cf_action_cfg {
19     const srv_cf_user_filter_t *matchingFilter;
20     char header[128];
21     int action;
22     int scoreOperator;
23     int score;
24     char template[512];
25     char **replaceInfo;
26 } srv_cf_action_cfg_t;
27 
28 const char *srv_cf_action_str(int action);
29 int srv_cf_action_parse(const char *str);
30 const srv_cf_user_filter_t *srv_cf_action_score_parse(const char *str, int *scoreOperator, int *score);
31 
32 void srv_cf_filters_reset();
33 void srv_cf_filters_debug_print(int dlevel);
34 
35 typedef struct srv_cf_filter_apply {
36     const srv_cf_user_filter_t *filter;
37     int needReplaceParts;
38 } srv_cf_filter_apply_t;
39 
40 typedef struct srv_cf_profile {
41     char *name;
42     int anyContentType;
43     int64_t maxBodyData;
44     ci_access_entry_t *access_list;
45     ci_list_t *actions; /*ci_list of srv_cf_action_cfg entries*/
46     ci_list_t *filters; /*ci_list of srv_cf_filter_apply_t. Filters to be applied*/
47     ci_list_t *replaceInfo; /*ci_list of (const char *). The infos/tags holding the replacement info*/
48 } srv_cf_profile_t;
49 
50 const srv_cf_profile_t *srv_srv_cf_profile_search(const char *name);
51 const srv_cf_profile_t *srv_srv_cf_profile_select(ci_request_t *req);
52 void srv_srv_cf_profiles_reset();
53 int srv_cf_cfg_profile(const char *directive, const char **argv, void *setdata);
54 int srv_cf_cfg_profile_option(const char *directive, const char **argv, void *setdata);
55 int srv_cf_cfg_profile_access(const char *directive, const char **argv, void *setdata);
56 int srv_cf_cfg_match(const char *directive,const char **argv,void *setdata);
57 int srv_cf_cfg_action(const char *directive,const char **argv,void *setdata);
58 
59 typedef struct srv_cf_results {
60     const srv_cf_action_cfg_t *action;
61     int action_score;
62     int action_matchesCount;
63     ci_list_t *scores;
64     ci_membuf_t *replaceBody;
65     ci_headers_list_t *addHeaders;
66 } srv_cf_results_t;
67 
68 int srv_cf_print_scores_list(ci_list_t *scores, char *buf, int buf_size);
69 
70 int srv_cf_apply_actions(ci_request_t *req, const srv_cf_profile_t *prof, ci_membuf_t *body, srv_cf_results_t *result, struct ci_fmt_entry *fmtTable);
71 
72 
73 enum srv_cf_filters {BodyRegex, HeaderRegex, RequestHeaderRegex, UrlRegex};
74 
75 typedef struct srv_cf_user_filter_data {
76     int type; /*of type srv_cf_filters*/
77     char *header; /*header name or NULL for all headers*/
78     char *regex_str;
79     int regex_flags;
80     ci_regex_t regex_compiled;
81     int recursive;
82     /*Members for tagging or score or etc....*/
83     int score;
84     ci_str_array_t *infoStrings;
85 } srv_cf_user_filter_data_t;
86 
87 
88 #endif //__FILTERS_H
89