Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
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 
130  const char *src, apr_size_t slen);
131 
144  apr_size_t slen);
145 
167  const char *src, apr_size_t slen);
168 
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 
278  apr_off_t *wlen,
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  {
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 
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 
400  const char *name,
401  const apr_size_t nlen,
402  const char **val,
403  apr_size_t *vlen);
404 
405 
424  const char *temp_dir,
425  apr_size_t brigade_limit,
426  apr_bucket_brigade *out,
427  apr_bucket_brigade *in);
428 
438 
439 #ifdef __cplusplus
440  }
441 #endif
442 
443 #endif /* APREQ_UTIL_H */
apr_int64_t apreq_atoi64t(const char *s)
size_t apr_size_t
Definition: apr.h:375
apr_size_t apreq_cp1252_to_utf8(char *dest, const char *src, apr_size_t slen)
apr_size_t apreq_encode(char *dest, const char *src, const apr_size_t slen)
Definition: apr_arch_file_io.h:107
Definition: apr_tables.h:62
apreq_charset_t apreq_charset_divine(const char *src, apr_size_t slen)
apr_status_t apreq_file_mktemp(apr_file_t **fp, apr_pool_t *pool, const char *path)
apr_size_t apreq_quote(char *dest, const char *src, const apr_size_t slen)
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:556
apr_status_t apreq_brigade_fwrite(apr_file_t *f, apr_off_t *wlen, apr_bucket_brigade *bb)
char * apreq_join(apr_pool_t *p, const char *sep, const apr_array_header_t *arr, apreq_join_t mode)
#define apr_bucket_copy(e, c)
Definition: apr_buckets.h:1133
#define APREQ_DECLARE(x)
Definition: macros.h:12
void * apr_palloc(apr_pool_t *p, apr_size_t size) __attribute__((nonnull(1)))
apreq_charset_t
Definition: apreq.h:160
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)
apr_int64_t apreq_atoi64f(const char *s)
Definition: apr_buckets.h:258
APR File I/O Handling.
const char apr_size_t dlen
Definition: mod_proxy.h:649
#define APR_BRIGADE_CONCAT(a, b)
Definition: apr_buckets.h:383
apr_bucket_brigade * bb
Definition: mod_dav.h:556
apr_status_t apreq_decodev(char *dest, apr_size_t *dlen, struct iovec *v, int nelts)
apreq_match_t
Definition: apreq.h:177
Definition: apr_buckets.h:224
dav_error * src
Definition: mod_dav.h:186
APR-UTIL Buckets/Bucket Brigades.
#define APR_RING_PREV(ep, link)
Definition: apr_ring.h:183
#define APR_BUCKET_NEXT(e)
Definition: apr_buckets.h:425
#define APR_INLINE
Definition: apr.h:65
apr_file_t * apreq_brigade_spoolfile(apr_bucket_brigade *bb)
apr_ssize_t apreq_index(const char *hay, apr_size_t hlen, const char *ndl, apr_size_t nlen, const apreq_match_t type)
apr_pool_t * p
Main header file...Define the common data structures.
apreq_join_t
Definition: apreq.h:169
apr_status_t apreq_header_attribute(const char *hdr, const char *name, const apr_size_t nlen, const char **val, apr_size_t *vlen)
apr_size_t apreq_quote_once(char *dest, const char *src, const apr_size_t slen)
#define APR_BRIGADE_INSERT_TAIL(b, e)
Definition: apr_buckets.h:372
ssize_t apr_ssize_t
Definition: apr.h:376
dav_buffer const char * str
Definition: mod_dav.h:465
#define APR_RING_FIRST(hp)
Definition: apr_ring.h:166
#define APR_BRIGADE_FIRST(b)
Definition: apr_buckets.h:348
long apr_int64_t
Definition: apr.h:371
const char * name
Definition: mod_dav.h:730
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
int apr_status_t
Definition: apr_errno.h:44
#define APR_RING_UNSPLICE(ep1, epN, link)
Definition: apr_ring.h:364
apr_status_t apreq_decode(char *dest, apr_size_t *dlen, const char *src, apr_size_t slen)
#define APR_SUCCESS
Definition: apr_errno.h:225
#define APR_BRIGADE_SENTINEL(b)
Definition: apr_buckets.h:334
#define apr_bucket_setaside(e, p)
Definition: apr_buckets.h:1114
#define APR_RING_SPLICE_HEAD(hp, ep1, epN, elem, link)
Definition: apr_ring.h:286
off_t apr_off_t
Definition: apr.h:377