libapreq2-2.05-dev: libapreq2: include/apreq_util.h Source File

Apache HTTP Server Request Library

Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# apreq_util.h

Go to the documentation of this file.

    00001 /*
    00002 **  Copyright 2003-2005  The Apache Software Foundation
    00003 **
    00004 **  Licensed under the Apache License, Version 2.0 (the "License");
    00005 **  you may not use this file except in compliance with the License.
    00006 **  You may obtain a copy of the License at
    00007 **
    00008 **      http://www.apache.org/licenses/LICENSE-2.0
    00009 **
    00010 **  Unless required by applicable law or agreed to in writing, software
    00011 **  distributed under the License is distributed on an "AS IS" BASIS,
    00012 **  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00013 **  See the License for the specific language governing permissions and
    00014 **  limitations under the License.
    00015 */
    00016
    00017 #ifndef APREQ_UTIL_H
    00018 #define APREQ_UTIL_H
    00019
    00020 #include "apr_file_io.h"
    00021 #include "apr_buckets.h"
    00022 #include "apreq.h"
    00023
    00024 #ifdef  __cplusplus
    00025  extern "C" {
    00026 #endif
    00027
    00052 APREQ_DECLARE(char *) apreq_join(apr_pool_t *p,
    00053                                  const char *sep,
    00054                                  const apr_array_header_t *arr,
    00055                                  apreq_join_t mode);
    00056
    00069 APREQ_DECLARE(apr_ssize_t) apreq_index(const char* hay, apr_size_t hlen,
    00070                                        const char* ndl, apr_size_t nlen,
    00071                                        const apreq_match_t type);
    00072
    00085 APREQ_DECLARE(apr_size_t) apreq_quote(char *dest, const char *src,
    00086                                       const apr_size_t slen);
    00087
    00101 APREQ_DECLARE(apr_size_t) apreq_quote_once(char *dest, const char *src,
    00102                                            const apr_size_t slen);
    00103
    00114 APREQ_DECLARE(apr_size_t) apreq_encode(char *dest, const char *src,
    00115                                        const apr_size_t slen);
    00116
    00128 APREQ_DECLARE(apr_size_t) apreq_cp1252_to_utf8(char *dest,
    00129                                                const char *src, apr_size_t slen);
    00130
    00151 APREQ_DECLARE(apr_status_t) apreq_decode(char *dest, apr_size_t *dlen,
    00152                                          const char *src, apr_size_t slen);
    00153
    00174 APREQ_DECLARE(apr_status_t) apreq_decodev(char *dest, apr_size_t *dlen,
    00175                                           struct iovec *v, int nelts);
    00176
    00189 static APR_INLINE
    00190 char *apreq_escape(apr_pool_t *p, const char *src, const apr_size_t slen)
    00191 {
    00192     char *rv;
    00193
    00194     if (src == NULL)
    00195         return NULL;
    00196
    00197     rv = apr_palloc(p, 3 * slen + 1);
    00198     apreq_encode(rv, src, slen);
    00199     return rv;
    00200 }
    00201
    00209 static APR_INLINE apr_ssize_t apreq_unescape(char *str)
    00210 {
    00211     apr_size_t len;
    00212     apr_status_t rv = apreq_decode(str, &len, str, strlen(str));
    00213     if (rv == APR_SUCCESS)
    00214         return (apr_ssize_t)len;
    00215     else
    00216         return -1;
    00217 }
    00218
    00230 APREQ_DECLARE(apr_int64_t) apreq_atoi64f(const char *s);
    00231
    00243 APREQ_DECLARE(apr_int64_t) apreq_atoi64t(const char *s);
    00244
    00262 APREQ_DECLARE(apr_status_t) apreq_brigade_fwrite(apr_file_t *f,
    00263                                                  apr_off_t *wlen,
    00264                                                  apr_bucket_brigade *bb);
    00281 APREQ_DECLARE(apr_status_t) apreq_file_mktemp(apr_file_t **fp,
    00282                                               apr_pool_t *pool,
    00283                                               const char *path);
    00284
    00294 static APR_INLINE
    00295 apr_status_t apreq_brigade_setaside(apr_bucket_brigade *bb, apr_pool_t *p)
    00296 {
    00297     apr_bucket *e;
    00298     for (e = APR_BRIGADE_FIRST(bb); e != APR_BRIGADE_SENTINEL(bb);
    00299          e = APR_BUCKET_NEXT(e))
    00300     {
    00301         apr_status_t rv = apr_bucket_setaside(e, p);
    00302         if (rv != APR_SUCCESS)
    00303             return rv;
    00304     }
    00305     return APR_SUCCESS;
    00306 }
    00307
    00308
    00321 static APR_INLINE
    00322 apr_status_t apreq_brigade_copy(apr_bucket_brigade *d, apr_bucket_brigade *s) {
    00323     apr_bucket *e;
    00324     for (e = APR_BRIGADE_FIRST(s); e != APR_BRIGADE_SENTINEL(s);
    00325          e = APR_BUCKET_NEXT(e))
    00326     {
    00327         apr_bucket *c;
    00328         apr_status_t rv = apr_bucket_copy(e, &c);
    00329         if (rv != APR_SUCCESS)
    00330             return rv;
    00331
    00332         APR_BRIGADE_INSERT_TAIL(d, c);
    00333     }
    00334     return APR_SUCCESS;
    00335 }
    00336
    00348 static APR_INLINE
    00349 void apreq_brigade_move(apr_bucket_brigade *d, apr_bucket_brigade *s,
    00350                         apr_bucket *e)
    00351 {
    00352     apr_bucket *f;
    00353
    00354     if (e != APR_BRIGADE_SENTINEL(s)) {
    00355         f = APR_RING_FIRST(&s->list);
    00356         APR_RING_UNSPLICE(f, e, link);
    00357         APR_RING_SPLICE_HEAD(&d->list, f, e, apr_bucket, link);
    00358     }
    00359     else {
    00360         APR_BRIGADE_CONCAT(d, s);
    00361     }
    00362 }
    00363
    00364
    00378 APREQ_DECLARE(apr_status_t) apreq_header_attribute(const char *hdr,
    00379                                                    const char *name,
    00380                                                    const apr_size_t nlen,
    00381                                                    const char **val,
    00382                                                    apr_size_t *vlen);
    00383
    00384
    00402 APREQ_DECLARE(apr_status_t) apreq_brigade_concat(apr_pool_t *pool,
    00403                                                  const char *temp_dir,
    00404                                                  apr_size_t brigade_limit,
    00405                                                  apr_bucket_brigade *out,
    00406                                                  apr_bucket_brigade *in);
    00407
    00416 APREQ_DECLARE(apr_file_t *)apreq_brigade_spoolfile(apr_bucket_brigade *bb);
    00417
    00418 #ifdef __cplusplus
    00419  }
    00420 #endif
    00421
    00422 #endif /* APREQ_UTIL_H */