Hi everyone, Am I missing something obvious for modules on MacOSX? The attached simple example of reading the request->per_dir_config works fine on Windows and other Unix platforms but not at all when built for Apache on MacOS X platforms.
All this module does is setup a header with the value from a directory configuration parameter, simple enough but doesn't work due to the per_dir_config for the module being always NULL. I compile the example through apxs both for 32 and 64 bit versions of Apache, prebuilt Apache binaries and Apache built from source by me. The result is always the same. To compile for example for 32bit Apache on MacOSX: apxs -i -a -c -Wc,"-arch i386" -Wl,"-arch i386" testmodule.c Before anyone mentions it, yes I know the example here is incomplete and will make multiple header entries in any number of cases, but thats not the point. Is this a real problem on MacOSX, or am I missing something? :) To test the module just add the following parameter to the default directory configuration of any out-of-the-box Apache 2.2.x with the module installed. DirHeaderName TestingTesting123 /Anthony
#include "httpd.h" #include "http_config.h" #include "http_log.h" #include "apr_strings.h" module AP_MODULE_DECLARE_DATA test_module; /* * Data types for per-directory and per-server configuration */ typedef struct { char *header_name; /* Header Name */ } dir_config_rec; typedef struct { char *header_name; /* Header Name */ } srv_config_rec; static int addHeaders(request_rec *request) { module *m = &test_module; dir_config_rec *dir= (dir_config_rec *) ap_get_module_config(request->per_dir_config, &test_module); srv_config_rec *srv= (srv_config_rec *) ap_get_module_config(request->server->module_config, &test_module); ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "Module Index (addHeaders): %s -> %d", request->uri, m->module_index); apr_table_set(request->headers_out, srv->header_name, "Hello, world!"); if( dir != NULL ) { apr_table_set(request->headers_out, dir->header_name, "Hello, world!"); } else { ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "Per_dir_config for %s was NULL!!!", request->uri); } return OK; } static void reg_hooks(apr_pool_t *p) { ap_hook_fixups(addHeaders, NULL, NULL, APR_HOOK_MIDDLE); } static void *create_dir_config(apr_pool_t *p, char *d) { module *m = &test_module; dir_config_rec *dir= (dir_config_rec *) apr_palloc(p, sizeof(dir_config_rec)); dir->header_name = apr_pstrdup(p, "X-Dir-Test"); ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "Module Index (create_dir_config): %s -> %d", d, m->module_index); return dir; } static void *create_srv_config( apr_pool_t *p, server_rec *s) { srv_config_rec *srv= (srv_config_rec *) apr_palloc(p, sizeof(srv_config_rec)); srv->header_name = apr_pstrdup(p, "X-Srv-Test"); return (void *)srv; } /* * Config file commands that this module can handle */ static const command_rec setup_cmds[] = { AP_INIT_TAKE1("DirHeaderName", ap_set_string_slot, (void *)APR_OFFSETOF(dir_config_rec, header_name), OR_AUTHCFG, "Name of the header in this directory."), { NULL } }; module AP_MODULE_DECLARE_DATA test_module = { STANDARD20_MODULE_STUFF, create_dir_config, /* create per-directory config structures */ NULL, /* merge per-directory config structures */ create_srv_config, /* create per-server config structures */ NULL, /* merge per-server config structures */ setup_cmds, /* command handlers */ reg_hooks /* register hooks */ };