File Coverage

third_party/modest/source/myurl/scheme.c
Criterion Covered Total %
statement 0 41 0.0
branch 0 24 0.0
condition n/a
subroutine n/a
pod n/a
total 0 65 0.0


line stmt bran cond sub pod time code
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 0         if(scheme->name)
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 0         if(scheme == NULL)
37 0           return NULL;
38            
39 0 0         if(scheme->name)
40 0           url->callback_free(scheme->name, url->callback_ctx);
41            
42 0 0         if(self_destroy) {
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 0         while (myurl_scheme_entry_static_index[idx].name)
58             {
59 0 0         if(myurl_scheme_entry_static_index[idx].name_length == length) {
60 0 0         if(mycore_strncasecmp(myurl_scheme_entry_static_index[idx].name, name, length) == 0)
61 0           return &myurl_scheme_entry_static_index[idx];
62            
63 0 0         if(myurl_scheme_entry_static_index[idx].next)
64 0           idx = myurl_scheme_entry_static_index[idx].next;
65             else
66 0           return NULL;
67             }
68 0 0         else if(myurl_scheme_entry_static_index[idx].name_length > length) {
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 0         if(entry)
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 0         if(from->name) {
94 0           to->name = myurl_utils_data_copy(url, from->name, from->length);
95            
96 0 0         if(to->name == NULL) {
97 0           return MyURL_STATUS_ERROR_MEMORY_ALLOCATION;
98             }
99             }
100            
101 0           return MyURL_STATUS_OK;
102             }
103              
104