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 
129 APREQ_DECLARE(apr_size_t) apreq_cp1252_to_utf8(char *dest,
130  const char *src, apr_size_t slen);
131 
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 
278  apr_off_t *wlen,
279  apr_bucket_brigade *bb);
297  apr_pool_t *pool,
298  const char *path);
299 
309 static APR_INLINE
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
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
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 */
Main header file...
#define APREQ_DECLARE(d)
Definition: apreq.h:50
apreq_match_t
Definition: apreq.h:222
apreq_charset_t
Definition: apreq.h:205
apreq_join_t
Definition: apreq.h:214
apr_size_t apreq_encode(char *dest, const char *src, const apr_size_t slen)
apr_status_t apreq_decodev(char *dest, apr_size_t *dlen, struct iovec *v, int nelts)
char * apreq_join(apr_pool_t *p, const char *sep, const apr_array_header_t *arr, apreq_join_t mode)
apr_status_t apreq_brigade_fwrite(apr_file_t *f, apr_off_t *wlen, apr_bucket_brigade *bb)
apr_status_t apreq_decode(char *dest, apr_size_t *dlen, const char *src, apr_size_t slen)
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_atoi64t(const char *s)
apr_int64_t apreq_atoi64f(const char *s)
static APR_INLINE char * apreq_escape(apr_pool_t *p, const char *src, const apr_size_t slen)
Definition: apreq_util.h:205
apr_size_t apreq_cp1252_to_utf8(char *dest, const char *src, apr_size_t slen)
apr_status_t apreq_header_attribute(const char *hdr, const char *name, const apr_size_t nlen, const char **val, apr_size_t *vlen)
static APR_INLINE apr_status_t apreq_brigade_setaside(apr_bucket_brigade *bb, apr_pool_t *p)
Definition: apreq_util.h:310
static APR_INLINE apr_ssize_t apreq_unescape(char *str)
Definition: apreq_util.h:224
static APR_INLINE void apreq_brigade_move(apr_bucket_brigade *d, apr_bucket_brigade *s, apr_bucket *e)
Definition: apreq_util.h:364
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)
static APR_INLINE apr_status_t apreq_brigade_copy(apr_bucket_brigade *d, apr_bucket_brigade *s)
Definition: apreq_util.h:337
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_charset_t apreq_charset_divine(const char *src, apr_size_t slen)
apr_file_t * apreq_brigade_spoolfile(apr_bucket_brigade *bb)
apr_size_t apreq_quote_once(char *dest, const char *src, const apr_size_t slen)
#define APR_BRIGADE_INSERT_TAIL(b, e)
#define APR_BUCKET_NEXT(e)
#define APR_BRIGADE_CONCAT(a, b)
#define APR_BRIGADE_SENTINEL(b)
#define apr_bucket_setaside(e, p)
#define apr_bucket_copy(e, c)
#define APR_BRIGADE_FIRST(b)
#define APR_SUCCESS
int apr_status_t
struct apr_file_t apr_file_t
void * apr_palloc(apr_pool_t *p, apr_size_t size)
struct apr_pool_t apr_pool_t
#define APR_RING_UNSPLICE(ep1, epN, link)
#define APR_RING_SPLICE_HEAD(hp, ep1, epN, elem, link)
#define APR_RING_PREV(ep, link)
#define APR_RING_FIRST(hp)