bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / native / common / jk_uri_worker_map.h
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17
18 /***************************************************************************
19  * Description: URI to worker mapper header file                           *
20  * Author:      Gal Shachor <shachor@il.ibm.com>                           *
21  * Version:     $Revision: 705283 $                                           *
22  ***************************************************************************/
23
24 #ifndef JK_URI_WORKER_MAP_H
25 #define JK_URI_WORKER_MAP_H
26
27
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif                          /* __cplusplus */
32
33 #include "jk_global.h"
34 #include "jk_map.h"
35 #include "jk_logger.h"
36 #include "jk_mt.h"
37
38 #define MATCH_TYPE_EXACT            0x0001
39 /* deprecated
40 #define MATCH_TYPE_CONTEXT          0x0002
41  */
42 /* match all context path URIs with a path component suffix */
43 /* deprecated
44 #define MATCH_TYPE_CONTEXT_PATH     0x0004
45  */
46 /* deprecated
47 #define MATCH_TYPE_SUFFIX           0x0010
48  */
49 /* match all URIs of the form *ext */
50 /* deprecated
51 #define MATCH_TYPE_GENERAL_SUFFIX   0x0020
52  */
53 /* match multiple wild characters (*) and (?) */
54 #define MATCH_TYPE_WILDCHAR_PATH    0x0040
55 #define MATCH_TYPE_NO_MATCH         0x1000
56 #define MATCH_TYPE_DISABLED         0x2000
57 /* deprecated
58 #define MATCH_TYPE_STOPPED          0x4000
59  */
60
61 #define SOURCE_TYPE_WORKERDEF       0x0001
62 #define SOURCE_TYPE_JKMOUNT         0x0002
63 #define SOURCE_TYPE_URIMAP          0x0003
64 #define SOURCE_TYPE_DISCOVER        0x0004
65 #define SOURCE_TYPE_TEXT_WORKERDEF  ("worker definition")
66 #define SOURCE_TYPE_TEXT_JKMOUNT    ("JkMount")
67 #define SOURCE_TYPE_TEXT_URIMAP     ("uriworkermap")
68 #define SOURCE_TYPE_TEXT_DISCOVER   ("ajp14")
69
70 #define JK_MAX_URI_LEN              4095
71
72 struct rule_extension
73 {
74     /* reply_timeout overwrite */
75     int reply_timeout;
76     /* activation state overwrites for load balancers */
77     /* Number of elements in the array activations. */
78     int activation_size;
79     /* Dynamically allocated array with one entry per lb member. */
80     int *activation;
81     /* Temporary storage for the original extension strings. */
82     char *active;
83     char *disabled;
84     char *stopped;
85     /* fail_on_status overwrites */
86     /* Number of elements in the array fail_on_status. */
87     int fail_on_status_size;
88     /* Dynamically allocated array with one entry per status. */
89     int *fail_on_status;
90     /* Temporary storage for the original extension strings. */
91     char *fail_on_status_str;
92     /* Use server error pages for responses >= 400. */
93     int use_server_error_pages;
94 };
95 typedef struct rule_extension rule_extension_t;
96
97 struct uri_worker_record
98 {
99     /* Original uri for logging */
100     char *uri;
101
102     /* Name of worker mapped */
103     const char *worker_name;
104
105     /* Base context */
106     const char *context;
107
108     /* Match type */
109     unsigned int match_type;
110
111     /* Definition source type */
112     unsigned int source_type;
113
114     /* char length of the context */
115     size_t context_len;
116
117     /* extended mapping properties */
118     rule_extension_t extensions;
119 };
120 typedef struct uri_worker_record uri_worker_record_t;
121
122 struct jk_uri_worker_map
123 {
124     /* Memory Pool */
125     jk_pool_t p;
126     jk_pool_atom_t buf[BIG_POOL_SIZE];
127
128     /* Index 0 or 1, which map instance do we use */
129     /* Needed to make map reload more atomically */
130     int index;
131
132     /* Memory Pool - cleared when doing reload */
133     /* Use this pool to allocate objects, that are deleted */
134     /* when the map gets dynamically reloaded from uriworkermap.properties. */
135     jk_pool_t p_dyn[2];
136     jk_pool_atom_t buf_dyn[2][BIG_POOL_SIZE];
137
138     /* map URI->WORKER */
139     uri_worker_record_t **maps[2];
140     
141     /* Map Number */
142     unsigned int size[2];
143
144     /* Map Capacity */
145     unsigned int capacity[2];
146
147     /* NoMap Number */
148     unsigned int nosize[2];
149
150     /* Dynamic config support */
151
152     JK_CRIT_SEC cs;
153     /* should we forward potentially unsafe URLs */
154     int reject_unsafe;    
155     /* uriworkermap filename */
156     const char *fname;    
157     /* uriworkermap reload check interval */
158     int reload;    
159     /* Last modified time */
160     time_t  modified;
161     /* Last checked time */
162     time_t  checked;
163 };
164 typedef struct jk_uri_worker_map jk_uri_worker_map_t;
165
166 const char *uri_worker_map_get_source(uri_worker_record_t *uwr, jk_logger_t *l);
167
168 char *uri_worker_map_get_match(uri_worker_record_t *uwr, char *buf, jk_logger_t *l);
169
170 int uri_worker_map_alloc(jk_uri_worker_map_t **uw_map,
171                          jk_map_t *init_data, jk_logger_t *l);
172
173 int uri_worker_map_free(jk_uri_worker_map_t **uw_map, jk_logger_t *l);
174
175 int uri_worker_map_open(jk_uri_worker_map_t *uw_map,
176                         jk_map_t *init_data, jk_logger_t *l);
177
178 void uri_worker_map_switch(jk_uri_worker_map_t *uw_map, jk_logger_t *l);
179
180 void uri_worker_map_ext(jk_uri_worker_map_t *uw_map, jk_logger_t *l);
181
182 int uri_worker_map_add(jk_uri_worker_map_t *uw_map,
183                        const char *puri, const char *worker,
184                        unsigned int source_type, jk_logger_t *l);
185
186 const char *map_uri_to_worker(jk_uri_worker_map_t *uw_map,
187                               const char *uri, const char *vhost,
188                               jk_logger_t *l);
189
190 const char *map_uri_to_worker_ext(jk_uri_worker_map_t *uw_map,
191                                   const char *uri, const char *vhost,
192                                   rule_extension_t **extensions,
193                                   int *index,
194                                   jk_logger_t *l);
195
196 rule_extension_t *get_uri_to_worker_ext(jk_uri_worker_map_t *uw_map,
197                                         int index);
198
199 int uri_worker_map_load(jk_uri_worker_map_t *uw_map,
200                         jk_logger_t *l);
201
202 int uri_worker_map_update(jk_uri_worker_map_t *uw_map,
203                           int force, jk_logger_t *l);
204
205 #ifdef __cplusplus
206 }
207 #endif    /* __cplusplus */
208 #endif    /* JK_URI_WORKER_MAP_H */