0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #ifndef _NGX_STRING_H_INCLUDED_
|
|
8 #define _NGX_STRING_H_INCLUDED_
|
|
9
|
|
10
|
|
11 #include <ngx_config.h>
|
|
12 #include <ngx_core.h>
|
|
13
|
|
14
|
|
15 typedef struct {
|
198
|
16 size_t len;
|
|
17 u_char *data;
|
0
|
18 } ngx_str_t;
|
|
19
|
|
20
|
198
|
21 typedef struct {
|
|
22 ngx_str_t key;
|
|
23 ngx_str_t value;
|
|
24 } ngx_keyval_t;
|
|
25
|
|
26
|
286
|
27 #define ngx_string(str) { sizeof(str) - 1, (u_char *) str }
|
|
28 #define ngx_null_string { 0, NULL }
|
26
|
29
|
|
30
|
286
|
31 #define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)
|
|
32 #define ngx_toupper(c) (u_char) ((c >= 'a' && c <= 'z') ? (c & ~0x20) : c)
|
0
|
33
|
|
34
|
10
|
35 #define ngx_strncmp(s1, s2, n) strncmp((const char *) s1, (const char *) s2, n)
|
|
36
|
0
|
37
|
122
|
38 /* msvc and icc7 compile strcmp() to inline loop */
|
0
|
39 #define ngx_strcmp(s1, s2) strcmp((const char *) s1, (const char *) s2)
|
|
40
|
10
|
41
|
0
|
42 #define ngx_strstr(s1, s2) strstr((const char *) s1, (const char *) s2)
|
|
43 #define ngx_strlen(s) strlen((const char *) s)
|
|
44
|
10
|
45
|
0
|
46 /*
|
122
|
47 * msvc and icc7 compile memset() to the inline "rep stos"
|
0
|
48 * while ZeroMemory() and bzero() are the calls.
|
122
|
49 * icc7 may also inline several mov's of a zeroed register for small blocks.
|
0
|
50 */
|
64
|
51 #define ngx_memzero(buf, n) (void) memset(buf, 0, n)
|
|
52 #define ngx_memset(buf, c, n) (void) memset(buf, c, n)
|
0
|
53
|
10
|
54
|
132
|
55 #if (NGX_MEMCPY_LIMIT)
|
|
56
|
|
57 void *ngx_memcpy(void *dst, void *src, size_t n);
|
|
58 #define ngx_cpymem(dst, src, n) ((u_char *) ngx_memcpy(dst, src, n)) + (n)
|
|
59
|
|
60 #else
|
|
61
|
122
|
62 /*
|
|
63 * gcc3, msvc, and icc7 compile memcpy() to the inline "rep movs".
|
|
64 * gcc3 compiles memcpy(d, s, 4) to the inline "mov"es.
|
|
65 * icc8 compile memcpy(d, s, 4) to the inline "mov"es or XMM moves.
|
|
66 */
|
64
|
67 #define ngx_memcpy(dst, src, n) (void) memcpy(dst, src, n)
|
28
|
68 #define ngx_cpymem(dst, src, n) ((u_char *) memcpy(dst, src, n)) + (n)
|
0
|
69
|
132
|
70 #endif
|
|
71
|
10
|
72
|
122
|
73 #if ( __INTEL_COMPILER >= 800 )
|
|
74
|
|
75 /*
|
|
76 * the simple inline cycle copies the variable length strings up to 16
|
|
77 * bytes faster than icc8 autodetecting _intel_fast_memcpy()
|
|
78 */
|
|
79
|
|
80 static ngx_inline u_char *
|
|
81 ngx_copy(u_char *dst, u_char *src, size_t len)
|
|
82 {
|
|
83 if (len < 17) {
|
|
84
|
|
85 while (len) {
|
|
86 *dst++ = *src++;
|
|
87 len--;
|
|
88 }
|
|
89
|
|
90 return dst;
|
|
91
|
|
92 } else {
|
|
93 return ngx_cpymem(dst, src, len);
|
|
94 }
|
|
95 }
|
|
96
|
|
97 #else
|
|
98
|
|
99 #define ngx_copy ngx_cpymem
|
|
100
|
|
101 #endif
|
|
102
|
|
103
|
|
104 /* msvc and icc7 compile memcmp() to the inline loop */
|
0
|
105 #define ngx_memcmp memcmp
|
|
106
|
10
|
107
|
0
|
108 u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n);
|
34
|
109 u_char *ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src);
|
52
|
110 u_char * ngx_cdecl ngx_sprintf(u_char *buf, const char *fmt, ...);
|
|
111 u_char * ngx_cdecl ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...);
|
10
|
112 u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args);
|
4
|
113
|
286
|
114 ngx_int_t ngx_strcasecmp(u_char *s1, u_char *s2);
|
|
115 ngx_int_t ngx_strncasecmp(u_char *s1, u_char *s2, size_t n);
|
|
116
|
0
|
117 ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n);
|
4
|
118 ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);
|
274
|
119 ngx_int_t ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2);
|
0
|
120
|
|
121 ngx_int_t ngx_atoi(u_char *line, size_t n);
|
50
|
122 ssize_t ngx_atosz(u_char *line, size_t n);
|
|
123 off_t ngx_atoof(u_char *line, size_t n);
|
|
124 time_t ngx_atotm(u_char *line, size_t n);
|
0
|
125 ngx_int_t ngx_hextoi(u_char *line, size_t n);
|
|
126
|
|
127 void ngx_md5_text(u_char *text, u_char *md5);
|
|
128
|
|
129
|
|
130 #define ngx_base64_encoded_length(len) (((len + 2) / 3) * 4)
|
|
131 #define ngx_base64_decoded_length(len) (((len + 3) / 4) * 3)
|
|
132
|
2
|
133 void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src);
|
|
134 ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src);
|
10
|
135
|
206
|
136 uint32_t ngx_utf_decode(u_char **p, size_t n);
|
|
137 size_t ngx_utf_length(u_char *p, size_t n);
|
76
|
138 u_char * ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n);
|
|
139
|
10
|
140
|
150
|
141 #define NGX_ESCAPE_URI 0
|
|
142 #define NGX_ESCAPE_ARGS 1
|
|
143 #define NGX_ESCAPE_HTML 2
|
|
144
|
|
145 #define NGX_UNESCAPE_URI 1
|
10
|
146
|
34
|
147 uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
|
42
|
148 ngx_uint_t type);
|
150
|
149 void ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type);
|
0
|
150
|
|
151
|
|
152 #define ngx_qsort qsort
|
|
153
|
|
154
|
|
155 #define ngx_value_helper(n) #n
|
|
156 #define ngx_value(n) ngx_value_helper(n)
|
|
157
|
|
158
|
|
159 #endif /* _NGX_STRING_H_INCLUDED_ */
|