aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_string.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-10-11 15:07:03 +0000
committerIgor Sysoev <igor@sysoev.ru>2004-10-11 15:07:03 +0000
commit924bd79e317e9a137c0d1b9d349185758a628ec4 (patch)
treef877c8b19e53e7d0a7683e3dd9aeb713146c4a8f /src/core/ngx_string.c
parentaef13d7f6660f4f8d2c50c95b8e182e62c115f88 (diff)
downloadnginx-924bd79e317e9a137c0d1b9d349185758a628ec4.tar.gz
nginx-924bd79e317e9a137c0d1b9d349185758a628ec4.zip
nginx-0.1.1-RELEASE importrelease-0.1.1
*) Feature: the gzip_types directive. *) Feature: the tcp_nodelay directive. *) Feature: the send_lowat directive is working not only on OSes that support kqueue NOTE_LOWAT, but also on OSes that support SO_SNDLOWAT. *) Feature: the setproctitle() emulation for Linux and Solaris. *) Bugfix: the "Location" header rewrite bug fixed while the proxying. *) Bugfix: the ngx_http_chunked_module module may get caught in an endless loop. *) Bugfix: the /dev/poll module bugs fixed. *) Bugfix: the responses were corrupted when the temporary files were used while the proxying. *) Bugfix: the unescaped requests were passed to the backend. *) Bugfix: while the build configuration on Linux 2.4 the --with-poll_module parameter was required.
Diffstat (limited to 'src/core/ngx_string.c')
-rw-r--r--src/core/ngx_string.c93
1 files changed, 47 insertions, 46 deletions
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index 3d6a9eb1d..32a4079a0 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -128,7 +128,7 @@ void ngx_md5_text(u_char *text, u_char *md5)
}
-void ngx_encode_base64(ngx_str_t *src, ngx_str_t *dst)
+void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src)
{
u_char *d, *s;
size_t len;
@@ -168,7 +168,7 @@ void ngx_encode_base64(ngx_str_t *src, ngx_str_t *dst)
}
-ngx_int_t ngx_decode_base64(ngx_str_t *src, ngx_str_t *dst)
+ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src)
{
size_t len;
u_char *d, *s;
@@ -231,54 +231,55 @@ ngx_int_t ngx_decode_base64(ngx_str_t *src, ngx_str_t *dst)
}
-#if 0
-char *ngx_psprintf(ngx_pool_t *p, const char *fmt, ...)
+ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size)
{
- va_list args;
-
- va_start(args, fmt);
-
- while (*fmt) {
- switch(*fmt++) {
- case '%':
- switch(*fmt++) {
- case 's':
- s = va_arg(args, char *);
- n += ngx_strlen(s);
- break;
-
- default:
- n++;
- }
- default:
- n++;
- }
- }
+ ngx_int_t n;
+ ngx_uint_t i;
+ static u_char hex[] = "0123456789abcdef";
+ static uint32_t escape[] =
+ { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
+ 0x80000021, /* 1000 0000 0000 0000 0000 0000 0010 0001 */
+
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
+
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
+ 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
+
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
+
+ if (dst == NULL) {
+
+ /* find the number of the characters to be escaped */
- str = ngx_palloc(p, n);
-
- va_start(args, fmt);
-
- for (i = 0; i < n; i++) {
- switch(*fmt++) {
- case '%':
- switch(*fmt++) {
- case 's':
- s = va_arg(args, char *);
- while (str[i++] = s);
- break;
-
- default:
- n++;
- }
- default:
- str[i] = *fmt;
- }
+ n = 0;
+
+ for (i = 0; i < size; i++) {
+ if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
+ n++;
+ }
+ src++;
+ }
+
+ return n;
}
- len += ngx_vsnprintf(errstr + len, sizeof(errstr) - len - 1, fmt, args);
+ for (i = 0; i < size; i++) {
+ if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
+ *dst++ = '%';
+ *dst++ = hex[*src >> 4];
+ *dst++ = hex[*src & 0xf];
+ src++;
- va_end(args);
+ } else {
+ *dst++ = *src++;
+ }
+ }
+ return NGX_OK;
}
-#endif