third_party/modest/source/mycore/incoming.c

filter: Statementstmt 0.0% 0 / 103 Branchbran 0.0% 0 / 44 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 147 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« third_party/modest/source/modest/style/sheet.c ↑ Summary third_party/modest/source/mycore/mythread.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 "mycore/incoming.h"
22 #include "mycore/utils/resources.h"
23  
24 0 mycore_incoming_buffer_t * mycore_incoming_buffer_add(mycore_incoming_buffer_t *current, mcobject_t *mcobject,
25 const char *html, size_t html_size)
26 {
27 0 mycore_incoming_buffer_t *inc_buf = mcobject_malloc(mcobject, NULL);
28
29 0 inc_buf->size = html_size;
30 0 inc_buf->length = 0;
31 0 inc_buf->data = html;
32
33 0 ▶ if(current) {
Branch: 1 branch
BranchTrueFalseTotal
if(current) { 0 0 0
34 0 inc_buf->offset = current->offset + current->size;
35 0 current->next = inc_buf;
36 }
37 else {
38 0 inc_buf->offset = 0;
39 }
40
41 0 inc_buf->prev = current;
42 0 inc_buf->next = NULL;
43
44 0 return inc_buf;
45 }
46  
47 0 void mycore_incoming_buffer_clean(mycore_incoming_buffer_t *current)
48 {
49 0 memset(current, 0, sizeof(mycore_incoming_buffer_t));
50 0 }
51  
52 0 mycore_incoming_buffer_t * mycore_incoming_buffer_split(mycore_incoming_buffer_t *current, mcobject_t *mcobject, size_t global_pos)
53 {
54 0 size_t relative_pos = global_pos - current->offset;
55 0 mycore_incoming_buffer_t *inc_buf = mcobject_malloc(mcobject, NULL);
56
57 0 inc_buf->size = current->size - relative_pos;
58 0 inc_buf->length = inc_buf->size;
59 0 inc_buf->data = &current->data[relative_pos];
60 0 inc_buf->offset = current->offset + relative_pos;
61 0 inc_buf->next = NULL;
62 0 inc_buf->prev = current;
63
64 0 current->next = inc_buf;
65 0 current->size = relative_pos;
66 0 current->length = relative_pos;
67
68 0 return inc_buf;
69 }
70  
71 0 mycore_incoming_buffer_t * mycore_incoming_buffer_find_by_position(mycore_incoming_buffer_t *inc_buf, size_t begin)
72 {
73 0 ▶ if(inc_buf->offset < begin) {
Branch: 1 branch
BranchTrueFalseTotal
if(inc_buf->offset < begin) { 0 0 0
74 0 ▶ while(inc_buf && (inc_buf->offset + inc_buf->size) < begin)
Branch: 2 branches
BranchTrueFalseTotal
while(inc_buf && (inc_buf->offset + inc_buf->size) < begin) 0 0 0
while(inc_buf && (inc_buf->offset + inc_buf->size) < begin) 0 0 0
75 0 inc_buf = inc_buf->next;
76 }
77 else {
78 0 ▶ while(inc_buf && inc_buf->offset > begin)
Branch: 2 branches
BranchTrueFalseTotal
while(inc_buf && inc_buf->offset > begin) 0 0 0
while(inc_buf && inc_buf->offset > begin) 0 0 0
79 0 inc_buf = inc_buf->prev;
80 }
81
82 0 return inc_buf;
83 }
84  
85 0 const char * mycore_incoming_buffer_data(mycore_incoming_buffer_t *inc_buf)
86 {
87 0 return inc_buf->data;
88 }
89  
90 0 size_t mycore_incoming_buffer_length(mycore_incoming_buffer_t *inc_buf)
91 {
92 0 return inc_buf->length;
93 }
94  
95 0 size_t mycore_incoming_buffer_size(mycore_incoming_buffer_t *inc_buf)
96 {
97 0 return inc_buf->size;
98 }
99  
100 0 size_t mycore_incoming_buffer_offset(mycore_incoming_buffer_t *inc_buf)
101 {
102 0 return inc_buf->offset;
103 }
104  
105 0 size_t mycore_incoming_buffer_relative_begin(mycore_incoming_buffer_t *inc_buf, size_t begin)
106 {
107 0 return (begin - inc_buf->offset);
108 }
109  
110 0 size_t mycore_incoming_buffer_available_length(mycore_incoming_buffer_t *inc_buf, size_t relative_begin, size_t length)
111 {
112 0 ▶ if((relative_begin + length) > inc_buf->size)
Branch: 1 branch
BranchTrueFalseTotal
if((relative_begin + length) > inc_buf->size) 0 0 0
113 0 return (inc_buf->size - relative_begin);
114
115 0 return length;
116 }
117  
118 0 mycore_incoming_buffer_t * mycore_incoming_buffer_next(mycore_incoming_buffer_t *inc_buf)
119 {
120 0 return inc_buf->next;
121 }
122  
123 0 mycore_incoming_buffer_t * mycore_incoming_buffer_prev(mycore_incoming_buffer_t *inc_buf)
124 {
125 0 return inc_buf->prev;
126 }
127  
128 // // //
129 // convert only one 002345 (\002345) to code point
130 //
131 0 size_t mycore_incoming_buffer_convert_one_escaped_to_code_point(mycore_incoming_buffer_t **inc_buf, size_t *relative_pos)
132 {
133 const unsigned char *u_data;
134 0 mycore_incoming_buffer_t *current = *inc_buf;
135
136 0 ▶ if(*relative_pos >= current->size) {
Branch: 1 branch
BranchTrueFalseTotal
if(*relative_pos >= current->size) { 0 0 0
137 0 *relative_pos = 0;
138 0 current = current->next;
139 }
140
141 0 u_data = (const unsigned char*)current->data;
142
143 0 unsigned int consume = 0;
144 0 size_t code_point = 0;
145
146 0 ▶ while(current)
Branch: 1 branch
BranchTrueFalseTotal
while(current) 0 0 0
147 {
148 0 ▶ if(mycore_string_chars_num_map[ u_data[*relative_pos] ] != 0xff && consume < 6) {
Branch: 2 branches
BranchTrueFalseTotal
if(mycore_string_chars_num_map[ u_data[*relative_pos] ] != 0xff && consume < 6) { 0 0 0
if(mycore_string_chars_num_map[ u_data[*relative_pos] ] != 0xff && consume < 6) { 0 0 0
149 0 code_point <<= 4;
150 0 code_point |= mycore_string_chars_hex_map[ u_data[*relative_pos] ];
151
152 0 ++consume;
153 }
154 else
155 break;
156
157 0 *relative_pos += 1;
158
159 0 ▶ if(*relative_pos >= current->size)
Branch: 1 branch
BranchTrueFalseTotal
if(*relative_pos >= current->size) 0 0 0
160 {
161 0 ▶ if(current->next == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(current->next == NULL) 0 0 0
162 0 break;
163
164 0 *relative_pos = 0;
165
166 0 u_data = (const unsigned char*)current->data;
167 0 current = current->next;
168 }
169 }
170
171 0 *inc_buf = current;
172
173 0 return code_point;
174 }
175  
176 0 size_t mycore_incoming_buffer_escaped_case_cmp(mycore_incoming_buffer_t **inc_buf, const char *to, size_t to_size, size_t *relative_pos)
177 {
178 0 mycore_incoming_buffer_t *current = *inc_buf;
179
180 0 ▶ if(*relative_pos >= current->size) {
Branch: 1 branch
BranchTrueFalseTotal
if(*relative_pos >= current->size) { 0 0 0
181 0 ▶ if(current->next == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(current->next == 0) 0 0 0
182 0 return to_size;
183
184 0 *relative_pos = 0;
185 0 current = current->next;
186 }
187
188 0 const unsigned char *u_to = (const unsigned char*)to;
189 0 const unsigned char *u_data = (const unsigned char*)current->data;
190
191 0 size_t i = 0;
192
193 0 ▶ while(i < to_size)
Branch: 1 branch
BranchTrueFalseTotal
while(i < to_size) 0 0 0
194 {
195 0 ▶ if(u_data[*relative_pos] == 0x5C) {
Branch: 1 branch
BranchTrueFalseTotal
if(u_data[*relative_pos] == 0x5C) { 0 0 0
196 0 *relative_pos += 1;
197
198 0 size_t code_point = mycore_incoming_buffer_convert_one_escaped_to_code_point(&current, relative_pos);
199
200 0 ▶ if(code_point > 255 || mycore_string_chars_lowercase_map[code_point] != mycore_string_chars_lowercase_map[ u_to[i] ]) {
Branch: 2 branches
BranchTrueFalseTotal
if(code_point > 255 || mycore_string_chars_lowercase_map[code_point] != mycore_string_chars_lowercase_map[ u_to[i] ]) { 0 0 0
if(code_point > 255 || mycore_string_chars_lowercase_map[code_point] != mycore_string_chars_lowercase_map[ u_to[i] ]) { 0 0 0
201 break;
202 }
203
204 0 u_data = (const unsigned char*)current->data;
205 }
206 0 ▶ else if(mycore_string_chars_lowercase_map[ u_data[*relative_pos] ] != mycore_string_chars_lowercase_map[ u_to[i] ]) {
Branch: 1 branch
BranchTrueFalseTotal
else if(mycore_string_chars_lowercase_map[ u_data[*relative_pos] ] != mycore_string_chars_lowercase_map[ u_to[i] ]) { 0 0 0
207 0 break;
208 }
209 else {
210 0 ++(*relative_pos);
211 }
212
213 0 i++;
214
215 0 ▶ if(*relative_pos >= current->size)
Branch: 1 branch
BranchTrueFalseTotal
if(*relative_pos >= current->size) 0 0 0
216 {
217 0 ▶ if(current->next == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(current->next == NULL) 0 0 0
218 0 break;
219
220 0 current = current->next;
221 0 u_data = (const unsigned char*)current->data;
222 0 *relative_pos = 0;
223 }
224 }
225
226 0 *inc_buf = current;
227 0 return (to_size - i);
228 }
« third_party/modest/source/modest/style/sheet.c ↑ Summary third_party/modest/source/mycore/mythread.c »