4 #include "http_config.h"
6 #include "http_protocol.h"
8 #include "apr_optional.h"
10 /* Must be declared if modsecurity.h is not included */
11 APR_DECLARE_OPTIONAL_FN(void, modsec_register_tfn, (const char *name, void *fn));
15 * This function will be invoked by
16 * ModSecurity to transform input.
18 static int reverse(apr_pool_t *mptmp, unsigned char *input,
19 long int input_len, char **rval, long int *rval_len)
21 /* Transformation functions can choose to do their
22 * thing in-place, overwriting the existing content. This
23 * is normally possible only if the transformed content
24 * is of equal length or shorter.
26 * If you need to expand the content use the temporary
27 * memory pool mptmp to allocate the space.
30 /* Reverse the string in place, but only if it's long enough. */
33 long int j = input_len - 1;
43 /* Tell ModSecurity about the content
44 * we have generated. In this case we
45 * merely point back to the input buffer.
47 *rval = (char *)input;
48 *rval_len = input_len;
50 /* Must return 1 if the content was
51 * changed, or 0 otherwise.
56 static int hook_pre_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_temp) {
57 void (*fn)(const char *name, void *fn);
59 /* Look for the registration function
60 * exported by ModSecurity.
62 fn = APR_RETRIEVE_OPTIONAL_FN(modsec_register_tfn);
64 /* Use it to register our new
65 * transformation function under the
68 fn("reverse", (void *)reverse);
74 static void register_hooks(apr_pool_t *p) {
75 ap_hook_pre_config(hook_pre_config, NULL, NULL, APR_HOOK_LAST);
78 /* Dispatch list for API hooks */
79 module AP_MODULE_DECLARE_DATA tfn_reverse_module = {
80 STANDARD20_MODULE_STUFF,
81 NULL, /* create per-dir config structures */
82 NULL, /* merge per-dir config structures */
83 NULL, /* create per-server config structures */
84 NULL, /* merge per-server config structures */
85 NULL, /* table of config file commands */
86 register_hooks /* register hooks */