From 37f85438b274e6285335f8484031f06522ce1fe2 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Wed, 9 Aug 2000 05:12:19 +0000 Subject: use x-evolution-any-field. 2000-08-08 Chris Toshok * gui/component/e-addressbook-model.c (e_addressbook_model_init): use x-evolution-any-field. * gui/component/addressbook.c (search_entry_activated): use x-evolution-any-field. (change_view_type): same. * gui/minicard/e-minicard-view.c (e_minicard_view_init): set query to x-evolution-any-field. * backend/pas/pas-backend-ldap.c (func_contains): support x-evolution-any-field for matching any evolution supported field. * backend/pas/pas-backend-file.c (compare_email): switch to using ECardSimple calls. (compare_phone): same. (compare_address): same. (entry_compare): switch to using ECardSimple calls, and support a 'x-evolution-any-field' wildcard field. (vcard_matches_search): use an ECardSimple. svn path=/trunk/; revision=4626 --- addressbook/backend/pas/pas-backend-ldap.c | 115 +++++++++++++++++++---------- 1 file changed, 78 insertions(+), 37 deletions(-) (limited to 'addressbook/backend/pas/pas-backend-ldap.c') diff --git a/addressbook/backend/pas/pas-backend-ldap.c b/addressbook/backend/pas/pas-backend-ldap.c index 5257177328..3968648972 100644 --- a/addressbook/backend/pas/pas-backend-ldap.c +++ b/addressbook/backend/pas/pas-backend-ldap.c @@ -314,6 +314,36 @@ pas_backend_ldap_process_get_cursor (PASBackend *backend, cursor); } +static void +construct_email_list(ECardSimple *card, const char *prop, char **values) +{ + int i; + + for (i = 0; values[i] && i < 3; i ++) { + e_card_simple_set_email (card, i, values[i]); + } +} + +struct prop_info { + ECardSimpleField field_id; + char *query_prop; + char *ldap_attr; +#define PROP_TYPE_NORMAL 0x01 +#define PROP_TYPE_LIST 0x02 +#define PROP_TYPE_LISTITEM 0x03 + int prop_type; + void (*construct_list_func)(ECardSimple *card, const char *prop, char **values); +} prop_info_table[] = { + /* field_id, query prop, ldap attr, type, list construct function */ + { E_CARD_SIMPLE_FIELD_FULL_NAME, "full_name", "cn", PROP_TYPE_NORMAL, NULL }, + { E_CARD_SIMPLE_FIELD_TITLE, "title", "title", PROP_TYPE_NORMAL, NULL }, + { E_CARD_SIMPLE_FIELD_ORG, "org", "o", PROP_TYPE_NORMAL, NULL }, + { E_CARD_SIMPLE_FIELD_PHONE_PRIMARY, "phone", "telephonenumber", PROP_TYPE_NORMAL, NULL }, + { 0 /* unused */, "email", "mail", PROP_TYPE_LIST, construct_email_list }, +}; + +static int num_prop_infos = sizeof(prop_info_table) / sizeof(prop_info_table[0]); + static ESExpResult * func_and(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) { @@ -415,18 +445,59 @@ func_contains(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data && argv[1]->type == ESEXP_RES_STRING) { char *propname = argv[0]->value.string; char *str = argv[1]->value.string; - char *ldap_attr = query_prop_to_ldap(propname); gboolean one_star = FALSE; if (strlen(str) == 0) one_star = TRUE; - if (ldap_attr) - *list = g_list_prepend(*list, - g_strdup_printf("(%s=*%s%s)", - ldap_attr, - str, - one_star ? "" : "*")); + if (!strcmp (propname, "x-evolution-any-field")) { + int i; + int query_length; + char *big_query; + char *header, *footer; + char *match_str; + + header = g_malloc0((num_prop_infos - 1) * 2 + 1); + footer = g_malloc0(num_prop_infos + 1); + for (i = 0; i < num_prop_infos - 1; i ++) { + strcat (header, "(|"); + strcat (footer, ")"); + } + + match_str = g_strdup_printf("=*%s%s)", + str, one_star ? "" : "*"); + + query_length = strlen (header); + + for (i = 0; i < num_prop_infos; i ++) { + query_length += 1 + strlen(prop_info_table[i].ldap_attr) + strlen (match_str); + } + + big_query = g_malloc0(query_length + 1); + strcat (big_query, header); + for (i = 0; i < num_prop_infos; i ++) { + strcat (big_query, "("); + strcat (big_query, prop_info_table[i].ldap_attr); + strcat (big_query, match_str); + } + strcat (big_query, footer); + + *list = g_list_prepend(*list, big_query); + + g_free (match_str); + g_free (header); + g_free (footer); + } + else { + char *ldap_attr = query_prop_to_ldap(propname); + + if (ldap_attr) + *list = g_list_prepend(*list, + g_strdup_printf("(%s=*%s%s)", + ldap_attr, + str, + one_star ? "" : "*")); + } } r = e_sexp_result_new(ESEXP_RES_BOOL); @@ -578,36 +649,6 @@ pas_backend_ldap_build_query (gchar *query) return retval; } -static void -construct_email_list(ECardSimple *card, const char *prop, char **values) -{ - int i; - - for (i = 0; values[i] && i < 3; i ++) { - e_card_simple_set_email (card, i, values[i]); - } -} - -struct prop_info { - ECardSimpleField field_id; - char *query_prop; - char *ldap_attr; -#define PROP_TYPE_NORMAL 0x01 -#define PROP_TYPE_LIST 0x02 -#define PROP_TYPE_LISTITEM 0x03 - int prop_type; - void (*construct_list_func)(ECardSimple *card, const char *prop, char **values); -} prop_info_table[] = { - /* field_id, query prop, ldap attr, type, list construct function */ - { E_CARD_SIMPLE_FIELD_FULL_NAME, "full_name", "cn", PROP_TYPE_NORMAL, NULL }, - { E_CARD_SIMPLE_FIELD_TITLE, "title", "title", PROP_TYPE_NORMAL, NULL }, - { E_CARD_SIMPLE_FIELD_ORG, "org", "o", PROP_TYPE_NORMAL, NULL }, - { E_CARD_SIMPLE_FIELD_PHONE_PRIMARY, "phone", "telephonenumber", PROP_TYPE_NORMAL, NULL }, - { 0 /* unused */, "email", "mail", PROP_TYPE_LIST, construct_email_list }, -}; - -static int num_prop_infos = sizeof(prop_info_table) / sizeof(prop_info_table[0]); - static gchar * query_prop_to_ldap(gchar *query_prop) { -- cgit v1.2.3