1 /* This program is free software; you can redistribute it and/or modify
2  * it under the terms of the GNU General Public License as published by
3  * the Free Software Foundation; version 2 of the License. For a copy,
4  * see http://www.gnu.org/licenses/gpl-2.0.html.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  */
11 
12 #ifndef _LIBLIST_H
13 #define _LIBLIST_H
14 
15 #include <stdbool.h>
16 #include "global.h"
17 #include "ip.h"
18 
19 typedef enum { deny, allow, pwd, unspecified } t_access;
20 typedef enum { tc_data, tc_charlist, tc_accesslist, tc_keyvalue, tc_errorhandler } t_tempdata_type;
21 
22 typedef struct type_http_header {
23 	char *data;
24 	int  length;
25 	int  value_offset;
26 
27 	struct type_http_header *next;
28 } t_http_header;
29 
30 typedef struct type_charlist {
31 	int  size;
32 	char **item;
33 } t_charlist;
34 
35 typedef struct type_accesslist {
36 	t_ip_addr ip;
37 	int netmask;
38 	bool all_ip;
39 	t_access access;
40 
41 	struct type_accesslist *next;
42 } t_accesslist;
43 
44 typedef struct type_keyvalue {
45 	char *key;
46 	char *value;
47 	size_t key_len, value_len;
48 
49 	struct type_keyvalue *next;
50 } t_keyvalue;
51 
52 typedef struct type_tempdata {
53 	void *content;
54 	t_tempdata_type type;
55 
56 	struct type_tempdata *next;
57 } t_tempdata;
58 
59 typedef struct type_ipcounterlist {
60 	t_ip_addr ip;
61 	int count;
62 
63 	struct type_ipcounterlist *next;
64 } t_ipcounterlist;
65 
66 typedef struct type_error_handler {
67 	int  code;
68 	char *handler;
69 	char *parameters;
70 
71 	struct type_error_handler *next;
72 } t_error_handler;
73 
74 t_http_header *parse_http_headers(char *line);
75 char *get_http_header(char *key, t_http_header *http_headers);
76 char *get_referer_header(t_http_header *http_headers);
77 t_http_header *remove_http_headers(t_http_header *http_headers);
78 
79 void init_charlist(t_charlist *list);
80 int  parse_charlist(char *value, t_charlist *list);
81 void copy_charlist(t_charlist *dest, t_charlist *src);
82 bool in_charlist(char *item, t_charlist *list);
83 bool matches_charlist(char *item, t_charlist *list);
84 void remove_charlist(t_charlist *list);
85 
86 t_accesslist *parse_accesslist(char *line, bool pwd_allowed, t_accesslist *list);
87 t_accesslist *remove_accesslist(t_accesslist *list);
88 t_access ip_allowed(t_ip_addr *ip, t_accesslist *list);
89 
90 int  parse_keyvalue(char *line, t_keyvalue **kvlist, char *delimiter);
91 t_keyvalue *remove_keyvaluelist(t_keyvalue *list);
92 
93 int  parse_error_handler(char *line, t_error_handler **handlers);
94 void remove_error_handler(t_error_handler *handler);
95 
96 int  register_tempdata(t_tempdata **tempdata, void *data, t_tempdata_type type);
97 void remove_tempdata(t_tempdata *tempdata);
98 
99 #endif
100