forked from zhwj184/apache-replace-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurlreplace.c
80 lines (73 loc) · 2.29 KB
/
urlreplace.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
#include "apr.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_want.h"
//该模块的配置信息定义一个结构。
typedef struct
{
const char *src_path;
const char *desc_path;
}auth_jira_conf;
//声明模块名称
module AP_MODULE_DECLARE_DATA pathreplace_module;
// 测试用的handler实际。输出从配置文件中读入的配置信息。
static int pathreplace_handler(request_rec *r)
{
r->content_type = "text/html";
//取conf数据
auth_jira_conf *conf = ap_get_module_config(r->per_dir_config,
&pathreplace_module);
ap_rprintf(r, "src_path:%s\n",conf->src_path);
ap_rprintf(r, "desc_path:%s",conf->desc_path);
return OK;
}
static void pathreplace_register_hooks(apr_pool_t *p)
{
ap_hook_handler(pathreplace_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
static const char *set_src_path(cmd_parms *cmd,
void *mconfig,
const char *arg)
{
auth_jira_conf *conf = (auth_jira_conf *) mconfig;
conf->src_path = apr_pstrdup(cmd->pool, arg);
return NULL;
}
static const char *set_desc_path(cmd_parms *cmd,
void *mconfig,
const char *arg)
{
auth_jira_conf *conf = (auth_jira_conf *) mconfig;
conf->desc_path = apr_pstrdup(cmd->pool, arg);
return NULL;
}
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->src_path = d;
conf->desc_path = d;
return conf;
}
//对应的http.conf的命令读到方法。
static const command_rec authn_jira_cmds[] =
{
AP_INIT_TAKE1("srcpath", set_src_path, NULL, OR_FILEINFO,
"src path regex must not be null"),
AP_INIT_TAKE1("descpath", set_desc_path, NULL, OR_FILEINFO,
"desc path must not be null"),
{ NULL }
};
module AP_MODULE_DECLARE_DATA pathreplace_module = {
STANDARD20_MODULE_STUFF,
create_authjira_dir_config,
NULL,
NULL,
NULL,
authn_jira_cmds,
pathreplace_register_hooks
};