From f34f55edfc3dbeb8cccb21955ad22a8fc4a532bd Mon Sep 17 00:00:00 2001 From: horuga23 Date: Sun, 13 Jun 2010 23:11:15 +0200 Subject: [PATCH] Added support for Instant Messaging, fixed mem leaks, documentation. - fixed memory leaks in structured entries - documented some functions --- inc/gcontact.h | 123 ++++++++++++++++++++++++++++++++---------------- inc/internal_gcal.h | 18 +++++-- src/atom_parser.c | 74 +++++++++++++++++++---------- src/gcal_parser.c | 28 ++++++++++- src/gcont.c | 16 +++++-- src/gcontact.c | 125 +++++++++++++++++++++++++++++++++++++++++++++---- utests/utest_contact.c | 54 +++++++++++++++++++-- utests/utest_userapi.c | 12 +++-- 8 files changed, 357 insertions(+), 93 deletions(-) diff --git a/inc/gcontact.h b/inc/gcontact.h index 9422c71..f8011ee 100644 --- a/inc/gcontact.h +++ b/inc/gcontact.h @@ -84,7 +84,7 @@ typedef enum { P_WORK_PAGER, P_ITEMS_COUNT // must be the last one! } gcal_phone_type; - + /** Email types allowed by Google API */ typedef enum { E_INVALID = -1, @@ -103,33 +103,15 @@ typedef enum { A_ITEMS_COUNT // must be the last one! } gcal_address_type; - -/** Address structure, represents each field in structuredPostalAddress (Google API 3.0) */ -/* -F_AGENT, not used -F_HOUSENAME, not used -F_STREET, -F_POBOX, -F_NEIGHBORHOOD, not used -F_CITY, -F_SUBREGION, not used -F_REGION, -F_POSTCODE, -F_COUNTRY, -F_FORMATTEDADDRESS, -*/ +/** IM types allowed by Google API */ typedef enum { - F_INVALID = -1, - F_STREET, - F_POBOX, - F_CITY, - F_REGION, - F_POSTCODE, - F_COUNTRY, - F_FORMATTEDADDRESS, - F_ITEMS_COUNT // must be the last one! -} gcal_structured_postal_address_fields; - + I_INVALID = -1, + I_HOME, + I_WORK, + I_NETMEETING, + I_OTHER, + I_ITEMS_COUNT // must be the last one! +} gcal_im_type; /** Creates a new google contact object. * @@ -376,6 +358,7 @@ char gcal_contact_is_deleted(gcal_contact_t contact); * atom stream, it will be set to an empty string (i.e. ""). */ +/* TODO: document new functions */ int gcal_contact_get_emails_count(gcal_contact_t contact); int gcal_contact_get_pref_email(gcal_contact_t contact); char *gcal_contact_get_email_address(gcal_contact_t contact, int i); @@ -436,17 +419,6 @@ char *gcal_contact_get_profission(gcal_contact_t contact); */ char *gcal_contact_get_occupation(gcal_contact_t contact); - -/** Missing implementation. - * - * \todo Implement retrieve of extra fields in \ref atom_parser.c - * - * @param contact A contact object, see \ref gcal_contact. - * - * @return Will only return NULL. - */ -char *gcal_contact_get_im(gcal_contact_t contact); - /** Access contact website. * * @param contact A contact object, see \ref gcal_contact. @@ -477,6 +449,54 @@ int gcal_contact_get_phone_numbers_count(gcal_contact_t contact); char *gcal_contact_get_phone_number(gcal_contact_t contact, int i); gcal_phone_type gcal_contact_get_phone_number_type(gcal_contact_t contact, int i); +/** Access contact IM count. + * + * @param contact A contact object, see \ref gcal_contact. + * + * @return Number of IM entries. + * + */ +int gcal_contact_get_im_count(gcal_contact_t contact); + +/** Access contact preferred IM account. + * + * @param contact A contact object, see \ref gcal_contact. + * + * @return Number of preferred IM account. + * + */ +int gcal_contact_get_pref_im(gcal_contact_t contact); + +/** Access contact IM protocol. + * + * @param contact A contact object, see \ref gcal_contact. + * + * @param i Number of the IM entry + * + * @return Pointer to internal object field. + */ +char *gcal_contact_get_im_protocol(gcal_contact_t contact, int i); + +/** Access contact IM address. + * + * @param contact A contact object, see \ref gcal_contact. + * + * @param i Number of the IM entry + * + * @return Pointer to internal object field. + */ +char *gcal_contact_get_im_address(gcal_contact_t contact, int i); + +/** Access contact IM type. + * + * @param contact A contact object, see \ref gcal_contact. + * + * @param i Number of the IM entry + * + * @return Type of the IM account. + */ +gcal_phone_type gcal_contact_get_im_type(gcal_contact_t contact, int i); + /** Access contact address (structuredPostalAddress.formattedAddress). * * @param contact A contact object, see \ref gcal_contact. @@ -685,9 +705,7 @@ int gcal_contact_set_etag(gcal_contact_t contact, const char *field); -/** Sets the contact telephone (for while only a single number is supported). - * - * \todo Implement multiple numbers support +/** Sets the contact telephone. * * @param contact A contact object, see \ref gcal_contact. * @@ -703,6 +721,29 @@ int gcal_contact_add_phone_number(gcal_contact_t contact, const char *field, /* TODO: document new functions */ int gcal_contact_delete_phone_numbers(gcal_contact_t contact); +/** Sets contact IM. + * + * @param contact A contact object, see \ref gcal_contact. + * + * @param protcol IM protocol. + * + * @param address IM address. + * + * @param type IM type. + * + * @return 0 for success, -1 otherwise + */ +int gcal_contact_add_im(gcal_contact_t contact, const char *protcol, + const char *address, gcal_im_type type, int pref); + +/** Deletes contact IM. + * + * @param contact A contact object, see \ref gcal_contact. + * + * @return 0 for success, -1 otherwise + */ +int gcal_contact_delete_im(gcal_contact_t contact); + /** Sets the contact address (Google API v2.0 gd:postalAddress). * * @param contact A contact object, see \ref gcal_contact. diff --git a/inc/internal_gcal.h b/inc/internal_gcal.h index 3040332..584b4bf 100644 --- a/inc/internal_gcal.h +++ b/inc/internal_gcal.h @@ -185,12 +185,14 @@ struct gcal_event { /** Sub structures, e.g. represents each field of gd:structuredPostalAddress or gd:name. */ - struct gcal_structured_subvalues { - /* TODO: insert missing documentation here */ + /** Pointer to the next structured field */ struct gcal_structured_subvalues *next_field; + /** Number of address */ int field_typenr; + /** Index key of the entry (e.g. 'street') */ char *field_key; + /** Value of the entry */ char *field_value; }; @@ -227,14 +229,22 @@ struct gcal_contact { char *org_title; /** Occupation/Profession */ char *occupation; - /** IM contact */ - char *im; /** Phone numbers */ char **phone_numbers_field; /** Phone number types */ char **phone_numbers_type; /** Number of phone numbers */ int phone_numbers_nr; + /** IM address */ + char **im_address; + /** IM protocol */ + char **im_protocol; + /** IM types */ + char **im_type; + /** Number of IM accounts */ + int im_nr; + /** Number of preferred IM account */ + int im_pref; /** Address */ char *post_address; /** Structured postal address address */ diff --git a/src/atom_parser.c b/src/atom_parser.c index 85ec482..409aaf9 100644 --- a/src/atom_parser.c +++ b/src/atom_parser.c @@ -230,8 +230,8 @@ exit: static int extract_and_check_multi(xmlDoc *doc, char *xpath_expression, int getContent, char *attr1, char *attr2, - char* attr3, char ***values, char ***types, - int *pref) + char* attr3, char* attr4, char ***values, + char ***types, char ***protocols, int *pref) { xmlXPathObject *xpath_obj; xmlNodeSet *node; @@ -243,7 +243,7 @@ static int extract_and_check_multi(xmlDoc *doc, char *xpath_expression, xpath_expression, NULL); - if ((!values) || (attr2 && !types) || (attr3 && !pref)) { + if ((!values) || (attr2 && !types) || (attr3 && !protocols) || (attr4 && !pref)) { fprintf(stderr, "extract_and_check_multi: null pointers received"); goto exit; } @@ -268,6 +268,8 @@ static int extract_and_check_multi(xmlDoc *doc, char *xpath_expression, *values = (char **)malloc(node->nodeNr * sizeof(char*)); if (attr2) *types = (char **)malloc(node->nodeNr * sizeof(char*)); + if (attr3) + *protocols = (char **)malloc(node->nodeNr * sizeof(char*)); for (i = 0; i < node->nodeNr; i++) { if (getContent) @@ -290,6 +292,16 @@ static int extract_and_check_multi(xmlDoc *doc, char *xpath_expression, if (attr3) { if (xmlHasProp(node->nodeTab[i], attr3)) { tmp = xmlGetProp(node->nodeTab[i], attr3); + (*protocols)[i] = strdup(strchr(tmp,'#') + 1); + xmlFree(tmp); + } + else + (*protocols)[i] = strdup(""); + } + + if (attr4) { + if (xmlHasProp(node->nodeTab[i], attr4)) { + tmp = xmlGetProp(node->nodeTab[i], attr4); if (!strcmp(tmp,"true")) *pref = i; xmlFree(tmp); @@ -342,9 +354,7 @@ static int extract_and_check_multisub(xmlDoc *doc, char *xpath_expression, if (result == 0) goto exit; - tempval = (struct gcal_structured_subvalues *)malloc(sizeof(struct gcal_structured_subvalues)); - tempval->next_field = NULL; - (*values) = tempval; + tempval = (*values); if (attr1) *types = (char **)malloc(node->nodeNr * sizeof(char*)); @@ -353,18 +363,19 @@ static int extract_and_check_multisub(xmlDoc *doc, char *xpath_expression, cur_node = node->nodeTab[i]->children; for (child = cur_node; child; child = child->next) { if (tempval->next_field == NULL) { - tempval->next_field = (struct gcal_structured_subvalues *)malloc(sizeof(struct gcal_structured_subvalues)); - tempval->field_typenr = i; - tempval->field_key = strdup(child->name); - tmp = xmlNodeGetContent(child); - tempval->field_value = strdup(tmp); - free(tmp); - tempval = tempval->next_field; - /* init next entry */ - tempval->field_typenr = 0; - tempval->field_key = NULL; - tempval->field_value = NULL; - tempval->next_field = NULL; + if((tmp = xmlNodeGetContent(child))) { + tempval->next_field = (struct gcal_structured_subvalues *)malloc(sizeof(struct gcal_structured_subvalues)); + tempval->field_typenr = i; + tempval->field_key = strdup(child->name); + tempval->field_value = strdup(tmp); + xmlFree(tmp); + /* init next entry */ + tempval = tempval->next_field; + tempval->field_typenr = 0; + tempval->field_key = NULL; + tempval->field_value = NULL; + tempval->next_field = NULL; + } } } } @@ -669,9 +680,11 @@ int atom_extract_contact(xmlNode *entry, struct gcal_contact *ptr_entry) 0, "address", "rel", + NULL, "primary", &ptr_entry->emails_field, &ptr_entry->emails_type, + NULL, &ptr_entry->pref_email); /* TODO Commented to allow contacts without an email address @@ -730,10 +743,26 @@ int atom_extract_contact(xmlNode *entry, struct gcal_contact *ptr_entry) NULL, "rel", NULL, + NULL, &ptr_entry->phone_numbers_field, &ptr_entry->phone_numbers_type, + NULL, NULL); - + + /* Gets contact IM addresses */ + ptr_entry->im_nr = extract_and_check_multi(doc, + "//atom:entry/" + "gd:im", + 0, + "address", + "rel", + "protocol", + "primary", + &ptr_entry->im_address, + &ptr_entry->im_type, + &ptr_entry->im_protocol, + &ptr_entry->im_pref); + /* The 'postalAddress' contact field changed in GData-Version: 3.0 API, see: * http://code.google.com/intl/en-EN/apis/contacts/docs/3.0/ * migration_guide.html#Protocol @@ -763,8 +792,10 @@ int atom_extract_contact(xmlNode *entry, struct gcal_contact *ptr_entry) "href", NULL, NULL, + NULL, &ptr_entry->groupMembership, NULL, + NULL, NULL); /* Gets contact birthday */ @@ -785,11 +816,6 @@ int atom_extract_contact(xmlNode *entry, struct gcal_contact *ptr_entry) free(tmp); } - - /* TODO: implement remaining extra fields */ - ptr_entry->im = NULL; - - result = 0; cleanup: diff --git a/src/gcal_parser.c b/src/gcal_parser.c index 142fe11..88093df 100644 --- a/src/gcal_parser.c +++ b/src/gcal_parser.c @@ -557,6 +557,7 @@ int xmlcontact_create(struct gcal_contact *contact, char **xml_contact, xmlAddChild(root, node); } + /* email addresses */ if (contact->emails_nr > 0) { for (i = 0; i < contact->emails_nr; i++) { @@ -635,7 +636,7 @@ int xmlcontact_create(struct gcal_contact *contact, char **xml_contact, xmlAddChild(root, node); } - + if (contact->occupation) { node = xmlNewNode(NULL, "gContact:occupation"); if (!node) @@ -663,6 +664,31 @@ int xmlcontact_create(struct gcal_contact *contact, char **xml_contact, } } + /* im addresses */ + if (contact->im_nr > 0) { + for (i = 0; i < contact->im_nr; i++) { + if (!(node = xmlNewNode(ns, "im"))) + goto cleanup; + temp = (char *)malloc((strlen(contact->im_type[i])+strlen(rel_prefix)+1) * sizeof(char)); + strcpy(temp, rel_prefix); + strcat(temp, contact->im_type[i]); + xmlSetProp(node, BAD_CAST "rel", + BAD_CAST temp); + temp = (char *)malloc((strlen(contact->im_protocol[i])+strlen(rel_prefix)+1) * sizeof(char)); + strcpy(temp, rel_prefix); + strcat(temp, contact->im_protocol[i]); + xmlSetProp(node, BAD_CAST "protocol", + BAD_CAST temp); + xmlSetProp(node, BAD_CAST "address", + BAD_CAST contact->im_address[i]); + if (i == contact->im_pref) + xmlSetProp(node, BAD_CAST "primary", + BAD_CAST "true"); + xmlAddChild(root, node); + free(temp); + } + } + /* Sets contact structured postal addressees (Google API 3.0) */ /* TODO: move this to another function (identation is looking bad) */ if (contact->structured_address_nr > 0) { diff --git a/src/gcont.c b/src/gcont.c index 5dc53a1..c5c4d68 100644 --- a/src/gcont.c +++ b/src/gcont.c @@ -92,7 +92,6 @@ struct gcal_contact *gcal_get_all_contacts(struct gcal_resource *gcalobj, if (!gcalobj->document) goto exit; - result = get_entries_number(gcalobj->document); if (result == -1) goto cleanup; @@ -173,7 +172,7 @@ void gcal_init_contact(struct gcal_contact *contact) { if (!contact) return; - + contact->structured_address = (struct gcal_structured_subvalues *)malloc( sizeof(struct gcal_structured_subvalues)); contact->structured_address->field_typenr = 0; @@ -182,7 +181,7 @@ void gcal_init_contact(struct gcal_contact *contact) contact->structured_address->next_field = NULL; contact->structured_address_nr = 0; contact->structured_address_type = NULL; - + contact->structured_name = (struct gcal_structured_subvalues *)malloc( sizeof(struct gcal_structured_subvalues)); contact->structured_name->field_typenr = 0; @@ -199,9 +198,11 @@ void gcal_init_contact(struct gcal_contact *contact) contact->content = NULL; contact->nickname = NULL; contact->occupation = NULL; - contact->org_name = contact->org_title = contact->im = NULL; + contact->org_name = contact->org_title = NULL; contact->phone_numbers_field = contact->phone_numbers_type = NULL; contact->phone_numbers_nr = contact->groupMembership_nr = 0; + contact->im_protocol = contact->im_address = contact->im_type = NULL; + contact->im_nr = contact->im_pref = 0; contact->post_address = NULL; contact->groupMembership = NULL; contact->homepage = NULL; @@ -234,11 +235,14 @@ void gcal_destroy_contact(struct gcal_contact *contact) clean_string(contact->occupation); clean_string(contact->org_name); clean_string(contact->org_title); - clean_string(contact->im); clean_multi_string(contact->phone_numbers_field, contact->phone_numbers_nr); clean_multi_string(contact->phone_numbers_type, contact->phone_numbers_nr); clean_multi_string(contact->groupMembership, contact->groupMembership_nr); contact->phone_numbers_nr = contact->groupMembership_nr = 0; + clean_multi_string(contact->im_protocol, contact->im_nr); + clean_multi_string(contact->im_address, contact->im_nr); + clean_multi_string(contact->im_type, contact->im_nr); + contact->im_nr = contact->im_pref = 0; clean_string(contact->post_address); clean_string(contact->homepage); clean_string(contact->blog); @@ -257,6 +261,7 @@ void gcal_destroy_contact(struct gcal_contact *contact) free(temp_structured_entry); } } while (contact->structured_address); + free(contact->structured_address); clean_multi_string(contact->structured_address_type, contact->structured_address_nr); contact->structured_address_nr = 0; @@ -271,6 +276,7 @@ void gcal_destroy_contact(struct gcal_contact *contact) free(temp_structured_entry); } } while (contact->structured_name); + free(contact->structured_name); } void gcal_destroy_contacts(struct gcal_contact *contacts, size_t length) diff --git a/src/gcontact.c b/src/gcontact.c index 759043b..942b303 100644 --- a/src/gcontact.c +++ b/src/gcontact.c @@ -87,6 +87,14 @@ const char* gcal_address_type_str[] = { "other" // A_OTHER }; +/** Strings associated with im types */ +const char* gcal_im_type_str[] = { + "home", // I_HOME + "work", // I_WORK + "netmeeting", // I_NETMEETING + "other" // I_OTHER +}; + gcal_contact_t gcal_contact_new(char *raw_xml) { gcal_contact_t contact = NULL; @@ -429,13 +437,6 @@ char *gcal_contact_get_occupation(gcal_contact_t contact) return contact->occupation; } -char *gcal_contact_get_im(gcal_contact_t contact) -{ - if ((!contact)) - return NULL; - return contact->im; -} - char *gcal_contact_get_homepage(gcal_contact_t contact) { if ((!contact)) @@ -481,6 +482,53 @@ gcal_phone_type gcal_contact_get_phone_number_type(gcal_contact_t contact, int i return result; } +int gcal_contact_get_im_count(gcal_contact_t contact) +{ + if ((!contact)) + return -1; + return contact->im_nr; +} + +int gcal_contact_get_pref_im(gcal_contact_t contact) +{ + if ((!contact)) + return -1; + return contact->im_pref; +} + +char *gcal_contact_get_im_protocol(gcal_contact_t contact, int i) +{ + if ((!contact)) + return NULL; + if (!(contact->im_protocol) || (i >= contact->im_nr)) + return NULL; + return contact->im_protocol[i]; +} + +char *gcal_contact_get_im_address(gcal_contact_t contact, int i) +{ + if ((!contact)) + return NULL; + if (!(contact->im_address) || (i >= contact->im_nr)) + return NULL; + return contact->im_address[i]; +} + +gcal_phone_type gcal_contact_get_im_type(gcal_contact_t contact, int i) +{ + gcal_im_type result = P_INVALID; + int j; + + if ((!contact)) + return result; + if (!(contact->im_type) || (i >= contact->im_nr)) + return result; + for (j = 0; j < I_ITEMS_COUNT; j++) + if (!strcmp(contact->im_type[i], gcal_im_type_str[j])) + result = j; + return result; +} + gcal_structured_subvalues_t gcal_contact_get_structured_name(gcal_contact_t contact) { if ((!contact) || (!contact->structured_name)) @@ -650,6 +698,8 @@ int gcal_contact_delete_email_addresses(gcal_contact_t contact) } contact->emails_nr = contact->pref_email = 0; + + /* XXX: Think, this is obsolete??? */ contact->emails_field = contact->emails_type = 0; result = 0; @@ -788,6 +838,62 @@ int gcal_contact_add_phone_number(gcal_contact_t contact, const char *field, return result; } +int gcal_contact_delete_im(gcal_contact_t contact) +{ + int result = -1; + int temp; + + if (!contact) + return result; + + if (contact->im_nr > 0) { + for (temp = 0; temp < contact->im_nr; temp++) { + if (contact->im_protocol[temp]) + free(contact->im_protocol[temp]); + if (contact->im_address[temp]) + free(contact->im_address[temp]); + if (contact->im_type[temp]) + free(contact->im_type[temp]); + } + free(contact->im_protocol); + free(contact->im_address); + free(contact->im_type); + } + + contact->im_nr = contact->im_pref = 0; + + result = 0; + + return result; +} + +int gcal_contact_add_im(gcal_contact_t contact, const char *protcol, + const char *address, gcal_im_type type, int pref) +{ + int result = -1; + + if ((!contact) || (!protcol) || (!address) || (type<0) || (type>=I_ITEMS_COUNT)) + return result; + + contact->im_protocol = (char**) realloc(contact->im_protocol, (contact->im_nr+1) * sizeof(char*)); + contact->im_protocol[contact->im_nr] = strdup(protcol); + + contact->im_address = (char**) realloc(contact->im_address, (contact->im_nr+1) * sizeof(char*)); + contact->im_address[contact->im_nr] = strdup(address); + + contact->im_type = (char**) realloc(contact->im_type, (contact->im_nr+1) * sizeof(char*)); + contact->im_type[contact->im_nr] = strdup(gcal_im_type_str[type]); + + if (pref) + contact->im_pref = contact->im_nr; + + contact->im_nr++; + + result = 0; + + return result; +} + int gcal_contact_set_address(gcal_contact_t contact, const char *field) { int result = -1; @@ -881,11 +987,10 @@ int gcal_contact_delete_structured_entry(gcal_structured_subvalues_t structured_ if (!structured_entry) return result; - + for (temp_structured_entry = structured_entry; temp_structured_entry != NULL; temp_structured_entry = temp_structured_entry->next_field) { - if (temp_structured_entry->field_typenr) temp_structured_entry->field_typenr = 0; if (temp_structured_entry->field_key) @@ -893,7 +998,7 @@ int gcal_contact_delete_structured_entry(gcal_structured_subvalues_t structured_ if (temp_structured_entry->field_value) free(temp_structured_entry->field_value); } - + if (structured_entry_count && structured_entry_type) { if ((*structured_entry_count) > 0) { for (i = 0; i < (*structured_entry_count); i++) diff --git a/utests/utest_contact.c b/utests/utest_contact.c index 46c2459..2b43412 100644 --- a/utests/utest_contact.c +++ b/utests/utest_contact.c @@ -178,7 +178,13 @@ START_TEST (test_contact_xml) contact.groupMembership[0] = "http://www.google.com/m8/feeds/groups/gcal4tester%40gmail.com/base/6"; contact.groupMembership_nr = 1; contact.birthday = "1980-10-10"; - contact.im = "john_skype"; + contact.im_address = malloc(sizeof(char*)); + contact.im_address[0] = "john_skype"; + contact.im_protocol = malloc(sizeof(char*)); + contact.im_protocol[0] = "SKYPE"; + contact.im_type = malloc(sizeof(char*)); + contact.im_type[0] = "home"; + contact.im_nr = 1; contact.homepage = "www.homegage.com"; contact.blog = "myblog.homegage.com"; contact.post_address = NULL; @@ -283,7 +289,14 @@ START_TEST (test_contact_add) contact.org_name = "Foo software"; contact.org_title = "Software engineer"; contact.occupation = "Programmer"; - contact.im = "john"; + contact.birthday = "1980-10-10"; + contact.im_address = malloc(sizeof(char*)); + contact.im_address[0] = "john"; + contact.im_protocol = malloc(sizeof(char*)); + contact.im_protocol[0] = "SKYPE"; + contact.im_type = malloc(sizeof(char*)); + contact.im_type[0] = "home"; + contact.im_nr = 1; contact.phone_numbers_field = malloc(sizeof(char*)); contact.phone_numbers_field[0] = "+9977554422119900"; contact.phone_numbers_type = malloc(sizeof(char*)); @@ -392,6 +405,7 @@ START_TEST (test_contact_edit) { int result, address_nr, address_count; struct gcal_contact contact, contact_new, updated; + gcal_structured_subvalues_t structured_entry; // contact.common.title = "Johny Doe"; contact.common.title = NULL; @@ -423,7 +437,14 @@ START_TEST (test_contact_edit) contact.org_name = "Foo software"; contact.org_title = "Software engineer"; contact.occupation = "Programmer"; - contact.im = "johny"; + contact.birthday = "1980-10-10"; + contact.im_address = malloc(sizeof(char*)); + contact.im_address[0] = "johny"; + contact.im_protocol = malloc(sizeof(char*)); + contact.im_protocol[0] = "SKYPE"; + contact.im_type = malloc(sizeof(char*)); + contact.im_type[0] = "home"; + contact.im_nr = 1; contact.phone_numbers_field = malloc(sizeof(char*)); contact.phone_numbers_field[0] = "+9977554422119900"; contact.phone_numbers_type= malloc(sizeof(char*)); @@ -483,7 +504,32 @@ START_TEST (test_contact_edit) result = gcal_edit_contact(ptr_gcal, &contact_new, &updated); fail_if(result == -1, "Failed editing contact!"); - gcal_structured_subvalues_t structured_entry; + structured_entry = gcal_contact_get_structured_address(&contact); + gcal_contact_delete_structured_entry(structured_entry,gcal_contact_get_structured_address_count_obj(&contact),gcal_contact_get_structured_address_type_obj(&contact)); + + contact.structured_address->field_typenr = 0; + contact.structured_address->field_key = malloc(sizeof(char*)); + contact.structured_address->field_key = NULL; + contact.structured_address->field_value = malloc(sizeof(char*)); + contact.structured_address->field_value = NULL; + contact.structured_address_nr = 0; + contact.structured_address_type = (char**)malloc(sizeof(char*)); + address_nr = gcal_contact_set_structured_address_nr(&contact,A_HOME); + address_count = contact.structured_address_nr; + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"street","Unknown Av St, n 69"); + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"pobox","PO BOX 123 456"); + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"city","Dirty Old Town"); + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"region","Somewhere"); + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"postcode","ABC 12345-D"); + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"country","Madagascar"); + address_nr = gcal_contact_set_structured_address_nr(&contact,A_WORK); + address_count = contact.structured_address_nr; + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"street","This One St, n 23"); + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"pobox","PO BOX 333 444 5"); + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"city","My Hometown"); + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"region","Hereorthere"); + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"postcode","XYZ 98765-C"); + gcal_contact_set_structured_entry(contact.structured_address,address_nr,address_count,"country","Island"); structured_entry = gcal_contact_get_structured_address(&contact); gcal_contact_delete_structured_entry(structured_entry,gcal_contact_get_structured_address_count_obj(&contact),gcal_contact_get_structured_address_type_obj(&contact)); diff --git a/utests/utest_userapi.c b/utests/utest_userapi.c index 75ae9a1..e9de7f9 100644 --- a/utests/utest_userapi.c +++ b/utests/utest_userapi.c @@ -247,6 +247,7 @@ START_TEST (test_access_contacts) int j; gcal_email_type get; gcal_phone_type gpt; + gcal_im_type git; gcal = gcal_new(GCONTACT); result = gcal_get_authentication(gcal, "gcal4tester", "66libgcal"); @@ -277,7 +278,10 @@ START_TEST (test_access_contacts) ptr = gcal_contact_get_content(contact); ptr = gcal_contact_get_organization(contact); ptr = gcal_contact_get_profission(contact); - ptr = gcal_contact_get_im(contact); + j = gcal_contact_get_im_count(contact); + ptr = gcal_contact_get_im_address(contact, 0); + ptr = gcal_contact_get_im_protocol(contact, 0); + git = gcal_contact_get_im_type(contact, 0); j = gcal_contact_get_phone_numbers_count(contact); ptr = gcal_contact_get_phone_number(contact, 0); gpt = gcal_contact_get_phone_number_type(contact, 0); @@ -312,8 +316,8 @@ START_TEST (test_access_contacts) ptr = gcal_contact_get_profission(gcal_contact_element(&contact_array, contact_array.length)); fail_if(ptr != NULL, "Getting field must fail!"); - ptr = gcal_contact_get_im(gcal_contact_element(&contact_array, - contact_array.length)); + ptr = gcal_contact_get_im_address(gcal_contact_element(&contact_array, + contact_array.length), 0); fail_if(ptr != NULL, "Getting field must fail!"); ptr = gcal_contact_get_phone_number(gcal_contact_element(&contact_array, contact_array.length), 0); @@ -322,7 +326,6 @@ START_TEST (test_access_contacts) contact_array.length)); fail_if(ptr != NULL, "Getting field must fail!"); - /* Cleanup */ gcal_cleanup_contacts(&contact_array); gcal_delete(gcal); @@ -386,6 +389,7 @@ START_TEST (test_oper_contact) /* Cleanup */ gcal_contact_delete(contact); gcal_delete(gcal); + } END_TEST -- 2.11.4.GIT