From a14059d9f297b7ccbec0f4de81e1f1053da61cac Mon Sep 17 00:00:00 2001 From: Sushma Rai Date: Sat, 22 Oct 2005 08:04:58 +0000 Subject: Making the LDAP search filter configurable. Fixes #311884. svn path=/trunk/; revision=30553 --- addressbook/gui/component/addressbook-config.c | 41 ++- addressbook/gui/component/ldap-config.glade | 353 ++++++++++++++++++++++++- 2 files changed, 377 insertions(+), 17 deletions(-) (limited to 'addressbook/gui') diff --git a/addressbook/gui/component/addressbook-config.c b/addressbook/gui/component/addressbook-config.c index a9e4255308..e4c10032ae 100644 --- a/addressbook/gui/component/addressbook-config.c +++ b/addressbook/gui/component/addressbook-config.c @@ -107,6 +107,7 @@ struct _AddressbookSourceDialog { GtkWidget *rootdn; AddressbookLDAPScopeType scope; GtkWidget *scope_optionmenu; + GtkWidget *search_filter; GtkWidget *timeout_scale; GtkWidget *limit_spinbutton; @@ -195,7 +196,7 @@ ldap_parse_ssl (const char *ssl) } static gboolean -source_to_uri_parts (ESource *source, gchar **host, gchar **rootdn, AddressbookLDAPScopeType *scope, gint *port) +source_to_uri_parts (ESource *source, gchar **host, gchar **rootdn, AddressbookLDAPScopeType *scope, gchar **search_filter, gint *port) { gchar *uri; LDAPURLDesc *lud; @@ -221,6 +222,8 @@ source_to_uri_parts (ESource *source, gchar **host, gchar **rootdn, AddressbookL lud->lud_scope == LDAP_SCOPE_ONELEVEL ? ADDRESSBOOK_LDAP_SCOPE_ONELEVEL : lud->lud_scope == LDAP_SCOPE_SUBTREE ? ADDRESSBOOK_LDAP_SCOPE_SUBTREE : ADDRESSBOOK_LDAP_SCOPE_ONELEVEL; + if (search_filter && lud->lud_filter) + *search_filter = g_strdup (lud->lud_filter); ldap_free_urldesc (lud); return TRUE; @@ -242,7 +245,7 @@ addressbook_ldap_init (GtkWidget *window, ESource *source) int ldap_error; int protocol_version = LDAP_VERSION3; - if (!source_to_uri_parts (source, &host, NULL, NULL, &port)) + if (!source_to_uri_parts (source, &host, NULL, NULL, NULL, &port)) return NULL; if (!(ldap = ldap_init (host, port))) { @@ -618,17 +621,35 @@ eabc_general_offline(EConfig *ec, EConfigItem *item, struct _GtkWidget *parent, } #ifdef HAVE_LDAP +static gchar * +form_ldap_search_filter (GtkWidget *w) +{ + gchar *filter; + const gchar *search_filter = gtk_entry_get_text ((GtkEntry *) w); + + /* this function can be used to format the search filter entered */ + if ((strlen (search_filter) !=0) && *search_filter != '(' && *(search_filter + (strlen (search_filter-1))) != ')') + filter = g_strdup_printf ("(%s)", search_filter); + else + filter = g_strdup_printf ("%s", search_filter); + + return filter; +} + static void url_changed(AddressbookSourceDialog *sdialog) { - char *str; + gchar *str, *search_filter; - str = g_strdup_printf ("%s:%s/%s?" /* trigraph prevention */ "?%s", + search_filter = form_ldap_search_filter (sdialog->search_filter); + str = g_strdup_printf ("%s:%s/%s?" /* trigraph prevention */ "?%s?%s", gtk_entry_get_text (GTK_ENTRY (sdialog->host)), gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (sdialog->port_combo)->entry)), gtk_entry_get_text (GTK_ENTRY (sdialog->rootdn)), - ldap_unparse_scope (sdialog->scope)); + ldap_unparse_scope (sdialog->scope), + search_filter); e_source_set_relative_uri (sdialog->source, str); + g_free (search_filter); g_free (str); } @@ -788,6 +809,12 @@ rootdn_changed_cb(GtkWidget *w, AddressbookSourceDialog *sdialog) url_changed(sdialog); } +static void +search_filter_changed_cb (GtkWidget *w, AddressbookSourceDialog *sdialog) +{ + url_changed (sdialog); +} + static void scope_optionmenu_changed_cb(GtkWidget *w, AddressbookSourceDialog *sdialog) { @@ -836,6 +863,10 @@ eabc_details_search(EConfig *ec, EConfigItem *item, struct _GtkWidget *parent, s gtk_option_menu_set_history (GTK_OPTION_MENU(sdialog->scope_optionmenu), sdialog->scope); g_signal_connect(sdialog->scope_optionmenu, "changed", G_CALLBACK(scope_optionmenu_changed_cb), sdialog); + sdialog->search_filter = glade_xml_get_widget (gui, "search-filter-entry"); + gtk_entry_set_text((GtkEntry *)sdialog->search_filter, lud && lud->lud_filter ? lud->lud_filter : ""); + g_signal_connect (sdialog->search_filter, "changed", G_CALLBACK (search_filter_changed_cb), sdialog); + g_signal_connect (glade_xml_get_widget(gui, "rootdn-button"), "clicked", G_CALLBACK(query_for_supported_bases), sdialog); diff --git a/addressbook/gui/component/ldap-config.glade b/addressbook/gui/component/ldap-config.glade index dfa5ecb0cd..abbc73cf33 100644 --- a/addressbook/gui/component/ldap-config.glade +++ b/addressbook/gui/component/ldap-config.glade @@ -16,6 +16,7 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True False @@ -94,6 +95,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -121,6 +126,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -143,6 +152,10 @@ 0 0 account-editor-display-name-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -161,7 +174,7 @@ 0 True - * + * False @@ -196,6 +209,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -223,6 +240,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -254,6 +275,10 @@ 0 0 entry27 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -279,6 +304,10 @@ 0 0 server-name-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -310,6 +339,10 @@ 0 0 ssl-optionmenu + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -394,7 +427,7 @@ 0 True - * + * False @@ -450,7 +483,7 @@ 0 True - * + * False @@ -489,6 +522,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -516,6 +553,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -547,6 +588,10 @@ 0 0 auth-optionmenu + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -572,6 +617,10 @@ 0 0 auth-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -640,7 +689,7 @@ 0 True - * + * False @@ -692,6 +741,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -717,6 +770,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -744,6 +801,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -755,7 +816,7 @@ True - 3 + 4 3 False 6 @@ -774,6 +835,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -799,6 +864,10 @@ 0 0 rootdn-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -824,6 +893,10 @@ 0 0 scope-optionmenu + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -884,7 +957,7 @@ 0 True - * + * False @@ -952,6 +1025,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -973,6 +1050,61 @@ shrink|fill + + + + True + Search _filter: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + search-filter-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 3 + 4 + expand|shrink|fill + shrink|fill + + + + + + True + True + True + True + 0 + + True + * + False + + Search Filter + Search filter is the type of the objects searched for, while performing the search. If this is not modified, by default search will be performed on objectclass of the type "person". + + + + 1 + 3 + 3 + 4 + expand|shrink|fill + shrink|fill + + 0 @@ -1001,6 +1133,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1028,6 +1164,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1064,6 +1204,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1103,6 +1247,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1134,6 +1282,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 2 @@ -1158,6 +1310,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 2 @@ -1183,6 +1339,10 @@ 0 0 timeout-scale + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1208,6 +1368,10 @@ 0 0 download-limit-spinbutton + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1275,6 +1439,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -1305,6 +1473,7 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True False @@ -1397,6 +1566,7 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True False @@ -1480,6 +1650,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1540,6 +1714,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1599,7 +1777,7 @@ 0 True - * + * False @@ -1625,6 +1803,10 @@ 0 0 display-name-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1651,6 +1833,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 label_item @@ -1690,7 +1876,7 @@ 0 True - * + * False @@ -1716,6 +1902,10 @@ 0 0 port-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1745,7 +1935,7 @@ 0 True - * + * False @@ -1810,6 +2000,10 @@ 0 0 ssl-optionmenu + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1886,6 +2080,10 @@ 0 0 server-name-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1912,6 +2110,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 label_item @@ -1956,6 +2158,10 @@ 0 0 auth-optionmenu + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1981,6 +2187,10 @@ 0 0 auth-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2001,7 +2211,7 @@ 0 True - * + * False @@ -2076,6 +2286,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 label_item @@ -2108,6 +2322,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -2132,7 +2350,7 @@ 12 True - 3 + 4 3 False 6 @@ -2152,6 +2370,10 @@ 0 0 rootdn-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2177,6 +2399,10 @@ 0 0 scope-optionmenu + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2197,7 +2423,7 @@ 0 True - * + * False @@ -2264,6 +2490,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2336,6 +2566,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2360,6 +2594,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 2 @@ -2370,6 +2608,61 @@ + + + + True + Search _filter: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + entry30 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 3 + 4 + expand|shrink|fill + shrink|fill + + + + + + True + True + True + True + 0 + + True + * + False + + Search filter + Search filter is the type of the objects searched for, while performing the search. If this is not modified, by default search will be performed on objectclass of the type "person". + + + + 1 + 3 + 3 + 4 + expand|shrink|fill + shrink|fill + + @@ -2386,6 +2679,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 label_item @@ -2430,6 +2727,10 @@ 0 0 timeout-scale + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2454,6 +2755,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 2 @@ -2484,6 +2789,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2523,6 +2832,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2554,6 +2867,10 @@ 0 0 download-limit-spinbutton + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2578,6 +2895,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 2 @@ -2625,6 +2946,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 label_item @@ -2657,6 +2982,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab -- cgit v1.2.3