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(const 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
,
280 const char *timestamp
)
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 const char *gcal_contact_get_xml(gcal_contact_t contact
)
320 return gcal_get_xml(&(contact
->common
));
323 const char *gcal_contact_get_id(gcal_contact_t contact
)
327 return gcal_get_id(&(contact
->common
));
330 const char *gcal_contact_get_updated(gcal_contact_t contact
)
334 return gcal_get_updated(&(contact
->common
));
337 const char *gcal_contact_get_title(gcal_contact_t contact
)
341 return gcal_get_title(&(contact
->common
));
344 const char *gcal_contact_get_url(gcal_contact_t contact
)
348 return gcal_get_url(&(contact
->common
));
351 const 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 const 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 const 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 const char *gcal_contact_get_content(gcal_contact_t contact
)
419 return contact
->content
;
422 const char *gcal_contact_get_nickname(gcal_contact_t contact
)
426 return contact
->nickname
;
429 const char *gcal_contact_get_organization(gcal_contact_t contact
)
433 return contact
->org_name
;
436 const char *gcal_contact_get_profession(gcal_contact_t contact
)
440 return contact
->org_title
;
443 const char *gcal_contact_get_occupation(gcal_contact_t contact
)
447 return contact
->occupation
;
450 const char *gcal_contact_get_homepage(gcal_contact_t contact
)
454 return contact
->homepage
;
457 const 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 const 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 const 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 const char *gcal_contact_get_im(gcal_contact_t contact
)
510 if (!(contact
->im_address
))
515 pref_im
= gcal_contact_get_pref_im(contact
);
518 res
= gcal_contact_get_im_address(contact
, pref_im
);
522 int gcal_contact_get_im_count(gcal_contact_t contact
)
526 return contact
->im_nr
;
529 int gcal_contact_get_pref_im(gcal_contact_t contact
)
533 return contact
->im_pref
;
536 const char *gcal_contact_get_im_protocol(gcal_contact_t contact
, int i
)
540 if (!(contact
->im_protocol
) || (i
>= contact
->im_nr
))
542 return contact
->im_protocol
[i
];
545 const char *gcal_contact_get_im_address(gcal_contact_t contact
, int i
)
549 if (!(contact
->im_address
) || (i
>= contact
->im_nr
))
551 return contact
->im_address
[i
];
554 gcal_phone_type
gcal_contact_get_im_type(gcal_contact_t contact
, int i
)
556 gcal_im_type result
= P_INVALID
;
561 if (!(contact
->im_type
) || (i
>= contact
->im_nr
))
563 for (j
= 0; j
< I_ITEMS_COUNT
; j
++)
564 if (!strcmp(contact
->im_type
[i
], gcal_im_type_str
[j
]))
569 gcal_structured_subvalues_t
gcal_contact_get_structured_name(gcal_contact_t contact
)
571 if ((!contact
) || (!contact
->structured_name
))
573 return contact
->structured_name
;
576 const char *gcal_contact_get_address(gcal_contact_t contact
)
580 return contact
->post_address
;
583 gcal_structured_subvalues_t
gcal_contact_get_structured_address(gcal_contact_t contact
)
585 if ((!contact
) || (!contact
->structured_address
))
587 return contact
->structured_address
;
590 int gcal_contact_get_structured_address_count(gcal_contact_t contact
)
594 return contact
->structured_address_nr
;
597 const int *gcal_contact_get_structured_address_count_obj(gcal_contact_t contact
)
601 return &contact
->structured_address_nr
;
604 const char *gcal_contact_get_structured_entry(gcal_structured_subvalues_t structured_entry
,
605 int structured_entry_nr
,
606 int structured_entry_count
,
607 const char *field_key
)
609 struct gcal_structured_subvalues
*temp_structured_entry
;
611 if(field_key
== NULL
)
614 if (!structured_entry
|| (structured_entry_nr
>= structured_entry_count
))
617 for (temp_structured_entry
= structured_entry
;
618 temp_structured_entry
!= NULL
;
619 temp_structured_entry
= temp_structured_entry
->next_field
) {
621 if (temp_structured_entry
->next_field
!= NULL
) {
622 if (!strcmp(temp_structured_entry
->field_key
, field_key
)
623 && (temp_structured_entry
->field_typenr
== structured_entry_nr
)) {
624 return temp_structured_entry
->field_value
;
632 char ***gcal_contact_get_structured_address_type_obj(gcal_contact_t contact
)
636 return &contact
->structured_address_type
;
639 gcal_address_type
gcal_contact_get_structured_address_type(gcal_contact_t contact
,
640 int structured_entry_nr
,
641 int structured_entry_count
)
643 gcal_address_type result
= A_INVALID
;
649 if (!(contact
->structured_address_type
) ||
650 (structured_entry_nr
>= structured_entry_count
))
653 for (j
= 0; j
< A_ITEMS_COUNT
; j
++)
654 if (!strcmp(contact
->structured_address_type
[structured_entry_nr
], gcal_address_type_str
[j
]))
660 int gcal_contact_get_pref_structured_address(gcal_contact_t contact
)
664 return contact
->structured_address_pref
;
667 int gcal_contact_get_groupMembership_count(gcal_contact_t contact
)
671 return contact
->groupMembership_nr
;
674 const char *gcal_contact_get_groupMembership(gcal_contact_t contact
, int i
)
678 if (!(contact
->groupMembership
) || (i
>= contact
->groupMembership_nr
))
680 return contact
->groupMembership
[i
];
683 const char *gcal_contact_get_photo(gcal_contact_t contact
)
688 return contact
->photo_data
;
691 unsigned int gcal_contact_get_photolength(gcal_contact_t contact
)
696 return contact
->photo_length
;
699 const char *gcal_contact_get_birthday(gcal_contact_t contact
)
703 return contact
->birthday
;
706 /* Here starts the gcal_contact setters */
707 int gcal_contact_set_title(gcal_contact_t contact
, const char *field
)
711 if ((!contact
) || (!field
))
714 if (contact
->common
.title
)
715 free(contact
->common
.title
);
717 contact
->common
.title
= strdup(field
);
718 if (contact
->common
.title
)
724 int gcal_contact_delete_email_addresses(gcal_contact_t contact
)
732 if (contact
->emails_nr
> 0) {
733 for (temp
= 0; temp
< contact
->emails_nr
; temp
++) {
734 if (contact
->emails_field
[temp
])
735 free(contact
->emails_field
[temp
]);
736 if (contact
->emails_type
[temp
])
737 free(contact
->emails_type
[temp
]);
740 free(contact
->emails_field
);
741 free(contact
->emails_type
);
744 contact
->emails_nr
= contact
->pref_email
= 0;
746 /* XXX: Think, this is obsolete??? */
747 contact
->emails_field
= contact
->emails_type
= 0;
754 int gcal_contact_add_email_address(gcal_contact_t contact
, const char *field
,
755 gcal_email_type type
, int pref
)
759 if ((!contact
) || (!field
) || (type
<0) || (type
>=E_ITEMS_COUNT
))
762 contact
->emails_field
= (char**) realloc(contact
->emails_field
,
763 (contact
->emails_nr
+1) *
766 contact
->emails_field
[contact
->emails_nr
] = strdup(field
);
768 contact
->emails_type
= (char**) realloc(contact
->emails_type
,
769 (contact
->emails_nr
+1) *
772 contact
->emails_type
[contact
->emails_nr
] = strdup(gcal_email_type_str
[type
]);
775 contact
->pref_email
= contact
->emails_nr
;
777 contact
->emails_nr
++;
784 int gcal_contact_set_email(gcal_contact_t contact
, const char *pref_email
)
787 res
= gcal_contact_add_email_address(contact
, pref_email
, E_HOME
, 1);
791 int gcal_contact_set_url(gcal_contact_t contact
, const char *field
)
795 if ((!contact
) || (!field
))
798 if (contact
->common
.edit_uri
)
799 free(contact
->common
.edit_uri
);
801 contact
->common
.edit_uri
= strdup(field
);
802 if (contact
->common
.edit_uri
)
809 int gcal_contact_set_id(gcal_contact_t contact
, const char *field
)
813 if ((!contact
) || (!field
))
816 if (contact
->common
.id
)
817 free(contact
->common
.id
);
819 contact
->common
.id
= strdup(field
);
820 if (contact
->common
.id
)
827 int gcal_contact_set_etag(gcal_contact_t contact
, const char *field
)
831 if ((!contact
) || (!field
))
834 if (contact
->common
.etag
)
835 free(contact
->common
.etag
);
837 contact
->common
.etag
= strdup(field
);
838 if (contact
->common
.etag
)
844 int gcal_contact_delete_phone_numbers(gcal_contact_t contact
)
852 if (contact
->phone_numbers_nr
> 0) {
853 for (temp
= 0; temp
< contact
->phone_numbers_nr
; temp
++) {
854 if (contact
->phone_numbers_field
[temp
])
855 free(contact
->phone_numbers_field
[temp
]);
856 if (contact
->phone_numbers_type
[temp
])
857 free(contact
->phone_numbers_type
[temp
]);
860 free(contact
->phone_numbers_field
);
861 free(contact
->phone_numbers_type
);
864 contact
->phone_numbers_nr
= 0;
871 int gcal_contact_add_phone_number(gcal_contact_t contact
, const char *field
,
872 gcal_phone_type type
)
876 if ((!contact
) || (!field
) || (type
<0) || (type
>=P_ITEMS_COUNT
))
879 contact
->phone_numbers_field
= (char**) realloc(contact
->phone_numbers_field
, (contact
->phone_numbers_nr
+1) * sizeof(char*));
880 contact
->phone_numbers_field
[contact
->phone_numbers_nr
] = strdup(field
);
882 contact
->phone_numbers_type
= (char**) realloc(contact
->phone_numbers_type
, (contact
->phone_numbers_nr
+1) * sizeof(char*));
883 contact
->phone_numbers_type
[contact
->phone_numbers_nr
] = strdup(gcal_phone_type_str
[type
]);
885 contact
->phone_numbers_nr
++;
892 int gcal_contact_set_phone(gcal_contact_t contact
, const char *phone
)
895 res
= gcal_contact_delete_phone_numbers(contact
);
899 res
= gcal_contact_add_phone_number(contact
, phone
, P_MOBILE
);
903 int gcal_contact_delete_im(gcal_contact_t contact
)
911 if (contact
->im_nr
> 0) {
912 for (temp
= 0; temp
< contact
->im_nr
; temp
++) {
913 if (contact
->im_protocol
[temp
])
914 free(contact
->im_protocol
[temp
]);
915 if (contact
->im_address
[temp
])
916 free(contact
->im_address
[temp
]);
917 if (contact
->im_type
[temp
])
918 free(contact
->im_type
[temp
]);
920 free(contact
->im_protocol
);
921 free(contact
->im_address
);
922 free(contact
->im_type
);
925 contact
->im_nr
= contact
->im_pref
= 0;
932 int gcal_contact_add_im(gcal_contact_t contact
, const char *protcol
,
933 const char *address
, gcal_im_type type
, int pref
)
937 if ((!contact
) || (!protcol
) || (!address
) || (type
<0) || (type
>=I_ITEMS_COUNT
))
940 contact
->im_protocol
= (char**) realloc(contact
->im_protocol
, (contact
->im_nr
+1) * sizeof(char*));
941 contact
->im_protocol
[contact
->im_nr
] = strdup(protcol
);
943 contact
->im_address
= (char**) realloc(contact
->im_address
, (contact
->im_nr
+1) * sizeof(char*));
944 contact
->im_address
[contact
->im_nr
] = strdup(address
);
946 contact
->im_type
= (char**) realloc(contact
->im_type
, (contact
->im_nr
+1) * sizeof(char*));
947 contact
->im_type
[contact
->im_nr
] = strdup(gcal_im_type_str
[type
]);
950 contact
->im_pref
= contact
->im_nr
;
959 int gcal_contact_set_address(gcal_contact_t contact
, const char *field
)
963 if ((!contact
) || (!field
))
966 if (contact
->post_address
)
967 free(contact
->post_address
);
969 contact
->post_address
= strdup(field
);
970 if (contact
->post_address
)
976 int gcal_contact_set_structured_address_nr(gcal_contact_t contact
,
977 gcal_address_type type
)
979 int entry_nr
, result
= -1;
981 if (!contact
|| (type
< 0) || (type
>= A_ITEMS_COUNT
))
984 entry_nr
= contact
->structured_address_nr
;
985 contact
->structured_address_type
= (char**) realloc(contact
->structured_address_type
, (entry_nr
+ 1) * sizeof(char*));
986 contact
->structured_address_type
[entry_nr
] = strdup(gcal_address_type_str
[type
]);
987 contact
->structured_address_nr
++;
994 int gcal_contact_set_pref_structured_address(gcal_contact_t contact
, int pref_address
)
998 if ((!contact
) || (pref_address
< 0))
1001 contact
->structured_address_pref
= pref_address
;
1008 int gcal_contact_set_structured_entry(gcal_structured_subvalues_t structured_entry
,
1009 int structured_entry_nr
,
1010 int structured_entry_count
,
1011 const char *field_key
,
1012 const char *field_value
)
1014 struct gcal_structured_subvalues
*temp_structured_entry
;
1016 if (!structured_entry
|| (!field_value
) || (!field_key
) ||
1017 (structured_entry_nr
< 0) ||
1018 (structured_entry_nr
>= structured_entry_count
))
1021 if (field_value
== NULL
)
1024 if (structured_entry
->field_key
== NULL
) {
1025 structured_entry
->field_typenr
= structured_entry_nr
;
1026 structured_entry
->field_key
= strdup(field_key
);
1027 structured_entry
->field_value
= strdup(field_value
);
1028 structured_entry
->next_field
= NULL
;
1032 for (temp_structured_entry
= structured_entry
; temp_structured_entry
; temp_structured_entry
= temp_structured_entry
->next_field
) {
1033 if (!strcmp(temp_structured_entry
->field_key
,field_key
) &&
1034 (temp_structured_entry
->field_typenr
== structured_entry_nr
)) {
1035 if (temp_structured_entry
->field_value
!= NULL
) {
1036 free(temp_structured_entry
->field_value
);
1037 temp_structured_entry
->field_value
= strdup(field_value
);
1042 if (temp_structured_entry
->next_field
== NULL
) {
1043 temp_structured_entry
->next_field
= (struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
1044 temp_structured_entry
= temp_structured_entry
->next_field
;
1046 temp_structured_entry
->field_typenr
= structured_entry_nr
;
1047 temp_structured_entry
->field_key
= strdup(field_key
);
1048 temp_structured_entry
->field_value
= strdup(field_value
);
1049 temp_structured_entry
->next_field
= NULL
;
1057 int gcal_contact_delete_structured_entry(gcal_structured_subvalues_t structured_entry
,
1058 int *structured_entry_count
,
1059 char ***structured_entry_type
)
1062 struct gcal_structured_subvalues
*temp_structured_entry
;
1064 if (!structured_entry
)
1067 for (temp_structured_entry
= structured_entry
;
1068 temp_structured_entry
!= NULL
;
1069 temp_structured_entry
= temp_structured_entry
->next_field
) {
1070 if (temp_structured_entry
->field_typenr
)
1071 temp_structured_entry
->field_typenr
= 0;
1072 if (temp_structured_entry
->field_key
)
1073 free(temp_structured_entry
->field_key
);
1074 if (temp_structured_entry
->field_value
)
1075 free(temp_structured_entry
->field_value
);
1078 if (structured_entry_count
&& structured_entry_type
) {
1079 if ((*structured_entry_count
) > 0) {
1080 for (i
= 0; i
< (*structured_entry_count
); i
++)
1081 if ((*structured_entry_type
)[i
])
1082 free((*structured_entry_type
)[i
]);
1083 free((*structured_entry_type
));
1086 (*structured_entry_count
) = 0;
1093 int gcal_contact_delete_groupMembership(gcal_contact_t contact
)
1101 if (contact
->groupMembership_nr
> 0) {
1102 for (temp
= 0; temp
< contact
->groupMembership_nr
; temp
++) {
1103 if (contact
->groupMembership
[temp
])
1104 free(contact
->groupMembership
[temp
]);
1107 free(contact
->groupMembership
);
1110 contact
->groupMembership_nr
= 0;
1115 int gcal_contact_add_groupMembership(gcal_contact_t contact
, const char *field
)
1119 if ((!contact
) || (!field
))
1122 contact
->groupMembership
= (char**) realloc(contact
->groupMembership
, (contact
->groupMembership_nr
+1) * sizeof(char*));
1123 contact
->groupMembership
[contact
->groupMembership_nr
] = strdup(field
);
1125 contact
->groupMembership_nr
++;
1132 int gcal_contact_set_profession(gcal_contact_t contact
, const char *field
)
1136 if ((!contact
) || (!field
))
1139 if (contact
->org_title
)
1140 free(contact
->org_title
);
1142 contact
->org_title
= strdup(field
);
1143 if (contact
->org_title
)
1150 int gcal_contact_set_organization(gcal_contact_t contact
, const char *field
)
1154 if ((!contact
) || (!field
))
1157 if (contact
->org_name
)
1158 free(contact
->org_name
);
1160 contact
->org_name
= strdup(field
);
1161 if (contact
->org_name
)
1167 int gcal_contact_set_occupation(gcal_contact_t contact
, const char *field
)
1171 if ((!contact
) || (!field
))
1174 if (contact
->occupation
)
1175 free(contact
->occupation
);
1177 contact
->occupation
= strdup(field
);
1178 if (contact
->occupation
)
1184 int gcal_contact_set_content(gcal_contact_t contact
, const char *field
)
1188 if ((!contact
) || (!field
))
1191 if (contact
->content
)
1192 free(contact
->content
);
1194 contact
->content
= strdup(field
);
1195 if (contact
->content
)
1201 int gcal_contact_set_nickname(gcal_contact_t contact
, const char *field
)
1205 if ((!contact
) || (!field
))
1208 if (contact
->nickname
)
1209 free(contact
->nickname
);
1211 contact
->nickname
= strdup(field
);
1212 if (contact
->nickname
)
1218 int gcal_contact_set_photo(gcal_contact_t contact
, const char *field
,
1223 if ((!contact
) || (!field
))
1226 if (contact
->photo_data
)
1227 if (contact
->photo_length
> 1)
1228 free(contact
->photo_data
);
1230 if (!(contact
->photo_data
= malloc(length
* sizeof(unsigned char))))
1233 memcpy(contact
->photo_data
, field
, length
);
1234 contact
->photo_length
= length
;
1240 int gcal_contact_set_birthday(gcal_contact_t contact
, const char *field
)
1244 if ((!contact
) || (!field
))
1247 if (contact
->birthday
)
1248 free(contact
->birthday
);
1250 contact
->birthday
= strdup(field
);
1251 if (contact
->birthday
)
1257 int gcal_contact_set_homepage(gcal_contact_t contact
, const char *field
)
1261 if ((!contact
) || (!field
))
1264 if (contact
->homepage
)
1265 free(contact
->homepage
);
1267 contact
->homepage
= strdup(field
);
1268 if (contact
->homepage
)
1274 int gcal_contact_set_blog(gcal_contact_t contact
, const char *field
)
1278 if ((!contact
) || (!field
))
1282 free(contact
->blog
);
1284 contact
->blog
= strdup(field
);