include/apreq_parser.h

Go to the documentation of this file.
00001 /*
00002 **  Licensed to the Apache Software Foundation (ASF) under one or more
00003 ** contributor license agreements.  See the NOTICE file distributed with
00004 ** this work for additional information regarding copyright ownership.
00005 ** The ASF licenses this file to You under the Apache License, Version 2.0
00006 ** (the "License"); you may not use this file except in compliance with
00007 ** the License.  You may obtain a copy of the License at
00008 **
00009 **      http://www.apache.org/licenses/LICENSE-2.0
00010 **
00011 **  Unless required by applicable law or agreed to in writing, software
00012 **  distributed under the License is distributed on an "AS IS" BASIS,
00013 **  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 **  See the License for the specific language governing permissions and
00015 **  limitations under the License.
00016 */
00017 
00018 #ifndef APREQ_PARSERS_H
00019 #define APREQ_PARSERS_H
00020 /* These structs are defined below */
00021 
00022 #include "apreq_param.h"
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif /* __cplusplus */
00027 
00039 typedef struct apreq_hook_t apreq_hook_t;
00040 
00044 typedef struct apreq_parser_t apreq_parser_t;
00045 
00047 #define APREQ_PARSER_ARGS  apreq_parser_t *parser,     \
00048                            apr_table_t *t,             \
00049                            apr_bucket_brigade *bb
00050 
00052 #define APREQ_HOOK_ARGS    apreq_hook_t *hook,         \
00053                            apreq_param_t *param,       \
00054                            apr_bucket_brigade *bb
00055 
00059 typedef apr_status_t (*apreq_parser_function_t)(APREQ_PARSER_ARGS);
00060 
00064 typedef apr_status_t (*apreq_hook_function_t)(APREQ_HOOK_ARGS);
00065 
00069 #define APREQ_DECLARE_PARSER(f) APREQ_DECLARE_NONSTD(apr_status_t) \
00070                                 (f) (APREQ_PARSER_ARGS)
00071 
00075 #define APREQ_DECLARE_HOOK(f)   APREQ_DECLARE_NONSTD(apr_status_t) \
00076                                 (f) (APREQ_HOOK_ARGS)
00077 
00083 struct apreq_hook_t {
00084     apreq_hook_function_t hook; 
00085     apreq_hook_t         *next; 
00086     apr_pool_t           *pool; 
00087     void *ctx; 
00088 };
00089 
00093 struct apreq_parser_t {
00095     apreq_parser_function_t parser;
00097     const char             *content_type;
00099     apr_pool_t             *pool;
00101     apr_bucket_alloc_t     *bucket_alloc;
00103     apr_size_t              brigade_limit;
00105     const char             *temp_dir;
00107     apreq_hook_t           *hook;
00109     void                   *ctx;
00110 };
00111 
00112 
00123 static APR_INLINE
00124 apr_status_t apreq_parser_run(struct apreq_parser_t *psr, apr_table_t *t,
00125                               apr_bucket_brigade *bb)
00126 {
00127     return psr->parser(psr, t, bb);
00128 }
00129 
00137 static APR_INLINE
00138 apr_status_t apreq_hook_run(struct apreq_hook_t *h, apreq_param_t *param,
00139                             apr_bucket_brigade *bb)
00140 {
00141     return h->hook(h, param, bb);
00142 }
00143 
00144 
00150 APREQ_DECLARE_PARSER(apreq_parse_headers);
00151 
00155 APREQ_DECLARE_PARSER(apreq_parse_urlencoded);
00156 
00163 APREQ_DECLARE_PARSER(apreq_parse_multipart);
00164 
00173 APREQ_DECLARE_PARSER(apreq_parse_generic);
00174 
00182 APREQ_DECLARE_HOOK(apreq_hook_apr_xml_parser);
00183 
00197 APREQ_DECLARE(apreq_parser_t *) apreq_parser_make(apr_pool_t *pool,
00198                                                   apr_bucket_alloc_t *ba,
00199                                                   const char *content_type,
00200                                                   apreq_parser_function_t pfn,
00201                                                   apr_size_t brigade_limit,
00202                                                   const char *temp_dir,
00203                                                   apreq_hook_t *hook,
00204                                                   void *ctx);
00205 
00215 APREQ_DECLARE(apreq_hook_t *) apreq_hook_make(apr_pool_t *pool,
00216                                               apreq_hook_function_t hook,
00217                                               apreq_hook_t *next,
00218                                               void *ctx);
00219 
00220 
00227 APREQ_DECLARE(apr_status_t) apreq_parser_add_hook(apreq_parser_t *p,
00228                                                   apreq_hook_t *h);
00229 
00230 
00237 APREQ_DECLARE(apreq_parser_function_t)apreq_parser(const char *enctype);
00238 
00239 
00252 APREQ_DECLARE(apr_status_t) apreq_register_parser(const char *enctype,
00253                                                   apreq_parser_function_t pfn);
00254 
00255 
00261 APREQ_DECLARE_HOOK(apreq_hook_disable_uploads);
00262 
00267 APREQ_DECLARE_HOOK(apreq_hook_discard_brigade);
00268 
00272 typedef struct apreq_hook_find_param_ctx_t {
00273     const char    *name;
00274     apreq_param_t *param;
00275     apreq_hook_t  *prev;
00276 } apreq_hook_find_param_ctx_t;
00277 
00278 
00293 APREQ_DECLARE_HOOK(apreq_hook_find_param);
00294 
00295 
00296 #ifdef __cplusplus
00297 }
00298 
00299 #endif
00300 #endif /* APREQ_PARSERS_H */