libapreq2-2.15: include/apreq_util.h Source File

Apache HTTP Server Request Library

apreq_util.h
Go to the documentation of this file.
1 /*
2 ** Licensed to the Apache Software Foundation (ASF) under one or more
3 ** contributor license agreements. See the NOTICE file distributed with
4 ** this work for additional information regarding copyright ownership.
5 ** The ASF licenses this file to You under the Apache License, Version 2.0
6 ** (the "License"); you may not use this file except in compliance with
7 ** the License. You may obtain a copy of the License at
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17
18 #ifndef APREQ_UTIL_H
19 #define APREQ_UTIL_H
20
21 #include "apr_file_io.h"
22 #include "apr_buckets.h"
23 #include "apreq.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
53 APREQ_DECLARE(char *) apreq_join(apr_pool_t *p,
54 const char *sep,
55 const apr_array_header_t *arr,
56 apreq_join_t mode);
57
70 APREQ_DECLARE(apr_ssize_t) apreq_index(const char* hay, apr_size_t hlen,
71 const char* ndl, apr_size_t nlen,
72 const apreq_match_t type);
73
86 APREQ_DECLARE(apr_size_t) apreq_quote(char *dest, const char *src,
87 const apr_size_t slen);
88
102 APREQ_DECLARE(apr_size_t) apreq_quote_once(char *dest, const char *src,
103 const apr_size_t slen);
104
115 APREQ_DECLARE(apr_size_t) apreq_encode(char *dest, const char *src,
116 const apr_size_t slen);
117
129 APREQ_DECLARE(apr_size_t) apreq_cp1252_to_utf8(char *dest,
130 const char *src, apr_size_t slen);
131
143 APREQ_DECLARE(apreq_charset_t) apreq_charset_divine(const char *src,
144 apr_size_t slen);
145
166 APREQ_DECLARE(apr_status_t) apreq_decode(char *dest, apr_size_t *dlen,
167 const char *src, apr_size_t slen);
168
189 APREQ_DECLARE(apr_status_t) apreq_decodev(char *dest, apr_size_t *dlen,
190 struct iovec *v, int nelts);
191
204 static APR_INLINE
205 char *apreq_escape(apr_pool_t *p, const char *src, const apr_size_t slen)
206 {
207 char *rv;
208
209 if (src == NULL)
210 return NULL;
211
212 rv = (char *)apr_palloc(p, 3 * slen + 1);
213 apreq_encode(rv, src, slen);
214 return rv;
215 }
216
224 static APR_INLINE apr_ssize_t apreq_unescape(char *str)
225 {
226 apr_size_t len;
227 apr_status_t rv = apreq_decode(str, &len, str, strlen(str));
228 if (rv == APR_SUCCESS)
229 return (apr_ssize_t)len;
230 else
231 return -1;
232 }
233
245 APREQ_DECLARE(apr_int64_t) apreq_atoi64f(const char *s);
246
258 APREQ_DECLARE(apr_int64_t) apreq_atoi64t(const char *s);
259
277 APREQ_DECLARE(apr_status_t) apreq_brigade_fwrite(apr_file_t *f,
278 apr_off_t *wlen,
279 apr_bucket_brigade *bb);
296 APREQ_DECLARE(apr_status_t) apreq_file_mktemp(apr_file_t **fp,
297 apr_pool_t *pool,
298 const char *path);
299
309 static APR_INLINE
310 apr_status_t apreq_brigade_setaside(apr_bucket_brigade *bb, apr_pool_t *p)
311 {
312 apr_bucket *e;
313 for (e = APR_BRIGADE_FIRST(bb); e != APR_BRIGADE_SENTINEL(bb);
314 e = APR_BUCKET_NEXT(e))
315 {
316 apr_status_t rv = apr_bucket_setaside(e, p);
317 if (rv != APR_SUCCESS)
318 return rv;
319 }
320 return APR_SUCCESS;
321 }
322
323
336 static APR_INLINE
337 apr_status_t apreq_brigade_copy(apr_bucket_brigade *d, apr_bucket_brigade *s) {
338 apr_bucket *e;
339 for (e = APR_BRIGADE_FIRST(s); e != APR_BRIGADE_SENTINEL(s);
340 e = APR_BUCKET_NEXT(e))
341 {
342 apr_bucket *c;
343 apr_status_t rv = apr_bucket_copy(e, &c);
344 if (rv != APR_SUCCESS)
345 return rv;
346
347 APR_BRIGADE_INSERT_TAIL(d, c);
348 }
349 return APR_SUCCESS;
350 }
351
363 static APR_INLINE
364 void apreq_brigade_move(apr_bucket_brigade *d, apr_bucket_brigade *s,
365 apr_bucket *e)
366 {
367 apr_bucket *f;
368
369 if (e != APR_BRIGADE_SENTINEL(s)) {
370 f = APR_RING_FIRST(&s->list);
371 if (f == e) /* zero buckets to be moved */
372 return;
373
374 /* obtain the last bucket to be moved */
375 e = APR_RING_PREV(e, link);
376
377 APR_RING_UNSPLICE(f, e, link);
378 APR_RING_SPLICE_HEAD(&d->list, f, e, apr_bucket, link);
379 }
380 else {
381 APR_BRIGADE_CONCAT(d, s);
382 }
383 }
384
385
399 APREQ_DECLARE(apr_status_t) apreq_header_attribute(const char *hdr,
400 const char *name,
401 const apr_size_t nlen,
402 const char **val,
403 apr_size_t *vlen);
404
405
423 APREQ_DECLARE(apr_status_t) apreq_brigade_concat(apr_pool_t *pool,
424 const char *temp_dir,
425 apr_size_t brigade_limit,
426 apr_bucket_brigade *out,
427 apr_bucket_brigade *in);
428
437 APREQ_DECLARE(apr_file_t *)apreq_brigade_spoolfile(apr_bucket_brigade *bb);
438
439 #ifdef __cplusplus
440 }
441 #endif
442
443 #endif /* APREQ_UTIL_H */
apreq_brigade_concat
apr_status_t apreq_brigade_concat(apr_pool_t *pool, const char *temp_dir, apr_size_t brigade_limit, apr_bucket_brigade *out, apr_bucket_brigade *in)
apreq_brigade_move
static APR_INLINE void apreq_brigade_move(apr_bucket_brigade *d, apr_bucket_brigade *s, apr_bucket *e)
Definition: apreq_util.h:364
APREQ_DECLARE
#define APREQ_DECLARE(d)
Definition: apreq.h:50
apreq_match_t
apreq_match_t
Definition: apreq.h:222
apreq_atoi64t
apr_int64_t apreq_atoi64t(const char *s)
apreq_escape
static APR_INLINE char * apreq_escape(apr_pool_t *p, const char *src, const apr_size_t slen)
Definition: apreq_util.h:205
apreq_unescape
static APR_INLINE apr_ssize_t apreq_unescape(char *str)
Definition: apreq_util.h:224
apreq_file_mktemp
apr_status_t apreq_file_mktemp(apr_file_t **fp, apr_pool_t *pool, const char *path)
apreq_header_attribute
apr_status_t apreq_header_attribute(const char *hdr, const char *name, const apr_size_t nlen, const char **val, apr_size_t *vlen)
apreq_quote_once
apr_size_t apreq_quote_once(char *dest, const char *src, const apr_size_t slen)
apreq.h
Main header file...
apreq_join_t
apreq_join_t
Definition: apreq.h:214
apreq_charset_t
apreq_charset_t
Definition: apreq.h:205
apreq_brigade_spoolfile
apr_file_t * apreq_brigade_spoolfile(apr_bucket_brigade *bb)
apreq_brigade_copy
static APR_INLINE apr_status_t apreq_brigade_copy(apr_bucket_brigade *d, apr_bucket_brigade *s)
Definition: apreq_util.h:337
apreq_decode
apr_status_t apreq_decode(char *dest, apr_size_t *dlen, const char *src, apr_size_t slen)
apreq_cp1252_to_utf8
apr_size_t apreq_cp1252_to_utf8(char *dest, const char *src, apr_size_t slen)
apreq_brigade_setaside
static APR_INLINE apr_status_t apreq_brigade_setaside(apr_bucket_brigade *bb, apr_pool_t *p)
Definition: apreq_util.h:310
apreq_atoi64f
apr_int64_t apreq_atoi64f(const char *s)
apreq_encode
apr_size_t apreq_encode(char *dest, const char *src, const apr_size_t slen)
apreq_index
apr_ssize_t apreq_index(const char *hay, apr_size_t hlen, const char *ndl, apr_size_t nlen, const apreq_match_t type)
apreq_brigade_fwrite
apr_status_t apreq_brigade_fwrite(apr_file_t *f, apr_off_t *wlen, apr_bucket_brigade *bb)
apreq_join
char * apreq_join(apr_pool_t *p, const char *sep, const apr_array_header_t *arr, apreq_join_t mode)
apreq_charset_divine
apreq_charset_t apreq_charset_divine(const char *src, apr_size_t slen)
apreq_quote
apr_size_t apreq_quote(char *dest, const char *src, const apr_size_t slen)
apreq_decodev
apr_status_t apreq_decodev(char *dest, apr_size_t *dlen, struct iovec *v, int nelts)