Apache HTTPD
mod_case_filter_in.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * An example input filter - this converts input to upper case. Note that
19 * because of the moment it gets inserted it does NOT convert request headers.
20 */
21
22#include "httpd.h"
23#include "http_config.h"
24#include "apr_buckets.h"
25#include "apr_general.h"
26#include "apr_lib.h"
27#include "util_filter.h"
28#include "http_request.h"
29
30#include <ctype.h>
31
32static const char s_szCaseFilterName[] = "CaseFilterIn";
33module AP_MODULE_DECLARE_DATA case_filter_in_module;
34
35typedef struct
36{
39
44
46{
48
49 pConfig->bEnabled = 0;
50
51 return pConfig;
52}
53
55{
57 &case_filter_in_module);
58 if (!pConfig->bEnabled)
59 return;
60
62}
63
68 apr_off_t nBytes)
69{
70 request_rec *r = f->r;
74
75 if (!(pCtx = f->ctx)) {
76 f->ctx = pCtx = apr_palloc(r->pool, sizeof *pCtx);
77 pCtx->pbbTmp = apr_brigade_create(r->pool, c->bucket_alloc);
78 }
79
80 if (APR_BRIGADE_EMPTY(pCtx->pbbTmp)) {
81 ret = ap_get_brigade(f->next, pCtx->pbbTmp, eMode, eBlock, nBytes);
82
84 return ret;
85 }
86
87 while (!APR_BRIGADE_EMPTY(pCtx->pbbTmp)) {
90 const char *data;
92 char *buf;
94
95 /* It is tempting to do this...
96 * APR_BUCKET_REMOVE(pB);
97 * APR_BRIGADE_INSERT_TAIL(pbbOut,pB);
98 * and change the case of the bucket data, but that would be wrong
99 * for a file or socket buffer, for example...
100 */
101
105 break;
106 }
107
109 if (ret != APR_SUCCESS)
110 return ret;
111
112 buf = ap_malloc(len);
113 for (n=0 ; n < len ; ++n) {
114 buf[n] = apr_toupper(data[n]);
115 }
116
117 pbktOut = apr_bucket_heap_create(buf, len, free, c->bucket_alloc);
120 }
121
122 return APR_SUCCESS;
123}
124
125static const char *CaseFilterInEnable(cmd_parms *cmd, void *dummy, int arg)
126{
128 = ap_get_module_config(cmd->server->module_config,
129 &case_filter_in_module);
130 pConfig->bEnabled=arg;
131
132 return NULL;
133}
134
136{
138 "Run an input case filter on this host"),
139 { NULL }
140};
141
142
150
152{
154 NULL,
155 NULL,
157 NULL,
160};
int n
Definition ap_regex.h:278
const char apr_size_t len
Definition ap_regex.h:187
APR-UTIL Buckets/Bucket Brigades.
APR Miscellaneous library routines.
APR general purpose library routines.
#define ap_get_module_config(v, m)
#define AP_DECLARE_MODULE(foo)
#define AP_INIT_FLAG(directive, func, mconfig, where, help)
request_rec * r
ap_filter_t * ap_add_input_filter(const char *name, void *ctx, request_rec *r, conn_rec *c)
apr_status_t ap_filter_rec_t * ap_register_input_filter(const char *name, ap_in_filter_func filter_func, ap_init_filter_func filter_init, ap_filter_type ftype)
apr_status_t ap_get_brigade(ap_filter_t *filter, apr_bucket_brigade *bucket, ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes)
@ AP_FTYPE_RESOURCE
const unsigned char * buf
Definition util_md5.h:50
void ap_hook_insert_filter(ap_HOOK_insert_filter_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:96
void * dummy
Definition http_vhost.h:62
void const char * arg
Definition http_vhost.h:63
apr_file_t * f
#define APR_BUCKET_REMOVE(e)
#define APR_BRIGADE_INSERT_TAIL(b, e)
apr_read_type_e
Definition apr_buckets.h:57
#define APR_BRIGADE_EMPTY(b)
#define apr_bucket_delete(e)
#define APR_BUCKET_IS_EOS(e)
#define APR_BRIGADE_FIRST(b)
#define apr_bucket_read(e, str, len, block)
#define APR_HOOK_MIDDLE
Definition apr_hooks.h:303
#define RSRC_CONF
#define STANDARD20_MODULE_STUFF
void * ap_malloc(size_t size) __attribute__((malloc))
Definition util.c:3152
apr_size_t size
#define apr_toupper(c)
Definition apr_lib.h:233
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
apr_vformatter_buff_t * c
Definition apr_lib.h:175
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
const char * s
Definition apr_strings.h:95
apr_cmdtype_e cmd
Apache Configuration.
Apache Request library.
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
static const char s_szCaseFilterName[]
static void * CaseFilterInCreateServerConfig(apr_pool_t *p, server_rec *s)
static void CaseFilterInInsertFilter(request_rec *r)
static const command_rec CaseFilterInCmds[]
static apr_status_t CaseFilterInFilter(ap_filter_t *f, apr_bucket_brigade *pbbOut, ap_input_mode_t eMode, apr_read_type_e eBlock, apr_off_t nBytes)
static const char * CaseFilterInEnable(cmd_parms *cmd, void *dummy, int arg)
static void CaseFilterInRegisterHooks(apr_pool_t *p)
return NULL
Definition mod_so.c:359
apr_bucket_brigade * pbbTmp
The representation of a filter chain.
Structure to store things which are per connection.
Definition httpd.h:1152
A structure that represents the current request.
Definition httpd.h:845
apr_pool_t * pool
Definition httpd.h:847
conn_rec * connection
Definition httpd.h:849
server_rec * server
Definition httpd.h:851
A structure to store information for each virtual server.
Definition httpd.h:1322
struct ap_conf_vector_t * module_config
Definition httpd.h:1341
Apache filter library.
ap_input_mode_t
input filtering modes
Definition util_filter.h:41
@ AP_MODE_EATCRLF
Definition util_filter.h:50