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 | 10a543a | 2004-03-16 07:10:12 +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 | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 21 | #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } |
Igor Sysoev | b738757 | 2003-03-11 20:38:13 +0000 | [diff] [blame] | 22 | #define ngx_null_string { 0, NULL } |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 23 | |
| 24 | |
Igor Sysoev | b1dfe47 | 2004-12-21 12:30:30 +0000 | [diff] [blame] | 25 | #define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c) |
| 26 | |
| 27 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 28 | #if (NGX_WIN32) |
Igor Sysoev | 42feecb | 2002-12-15 06:25:09 +0000 | [diff] [blame] | 29 | |
Igor Sysoev | da85f7f | 2004-03-16 21:26:01 +0000 | [diff] [blame] | 30 | #define ngx_strncasecmp(s1, s2, n) \ |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 31 | strnicmp((const char *) s1, (const char *) s2, n) |
Igor Sysoev | da85f7f | 2004-03-16 21:26:01 +0000 | [diff] [blame] | 32 | #define ngx_strcasecmp(s1, s2) \ |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 33 | stricmp((const char *) s1, (const char *) s2) |
Igor Sysoev | ad22e01 | 2003-01-15 07:02:27 +0000 | [diff] [blame] | 34 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 35 | #else |
| 36 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 37 | #define ngx_strncasecmp(s1, s2, n) \ |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 38 | strncasecmp((const char *) s1, (const char *) s2, n) |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 39 | #define ngx_strcasecmp(s1, s2) \ |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 40 | strcasecmp((const char *) s1, (const char *) s2) |
Igor Sysoev | ad22e01 | 2003-01-15 07:02:27 +0000 | [diff] [blame] | 41 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
Igor Sysoev | 3646a16 | 2004-03-14 20:46:25 +0000 | [diff] [blame] | 44 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 45 | #define ngx_strncmp(s1, s2, n) strncmp((const char *) s1, (const char *) s2, n) |
| 46 | |
Igor Sysoev | 3646a16 | 2004-03-14 20:46:25 +0000 | [diff] [blame] | 47 | |
| 48 | /* msvc and icc compile strcmp() to inline loop */ |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 49 | #define ngx_strcmp(s1, s2) strcmp((const char *) s1, (const char *) s2) |
Igor Sysoev | 3646a16 | 2004-03-14 20:46:25 +0000 | [diff] [blame] | 50 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 51 | |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 52 | #define ngx_strstr(s1, s2) strstr((const char *) s1, (const char *) s2) |
| 53 | #define ngx_strlen(s) strlen((const char *) s) |
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 | 6abfde6 | 2003-07-01 15:00:03 +0000 | [diff] [blame] | 56 | /* |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 57 | * msvc and icc compile memset() to the inline "rep stos" |
| 58 | * while ZeroMemory() and bzero() are the calls. |
| 59 | * icc 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] | 60 | */ |
Igor Sysoev | 9d9f58f | 2003-07-02 18:51:41 +0000 | [diff] [blame] | 61 | #define ngx_memzero(buf, n) memset(buf, 0, n) |
Igor Sysoev | 924bd79 | 2004-10-11 15:07:03 +0000 | [diff] [blame] | 62 | #define ngx_memset(buf, c, n) memset(buf, c, n) |
Igor Sysoev | 6abfde6 | 2003-07-01 15:00:03 +0000 | [diff] [blame] | 63 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 64 | |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 65 | /* msvc and icc compile memcpy() to the inline "rep movs" */ |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 66 | #define ngx_memcpy(dst, src, n) memcpy(dst, src, n) |
Igor Sysoev | 02025fd | 2005-01-18 13:03:58 +0000 | [diff] [blame] | 67 | #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] | 68 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 69 | |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 70 | /* msvc and icc compile memcmp() to the inline loop */ |
Igor Sysoev | 6abfde6 | 2003-07-01 15:00:03 +0000 | [diff] [blame] | 71 | #define ngx_memcmp memcmp |
| 72 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 73 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 74 | 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] | 75 | u_char *ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src); |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 76 | u_char *ngx_sprintf(u_char *buf, const char *fmt, ...); |
| 77 | u_char *ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...); |
| 78 | 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] | 79 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 80 | 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] | 81 | ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n); |
Igor Sysoev | 18684bd | 2004-05-20 17:33:52 +0000 | [diff] [blame] | 82 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 83 | ngx_int_t ngx_atoi(u_char *line, size_t n); |
Igor Sysoev | 18684bd | 2004-05-20 17:33:52 +0000 | [diff] [blame] | 84 | ngx_int_t ngx_hextoi(u_char *line, size_t n); |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 85 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 86 | void ngx_md5_text(u_char *text, u_char *md5); |
Igor Sysoev | 9cc1ace | 2003-11-04 22:12:39 +0000 | [diff] [blame] | 87 | |
Igor Sysoev | a7c4a2a | 2004-08-29 03:55:41 +0000 | [diff] [blame] | 88 | |
| 89 | #define ngx_base64_encoded_length(len) (((len + 2) / 3) * 4) |
| 90 | #define ngx_base64_decoded_length(len) (((len + 3) / 4) * 3) |
| 91 | |
Igor Sysoev | 924bd79 | 2004-10-11 15:07:03 +0000 | [diff] [blame] | 92 | void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src); |
| 93 | 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] | 94 | |
| 95 | |
| 96 | #define NGX_ESCAPE_URI 0 |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 97 | #define NGX_ESCAPE_ARGS 1 |
| 98 | #define NGX_ESCAPE_HTML 2 |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 99 | |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 100 | 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^] | 101 | ngx_uint_t type); |
Igor Sysoev | 967fd63 | 2004-08-27 15:40:59 +0000 | [diff] [blame] | 102 | |
Igor Sysoev | 9cc1ace | 2003-11-04 22:12:39 +0000 | [diff] [blame] | 103 | |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 104 | #define ngx_qsort qsort |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 105 | |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 106 | |
| 107 | #define ngx_value_helper(n) #n |
| 108 | #define ngx_value(n) ngx_value_helper(n) |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 109 | |
| 110 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 111 | #endif /* _NGX_STRING_H_INCLUDED_ */ |