« third_party/modest/source/myurl/punycode.c
↑ Summary
third_party/modest/source/myurl/serialization.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 Street, 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/scheme.h" | ||||||||||
| 23 | #include "myurl/scheme_resources.h" | ||||||||||
| 24 | #include "mycore/utils/resources.h" | ||||||||||
| 25 | |||||||||||
| 26 | 0 | void myurl_scheme_clean(myurl_t* url, myurl_scheme_t* scheme) | |||||||||
| 27 | { | ||||||||||
| 28 | 0 | ▶ | if(scheme->name) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | url->callback_free(scheme->name, url->callback_ctx); | |||||||||
| 30 | |||||||||||
| 31 | 0 | memset(scheme, 0, sizeof(myurl_scheme_t)); | |||||||||
| 32 | 0 | } | |||||||||
| 33 | |||||||||||
| 34 | 0 | myurl_scheme_t * myurl_scheme_destroy(myurl_t* url, myurl_scheme_t* scheme, bool self_destroy) | |||||||||
| 35 | { | ||||||||||
| 36 | 0 | ▶ | if(scheme == NULL) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | return NULL; | |||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | if(scheme->name) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | url->callback_free(scheme->name, url->callback_ctx); | |||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | if(self_destroy) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | url->callback_free(scheme, url->callback_ctx); | |||||||||
| 44 | 0 | return NULL; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | return scheme; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 0 | const myurl_scheme_entry_t * myurl_scheme_find_entry(const char* name, size_t length) | |||||||||
| 51 | { | ||||||||||
| 52 | 0 | size_t idx = ((mycore_string_chars_lowercase_map[ (const unsigned char)name[0] ] * | |||||||||
| 53 | 0 | mycore_string_chars_lowercase_map[ (const unsigned char)name[(length - 1)] ] * | |||||||||
| 54 | length) | ||||||||||
| 55 | 0 | % MyURL_SCHEME_STATIC_INDEX_LENGTH) + 1; | |||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | while (myurl_scheme_entry_static_index[idx].name) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | { | ||||||||||
| 59 | 0 | ▶ | if(myurl_scheme_entry_static_index[idx].name_length == length) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | ▶ | if(mycore_strncasecmp(myurl_scheme_entry_static_index[idx].name, name, length) == 0) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | return &myurl_scheme_entry_static_index[idx]; | |||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | if(myurl_scheme_entry_static_index[idx].next) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | idx = myurl_scheme_entry_static_index[idx].next; | |||||||||
| 65 | else | ||||||||||
| 66 | 0 | return NULL; | |||||||||
| 67 | } | ||||||||||
| 68 | 0 | ▶ | else if(myurl_scheme_entry_static_index[idx].name_length > length) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | return NULL; | |||||||||
| 70 | } | ||||||||||
| 71 | else { | ||||||||||
| 72 | 0 | idx = myurl_scheme_entry_static_index[idx].next; | |||||||||
| 73 | } | ||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 0 | return NULL; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 0 | myurl_scheme_id_t myurl_scheme_id_by_name(const char *name, size_t length) | |||||||||
| 80 | { | ||||||||||
| 81 | 0 | const myurl_scheme_entry_t *entry = myurl_scheme_find_entry(name, length); | |||||||||
| 82 | |||||||||||
| 83 | 0 | ▶ | if(entry) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | return entry->m_id; | |||||||||
| 85 | |||||||||||
| 86 | 0 | return MyURL_SCHEME_ID_UNDEF; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 0 | mystatus_t myurl_scheme_copy(myurl_t* url, myurl_scheme_t* from, myurl_scheme_t* to) | |||||||||
| 90 | { | ||||||||||
| 91 | 0 | memcpy(to, from, sizeof(myurl_scheme_t)); | |||||||||
| 92 | |||||||||||
| 93 | 0 | ▶ | if(from->name) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 0 | to->name = myurl_utils_data_copy(url, from->name, from->length); | |||||||||
| 95 | |||||||||||
| 96 | 0 | ▶ | if(to->name == NULL) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | return MyURL_STATUS_ERROR_MEMORY_ALLOCATION; | |||||||||
| 98 | } | ||||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 0 | return MyURL_STATUS_OK; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | |||||||||||