[evolution-ews] Fix parsing Ews physical address.
- From: Chenthill Palanisamy <pchen src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] Fix parsing Ews physical address.
- Date: Thu, 23 Jun 2011 08:35:55 +0000 (UTC)
commit 9690fbda88aa2b6e37c87d2834364b381e7d5de5
Author: Chenthill Palanisamy <pchenthill novell com>
Date: Thu Jun 23 13:04:41 2011 +0530
Fix parsing Ews physical address.
src/addressbook/e-book-backend-ews.c | 26 +++++++++++--
src/server/e-ews-item.c | 67 +++++++++++++++++++++++++++++-----
src/server/e-ews-item.h | 3 +-
3 files changed, 82 insertions(+), 14 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index e690f1e..2af2db4 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -184,13 +184,31 @@ ebews_populate_phone_numbers (EContact *contact, EEwsItem *item)
}
static void
+copy_ews_address_to_contact_address ( EContactAddress *contact_addr, const EwsAddress *address)
+{
+ contact_addr->address_format = NULL;
+ contact_addr->po = NULL;
+ contact_addr->street = g_strdup (address->street);
+ contact_addr->ext = NULL;
+ contact_addr->locality = g_strdup (address->city);
+ contact_addr->region = g_strdup (address->state);
+ contact_addr->code = g_strdup (address->postal_code);
+ contact_addr->country = g_strdup (address->country);
+}
+static void
set_address (EContact *contact, EContactField field, EEwsItem *item, const gchar *item_field)
{
- const gchar *add;
+ const EwsAddress *address;
- add = e_ews_item_get_physical_address (item, item_field);
- if (add && *add)
- e_contact_set (contact, field, add);
+ address = e_ews_item_get_physical_address (item, item_field);
+ if (address) {
+ EContactAddress *addr;
+
+ addr = g_new0 (EContactAddress, 1);
+ copy_ews_address_to_contact_address (addr, address);
+ e_contact_set (contact, field, addr);
+ e_contact_address_free (addr);
+ }
}
static void
diff --git a/src/server/e-ews-item.c b/src/server/e-ews-item.c
index fd42ea9..7aaace7 100644
--- a/src/server/e-ews-item.c
+++ b/src/server/e-ews-item.c
@@ -177,6 +177,8 @@ static void ews_item_free_mailbox (EwsMailbox *mb);
static void ews_item_free_attendee (EwsAttendee *attendee);
static void ews_free_contact_fields (struct _EEwsContactFields *con_fields);
+typedef gpointer (* EwsGetValFunc) (ESoapParameter *param);
+
static void
e_ews_item_dispose (GObject *object)
{
@@ -589,18 +591,50 @@ parse_complete_name (struct _EEwsContactFields *con_fields, ESoapParameter *para
con_fields->complete_name = cn;
}
+static gpointer
+ews_get_physical_address (ESoapParameter *param)
+{
+ ESoapParameter *subparam;
+ EwsAddress *address;
+
+ address = g_new0 (EwsAddress, 1);
+
+ subparam = e_soap_parameter_get_first_child_by_name (param, "Street");
+ if (subparam)
+ address->street = e_soap_parameter_get_string_value (subparam);
+
+ subparam = e_soap_parameter_get_first_child_by_name (param, "City");
+ if (subparam)
+ address->city = e_soap_parameter_get_string_value (subparam);
+
+ subparam = e_soap_parameter_get_first_child_by_name (param, "State");
+ if (subparam)
+ address->state = e_soap_parameter_get_string_value (subparam);
+
+ subparam = e_soap_parameter_get_first_child_by_name (param, "Country");
+ if (subparam)
+ address->country = e_soap_parameter_get_string_value (subparam);
+
+ subparam = e_soap_parameter_get_first_child_by_name (param, "PostalCode");
+ if (subparam)
+ address->postal_code = e_soap_parameter_get_string_value (subparam);
+
+ return address;
+}
+
static void
-parse_entries (GHashTable *hash_table, ESoapParameter *param)
+parse_entries (GHashTable *hash_table, ESoapParameter *param, EwsGetValFunc get_val_func)
{
ESoapParameter *subparam;
for (subparam = e_soap_parameter_get_first_child_by_name (param, "Entry");
subparam != NULL;
subparam = e_soap_parameter_get_next_child_by_name (subparam, "Entry")) {
- gchar *key, *value;
+ gchar *key;
+ gpointer value;
key = e_soap_parameter_get_property (subparam, "Key");
- value = e_soap_parameter_get_string_value (subparam);
+ value = get_val_func (subparam);
if (value)
g_hash_table_insert (hash_table, key, value);
@@ -610,6 +644,21 @@ parse_entries (GHashTable *hash_table, ESoapParameter *param)
}
static void
+ews_free_physical_address (gpointer value)
+{
+ EwsAddress *address = (EwsAddress *) value;
+
+ if (address) {
+ g_free (address->street);
+ g_free (address->city);
+ g_free (address->state);
+ g_free (address->country);
+ g_free (address->postal_code);
+ g_free (address);
+ }
+}
+
+static void
parse_contact_field (EEwsItem *item, const gchar *name, ESoapParameter *subparam)
{
EEwsItemPrivate *priv = item->priv;
@@ -625,13 +674,13 @@ parse_contact_field (EEwsItem *item, const gchar *name, ESoapParameter *subparam
priv->contact_fields->company_name = e_soap_parameter_get_string_value (subparam);
} else if (!g_ascii_strcasecmp (name, "EmailAddresses")) {
priv->contact_fields->email_addresses = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- parse_entries (priv->contact_fields->email_addresses, subparam);
+ parse_entries (priv->contact_fields->email_addresses, subparam, (EwsGetValFunc) e_soap_parameter_get_string_value);
} else if (!g_ascii_strcasecmp (name, "PhysicalAddresses")) {
- priv->contact_fields->physical_addresses = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- parse_entries (priv->contact_fields->physical_addresses, subparam);
+ priv->contact_fields->physical_addresses = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, ews_free_physical_address);
+ parse_entries (priv->contact_fields->physical_addresses, subparam, ews_get_physical_address);
} else if (!g_ascii_strcasecmp (name, "PhoneNumbers")) {
priv->contact_fields->phone_numbers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- parse_entries (priv->contact_fields->phone_numbers, subparam);
+ parse_entries (priv->contact_fields->phone_numbers, subparam, (EwsGetValFunc) e_soap_parameter_get_string_value);
} else if (!g_ascii_strcasecmp (name, "AssistantName")) {
priv->contact_fields->assistant_name = e_soap_parameter_get_string_value (subparam);
} else if (!g_ascii_strcasecmp (name, "Birthday")) {
@@ -644,7 +693,7 @@ parse_contact_field (EEwsItem *item, const gchar *name, ESoapParameter *subparam
priv->contact_fields->department = e_soap_parameter_get_string_value (subparam);
} else if (!g_ascii_strcasecmp (name, "ImAddresses")) {
priv->contact_fields->im_addresses = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- parse_entries (priv->contact_fields->im_addresses, subparam);
+ parse_entries (priv->contact_fields->im_addresses, subparam, (EwsGetValFunc) e_soap_parameter_get_string_value);
} else if (!g_ascii_strcasecmp (name, "JobTitle")) {
priv->contact_fields->job_title = e_soap_parameter_get_string_value (subparam);
} else if (!g_ascii_strcasecmp (name, "Manager")) {
@@ -1227,7 +1276,7 @@ e_ews_item_get_email_address (EEwsItem *item, const gchar *field)
*
* Returns:
**/
-const gchar *
+const EwsAddress *
e_ews_item_get_physical_address (EEwsItem *item, const gchar *field)
{
g_return_val_if_fail (E_IS_EWS_ITEM(item), NULL);
diff --git a/src/server/e-ews-item.h b/src/server/e-ews-item.h
index f4982bd..b965596 100644
--- a/src/server/e-ews-item.h
+++ b/src/server/e-ews-item.h
@@ -170,7 +170,8 @@ const gchar * e_ews_item_get_fileas (EEwsItem *item);
const EwsCompleteName *
e_ews_item_get_complete_name (EEwsItem *item);
const gchar * e_ews_item_get_email_address (EEwsItem *item, const gchar *type);
-const gchar * e_ews_item_get_physical_address (EEwsItem *item, const gchar *type);
+const EwsAddress *
+ e_ews_item_get_physical_address (EEwsItem *item, const gchar *type);
const gchar * e_ews_item_get_phone_number (EEwsItem *item, const gchar *type);
const gchar * e_ews_item_get_im_address (EEwsItem *item, const gchar *type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]