don't know whether it makes sense in general, but it just makes sense for
me ;-) Instead of generating a unique id for *every* request, it seems
better to give the user the possibility of restricting it to some files
(cgi-scripts etc.)
The attached patch works for me, but I'm not sure, that I considered all
implications (subrequests? etc.) However, it does the following:
- introduce the directive UniqueID On|Off, that is allowed everywere
(.htaccess with AllowOverride Options)
- it hooks the id generation additionally into header_parser, so directory
configuration gets a chance to be applied.
- for backwards compatibility I kept the post_read_request hook, that
generates the unique ID, if the server config says "On" (or unset).
Of course, once generated you cannot disable the ID generation; the
apache throws a warning, if someone is trying that.
That means, you have to set globally UniqueID Off, in order to get any
effect due to directory configuration.
If there's something bogus or could be done better, please tell me...
TIA, nd
--
my @japh = (sub{q~Just~},sub{q~Another~},sub{q~Perl~},sub{q~Hacker~});
my $japh = q[sub japh { }]; print join #########################
[ $japh =~ /{(.)}/] -> [0] => map $_ -> () # Andr� Malo #
=> @japh; # http://www.perlig.de/ #
Index: modules/metadata/mod_unique_id.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/metadata/mod_unique_id.c,v
retrieving revision 1.45
diff -u -r1.45 mod_unique_id.c
--- modules/metadata/mod_unique_id.c 15 Jul 2002 08:26:06 -0000 1.45
+++ modules/metadata/mod_unique_id.c 2 Dec 2002 19:13:49 -0000
@@ -85,6 +85,14 @@
unsigned int thread_index;
} unique_id_rec;
+typedef struct {
+ int enabled;
+} unique_id_cfg_rec;
+
+#define UNID_FLAG_OFF 0
+#define UNID_FLAG_ON 1
+#define UNID_FLAG_UNSET 2
+
/* We are using thread_index (the index into the scoreboard), because we
* cannot guarantee the thread_id will be an integer.
*
@@ -162,6 +170,8 @@
static unique_id_rec cur_unique_id;
+module AP_MODULE_DECLARE_DATA unique_id_module;
+
/*
* Number of elements in the structure unique_id_rec.
*/
@@ -333,13 +343,30 @@
unsigned short counter;
const char *e;
int i,j,k;
+ unique_id_cfg_rec *conf;
+
+ if (apr_table_get(r->subprocess_env, "UNIQUE_ID")) {
+ return DECLINED;
+ }
/* copy the unique_id if this is an internal redirect (we're never
* actually called for sub requests, so we don't need to test for
* them) */
- if (r->prev && (e = apr_table_get(r->subprocess_env, "REDIRECT_UNIQUE_ID"))) {
- apr_table_setn(r->subprocess_env, "UNIQUE_ID", e);
- return DECLINED;
+ if (r->prev &&
+ (e = apr_table_get(r->subprocess_env, "REDIRECT_UNIQUE_ID"))) {
+
+ apr_table_setn(r->subprocess_env, "UNIQUE_ID", e);
+ return DECLINED;
+ }
+
+ conf = ap_get_module_config(r->server->module_config, &unique_id_module);
+
+ if (!conf->enabled) {
+ conf = ap_get_module_config(r->per_dir_config, &unique_id_module);
+
+ if (!conf || conf->enabled != UNID_FLAG_ON) {
+ return DECLINED;
+ }
}
new_unique_id.in_addr = cur_unique_id.in_addr;
@@ -391,19 +418,81 @@
return DECLINED;
}
+static void *create_unid_sconfig(apr_pool_t *p, server_rec *dummy)
+{
+ unique_id_cfg_rec *cfg = apr_pcalloc(p, sizeof(unique_id_cfg_rec));
+
+ cfg->enabled = UNID_FLAG_UNSET;
+
+ return (void *)cfg;
+}
+
+static void *create_unid_dconfig(apr_pool_t *p, char *dummy)
+{
+ unique_id_cfg_rec *cfg = apr_pcalloc(p, sizeof(unique_id_cfg_rec));
+
+ cfg->enabled = UNID_FLAG_UNSET;
+
+ return (void *)cfg;
+}
+
+static void *merge_unid_config(apr_pool_t *p, void *basev, void *overridesv)
+{
+ unique_id_cfg_rec *cfg = apr_pcalloc(p, sizeof(unique_id_cfg_rec));
+ unique_id_cfg_rec *base = basev;
+ unique_id_cfg_rec *override = overridesv;
+
+ cfg->enabled = (override->enabled == UNID_FLAG_UNSET)
+ ? base->enabled
+ : override->enabled;
+
+ return (void *)cfg;
+}
+
+static const char *unique_id_flag(cmd_parms *cmd, void *dconf_, int arg)
+{
+ unique_id_cfg_rec *sc = ap_get_module_config(cmd->server->module_config,
+ &unique_id_module);
+ unique_id_cfg_rec *dconf = dconf_;
+
+ if (cmd->path) {
+ if (!arg && sc->enabled) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
+ "\"UniqueID Off\" cannot be used to discard a "
+ "globally generated unique ID in directory "
+ "context.");
+ }
+ else {
+ dconf->enabled = arg ? UNID_FLAG_ON : UNID_FLAG_OFF;
+ }
+ }
+ else {
+ sc->enabled = arg ? UNID_FLAG_ON : UNID_FLAG_OFF;
+ }
+
+ return NULL;
+}
+
+static const command_rec unique_id_cmds[] = {
+ AP_INIT_FLAG("UniqueID", unique_id_flag, NULL, RSRC_CONF | OR_OPTIONS,
+ "turns unique ID generation 'On' (default) or 'Off'"),
+ {NULL}
+};
+
static void register_hooks(apr_pool_t *p)
{
ap_hook_post_config(unique_id_global_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_init(unique_id_child_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_read_request(gen_unique_id, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_header_parser(gen_unique_id, NULL, NULL, APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA unique_id_module = {
STANDARD20_MODULE_STUFF,
- NULL, /* dir config creater */
- NULL, /* dir merger --- default is to override */
- NULL, /* server config */
- NULL, /* merge server configs */
- NULL, /* command apr_table_t */
+ create_unid_dconfig, /* dir config creater */
+ merge_unid_config, /* dir merger --- default is to override */
+ create_unid_sconfig, /* server config */
+ merge_unid_config, /* merge server configs */
+ unique_id_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};