2 Copyright (c) 2008 Instituto Nokia de Tecnologia
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13 * Neither the name of the INdT nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
31 * @author Adenilson Cavalcanti da Silva <adenilson.silva@indt.org.br>
32 * @date Thu Jun 26 07:37:03 2008
34 * @brief libgcal google contacts user public API.
36 * Use this functions to handle common tasks when dealing with google contacts.
48 #include "gcal_parser.h"
49 #include "internal_gcal.h"
52 /** Strings associated with phone number types */
53 const char* gcal_phone_type_str
[] = {
54 "assistant", // P_ASSISTANT
55 "callback", // P_CALLBACK
57 "company_main", // P_COMPANY_MAIN
60 "home_fax", // P_HOME_FAX
65 "other_fax", // P_OTHER_FAX
69 "tty_tdd", // P_TTY_TDD
71 "work_fax", // P_WORK_FAX
72 "work_mobile", // P_WORK_MOBILE
73 "work_pager" // P_WORK_PAGER
76 /** Strings associated with email types */
77 const char* gcal_email_type_str
[] = {
83 /** Strings associated with address types */
84 const char* gcal_address_type_str
[] = {
90 /** Strings associated with im types */
91 const char* gcal_im_type_str
[] = {
94 "netmeeting", // I_NETMEETING
98 gcal_contact_t
gcal_contact_new(char *raw_xml
)
100 gcal_contact_t contact
= NULL
;
104 contact
= (gcal_contact_t
) malloc(sizeof(struct gcal_contact
));
108 gcal_init_contact(contact
);
112 /* Builds a doc, parse and init object */
113 doc
= build_dom_document(raw_xml
);
117 result
= extract_all_contacts(doc
, contact
, 1);
118 clean_dom_document(doc
);
129 void gcal_contact_delete(gcal_contact_t contact
)
134 gcal_destroy_contact(contact
);
139 int gcal_get_contacts(gcal_t gcalobj
, struct gcal_contact_array
*contact_array
)
143 contact_array
->length
= 0;
145 if ((!gcalobj
) || (!contact_array
))
148 result
= gcal_dump(gcalobj
, "GData-Version: 3.0");
150 contact_array
->entries
= NULL
;
151 contact_array
->length
= 0;
155 contact_array
->entries
= gcal_get_all_contacts(gcalobj
,
156 &contact_array
->length
);
157 if (!contact_array
->entries
)
166 void gcal_cleanup_contacts(struct gcal_contact_array
*contacts
)
171 gcal_destroy_contacts(contacts
->entries
, contacts
->length
);
172 contacts
->length
= 0;
173 contacts
->entries
= NULL
;
178 int gcal_add_contact(gcal_t gcalobj
, gcal_contact_t contact
)
181 struct gcal_contact updated
;
182 gcal_init_contact(&updated
);
184 if ((!gcalobj
) || (!contact
))
188 result
= gcal_create_contact(gcalobj
, contact
, &updated
);
192 /* Swap updated fields: id, updated, edit_uri, etag, photo url */
193 if (contact
->common
.id
)
194 free(contact
->common
.id
);
195 contact
->common
.id
= updated
.common
.id
;
196 updated
.common
.id
= NULL
;
198 if (contact
->common
.updated
)
199 free(contact
->common
.updated
);
200 contact
->common
.updated
= updated
.common
.updated
;
201 updated
.common
.updated
= NULL
;
203 if (contact
->common
.edit_uri
)
204 free(contact
->common
.edit_uri
);
205 contact
->common
.edit_uri
= updated
.common
.edit_uri
;
206 updated
.common
.edit_uri
= NULL
;
208 if (contact
->common
.etag
)
209 free(contact
->common
.etag
);
210 contact
->common
.etag
= updated
.common
.etag
;
211 updated
.common
.etag
= NULL
;
214 free(contact
->photo
);
215 contact
->photo
= updated
.photo
;
216 updated
.photo
= NULL
;
218 /* Cleanup updated contact */
219 gcal_destroy_contact(&updated
);
225 int gcal_update_contact(gcal_t gcalobj
, gcal_contact_t contact
)
228 struct gcal_contact updated
;
229 gcal_init_contact(&updated
);
231 if ((!gcalobj
) || (!contact
))
235 result
= gcal_edit_contact(gcalobj
, contact
, &updated
);
239 /* Swap updated fields: updated, edit_uri, etag */
240 if (contact
->common
.updated
)
241 free(contact
->common
.updated
);
242 contact
->common
.updated
= updated
.common
.updated
;
243 updated
.common
.updated
= NULL
;
245 if (contact
->common
.edit_uri
)
246 free(contact
->common
.edit_uri
);
247 contact
->common
.edit_uri
= updated
.common
.edit_uri
;
248 updated
.common
.edit_uri
= NULL
;
250 if (contact
->common
.etag
)
251 free(contact
->common
.etag
);
252 contact
->common
.etag
= updated
.common
.etag
;
253 updated
.common
.etag
= NULL
;
256 free(contact
->photo
);
257 contact
->photo
= updated
.photo
;
258 updated
.photo
= NULL
;
260 /* Cleanup updated contact */
261 gcal_destroy_contact(&updated
);
267 int gcal_erase_contact(gcal_t gcalobj
, gcal_contact_t contact
)
270 if ((!gcalobj
) || (!contact
))
273 result
= gcal_delete_contact(gcalobj
, contact
);
278 int gcal_get_updated_contacts(gcal_t gcal_obj
,
279 struct gcal_contact_array
*contacts
,
284 contacts
->length
= 0;
286 if ((!gcal_obj
) || (!contacts
))
289 result
= gcal_query_updated(gcal_obj
, timestamp
, "GData-Version: 3.0");
291 contacts
->entries
= NULL
;
292 contacts
->length
= 0;
296 contacts
->entries
= gcal_get_all_contacts(gcal_obj
, &contacts
->length
);
297 if (contacts
->entries
)
303 gcal_contact_t
gcal_contact_element(struct gcal_contact_array
*contacts
,
307 struct gcal_contact
*contact
= NULL
;
308 if ((!contacts
) || (_index
> (contacts
->length
- 1)) ||
309 (contacts
->length
== 0))
312 contact
= &contacts
->entries
[_index
];
316 char *gcal_contact_get_xml(gcal_contact_t contact
)
320 return gcal_get_xml(&(contact
->common
));
323 char *gcal_contact_get_id(gcal_contact_t contact
)
327 return gcal_get_id(&(contact
->common
));
330 char *gcal_contact_get_updated(gcal_contact_t contact
)
334 return gcal_get_updated(&(contact
->common
));
337 char *gcal_contact_get_title(gcal_contact_t contact
)
341 return gcal_get_title(&(contact
->common
));
344 char *gcal_contact_get_url(gcal_contact_t contact
)
348 return gcal_get_url(&(contact
->common
));
351 char *gcal_contact_get_etag(gcal_contact_t contact
)
355 return gcal_get_etag(&(contact
->common
));
358 char gcal_contact_is_deleted(gcal_contact_t contact
)
362 return gcal_get_deleted(&(contact
->common
));
366 /* This are the fields unique to contacts */
367 int gcal_contact_get_emails_count(gcal_contact_t contact
)
371 return contact
->emails_nr
;
374 int gcal_contact_get_pref_email(gcal_contact_t contact
)
378 return contact
->pref_email
;
381 char *gcal_contact_get_email_address(gcal_contact_t contact
, int i
)
385 if (!(contact
->emails_field
) || (i
>= contact
->emails_nr
))
387 return contact
->emails_field
[i
];
390 char *gcal_contact_get_email(gcal_contact_t contact
)
396 tmp
= gcal_contact_get_pref_email(contact
);
397 return gcal_contact_get_email_address(contact
, tmp
);
400 gcal_email_type
gcal_contact_get_email_address_type(gcal_contact_t contact
, int i
)
402 gcal_email_type result
= E_INVALID
;
407 if (!(contact
->emails_type
) || (i
>= contact
->emails_nr
))
409 for (j
= 0; j
< E_ITEMS_COUNT
; j
++)
410 if (!strcmp(contact
->emails_type
[i
], gcal_email_type_str
[j
]))
415 char *gcal_contact_get_content(gcal_contact_t contact
)
419 return contact
->content
;
422 char *gcal_contact_get_nickname(gcal_contact_t contact
)
426 return contact
->nickname
;
429 char *gcal_contact_get_organization(gcal_contact_t contact
)
433 return contact
->org_name
;
436 char *gcal_contact_get_profission(gcal_contact_t contact
)
440 return contact
->org_title
;
443 char *gcal_contact_get_occupation(gcal_contact_t contact
)
447 return contact
->occupation
;
450 char *gcal_contact_get_homepage(gcal_contact_t contact
)
454 return contact
->homepage
;
457 char *gcal_contact_get_blog(gcal_contact_t contact
)
461 return contact
->blog
;
464 int gcal_contact_get_phone_numbers_count(gcal_contact_t contact
)
468 return contact
->phone_numbers_nr
;
471 char *gcal_contact_get_phone_number(gcal_contact_t contact
, int i
)
475 if (!(contact
->phone_numbers_field
) || (i
>= contact
->phone_numbers_nr
))
477 return contact
->phone_numbers_field
[i
];
480 char *gcal_contact_get_phone(gcal_contact_t contact
)
486 /* The prefered phone is *always* the first */
487 res
= gcal_contact_get_phone_number(contact
, 0);
491 gcal_phone_type
gcal_contact_get_phone_number_type(gcal_contact_t contact
, int i
)
493 gcal_phone_type result
= P_INVALID
;
498 if (!(contact
->phone_numbers_type
) || (i
>= contact
->phone_numbers_nr
))
500 for (j
= 0; j
< P_ITEMS_COUNT
; j
++)
501 if (!strcmp(contact
->phone_numbers_type
[i
], gcal_phone_type_str
[j
]))
506 int gcal_contact_get_im_count(gcal_contact_t contact
)
510 return contact
->im_nr
;
513 int gcal_contact_get_pref_im(gcal_contact_t contact
)
517 return contact
->im_pref
;
520 char *gcal_contact_get_im_protocol(gcal_contact_t contact
, int i
)
524 if (!(contact
->im_protocol
) || (i
>= contact
->im_nr
))
526 return contact
->im_protocol
[i
];
529 char *gcal_contact_get_im_address(gcal_contact_t contact
, int i
)
533 if (!(contact
->im_address
) || (i
>= contact
->im_nr
))
535 return contact
->im_address
[i
];
538 gcal_phone_type
gcal_contact_get_im_type(gcal_contact_t contact
, int i
)
540 gcal_im_type result
= P_INVALID
;
545 if (!(contact
->im_type
) || (i
>= contact
->im_nr
))
547 for (j
= 0; j
< I_ITEMS_COUNT
; j
++)
548 if (!strcmp(contact
->im_type
[i
], gcal_im_type_str
[j
]))
553 gcal_structured_subvalues_t
gcal_contact_get_structured_name(gcal_contact_t contact
)
555 if ((!contact
) || (!contact
->structured_name
))
557 return contact
->structured_name
;
560 char *gcal_contact_get_address(gcal_contact_t contact
)
564 return contact
->post_address
;
567 gcal_structured_subvalues_t
gcal_contact_get_structured_address(gcal_contact_t contact
)
569 if ((!contact
) || (!contact
->structured_address
))
571 return contact
->structured_address
;
574 int gcal_contact_get_structured_address_count(gcal_contact_t contact
)
578 return contact
->structured_address_nr
;
581 int *gcal_contact_get_structured_address_count_obj(gcal_contact_t contact
)
585 return &contact
->structured_address_nr
;
588 char *gcal_contact_get_structured_entry(gcal_structured_subvalues_t structured_entry
,
589 int structured_entry_nr
,
590 int structured_entry_count
,
591 const char *field_key
)
593 struct gcal_structured_subvalues
*temp_structured_entry
;
595 if(field_key
== NULL
)
598 if (!structured_entry
|| (structured_entry_nr
>= structured_entry_count
))
601 for (temp_structured_entry
= structured_entry
;
602 temp_structured_entry
!= NULL
;
603 temp_structured_entry
= temp_structured_entry
->next_field
) {
605 if (temp_structured_entry
->next_field
!= NULL
) {
606 if (!strcmp(temp_structured_entry
->field_key
, field_key
)
607 && (temp_structured_entry
->field_typenr
== structured_entry_nr
)) {
608 return temp_structured_entry
->field_value
;
616 char ***gcal_contact_get_structured_address_type_obj(gcal_contact_t contact
)
620 return &contact
->structured_address_type
;
623 gcal_address_type
gcal_contact_get_structured_address_type(gcal_contact_t contact
,
624 int structured_entry_nr
,
625 int structured_entry_count
)
627 gcal_address_type result
= A_INVALID
;
633 if (!(contact
->structured_address_type
) ||
634 (structured_entry_nr
>= structured_entry_count
))
637 for (j
= 0; j
< A_ITEMS_COUNT
; j
++)
638 if (!strcmp(contact
->structured_address_type
[structured_entry_nr
], gcal_address_type_str
[j
]))
644 int gcal_contact_get_pref_structured_address(gcal_contact_t contact
)
648 return contact
->structured_address_pref
;
651 int gcal_contact_get_groupMembership_count(gcal_contact_t contact
)
655 return contact
->groupMembership_nr
;
658 char *gcal_contact_get_groupMembership(gcal_contact_t contact
, int i
)
662 if (!(contact
->groupMembership
) || (i
>= contact
->groupMembership_nr
))
664 return contact
->groupMembership
[i
];
667 char *gcal_contact_get_photo(gcal_contact_t contact
)
672 return contact
->photo_data
;
675 unsigned int gcal_contact_get_photolength(gcal_contact_t contact
)
680 return contact
->photo_length
;
683 char *gcal_contact_get_birthday(gcal_contact_t contact
)
687 return contact
->birthday
;
690 /* Here starts the gcal_contact setters */
691 int gcal_contact_set_title(gcal_contact_t contact
, const char *field
)
695 if ((!contact
) || (!field
))
698 if (contact
->common
.title
)
699 free(contact
->common
.title
);
701 contact
->common
.title
= strdup(field
);
702 if (contact
->common
.title
)
708 int gcal_contact_delete_email_addresses(gcal_contact_t contact
)
716 if (contact
->emails_nr
> 0) {
717 for (temp
= 0; temp
< contact
->emails_nr
; temp
++) {
718 if (contact
->emails_field
[temp
])
719 free(contact
->emails_field
[temp
]);
720 if (contact
->emails_type
[temp
])
721 free(contact
->emails_type
[temp
]);
724 free(contact
->emails_field
);
725 free(contact
->emails_type
);
728 contact
->emails_nr
= contact
->pref_email
= 0;
730 /* XXX: Think, this is obsolete??? */
731 contact
->emails_field
= contact
->emails_type
= 0;
738 int gcal_contact_add_email_address(gcal_contact_t contact
, const char *field
,
739 gcal_email_type type
, int pref
)
743 if ((!contact
) || (!field
) || (type
<0) || (type
>=E_ITEMS_COUNT
))
746 contact
->emails_field
= (char**) realloc(contact
->emails_field
,
747 (contact
->emails_nr
+1) *
750 contact
->emails_field
[contact
->emails_nr
] = strdup(field
);
752 contact
->emails_type
= (char**) realloc(contact
->emails_type
,
753 (contact
->emails_nr
+1) *
756 contact
->emails_type
[contact
->emails_nr
] = strdup(gcal_email_type_str
[type
]);
759 contact
->pref_email
= contact
->emails_nr
;
761 contact
->emails_nr
++;
768 int gcal_contact_set_email(gcal_contact_t contact
, const char *pref_email
)
771 res
= gcal_contact_add_email_address(contact
, pref_email
, E_HOME
, 1);
775 int gcal_contact_set_url(gcal_contact_t contact
, const char *field
)
779 if ((!contact
) || (!field
))
782 if (contact
->common
.edit_uri
)
783 free(contact
->common
.edit_uri
);
785 contact
->common
.edit_uri
= strdup(field
);
786 if (contact
->common
.edit_uri
)
793 int gcal_contact_set_id(gcal_contact_t contact
, const char *field
)
797 if ((!contact
) || (!field
))
800 if (contact
->common
.id
)
801 free(contact
->common
.id
);
803 contact
->common
.id
= strdup(field
);
804 if (contact
->common
.id
)
811 int gcal_contact_set_etag(gcal_contact_t contact
, const char *field
)
815 if ((!contact
) || (!field
))
818 if (contact
->common
.etag
)
819 free(contact
->common
.etag
);
821 contact
->common
.etag
= strdup(field
);
822 if (contact
->common
.etag
)
828 int gcal_contact_delete_phone_numbers(gcal_contact_t contact
)
836 if (contact
->phone_numbers_nr
> 0) {
837 for (temp
= 0; temp
< contact
->phone_numbers_nr
; temp
++) {
838 if (contact
->phone_numbers_field
[temp
])
839 free(contact
->phone_numbers_field
[temp
]);
840 if (contact
->phone_numbers_type
[temp
])
841 free(contact
->phone_numbers_type
[temp
]);
844 free(contact
->phone_numbers_field
);
845 free(contact
->phone_numbers_type
);
848 contact
->phone_numbers_nr
= 0;
855 int gcal_contact_add_phone_number(gcal_contact_t contact
, const char *field
,
856 gcal_phone_type type
)
860 if ((!contact
) || (!field
) || (type
<0) || (type
>=P_ITEMS_COUNT
))
863 contact
->phone_numbers_field
= (char**) realloc(contact
->phone_numbers_field
, (contact
->phone_numbers_nr
+1) * sizeof(char*));
864 contact
->phone_numbers_field
[contact
->phone_numbers_nr
] = strdup(field
);
866 contact
->phone_numbers_type
= (char**) realloc(contact
->phone_numbers_type
, (contact
->phone_numbers_nr
+1) * sizeof(char*));
867 contact
->phone_numbers_type
[contact
->phone_numbers_nr
] = strdup(gcal_phone_type_str
[type
]);
869 contact
->phone_numbers_nr
++;
876 int gcal_contact_set_phone(gcal_contact_t contact
, const char *phone
)
879 res
= gcal_contact_delete_phone_numbers(contact
);
883 res
= gcal_contact_add_phone_number(contact
, phone
, P_MOBILE
);
887 int gcal_contact_delete_im(gcal_contact_t contact
)
895 if (contact
->im_nr
> 0) {
896 for (temp
= 0; temp
< contact
->im_nr
; temp
++) {
897 if (contact
->im_protocol
[temp
])
898 free(contact
->im_protocol
[temp
]);
899 if (contact
->im_address
[temp
])
900 free(contact
->im_address
[temp
]);
901 if (contact
->im_type
[temp
])
902 free(contact
->im_type
[temp
]);
904 free(contact
->im_protocol
);
905 free(contact
->im_address
);
906 free(contact
->im_type
);
909 contact
->im_nr
= contact
->im_pref
= 0;
916 int gcal_contact_add_im(gcal_contact_t contact
, const char *protcol
,
917 const char *address
, gcal_im_type type
, int pref
)
921 if ((!contact
) || (!protcol
) || (!address
) || (type
<0) || (type
>=I_ITEMS_COUNT
))
924 contact
->im_protocol
= (char**) realloc(contact
->im_protocol
, (contact
->im_nr
+1) * sizeof(char*));
925 contact
->im_protocol
[contact
->im_nr
] = strdup(protcol
);
927 contact
->im_address
= (char**) realloc(contact
->im_address
, (contact
->im_nr
+1) * sizeof(char*));
928 contact
->im_address
[contact
->im_nr
] = strdup(address
);
930 contact
->im_type
= (char**) realloc(contact
->im_type
, (contact
->im_nr
+1) * sizeof(char*));
931 contact
->im_type
[contact
->im_nr
] = strdup(gcal_im_type_str
[type
]);
934 contact
->im_pref
= contact
->im_nr
;
943 int gcal_contact_set_address(gcal_contact_t contact
, const char *field
)
947 if ((!contact
) || (!field
))
950 if (contact
->post_address
)
951 free(contact
->post_address
);
953 contact
->post_address
= strdup(field
);
954 if (contact
->post_address
)
960 int gcal_contact_set_structured_address_nr(gcal_contact_t contact
,
961 gcal_address_type type
)
963 int entry_nr
, result
= -1;
965 if (!contact
|| (type
< 0) || (type
>= A_ITEMS_COUNT
))
968 entry_nr
= contact
->structured_address_nr
;
969 contact
->structured_address_type
= (char**) realloc(contact
->structured_address_type
, (entry_nr
+ 1) * sizeof(char*));
970 contact
->structured_address_type
[entry_nr
] = strdup(gcal_address_type_str
[type
]);
971 contact
->structured_address_nr
++;
978 int gcal_contact_set_pref_structured_address(gcal_contact_t contact
, int pref_address
)
982 if ((!contact
) || (pref_address
< 0))
985 contact
->structured_address_pref
= pref_address
;
992 int gcal_contact_set_structured_entry(gcal_structured_subvalues_t structured_entry
,
993 int structured_entry_nr
,
994 int structured_entry_count
,
995 const char *field_key
,
996 const char *field_value
)
998 struct gcal_structured_subvalues
*temp_structured_entry
;
1000 if (!structured_entry
|| (!field_value
) || (!field_key
) ||
1001 (structured_entry_nr
< 0) ||
1002 (structured_entry_nr
>= structured_entry_count
))
1005 if (field_value
== NULL
)
1008 if (structured_entry
->field_key
== NULL
) {
1009 structured_entry
->field_typenr
= structured_entry_nr
;
1010 structured_entry
->field_key
= strdup(field_key
);
1011 structured_entry
->field_value
= strdup(field_value
);
1012 structured_entry
->next_field
= NULL
;
1016 for (temp_structured_entry
= structured_entry
; temp_structured_entry
; temp_structured_entry
= temp_structured_entry
->next_field
) {
1017 if (!strcmp(temp_structured_entry
->field_key
,field_key
) &&
1018 (temp_structured_entry
->field_typenr
== structured_entry_nr
)) {
1019 if (temp_structured_entry
->field_value
!= NULL
) {
1020 free(temp_structured_entry
->field_value
);
1021 temp_structured_entry
->field_value
= strdup(field_value
);
1026 if (temp_structured_entry
->next_field
== NULL
) {
1027 temp_structured_entry
->next_field
= (struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
1028 temp_structured_entry
= temp_structured_entry
->next_field
;
1030 temp_structured_entry
->field_typenr
= structured_entry_nr
;
1031 temp_structured_entry
->field_key
= strdup(field_key
);
1032 temp_structured_entry
->field_value
= strdup(field_value
);
1033 temp_structured_entry
->next_field
= NULL
;
1041 int gcal_contact_delete_structured_entry(gcal_structured_subvalues_t structured_entry
,
1042 int *structured_entry_count
,
1043 char ***structured_entry_type
)
1046 struct gcal_structured_subvalues
*temp_structured_entry
;
1048 if (!structured_entry
)
1051 for (temp_structured_entry
= structured_entry
;
1052 temp_structured_entry
!= NULL
;
1053 temp_structured_entry
= temp_structured_entry
->next_field
) {
1054 if (temp_structured_entry
->field_typenr
)
1055 temp_structured_entry
->field_typenr
= 0;
1056 if (temp_structured_entry
->field_key
)
1057 free(temp_structured_entry
->field_key
);
1058 if (temp_structured_entry
->field_value
)
1059 free(temp_structured_entry
->field_value
);
1062 if (structured_entry_count
&& structured_entry_type
) {
1063 if ((*structured_entry_count
) > 0) {
1064 for (i
= 0; i
< (*structured_entry_count
); i
++)
1065 if ((*structured_entry_type
)[i
])
1066 free((*structured_entry_type
)[i
]);
1067 free((*structured_entry_type
));
1070 (*structured_entry_count
) = 0;
1077 int gcal_contact_delete_groupMembership(gcal_contact_t contact
)
1085 if (contact
->groupMembership_nr
> 0) {
1086 for (temp
= 0; temp
< contact
->groupMembership_nr
; temp
++) {
1087 if (contact
->groupMembership
[temp
])
1088 free(contact
->groupMembership
[temp
]);
1091 free(contact
->groupMembership
);
1094 contact
->groupMembership_nr
= 0;
1099 int gcal_contact_add_groupMembership(gcal_contact_t contact
, char *field
)
1103 if ((!contact
) || (!field
))
1106 contact
->groupMembership
= (char**) realloc(contact
->groupMembership
, (contact
->groupMembership_nr
+1) * sizeof(char*));
1107 contact
->groupMembership
[contact
->groupMembership_nr
] = strdup(field
);
1109 contact
->groupMembership_nr
++;
1116 int gcal_contact_set_profission(gcal_contact_t contact
, const char *field
)
1120 if ((!contact
) || (!field
))
1123 if (contact
->org_title
)
1124 free(contact
->org_title
);
1126 contact
->org_title
= strdup(field
);
1127 if (contact
->org_title
)
1134 int gcal_contact_set_organization(gcal_contact_t contact
, const char *field
)
1138 if ((!contact
) || (!field
))
1141 if (contact
->org_name
)
1142 free(contact
->org_name
);
1144 contact
->org_name
= strdup(field
);
1145 if (contact
->org_name
)
1151 int gcal_contact_set_occupation(gcal_contact_t contact
, const char *field
)
1155 if ((!contact
) || (!field
))
1158 if (contact
->occupation
)
1159 free(contact
->occupation
);
1161 contact
->occupation
= strdup(field
);
1162 if (contact
->occupation
)
1168 int gcal_contact_set_content(gcal_contact_t contact
, const char *field
)
1172 if ((!contact
) || (!field
))
1175 if (contact
->content
)
1176 free(contact
->content
);
1178 contact
->content
= strdup(field
);
1179 if (contact
->content
)
1185 int gcal_contact_set_nickname(gcal_contact_t contact
, const char *field
)
1189 if ((!contact
) || (!field
))
1192 if (contact
->nickname
)
1193 free(contact
->nickname
);
1195 contact
->nickname
= strdup(field
);
1196 if (contact
->nickname
)
1202 int gcal_contact_set_photo(gcal_contact_t contact
, const char *field
,
1207 if ((!contact
) || (!field
))
1210 if (contact
->photo_data
)
1211 if (contact
->photo_length
> 1)
1212 free(contact
->photo_data
);
1214 if (!(contact
->photo_data
= malloc(length
* sizeof(unsigned char))))
1217 memcpy(contact
->photo_data
, field
, length
);
1218 contact
->photo_length
= length
;
1224 int gcal_contact_set_birthday(gcal_contact_t contact
, const char *field
)
1228 if ((!contact
) || (!field
))
1231 if (contact
->birthday
)
1232 free(contact
->birthday
);
1234 contact
->birthday
= strdup(field
);
1235 if (contact
->birthday
)
1241 int gcal_contact_set_homepage(gcal_contact_t contact
, const char *field
)
1245 if ((!contact
) || (!field
))
1248 if (contact
->homepage
)
1249 free(contact
->homepage
);
1251 contact
->homepage
= strdup(field
);
1252 if (contact
->homepage
)
1258 int gcal_contact_set_blog(gcal_contact_t contact
, const char *field
)
1262 if ((!contact
) || (!field
))
1266 free(contact
->blog
);
1268 contact
->blog
= strdup(field
);