Re: [evolution-patches] Bug 45210 - LDAP PostalAddress compliance patch for evolution-data-server, contacts
- From: Edward Rudd <eddie omegaware com>
- To: Chris Toshok <toshok ximian com>
- Cc: evolution-patches lists ximian com
- Subject: Re: [evolution-patches] Bug 45210 - LDAP PostalAddress compliance patch for evolution-data-server, contacts
- Date: Mon, 03 May 2004 17:10:42 -0500
On Mon, 2004-05-03 at 16:17, Chris Toshok wrote:
> > >
> > Well, from tacking down what e_contact_get does, returns a gpointer
> > retrieved from g_object_get, and not a copy of the structure.
>
> e_contact_get on string fields (like the address labels) returns
> allocated space for the string. Trust me, I wrote the code.
> e_contact_get_const is what you want to use if you don't want the copy,
> but in this case you do want the copy - just not the extra g_strdup.
>
OK, then the functions email_ber, homephone_ber, businessphone_ber, and
the like all need to be updated as they use e_contact_get instead of
e_contact_get_const and then g_strdup the results into the berval *.
I've attached an updated patch, that removed the temp char *, and also
uses e-contact_get_const in the address_compare function.
> > And all
> > the other *_ber functions for complex type handling never touch the data
> > retrieved from e_contact_get and type them as const char *, and they
> > always make a copy which they place in the (berval*)->bv-val. Therefore
> > no leak is happening at all as I am putting the fixed temp var directly
> > into the berval stucture.
>
> No, therefore the other *_ber functions (and lots of other functions in
> there) are leaking :) look at email_compare. it uses (correctly)
> e_contact_get_const.
>
> Chris
--
Edward Rudd <eddie omegaware com>
Website http://www.outoforder.cc/
Index: addressbook/backends/ldap/e-book-backend-ldap.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/backends/ldap/e-book-backend-ldap.c,v
retrieving revision 1.17
diff -u -3 -p -r1.17 e-book-backend-ldap.c
--- a/addressbook/backends/ldap/e-book-backend-ldap.c 23 Apr 2004 08:42:22 -0000 1.17
+++ b/addressbook/backends/ldap/e-book-backend-ldap.c 3 May 2004 22:09:22 -0000
@@ -163,6 +163,18 @@ static void category_populate (EContact
struct berval** category_ber (EContact *contact);
static gboolean category_compare (EContact *contact1, EContact *contact2);
+static void home_address_populate(EContact * card, char **values);
+struct berval **home_address_ber(EContact * card);
+static gboolean home_address_compare(EContact * ecard1, EContact * ecard2);
+
+static void work_address_populate(EContact * card, char **values);
+struct berval **work_address_ber(EContact * card);
+static gboolean work_address_compare(EContact * ecard1, EContact * ecard2);
+
+static void other_address_populate(EContact * card, char **values);
+struct berval **other_address_ber(EContact * card);
+static gboolean other_address_compare(EContact * ecard1, EContact * ecard2);
+
static void photo_populate (EContact *contact, struct berval **ber_values);
static void cert_populate (EContact *contact, struct berval **ber_values);
@@ -235,9 +247,9 @@ struct prop_info {
E_STRING_PROP (E_CONTACT_ASSISTANT, "assistantName"),
/* addresses */
- STRING_PROP (E_CONTACT_ADDRESS_LABEL_WORK, "postalAddress"),
- STRING_PROP (E_CONTACT_ADDRESS_LABEL_HOME, "homePostalAddress"),
- E_STRING_PROP (E_CONTACT_ADDRESS_LABEL_OTHER, "otherPostalAddress"),
+ COMPLEX_PROP (E_CONTACT_ADDRESS_LABEL_WORK, "postalAddress", work_address_populate, work_address_ber, work_address_compare),
+ COMPLEX_PROP (E_CONTACT_ADDRESS_LABEL_HOME, "homePostalAddress", home_address_populate, home_address_ber, home_address_compare),
+ E_COMPLEX_PROP(E_CONTACT_ADDRESS_LABEL_OTHER, "otherPostalAddress", other_address_populate, other_address_ber, other_address_compare),
/* photos */
BINARY_PROP (E_CONTACT_PHOTO, "jpegPhoto", photo_populate, NULL/*XXX*/, NULL/*XXX*/),
@@ -2228,6 +2240,117 @@ category_compare (EContact *contact1, EC
}
static void
+address_populate(EContact * card, char **values, EContactField field)
+{
+ if (values[0]) {
+ char *temp = g_strdup(values[0]);
+ char *i;
+ for (i = temp; *i != '\0'; i++) {
+ if (*i == '$') {
+ *i = '\n';
+ }
+ }
+ e_contact_set(card, field, temp);
+ g_free(temp);
+ }
+}
+
+static void
+home_address_populate(EContact * card, char **values)
+{
+ address_populate(card, values, E_CONTACT_ADDRESS_LABEL_HOME);
+}
+
+static void
+work_address_populate(EContact * card, char **values)
+{
+ address_populate(card, values, E_CONTACT_ADDRESS_LABEL_WORK);
+}
+
+static void
+other_address_populate(EContact * card, char **values)
+{
+ address_populate(card, values, E_CONTACT_ADDRESS_LABEL_OTHER);
+}
+
+struct berval **
+address_ber(EContact * card, EContactField field)
+{
+ struct berval **result = NULL;
+ char *address, *i;
+
+ address = e_contact_get(card, field);
+ if (address) {
+ for (i = address; *i != '\0'; i++) {
+ if (*i == '\n') {
+ *i = '$';
+ }
+ }
+
+ result = g_new(struct berval *, 2);
+ result[0] = g_new(struct berval, 1);
+ result[0]->bv_val = address;
+ result[0]->bv_len = strlen(address);
+
+ result[1] = NULL;
+ }
+ return result;
+}
+
+struct berval **
+home_address_ber(EContact * card)
+{
+ return address_ber(card, E_CONTACT_ADDRESS_LABEL_HOME);
+}
+
+struct berval **
+work_address_ber(EContact * card)
+{
+ return address_ber(card, E_CONTACT_ADDRESS_LABEL_WORK);
+}
+
+struct berval **
+other_address_ber(EContact * card)
+{
+ return address_ber(card, E_CONTACT_ADDRESS_LABEL_OTHER);
+}
+
+static gboolean
+address_compare(EContact * ecard1, EContact * ecard2, EContactField field)
+{
+ const char *address1, *address2;
+
+ gboolean equal;
+ address1 = e_contact_get_const(ecard1, field);
+ address2 = e_contact_get_const(ecard2, field);
+
+ if (address1 && address2)
+ equal = !strcmp(address1, address2);
+ else
+ equal = (!!address1 == !!address2);
+
+ return equal;
+}
+
+static gboolean
+home_address_compare(EContact * ecard1, EContact * ecard2)
+{
+ return address_compare(ecard1, ecard2, E_CONTACT_ADDRESS_LABEL_HOME);
+}
+
+static gboolean
+work_address_compare(EContact * ecard1, EContact * ecard2)
+{
+ return address_compare(ecard1, ecard2, E_CONTACT_ADDRESS_LABEL_WORK);
+}
+
+static gboolean
+other_address_compare(EContact * ecard1, EContact * ecard2)
+{
+ return address_compare(ecard1, ecard2, E_CONTACT_ADDRESS_LABEL_OTHER);
+}
+
+static void
photo_populate (EContact *contact, struct berval **ber_values)
{
if (ber_values && ber_values[0]) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]