blob: b4a96c543b5631f1dd3be184019d4afcc92a3bbc [file] [log] [blame]
Igor Sysoevd90282d2004-09-28 08:34:51 +00001
2/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Igor Sysoevd90282d2004-09-28 08:34:51 +00004 */
5
6
Igor Sysoev6de5c2c2002-08-06 16:39:45 +00007#ifndef _NGX_STRING_H_INCLUDED_
8#define _NGX_STRING_H_INCLUDED_
9
10
11#include <ngx_config.h>
Igor Sysoev1c104622003-06-03 15:42:58 +000012#include <ngx_core.h>
Igor Sysoev6de5c2c2002-08-06 16:39:45 +000013
14
Igor Sysoeva0bb31f2002-12-02 16:09:40 +000015typedef struct {
Igor Sysoevf42ed052007-07-17 09:23:23 +000016 size_t len;
17 u_char *data;
Igor Sysoeva0bb31f2002-12-02 16:09:40 +000018} ngx_str_t;
19
Igor Sysoev6de5c2c2002-08-06 16:39:45 +000020
Igor Sysoev3338cfd2006-05-11 14:43:47 +000021typedef struct {
Igor Sysoevf42ed052007-07-17 09:23:23 +000022 ngx_str_t key;
23 ngx_str_t value;
Igor Sysoev3338cfd2006-05-11 14:43:47 +000024} ngx_keyval_t;
25
26
Igor Sysoevf42ed052007-07-17 09:23:23 +000027typedef struct {
28 unsigned len:29;
29
30 unsigned valid:1;
31 unsigned no_cachable:1;
32 unsigned not_found:1;
33
34 u_char *data;
35} ngx_variable_value_t;
36
37
Igor Sysoev722231f2007-02-14 18:51:19 +000038#define ngx_string(str) { sizeof(str) - 1, (u_char *) str }
39#define ngx_null_string { 0, NULL }
Igor Sysoev960ffa42002-12-26 07:24:21 +000040
41
Igor Sysoev722231f2007-02-14 18:51:19 +000042#define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)
43#define ngx_toupper(c) (u_char) ((c >= 'a' && c <= 'z') ? (c & ~0x20) : c)
Igor Sysoev6de5c2c2002-08-06 16:39:45 +000044
Igor Sysoev3646a162004-03-14 20:46:25 +000045
Igor Sysoev1b735832004-11-11 14:07:14 +000046#define ngx_strncmp(s1, s2, n) strncmp((const char *) s1, (const char *) s2, n)
47
Igor Sysoev3646a162004-03-14 20:46:25 +000048
Igor Sysoev09c684b2005-11-09 17:25:55 +000049/* msvc and icc7 compile strcmp() to inline loop */
Igor Sysoevd90282d2004-09-28 08:34:51 +000050#define ngx_strcmp(s1, s2) strcmp((const char *) s1, (const char *) s2)
Igor Sysoev3646a162004-03-14 20:46:25 +000051
Igor Sysoev1b735832004-11-11 14:07:14 +000052
Igor Sysoevd90282d2004-09-28 08:34:51 +000053#define ngx_strstr(s1, s2) strstr((const char *) s1, (const char *) s2)
Igor Sysoev7a588602007-04-02 06:27:30 +000054#define ngx_strchr(s1, c) strchr((const char *) s1, (int) c)
Igor Sysoevd90282d2004-09-28 08:34:51 +000055#define ngx_strlen(s) strlen((const char *) s)
Igor Sysoev3646a162004-03-14 20:46:25 +000056
Igor Sysoev1b735832004-11-11 14:07:14 +000057
Igor Sysoev6abfde62003-07-01 15:00:03 +000058/*
Igor Sysoev09c684b2005-11-09 17:25:55 +000059 * msvc and icc7 compile memset() to the inline "rep stos"
Igor Sysoevd90282d2004-09-28 08:34:51 +000060 * while ZeroMemory() and bzero() are the calls.
Igor Sysoev09c684b2005-11-09 17:25:55 +000061 * icc7 may also inline several mov's of a zeroed register for small blocks.
Igor Sysoev6abfde62003-07-01 15:00:03 +000062 */
Igor Sysoeve31e90b2005-05-19 13:25:22 +000063#define ngx_memzero(buf, n) (void) memset(buf, 0, n)
64#define ngx_memset(buf, c, n) (void) memset(buf, c, n)
Igor Sysoev6abfde62003-07-01 15:00:03 +000065
Igor Sysoev1b735832004-11-11 14:07:14 +000066
Igor Sysoevd3283ff2005-12-05 13:18:09 +000067#if (NGX_MEMCPY_LIMIT)
68
69void *ngx_memcpy(void *dst, void *src, size_t n);
70#define ngx_cpymem(dst, src, n) ((u_char *) ngx_memcpy(dst, src, n)) + (n)
71
72#else
73
Igor Sysoev09c684b2005-11-09 17:25:55 +000074/*
75 * gcc3, msvc, and icc7 compile memcpy() to the inline "rep movs".
76 * gcc3 compiles memcpy(d, s, 4) to the inline "mov"es.
77 * icc8 compile memcpy(d, s, 4) to the inline "mov"es or XMM moves.
78 */
Igor Sysoeve31e90b2005-05-19 13:25:22 +000079#define ngx_memcpy(dst, src, n) (void) memcpy(dst, src, n)
Igor Sysoev02025fd2005-01-18 13:03:58 +000080#define ngx_cpymem(dst, src, n) ((u_char *) memcpy(dst, src, n)) + (n)
Igor Sysoev6de5c2c2002-08-06 16:39:45 +000081
Igor Sysoevd3283ff2005-12-05 13:18:09 +000082#endif
83
Igor Sysoev1b735832004-11-11 14:07:14 +000084
Igor Sysoev09c684b2005-11-09 17:25:55 +000085#if ( __INTEL_COMPILER >= 800 )
86
87/*
88 * the simple inline cycle copies the variable length strings up to 16
89 * bytes faster than icc8 autodetecting _intel_fast_memcpy()
90 */
91
92static ngx_inline u_char *
93ngx_copy(u_char *dst, u_char *src, size_t len)
94{
95 if (len < 17) {
96
97 while (len) {
98 *dst++ = *src++;
99 len--;
100 }
101
102 return dst;
103
104 } else {
105 return ngx_cpymem(dst, src, len);
106 }
107}
108
109#else
110
111#define ngx_copy ngx_cpymem
112
113#endif
114
115
116/* msvc and icc7 compile memcmp() to the inline loop */
Igor Sysoev6abfde62003-07-01 15:00:03 +0000117#define ngx_memcmp memcmp
118
Igor Sysoev1b735832004-11-11 14:07:14 +0000119
Igor Sysoev10a543a2004-03-16 07:10:12 +0000120u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n);
Igor Sysoev805d9db2005-02-03 19:33:37 +0000121u_char *ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src);
Igor Sysoev4d656dc2005-03-22 16:02:46 +0000122u_char * ngx_cdecl ngx_sprintf(u_char *buf, const char *fmt, ...);
123u_char * ngx_cdecl ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...);
Igor Sysoev1b735832004-11-11 14:07:14 +0000124u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args);
Igor Sysoevc0edbcc2004-10-21 15:34:38 +0000125
Igor Sysoev722231f2007-02-14 18:51:19 +0000126ngx_int_t ngx_strcasecmp(u_char *s1, u_char *s2);
127ngx_int_t ngx_strncasecmp(u_char *s1, u_char *s2, size_t n);
128
Igor Sysoev10a543a2004-03-16 07:10:12 +0000129ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n);
Igor Sysoevc0edbcc2004-10-21 15:34:38 +0000130ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);
Igor Sysoevec3cabd2007-01-12 21:58:02 +0000131ngx_int_t ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2);
Igor Sysoev18684bd2004-05-20 17:33:52 +0000132
Igor Sysoev10a543a2004-03-16 07:10:12 +0000133ngx_int_t ngx_atoi(u_char *line, size_t n);
Igor Sysoevc1571722005-03-19 12:38:37 +0000134ssize_t ngx_atosz(u_char *line, size_t n);
135off_t ngx_atoof(u_char *line, size_t n);
136time_t ngx_atotm(u_char *line, size_t n);
Igor Sysoev18684bd2004-05-20 17:33:52 +0000137ngx_int_t ngx_hextoi(u_char *line, size_t n);
Igor Sysoev6de5c2c2002-08-06 16:39:45 +0000138
Igor Sysoev10a543a2004-03-16 07:10:12 +0000139void ngx_md5_text(u_char *text, u_char *md5);
Igor Sysoev9cc1ace2003-11-04 22:12:39 +0000140
Igor Sysoeva7c4a2a2004-08-29 03:55:41 +0000141
142#define ngx_base64_encoded_length(len) (((len + 2) / 3) * 4)
143#define ngx_base64_decoded_length(len) (((len + 3) / 4) * 3)
144
Igor Sysoev924bd792004-10-11 15:07:03 +0000145void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src);
146ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src);
Igor Sysoev1b735832004-11-11 14:07:14 +0000147
Igor Sysoevef809b82006-06-28 16:00:26 +0000148uint32_t ngx_utf_decode(u_char **p, size_t n);
149size_t ngx_utf_length(u_char *p, size_t n);
Igor Sysoev33787502007-05-19 17:39:44 +0000150u_char *ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n);
Igor Sysoev5192b362005-07-08 14:34:20 +0000151
Igor Sysoev1b735832004-11-11 14:07:14 +0000152
Igor Sysoev3f707822007-07-22 19:18:59 +0000153#define NGX_ESCAPE_URI 0
154#define NGX_ESCAPE_ARGS 1
155#define NGX_ESCAPE_HTML 2
156#define NGX_ESCAPE_REFRESH 3
157#define NGX_ESCAPE_MEMCACHED 4
Igor Sysoevae33d012006-01-17 20:04:32 +0000158
Igor Sysoev3f707822007-07-22 19:18:59 +0000159#define NGX_UNESCAPE_URI 1
Igor Sysoev1b735832004-11-11 14:07:14 +0000160
Igor Sysoev805d9db2005-02-03 19:33:37 +0000161uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
Igor Sysoevd039a2e2005-02-22 14:40:13 +0000162 ngx_uint_t type);
Igor Sysoevae33d012006-01-17 20:04:32 +0000163void ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type);
Igor Sysoev967fd632004-08-27 15:40:59 +0000164
Igor Sysoev9cc1ace2003-11-04 22:12:39 +0000165
Igor Sysoev35921282007-05-21 14:05:23 +0000166void ngx_sort(void *base, size_t n, size_t size,
167 int (*cmp)(const void *, const void *));
Igor Sysoev3f707822007-07-22 19:18:59 +0000168#define ngx_qsort qsort
Igor Sysoev6de5c2c2002-08-06 16:39:45 +0000169
Igor Sysoev13933252003-05-29 13:02:09 +0000170
Igor Sysoev3f707822007-07-22 19:18:59 +0000171#define ngx_value_helper(n) #n
172#define ngx_value(n) ngx_value_helper(n)
Igor Sysoeva9830112003-05-19 16:39:14 +0000173
174
Igor Sysoev6de5c2c2002-08-06 16:39:45 +0000175#endif /* _NGX_STRING_H_INCLUDED_ */