# Include "httpd. h"
# Include "http_config.h"
# Include "http_protocol.h"
# Include "ap_config.h"
/* Header file. This article uses the ap_rprintf function */
# Include "apr. h"
# Include "apr_lib.h"
# Include "apr_strings.h"
# Include "apr_want.h"
// The configuration information of this module defines a structure.
Typedef struct
{
Short IsAll;
Const char * gpfpath;
} Auth_jira_conf;
// Declare the module name
Module AP_MODULE_DECLARE_DATA pathtest_module;
// The actual handler used for testing. Output the configuration information read from the configuration file.
Static int pathtest_handler (request_rec * r)
{
R-> content_type = "text/html ";
// Retrieve the conf data
Auth_jira_conf * conf = ap_get_module_config (r-> per_dir_config,
& Pathtest_module );
Ap_rprintf (r, "IsAll: % d \ n", conf-> IsAll );
Ap_rprintf (r, "path: % s", conf-> gpfpath );
Return OK;
}
Static void pathtest_register_hooks (apr_pool_t * p)
{
Ap_hook_handler (pathtest_handler, NULL, NULL, APR_HOOK_MIDDLE );
}
/* Set the read/write method for the IsAll field */
Static const char * set_authjira_is_all_check (pai_parms * cmd,
Void * mconfig,
Int arg)
{
Auth_jira_conf * conf = (auth_jira_conf *) mconfig;
Conf-> IsAll = arg;
Return NULL;
}
/* Read the string method for setting a file. For a file, determine whether the file is valid */
Static const char * set_jira_group_file (pai_parms * cmd,
Void * mconfig,
Const char * name)
{
Auth_jira_conf * conf = (auth_jira_conf *) mconfig;
/* Ap_configfile_t * f = NULL;
Apr_status_t status;
If (strlen (name) <= 0)
Return "File can not be null .";
Status = ap_pcfg_openfile (& f, cmd-> pool, name );
If (status! = APR_SUCCESS ){
Return "Can not open given file .";
}
Ap_pai_closefile (f );*/
Conf-> gpfpath = apr_pstrdup (cmd-> pool, name );
Return NULL;
}
/* Init per dir */
Static void * create_authjira_dir_config (apr_pool_t * p, char * d)
{
Auth_jira_conf * conf = (auth_jira_conf *) apr_pcalloc (p, sizeof (* conf ));
If (conf = NULL) return NULL;
Conf-> gpfpath = d;
Return conf;
}
// Read the method through the corresponding http. conf command.
Static const command_rec authn_jira_cmds [] =
{
AP_INIT_FLAG ("IsAllCheck", set_authjira_is_all_check, NULL, OR_FILEINFO,
"Enable authSVN or not ."),
AP_INIT_TAKE1 ("filepath", set_jira_group_file, NULL, OR_FILEINFO,
"Set jira group file ."),
{NULL}
};
/* Dispatch list for API hooks */
Module AP_MODULE_DECLARE_DATA pathtest_module = {
STANDARD20_MODULE_STUFF,
Create_authjira_dir_config,/* create per-dir config structures */
NULL,/* merge per-dir config structures */
NULL,/* create per-server config structures */
NULL,/* merge per-server config structures */
Authn_jira_cmds,/* table of config file commands */
Pathtest_register_hooks/* register hooks */
};
Then add
<Location/>
IsAllCheck on
Filepath/usr/local/abc
SetHandler pathtest
</Location>
Use apxs-a-c-I/path_to/mod_pathtest.c to add the module.
Restart apache and enable http: // localhost/
The configuration file is read.
Reference: http://www.apachetutor.org/dev/config