2
* rivetConf.c - Functions for accessing Rivet configuration variables
4
* Functions in this file implement core function to be called mainly
5
* by the Rivet_InspectCmd function, which implments command 'inspect'
9
/* Copyright 2002-2004 The Apache Software Foundation
11
Licensed under the Apache License, Version 2.0 (the "License");
12
you may not use this file except in compliance with the License.
13
You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
28
#include <apr_errno.h>
29
#include <apr_strings.h>
30
#include <apr_tables.h>
33
#include "http_config.h"
34
#include "http_request.h"
35
#include "http_core.h"
36
#include "http_main.h"
37
#include "util_script.h"
38
#include "http_config.h"
40
#include "mod_rivet.h"
42
static const char* confDirectives[] =
56
"SeparateVirtualInterps",
57
"HonorHeaderOnlyRequests",
74
separate_virtual_interps,
75
honor_header_only_requests,
80
* -- Rivet_ReadConfParameter
82
* This procedure reads a single field named par_name from
83
* rivet_server_conf structure and returns a Tcl_Obj pointer
84
* containing the field value. See confDirectives for a list
85
* of possible names. If the procedure is queried for a non
86
* existing field a NULL is returned.
90
* - interp: pointer to the current Tcl interpreter structure
91
* - rsc: a pointer to a rivet_server_conf structure
92
* - par_name: parameter name (as listed in confDirectives)
96
* - A Tcl_Obj pointer to the parameter value whose refCount is
97
* set to 1 before returning to the caller
102
Rivet_ReadConfParameter ( Tcl_Interp* interp,
103
rivet_server_conf* rsc,
109
if (Tcl_GetIndexFromObj(interp, par_name, confDirectives,
110
"<one of conf directives>", 0, ¶meter_i) == TCL_ERROR) {
116
case server_init_script:
118
par_value = rsc->rivet_server_init_script;
121
case global_init_script:
123
par_value = rsc->rivet_global_init_script;
126
case child_init_script:
128
par_value = rsc->rivet_child_init_script;
131
case child_exit_script:
133
par_value = rsc->rivet_child_exit_script;
138
par_value = rsc->rivet_before_script;
143
par_value = rsc->rivet_after_script;
146
case after_every_script:
148
par_value = rsc->after_every_script;
153
par_value = rsc->rivet_abort_script;
158
par_value = rsc->rivet_error_script;
163
par_value = Tcl_NewIntObj(rsc->upload_max);
166
case upload_directory:
168
par_value = Tcl_NewStringObj(rsc->upload_dir,-1);
171
case upload_files_to_var:
173
par_value = Tcl_NewIntObj(rsc->upload_files_to_var);
176
case separate_virtual_interps:
178
par_value = Tcl_NewIntObj(rsc->separate_virtual_interps);
181
case honor_header_only_requests:
183
par_value = Tcl_NewIntObj(rsc->honor_header_only_reqs);
192
if (par_value == NULL)
194
par_value=Tcl_NewStringObj("<undef>",-1);
197
Tcl_IncrRefCount(par_value);
203
* Rivet_ReadConfTable:
205
* This procedure builds a key-value list from an apr table
206
* It's called by Rivet_BuildConfDictionary to read theRivet
207
* configuration tables but it can work for every apr table
211
* - interp: Tcl_Interp pointer
212
* - table: an apr_table_t pointer
216
Tcl_Obj* Rivet_ReadConfTable ( Tcl_Interp* interp,
221
apr_array_header_t *arr;
222
apr_table_entry_t *elts;
224
int tcl_status = TCL_OK;
225
Tcl_Obj* keyval_list = Tcl_NewObj();
227
Tcl_IncrRefCount(keyval_list);
229
arr = (apr_array_header_t*) apr_table_elts( table );
230
elts = (apr_table_entry_t *) arr->elts;
234
if (Tcl_IsShared(keyval_list))
236
fprintf(stderr,"building duplicate keyval_list\n");
237
keyval_list = Tcl_DuplicateObj(keyval_list);
241
for (i = 0; i < nelts; i++)
243
key = Tcl_NewStringObj( elts[i].key, -1);
244
val = Tcl_NewStringObj( elts[i].val, -1);
245
Tcl_IncrRefCount(key);
246
Tcl_IncrRefCount(val);
248
tcl_status = Tcl_ListObjAppendElement (interp,keyval_list,key);
249
if (tcl_status == TCL_ERROR)
251
Tcl_DecrRefCount(keyval_list);
252
Tcl_DecrRefCount(key);
253
Tcl_DecrRefCount(val);
257
tcl_status = Tcl_ListObjAppendElement (interp,keyval_list,val);
258
if (tcl_status == TCL_ERROR)
260
Tcl_DecrRefCount(keyval_list);
261
Tcl_DecrRefCount(key);
262
Tcl_DecrRefCount(val);
266
Tcl_DecrRefCount(key);
267
Tcl_DecrRefCount(val);
275
* -- Rivet_BuildConfDictionary
277
* Parameters set in the configuration files are collected in three
278
* APR tables by Rivet_ServerConf,Rivet_DirConf and Rivet_UserConf.
282
* - interp: Tcl_Interp pointer
283
* - rivet_conf: pointer to a rivet_server_conf structure as
284
* returned by Rivet_GetConf
288
* - Tcl dictionary storing the dir/user/server configuration. The
289
* dictionary refCount is incremented
293
Tcl_Obj* Rivet_BuildConfDictionary ( Tcl_Interp* interp,
294
rivet_server_conf* rivet_conf)
296
apr_table_t* conf_tables[3];
297
Tcl_Obj* keyval_list = NULL;
298
Tcl_Obj* key_list[2];
300
Tcl_Obj* conf_dict = Tcl_NewObj();
302
static const char* section_names[] =
316
conf_tables[0] = rivet_conf->rivet_dir_vars;
317
conf_tables[1] = rivet_conf->rivet_user_vars;
318
conf_tables[2] = rivet_conf->rivet_server_vars;
320
Tcl_IncrRefCount(conf_dict);
322
for (it=0; it < 3; it++)
324
keyval_list = Rivet_ReadConfTable(interp,conf_tables[it]);
326
if (keyval_list != NULL)
329
Tcl_Obj** objArrayPnt;
333
key_list[0] = Tcl_NewStringObj(section_names[it],-1);
334
Tcl_IncrRefCount(key_list[0]);
336
Tcl_ListObjGetElements(interp,keyval_list,&objArrayCnt,&objArrayPnt);
337
for (i=0; i < objArrayCnt; i+=2)
339
key_list[1] = objArrayPnt[i];
340
val = objArrayPnt[i+1];
342
Tcl_IncrRefCount(key_list[1]);
343
Tcl_IncrRefCount(val);
345
Tcl_DictObjPutKeyList(interp,conf_dict,2,key_list,val);
347
Tcl_DecrRefCount(key_list[1]);
348
Tcl_DecrRefCount(val);
350
Tcl_DecrRefCount(key_list[0]);
351
Tcl_DecrRefCount(keyval_list);
364
* Rivet_CurrentConfDict
366
* This function is called by Rivet_InspectCmd which implements command
367
* '::rivet::inspect -all'. The function returns a dictionary where every
368
* parameter name (confDirectives) is associated to its value stored in
369
* the rivet_server_conf as returned by Rivet_GetConf
373
* - interp: Tcl interpreter pointer
374
* - rivet_conf: a pointer to a rivet_server_conf structure
378
* - a Tcl_Obj* pointer to a dictionary. The dictionary object
379
* refCount is set to 1
382
Tcl_Obj* Rivet_CurrentConfDict ( Tcl_Interp* interp,
383
rivet_server_conf* rivet_conf)
385
Tcl_Obj* dictObj = Tcl_NewObj();
387
static const char** p;
389
Tcl_IncrRefCount(dictObj);
391
for (p = confDirectives; (*p) != NULL; p++)
395
par_name = Tcl_NewStringObj(*p,-1);
396
Tcl_IncrRefCount(par_name);
398
par_value = Rivet_ReadConfParameter(interp,rivet_conf,par_name);
399
if (par_value != NULL)
401
Tcl_DictObjPut(interp,dictObj,par_name,par_value);
402
Tcl_DecrRefCount(par_value);
406
Tcl_Obj* message = Tcl_NewStringObj("Invalid configuration option: ",-1);
408
Tcl_IncrRefCount(message);
409
Tcl_AppendObjToObj(message,par_name);
410
Tcl_AddErrorInfo(interp, Tcl_GetStringFromObj(message,NULL));
412
Tcl_DecrRefCount(message);
413
Tcl_DecrRefCount(par_name);
414
Tcl_DecrRefCount(dictObj);
418
Tcl_DecrRefCount(par_name);