Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.11 ]​[ nginx-1.14.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_STRING_H_INCLUDED_
0009 #define _NGX_STRING_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 
0015 
0016 typedef struct {
0017     size_t      len;
0018     u_char     *data;
0019 } ngx_str_t;
0020 
0021 
0022 typedef struct {
0023     ngx_str_t   key;
0024     ngx_str_t   value;
0025 } ngx_keyval_t;
0026 
0027 
0028 typedef struct {
0029     unsigned    len:28;
0030 
0031     unsigned    valid:1;
0032     unsigned    no_cacheable:1;
0033     unsigned    not_found:1;
0034     unsigned    escape:1;
0035 
0036     u_char     *data;
0037 } ngx_variable_value_t;
0038 
0039 
0040 #define ngx_string(str)     { sizeof(str) - 1, (u_char *) str }
0041 #define ngx_null_string     { 0, NULL }
0042 #define ngx_str_set(str, text)                                               \
0043     (str)->len = sizeof(text) - 1; (str)->data = (u_char *) text
0044 #define ngx_str_null(str)   (str)->len = 0; (str)->data = NULL
0045 
0046 
0047 #define ngx_tolower(c)      (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)
0048 #define ngx_toupper(c)      (u_char) ((c >= 'a' && c <= 'z') ? (c & ~0x20) : c)
0049 
0050 void ngx_strlow(u_char *dst, u_char *src, size_t n);
0051 
0052 
0053 #define ngx_strncmp(s1, s2, n)  strncmp((const char *) s1, (const char *) s2, n)
0054 
0055 
0056 /* msvc and icc7 compile strcmp() to inline loop */
0057 #define ngx_strcmp(s1, s2)  strcmp((const char *) s1, (const char *) s2)
0058 
0059 
0060 #define ngx_strstr(s1, s2)  strstr((const char *) s1, (const char *) s2)
0061 #define ngx_strlen(s)       strlen((const char *) s)
0062 
0063 size_t ngx_strnlen(u_char *p, size_t n);
0064 
0065 #define ngx_strchr(s1, c)   strchr((const char *) s1, (int) c)
0066 
0067 static ngx_inline u_char *
0068 ngx_strlchr(u_char *p, u_char *last, u_char c)
0069 {
0070     while (p < last) {
0071 
0072         if (*p == c) {
0073             return p;
0074         }
0075 
0076         p++;
0077     }
0078 
0079     return NULL;
0080 }
0081 
0082 
0083 /*
0084  * msvc and icc7 compile memset() to the inline "rep stos"
0085  * while ZeroMemory() and bzero() are the calls.
0086  * icc7 may also inline several mov's of a zeroed register for small blocks.
0087  */
0088 #define ngx_memzero(buf, n)       (void) memset(buf, 0, n)
0089 #define ngx_memset(buf, c, n)     (void) memset(buf, c, n)
0090 
0091 void ngx_explicit_memzero(void *buf, size_t n);
0092 
0093 
0094 #if (NGX_MEMCPY_LIMIT)
0095 
0096 void *ngx_memcpy(void *dst, const void *src, size_t n);
0097 #define ngx_cpymem(dst, src, n)   (((u_char *) ngx_memcpy(dst, src, n)) + (n))
0098 
0099 #else
0100 
0101 /*
0102  * gcc3, msvc, and icc7 compile memcpy() to the inline "rep movs".
0103  * gcc3 compiles memcpy(d, s, 4) to the inline "mov"es.
0104  * icc8 compile memcpy(d, s, 4) to the inline "mov"es or XMM moves.
0105  */
0106 #define ngx_memcpy(dst, src, n)   (void) memcpy(dst, src, n)
0107 #define ngx_cpymem(dst, src, n)   (((u_char *) memcpy(dst, src, n)) + (n))
0108 
0109 #endif
0110 
0111 
0112 #if ( __INTEL_COMPILER >= 800 )
0113 
0114 /*
0115  * the simple inline cycle copies the variable length strings up to 16
0116  * bytes faster than icc8 autodetecting _intel_fast_memcpy()
0117  */
0118 
0119 static ngx_inline u_char *
0120 ngx_copy(u_char *dst, u_char *src, size_t len)
0121 {
0122     if (len < 17) {
0123 
0124         while (len) {
0125             *dst++ = *src++;
0126             len--;
0127         }
0128 
0129         return dst;
0130 
0131     } else {
0132         return ngx_cpymem(dst, src, len);
0133     }
0134 }
0135 
0136 #else
0137 
0138 #define ngx_copy                  ngx_cpymem
0139 
0140 #endif
0141 
0142 
0143 #define ngx_memmove(dst, src, n)   (void) memmove(dst, src, n)
0144 #define ngx_movemem(dst, src, n)   (((u_char *) memmove(dst, src, n)) + (n))
0145 
0146 
0147 /* msvc and icc7 compile memcmp() to the inline loop */
0148 #define ngx_memcmp(s1, s2, n)  memcmp((const char *) s1, (const char *) s2, n)
0149 
0150 
0151 u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n);
0152 u_char *ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src);
0153 u_char * ngx_cdecl ngx_sprintf(u_char *buf, const char *fmt, ...);
0154 u_char * ngx_cdecl ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...);
0155 u_char * ngx_cdecl ngx_slprintf(u_char *buf, u_char *last, const char *fmt,
0156     ...);
0157 u_char *ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args);
0158 #define ngx_vsnprintf(buf, max, fmt, args)                                   \
0159     ngx_vslprintf(buf, buf + (max), fmt, args)
0160 
0161 ngx_int_t ngx_strcasecmp(u_char *s1, u_char *s2);
0162 ngx_int_t ngx_strncasecmp(u_char *s1, u_char *s2, size_t n);
0163 
0164 u_char *ngx_strnstr(u_char *s1, char *s2, size_t n);
0165 
0166 u_char *ngx_strstrn(u_char *s1, char *s2, size_t n);
0167 u_char *ngx_strcasestrn(u_char *s1, char *s2, size_t n);
0168 u_char *ngx_strlcasestrn(u_char *s1, u_char *last, u_char *s2, size_t n);
0169 
0170 ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n);
0171 ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);
0172 ngx_int_t ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2);
0173 ngx_int_t ngx_dns_strcmp(u_char *s1, u_char *s2);
0174 ngx_int_t ngx_filename_cmp(u_char *s1, u_char *s2, size_t n);
0175 
0176 ngx_int_t ngx_atoi(u_char *line, size_t n);
0177 ngx_int_t ngx_atofp(u_char *line, size_t n, size_t point);
0178 ssize_t ngx_atosz(u_char *line, size_t n);
0179 off_t ngx_atoof(u_char *line, size_t n);
0180 time_t ngx_atotm(u_char *line, size_t n);
0181 ngx_int_t ngx_hextoi(u_char *line, size_t n);
0182 
0183 u_char *ngx_hex_dump(u_char *dst, u_char *src, size_t len);
0184 
0185 
0186 #define ngx_base64_encoded_length(len)  (((len + 2) / 3) * 4)
0187 #define ngx_base64_decoded_length(len)  (((len + 3) / 4) * 3)
0188 
0189 void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src);
0190 void ngx_encode_base64url(ngx_str_t *dst, ngx_str_t *src);
0191 ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src);
0192 ngx_int_t ngx_decode_base64url(ngx_str_t *dst, ngx_str_t *src);
0193 
0194 uint32_t ngx_utf8_decode(u_char **p, size_t n);
0195 size_t ngx_utf8_length(u_char *p, size_t n);
0196 u_char *ngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len);
0197 
0198 
0199 #define NGX_ESCAPE_URI            0
0200 #define NGX_ESCAPE_ARGS           1
0201 #define NGX_ESCAPE_URI_COMPONENT  2
0202 #define NGX_ESCAPE_HTML           3
0203 #define NGX_ESCAPE_REFRESH        4
0204 #define NGX_ESCAPE_MEMCACHED      5
0205 #define NGX_ESCAPE_MAIL_AUTH      6
0206 
0207 #define NGX_UNESCAPE_URI       1
0208 #define NGX_UNESCAPE_REDIRECT  2
0209 
0210 uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
0211     ngx_uint_t type);
0212 void ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type);
0213 uintptr_t ngx_escape_html(u_char *dst, u_char *src, size_t size);
0214 uintptr_t ngx_escape_json(u_char *dst, u_char *src, size_t size);
0215 
0216 
0217 typedef struct {
0218     ngx_rbtree_node_t         node;
0219     ngx_str_t                 str;
0220 } ngx_str_node_t;
0221 
0222 
0223 void ngx_str_rbtree_insert_value(ngx_rbtree_node_t *temp,
0224     ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
0225 ngx_str_node_t *ngx_str_rbtree_lookup(ngx_rbtree_t *rbtree, ngx_str_t *name,
0226     uint32_t hash);
0227 
0228 
0229 void ngx_sort(void *base, size_t n, size_t size,
0230     ngx_int_t (*cmp)(const void *, const void *));
0231 #define ngx_qsort             qsort
0232 
0233 
0234 #define ngx_value_helper(n)   #n
0235 #define ngx_value(n)          ngx_value_helper(n)
0236 
0237 
0238 #endif /* _NGX_STRING_H_INCLUDED_ */