Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
Igor Sysoev | ff8da91 | 2004-09-29 16:00:49 +0000 | [diff] [blame] | 3 | * Copyright (C) Igor Sysoev |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 7 | #ifndef _NGX_STRING_H_INCLUDED_ |
| 8 | #define _NGX_STRING_H_INCLUDED_ |
| 9 | |
| 10 | |
| 11 | #include <ngx_config.h> |
Igor Sysoev | 1c10462 | 2003-06-03 15:42:58 +0000 | [diff] [blame] | 12 | #include <ngx_core.h> |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 13 | |
| 14 | |
Igor Sysoev | a0bb31f | 2002-12-02 16:09:40 +0000 | [diff] [blame] | 15 | typedef struct { |
Igor Sysoev | f42ed05 | 2007-07-17 09:23:23 +0000 | [diff] [blame] | 16 | size_t len; |
| 17 | u_char *data; |
Igor Sysoev | a0bb31f | 2002-12-02 16:09:40 +0000 | [diff] [blame] | 18 | } ngx_str_t; |
| 19 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 20 | |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 21 | typedef struct { |
Igor Sysoev | f42ed05 | 2007-07-17 09:23:23 +0000 | [diff] [blame] | 22 | ngx_str_t key; |
| 23 | ngx_str_t value; |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 24 | } ngx_keyval_t; |
| 25 | |
| 26 | |
Igor Sysoev | f42ed05 | 2007-07-17 09:23:23 +0000 | [diff] [blame] | 27 | typedef struct { |
Igor Sysoev | 5f3521c | 2008-05-15 15:09:39 +0000 | [diff] [blame] | 28 | unsigned len:28; |
Igor Sysoev | f42ed05 | 2007-07-17 09:23:23 +0000 | [diff] [blame] | 29 | |
| 30 | unsigned valid:1; |
Igor Sysoev | 2d3f3f6 | 2007-10-14 18:56:15 +0000 | [diff] [blame] | 31 | unsigned no_cacheable:1; |
Igor Sysoev | f42ed05 | 2007-07-17 09:23:23 +0000 | [diff] [blame] | 32 | unsigned not_found:1; |
Igor Sysoev | 5f3521c | 2008-05-15 15:09:39 +0000 | [diff] [blame] | 33 | unsigned escape:1; |
Igor Sysoev | f42ed05 | 2007-07-17 09:23:23 +0000 | [diff] [blame] | 34 | |
| 35 | u_char *data; |
| 36 | } ngx_variable_value_t; |
| 37 | |
| 38 | |
Igor Sysoev | 722231f | 2007-02-14 18:51:19 +0000 | [diff] [blame] | 39 | #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } |
| 40 | #define ngx_null_string { 0, NULL } |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 41 | |
| 42 | |
Igor Sysoev | 722231f | 2007-02-14 18:51:19 +0000 | [diff] [blame] | 43 | #define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c) |
| 44 | #define ngx_toupper(c) (u_char) ((c >= 'a' && c <= 'z') ? (c & ~0x20) : c) |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 45 | |
Igor Sysoev | 777b019 | 2008-08-04 10:07:00 +0000 | [diff] [blame] | 46 | void ngx_strlow(u_char *dst, u_char *src, size_t n); |
| 47 | |
Igor Sysoev | 3646a16 | 2004-03-14 20:46:25 +0000 | [diff] [blame] | 48 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 49 | #define ngx_strncmp(s1, s2, n) strncmp((const char *) s1, (const char *) s2, n) |
| 50 | |
Igor Sysoev | 3646a16 | 2004-03-14 20:46:25 +0000 | [diff] [blame] | 51 | |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 52 | /* msvc and icc7 compile strcmp() to inline loop */ |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 53 | #define ngx_strcmp(s1, s2) strcmp((const char *) s1, (const char *) s2) |
Igor Sysoev | 3646a16 | 2004-03-14 20:46:25 +0000 | [diff] [blame] | 54 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 55 | |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 56 | #define ngx_strstr(s1, s2) strstr((const char *) s1, (const char *) s2) |
| 57 | #define ngx_strlen(s) strlen((const char *) s) |
Igor Sysoev | 3646a16 | 2004-03-14 20:46:25 +0000 | [diff] [blame] | 58 | |
Igor Sysoev | caa4a45 | 2008-08-26 14:16:36 +0000 | [diff] [blame] | 59 | #define ngx_strchr(s1, c) strchr((const char *) s1, (int) c) |
| 60 | |
| 61 | static ngx_inline u_char * |
| 62 | ngx_strlchr(u_char *p, u_char *last, u_char c) |
| 63 | { |
| 64 | while (p < last) { |
| 65 | |
| 66 | if (*p == c) { |
| 67 | return p; |
| 68 | } |
| 69 | |
| 70 | p++; |
| 71 | } |
| 72 | |
| 73 | return NULL; |
| 74 | } |
| 75 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 76 | |
Igor Sysoev | 6abfde6 | 2003-07-01 15:00:03 +0000 | [diff] [blame] | 77 | /* |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 78 | * msvc and icc7 compile memset() to the inline "rep stos" |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 79 | * while ZeroMemory() and bzero() are the calls. |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 80 | * icc7 may also inline several mov's of a zeroed register for small blocks. |
Igor Sysoev | 6abfde6 | 2003-07-01 15:00:03 +0000 | [diff] [blame] | 81 | */ |
Igor Sysoev | e31e90b | 2005-05-19 13:25:22 +0000 | [diff] [blame] | 82 | #define ngx_memzero(buf, n) (void) memset(buf, 0, n) |
| 83 | #define ngx_memset(buf, c, n) (void) memset(buf, c, n) |
Igor Sysoev | 6abfde6 | 2003-07-01 15:00:03 +0000 | [diff] [blame] | 84 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 85 | |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 86 | #if (NGX_MEMCPY_LIMIT) |
| 87 | |
| 88 | void *ngx_memcpy(void *dst, void *src, size_t n); |
| 89 | #define ngx_cpymem(dst, src, n) ((u_char *) ngx_memcpy(dst, src, n)) + (n) |
| 90 | |
| 91 | #else |
| 92 | |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 93 | /* |
| 94 | * gcc3, msvc, and icc7 compile memcpy() to the inline "rep movs". |
| 95 | * gcc3 compiles memcpy(d, s, 4) to the inline "mov"es. |
| 96 | * icc8 compile memcpy(d, s, 4) to the inline "mov"es or XMM moves. |
| 97 | */ |
Igor Sysoev | e31e90b | 2005-05-19 13:25:22 +0000 | [diff] [blame] | 98 | #define ngx_memcpy(dst, src, n) (void) memcpy(dst, src, n) |
Igor Sysoev | 02025fd | 2005-01-18 13:03:58 +0000 | [diff] [blame] | 99 | #define ngx_cpymem(dst, src, n) ((u_char *) memcpy(dst, src, n)) + (n) |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 100 | |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 101 | #endif |
| 102 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 103 | |
Igor Sysoev | 09c684b | 2005-11-09 17:25:55 +0000 | [diff] [blame] | 104 | #if ( __INTEL_COMPILER >= 800 ) |
| 105 | |
| 106 | /* |
| 107 | * the simple inline cycle copies the variable length strings up to 16 |
| 108 | * bytes faster than icc8 autodetecting _intel_fast_memcpy() |
| 109 | */ |
| 110 | |
| 111 | static ngx_inline u_char * |
| 112 | ngx_copy(u_char *dst, u_char *src, size_t len) |
| 113 | { |
| 114 | if (len < 17) { |
| 115 | |
| 116 | while (len) { |
| 117 | *dst++ = *src++; |
| 118 | len--; |
| 119 | } |
| 120 | |
| 121 | return dst; |
| 122 | |
| 123 | } else { |
| 124 | return ngx_cpymem(dst, src, len); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | #else |
| 129 | |
| 130 | #define ngx_copy ngx_cpymem |
| 131 | |
| 132 | #endif |
| 133 | |
| 134 | |
| 135 | /* msvc and icc7 compile memcmp() to the inline loop */ |
Igor Sysoev | 2e8f0d0 | 2007-11-23 17:00:11 +0000 | [diff] [blame] | 136 | #define ngx_memcmp(s1, s2, n) memcmp((const char *) s1, (const char *) s2, n) |
Igor Sysoev | 6abfde6 | 2003-07-01 15:00:03 +0000 | [diff] [blame] | 137 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 138 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 139 | u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n); |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 140 | u_char *ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src); |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 141 | u_char * ngx_cdecl ngx_sprintf(u_char *buf, const char *fmt, ...); |
| 142 | u_char * ngx_cdecl ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...); |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 143 | u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args); |
Igor Sysoev | c0edbcc | 2004-10-21 15:34:38 +0000 | [diff] [blame] | 144 | |
Igor Sysoev | 722231f | 2007-02-14 18:51:19 +0000 | [diff] [blame] | 145 | ngx_int_t ngx_strcasecmp(u_char *s1, u_char *s2); |
| 146 | ngx_int_t ngx_strncasecmp(u_char *s1, u_char *s2, size_t n); |
| 147 | |
Igor Sysoev | 35fe5fd | 2007-10-01 14:48:33 +0000 | [diff] [blame] | 148 | u_char *ngx_strnstr(u_char *s1, char *s2, size_t n); |
| 149 | |
Igor Sysoev | 1bd9870 | 2007-09-26 19:25:52 +0000 | [diff] [blame] | 150 | u_char *ngx_strstrn(u_char *s1, char *s2, size_t n); |
| 151 | u_char *ngx_strcasestrn(u_char *s1, char *s2, size_t n); |
| 152 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 153 | ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n); |
Igor Sysoev | c0edbcc | 2004-10-21 15:34:38 +0000 | [diff] [blame] | 154 | ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n); |
Igor Sysoev | ec3cabd | 2007-01-12 21:58:02 +0000 | [diff] [blame] | 155 | ngx_int_t ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2); |
Igor Sysoev | 18684bd | 2004-05-20 17:33:52 +0000 | [diff] [blame] | 156 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 157 | ngx_int_t ngx_atoi(u_char *line, size_t n); |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 158 | ssize_t ngx_atosz(u_char *line, size_t n); |
| 159 | off_t ngx_atoof(u_char *line, size_t n); |
| 160 | time_t ngx_atotm(u_char *line, size_t n); |
Igor Sysoev | 18684bd | 2004-05-20 17:33:52 +0000 | [diff] [blame] | 161 | ngx_int_t ngx_hextoi(u_char *line, size_t n); |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 162 | |
Igor Sysoev | a03fa36 | 2007-12-17 21:06:17 +0000 | [diff] [blame] | 163 | u_char *ngx_hex_dump(u_char *dst, u_char *src, size_t len); |
Igor Sysoev | 9cc1ace | 2003-11-04 22:12:39 +0000 | [diff] [blame] | 164 | |
Igor Sysoev | a7c4a2a | 2004-08-29 03:55:41 +0000 | [diff] [blame] | 165 | |
| 166 | #define ngx_base64_encoded_length(len) (((len + 2) / 3) * 4) |
| 167 | #define ngx_base64_decoded_length(len) (((len + 3) / 4) * 3) |
| 168 | |
Igor Sysoev | 924bd79 | 2004-10-11 15:07:03 +0000 | [diff] [blame] | 169 | void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src); |
| 170 | ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src); |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 171 | |
Igor Sysoev | a089857 | 2008-07-29 14:41:34 +0000 | [diff] [blame] | 172 | uint32_t ngx_utf8_decode(u_char **p, size_t n); |
| 173 | size_t ngx_utf8_length(u_char *p, size_t n); |
| 174 | u_char *ngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len); |
Igor Sysoev | 5192b36 | 2005-07-08 14:34:20 +0000 | [diff] [blame] | 175 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 176 | |
Igor Sysoev | f0a51cf | 2007-10-22 10:19:17 +0000 | [diff] [blame] | 177 | #define NGX_ESCAPE_URI 0 |
| 178 | #define NGX_ESCAPE_ARGS 1 |
| 179 | #define NGX_ESCAPE_HTML 2 |
| 180 | #define NGX_ESCAPE_REFRESH 3 |
| 181 | #define NGX_ESCAPE_MEMCACHED 4 |
| 182 | #define NGX_ESCAPE_MAIL_AUTH 5 |
Igor Sysoev | ae33d01 | 2006-01-17 20:04:32 +0000 | [diff] [blame] | 183 | |
Igor Sysoev | f0a51cf | 2007-10-22 10:19:17 +0000 | [diff] [blame] | 184 | #define NGX_UNESCAPE_URI 1 |
| 185 | #define NGX_UNESCAPE_REDIRECT 2 |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 186 | |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 187 | uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size, |
Igor Sysoev | d039a2e | 2005-02-22 14:40:13 +0000 | [diff] [blame] | 188 | ngx_uint_t type); |
Igor Sysoev | ae33d01 | 2006-01-17 20:04:32 +0000 | [diff] [blame] | 189 | void ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type); |
Igor Sysoev | 1730c75 | 2007-09-27 09:36:50 +0000 | [diff] [blame] | 190 | uintptr_t ngx_escape_html(u_char *dst, u_char *src, size_t size); |
| 191 | |
Igor Sysoev | 967fd63 | 2004-08-27 15:40:59 +0000 | [diff] [blame] | 192 | |
Igor Sysoev | 9cc1ace | 2003-11-04 22:12:39 +0000 | [diff] [blame] | 193 | |
Igor Sysoev | 3592128 | 2007-05-21 14:05:23 +0000 | [diff] [blame] | 194 | void ngx_sort(void *base, size_t n, size_t size, |
Igor Sysoev | de8ec1e | 2008-03-24 13:04:02 +0000 | [diff] [blame] | 195 | ngx_int_t (*cmp)(const void *, const void *)); |
Igor Sysoev | 3f70782 | 2007-07-22 19:18:59 +0000 | [diff] [blame] | 196 | #define ngx_qsort qsort |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 197 | |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 198 | |
Igor Sysoev | 3f70782 | 2007-07-22 19:18:59 +0000 | [diff] [blame] | 199 | #define ngx_value_helper(n) #n |
| 200 | #define ngx_value(n) ngx_value_helper(n) |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 201 | |
| 202 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 203 | #endif /* _NGX_STRING_H_INCLUDED_ */ |