Rudiments

apachemodule.h
1 // Copyright (c) 1999-2018 David Muse
2 // See the COPYING file for more information
3
4 #ifndef RUDIMENTS_APACHEMODULE_H
5 #define RUDIMENTS_APACHEMODULE_H
6
7 #ifndef HTTP_MODULE_NAME
8 #error HTTP_MODULE_NAME not defined
9 #endif
10
11 #define XHANDLER_DO_FUNCTION(NM) HANDLER_DO_FUNCTION(NM)
12 #define HANDLER_DO_FUNCTION(NM) do_##NM##_handler
13
14 #define XHANDLER_FUNCTION(NM) HANDLER_FUNCTION(NM)
15 #define HANDLER_FUNCTION(NM) NM##_handler
16
17 #define XMODULE_STRUCT(NM) MODULE_STRUCT(NM)
18 #define MODULE_STRUCT(NM) NM##_module
19
20 #define XXFILE_NAME(NM) XFILE_NAME(NM)
21 #define XFILE_NAME(NM) FILE_NAME(mod_##NM)
22 #define FILE_NAME(NM) #NM".c"
23
24 #define XMOD_NAME(NM) MOD_NAME(NM)
25 #define MOD_NAME(NM) #NM
26
27 #include <rudiments/apachehttpserverapi.h>
28 #include <rudiments/private/apacheincludes.h>
29
30 #ifdef APACHE_2
31 #include <rudiments/charstring.h>
32 #endif
33
34 static bool httpModuleMain(httpserverapi *sapi);
35
36 extern "C" {
37
38 static int XHANDLER_FUNCTION(HTTP_MODULE_NAME)(request_rec *r);
39
40 #ifdef APACHE_2
41
42 static int XHANDLER_DO_FUNCTION(HTTP_MODULE_NAME)(request_rec *r) {
43
44 if (charstring::compare(r->handler,
45 XMOD_NAME(HTTP_MODULE_NAME))) {
46 return DECLINED;
47 }
48
49 return XHANDLER_FUNCTION(HTTP_MODULE_NAME)(r);
50 }
51
52 static void register_hooks(apr_pool_t *pool) {
53 ap_hook_handler(XHANDLER_DO_FUNCTION(HTTP_MODULE_NAME),
54 NULL,NULL,APR_HOOK_FIRST);
55 }
56
57 module AP_MODULE_DECLARE_DATA XMODULE_STRUCT(HTTP_MODULE_NAME) = {
58 MODULE_MAGIC_NUMBER_MAJOR,
59 MODULE_MAGIC_NUMBER_MINOR,
60 -1,
61 XXFILE_NAME(HTTP_MODULE_NAME),
62 NULL,
63 NULL,
64 MODULE_MAGIC_COOKIE,
65 NULL, /* module initializer */
66 NULL, /* create per-dir config structures */
67 NULL, /* merge per-dir config structures */
68 NULL, /* create per-server config structures */
69 NULL, /* merge per-server config structures */
70 NULL, /* command handlers */
71 register_hooks /* register hooks */
72 };
73
74 #else
75
76 static const handler_rec handler_struct[] = {
77 { XMOD_NAME(HTTP_MODULE_NAME),
78 XHANDLER_FUNCTION(HTTP_MODULE_NAME) },
79 { NULL, NULL }
80 };
81
82 #ifdef MODULE_MAGIC_COOKIE
83 #define GW_MODULE_MAGIC_COOKIE MODULE_MAGIC_COOKIE,
84 #else
85 #define GW_MODULE_MAGIC_COOKIE
86 #endif
87
88 module MODULE_VAR_EXPORT XMODULE_STRUCT(HTTP_MODULE_NAME) = {
89 MODULE_MAGIC_NUMBER_MAJOR,
90 MODULE_MAGIC_NUMBER_MINOR,
91 -1,
92 XXFILE_NAME(HTTP_MODULE_NAME),
93 NULL,
94 NULL,
95 GW_MODULE_MAGIC_COOKIE
96 NULL, /* module initializer */
97 NULL, /* create per-dir config structures */
98 NULL, /* merge per-dir config structures */
99 NULL, /* create per-server config structures */
100 NULL, /* merge per-server config structures */
101 NULL, /* table of config file commands */
102 handler_struct, /* [#8] MIME-typed-dispatched handlers */
103 NULL, /* [#1] URI to filename translation */
104 NULL, /* [#4] validate user id from request */
105 NULL, /* [#5] check if the user is ok _here_ */
106 NULL, /* [#3] check access by host address */
107 NULL, /* [#6] determine MIME type */
108 NULL, /* [#7] pre-run fixups */
109 NULL, /* [#9] log a transaction */
110 NULL, /* [#2] header parser */
111 NULL, /* child_init */
112 NULL, /* child_exit */
113 NULL /* [#0] post read-request */
114 #ifdef EAPI
115 ,NULL, /* EAPI: add_module */
116 NULL, /* EAPI: remove_module */
117 NULL, /* EAPI: rewrite_command */
118 NULL /* EAPI: new_connection */
119 #endif
120 };
121
122 #endif
123
124 static int XHANDLER_FUNCTION(HTTP_MODULE_NAME)(request_rec *r) {
125 apachehttpserverapi sapi((void *)r);
126 return (httpModuleMain(&sapi))?OK:DECLINED;
127 }
128
129 }
130
131 #endif
apachehttpserverapi
Definition: apachehttpserverapi.h:9
charstring::compare
static int32_t compare(const char *str1, const char *str2)
httpserverapi
Definition: httpserverapi.h:9