#include
"
httpd.h
"
#include " http_config.h "
#include " http_protocol.h "
#include " ap_config.h "
/* 头文件,本文用到了ap_rprintf函数 */
#include " apr.h "
#include " apr_lib.h "
#include " apr_strings.h "
#include " apr_want.h "
// 该模块的配置信息定义一个结构。
typedef struct
{
short IsAll;
const char * gpfpath;
}auth_jira_conf;
// 声明模块名称
module AP_MODULE_DECLARE_DATA pathtest_module;
// 测试用的handler实际。输出从配置文件中读入的配置信息。
static int pathtest_handler(request_rec * r)
{
r -> content_type = " text/html " ;
// 取conf数据
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);
}
/* 设置IsAll字段的读放法 */
static const char * set_authjira_is_all_check(cmd_parms * cmd,
void * mconfig,
int arg)
{
auth_jira_conf * conf = (auth_jira_conf * ) mconfig;
conf -> IsAll = arg;
return NULL;
}
/* 读取设置某个文件的字符串方法,对于文件,判断文件是否有效 */
static const char * set_jira_group_file(cmd_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_cfg_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;
}
// 对应的http.conf的命令读到方法。
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 */
};
#include " http_config.h "
#include " http_protocol.h "
#include " ap_config.h "
/* 头文件,本文用到了ap_rprintf函数 */
#include " apr.h "
#include " apr_lib.h "
#include " apr_strings.h "
#include " apr_want.h "
// 该模块的配置信息定义一个结构。
typedef struct
{
short IsAll;
const char * gpfpath;
}auth_jira_conf;
// 声明模块名称
module AP_MODULE_DECLARE_DATA pathtest_module;
// 测试用的handler实际。输出从配置文件中读入的配置信息。
static int pathtest_handler(request_rec * r)
{
r -> content_type = " text/html " ;
// 取conf数据
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);
}
/* 设置IsAll字段的读放法 */
static const char * set_authjira_is_all_check(cmd_parms * cmd,
void * mconfig,
int arg)
{
auth_jira_conf * conf = (auth_jira_conf * ) mconfig;
conf -> IsAll = arg;
return NULL;
}
/* 读取设置某个文件的字符串方法,对于文件,判断文件是否有效 */
static const char * set_jira_group_file(cmd_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_cfg_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;
}
// 对应的http.conf的命令读到方法。
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 */
};
然后在配置文件中添加
<Location />
IsAllCheck on
filepath /usr/local/abc
SetHandler pathtest
</Location>
通过apxs -a -c -i /path_to/mod_pathtest.c 添加该模块。
重启apache ,打开http://localhost/
就可以看到读取到了配置文件信息。
参考网址:http://www.apachetutor.org/dev/config