summaryrefslogtreecommitdiffstats
path: root/server/util.c
diff options
context:
space:
mode:
authorWilliam A. Rowe Jr <wrowe@apache.org>2016-07-29 17:56:54 +0200
committerWilliam A. Rowe Jr <wrowe@apache.org>2016-07-29 17:56:54 +0200
commitb167818f7dded95a73f83b181fdcd322fc956cbf (patch)
tree5415a91c379352429716e659921608fb2fdf9bf2 /server/util.c
parentIntroduce T_HTTP_CTRLS for efficiently finding non-text chars (diff)
downloadapache2-b167818f7dded95a73f83b181fdcd322fc956cbf.tar.xz
apache2-b167818f7dded95a73f83b181fdcd322fc956cbf.zip
Introduce ap_scan_http_field_content, ap_scan_http_token
and ap_get_http_token for more efficient string handling. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1754541 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'server/util.c')
-rw-r--r--server/util.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/server/util.c b/server/util.c
index aab8311532..470f6c343b 100644
--- a/server/util.c
+++ b/server/util.c
@@ -80,7 +80,7 @@
* char in here and get it to work, because if char is signed then it
* will first be sign extended.
*/
-#define TEST_CHAR(c, f) (test_char_table[(unsigned)(c)] & (f))
+#define TEST_CHAR(c, f) (test_char_table[(unsigned char)(c)] & (f))
/* Win32/NetWare/OS2 need to check for both forward and back slashes
* in ap_getparents() and ap_escape_url.
@@ -1594,6 +1594,46 @@ AP_DECLARE(const char *) ap_parse_token_list_strict(apr_pool_t *p,
return NULL;
}
+/* Scan a string for HTTP VCHAR/obs-text characters including HT and SP
+ * (as used in header values, for example, in RFC 7230 section 3.2)
+ * returning the pointer to the first non-HT ASCII ctrl character.
+ */
+AP_DECLARE(const char *) ap_scan_http_field_content(const char *ptr)
+{
+ for ( ; !TEST_CHAR(*ptr, T_HTTP_CTRLS); ++ptr) ;
+
+ return ptr;
+}
+
+/* Scan a string for HTTP token characters, returning the pointer to
+ * the first non-token character.
+ */
+AP_DECLARE(const char *) ap_scan_http_token(const char *ptr)
+{
+ for ( ; !TEST_CHAR(*ptr, T_HTTP_TOKEN_STOP); ++ptr) ;
+
+ return ptr;
+}
+
+/* Retrieve a token, advancing the pointer to the first non-token character
+ * and returning a copy of the token string.
+ * The caller must handle whitespace and determine the meaning of the
+ * terminating character. Returns NULL if the character at **ptr is not
+ * a valid token character.
+ */
+AP_DECLARE(char *) ap_get_http_token(apr_pool_t *p, const char **ptr)
+{
+ const char *tok_end = ap_scan_http_token(*ptr);
+ char *tok;
+
+ if (tok_end == *ptr)
+ return NULL;
+
+ tok = apr_pstrmemdup(p, *ptr, tok_end - *ptr);
+ *ptr = tok_end;
+ return tok;
+}
+
/* Retrieve a token, spacing over it and returning a pointer to
* the first non-white byte afterwards. Note that these tokens
* are delimited by semis and commas; and can also be delimited