/
mod_research_request.c
128 lines (115 loc) · 4.08 KB
/
mod_research_request.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
** mod_research_request.c -- Apache sample research_request module
** [Autogenerated via ``apxs -n research_request -g'']
**
** To play with this sample module first compile it into a
** DSO file and install it into Apache's modules directory
** by running:
**
** $ apxs -c -i mod_research_request.c
**
** Then activate it in Apache's httpd.conf file for instance
** for the URL /research_request in as follows:
**
** # httpd.conf
** LoadModule research_request_module modules/mod_research_request.so
** <Location /research_request>
** SetHandler research_request
** </Location>
**
** Then after restarting Apache via
**
** $ apachectl restart
**
** you immediately can request the URL /research_request and watch for the
** output of this module. This can be achieved for instance via:
**
** $ lynx -mime_header http://localhost/research_request
**
** The output should be similar to the following one:
**
** HTTP/1.1 200 OK
** Date: Tue, 31 Mar 1998 14:42:22 GMT
** Server: Apache/1.3.4 (Unix)
** Connection: close
** Content-Type: text/html
**
** The sample page from mod_research_request.c
*/
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
/*
#include "http_connection.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
#include "http_request.h"
#include "ap_listen.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_optional.h"
*/
#define ON 1
#define OFF 0
typedef struct {
u_int webdav_enable;
} config_t;
module AP_MODULE_DECLARE_DATA research_request_module;
static void *create_config(apr_pool_t *p, server_rec *s)
{
config_t *conf = apr_palloc(p, sizeof(config_t));
conf->webdav_enable = OFF;
return conf;
}
/* The sample content handler */
static int research_request_handler(request_rec *r)
{
r->content_type = "text/plain";
ap_rputs("************************\n",r);
ap_rputs("* Mod Research Reqeust *\n",r);
ap_rputs("************************\n",r);
ap_rprintf(r, "protocol: %s\n", r->protocol);
ap_rprintf(r, "method: %s\n", r->method);
ap_rprintf(r, "method_number: %d\n", r->method_number);
ap_rprintf(r, "uri: %s\n", r->uri);
ap_rprintf(r, "args: %s\n", r->args ? r->args : "");
ap_rprintf(r, "client ip: %s\n", r->connection->client_ip);
ap_rprintf(r, "local ip: %s\n", r->connection->local_ip);
ap_rprintf(r, "useragent: %s\n", apr_table_get(r->headers_in, "User-Agent") ?
apr_table_get(r->headers_in, "User-Agent") : "");
ap_rprintf(r, "referer: %s\n", apr_table_get(r->headers_in, "Referer") ?
apr_table_get(r->headers_in, "Referer") : "");
config_t *conf = ap_get_module_config(r->server->module_config, &research_request_module);
ap_rprintf(r, "webdav: %d\n", conf->webdav_enable);
return OK;
}
static const char *set_webdav_enable(cmd_parms *cmd, void *mconfig, int flag)
{
config_t *conf = ap_get_module_config(cmd->server->module_config, &research_request_module);
const char *err = ap_check_cmd_context(cmd, NOT_IN_FILES | NOT_IN_LIMIT);
if(err != NULL)
return err;
conf->webdav_enable = flag;
return NULL;
}
static const command_rec research_request_cmds[] = {
AP_INIT_FLAG("DAV", set_webdav_enable, NULL, ACCESS_CONF | RSRC_CONF,
"set enable webdav ON / OFF. (default off)"),
{NULL},
};
static void register_hooks(apr_pool_t *p)
{
ap_hook_handler(research_request_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
/* Dispatch list for API hooks */
module AP_MODULE_DECLARE_DATA research_request_module = {
STANDARD20_MODULE_STUFF,
NULL, /* create per-dir config structures */
NULL, /* merge per-dir config structures */
create_config, /* create per-server config structures */
NULL, /* merge per-server config structures */
research_request_cmds, /* table of config file commands */
register_hooks /* register hooks */
};