summaryrefslogtreecommitdiff
path: root/src/mod_cml.h
blob: 2185e8dc886373bda813b386875564123242467b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef _MOD_CACHE_H_
#define _MOD_CACHE_H_

#include "buffer.h"
#include "server.h"
#include "response.h"

#include "stream.h"

#define plugin_data mod_cache_plugin_data

typedef enum { UNSET, PART, TIMES, MINUS, PLUS, OR, AND, GT, LT, GE, LE, EQ, NE } tnode_op_t;

typedef enum { T_NODE_VALUE_UNSET, T_NODE_VALUE_LONG, T_NODE_VALUE_STRING } tnode_val_t;

typedef struct {
	tnode_val_t type;
	
	union {
		buffer *str;
		long    lon;
	} data;
} tnode_val;

#define VAL_LONG(x) x->value.data.lon
#define VAL_STRING(x) x->value.data.str

#define IS_LONG(x) ((x->op == UNSET) && (x->value.type == T_NODE_VALUE_LONG))
#define IS_STRING(x) ((x->op == UNSET) && (x->value.type == T_NODE_VALUE_STRING))

typedef struct tnode {
	tnode_val value;
	tnode_op_t op;
	
	struct tnode *l, *r;
} tnode;

typedef struct  {
	tnode_val **ptr;
	
	size_t size;
	size_t used;
} tnode_val_array;

typedef struct {
	buffer *ext;
	
} plugin_config;

typedef struct {
	PLUGIN_DATA;
	
	buffer *basedir;
	
	buffer *trigger_handler;
	
	buffer *session_id;
	
	buffer_array *eval;
	buffer_array *trigger_if;
	buffer_array *output_include;
	
	tnode_val_array *params;
	
	plugin_config **config_storage;
	
	plugin_config conf; 
} plugin_data;

typedef struct {
	char *name;
	size_t params;
	int (*func)(server *srv, connection *con, plugin_data *p, tnode *result);
} cache_trigger_functions;

int cache_parse_parameters(server *srv, connection *con, plugin_data *p, const char *params, size_t param_len, tnode_val_array *res);
int cache_parse(server *srv, connection *con, plugin_data *p, buffer *fn);
int tnode_prepare_long(tnode *t);
int tnode_prepare_string(tnode *t);

tnode_val_array *tnode_val_array_init();
void tnode_val_array_free(tnode_val_array *tva);
void tnode_val_array_reset(tnode_val_array *tva);

#define CACHE_FUNC_PROTO(x) int x(server *srv, connection *con, plugin_data *p, tnode *result)

CACHE_FUNC_PROTO(f_unix_time_now);
CACHE_FUNC_PROTO(f_file_mtime);
CACHE_FUNC_PROTO(f_mysql_escape);
CACHE_FUNC_PROTO(f_mysql_connect);
CACHE_FUNC_PROTO(f_mysql_query);

#endif