From cc230e4191ee4377b343debcf504c60bf574c283 Mon Sep 17 00:00:00 2001 From: Jeesun Kim Date: Wed, 24 Feb 2016 14:16:25 +0900 Subject: [PATCH] [contacts-service] fixed invalid parameter, api usage Signed-off-by: Jeesun Kim Change-Id: I361b2ed09705d284263e7709814d9bb004643dc8 --- .../html/native/social/contact_tutorial_n.htm | 356 +++++++++++---------- 1 file changed, 184 insertions(+), 172 deletions(-) diff --git a/org.tizen.tutorials/html/native/social/contact_tutorial_n.htm b/org.tizen.tutorials/html/native/social/contact_tutorial_n.htm index eae45ac..b94b969 100644 --- a/org.tizen.tutorials/html/native/social/contact_tutorial_n.htm +++ b/org.tizen.tutorials/html/native/social/contact_tutorial_n.htm @@ -68,7 +68,7 @@
  • Getting Logs
  • Deleting a Log
  • - +
  • Records
  • - +

    Related Info

    -
  • Speed dials +
  • Speed dials
  • -
  • Phone logs +
  • Phone logs
    • Creating a Log

      Create a new log.

    • @@ -182,9 +182,9 @@

      Retrieve single log or a list of logs.

    • Deleting a Log

      Delete the log from the database.

    • -
    +
  • -

    Follow-up

    +

    Follow-up

    Once we have learned the basics of the Contacts API, we can now move on to more advanced tasks, including:

    - +

    Initializing Contacts

    To start with the Contact Service:

    -
    1. +
      1. To use the functions and data types of the Contacts API, include the <contacts.h> header file in your application:

         #include <contacts.h>
        -
      2. +
      3. Most of the API functions return error codes, therefore define at the beginning of your code the int type, which is used to store error codes. Each time when a function returns error codes, verify the result of the operation.
      4. Call the contacts_connect() function, which connects your application with the Contact Service. Without this function, you cannot get access to the contacts database.

        int error_code;
        @@ -379,19 +379,19 @@ error_code = contacts_db_get_all_records(_contacts_person._uri, 0, 0, &list)
         
      5. Iterate the list and read the records:

        - - - - - - - - - -
        Note
        Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
        - -
        1. To get the records from the list, use the contacts_list_get_current_record_p(), and contacts_list_next() or contacts_list_prev() functions. Get the details of each record in the loop.

          - + + + + + + + + + +
          Note
          Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
          + +
          1. To get the records from the list, use the contacts_list_get_current_record_p(), and contacts_list_next() or contacts_list_prev() functions. Get the details of each record in the loop.

            +
            contacts_record_h record;
             while (contacts_list_get_current_record_p(list, &record) == CONTACTS_ERROR_NONE)
             {
            @@ -415,7 +415,7 @@ while (contacts_list_get_current_record_p(list, &record) == CONTACTS_ERROR_N
             }
          2. The memory for the record data is allocated, and the data is copied from the record by the functions listed further on in this tutorial:
            -typedef struct 
            +typedef struct
             _contacts_gl_person_data
             {
                int id;
            @@ -424,7 +424,7 @@ _contacts_gl_person_data
                contacts_list_h associated_contacts;
             } contacts_gl_person_data_t;
             
            -static void 
            +static void
             _free_gl_person_data(contacts_gl_person_data_t *gl_person_data)
             {
                if (NULL == gl_person_data)
            @@ -436,7 +436,7 @@ _free_gl_person_data(contacts_gl_person_data_t *gl_person_data)
                free(gl_person_data);
             }
             
            -static contacts_gl_person_data_t* 
            +static contacts_gl_person_data_t*
             _create_gl_person_data(contacts_record_h record)
             {
                contacts_gl_person_data_t *gl_person_data;
            @@ -481,7 +481,7 @@ _create_gl_person_data(contacts_record_h record)
             
          3. Get the display name.

            Assuming that you have the person record handle (contacts_record_h), you can access the display_name property. You can read the display name property and print it.

            -static bool 
            +static bool
             _get_display_name(contacts_record_h record, char **display_name)
             {
                int error_code;
            @@ -495,7 +495,7 @@ _get_display_name(contacts_record_h record, char **display_name)
             }
          4. Get associated contacts of a person by query:
            -static bool 
            +static bool
             _get_associated_contacts(contacts_record_h record, contacts_list_h *associated_contacts)
             {
                int error_code;
            @@ -523,12 +523,12 @@ _get_associated_contacts(contacts_record_h record, contacts_list_h *associated_c
             }
          5. Get phone numbers by iterating the contacts list. The following example shows how to get all the number records and print them.
            -static void 
            +static void
             _print_phone_numbers(contacts_list_h associated_contacts)
             {
                int error_code;
                contacts_record_h contact;
            -   if (NULL == associated_contacts) 
            +   if (NULL == associated_contacts)
                {
                   dlog_print(DLOG_ERROR, LOG_TAG, "associated_contacts is NULL");
             
            @@ -540,7 +540,7 @@ _print_phone_numbers(contacts_list_h associated_contacts)
                   unsigned int count = 0;
             
                   error_code = contacts_record_get_child_record_count(contact, _contacts_contact.number, &count);
            -      if (CONTACTS_ERROR_NONE != error_code) 
            +      if (CONTACTS_ERROR_NONE != error_code)
                   {
                      dlog_print(DLOG_ERROR, LOG_TAG, "contacts_record_get_child_record_count(%d)", error_code);
             
            @@ -567,7 +567,7 @@ _print_phone_numbers(contacts_list_h associated_contacts)
             
          6. Get the default phone number.

            If a contact has multiple phone numbers, one of them is defined as the default phone number. A person also has a default phone number. The Contact Service provides the _contacts_person_number view for getting the default phone number of a person. In the default phone number record, the is_primary_default property value is true. The following example shows how to get the default phone number of a person by query.

            -static bool 
            +static bool
             _get_default_phone_number(contacts_record_h record, char **default_phone_number)
             {
                contacts_query_h query = NULL;
            @@ -599,12 +599,12 @@ _get_default_phone_number(contacts_record_h record, char **default_phone_number)
             }
          7. Get events by iterating the contacts list:
            -static void 
            +static void
             _print_events(contacts_list_h associated_contacts)
             {
                int error_code;
                contacts_record_h contact;
            -   if (NULL == associated_contacts) 
            +   if (NULL == associated_contacts)
                {
                   dlog_print(DLOG_ERROR, LOG_TAG, "associated_contacts is NULL");
             
            @@ -616,7 +616,7 @@ _print_events(contacts_list_h associated_contacts)
                   unsigned int count = 0;
             
                   error_code = contacts_record_get_child_record_count(contact, _contacts_contact.event, &count);
            -      if (CONTACTS_ERROR_NONE != error_code) 
            +      if (CONTACTS_ERROR_NONE != error_code)
                   {
                      dlog_print(DLOG_ERROR, LOG_TAG, "contacts_record_get_child_record_count(%d)", error_code);
             
            @@ -854,7 +854,7 @@ contacts_record_destroy(person, true);
          8. The callback function is called when the person data changes. The following example shows how to update person details in the callback function.

             static contacts_gl_person_data_t *_gl_person_data = ...
            -void 
            +void
             _person_changed_callback(const char *view_uri, void *user_data)
             {
                int error_code;
            @@ -941,16 +941,16 @@ error_code = contacts_db_get_all_records(_contacts_group._uri, 0, 0, &list);
             
             
          9. To iterate the list and read the records: - - - - - - - - - -
            Note
            Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
            + + + + + + + + + +
            Note
            Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
            1. To get the records from the list, use the contacts_list_get_current_record_p(), and contacts_list_next() or contacts_list_prev() functions. The following example gets the details of each record in the loop.

              @@ -985,7 +985,7 @@ while (contacts_list_get_current_record_p(list, &record) == CONTACTS_ERROR_N
            2. The memory for the record data is allocated, and the data is copied from the record by the functions listed in the following example:
              -typedef struct 
              +typedef struct
               _contacts_gl_group_data
               {
                  int id;
              @@ -994,7 +994,7 @@ _contacts_gl_group_data
                  char *ringtone_path;
               } contacts_gl_group_data_t;
               
              -static void 
              +static void
               _free_gl_group_data(contacts_gl_group_data_t *gl_group_data)
               {
                  if (NULL == gl_group_data)
              @@ -1006,7 +1006,7 @@ _free_gl_group_data(contacts_gl_group_data_t *gl_group_data)
                  free(gl_group_data);
               }
               
              -static contacts_gl_group_data_t* 
              +static contacts_gl_group_data_t*
               _create_gl_group_data(contacts_record_h record)
               {
                  contacts_gl_group_data_t *gl_group_data;
              @@ -1093,16 +1093,16 @@ contacts_query_destroy(query);
               
          10. To iterate the list and read the records: - - - - - - - - - -
            Note
            Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
            + + + + + + + + + +
            Note
            Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
            1. To get the records from the list, use the contacts_list_get_current_record_p(), and contacts_list_next() or contacts_list_prev() functions. Get the details of each record in the loop.

              @@ -1132,7 +1132,7 @@ while (contacts_list_get_current_record_p(list, &record) == CONTACTS_ERROR_N }
          11. The memory for the record data is allocated, and the data is copied from the record by the functions listed further on in this tutorial:

            -typedef struct 
            +typedef struct
             _contacts_gl_group_data
             {
                int id;
            @@ -1141,7 +1141,7 @@ _contacts_gl_group_data
                char *ringtone_path;
             } contacts_gl_group_data_t;
             
            -static void 
            +static void
             _free_gl_group_data(contacts_gl_group_data_t *gl_group_data)
             {
                if (NULL == gl_group_data)
            @@ -1153,7 +1153,7 @@ _free_gl_group_data(contacts_gl_group_data_t *gl_group_data)
                free(gl_group_data);
             }
             
            -static contacts_gl_group_data_t* 
            +static contacts_gl_group_data_t*
             _create_gl_group_data(contacts_record_h record)
             {
                contacts_gl_group_data_t *gl_group_data;
            @@ -1291,7 +1291,7 @@ contacts_query_destroy(query);
        2. Define the callback function to be called when the group data changes:
          static contacts_gl_group_data_t *_gl_group_data = ...
          -static void 
          +static void
           _group_changed_callback(const char *view_uri, void *user_data)
           {
              int error_code;
          @@ -1366,7 +1366,7 @@ error_code = contacts_vcard_parse_to_contact_foreach(temp_path, // File path of
           
           

          The vCard stream contains multiple contact objects. The callback function is called after parsing each contact. If you return false on the callback function, parsing stops.

          -static bool 
          +static bool
           _vcard_parse_cb(contacts_record_h contact, void *user_data)
           {
              if (NULL == contact)
          @@ -1407,7 +1407,7 @@ error_code = contacts_record_set_int(speeddial, _contacts_speeddial. number_id,
           
        - +

        Inserting a Speed Dial to the Database

        To insert a speed dial record:

        @@ -1415,7 +1415,7 @@ error_code = contacts_record_set_int(speeddial, _contacts_speeddial. number_id,
         int added_speeddial_id = -1;
         
        -error_code = contacts_db_insert_record(speeddial, &added_speeddial_id);	
        +error_code = contacts_db_insert_record(speeddial, &added_speeddial_id);
         
      6. @@ -1453,18 +1453,18 @@ error_code = contacts_db_get_all_records(_contacts_speeddial._uri, 0, 0, &li
      7. To iterate the list and read the records, you can get the records from the list using the contacts_list_get_current_record_p(), contacts_list_next(), or contacts_list_prev() function. Get the details of each record in the loop. - - - - - - - - - - -
        Note
        Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
        - + + + + + + + + + + +
        Note
        Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
        +
         contacts_record_h record;
        @@ -1499,7 +1499,7 @@ while (contacts_list_get_current_record_p(list, &record) == CONTACTS_ERROR_N
         		

        The memory for the record data is allocated, and the data is copied from the record by the functions shown in the following example:

        -typedef struct 
        +typedef struct
         _contacts_gl_speeddial_data
         {
            int speeddial_number;
        @@ -1508,7 +1508,7 @@ _contacts_gl_speeddial_data
            char *image_thumbnail_path;
         } contacts_gl_speeddial_data_t;
         
        -static void 
        +static void
         _free_gl_speeddial_data(contacts_gl_speeddial_data_t *gl_speeddial_data)
         {
            if (NULL == gl_speeddial_data)
        @@ -1520,7 +1520,7 @@ _free_gl_speeddial_data(contacts_gl_speeddial_data_t *gl_speeddial_data)
            free(gl_speeddial_data);
         }
         
        -static contacts_gl_speeddial_data_t* 
        +static contacts_gl_speeddial_data_t*
         _create_gl_speeddial_data(contacts_record_h record)
         {
            contacts_gl_speeddial_data_t *gl_speeddial_data;
        @@ -1602,7 +1602,7 @@ error_code = contacts_filter_add_int(filter, _contacts_speeddial.speeddial_numbe
         
      8. -
      9. Connect the query with the list: +
      10. Connect the query with the list:
         error_code = contacts_query_set_filter(query, filter);
         
        @@ -1611,7 +1611,7 @@ error_code = contacts_db_get_records_with_query(query, 0, 0, &list);
         	

        The third parameter refers to the limit of the results. If 0 is passed, there are no limits. Remember that after all operations, the list must be released.

      11. -
      12. Free the filter and query: +
      13. Free the filter and query:
         contacts_filter_destroy(filter);
         contacts_query_destroy(query);
        @@ -1622,16 +1622,16 @@ contacts_query_destroy(query);
         
         
      14. To iterate the list and read the records, you can get the records from the list using the contacts_list_get_current_record_p(), contacts_list_next(), or contacts_list_prev() function. Get the details of each record in the loop. - - - - - - - - - -
        Note
        Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
        + + + + + + + + + +
        Note
        Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
         contacts_record_h record;
        @@ -1663,7 +1663,7 @@ while (contacts_list_get_current_record_p(list, &record) == CONTACTS_ERROR_N
         

        The memory for the record data is allocated, and the data is copied from the record by the functions shown in the following example.

        -typedef struct 
        +typedef struct
         _contacts_gl_speeddial_data
         {
            int speeddial_number;
        @@ -1672,7 +1672,7 @@ _contacts_gl_speeddial_data
            char *image_thumbnail_path;
         } contacts_gl_speeddial_data_t;
         
        -static void 
        +static void
         _free_gl_speeddial_data(contacts_gl_speeddial_data_t *gl_speeddial_data)
         {
            if (NULL == gl_speeddial_data)
        @@ -1684,7 +1684,7 @@ _free_gl_speeddial_data(contacts_gl_speeddial_data_t *gl_speeddial_data)
            free(gl_speeddial_data);
         }
         
        -static contacts_gl_speeddial_data_t* 
        +static contacts_gl_speeddial_data_t*
         _create_gl_speeddial_data(contacts_record_h record)
         {
            contacts_gl_speeddial_data_t *gl_speeddial_data;
        @@ -1735,7 +1735,7 @@ contacts_list_destroy(list, true);
      15. To change the number ID of an existing speed dial:

          -
        1. Get the speed dial. +
        2. Get the speed dial.

          To modify a record, you need to have a handle (contacts_record_h type variable) to a memory object representing the record in the database. One of the ways to acquire it is to use the speed dial number:

           int speeddial_number = ... // Acquire speed dial number
          @@ -1777,7 +1777,7 @@ int speeddial_number = ... // Acquire speed dial number
           
           error_code = contacts_db_delete_record(_contacts_speeddial._uri, speeddial_number);
           
          - +

          Creating a Log

          @@ -1844,7 +1844,7 @@ if (error_code != CONTACTS_ERROR_NONE)

          To get all log records one by one, or to filter them by one of the properties:

            -
          1. Get a single log record: +
          2. Get a single log record:
            1. Use the contacts_db_get_record() function with the appropriate log_id:

              contacts_record_h log;
               int log_id = ... // Acquire log ID
              @@ -1867,16 +1867,16 @@ if (error_code != CONTACTS_ERROR_NONE)
               
               
            2. To iterate the list and read the records, you can get the records from the list using the contacts_list_get_current_record_p(), contacts_list_next(), or contacts_list_prev() function. Get the details of each record in the loop. - - - - - - - - - -
              Note
              Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
              + + + + + + + + + +
              Note
              Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
              @@ -1912,7 +1912,7 @@ while (contacts_list_get_current_record_p(list, &record) == CONTACTS_ERROR_N
               

              The memory for the record data is allocated, and the data is copied from the record by the functions listed further on in this tutorial.

              -typedef struct 
              +typedef struct
               _contacts_gl_log_data
               {
                  int id;
              @@ -1921,7 +1921,7 @@ _contacts_gl_log_data
                  int log_time;
               } contacts_gl_log_data_t;
               
              -static void 
              +static void
               _free_gl_log_data(contacts_gl_log_data_t *gl_log_data)
               {
                  if (NULL == gl_log_data)
              @@ -1931,7 +1931,7 @@ _free_gl_log_data(contacts_gl_log_data_t *gl_log_data)
                  free(gl_log_data);
               }
               
              -static contacts_gl_log_data_t* 
              +static contacts_gl_log_data_t*
               _create_gl_log_data(contacts_record_h record)
               {
                  contacts_gl_log_data_t *gl_log_data;
              @@ -1948,7 +1948,7 @@ _create_gl_log_data(contacts_record_h record)
                     return NULL;
                  }
                  if (CONTACTS_ERROR_NONE != contacts_record_get_str(record, _contacts_phone_log.address, &gl_log_data->address))
              -   {								
              +   {
                     dlog_print(DLOG_ERROR, LOG_TAG, "contacts record get string failed ");
                     _free_gl_log_data(gl_log_data);
               
              @@ -1993,8 +1993,8 @@ if (error_code != CONTACTS_ERROR_NONE)
                  dlog_print(DLOG_ERROR, LOG_TAG, "contacts query create failed: %x", error_code);
               
            3. - -
            4. Before getting the logs, filter the list. There is a possibility to filter based on various parameters. To create a filter: + +
            5. Before getting the logs, filter the list. There is a possibility to filter based on various parameters. To create a filter:
               contacts_filter_h filter = NULL;
               
              @@ -2003,7 +2003,7 @@ if (error_code != CONTACTS_ERROR_NONE)
                  dlog_print(DLOG_ERROR, LOG_TAG, "contacts filter create failed: %x", error_code);
               
            6. - +
            7. Add a condition, such as the log type.

              The following example retrieves only those logs which type is CONTACTS_PLOG_TYPE_VOICE_INCOMING.

              @@ -2011,7 +2011,7 @@ error_code = contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTA
               if (error_code != CONTACTS_ERROR_NONE)
                  dlog_print(DLOG_ERROR, LOG_TAG, "contacts filter add integer failed: %x", error_code);
               
              - +

              To use multiple conditions, add an operator between them:

               error_code = contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
              @@ -2022,8 +2022,8 @@ if (error_code != CONTACTS_ERROR_NONE)
                  dlog_print(DLOG_ERROR, LOG_TAG, "contacts filter add integer failed: %x", error_code);
               
            8. - -
            9. Connect the query with the list: + +
            10. Connect the query with the list:
               error_code = contacts_query_set_filter(query, filter);
               if (error_code != CONTACTS_ERROR_NONE)
              @@ -2035,8 +2035,8 @@ if (error_code != CONTACTS_ERROR_NONE)
               

              The third parameter refers to the limit of the results. If 0 is passed, there are no limits. After all operations, release the list.

            11. - -
            12. Free the filter and query: + +
            13. Free the filter and query:
               contacts_filter_destroy(filter);
               contacts_query_destroy(query);
              @@ -2048,16 +2048,16 @@ contacts_query_destroy(query);
               
            14. To iterate the list and read the records, use the contacts_list_get_current_record_p(), contacts_list_next(), or contacts_list_prev() function. Get the details of each record in the loop. - - - - - - - - - -
              Note
              Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
              + + + + + + + + + +
              Note
              Some functions have the _p postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.
               contacts_record_h record;
              @@ -2089,7 +2089,7 @@ while (contacts_list_get_current_record_p(list, &record) == CONTACTS_ERROR_N
               

              The memory for the record data is allocated, and the data is copied from the record by the functions listed further on in this tutorial.

              -typedef struct 
              +typedef struct
               _contacts_gl_log_data
               {
                  int id;
              @@ -2098,7 +2098,7 @@ _contacts_gl_log_data
                  int log_time;
               } contacts_gl_log_data_t;
               
              -static void 
              +static void
               _free_gl_log_data(contacts_gl_log_data_t *gl_log_data)
               {
                  if (NULL == gl_log_data)
              @@ -2108,7 +2108,7 @@ _free_gl_log_data(contacts_gl_log_data_t *gl_log_data)
                  free(gl_log_data);
               }
               
              -static contacts_gl_log_data_t* 
              +static contacts_gl_log_data_t*
               _create_gl_log_data(contacts_record_h record)
               {
                  contacts_gl_log_data_t *gl_log_data;
              @@ -2125,7 +2125,7 @@ _create_gl_log_data(contacts_record_h record)
                     return NULL;
                  }
                  if (CONTACTS_ERROR_NONE != contacts_record_get_str(record, _contacts_phone_log.address, &gl_log_data->address))
              -   {								
              +   {
                     dlog_print(DLOG_ERROR, LOG_TAG, "contacts record get string failed ");
                     _free_gl_log_data(gl_log_data);
               
              @@ -2263,8 +2263,8 @@ free(d_name);
               contacts_record_h child_record;
               contacts_record_get_child_record_at_p(record, _contacts_contact.name, 0, &child_record);
               // In the child_record, you have the record form name view
              -char *f_name;
              -contacts_record_get_str(record, _contacts_name.first_name, f_name);
              +char *f_name = NULL;
              +contacts_record_get_str(child_record, _contacts_name.first_name, &f_name);
               free(f_name);
               
            15. @@ -2276,7 +2276,7 @@ free(f_name); contacts_record_h parent_record; int parent_id; contacts_record_get_int(record, _contacts_name.contact_id, &parent_id); -contacts_db_get_child_record(_contacts_contact._uri, parent_id, &parent_record); +contacts_db_get_record(_contacts_contact._uri, parent_id, &parent_record); // In the parent_record, get bool bool h_email; contacts_record_get_bool(parent_record, _contacts_contact.has_email, &h_email); @@ -2291,7 +2291,7 @@ contacts_record_get_bool(parent_record, _contacts_contact.has_email, &h_emai gldata = _create_gl_data(record); char * number = gldata->number; -typedef struct +typedef struct _contact_gl_data {    int id; @@ -2357,7 +2357,7 @@ _create_gl_data(contacts_record_h r_contact)
              • To get the name details, get the _contacts_contact.name (representing the child) from the r_contact parent. Both structures have the contacts_record_h type. After obtaining a child record, get the desired data from it using the contacts_record_get_str() function.

                -static bool 
                +static bool
                 _get_contact_last(contacts_record_h r_contact, char **last)
                 {
                    contacts_record_h r_name;
                @@ -2372,7 +2372,7 @@ _get_contact_last(contacts_record_h r_contact, char **last)
                 
              • Obtain the record ID directly from the parent record. An ID is a unique number representing the record key in the database. You can manipulate a record with functions, such as contacts_db_get_record() or contacts_db_delete_records(), if you know their ID.

                -static bool 
                +static bool
                 _get_contact_id(contacts_record_h r_contact, int *id)
                 {
                    int error_code;
                @@ -2386,7 +2386,7 @@ _get_contact_id(contacts_record_h r_contact, int *id)
                 
              • To get a contact number, check whether it exists using the contacts_record_get_bool() function. If it exists, use the various Query and Filter functions from the Contacts API to make a query to get a list. At the end, free any data returned by a function not containing the _p suffix.

                • Get a list of all numbers and filter the list to get the default:
                  -static bool 
                  +static bool
                   _get_contact_number(contacts_record_h r_contact, char **number)
                   {
                      int id;
                  @@ -2432,7 +2432,7 @@ _get_contact_number(contacts_record_h r_contact, char **number)
                   
                • Directly access the default number:

                  -static bool 
                  +static bool
                   _get_contact_number(contacts_record_h r_contact, char **number)
                   {
                      int error_code;
                  @@ -2447,12 +2447,24 @@ _get_contact_number(contacts_record_h r_contact, char **number)
                   
                         return true;
                      }
                  +   int i;
                  +   unsigned int count = 0;
                  +   bool is_default = false;
                  +   error_code = contacts_record_get_child_record_count(contact, _contacts_contact.number, &count);
                   
                  -   error_code = contacts_record_get_child_record_at_p(r_contact, _contacts_contact.number, 0, &r_number);
                  -
                  -   error_code = contacts_record_get_str(r_number, _contacts_number.number, number);
                  +   for (i = 0; i < count; i++)
                  +   {
                  +      error_code = contacts_record_get_child_record_at_p(r_contact, _contacts_contact.number, i, &r_number);
                  +      error_code = contacts_record_get_bool(r_number, _contacts_number.is_default, &is_default);
                  +      if(is_default)
                  +      {
                  +         error_code = contacts_record_get_str(r_number, _contacts_number.number, number);
                  +         return true;
                  +      }
                  +   }
                  +   *number = NULL;
                   
                  -   return true;
                  +   return false;
                   }
                   

                  To get a second number, change the third parameter (contacts_record_get_child_record_at_p) from 0 to 1.

              • @@ -2461,7 +2473,7 @@ _get_contact_number(contacts_record_h r_contact, char **number)
              • Obtain an image directly from the parent record:

                -static bool 
                +static bool
                 _get_contact_image(contacts_record_h r_contact, char **image_path)
                 {
                    int error_code;
                @@ -2477,7 +2489,7 @@ _get_contact_image(contacts_record_h r_contact, char **image_path)
                 
              • Get the first name as the last name:

                -static bool 
                +static bool
                 _get_contact_first(contacts_record_h r_contact, char **first)
                 {
                    contacts_record_h r_name;
                @@ -2676,7 +2688,7 @@ while (contacts_list_get_current_record_p(list, &record) == 0)
                 {
                    int record_id;
                    contacts_record_h c_record;
                -   contacts_record_get_int(record, _contacts_name._uri, &contact_id);
                +   contacts_record_get_int(record, _contacts_name.contact_id, &contact_id);
                    contacts_db_get_record(_contacts_contact._uri, contact_id, &c_record);
                    gldata = _create_gl_data(c_record);
                 
                @@ -2870,13 +2882,13 @@ contacts_setting_set_name_sorting_order(CONTACTS_NAME_SORTING_ORDER_FIRSTLAST);
                 
                1. Register callbacks with the contacts_setting_add_name_display_order_changed_cb() and contacts_setting_add_name_sorting_order_changed_cb() functions.
                2. Define the callbacks themselves:
                  -static void 
                  +static void
                   display_changed_cb(contacts_name_display_order_e name_display_order, void *user_data)
                   {
                      dlog_print(DLOG_DEBUG, LOG_TAG, "changed display order: %s", name_display_order==CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST?"CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST":"CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST");
                   }
                   
                  -static void 
                  +static void
                   sorting_changed_cb(contacts_name_sorting_order_e name_display_order, void *user_data)
                   {
                      dlog_print(DLOG_DEBUG, LOG_TAG, "changed sorting order: %s", name_display_order==CONTACTS_NAME_SORTING_ORDER_FIRSTLAST?"CONTACTS_NAME_SORTING_ORDER_FIRSTLAST":"CONTACTS_NAME_SORTING_ORDER_LASTFIRST");
                  @@ -2925,7 +2937,7 @@ char * vcard_stream;
                   contacts_list_h contacts_list;
                   int err = contacts_vcard_parse_to_contacts(vcard_stream, contacts_list);
                   
                  -while (contacts_list_get_current_record_p(list_import, &record) == 0) 
                  +while (contacts_list_get_current_record_p(list_import, &record) == 0)
                   {
                      // Get next records from file
                      err = contacts_list_next(list_import);
                  @@ -2936,7 +2948,7 @@ err = contacts_list_destroy(list_import, true);
                   

                  You can also use the contacts_vcard_parse_to_contact_foreach() function. With this function, you have to get the file content manually, and it needs a callback.

                  -bool 
                  +bool
                   contacts_vcard_cb(contacts_record_h record, void *user_data)
                   {
                      // Here you have a record
                  @@ -2957,7 +2969,7 @@ contacts_vcard_cb(contacts_record_h record, void *user_data)
                   int internal_storage_id;
                   char *vcf_path = NULL;
                   
                  -static bool 
                  +static bool
                   storage_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
                   {
                      if (type == STORAGE_TYPE_INTERNAL)
                  @@ -2970,7 +2982,7 @@ storage_cb(int storage_id, storage_type_e type, storage_state_e state, const cha
                      return true;
                   }
                   
                  -void 
                  +void
                   _get_storage_path()
                   {
                      int error_code = 0;
                  @@ -2985,7 +2997,7 @@ _get_storage_path()
                      }
                   }
                   
                  -void 
                  +void
                   _import_vcard()
                   {
                      int path_len = 0;
                  @@ -3008,7 +3020,7 @@ _import_vcard()
                            continue;
                         char * filepath = malloc(strlen(vcf_path)+strlen(pDirent->d_name)+4);
                         sprintf(filepath, "%s/%s", vcf_path, pDirent->d_name);
                  -        
                  +
                         // Full path to file available through filepath string
                   
                         free(filepath);
                  @@ -3028,13 +3040,13 @@ if (bufsize < 1)
                   
                   char * vcard_stream = malloc(sizeof(char) * (bufsize));
                   memset(vcard_stream, '\0', sizeof(vcard_stream));
                  -if (fp != NULL) 
                  +if (fp != NULL)
                   {
                      char str[200];
                      while(fgets(str, 200, fp) != NULL)
                         sprintf(vcard_stream+strlen(vcard_stream), "%s", str);
                  -   fclose(fp); 
                  -} 
                  +   fclose(fp);
                  +}
                   else
                      // Error handling
                   int err = contacts_vcard_parse_to_contacts(vcard_stream, contacts_list);
                  @@ -3044,7 +3056,7 @@ free(vcard_stream);
                   
                3. You can also use the contacts_vcard_parse_to_contact_foreach() function. It requires a callback and retrieves the file path instead of a file stream.

                  -bool 
                  +bool
                   contacts_vcard_cb(contacts_record_h record, void *user_data)
                   {
                      // Here you have a record
                  @@ -3069,7 +3081,7 @@ contacts_list_h list_import;
                   contacts_record_h record;
                   err = contacts_vcard_parse_to_contacts(content, &list_import);
                   
                  -while (contacts_list_get_current_record_p(list_import, &record) == 0) 
                  +while (contacts_list_get_current_record_p(list_import, &record) == 0)
                   {
                      int id = -1;
                      err = contacts_db_insert_record(record, &id); // Add to list
                  @@ -3079,9 +3091,9 @@ while (contacts_list_get_current_record_p(list_import, &record) == 0)
                   
                   DIR *dir = opendir(folder);
                   struct dirent *pDirent = NULL;
                  -if (dir) 
                  +if (dir)
                   {
                  -   while ((pDirent = readdir(dir)) != NULL) 
                  +   while ((pDirent = readdir(dir)) != NULL)
                      {
                         if (pDirent->d_type != DT_REG)
                            continue;
                  @@ -3104,19 +3116,19 @@ if (dir)
                            // Error handling
                         int bufsize = ftell(fp);
                         rewind(fp);
                  -      dlog_print(DLOG_DEBUG, LOG_TAG, "file size: %i", bufsize); 
                  +      dlog_print(DLOG_DEBUG, LOG_TAG, "file size: %i", bufsize);
                         if (bufsize < 1)
                            return 1;
                   
                         char * vcard_stream = malloc(sizeof(char) * (bufsize));
                         memset(vcard_stream, '\0', sizeof(vcard_stream));
                  -      if (fp != NULL) 
                  +      if (fp != NULL)
                         {
                            char str[150];
                            while(fgets(str, 150, fp) != NULL)
                               sprintf(vcard_stream+strlen(vcard_stream), "%s", str);
                            fclose(fp);
                  -      } 
                  +      }
                         else
                            return 1;
                   
                  @@ -3126,7 +3138,7 @@ if (dir)
                         if (err != 0)
                            dlog_print(DLOG_ERROR, LOG_TAG, "contacts_vcard_parse_to_contacts failed: %d", err);
                         free(vcard_stream);
                  -      while (contacts_list_get_current_record_p(list_import, &record) == 0) 
                  +      while (contacts_list_get_current_record_p(list_import, &record) == 0)
                         {
                            int id = -1;
                            err = contacts_db_insert_record(record, &id); // Add to list
                  @@ -3190,7 +3202,7 @@ err = contacts_db_get_all_records(_contacts_contact._uri, 0, 0, &list);
                   contacts_record_h record;
                   FILE * file = fopen(file_path, "w");
                   
                  -while (contacts_list_get_current_record_p(list, &record) == 0) 
                  +while (contacts_list_get_current_record_p(list, &record) == 0)
                   {
                      err = contacts_vcard_make_from_contact(record, &vcard_stream);
                      // Save to file
                  @@ -3225,4 +3237,4 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga
                   
                   
                   
                  -
                  \ No newline at end of file
                  +
                  -- 
                  2.7.4