X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=utils_params.c;h=6e5dc892e377a43fb8b619772767dd1d13e02854;hb=d16fd38d41ba3c36820ae105988f42c900fcb30f;hp=ec943b56eaa8746435a0d9d32a48b9aa589382d7;hpb=9e5770370bb085ccfb19f3dd14707542bf1475f1;p=collection4.git diff --git a/utils_params.c b/utils_params.c index ec943b5..6e5dc89 100644 --- a/utils_params.c +++ b/utils_params.c @@ -215,4 +215,45 @@ const char *param (const char *key) /* {{{ */ return (parameter_lookup (key)); } /* }}} const char *param */ +int uri_escape (char *dst, const char *src, size_t size) /* {{{ */ +{ + size_t in; + size_t out; + + in = 0; + out = 0; + while (42) + { + if (src[in] == 0) + { + dst[out] = 0; + return (0); + } + else if ((src[in] < 32) + || (src[in] == '&') + || (src[in] == ';') + || (src[in] >= 128)) + { + char esc[4]; + + if ((size - out) < 4) + break; + + snprintf (esc, sizeof (esc), "%%%02x", (unsigned int) src[in]); + dst[out] = esc[0]; + dst[out+1] = esc[1]; + dst[out+2] = esc[2]; + + out += 3; + in++; + } + else + { + dst[out] = src[in]; + out++; + in++; + } + } /* while (42) */ +} /* }}} int uri_escape */ + /* vim: set sw=2 sts=2 et fdm=marker : */