« third_party/modest/source/myurl/url.c
↑ Summary
third_party/modest/source/mycss/selectors/function_parser.c »
| 1 | /* | ||||||||||||||||||||||||||||||
| 2 | Copyright (C) 2016-2017 Alexander Borisov | ||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||
| 4 | This library is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||
| 5 | modify it under the terms of the GNU Lesser General Public | ||||||||||||||||||||||||||||||
| 6 | License as published by the Free Software Foundation; either | ||||||||||||||||||||||||||||||
| 7 | version 2.1 of the License, or (at your option) any later version. | ||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||
| 9 | This library is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||||||||||||||||||||||||||||
| 12 | Lesser General Public License for more details. | ||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | You should have received a copy of the GNU Lesser General Public | ||||||||||||||||||||||||||||||
| 15 | License along with this library; if not, write to the Free Software | ||||||||||||||||||||||||||||||
| 16 | Foundation, Inc., 51 Franklin avl_treet, Fifth Floor, Boston, MA 02110-1301 USA | ||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | Author: lex.borisov@gmail.com (Alexander Borisov) | ||||||||||||||||||||||||||||||
| 19 | */ | ||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | #include "myurl/url.h" | ||||||||||||||||||||||||||||||
| 22 | #include "myurl/utils.h" | ||||||||||||||||||||||||||||||
| 23 | #include "myurl/resources.h" | ||||||||||||||||||||||||||||||
| 24 | #include "mycore/utils/resources.h" | ||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | /* data */ | ||||||||||||||||||||||||||||||
| 27 | 0 | char * myurl_utils_data_copy(myurl_t* url, const char* data, size_t size) | |||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||||
| 29 | 0 | char *copy = url->callback_malloc(((sizeof(char) * size) + 1), url->callback_ctx); | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if(copy) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 32 | 0 | memcpy(copy, data, sizeof(char) * size); | |||||||||||||||||||||||||||||
| 33 | 0 | copy[size] = '\0'; | |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | 0 | return copy; | |||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||
| 39 | 0 | mystatus_t myurl_utils_data_copy_set(myurl_t* url, const char* data, size_t size, char** to, size_t* to_length) | |||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if(data == NULL) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 42 | 0 | *to = NULL; | |||||||||||||||||||||||||||||
| 43 | 0 | *to_length = 0; | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | 0 | return MyURL_STATUS_OK; | |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||
| 48 | char *copy; | ||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||
| 50 | /* mem */ | ||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if(*to) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if((*to_length + 1) < size) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 53 | 0 | copy = url->callback_realloc(*to, (sizeof(char) * (size + 1)), url->callback_ctx); | |||||||||||||||||||||||||||||
| 54 | else | ||||||||||||||||||||||||||||||
| 55 | 0 | copy = *to; | |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||
| 57 | else | ||||||||||||||||||||||||||||||
| 58 | 0 | copy = url->callback_malloc(((sizeof(char) * size) + 1), url->callback_ctx); | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | /* process */ | ||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if(copy) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 62 | 0 | *to = copy; | |||||||||||||||||||||||||||||
| 63 | 0 | *to_length = size; | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | 0 | memcpy(copy, data, sizeof(char) * size); | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | 0 | copy[size] = '\0'; | |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||
| 69 | else { | ||||||||||||||||||||||||||||||
| 70 | 0 | *to_length = 0; | |||||||||||||||||||||||||||||
| 71 | 0 | return MyURL_STATUS_ERROR; | |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||
| 74 | 0 | return MyURL_STATUS_OK; | |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||
| 77 | 0 | mystatus_t myurl_utils_data_copy_append(myurl_t* url, const char* data, size_t size, char** to, size_t* to_length) | |||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if(data == NULL) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if(*to) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 81 | 0 | *to = url->callback_free(*to, url->callback_ctx); | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | 0 | *to = NULL; | |||||||||||||||||||||||||||||
| 84 | 0 | *to_length = 0; | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | 0 | return MyURL_STATUS_OK; | |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||
| 89 | char *copy; | ||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | /* mem */ | ||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if(*to) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if((*to_length + 1) < size) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 94 | 0 | copy = url->callback_realloc(*to, (sizeof(char) * (size + *to_length)) + 1, url->callback_ctx); | |||||||||||||||||||||||||||||
| 95 | else | ||||||||||||||||||||||||||||||
| 96 | 0 | copy = *to; | |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||
| 98 | else | ||||||||||||||||||||||||||||||
| 99 | 0 | copy = url->callback_malloc(((sizeof(char) * size) + 1), url->callback_ctx); | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | /* process */ | ||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if(copy) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 103 | 0 | *to = copy; | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||
| 105 | 0 | memcpy(©[ *to_length ], data, sizeof(char) * size); | |||||||||||||||||||||||||||||
| 106 | 0 | (*to_length) += size; | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | 0 | copy[size] = '\0'; | |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||||
| 111 | 0 | *to_length = 0; | |||||||||||||||||||||||||||||
| 112 | 0 | return MyURL_STATUS_ERROR; | |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||
| 115 | 0 | return MyURL_STATUS_OK; | |||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | 0 | void myurl_utils_data_set_null(myurl_t* url, char** to, size_t* length) | |||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if(*to) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 121 | 0 | *to = url->callback_free(*to, url->callback_ctx); | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if(length) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 124 | 0 | *length = 0; | |||||||||||||||||||||||||||||
| 125 | 0 | } | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | 0 | void myurl_utils_data_set_empty(myurl_t* url, char** to, size_t* length) | |||||||||||||||||||||||||||||
| 128 | { | ||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if(*to == NULL) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 130 | 0 | *to = url->callback_malloc(sizeof(char), url->callback_ctx); | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if(length) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 133 | 0 | *length = 0; | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||
| 135 | 0 | *to[0] = '\0'; | |||||||||||||||||||||||||||||
| 136 | 0 | } | |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||
| 138 | /* converter */ | ||||||||||||||||||||||||||||||
| 139 | 0 | char * myurl_utils_percent_encode(myurl_t* url, const char* data, size_t size, const unsigned char* encode_set, size_t* return_length) | |||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||||
| 141 | 0 | size_t new_size = size; | |||||||||||||||||||||||||||||
| 142 | 0 | const unsigned char *u_data = (const unsigned char*)data; | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||
| 144 | size_t len; | ||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | for(len = 0; len < size; len++) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if(encode_set[ u_data[len] ] == 0x00) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 147 | 0 | new_size += 2; | |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||
| 150 | 0 | char *out = url->callback_malloc((sizeof(char) * new_size) + 1, url->callback_ctx); | |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if(out == NULL) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if(return_length) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 153 | 0 | *return_length = 0; | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||
| 155 | 0 | return NULL; | |||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||
| 158 | 0 | char *out_link = out; | |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||
| 160 | 0 | len = 0; | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | while(len < size) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if(encode_set[ u_data[len] ] == 0x00) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 164 | 0 | const char *two_hex = mycore_string_char_to_two_hex_value[ u_data[len] ]; | |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||
| 166 | 0 | *out = '%'; out++; | |||||||||||||||||||||||||||||
| 167 | 0 | *out = (char)mycore_string_chars_uppercase_map[ (unsigned char)two_hex[0] ]; out++; | |||||||||||||||||||||||||||||
| 168 | 0 | *out = (char)mycore_string_chars_uppercase_map[ (unsigned char)two_hex[1] ]; out++; | |||||||||||||||||||||||||||||
| 169 | 0 | *out = '\0'; | |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||
| 171 | else { | ||||||||||||||||||||||||||||||
| 172 | 0 | *out = data[len]; | |||||||||||||||||||||||||||||
| 173 | 0 | out++; | |||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||
| 176 | 0 | len++; | |||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||
| 179 | 0 | *out = '\0'; | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if(return_length) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 182 | 0 | *return_length = new_size; | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||
| 184 | 0 | return out_link; | |||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||
| 187 | /* converter */ | ||||||||||||||||||||||||||||||
| 188 | 0 | size_t myurl_utils_percent_decode_bytes_in_data(char* data, size_t size) | |||||||||||||||||||||||||||||
| 189 | { | ||||||||||||||||||||||||||||||
| 190 | 0 | unsigned char *u_data = (unsigned char*)data; | |||||||||||||||||||||||||||||
| 191 | 0 | unsigned char tmp = '\0'; | |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||
| 193 | 0 | size_t len = 0, offset = 0; | |||||||||||||||||||||||||||||
| 194 | 0 | ▶ | while(len < size) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 195 | { | ||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if(u_data[len] == '%' && (len + 2) < size) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 197 | 0 | size_t pos = len; | |||||||||||||||||||||||||||||
| 198 | 0 | len++; | |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if(mycore_string_chars_hex_map[ u_data[len] ] != 0xFF && | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | mycore_string_chars_hex_map[ u_data[(len + 1)] ] != 0xFF) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 202 | { | ||||||||||||||||||||||||||||||
| 203 | 0 | tmp = mycore_string_chars_hex_map[ u_data[len] ]; | |||||||||||||||||||||||||||||
| 204 | 0 | tmp = (tmp << 4) | mycore_string_chars_hex_map[ u_data[(len + 1)] ]; | |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||
| 206 | 0 | u_data[(pos - offset)] = tmp; | |||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||
| 208 | 0 | offset += 2; | |||||||||||||||||||||||||||||
| 209 | 0 | len++; | |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||
| 211 | else { | ||||||||||||||||||||||||||||||
| 212 | 0 | len--; | |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if(offset) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 215 | 0 | u_data[(len - offset)] = data[len]; | |||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||
| 218 | 0 | len++; | |||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||
| 220 | else { | ||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if(offset) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 222 | 0 | u_data[(len - offset)] = data[len]; | |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||
| 224 | 0 | len++; | |||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if(offset) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 229 | 0 | size_t new_size = (len - offset); | |||||||||||||||||||||||||||||
| 230 | 0 | data[new_size] = '\0'; | |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||
| 232 | 0 | return new_size; | |||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||
| 235 | 0 | return size; | |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||
| 238 | 0 | bool myurl_utils_is_windows_drive_letter(const char* data, size_t length, size_t size) | |||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if(data == NULL) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 241 | 0 | return false; | |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||
| 243 | 0 | length++; | |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if(length >= size) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 246 | 0 | return false; | |||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | return mycore_string_alpha_character[ (unsigned char)data[(length - 1)] ] != 0xff && | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | (data[length] == ':' || data[length] == '|'); | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||
| 252 | 0 | bool myurl_utils_is_double_dot_path_segment(const char* data, size_t length) | |||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if(length < 2) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 255 | 0 | return false; | |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if(*data == '.' && data[1] == '.') { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if(length == 2) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 259 | 0 | return true; | |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||
| 261 | 0 | return false; | |||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if(length < 4) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 265 | 0 | return false; | |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if(*data == '.' && data[1] == '%' && data[2] == '2' && data[3] == 'e') { | ||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if(length == 4) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 269 | 0 | return true; | |||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||
| 271 | 0 | return false; | |||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if(*data == '%' && data[1] == '2' && data[2] == 'e' && data[3] == '.') { | ||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if(length == 4) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 276 | 0 | return true; | |||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||
| 278 | 0 | return false; | |||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if(length != 6) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 282 | 0 | return false; | |||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | if(*data == '%' && data[1] == '2' && data[2] == 'e' && data[3] == '%' && data[4] == '2' && data[5] == 'e') { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 285 | 0 | return true; | |||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||
| 288 | 0 | return false; | |||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||
| 291 | 0 | bool myurl_utils_is_single_dot_path_segment(const char* data, size_t length) | |||||||||||||||||||||||||||||
| 292 | { | ||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if(length < 1) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 294 | 0 | return false; | |||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | if(*data == '.') { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if(length == 1) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 298 | 0 | return true; | |||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||
| 300 | 0 | return false; | |||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if(length != 3) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 304 | 0 | return false; | |||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if(*data == '%' && data[1] == '2' && data[2] == 'e') { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 307 | 0 | return true; | |||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||
| 310 | 0 | return false; | |||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||
| 313 | 0 | size_t myurl_convert_integer_to_data_without_check_buffer(long digit, char* return_str) | |||||||||||||||||||||||||||||
| 314 | { | ||||||||||||||||||||||||||||||
| 315 | 0 | size_t length = 0; | |||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if(digit != 0) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | if(digit < 0) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 319 | 0 | length++; | |||||||||||||||||||||||||||||
| 320 | 0 | digit -= digit; | |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||
| 322 | 0 | return_str[0] = '-'; | |||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||
| 325 | /* calc end char count */ | ||||||||||||||||||||||||||||||
| 326 | 0 | length += (size_t)floor(log10( labs(digit) )) + 1; | |||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||
| 328 | else { | ||||||||||||||||||||||||||||||
| 329 | 0 | return_str[0] = '0'; | |||||||||||||||||||||||||||||
| 330 | 0 | return_str[1] = '\0'; | |||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||
| 332 | 0 | return 1; | |||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | for(size_t i = 0; i < length; i++) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 336 | 0 | return_str[ ((length - i) - 1) ] = (char)myurl_resources_static_map_digits[ digit % 10 ]; | |||||||||||||||||||||||||||||
| 337 | 0 | digit /= 10; | |||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||
| 340 | 0 | return_str[length] = '\0'; | |||||||||||||||||||||||||||||
| 341 | 0 | return length; | |||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||
| 344 | 0 | size_t myurl_convert_integer_to_hex_data_without_check_buffer(long digit, char* return_str) | |||||||||||||||||||||||||||||
| 345 | { | ||||||||||||||||||||||||||||||
| 346 | 0 | size_t length = 0; | |||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if(digit != 0) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if(digit < 0) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 350 | 0 | length++; | |||||||||||||||||||||||||||||
| 351 | 0 | digit -= digit; | |||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||
| 353 | 0 | return_str[0] = '-'; | |||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||
| 356 | /* calc end char count */ | ||||||||||||||||||||||||||||||
| 357 | 0 | long tmp_digit = digit; | |||||||||||||||||||||||||||||
| 358 | 0 | ▶ | while(tmp_digit) {length++; tmp_digit /= 16;} | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||
| 360 | else { | ||||||||||||||||||||||||||||||
| 361 | 0 | return_str[0] = '0'; | |||||||||||||||||||||||||||||
| 362 | 0 | return_str[1] = '\0'; | |||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||
| 364 | 0 | return 1; | |||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||
| 367 | 0 | size_t tmp_length = length; | |||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | while(digit) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 370 | 0 | unsigned long temp = digit % 16; | |||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||
| 372 | 0 | tmp_length--; | |||||||||||||||||||||||||||||
| 373 | 0 | ▶ | if(temp < 10) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 374 | 0 | return_str[tmp_length] = (char)(temp + 48); | |||||||||||||||||||||||||||||
| 375 | else | ||||||||||||||||||||||||||||||
| 376 | 0 | return_str[tmp_length] = (char)(temp + 87); | |||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||
| 378 | 0 | digit /= 16; | |||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||
| 381 | 0 | return_str[length] = '\0'; | |||||||||||||||||||||||||||||
| 382 | 0 | return length; | |||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||
| 385 | //void myurl_utils_data_set(myurl_parser_t* parser, myurl_parser_data_t* parse_data, const unsigned char* data, size_t length) | ||||||||||||||||||||||||||||||
| 386 | //{ | ||||||||||||||||||||||||||||||
| 387 | // if(parse_data->data == NULL) { | ||||||||||||||||||||||||||||||
| 388 | // parse_data->size = (length + 1); | ||||||||||||||||||||||||||||||
| 389 | // parse_data->length = length; | ||||||||||||||||||||||||||||||
| 390 | // | ||||||||||||||||||||||||||||||
| 391 | // parse_data->data = (unsigned char*)mchar_async_malloc(parser->mchar, parser->node_idx, parse_data->size); | ||||||||||||||||||||||||||||||
| 392 | // } | ||||||||||||||||||||||||||||||
| 393 | // else if(length >= parse_data->size) { | ||||||||||||||||||||||||||||||
| 394 | // parse_data->size = (length + 1); | ||||||||||||||||||||||||||||||
| 395 | // parse_data->length = length; | ||||||||||||||||||||||||||||||
| 396 | // | ||||||||||||||||||||||||||||||
| 397 | // parse_data->data = (unsigned char*)mchar_async_realloc(parser->mchar, parser->node_idx, | ||||||||||||||||||||||||||||||
| 398 | // (char*)parse_data->data, 0, parse_data->size); | ||||||||||||||||||||||||||||||
| 399 | // } | ||||||||||||||||||||||||||||||
| 400 | // | ||||||||||||||||||||||||||||||
| 401 | // if(data && length) { | ||||||||||||||||||||||||||||||
| 402 | // memcpy(parse_data->data, data, sizeof(unsigned char) * length); | ||||||||||||||||||||||||||||||
| 403 | // } | ||||||||||||||||||||||||||||||
| 404 | // | ||||||||||||||||||||||||||||||
| 405 | // parse_data->data[length] = '\0'; | ||||||||||||||||||||||||||||||
| 406 | //} | ||||||||||||||||||||||||||||||
| 407 | // | ||||||||||||||||||||||||||||||
| 408 | //void myurl_utils_data_append(myurl_parser_t* parser, myurl_parser_data_t* parse_data, const unsigned char* data, size_t length) | ||||||||||||||||||||||||||||||
| 409 | //{ | ||||||||||||||||||||||||||||||
| 410 | // if(parse_data->data == NULL) { | ||||||||||||||||||||||||||||||
| 411 | // parse_data->size = (length + 1); | ||||||||||||||||||||||||||||||
| 412 | // parse_data->data = (unsigned char*)mchar_async_malloc(parser->mchar, parser->node_idx, parse_data->size); | ||||||||||||||||||||||||||||||
| 413 | // } | ||||||||||||||||||||||||||||||
| 414 | // else if((parse_data->length + length) >= parse_data->size) { | ||||||||||||||||||||||||||||||
| 415 | // parse_data->size = (parse_data->length + length + 1); | ||||||||||||||||||||||||||||||
| 416 | // parse_data->data = (unsigned char*)mchar_async_realloc(parser->mchar, parser->node_idx, | ||||||||||||||||||||||||||||||
| 417 | // (char*)parse_data->data, 0, parse_data->size); | ||||||||||||||||||||||||||||||
| 418 | // } | ||||||||||||||||||||||||||||||
| 419 | // | ||||||||||||||||||||||||||||||
| 420 | // if(data && length) { | ||||||||||||||||||||||||||||||
| 421 | // memcpy(&parse_data->data[parse_data->length], data, sizeof(unsigned char) * length); | ||||||||||||||||||||||||||||||
| 422 | // } | ||||||||||||||||||||||||||||||
| 423 | // | ||||||||||||||||||||||||||||||
| 424 | // parse_data->length = parse_data->length + length; | ||||||||||||||||||||||||||||||
| 425 | // parse_data->data[parse_data->length] = '\0'; | ||||||||||||||||||||||||||||||
| 426 | //} | ||||||||||||||||||||||||||||||
| 427 | // | ||||||||||||||||||||||||||||||
| 428 | //void myurl_utils_data_copy(myurl_parser_t* parser, myurl_parser_data_t* to, const myurl_parser_data_t* from) | ||||||||||||||||||||||||||||||
| 429 | //{ | ||||||||||||||||||||||||||||||
| 430 | // if(to->data == NULL) { | ||||||||||||||||||||||||||||||
| 431 | // to->size = (from->length + 1); | ||||||||||||||||||||||||||||||
| 432 | // to->length = from->length; | ||||||||||||||||||||||||||||||
| 433 | // | ||||||||||||||||||||||||||||||
| 434 | // to->data = (unsigned char*)mchar_async_malloc(parser->mchar, parser->node_idx, to->size); | ||||||||||||||||||||||||||||||
| 435 | // } | ||||||||||||||||||||||||||||||
| 436 | // else if(from->length >= to->size) { | ||||||||||||||||||||||||||||||
| 437 | // to->size = (from->length + 1); | ||||||||||||||||||||||||||||||
| 438 | // to->length = from->length; | ||||||||||||||||||||||||||||||
| 439 | // | ||||||||||||||||||||||||||||||
| 440 | // to->data = (unsigned char*)mchar_async_realloc(parser->mchar, parser->node_idx, | ||||||||||||||||||||||||||||||
| 441 | // (char*)to->data, 0, to->size); | ||||||||||||||||||||||||||||||
| 442 | // } | ||||||||||||||||||||||||||||||
| 443 | // | ||||||||||||||||||||||||||||||
| 444 | // if(from->data && to->length) { | ||||||||||||||||||||||||||||||
| 445 | // memcpy(to->data, from->data, sizeof(unsigned char) * to->length); | ||||||||||||||||||||||||||||||
| 446 | // } | ||||||||||||||||||||||||||||||
| 447 | // | ||||||||||||||||||||||||||||||
| 448 | // to->data[to->length] = '\0'; | ||||||||||||||||||||||||||||||
| 449 | //} | ||||||||||||||||||||||||||||||
| 450 | // | ||||||||||||||||||||||||||||||
| 451 | //void myurl_utils_data_destroy(myurl_parser_t* parser, myurl_parser_data_t* parse_data, bool self_destroy) | ||||||||||||||||||||||||||||||
| 452 | //{ | ||||||||||||||||||||||||||||||
| 453 | // mchar_async_free(parser->mchar, parser->node_idx, (char*)parse_data->data); | ||||||||||||||||||||||||||||||
| 454 | // | ||||||||||||||||||||||||||||||
| 455 | // if(self_destroy) { | ||||||||||||||||||||||||||||||
| 456 | // mycore_free(parse_data); | ||||||||||||||||||||||||||||||
| 457 | // } | ||||||||||||||||||||||||||||||
| 458 | //} | ||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||