/src/unit/src/nxt_string.h
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | /* |
3 | | * Copyright (C) Igor Sysoev |
4 | | * Copyright (C) NGINX, Inc. |
5 | | */ |
6 | | |
7 | | #ifndef _NXT_STRING_H_INCLUDED_ |
8 | | #define _NXT_STRING_H_INCLUDED_ |
9 | | |
10 | | |
11 | | #define nxt_lowcase(c) \ |
12 | 14.8k | (u_char) ((c >= 'A' && c <= 'Z') ? c | 0x20 : c) |
13 | | |
14 | | #define nxt_upcase(c) \ |
15 | 0 | (u_char) ((c >= 'a' && c <= 'z') ? c & ~0x20 : c) |
16 | | |
17 | | #define nxt_isdigit(c) \ |
18 | 0 | ((u_char) ((c) - '0') <= 9) |
19 | | |
20 | | #define nxt_strtod(s, endptr) \ |
21 | 0 | strtod((char *) s, (char **) endptr) |
22 | | |
23 | | |
24 | | #define nxt_strlen(s) \ |
25 | 728 | strlen((char *) s) |
26 | | |
27 | | |
28 | | #define nxt_strdup(s) \ |
29 | 0 | strdup((char *) s) |
30 | | |
31 | | |
32 | | #define nxt_strchr(buf, delim) \ |
33 | | (u_char *) strchr((char *) buf, delim) |
34 | | |
35 | | |
36 | | #define nxt_memzero(buf, length) \ |
37 | 7.96k | (void) memset(buf, 0, length) |
38 | | |
39 | | |
40 | | #define nxt_memset(buf, c, length) \ |
41 | 0 | (void) memset(buf, c, length) |
42 | | |
43 | | |
44 | | #define nxt_memcpy(dst, src, length) \ |
45 | 1.69k | (void) memcpy(dst, src, length) |
46 | | |
47 | | |
48 | | NXT_EXPORT void nxt_memcpy_lowcase(u_char *dst, const u_char *src, |
49 | | size_t length); |
50 | | NXT_EXPORT void nxt_memcpy_upcase(u_char *dst, const u_char *src, |
51 | | size_t length); |
52 | | |
53 | | |
54 | | /* |
55 | | * nxt_cpymem() is an inline function but not a macro to |
56 | | * eliminate possible double evaluation of length "length". |
57 | | */ |
58 | | nxt_inline void * |
59 | | nxt_cpymem(void *dst, const void *src, size_t length) |
60 | 264 | { |
61 | 264 | return memcpy(dst, src, length) + length; |
62 | 264 | } Unexecuted instantiation: nxt_http_controller_fuzz.c:nxt_cpymem Unexecuted instantiation: nxt_lib.c:nxt_cpymem Line | Count | Source | 60 | 264 | { | 61 | 264 | return memcpy(dst, src, length) + length; | 62 | 264 | } |
Unexecuted instantiation: nxt_malloc.c:nxt_cpymem Unexecuted instantiation: nxt_file.c:nxt_cpymem Unexecuted instantiation: nxt_mem_map.c:nxt_cpymem Unexecuted instantiation: nxt_process.c:nxt_cpymem Unexecuted instantiation: nxt_process_title.c:nxt_cpymem Unexecuted instantiation: nxt_port_socket.c:nxt_cpymem Unexecuted instantiation: nxt_port_memory.c:nxt_cpymem Unexecuted instantiation: nxt_port_rpc.c:nxt_cpymem Unexecuted instantiation: nxt_port.c:nxt_cpymem Unexecuted instantiation: nxt_random.c:nxt_cpymem Unexecuted instantiation: nxt_mp.c:nxt_cpymem Unexecuted instantiation: nxt_string.c:nxt_cpymem Unexecuted instantiation: nxt_parse.c:nxt_cpymem Unexecuted instantiation: nxt_sprintf.c:nxt_cpymem Unexecuted instantiation: nxt_log.c:nxt_cpymem Unexecuted instantiation: nxt_murmur_hash.c:nxt_cpymem Unexecuted instantiation: nxt_lvlhsh.c:nxt_cpymem Unexecuted instantiation: nxt_buf.c:nxt_cpymem Unexecuted instantiation: nxt_sendbuf.c:nxt_cpymem Unexecuted instantiation: nxt_thread.c:nxt_cpymem Unexecuted instantiation: nxt_thread_mutex.c:nxt_cpymem Unexecuted instantiation: nxt_spinlock.c:nxt_cpymem Unexecuted instantiation: nxt_thread_time.c:nxt_cpymem Unexecuted instantiation: nxt_work_queue.c:nxt_cpymem Unexecuted instantiation: nxt_service.c:nxt_cpymem Unexecuted instantiation: nxt_log_moderation.c:nxt_cpymem Unexecuted instantiation: nxt_event_engine.c:nxt_cpymem Unexecuted instantiation: nxt_timer.c:nxt_cpymem Unexecuted instantiation: nxt_conn.c:nxt_cpymem Unexecuted instantiation: nxt_conn_connect.c:nxt_cpymem Unexecuted instantiation: nxt_conn_accept.c:nxt_cpymem Unexecuted instantiation: nxt_conn_read.c:nxt_cpymem Unexecuted instantiation: nxt_conn_write.c:nxt_cpymem Unexecuted instantiation: nxt_conn_close.c:nxt_cpymem Unexecuted instantiation: nxt_sockaddr.c:nxt_cpymem Unexecuted instantiation: nxt_listen_socket.c:nxt_cpymem Unexecuted instantiation: nxt_http_parse.c:nxt_cpymem Unexecuted instantiation: nxt_runtime.c:nxt_cpymem Unexecuted instantiation: nxt_conf.c:nxt_cpymem Unexecuted instantiation: nxt_conf_validation.c:nxt_cpymem Unexecuted instantiation: nxt_main_process.c:nxt_cpymem Unexecuted instantiation: nxt_signal_handlers.c:nxt_cpymem Unexecuted instantiation: nxt_router.c:nxt_cpymem Unexecuted instantiation: nxt_router_access_log.c:nxt_cpymem Unexecuted instantiation: nxt_h1proto.c:nxt_cpymem Unexecuted instantiation: nxt_status.c:nxt_cpymem Unexecuted instantiation: nxt_http_request.c:nxt_cpymem Unexecuted instantiation: nxt_http_response.c:nxt_cpymem Unexecuted instantiation: nxt_http_error.c:nxt_cpymem Unexecuted instantiation: nxt_http_route.c:nxt_cpymem Unexecuted instantiation: nxt_http_route_addr.c:nxt_cpymem Unexecuted instantiation: nxt_http_rewrite.c:nxt_cpymem Unexecuted instantiation: nxt_http_set_headers.c:nxt_cpymem Unexecuted instantiation: nxt_http_return.c:nxt_cpymem Unexecuted instantiation: nxt_http_static.c:nxt_cpymem Unexecuted instantiation: nxt_http_proxy.c:nxt_cpymem Unexecuted instantiation: nxt_http_chunk_parse.c:nxt_cpymem Unexecuted instantiation: nxt_http_variables.c:nxt_cpymem Unexecuted instantiation: nxt_application.c:nxt_cpymem Unexecuted instantiation: nxt_external.c:nxt_cpymem Unexecuted instantiation: nxt_port_hash.c:nxt_cpymem Unexecuted instantiation: nxt_websocket_accept.c:nxt_cpymem Unexecuted instantiation: nxt_http_websocket.c:nxt_cpymem Unexecuted instantiation: nxt_h1proto_websocket.c:nxt_cpymem Unexecuted instantiation: nxt_fs.c:nxt_cpymem Unexecuted instantiation: nxt_http_compression.c:nxt_cpymem Unexecuted instantiation: nxt_epoll_engine.c:nxt_cpymem Unexecuted instantiation: nxt_poll_engine.c:nxt_cpymem Unexecuted instantiation: nxt_select_engine.c:nxt_cpymem Unexecuted instantiation: nxt_linux_sendfile.c:nxt_cpymem Unexecuted instantiation: nxt_clone.c:nxt_cpymem Unexecuted instantiation: nxt_gmtime.c:nxt_cpymem Unexecuted instantiation: nxt_time.c:nxt_cpymem Unexecuted instantiation: nxt_socket.c:nxt_cpymem Unexecuted instantiation: nxt_socketpair.c:nxt_cpymem Unexecuted instantiation: nxt_socket_msg.c:nxt_cpymem Unexecuted instantiation: nxt_credential.c:nxt_cpymem Unexecuted instantiation: nxt_isolation.c:nxt_cpymem Unexecuted instantiation: nxt_signal.c:nxt_cpymem Unexecuted instantiation: nxt_rbtree.c:nxt_cpymem Unexecuted instantiation: nxt_utf8.c:nxt_cpymem Unexecuted instantiation: nxt_var.c:nxt_cpymem Unexecuted instantiation: nxt_tstr.c:nxt_cpymem Unexecuted instantiation: nxt_file_name.c:nxt_cpymem Unexecuted instantiation: nxt_djb_hash.c:nxt_cpymem Unexecuted instantiation: nxt_array.c:nxt_cpymem Unexecuted instantiation: nxt_list.c:nxt_cpymem Unexecuted instantiation: nxt_recvbuf.c:nxt_cpymem Unexecuted instantiation: nxt_thread_pool.c:nxt_cpymem Unexecuted instantiation: nxt_upstream.c:nxt_cpymem Unexecuted instantiation: nxt_upstream_round_robin.c:nxt_cpymem Unexecuted instantiation: nxt_capability.c:nxt_cpymem Unexecuted instantiation: nxt_sha1.c:nxt_cpymem Unexecuted instantiation: nxt_websocket.c:nxt_cpymem Unexecuted instantiation: nxt_fs_mount.c:nxt_cpymem Unexecuted instantiation: nxt_semaphore.c:nxt_cpymem |
63 | | |
64 | | |
65 | | #define nxt_memmove(dst, src, length) \ |
66 | 0 | (void) memmove(dst, src, length) |
67 | | |
68 | | |
69 | | #define nxt_strcmp(s1, s2) \ |
70 | 0 | strcmp((char *) s1, (char *) s2) |
71 | | |
72 | | |
73 | | #define nxt_strncmp(s1, s2, length) \ |
74 | 0 | strncmp((char *) s1, (char *) s2, length) |
75 | | |
76 | | |
77 | | NXT_EXPORT u_char *nxt_cpystr(u_char *dst, const u_char *src); |
78 | | NXT_EXPORT u_char *nxt_cpystrn(u_char *dst, const u_char *src, size_t length); |
79 | | NXT_EXPORT nxt_int_t nxt_strcasecmp(const u_char *s1, const u_char *s2); |
80 | | NXT_EXPORT nxt_int_t nxt_strncasecmp(const u_char *s1, const u_char *s2, |
81 | | size_t length); |
82 | | NXT_EXPORT nxt_int_t nxt_memcasecmp(const void *p1, const void *p2, |
83 | | size_t length); |
84 | | |
85 | | NXT_EXPORT u_char *nxt_memstrn(const u_char *s, const u_char *end, |
86 | | const char *ss, size_t length); |
87 | | NXT_EXPORT u_char *nxt_memcasestrn(const u_char *s, const u_char *end, |
88 | | const char *ss, size_t length); |
89 | | NXT_EXPORT u_char *nxt_rmemstrn(const u_char *s, const u_char *end, |
90 | | const char *ss, size_t length); |
91 | | NXT_EXPORT size_t nxt_str_strip(const u_char *start, u_char *end); |
92 | | |
93 | | |
94 | | typedef struct { |
95 | | size_t length; |
96 | | u_char *start; |
97 | | } nxt_str_t; |
98 | | |
99 | | |
100 | 0 | #define nxt_string(str) { nxt_length(str), (u_char *) str } |
101 | | #define nxt_string_zero(str) { sizeof(str), (u_char *) str } |
102 | | #define nxt_null_string { 0, NULL } |
103 | | |
104 | | |
105 | | #define nxt_str_set(str, text) \ |
106 | 0 | do { \ |
107 | 0 | (str)->length = nxt_length(text); \ |
108 | 0 | (str)->start = (u_char *) text; \ |
109 | 0 | } while (0) |
110 | | |
111 | | |
112 | | #define nxt_str_null(str) \ |
113 | 0 | do { \ |
114 | 0 | (str)->length = 0; \ |
115 | 0 | (str)->start = NULL; \ |
116 | 0 | } while (0) |
117 | | |
118 | | |
119 | | NXT_EXPORT nxt_str_t *nxt_str_alloc(nxt_mp_t *mp, size_t length); |
120 | | NXT_EXPORT nxt_str_t *nxt_str_dup(nxt_mp_t *mp, nxt_str_t *dst, |
121 | | const nxt_str_t *src); |
122 | | NXT_EXPORT char *nxt_str_cstrz(nxt_mp_t *mp, const nxt_str_t *src); |
123 | | |
124 | | |
125 | | #define nxt_strstr_eq(s1, s2) \ |
126 | 0 | (((s1)->length == (s2)->length) \ |
127 | 0 | && (memcmp((s1)->start, (s2)->start, (s1)->length) == 0)) |
128 | | |
129 | | |
130 | | #define nxt_strcasestr_eq(s1, s2) \ |
131 | 1.05k | (((s1)->length == (s2)->length) \ |
132 | 1.05k | && (nxt_memcasecmp((s1)->start, (s2)->start, (s1)->length) == 0)) |
133 | | |
134 | | |
135 | | #define nxt_str_eq(s, p, _length) \ |
136 | 0 | (((s)->length == _length) && (memcmp((s)->start, p, _length) == 0)) |
137 | | |
138 | | |
139 | | #define nxt_str_start(s, p, _length) \ |
140 | 0 | (((s)->length >= _length) && (memcmp((s)->start, p, _length) == 0)) |
141 | | |
142 | | |
143 | | #define nxt_strchr_eq(s, c) \ |
144 | | (((s)->length == 1) && ((s)->start[0] == c)) |
145 | | |
146 | | |
147 | | #define nxt_strchr_start(s, c) \ |
148 | 0 | (((s)->length != 0) && ((s)->start[0] == c)) |
149 | | |
150 | | |
151 | | NXT_EXPORT nxt_int_t nxt_strverscmp(const u_char *s1, const u_char *s2); |
152 | | NXT_EXPORT nxt_bool_t nxt_strvers_match(u_char *version, u_char *prefix, |
153 | | size_t length); |
154 | | |
155 | | NXT_EXPORT u_char *nxt_decode_uri(u_char *dst, u_char *src, size_t length); |
156 | | NXT_EXPORT u_char *nxt_decode_uri_plus(u_char *dst, u_char *src, size_t length); |
157 | | NXT_EXPORT uintptr_t nxt_encode_uri(u_char *dst, u_char *src, size_t length); |
158 | | NXT_EXPORT uintptr_t nxt_encode_complex_uri(u_char *dst, u_char *src, |
159 | | size_t length); |
160 | | NXT_EXPORT nxt_bool_t nxt_is_complex_uri_encoded(u_char *s, size_t length); |
161 | | |
162 | | NXT_EXPORT ssize_t nxt_base64_decode(u_char *dst, u_char *src, size_t length); |
163 | | |
164 | | extern const uint8_t nxt_hex2int[256]; |
165 | | |
166 | | |
167 | | #endif /* _NXT_STRING_H_INCLUDED_ */ |