aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--addressbook/ChangeLog17
-rw-r--r--addressbook/backend/pas/pas-backend-ldap.c111
2 files changed, 77 insertions, 51 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 0178a571da..9f9579f56f 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,5 +1,22 @@
2000-07-26 Chris Toshok <toshok@helixcode.com>
+ * backend/pas/pas-backend-ldap.c (view_destroy): wait to free the
+ view until we've taken care of freeing its internals. also, close
+ the ldap connection here.
+ (pas_backend_ldap_connect): rename p_b_l_ensure_connected to this,
+ since it's always called when we create a view.
+ (pas_backend_ldap_build_all_cards_list): open an ldap connection
+ in this function and close it at the end.
+ (poll_ldap): make sure to call ldap_unbind to close the view's
+ connection here.
+ (pas_backend_ldap_search): call pas_backend_ldap_connect here -
+ ldap_unbind will either be called from poll_ldap or from
+ view_destroy.
+ (pas_backend_ldap_get_vcard): the PASBackendLDAP no longer has an
+ LDAP*.
+
+2000-07-26 Chris Toshok <toshok@helixcode.com>
+
* backend/pas/pas-backend-ldap.c
(pas_backend_ldap_build_all_cards_list): add support for user settable scope.
(pas_backend_ldap_search): same.
diff --git a/addressbook/backend/pas/pas-backend-ldap.c b/addressbook/backend/pas/pas-backend-ldap.c
index f032ab08d4..5257177328 100644
--- a/addressbook/backend/pas/pas-backend-ldap.c
+++ b/addressbook/backend/pas/pas-backend-ldap.c
@@ -32,7 +32,6 @@ struct _PASBackendLDAPPrivate {
char *uri;
gboolean connected;
GList *clients;
- LDAP *ldap;
gchar *ldap_host;
gchar *ldap_rootdn;
int ldap_port;
@@ -51,6 +50,7 @@ struct _PASBackendLDAPCursorPrivate {
struct _PASBackendLDAPBookView {
PASBookView *book_view;
PASBackendLDAPPrivate *blpriv;
+ LDAP *ldap;
gchar *search;
int search_idle;
int search_msgid;
@@ -109,10 +109,12 @@ view_destroy(GtkObject *object, gpointer data)
for (list = bl->priv->book_views; list; list = g_list_next(list)) {
PASBackendLDAPBookView *view = list->data;
if (view->book_view == PAS_BOOK_VIEW(object)) {
- g_free (view->search);
- g_free (view);
if (view->search_idle != 0)
g_source_remove(view->search_idle);
+ if (view->ldap)
+ ldap_unbind (view->ldap);
+ g_free (view->search);
+ g_free (view);
bl->priv->book_views = g_list_remove_link(bl->priv->book_views, list);
g_list_free_1(list);
break;
@@ -134,9 +136,10 @@ view_destroy(GtkObject *object, gpointer data)
}
static void
-pas_backend_ldap_ensure_connected (PASBackendLDAP *bl)
+pas_backend_ldap_connect (PASBackendLDAPBookView *view)
{
- LDAP *ldap = bl->priv->ldap;
+ LDAP *ldap = view->ldap;
+ PASBackendLDAPPrivate *bl = view->blpriv;
/* the connection has gone down, or wasn't ever opened */
if (ldap == NULL ||
@@ -146,19 +149,19 @@ pas_backend_ldap_ensure_connected (PASBackendLDAP *bl)
if (ldap)
ldap_unbind (ldap);
- bl->priv->ldap = ldap_open (bl->priv->ldap_host, bl->priv->ldap_port);
- if (NULL != bl->priv->ldap) {
- ldap_simple_bind_s(bl->priv->ldap,
+ view->ldap = ldap_open (bl->ldap_host, bl->ldap_port);
+ if (NULL != view->ldap) {
+ ldap_simple_bind_s(view->ldap,
NULL /*binddn*/, NULL /*passwd*/);
- bl->priv->connected = TRUE;
+ bl->connected = TRUE;
}
else {
- g_warning ("pas_backend_ldap_ensure_connected failed for "
+ g_warning ("pas_backend_ldap_connect failed for "
"'ldap://%s:%d/%s'\n",
- bl->priv->ldap_host,
- bl->priv->ldap_port,
- bl->priv->ldap_rootdn ? bl->priv->ldap_rootdn : "");
- bl->priv->connected = FALSE;
+ bl->ldap_host,
+ bl->ldap_port,
+ bl->ldap_rootdn ? bl->ldap_rootdn : "");
+ bl->connected = FALSE;
}
}
}
@@ -201,47 +204,56 @@ pas_backend_ldap_build_all_cards_list(PASBackend *backend,
int ldap_error;
LDAPMessage *res, *e;
- pas_backend_ldap_ensure_connected(bl);
-
- ldap = bl->priv->ldap;
-
- if (ldap) {
- ldap->ld_sizelimit = LDAP_MAX_SEARCH_RESPONSES;
- ldap->ld_deref = LDAP_DEREF_ALWAYS;
+ ldap = ldap_open (bl->priv->ldap_host, bl->priv->ldap_port);
+ if (NULL != ldap) {
+ ldap_simple_bind_s(ldap, NULL /*binddn*/, NULL /*passwd*/);
+ }
+ else {
+ g_warning ("pas_backend_ldap_build_all_cards_list: ldap_open failed for "
+ "'ldap://%s:%d/%s'\n",
+ bl->priv->ldap_host,
+ bl->priv->ldap_port,
+ bl->priv->ldap_rootdn ? bl->priv->ldap_rootdn : "");
+ return;
+ }
- if ((ldap_error = ldap_search_s (ldap,
- bl->priv->ldap_rootdn,
- bl->priv->ldap_scope,
- "(objectclass=*)",
- NULL, 0, &res)) == -1) {
- g_warning ("ldap error '%s' in "
- "pas_backend_ldap_build_all_cards_list\n",
- ldap_err2string(ldap_error));
- }
+ ldap->ld_sizelimit = LDAP_MAX_SEARCH_RESPONSES;
+ ldap->ld_deref = LDAP_DEREF_ALWAYS;
+
+ if ((ldap_error = ldap_search_s (ldap,
+ bl->priv->ldap_rootdn,
+ bl->priv->ldap_scope,
+ "(objectclass=*)",
+ NULL, 0, &res)) == -1) {
+ g_warning ("ldap error '%s' in "
+ "pas_backend_ldap_build_all_cards_list\n",
+ ldap_err2string(ldap_error));
+ }
- cursor_data->elements = NULL;
+ cursor_data->elements = NULL;
- cursor_data->num_elements = ldap_count_entries (ldap, res);
+ cursor_data->num_elements = ldap_count_entries (ldap, res);
- e = ldap_first_entry(ldap, res);
+ e = ldap_first_entry(ldap, res);
- while (NULL != e) {
+ while (NULL != e) {
- /* for now just make a list of the dn's */
+ /* for now just make a list of the dn's */
#if 0
- for ( a = ldap_first_attribute( ldap, e, &ber ); a != NULL;
- a = ldap_next_attribute( ldap, e, ber ) ) {
- }
+ for ( a = ldap_first_attribute( ldap, e, &ber ); a != NULL;
+ a = ldap_next_attribute( ldap, e, ber ) ) {
+ }
#else
- cursor_data->elements = g_list_prepend(cursor_data->elements,
+ cursor_data->elements = g_list_prepend(cursor_data->elements,
g_strdup(ldap_get_dn(ldap, e)));
#endif
- e = ldap_next_entry(ldap, e);
- }
-
- ldap_msgfree(res);
+ e = ldap_next_entry(ldap, e);
}
+
+ ldap_msgfree(res);
+
+ ldap_unbind (ldap);
}
static void
@@ -616,12 +628,14 @@ poll_ldap (PASBackendLDAPBookView *view)
LDAPMessage *res, *e;
GList *cards = NULL;
- ldap = view->blpriv->ldap;
+ ldap = view->ldap;
if ((rc = ldap_result (ldap, view->search_msgid, 0, NULL, &res))
!= LDAP_RES_SEARCH_ENTRY) {
view->search_idle = 0;
pas_book_view_notify_complete (view->book_view);
+ ldap_unbind (ldap);
+ view->ldap = NULL;
return FALSE;
}
@@ -708,9 +722,9 @@ pas_backend_ldap_search (PASBackendLDAP *bl,
if (ldap_query != NULL) {
LDAP *ldap;
- /* pas_backend_ldap_ensure_connected(bl);*/
+ pas_backend_ldap_connect(view);
- ldap = bl->priv->ldap;
+ ldap = view->ldap;
if (ldap) {
ldap->ld_sizelimit = LDAP_MAX_SEARCH_RESPONSES;
@@ -856,11 +870,9 @@ static char *
pas_backend_ldap_get_vcard (PASBook *book, const char *id)
{
PASBackendLDAP *bl;
- LDAP *ldap;
int ldap_error = LDAP_SUCCESS; /* XXX */
bl = PAS_BACKEND_LDAP (pas_book_get_backend (book));
- ldap = bl->priv->ldap;
/* XXX use ldap_search */
@@ -897,7 +909,6 @@ pas_backend_ldap_load_uri (PASBackend *backend,
ldap_free_urldesc(lud);
- pas_backend_ldap_ensure_connected(bl);
return TRUE;
} else
return FALSE;
@@ -1025,8 +1036,6 @@ pas_backend_ldap_new (void)
return NULL;
}
- backend->priv->ldap = NULL;
-
return PAS_BACKEND (backend);
}