BBlack has submitted this change and it was merged.
Change subject: normalize_path: make it a C function
......................................................................
normalize_path: make it a C function
Bug: T127387
Change-Id: I127dd0afa72e83aefe9fe82b454216a2c9bf0caa
---
M templates/varnish/normalize_path.inc.vcl.erb
1 file changed, 73 insertions(+), 67 deletions(-)
Approvals:
BBlack: Verified; Looks good to me, approved
diff --git a/templates/varnish/normalize_path.inc.vcl.erb
b/templates/varnish/normalize_path.inc.vcl.erb
index b314042..8050fd3 100644
--- a/templates/varnish/normalize_path.inc.vcl.erb
+++ b/templates/varnish/normalize_path.inc.vcl.erb
@@ -1,7 +1,18 @@
C{
- #include <string.h>
-}C
-sub normalize_path {
+#include <string.h>
+
+/* DIY hexadecimal conversion, since it is simple enough for a fixed
+ * width, and all the relevant standard C library functions promise to
+ * malfunction if the locale is set to anything other than "C"
+ */
+#define NP_HEX_DIGIT(c) ( \
+ (c) >= '0' && (c) <= '9' ? (c) - '0' : ( \
+ (c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 0x0a : ( \
+ (c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 0x0a : -1 ) ) )
+#define NP_IS_HEX(c) (NP_HEX_DIGIT(c) != -1)
+#define NP_HEXCHAR(c1, c2) (char)( (NP_HEX_DIGIT(c1) << 4) | NP_HEX_DIGIT(c2) )
+
+void raw_normalize_path(struct sess *sp) {
/* Rewrite the path part of the URL, replacing unnecessarily escaped
* punctuation with the actual characters. The character list is from
* MediaWiki's wfUrlencode(), so the URLs produced here will be the
same as
@@ -9,74 +20,69 @@
* cache fragmentation and fixes T29935, i.e. stale cache entries due to
* MediaWiki purging only the wfUrlencode'd version of the URL.
*/
- C{
- /* DIY hexadecimal conversion, since it is simple enough for a
fixed
- * width, and all the relevant standard C library functions
promise to
- * malfunction if the locale is set to anything other than "C"
- */
- #define NP_HEX_DIGIT(c) ( \
- (c) >= '0' && (c) <= '9' ? (c) - '0' : ( \
- (c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 0x0a : (
\
- (c) >= 'a' && (c) <= 'f' ? (c) - 'a' +
0x0a : -1 ) ) )
- #define NP_IS_HEX(c) (NP_HEX_DIGIT(c) != -1)
- #define NP_HEXCHAR(c1, c2) (char)( (NP_HEX_DIGIT(c1) << 4) |
NP_HEX_DIGIT(c2) )
- const char * url = VRT_r_req_url(sp);
- size_t i, outPos;
- const size_t urlLength = strlen(url);
- // index for the last position %XX can start at:
- const size_t lastConvertIdx = urlLength > 2 ? urlLength - 3 : 0;
- char c;
- int dirty = 0;
+ const char * url = VRT_r_req_url(sp);
+ size_t i, outPos;
+ const size_t urlLength = strlen(url);
+ // index for the last position %XX can start at:
+ const size_t lastConvertIdx = urlLength > 2 ? urlLength - 3 : 0;
+ char c;
+ int dirty = 0;
- /* Allocate destination memory from the stack using the C99
- * variable-length automatic feature. We know the length in
advance
- * because this function can only shorten the input string.
- */
- char destBuffer[urlLength + 1];
- if (url) {
- for (i = 0, outPos = 0; i < urlLength; i++) {
- if (i <= lastConvertIdx && url[i] == '%' &&
NP_IS_HEX(url[i+1]) && NP_IS_HEX(url[i+2])) {
- c = NP_HEXCHAR(url[i+1], url[i+2]);
- if (c == ';'
- || c == '@'
- || c == '$'
- || c == '!'
- || c == '*'
- || c == '('
- || c == ')'
- || c == ','
- || c == '/'
- || c == ':')
- {
- destBuffer[outPos++] = c;
- dirty = 1;
- i += 2;
- } else {
- destBuffer[outPos++] = url[i];
- }
- } else if (url[i] == '?') {
- /* Reached the query part. Just copy
the rest of the URL
- * to the destination.
- */
- memcpy(destBuffer + outPos, url + i,
sizeof(char) * (urlLength - i));
- outPos += urlLength - i;
- i = urlLength;
+ /* Allocate destination memory from the stack using the C99
+ * variable-length automatic feature. We know the length in advance
+ * because this function can only shorten the input string.
+ */
+ char destBuffer[urlLength + 1];
+ if (url) {
+ for (i = 0, outPos = 0; i < urlLength; i++) {
+ if (i <= lastConvertIdx && url[i] == '%' &&
NP_IS_HEX(url[i+1]) && NP_IS_HEX(url[i+2])) {
+ c = NP_HEXCHAR(url[i+1], url[i+2]);
+ if (c == ';'
+ || c == '@'
+ || c == '$'
+ || c == '!'
+ || c == '*'
+ || c == '('
+ || c == ')'
+ || c == ','
+ || c == '/'
+ || c == ':')
+ {
+ destBuffer[outPos++] = c;
+ dirty = 1;
+ i += 2;
} else {
destBuffer[outPos++] = url[i];
}
- }
- destBuffer[outPos] = '\0';
-
- /* Set req.url. This will copy our stack buffer into
the workspace.
- * VRT_l_req_url() is varadic, and concatenates its
arguments. The
- * vrt_magic_string_end marks the end of the list.
- */
- if (dirty) {
- VRT_l_req_url(sp, destBuffer,
vrt_magic_string_end);
+ } else if (url[i] == '?') {
+ /* Reached the query part. Just copy the rest
of the URL
+ * to the destination.
+ */
+ memcpy(destBuffer + outPos, url + i,
sizeof(char) * (urlLength - i));
+ outPos += urlLength - i;
+ i = urlLength;
+ } else {
+ destBuffer[outPos++] = url[i];
}
}
- #undef NP_IS_HEX
- #undef NP_HEX_DIGIT
- #undef NP_HEXCHAR
- }C
+ destBuffer[outPos] = '\0';
+
+ /* Set req.url. This will copy our stack buffer into the
workspace.
+ * VRT_l_req_url() is varadic, and concatenates its arguments.
The
+ * vrt_magic_string_end marks the end of the list.
+ */
+ if (dirty) {
+ VRT_l_req_url(sp, destBuffer, vrt_magic_string_end);
+ }
+ }
+}
+
+#undef NP_IS_HEX
+#undef NP_HEX_DIGIT
+#undef NP_HEXCHAR
+
+}C
+
+sub normalize_path {
+ C{ raw_normalize_path(sp); }C
}
--
To view, visit https://gerrit.wikimedia.org/r/274084
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I127dd0afa72e83aefe9fe82b454216a2c9bf0caa
Gerrit-PatchSet: 3
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: BBlack <[email protected]>
Gerrit-Reviewer: BBlack <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits