diff options
Diffstat (limited to 'addressbook/backend')
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 156 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-ldap.c | 115 |
2 files changed, 148 insertions, 123 deletions
diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index a64a94c402..36310e0f43 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -20,7 +20,7 @@ #include "pas-backend-file.h" #include "pas-book.h" #include "pas-card-cursor.h" -#include <ebook/e-card.h> +#include <ebook/e-card-simple.h> #include <e-util/e-sexp.h> #include <e-util/e-util.h> @@ -56,7 +56,7 @@ struct _PASBackendFileBookView { }; struct _PASBackendFileSearchContext { - ECard *ecard; + ECardSimple *card; }; static long @@ -157,65 +157,39 @@ pas_backend_file_create_unique_id (char *vcard) } static gboolean -compare_email (ECard *ecard, const char *str, +compare_email (ECardSimple *card, const char *str, char *(*compare)(const char*, const char*)) { - EList *prop_list; - EIterator *iter; - gboolean truth = FALSE; - - gtk_object_get(GTK_OBJECT(ecard), - "email", &prop_list, NULL); + int i; - iter = e_list_get_iterator(prop_list); + for (i = E_CARD_SIMPLE_EMAIL_ID_EMAIL; i < E_CARD_SIMPLE_EMAIL_ID_LAST; i ++) { + const char *email = e_card_simple_get_email (card, i); - while (e_iterator_is_valid(iter)) { - - if (compare((char*)e_iterator_get(iter), str)) { - truth = TRUE; - break; - } - else { - e_iterator_next(iter); - } + if (compare(email, str)) + return TRUE; } - gtk_object_unref (GTK_OBJECT(iter)); - - return truth; + return FALSE; } static gboolean -compare_phone (ECard *ecard, const char *str, +compare_phone (ECardSimple *card, const char *str, char *(*compare)(const char*, const char*)) { - EList *prop_list; - EIterator *iter; - gboolean truth = FALSE; + int i; - gtk_object_get(GTK_OBJECT(ecard), - "phone", &prop_list, NULL); - - iter = e_list_get_iterator(prop_list); + for (i = E_CARD_SIMPLE_PHONE_ID_ASSISTANT; i < E_CARD_SIMPLE_PHONE_ID_LAST; i ++) { + const ECardPhone *phone = e_card_simple_get_phone (card, i); - while (e_iterator_is_valid(iter)) { - ECardPhone *phone = (ECardPhone*)e_iterator_get(iter); - if (compare(phone->number, str)) { - truth = TRUE; - break; - } - else { - e_iterator_next(iter); - } + if (compare(phone->number, str)) + return TRUE; } - gtk_object_unref (GTK_OBJECT(iter)); - - return truth; + return FALSE; } static gboolean -compare_address (ECard *ecard, const char *str, +compare_address (ECardSimple *card, const char *str, char *(*compare)(const char*, const char*)) { g_warning("address searching not implemented\n"); @@ -223,34 +197,38 @@ compare_address (ECard *ecard, const char *str, } static struct prop_info { + ECardSimpleField field_id; const char *query_prop; const char *ecard_prop; #define PROP_TYPE_NORMAL 0x01 #define PROP_TYPE_LIST 0x02 #define PROP_TYPE_LISTITEM 0x03 int prop_type; - gboolean (*list_compare)(ECard *ecard, const char *str, + gboolean (*list_compare)(ECardSimple *ecard, const char *str, char *(*compare)(const char*, const char*)); } prop_info_table[] = { +#define NORMAL_PROP(f,q,e) {f, q, e, PROP_TYPE_NORMAL, NULL} +#define LIST_PROP(q,e,c) {0, q, e, PROP_TYPE_LIST, c} + /* query prop, ecard prop, type, list compare function */ - { "file_as", "file_as", PROP_TYPE_NORMAL, NULL }, - { "full_name", "full_name", PROP_TYPE_NORMAL, NULL }, - { "url", "url", PROP_TYPE_NORMAL, NULL }, - { "mailer", "mailer", PROP_TYPE_NORMAL, NULL }, - { "org", "org", PROP_TYPE_NORMAL, NULL }, - { "org_unit", "org_unit", PROP_TYPE_NORMAL, NULL }, - { "office", "office", PROP_TYPE_NORMAL, NULL }, - { "title", "title", PROP_TYPE_NORMAL, NULL }, - { "role", "role", PROP_TYPE_NORMAL, NULL }, - { "manager", "manager", PROP_TYPE_NORMAL, NULL }, - { "assistant", "assistant", PROP_TYPE_NORMAL, NULL }, - { "nickname", "nickname", PROP_TYPE_NORMAL, NULL }, - { "spouse", "spouse", PROP_TYPE_NORMAL, NULL }, - { "email", "email", PROP_TYPE_LIST, compare_email }, - { "phone", "phone", PROP_TYPE_LIST, compare_phone }, - { "address", "address", PROP_TYPE_LIST, compare_address }, - { "note", "note", PROP_TYPE_NORMAL, NULL }, + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_FILE_AS, "file_as", "file_as" ), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_FULL_NAME, "full_name", "full_name" ), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_URL, "url", "url" ), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_MAILER, "mailer", "mailer"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ORG, "org", "org"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ORG_UNIT, "org_unit", "org_unit"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_OFFICE, "office", "office"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_TITLE, "title", "title"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ROLE, "role", "role"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_MANAGER, "manager", "manager"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ASSISTANT, "assistant", "assistant"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_NICKNAME, "nickname", "nickname"), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_SPOUSE, "spouse", "spouse" ), + NORMAL_PROP ( E_CARD_SIMPLE_FIELD_NOTE, "note", "note"), + LIST_PROP ( "email", "email", compare_email ), + LIST_PROP ( "phone", "phone", compare_phone ), + LIST_PROP ( "address", "address", compare_address ), }; static int num_prop_infos = sizeof(prop_info_table) / sizeof(prop_info_table[0]); @@ -268,35 +246,41 @@ entry_compare(PASBackendFileSearchContext *ctx, struct _ESExp *f, char *propname; struct prop_info *info = NULL; int i; + gboolean any_field; propname = argv[0]->value.string; + any_field = !strcmp(propname, "x-evolution-any-field"); for (i = 0; i < num_prop_infos; i ++) { - if (!strcmp (prop_info_table[i].query_prop, propname)) { + if (any_field + || strcmp (prop_info_table[i].query_prop, propname)) { info = &prop_info_table[i]; - break; - } - } - - if (info) { - if (info->prop_type == PROP_TYPE_NORMAL) { - char *prop = NULL; - /* searches where the query's property - maps directly to an ecard property */ - - gtk_object_get(GTK_OBJECT(ctx->ecard), - info->ecard_prop, &prop, NULL); - - if (prop && compare(prop, argv[1]->value.string)) { - truth = TRUE; - } - if ((!prop) && compare("", argv[1]->value.string)) { - truth = TRUE; + + if (info->prop_type == PROP_TYPE_NORMAL) { + char *prop = NULL; + /* searches where the query's property + maps directly to an ecard property */ + + prop = e_card_simple_get (ctx->card, info->field_id); + + if (prop && compare(prop, argv[1]->value.string)) { + truth = TRUE; + } + if ((!prop) && compare("", argv[1]->value.string)) { + truth = TRUE; + } } - } - else if (info->prop_type == PROP_TYPE_LIST) { + else if (info->prop_type == PROP_TYPE_LIST) { /* the special searches that match any of the list elements */ - truth = info->list_compare (ctx->ecard, argv[1]->value.string, compare); + truth = info->list_compare (ctx->card, argv[1]->value.string, compare); + } + + /* if we're looking at all fields and find a match, + or if we're just looking at this one field, + break. */ + if ((any_field && truth) + || !any_field) + break; } } @@ -389,17 +373,17 @@ vcard_matches_search (PASBackendFileBookView *view, char *vcard_string) ESExpResult *r; gboolean retval; - view->search_context->ecard = e_card_new (vcard_string); + view->search_context->card = e_card_simple_new (e_card_new (vcard_string)); /* if it's not a valid vcard why is it in our db? :) */ - if (!view->search_context->ecard) + if (!view->search_context->card) return FALSE; r = e_sexp_eval(view->search_sexp); retval = (r && r->type == ESEXP_RES_BOOL && r->value.bool); - gtk_object_unref(GTK_OBJECT(view->search_context->ecard)); + gtk_object_unref(GTK_OBJECT(view->search_context->card)); e_sexp_result_free(r); 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) { |