diff options
author | Stefan Fritsch <sf@apache.org> | 2011-09-26 22:05:09 +0200 |
---|---|---|
committer | Stefan Fritsch <sf@apache.org> | 2011-09-26 22:05:09 +0200 |
commit | e1fc6f9d0c3776f4b95261e4a75f71d0073fbb81 (patch) | |
tree | f383affdaeb83bae206ee1bc37ac6f5e6a4fb5d4 /include | |
parent | Adjust log message to reflect changed behaviour (diff) | |
download | apache2-e1fc6f9d0c3776f4b95261e4a75f71d0073fbb81.tar.xz apache2-e1fc6f9d0c3776f4b95261e4a75f71d0073fbb81.zip |
Some varbuf enhancements:
- Introduce new ap_varbuf_pdup() and ap_varbuf_regsub() functions.
- Fix some bugs in ap_varbuf_strmemcat().
- Make ap_varbuf.buf point to an empty string if no buffer has been allocated,
yet.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1176018 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'include')
-rw-r--r-- | include/ap_mmn.h | 3 | ||||
-rw-r--r-- | include/util_varbuf.h | 38 |
2 files changed, 39 insertions, 2 deletions
diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 94796ddd68..7a0f04943f 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -354,6 +354,7 @@ * 20110724.7 (2.3.15-dev) add ap_random_insecure_bytes(), ap_random_pick() * 20110724.8 (2.3.15-dev) add ap_abort_on_oom(), ap_malloc(), ap_calloc(), * ap_realloc() + * 20110724.9 (2.3.15-dev) add ap_varbuf_pdup() and ap_varbuf_regsub() */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ @@ -361,7 +362,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20110724 #endif -#define MODULE_MAGIC_NUMBER_MINOR 8 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 9 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/util_varbuf.h b/include/util_varbuf.h index ceb46feb3c..dc55e2c90c 100644 --- a/include/util_varbuf.h +++ b/include/util_varbuf.h @@ -36,7 +36,7 @@ struct ap_varbuf_info; /** A resizable buffer */ struct ap_varbuf { - /** the actual buffer */ + /** the actual buffer; will point to a const '\0' if avail == 0 */ char *buf; /** allocated size of the buffer (minus one for the final \0); @@ -100,6 +100,26 @@ AP_DECLARE(void) ap_varbuf_free(struct ap_varbuf *vb); AP_DECLARE(void) ap_varbuf_strmemcat(struct ap_varbuf *vb, const char *str, int len); +/** Duplicate an ap_varbuf's content into pool memory + * @param p the pool to allocate from + * @param vb the ap_varbuf to copy from + * @param prepend an optional buffer to prepend (may be NULL) + * @param prepend_len length of prepend + * @param append an optional buffer to append (may be NULL) + * @param append_len length of append + * @param new_len where to store the length of the resulting string + * (may be NULL) + * @return the new string + * @note ap_varbuf_pdup() uses vb->strlen to determine how much memory to + * copy. It works even if 0-bytes are embedded in vb->buf, prepend, or + * append + */ +AP_DECLARE(char *) ap_varbuf_pdup(apr_pool_t *p, struct ap_varbuf *vb, + const char *prepend, apr_size_t prepend_len, + const char *append, apr_size_t append_len, + apr_size_t *new_len); + + /** Concatenate a string to an ap_varbuf * @param vb pointer to the ap_varbuf struct * @param str the string to append @@ -107,6 +127,22 @@ AP_DECLARE(void) ap_varbuf_strmemcat(struct ap_varbuf *vb, const char *str, */ #define ap_varbuf_strcat(vb, str) ap_varbuf_strmemcat(vb, str, strlen(str)) +/** Perform string substitutions based on regexp match, using an ap_varbuf. + * This function behaves like ap_pregsub(), but appends to an ap_varbuf + * instead of allocating the result from a pool. + * @param input An arbitrary string containing $1 through $9. These are + * replaced with the corresponding matched sub-expressions + * @param source The string that was originally matched to the regex + * @param nmatch the nmatch returned from ap_pregex + * @param pmatch the pmatch array returned from ap_pregex + * @note Just like ap_pregsub(), this function does not copy the part of + * *source before the matching part (i.e. the first pmatch[0].rm_so + * characters). + */ +AP_DECLARE(void) ap_varbuf_regsub(struct ap_varbuf *vb, const char *input, + const char *source, size_t nmatch, + ap_regmatch_t pmatch[]); + /** Read a line from an ap_configfile_t into an ap_varbuf. * @param vb pointer to the ap_varbuf struct * @param cfg pointer to the ap_configfile_t |