GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tech/contacts.c
Date: 2026-12-03 19:36:00
Exec Total Coverage
Lines: 217 270 80.4%
Functions: 22 26 84.6%
Branches: 70 148 47.3%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2026, Stefan Meislinger |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/tech/contacts.h"
30 #include "gate/results.h"
31 #include "gate/utilities.h"
32 #include "gate/debugging.h"
33 #include "gate/encode/csv.h"
34
35 17 gate_result_t gate_contact_address_create_copy(gate_contact_address_t* address, gate_contact_address_t const* opt_src_address)
36 {
37
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 GATE_DEBUG_ASSERT(address != NULL);
38 17 gate_mem_clear(address, sizeof(gate_contact_address_t));
39
40
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
17 if (opt_src_address != NULL)
41 {
42 13 address->address_type = opt_src_address->address_type;
43 13 gate_string_duplicate(&address->po_box, &opt_src_address->po_box);
44 13 gate_string_duplicate(&address->extended, &opt_src_address->extended);
45 13 gate_string_duplicate(&address->street, &opt_src_address->street);
46 13 gate_string_duplicate(&address->locality, &opt_src_address->locality);
47 13 gate_string_duplicate(&address->region, &opt_src_address->region);
48 13 gate_string_duplicate(&address->code, &opt_src_address->code);
49 13 gate_string_duplicate(&address->country, &opt_src_address->country);
50 }
51 17 return GATE_RESULT_OK;
52 }
53
54 17 void gate_contact_address_destroy(gate_contact_address_t* address)
55 {
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 GATE_DEBUG_ASSERT(address != NULL);
57
58 17 gate_string_release(&address->po_box);
59 17 gate_string_release(&address->extended);
60 17 gate_string_release(&address->street);
61 17 gate_string_release(&address->locality);
62 17 gate_string_release(&address->region);
63 17 gate_string_release(&address->code);
64 17 gate_string_release(&address->country);
65 17 gate_mem_clear(address, sizeof(gate_contact_address_t));
66 17 }
67
68 6 static gate_result_t GATE_CALL cctor_contact_address(void* dest, void const* src)
69 {
70 6 return gate_contact_address_create_copy((gate_contact_address_t*)dest, (gate_contact_address_t const*)src);
71 }
72
73 6 static void GATE_CALL dtor_contact_address(void* dest)
74 {
75 6 gate_contact_address_destroy((gate_contact_address_t*)dest);
76 6 }
77
78
79
80 17 gate_result_t gate_contact_telephone_create_copy(gate_contact_telephone_t* tel, gate_contact_telephone_t const* opt_src_tel)
81 {
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 GATE_DEBUG_ASSERT(tel != NULL);
83 17 gate_mem_clear(tel, sizeof(gate_contact_telephone_t));
84
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
17 if (opt_src_tel != NULL)
85 {
86 13 tel->telephone_type = opt_src_tel->telephone_type;
87 13 gate_string_duplicate(&tel->number, &opt_src_tel->number);
88 }
89 17 return GATE_RESULT_OK;
90 }
91
92 17 void gate_contact_telephone_destroy(gate_contact_telephone_t* tel)
93 {
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 GATE_DEBUG_ASSERT(tel != NULL);
95 17 gate_string_release(&tel->number);
96 17 gate_mem_clear(tel, sizeof(gate_contact_telephone_t));
97 17 }
98
99 6 static gate_result_t GATE_CALL cctor_contact_telephone(void* dest, void const* src)
100 {
101 6 return gate_contact_telephone_create_copy((gate_contact_telephone_t*)dest, (gate_contact_telephone_t const*)src);
102 }
103
104 6 static void GATE_CALL dtor_contact_telephone(void* dest)
105 {
106 6 gate_contact_telephone_destroy((gate_contact_telephone_t*)dest);
107 6 }
108
109
110
111 17 gate_result_t gate_contact_email_create_copy(gate_contact_email_t* email, gate_contact_email_t const* opt_src_email)
112 {
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 GATE_DEBUG_ASSERT(email != NULL);
114 17 gate_mem_clear(email, sizeof(gate_contact_email_t));
115
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
17 if (opt_src_email != NULL)
116 {
117 13 email->email_type = opt_src_email->email_type;
118 13 gate_string_duplicate(&email->address, &opt_src_email->address);
119 }
120 17 return GATE_RESULT_OK;
121 }
122
123 17 void gate_contact_email_destroy(gate_contact_email_t* email)
124 {
125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 GATE_DEBUG_ASSERT(email != NULL);
126 17 gate_string_release(&email->address);
127 17 gate_mem_clear(email, sizeof(gate_contact_email_t));
128 17 }
129
130 6 static gate_result_t GATE_CALL cctor_contact_email(void* dest, void const* src)
131 {
132 6 return gate_contact_email_create_copy((gate_contact_email_t*)dest, (gate_contact_email_t const*)src);
133 }
134
135 6 static void GATE_CALL dtor_contact_email(void* dest)
136 {
137 6 gate_contact_email_destroy((gate_contact_email_t*)dest);
138 6 }
139
140
141
142 17 gate_result_t gate_contact_organization_create_copy(gate_contact_organization_t* org, gate_contact_organization_t const* opt_src_org)
143 {
144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 GATE_DEBUG_ASSERT(org != NULL);
145
146 17 gate_mem_clear(org, sizeof(gate_contact_organization_t));
147
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
17 if (NULL != opt_src_org)
148 {
149 13 gate_string_duplicate(&org->org_name, &opt_src_org->org_name);
150 13 gate_string_duplicate(&org->division, &opt_src_org->division);
151 13 gate_string_duplicate(&org->department, &opt_src_org->department);
152 13 gate_string_duplicate(&org->role, &opt_src_org->role);
153 13 gate_string_duplicate(&org->title, &opt_src_org->title);
154 }
155 17 return GATE_RESULT_OK;
156 }
157
158 17 void gate_contact_organization_destroy(gate_contact_organization_t* org)
159 {
160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 GATE_DEBUG_ASSERT(org != NULL);
161 17 gate_string_release(&org->org_name);
162 17 gate_string_release(&org->division);
163 17 gate_string_release(&org->department);
164 17 gate_string_release(&org->role);
165 17 gate_string_release(&org->title);
166 17 gate_mem_clear(org, sizeof(gate_contact_organization_t));
167
168 17 }
169
170 6 static gate_result_t GATE_CALL cctor_contact_org(void* dest, void const* src)
171 {
172 6 return gate_contact_organization_create_copy((gate_contact_organization_t*)dest, (gate_contact_organization_t const*)src);
173 }
174
175 6 static void GATE_CALL dtor_contact_org(void* dest)
176 {
177 6 gate_contact_organization_destroy((gate_contact_organization_t*)dest);
178 6 }
179
180
181
182 7 gate_result_t gate_contact_card_create_copy(gate_contact_card_t* card, gate_contact_card_t const* opt_src_card)
183 {
184
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 GATE_DEBUG_ASSERT(card != NULL);
185 7 gate_mem_clear(card, sizeof(gate_contact_card_t));
186
187
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
7 if (opt_src_card == NULL)
188 {
189 3 card->addresses = gate_arraylist_create(sizeof(gate_contact_address_t), NULL, 0, &cctor_contact_address, &dtor_contact_address);
190 3 card->telephones = gate_arraylist_create(sizeof(gate_contact_telephone_t), NULL, 0, &cctor_contact_telephone, &dtor_contact_telephone);
191 3 card->email_addresses = gate_arraylist_create(sizeof(gate_contact_email_t), NULL, 0, &cctor_contact_email, &dtor_contact_email);
192 3 card->organizations = gate_arraylist_create(sizeof(gate_contact_organization_t), NULL, 0, &cctor_contact_org, &dtor_contact_org);
193 }
194 else
195 {
196 4 gate_string_duplicate(&card->display_name, &opt_src_card->display_name);
197 4 gate_string_duplicate(&card->family_name, &opt_src_card->family_name);
198 4 gate_string_duplicate(&card->given_name, &opt_src_card->given_name);
199 4 gate_string_duplicate(&card->additional_name, &opt_src_card->additional_name);
200 4 gate_string_duplicate(&card->honoric_prefix, &opt_src_card->honoric_prefix);
201 4 gate_string_duplicate(&card->honoric_suffix, &opt_src_card->honoric_suffix);
202
203 4 card->addresses = gate_arraylist_copy(opt_src_card->addresses);
204 4 card->telephones = gate_arraylist_copy(opt_src_card->telephones);
205 4 card->email_addresses = gate_arraylist_copy(opt_src_card->email_addresses);
206
207 4 gate_string_duplicate(&card->nickname, &opt_src_card->nickname);
208 4 card->gender = opt_src_card->gender;
209 4 card->birthday = opt_src_card->birthday;
210
211 4 card->organizations = gate_arraylist_copy(opt_src_card->organizations);
212 4 card->creation_time = opt_src_card->creation_time;
213 4 card->update_time = opt_src_card->update_time;
214
215
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 if (gate_arraylist_is_null(card->addresses)
216
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 || gate_arraylist_is_null(card->telephones)
217
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 || gate_arraylist_is_null(card->email_addresses)
218
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 || gate_arraylist_is_null(card->organizations)
219 )
220 {
221 ✗ return GATE_RESULT_OUTOFMEMORY;
222 }
223 }
224 7 return GATE_RESULT_OK;
225 }
226
227 6 void gate_contact_card_destroy(gate_contact_card_t* card)
228 {
229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 GATE_DEBUG_ASSERT(card != NULL);
230
231 6 gate_string_release(&card->display_name);
232 6 gate_string_release(&card->family_name);
233 6 gate_string_release(&card->given_name);
234 6 gate_string_release(&card->additional_name);
235 6 gate_string_release(&card->honoric_prefix);
236 6 gate_string_release(&card->honoric_suffix);
237
238 6 gate_arraylist_release(&card->addresses);
239 6 gate_arraylist_release(&card->telephones);
240 6 gate_arraylist_release(&card->email_addresses);
241
242 6 gate_string_release(&card->nickname);
243 6 card->gender = ' ';
244 6 gate_mem_clear(&card->birthday, sizeof(gate_date_t));
245
246 6 gate_arraylist_release(&card->organizations);
247
248 6 gate_mem_clear(&card->creation_time, sizeof(gate_timestamp_t));
249 6 gate_mem_clear(&card->update_time, sizeof(gate_timestamp_t));
250 6 }
251
252
253 static gate_string_t const vcard_begin = GATE_STRING_INIT_STATIC("BEGIN:VCARD");
254 static gate_string_t const vcard_token_version = GATE_STRING_INIT_STATIC("VERSION:");
255 static gate_string_t const vcard_end = GATE_STRING_INIT_STATIC("END:VCARD");
256
257
258 ✗ static gate_result_t vcards_load(gate_stream_t* input_stream, gate_contact_cards_callback_t callback, void* param)
259 {
260 gate_result_t ret;
261 ✗ gate_bool_t in_card = false;
262 ✗ gate_contact_card_t current_card = GATE_INIT_EMPTY;
263 ✗ gate_bool_t continue_reading = true;
264
265 ✗ while (continue_reading)
266 {
267 gate_string_t line;
268 char line_buffer[1024];
269 ✗ gate_size_t line_len = 0;
270 ✗ ret = gate_stream_read_line(input_stream, line_buffer, sizeof(line_buffer), &line_len);
271 ✗ GATE_BREAK_IF_FAILED(ret);
272 ✗ if (line_len == 0)
273 {
274 ✗ break;
275 }
276 ✗ gate_string_create_static_len(&line, line_buffer, line_len);
277 ✗ gate_string_rtrim(&line, &line);
278
279 ✗ if (!in_card)
280 {
281 ✗ if (gate_string_equals(&line, &vcard_begin))
282 {
283 ✗ ret = gate_contact_card_create_copy(&current_card, NULL);
284 ✗ GATE_BREAK_IF_FAILED(ret);
285 ✗ in_card = true;
286 }
287 else
288 {
289 /* TODO invalid data !! */
290 }
291 }
292 else
293 {
294 ✗ if (gate_string_equals(&line, &vcard_end))
295 {
296 /* one card is completed -> send it to callback and release it afterwards*/
297 ✗ in_card = false;
298 ✗ if (callback != NULL)
299 {
300 ✗ if (!callback(&current_card, param))
301 {
302 /* canceled by user */
303 ✗ continue_reading = false;
304 }
305 }
306 ✗ gate_contact_card_destroy(&current_card);
307 }
308 ✗ else if (gate_string_starts_with(&line, &vcard_token_version))
309 {
310 /* do nothing */
311 }
312 else
313 {
314 /* TODO */
315 }
316 }
317 }
318 ✗ gate_contact_card_destroy(&current_card);
319
320 ✗ return ret;
321 }
322
323 static gate_string_t const csvkey_firstname = GATE_STRING_INIT_STATIC("First Name");
324 static gate_string_t const csvkey_middlename = GATE_STRING_INIT_STATIC("Middle Name");
325 static gate_string_t const csvkey_lastname = GATE_STRING_INIT_STATIC("Last Name");
326 static gate_string_t const csvkey_title = GATE_STRING_INIT_STATIC("Title");
327 static gate_string_t const csvkey_suffix = GATE_STRING_INIT_STATIC("Suffix");
328 static gate_string_t const csvkey_nickname = GATE_STRING_INIT_STATIC("Nickname");
329 static gate_string_t const csvkey_givenyomi = GATE_STRING_INIT_STATIC("Given Yomi");
330 static gate_string_t const csvkey_surnameyomi = GATE_STRING_INIT_STATIC("Surname Yomi");
331 static gate_string_t const csvkey_email1 = GATE_STRING_INIT_STATIC("E-mail Address");
332 static gate_string_t const csvkey_email2 = GATE_STRING_INIT_STATIC("E-mail 2 Address");
333 static gate_string_t const csvkey_email3 = GATE_STRING_INIT_STATIC("E-mail 3 Address");
334 static gate_string_t const csvkey_phonehome1 = GATE_STRING_INIT_STATIC("Home Phone");
335 static gate_string_t const csvkey_phonehome2 = GATE_STRING_INIT_STATIC("Home Phone 2");
336 static gate_string_t const csvkey_phonebusiness1 = GATE_STRING_INIT_STATIC("Business Phone");
337 static gate_string_t const csvkey_phonebusiness2 = GATE_STRING_INIT_STATIC("Business Phone 2");
338 static gate_string_t const csvkey_phonemobile = GATE_STRING_INIT_STATIC("Mobile Phone");
339 static gate_string_t const csvkey_phonecar = GATE_STRING_INIT_STATIC("Car Phone");
340 static gate_string_t const csvkey_phoneother = GATE_STRING_INIT_STATIC("Other Phone");
341 static gate_string_t const csvkey_phoneprimary = GATE_STRING_INIT_STATIC("Primary Phone");
342 static gate_string_t const csvkey_pager = GATE_STRING_INIT_STATIC("Pager");
343 static gate_string_t const csvkey_faxbusiness = GATE_STRING_INIT_STATIC("Business Fax");
344 static gate_string_t const csvkey_faxhome = GATE_STRING_INIT_STATIC("Home Fax");
345 static gate_string_t const csvkey_faxother = GATE_STRING_INIT_STATIC("Other Fax");
346 static gate_string_t const csvkey_phonecompany = GATE_STRING_INIT_STATIC("Company Main Phone");
347 static gate_string_t const csvkey_callback = GATE_STRING_INIT_STATIC("Callback");
348 static gate_string_t const csvkey_phoneradio = GATE_STRING_INIT_STATIC("Radio Phone");
349 static gate_string_t const csvkey_telex = GATE_STRING_INIT_STATIC("Telex");
350 static gate_string_t const csvkey_phonetty = GATE_STRING_INIT_STATIC("TTY/TDD Phone");
351 static gate_string_t const csvkey_imaddress = GATE_STRING_INIT_STATIC("IMAddress");
352 static gate_string_t const csvkey_jobtitle = GATE_STRING_INIT_STATIC("Job Title");
353 static gate_string_t const csvkey_department = GATE_STRING_INIT_STATIC("Department");
354 static gate_string_t const csvkey_company = GATE_STRING_INIT_STATIC("Company");
355 static gate_string_t const csvkey_officelocation = GATE_STRING_INIT_STATIC("Office Location");
356 static gate_string_t const csvkey_managername = GATE_STRING_INIT_STATIC("Manager's Name");
357 static gate_string_t const csvkey_assistantname = GATE_STRING_INIT_STATIC("Assistant's Name");
358 static gate_string_t const csvkey_assistantphone = GATE_STRING_INIT_STATIC("Assistant's Phone");
359 static gate_string_t const csvkey_companyyomi = GATE_STRING_INIT_STATIC("Company Yomi");
360 static gate_string_t const csvkey_businessstreet = GATE_STRING_INIT_STATIC("Business Street");
361 static gate_string_t const csvkey_businesscity = GATE_STRING_INIT_STATIC("Business City");
362 static gate_string_t const csvkey_businessstate = GATE_STRING_INIT_STATIC("Business State");
363 static gate_string_t const csvkey_businesspostalcode = GATE_STRING_INIT_STATIC("Business Postal Code");
364 static gate_string_t const csvkey_businesscountry = GATE_STRING_INIT_STATIC("Business Country/Region");
365 static gate_string_t const csvkey_homestreet = GATE_STRING_INIT_STATIC("Home Street");
366 static gate_string_t const csvkey_homecity = GATE_STRING_INIT_STATIC("Home City");
367 static gate_string_t const csvkey_homestate = GATE_STRING_INIT_STATIC("Home State");
368 static gate_string_t const csvkey_homepostalcode = GATE_STRING_INIT_STATIC("Home Postal Code");
369 static gate_string_t const csvkey_homecounty = GATE_STRING_INIT_STATIC("Home Country/Region");
370 static gate_string_t const csvkey_otherstreet = GATE_STRING_INIT_STATIC("Other Street");
371 static gate_string_t const csvkey_othercity = GATE_STRING_INIT_STATIC("Other City");
372 static gate_string_t const csvkey_otherstate = GATE_STRING_INIT_STATIC("Other State");
373 static gate_string_t const csvkey_otherpostalcode = GATE_STRING_INIT_STATIC("Other Postal Code");
374 static gate_string_t const csvkey_othercountry = GATE_STRING_INIT_STATIC("Other Country/Region");
375 static gate_string_t const csvkey_webpagepersonal = GATE_STRING_INIT_STATIC("Personal Web Page");
376 static gate_string_t const csvkey_spouse = GATE_STRING_INIT_STATIC("Spouse");
377 static gate_string_t const csvkey_schools = GATE_STRING_INIT_STATIC("Schools");
378 static gate_string_t const csvkey_hobby = GATE_STRING_INIT_STATIC("Hobby");
379 static gate_string_t const csvkey_location = GATE_STRING_INIT_STATIC("Location");
380 static gate_string_t const csvkey_webpage = GATE_STRING_INIT_STATIC("Web Page");
381 static gate_string_t const csvkey_birthday = GATE_STRING_INIT_STATIC("Birthday");
382 static gate_string_t const csvkey_anniversary = GATE_STRING_INIT_STATIC("Anniversary");
383 static gate_string_t const csvkey_notes = GATE_STRING_INIT_STATIC("Notes");
384
385 ✗ static gate_result_t mscsv_load(gate_stream_t* input_stream, gate_contact_cards_callback_t callback, void* param)
386 {
387 /* TODO */
388 ✗ return GATE_RESULT_NOTIMPLEMENTED;
389 }
390
391
392
393 ✗ gate_result_t gate_contact_cards_load(gate_enumint_t format, gate_stream_t* input_stream, gate_contact_cards_callback_t callback, void* param)
394 {
395 ✗ switch(format)
396 {
397 ✗ case GATE_CONTACT_FORMAT_VCARD:
398 ✗ return vcards_load(input_stream, callback, param);
399 ✗ case GATE_CONTACT_FORMAT_MSCSV:
400 ✗ return mscsv_load(input_stream, callback, param);
401 ✗ default:
402 ✗ break;
403 }
404 ✗ return GATE_RESULT_NOTSUPPORTED;
405 }
406
407 1 static char const* print_address_type(gate_contact_address_type_t addr_type)
408 {
409
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 switch(addr_type)
410 {
411 ✗ case GATE_CONTACT_ADDRESS_HOME: return "home";
412 ✗ case GATE_CONTACT_ADDRESS_WORK: return "work";
413 1 default:
414 1 case GATE_CONTACT_ADDRESS_DEFAULT: return "pref";
415 }
416 }
417
418 2 static char const* print_recipient_type(gate_contact_recipient_type_t reci_type)
419 {
420
1/7
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
2 switch(reci_type)
421 {
422 2 default:
423 case GATE_CONTACT_RECIPIENT_DEFAULT:
424 2 case GATE_CONTACT_RECIPIENT_HOME: return "home";
425 ✗ case GATE_CONTACT_RECIPIENT_WORK: return "work";
426 ✗ case GATE_CONTACT_RECIPIENT_CELLPHONE: return "cell";
427 ✗ case GATE_CONTACT_RECIPIENT_FAX: return "fax";
428 ✗ case GATE_CONTACT_RECIPIENT_VOICE: return "voice";
429 ✗ case GATE_CONTACT_RECIPIENT_VIDEO: return "video";
430 ✗ case GATE_CONTACT_RECIPIENT_TEXT: return "text";
431 }
432 }
433
434 1 static gate_result_t vcards_store(gate_enumerator_t* card_enumerator, gate_stream_t* output_stream)
435 {
436 1 gate_result_t ret = GATE_RESULT_OK;
437
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 for (; gate_enumerator_valid(card_enumerator); gate_enumerator_next(card_enumerator))
438 {
439 1 gate_contact_card_t const* card = (gate_contact_card_t const*)gate_enumerator_get(card_enumerator);
440 gate_enumerator_t enu;
441
442 1 ret = gate_stream_print(output_stream, GATE_PRINT_STRING, &vcard_begin, GATE_PRINT_CRLF, GATE_PRINT_END);
443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
444
445 1 ret = gate_stream_print(output_stream, GATE_PRINT_STRING, &vcard_token_version, GATE_PRINT_CSTR, "3.0", GATE_PRINT_CRLF, GATE_PRINT_END);
446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
447
448 1 ret = gate_stream_print(output_stream, GATE_PRINT_CSTR, "FN:", GATE_PRINT_STRING, &card->display_name, GATE_PRINT_CRLF, GATE_PRINT_END);
449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
450
451 1 ret = gate_stream_print(output_stream,
452 GATE_PRINT_CSTR, "N:", GATE_PRINT_STRING, &card->family_name,
453 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &card->given_name,
454 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &card->additional_name,
455 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &card->honoric_prefix,
456 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &card->honoric_suffix,
457 GATE_PRINT_CRLF, GATE_PRINT_END);
458
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
459
460
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (!gate_string_is_empty(&card->nickname))
461 {
462 1 ret = gate_stream_print(output_stream,
463 GATE_PRINT_CSTR, "NICKNAME:", GATE_PRINT_STRING, &card->nickname,
464 GATE_PRINT_CRLF, GATE_PRINT_END);
465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
466 }
467
468
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (card->gender != '\0' && card->gender != ' ')
469 {
470 1 ret = gate_stream_print(output_stream,
471 1 GATE_PRINT_CSTR, "GENDER:", GATE_PRINT_CHAR, card->gender,
472 GATE_PRINT_CRLF, GATE_PRINT_END);
473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
474 }
475
476
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (card->birthday.year >= 1601)
477 {
478 char buffer[32];
479 1 gate_size_t buffer_len = sizeof(buffer) - 1;
480 1 gate_datetime_t dt = GATE_INIT_EMPTY;
481 1 dt.date = card->birthday;
482 1 ret = gate_date_to_string(&dt, 0, "{YYYY}{MM}{DD}", buffer, &buffer_len);
483
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
484 1 ret = gate_stream_print(output_stream,
485 GATE_PRINT_CSTR, "BDAY:", GATE_PRINT_CSTR, buffer,
486 GATE_PRINT_CRLF, GATE_PRINT_END);
487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
488 }
489
490
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_arraylist_enumerate(card->addresses, &enu))
491 {
492
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 for (; gate_enumerator_valid(&enu); gate_enumerator_next(&enu))
493 {
494 1 gate_contact_address_t const* addr = (gate_contact_address_t const*)gate_enumerator_get(&enu);
495 1 ret = gate_stream_print(output_stream,
496 GATE_PRINT_CSTR, "ADR;TYPE=", GATE_PRINT_CSTR, print_address_type(addr->address_type),
497 GATE_PRINT_CSTR, ":", GATE_PRINT_STRING, &addr->po_box,
498 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &addr->extended,
499 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &addr->street,
500 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &addr->locality,
501 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &addr->region,
502 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &addr->code,
503 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &addr->country,
504 GATE_PRINT_CRLF, GATE_PRINT_END);
505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
506 }
507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
508 }
509
510
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_arraylist_enumerate(card->telephones, &enu))
511 {
512
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 for (; gate_enumerator_valid(&enu); gate_enumerator_next(&enu))
513 {
514 1 gate_contact_telephone_t const* tel = (gate_contact_telephone_t const*)gate_enumerator_get(&enu);
515 1 ret = gate_stream_print(output_stream,
516 GATE_PRINT_CSTR, "TEL;TYPE=", GATE_PRINT_CSTR, print_recipient_type(tel->telephone_type),
517 GATE_PRINT_CSTR, ":", GATE_PRINT_STRING, &tel->number,
518 GATE_PRINT_CRLF, GATE_PRINT_END);
519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
520 }
521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
522 }
523
524
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_arraylist_enumerate(card->email_addresses, &enu))
525 {
526
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 for (; gate_enumerator_valid(&enu); gate_enumerator_next(&enu))
527 {
528 1 gate_contact_email_t const* mail = (gate_contact_email_t const*)gate_enumerator_get(&enu);
529 1 ret = gate_stream_print(output_stream,
530 GATE_PRINT_CSTR, "EMAIL;TYPE=", GATE_PRINT_CSTR, print_recipient_type(mail->email_type),
531 GATE_PRINT_CSTR, ":", GATE_PRINT_STRING, &mail->address,
532 GATE_PRINT_CRLF, GATE_PRINT_END);
533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
534 }
535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
536 }
537
538
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_arraylist_enumerate(card->organizations, &enu))
539 {
540
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 for (; gate_enumerator_valid(&enu); gate_enumerator_next(&enu))
541 {
542 1 gate_contact_organization_t const* org = (gate_contact_organization_t const*)gate_enumerator_get(&enu);
543 1 ret = gate_stream_print(output_stream,
544 GATE_PRINT_CSTR, "ORG:", GATE_PRINT_STRING, &org->org_name,
545 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &org->division,
546 GATE_PRINT_CSTR, ";", GATE_PRINT_STRING, &org->department,
547 GATE_PRINT_CRLF, GATE_PRINT_END);
548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
549 1 ret = gate_stream_print(output_stream,
550 GATE_PRINT_CSTR, "ROLE:", GATE_PRINT_STRING, &org->role,
551 GATE_PRINT_CRLF, GATE_PRINT_END);
552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
553 1 ret = gate_stream_print(output_stream,
554 GATE_PRINT_CSTR, "TITLE:", GATE_PRINT_STRING, &org->title,
555 GATE_PRINT_CRLF, GATE_PRINT_END);
556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
557 }
558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
559 }
560
561
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (card->creation_time > 0)
562 {
563 1 gate_time_t tm = { card->creation_time, 0 };
564 char buffer[32];
565 1 gate_size_t buffer_len = sizeof(buffer);
566 1 ret = gate_time_to_string(&tm, "{YYYY}{MM}{DD}T{hh}{mm}{ss}Z", buffer, &buffer_len);
567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
568 1 ret = gate_stream_print(output_stream,
569 GATE_PRINT_CSTR, "CREATED:", GATE_PRINT_CSTR, buffer,
570 GATE_PRINT_CRLF, GATE_PRINT_END);
571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
572 }
573
574
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (card->update_time > 0)
575 {
576 1 gate_time_t tm = { card->creation_time, 0 };
577 char buffer[32];
578 1 gate_size_t buffer_len = sizeof(buffer);
579 1 ret = gate_time_to_string(&tm, "{YYYY}{MM}{DD}T{hh}{mm}{ss}Z", buffer, &buffer_len);
580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
581 1 ret = gate_stream_print(output_stream,
582 GATE_PRINT_CSTR, "REV:", GATE_PRINT_CSTR, buffer,
583 GATE_PRINT_CRLF, GATE_PRINT_END);
584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
585 }
586
587 1 ret = gate_stream_print(output_stream, GATE_PRINT_STRING, &vcard_end, GATE_PRINT_CRLF, GATE_PRINT_END);
588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
589 }
590 1 return ret;
591 }
592
593 ✗ static gate_result_t mscsv_store(gate_enumerator_t* card_enumerator, gate_stream_t* output_stream)
594 {
595 /* TODO */
596 ✗ return GATE_RESULT_NOTIMPLEMENTED;
597 }
598
599 1 gate_result_t gate_contact_cards_store(gate_enumint_t format, gate_enumerator_t* card_enumerator, gate_stream_t* output_stream)
600 {
601
1/3
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
1 switch(format)
602 {
603 1 case GATE_CONTACT_FORMAT_VCARD:
604 1 return vcards_store(card_enumerator, output_stream);
605 ✗ case GATE_CONTACT_FORMAT_MSCSV:
606 ✗ return mscsv_store(card_enumerator, output_stream);
607 ✗ default:
608 ✗ break;
609 }
610 ✗ return GATE_RESULT_NOTSUPPORTED;
611 }
612