Apache HTTP Server Request Library
00001 /* 00002 ** Copyright 2003-2006 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 00142 APREQ_DECLARE(apreq_charset_t) apreq_charset_divine(const char *src, 00143 apr_size_t slen); 00144 00165 APREQ_DECLARE(apr_status_t) apreq_decode(char *dest, apr_size_t *dlen, 00166 const char *src, apr_size_t slen); 00167 00188 APREQ_DECLARE(apr_status_t) apreq_decodev(char *dest, apr_size_t *dlen, 00189 struct iovec *v, int nelts); 00190 00203 static APR_INLINE 00204 char *apreq_escape(apr_pool_t *p, const char *src, const apr_size_t slen) 00205 { 00206 char *rv; 00207 00208 if (src == NULL) 00209 return NULL; 00210 00211 rv = (char *)apr_palloc(p, 3 * slen + 1); 00212 apreq_encode(rv, src, slen); 00213 return rv; 00214 } 00215 00223 static APR_INLINE apr_ssize_t apreq_unescape(char *str) 00224 { 00225 apr_size_t len; 00226 apr_status_t rv = apreq_decode(str, &len, str, strlen(str)); 00227 if (rv == APR_SUCCESS) 00228 return (apr_ssize_t)len; 00229 else 00230 return -1; 00231 } 00232 00244 APREQ_DECLARE(apr_int64_t) apreq_atoi64f(const char *s); 00245 00257 APREQ_DECLARE(apr_int64_t) apreq_atoi64t(const char *s); 00258 00276 APREQ_DECLARE(apr_status_t) apreq_brigade_fwrite(apr_file_t *f, 00277 apr_off_t *wlen, 00278 apr_bucket_brigade *bb); 00295 APREQ_DECLARE(apr_status_t) apreq_file_mktemp(apr_file_t **fp, 00296 apr_pool_t *pool, 00297 const char *path); 00298 00308 static APR_INLINE 00309 apr_status_t apreq_brigade_setaside(apr_bucket_brigade *bb, apr_pool_t *p) 00310 { 00311 apr_bucket *e; 00312 for (e = APR_BRIGADE_FIRST(bb); e != APR_BRIGADE_SENTINEL(bb); 00313 e = APR_BUCKET_NEXT(e)) 00314 { 00315 apr_status_t rv = apr_bucket_setaside(e, p); 00316 if (rv != APR_SUCCESS) 00317 return rv; 00318 } 00319 return APR_SUCCESS; 00320 } 00321 00322 00335 static APR_INLINE 00336 apr_status_t apreq_brigade_copy(apr_bucket_brigade *d, apr_bucket_brigade *s) { 00337 apr_bucket *e; 00338 for (e = APR_BRIGADE_FIRST(s); e != APR_BRIGADE_SENTINEL(s); 00339 e = APR_BUCKET_NEXT(e)) 00340 { 00341 apr_bucket *c; 00342 apr_status_t rv = apr_bucket_copy(e, &c); 00343 if (rv != APR_SUCCESS) 00344 return rv; 00345 00346 APR_BRIGADE_INSERT_TAIL(d, c); 00347 } 00348 return APR_SUCCESS; 00349 } 00350 00362 static APR_INLINE 00363 void apreq_brigade_move(apr_bucket_brigade *d, apr_bucket_brigade *s, 00364 apr_bucket *e) 00365 { 00366 apr_bucket *f; 00367 00368 if (e != APR_BRIGADE_SENTINEL(s)) { 00369 f = APR_RING_FIRST(&s->list); 00370 if (f == e) /* zero buckets to be moved */ 00371 return; 00372 00373 /* obtain the last bucket to be moved */ 00374 e = APR_RING_PREV(e, link); 00375 00376 APR_RING_UNSPLICE(f, e, link); 00377 APR_RING_SPLICE_HEAD(&d->list, f, e, apr_bucket, link); 00378 } 00379 else { 00380 APR_BRIGADE_CONCAT(d, s); 00381 } 00382 } 00383 00384 00398 APREQ_DECLARE(apr_status_t) apreq_header_attribute(const char *hdr, 00399 const char *name, 00400 const apr_size_t nlen, 00401 const char **val, 00402 apr_size_t *vlen); 00403 00404 00422 APREQ_DECLARE(apr_status_t) apreq_brigade_concat(apr_pool_t *pool, 00423 const char *temp_dir, 00424 apr_size_t brigade_limit, 00425 apr_bucket_brigade *out, 00426 apr_bucket_brigade *in); 00427 00436 APREQ_DECLARE(apr_file_t *)apreq_brigade_spoolfile(apr_bucket_brigade *bb); 00437 00438 #ifdef __cplusplus 00439 } 00440 #endif 00441 00442 #endif /* APREQ_UTIL_H */