| 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 |
* |
|---|
| 8 |
* Copyright (C) 2001-2008 Alvaro Lopez Ortega |
|---|
| 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|---|
| 22 |
* USA |
|---|
| 23 |
*/ |
|---|
| 24 |
|
|---|
| 25 |
#include "common-internal.h" |
|---|
| 26 |
#include "config_entry.h" |
|---|
| 27 |
|
|---|
| 28 |
#include "access.h" |
|---|
| 29 |
#include "http.h" |
|---|
| 30 |
#include "util.h" |
|---|
| 31 |
#include "encoder.h" |
|---|
| 32 |
|
|---|
| 33 |
#define ENTRIES "config,rules" |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
typedef enum { |
|---|
| 37 |
table_handler, |
|---|
| 38 |
table_validator |
|---|
| 39 |
} prop_table_types_t; |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
/* Implements _new() and _free() |
|---|
| 43 |
*/ |
|---|
| 44 |
CHEROKEE_ADD_FUNC_NEW (config_entry); |
|---|
| 45 |
CHEROKEE_ADD_FUNC_FREE (config_entry); |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
ret_t |
|---|
| 49 |
cherokee_config_entry_init (cherokee_config_entry_t *entry) |
|---|
| 50 |
{ |
|---|
| 51 |
entry->handler_new_func = NULL; |
|---|
| 52 |
entry->handler_properties = NULL; |
|---|
| 53 |
entry->handler_methods = http_unknown; |
|---|
| 54 |
|
|---|
| 55 |
entry->validator_new_func = NULL; |
|---|
| 56 |
entry->validator_properties = NULL; |
|---|
| 57 |
entry->auth_realm = NULL; |
|---|
| 58 |
|
|---|
| 59 |
entry->access = NULL; |
|---|
| 60 |
entry->authentication = http_auth_nothing; |
|---|
| 61 |
entry->only_secure = false; |
|---|
| 62 |
|
|---|
| 63 |
entry->document_root = NULL; |
|---|
| 64 |
entry->users = NULL; |
|---|
| 65 |
|
|---|
| 66 |
entry->expiration = cherokee_expiration_none; |
|---|
| 67 |
entry->expiration_time = 0; |
|---|
| 68 |
|
|---|
| 69 |
entry->encoders = NULL; |
|---|
| 70 |
|
|---|
| 71 |
return ret_ok; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
ret_t |
|---|
| 76 |
cherokee_config_entry_mrproper (cherokee_config_entry_t *entry) |
|---|
| 77 |
{ |
|---|
| 78 |
if (entry->handler_properties != NULL) { |
|---|
| 79 |
cherokee_module_props_free (entry->handler_properties); |
|---|
| 80 |
entry->handler_properties = NULL; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
if (entry->validator_properties != NULL) { |
|---|
| 84 |
cherokee_module_props_free (entry->validator_properties); |
|---|
| 85 |
entry->validator_properties = NULL; |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
if (entry->access != NULL) { |
|---|
| 89 |
cherokee_access_free (entry->access); |
|---|
| 90 |
entry->access = NULL; |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
if (entry->document_root != NULL) { |
|---|
| 94 |
cherokee_buffer_free (entry->document_root); |
|---|
| 95 |
entry->document_root = NULL; |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
if (entry->auth_realm != NULL) { |
|---|
| 99 |
cherokee_buffer_free (entry->auth_realm); |
|---|
| 100 |
entry->document_root = NULL; |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
if (entry->users != NULL) { |
|---|
| 104 |
cherokee_avl_free (entry->users, free); |
|---|
| 105 |
entry->users = NULL; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
if (entry->encoders) { |
|---|
| 109 |
cherokee_avl_mrproper (entry->encoders, NULL); |
|---|
| 110 |
entry->encoders = NULL; |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
return ret_ok; |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
ret_t |
|---|
| 117 |
cherokee_config_entry_add_encoder (cherokee_config_entry_t *entry, |
|---|
| 118 |
cherokee_buffer_t *name, |
|---|
| 119 |
cherokee_plugin_info_t *plugin_info) |
|---|
| 120 |
{ |
|---|
| 121 |
if (entry->encoders == NULL) { |
|---|
| 122 |
cherokee_avl_new (&entry->encoders); |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
cherokee_avl_add (entry->encoders, name, (void*)plugin_info->instance); |
|---|
| 126 |
return ret_ok; |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
ret_t |
|---|
| 131 |
cherokee_config_entry_set_handler (cherokee_config_entry_t *entry, |
|---|
| 132 |
cherokee_plugin_info_handler_t *plugin_info) |
|---|
| 133 |
{ |
|---|
| 134 |
return_if_fail (plugin_info != NULL, ret_error); |
|---|
| 135 |
|
|---|
| 136 |
if (PLUGIN_INFO(plugin_info)->type != cherokee_handler) { |
|---|
| 137 |
PRINT_ERROR ("Directory '%s' has not a handler module!\n", entry->document_root->buf); |
|---|
| 138 |
return ret_error; |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
entry->handler_new_func = PLUGIN_INFO(plugin_info)->instance; |
|---|
| 142 |
entry->handler_methods = plugin_info->valid_methods; |
|---|
| 143 |
|
|---|
| 144 |
return ret_ok; |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
ret_t |
|---|
| 149 |
cherokee_config_entry_complete (cherokee_config_entry_t *entry, cherokee_config_entry_t *source) |
|---|
| 150 |
{ |
|---|
| 151 |
/* This method is assigning pointer to the server data. The |
|---|
| 152 |
* target entry properties must NOT be freed. Take care. |
|---|
| 153 |
*/ |
|---|
| 154 |
|
|---|
| 155 |
if (! entry->handler_properties) |
|---|
| 156 |
entry->handler_properties = source->handler_properties; |
|---|
| 157 |
|
|---|
| 158 |
if (! entry->validator_properties) |
|---|
| 159 |
entry->validator_properties = source->validator_properties; |
|---|
| 160 |
|
|---|
| 161 |
if (! entry->handler_new_func) { |
|---|
| 162 |
entry->handler_new_func = source->handler_new_func; |
|---|
| 163 |
entry->handler_methods = source->handler_methods; |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
if (entry->authentication == 0) |
|---|
| 167 |
entry->authentication = source->authentication; |
|---|
| 168 |
|
|---|
| 169 |
if (entry->only_secure == false) |
|---|
| 170 |
entry->only_secure = source->only_secure; |
|---|
| 171 |
|
|---|
| 172 |
if (! entry->access) |
|---|
| 173 |
entry->access = source->access; |
|---|
| 174 |
|
|---|
| 175 |
if (! entry->validator_new_func) |
|---|
| 176 |
entry->validator_new_func = source->validator_new_func; |
|---|
| 177 |
|
|---|
| 178 |
if (! entry->document_root) |
|---|
| 179 |
entry->document_root = source->document_root; |
|---|
| 180 |
|
|---|
| 181 |
if (! entry->auth_realm) |
|---|
| 182 |
entry->auth_realm = source->auth_realm; |
|---|
| 183 |
|
|---|
| 184 |
if (! entry->users) |
|---|
| 185 |
entry->users = source->users; |
|---|
| 186 |
|
|---|
| 187 |
if ((entry->expiration == cherokee_expiration_none) && |
|---|
| 188 |
(source->expiration != cherokee_expiration_none)) |
|---|
| 189 |
{ |
|---|
| 190 |
entry->expiration = source->expiration; |
|---|
| 191 |
entry->expiration_time = source->expiration_time; |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
if (! entry->encoders) |
|---|
| 195 |
entry->encoders = source->encoders; |
|---|
| 196 |
|
|---|
| 197 |
return ret_ok; |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
ret_t |
|---|
| 202 |
cherokee_config_entry_print (cherokee_config_entry_t *entry) |
|---|
| 203 |
{ |
|---|
| 204 |
printf ("document_root: %s\n", entry->document_root ? entry->document_root->buf : ""); |
|---|
| 205 |
printf ("only_secure: %d\n", entry->only_secure); |
|---|
| 206 |
printf ("access: %p\n", entry->access); |
|---|
| 207 |
printf ("handler_new %p\n", entry->handler_new_func); |
|---|
| 208 |
printf ("http_methods: 0x%x\n", entry->handler_methods); |
|---|
| 209 |
printf ("handler_properties: %p\n", entry->handler_properties); |
|---|
| 210 |
printf ("validator_new: %p\n", entry->validator_new_func); |
|---|
| 211 |
printf ("validator_properties: %p\n", entry->validator_properties); |
|---|
| 212 |
printf ("auth_realm: %s\n", entry->auth_realm ? entry->auth_realm->buf : ""); |
|---|
| 213 |
printf ("users: %p\n", entry->users); |
|---|
| 214 |
printf ("expiration type: %d\n", entry->expiration); |
|---|
| 215 |
printf ("expiration_time %lu\n", entry->expiration_time); |
|---|
| 216 |
printf ("encoders_accepted %p\n", entry->encoders); |
|---|
| 217 |
|
|---|
| 218 |
return ret_ok; |
|---|
| 219 |
} |
|---|