Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 144 lines (114 sloc) 3.263 kB
72d9383 @alobbs Adds a new 'OR' Virtual Server match plug-in. The server and QA side
alobbs authored
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
920e20b @alobbs Happy new year!
alobbs authored
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
72d9383 @alobbs Adds a new 'OR' Virtual Server match plug-in. The server and QA side
alobbs authored
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
23 */
24
25 #include "common-internal.h"
26 #include "vrule_or.h"
27 #include "plugin_loader.h"
28 #include "connection.h"
29 #include "connection-protected.h"
30 #include "util.h"
31
32 #define ENTRIES "vrule,or"
33
34 PLUGIN_INFO_VRULE_EASIEST_INIT(v_or);
35
36
37 static ret_t
38 match (cherokee_vrule_or_t *vrule,
39 cherokee_buffer_t *host,
40 cherokee_connection_t *conn)
41 {
42 ret_t ret;
43
44 /* It only needs one of the sides to match.
45 */
46 ret = cherokee_vrule_match (vrule->left, host, conn);
47 if (ret != ret_deny)
48 return ret;
49
50 /* It didn't match, it is time for the right side
51 */
52 return cherokee_vrule_match (vrule->right, host, conn);
53 }
54
55
56 static ret_t
57 configure_branch (cherokee_config_node_t *conf,
58 cherokee_virtual_server_t *vsrv,
59 const char *branch,
60 cherokee_vrule_t **branch_vrule)
61 {
62 ret_t ret;
63 cherokee_config_node_t *subconf = NULL;
64
65 /* Get the configuration sub-tree
66 */
67 ret = cherokee_config_node_get (conf, branch, &subconf);
68 if (ret != ret_ok)
69 return ret;
70
71 /* Instance the sub-rule match
72 */
73 ret = cherokee_virtual_server_new_vrule (vsrv, subconf, branch_vrule);
74 if (ret != ret_ok)
75 return ret;
76
77 return ret_ok;
78 }
79
80
81 static ret_t
82 configure (cherokee_vrule_or_t *vrule,
83 cherokee_config_node_t *conf,
84 cherokee_virtual_server_t *vsrv)
85 {
86 ret_t ret;
87
88 ret = configure_branch (conf, vsrv, "right", &vrule->right);
89 if (ret != ret_ok)
90 return ret;
91
92 ret = configure_branch (conf, vsrv, "left", &vrule->left);
93 if (ret != ret_ok)
94 return ret;
95
96 return ret_ok;
97 }
98
99
100 static ret_t
101 _free (void *p)
102 {
103 ret_t ret;
104 cherokee_boolean_t error = false;
105 cherokee_vrule_or_t *vrule = VRULE_OR(p);
106
107 if (vrule->left) {
108 ret = cherokee_vrule_free (vrule->left);
109 if (ret != ret_ok) error = true;
110 }
111
112 if (vrule->right) {
113 ret = cherokee_vrule_free (vrule->right);
114 if (ret != ret_ok) error = true;
115 }
116
117 return (error)? ret_error : ret_ok;
118 }
119
120
121 ret_t
122 cherokee_vrule_v_or_new (cherokee_vrule_t **vrule)
123 {
124 CHEROKEE_NEW_STRUCT (n, vrule_or);
125
126 /* Parent class constructor
127 */
128 cherokee_vrule_init_base (VRULE(n), PLUGIN_INFO_PTR(v_or));
129
130 /* Virtual methods
131 */
132 VRULE(n)->match = (vrule_func_match_t) match;
133 VRULE(n)->configure = (vrule_func_configure_t) configure;
134 MODULE(n)->free = (module_func_free_t) _free;
135
136 /* Properties
137 */
138 n->left = NULL;
139 n->right = NULL;
140
141 *vrule = VRULE(n);
142 return ret_ok;
143 }
Something went wrong with that request. Please try again.