diff options
author | dormando <dormando@rydia.net> | 2016-07-30 12:42:23 -0700 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2016-08-19 17:34:55 -0700 |
commit | a8347f6d0913a3cf22d30400b66bfcedf610ebf9 (patch) | |
tree | 1ede0116490e8567bfd35ccf9382d23829620a0b /util.c | |
parent | c793bae62ebbf9b0c2b0663fcbd33684262e3062 (diff) | |
download | memcached-a8347f6d0913a3cf22d30400b66bfcedf610ebf9.tar.gz |
prototype functionality for LRU metadumper
Functionality is nearly all there. A handful of FIXME's and TODO's to address.
From there it needs to be refactored into something proper.
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -8,6 +8,41 @@ #include "memcached.h" +static char *uriencode_map[256]; +static char uriencode_str[768]; + +void uriencode_init(void) { + int x; + char *str = uriencode_str; + for (x = 0; x < 256; x++) { + if (isalnum(x) || x == '-' || x == '.' || x == '_' || x == '~') { + uriencode_map[x] = NULL; + } else { + snprintf(str, 4, "%%%02X", x); + uriencode_map[x] = str; + str += 3; /* lobbing off the \0 is fine */ + } + } +} + +bool uriencode(const char *src, char *dst, const size_t srclen, const size_t dstlen) { + int x; + size_t d = 0; + for (x = 0; x < srclen; x++) { + if (d + 4 >= dstlen) + return false; + if (uriencode_map[(unsigned char) src[x]] != NULL) { + memcpy(&dst[d], uriencode_map[(unsigned char) src[x]], 3); + d += 3; + } else { + dst[d] = src[x]; + d++; + } + } + dst[d] = '\0'; + return true; +} + /* Avoid warnings on solaris, where isspace() is an index into an array, and gcc uses signed chars */ #define xisspace(c) isspace((unsigned char)c) |