Apache HTTPD
util_xml.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#include "apr_xml.h"
18
19#include "httpd.h"
20#include "http_protocol.h"
21#include "http_log.h"
22#include "http_core.h"
23
24#include "util_charset.h"
25#include "util_xml.h"
26
27
28/* used for reading input blocks */
29#define READ_BLOCKSIZE 2048
30
31
32/* we know core's module_index is 0 */
33#undef APLOG_MODULE_INDEX
34#define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
35
37{
40 int seen_eos;
42 char errbuf[200];
44 apr_size_t limit_xml_body = ap_get_limit_xml_body(r);
46
49
50 seen_eos = 0;
51 total_read = 0;
52
53 do {
54 apr_bucket *bucket;
55
56 /* read the body, stuffing it into the parser */
60
61 if (status != APR_SUCCESS) {
63 goto read_error;
64 }
65
66 for (bucket = APR_BRIGADE_FIRST(brigade);
68 bucket = APR_BUCKET_NEXT(bucket))
69 {
70 const char *data;
72
73 if (APR_BUCKET_IS_EOS(bucket)) {
74 seen_eos = 1;
75 break;
76 }
77
78 if (APR_BUCKET_IS_METADATA(bucket)) {
79 continue;
80 }
81
83 if (status != APR_SUCCESS) {
84 goto read_error;
85 }
86
87 total_read += len;
88 if (total_read > limit_xml_body) {
90 "XML request body is larger than the configured "
91 "limit of %lu", (unsigned long)limit_xml_body);
93 goto read_error;
94 }
95
97 if (status) {
98 goto parser_error;
99 }
100 }
101
103 } while (!seen_eos);
104
106
107 /* tell the parser that we're done */
109 if (status) {
110 /* Some parsers are stupid and return an error on blank documents. */
111 if (!total_read) {
112 *pdoc = NULL;
113 return OK;
114 }
116 "XML parser error (at end). status=%d", status);
117 return HTTP_BAD_REQUEST;
118 }
119
120#if APR_CHARSET_EBCDIC
122#endif
123 return OK;
124
128 "XML Parser Error: %s", errbuf);
129
130 /* FALLTHRU */
131
133 /* make sure the parser is terminated */
135
137
138 /* Apache will supply a default error, plus the error log above. */
139 return result;
140}
#define AP_DECLARE(type)
Definition ap_config.h:67
const char apr_size_t len
Definition ap_regex.h:187
const ap_regex_t char * errbuf
Definition ap_regex.h:198
APR-UTIL XML Library.
request_rec * r
#define OK
Definition httpd.h:456
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)
apr_size_t ap_get_limit_xml_body(const request_rec *r)
Definition core.c:3863
#define APLOGNO(n)
Definition http_log.h:117
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_ERR
Definition http_log.h:67
#define APLOG_MARK
Definition http_log.h:283
int ap_map_http_request_error(apr_status_t rv, int status)
int ap_xml_parse_input(request_rec *r, apr_xml_doc **pdoc)
Definition util_xml.c:36
#define APR_BUCKET_IS_METADATA(e)
#define APR_BUCKET_NEXT(e)
#define APR_BRIGADE_SENTINEL(b)
#define APR_BUCKET_IS_EOS(e)
#define APR_BRIGADE_FIRST(b)
#define apr_bucket_read(e, str, len, block)
@ APR_BLOCK_READ
Definition apr_buckets.h:58
apr_xml_parser ** parser
Definition apr_xml.h:228
apr_xml_doc ** pdoc
Definition apr_xml.h:255
#define HTTP_BAD_REQUEST
Definition httpd.h:508
#define HTTP_REQUEST_ENTITY_TOO_LARGE
Definition httpd.h:521
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
apr_array_header_t ** result
int int status
CORE HTTP Daemon.
Apache Logging library.
HTTP protocol handling.
HTTP Daemon routines.
return NULL
Definition mod_so.c:359
struct apr_bucket_alloc_t * bucket_alloc
Definition httpd.h:1201
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
struct ap_filter_t * input_filters
Definition httpd.h:1072
charset conversion
@ AP_MODE_READBYTES
Definition util_filter.h:43
#define READ_BLOCKSIZE
Definition util_xml.c:29
Apache XML library.