Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.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 
0092 #if (NGX_MEMCPY_LIMIT)
0093 
0094 void *ngx_memcpy(void *dst, const void *src, size_t n);
0095 #define ngx_cpymem(dst, src, n)   (((u_char *) ngx_memcpy(dst, src, n)) + (n))
0096 
0097 #else
0098 
0099 /*
0100  * gcc3, msvc, and icc7 compile memcpy() to the inline "rep movs".
0101  * gcc3 compiles memcpy(d, s, 4) to the inline "mov"es.
0102  * icc8 compile memcpy(d, s, 4) to the inline "mov"es or XMM moves.
0103  */
0104 #define ngx_memcpy(dst, src, n)   (void) memcpy(dst, src, n)
0105 #define ngx_cpymem(dst, src, n)   (((u_char *) memcpy(dst, src, n)) + (n))
0106 
0107 #endif
0108 
0109 
0110 #if ( __INTEL_COMPILER >= 800 )
0111 
0112 /*
0113  * the simple inline cycle copies the variable length strings up to 16
0114  * bytes faster than icc8 autodetecting _intel_fast_memcpy()
0115  */
0116 
0117 static ngx_inline u_char *
0118 ngx_copy(u_char *dst, u_char *src, size_t len)
0119 {
0120     if (len < 17) {
0121 
0122         while (len) {
0123             *dst++ = *src++;
0124             len--;
0125         }
0126 
0127         return dst;
0128 
0129     } else {
0130         return ngx_cpymem(dst, src, len);
0131     }
0132 }
0133 
0134 #else
0135 
0136 #define ngx_copy                  ngx_cpymem
0137 
0138 #endif
0139 
0140 
0141 #define ngx_memmove(dst, src, n)   (void) memmove(dst, src, n)
0142 #define ngx_movemem(dst, src, n)   (((u_char *) memmove(dst, src, n)) + (n))
0143 
0144 
0145 /* msvc and icc7 compile memcmp() to the inline loop */
0146 #define ngx_memcmp(s1, s2, n)  memcmp((const char *) s1, (const char *) s2, n)
0147 
0148 
0149 u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n);
0150 u_char *ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src);
0151 u_char * ngx_cdecl ngx_sprintf(u_char *buf, const char *fmt, ...);
0152 u_char * ngx_cdecl ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...);
0153 u_char * ngx_cdecl ngx_slprintf(u_char *buf, u_char *last, const char *fmt,
0154     ...);
0155 u_char *ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args);
0156 #define ngx_vsnprintf(buf, max, fmt, args)                                   \
0157     ngx_vslprintf(buf, buf + (max), fmt, args)
0158 
0159 ngx_int_t ngx_strcasecmp(u_char *s1, u_char *s2);
0160 ngx_int_t ngx_strncasecmp(u_char *s1, u_char *s2, size_t n);
0161 
0162 u_char *ngx_strnstr(u_char *s1, char *s2, size_t n);
0163 
0164 u_char *ngx_strstrn(u_char *s1, char *s2, size_t n);
0165 u_char *ngx_strcasestrn(u_char *s1, char *s2, size_t n);
0166 u_char *ngx_strlcasestrn(u_char *s1, u_char *last, u_char *s2, size_t n);
0167 
0168 ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n);
0169 ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);
0170 ngx_int_t ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2);
0171 ngx_int_t ngx_dns_strcmp(u_char *s1, u_char *s2);
0172 ngx_int_t ngx_filename_cmp(u_char *s1, u_char *s2, size_t n);
0173 
0174 ngx_int_t ngx_atoi(u_char *line, size_t n);
0175 ngx_int_t ngx_atofp(u_char *line, size_t n, size_t point);
0176 ssize_t ngx_atosz(u_char *line, size_t n);
0177 off_t ngx_atoof(u_char *line, size_t n);
0178 time_t ngx_atotm(u_char *line, size_t n);
0179 ngx_int_t ngx_hextoi(u_char *line, size_t n);
0180 
0181 u_char *ngx_hex_dump(u_char *dst, u_char *src, size_t len);
0182 
0183 
0184 #define ngx_base64_encoded_length(len)  (((len + 2) / 3) * 4)
0185 #define ngx_base64_decoded_length(len)  (((len + 3) / 4) * 3)
0186 
0187 void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src);
0188 void ngx_encode_base64url(ngx_str_t *dst, ngx_str_t *src);
0189 ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src);
0190 ngx_int_t ngx_decode_base64url(ngx_str_t *dst, ngx_str_t *src);
0191 
0192 uint32_t ngx_utf8_decode(u_char **p, size_t n);
0193 size_t ngx_utf8_length(u_char *p, size_t n);
0194 u_char *ngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len);
0195 
0196 
0197 #define NGX_ESCAPE_URI            0
0198 #define NGX_ESCAPE_ARGS           1
0199 #define NGX_ESCAPE_URI_COMPONENT  2
0200 #define NGX_ESCAPE_HTML           3
0201 #define NGX_ESCAPE_REFRESH        4
0202 #define NGX_ESCAPE_MEMCACHED      5
0203 #define NGX_ESCAPE_MAIL_AUTH      6
0204 
0205 #define NGX_UNESCAPE_URI       1
0206 #define NGX_UNESCAPE_REDIRECT  2
0207 
0208 uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
0209     ngx_uint_t type);
0210 void ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type);
0211 uintptr_t ngx_escape_html(u_char *dst, u_char *src, size_t size);
0212 uintptr_t ngx_escape_json(u_char *dst, u_char *src, size_t size);
0213 
0214 
0215 typedef struct {
0216     ngx_rbtree_node_t         node;
0217     ngx_str_t                 str;
0218 } ngx_str_node_t;
0219 
0220 
0221 void ngx_str_rbtree_insert_value(ngx_rbtree_node_t *temp,
0222     ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
0223 ngx_str_node_t *ngx_str_rbtree_lookup(ngx_rbtree_t *rbtree, ngx_str_t *name,
0224     uint32_t hash);
0225 
0226 
0227 void ngx_sort(void *base, size_t n, size_t size,
0228     ngx_int_t (*cmp)(const void *, const void *));
0229 #define ngx_qsort             qsort
0230 
0231 
0232 #define ngx_value_helper(n)   #n
0233 #define ngx_value(n)          ngx_value_helper(n)
0234 
0235 
0236 #endif /* _NGX_STRING_H_INCLUDED_ */