ekiga r6237 - in trunk: . lib/engine/addressbook/ldap



Author: jpuydt
Date: Sat May  3 16:02:00 2008
New Revision: 6237
URL: http://svn.gnome.org/viewvc/ekiga?rev=6237&view=rev

Log:
Fixed #527763 and #474830


Modified:
   trunk/ChangeLog
   trunk/lib/engine/addressbook/ldap/ldap-book.cpp
   trunk/lib/engine/addressbook/ldap/ldap-book.h

Modified: trunk/lib/engine/addressbook/ldap/ldap-book.cpp
==============================================================================
--- trunk/lib/engine/addressbook/ldap/ldap-book.cpp	(original)
+++ trunk/lib/engine/addressbook/ldap/ldap-book.cpp	Sat May  3 16:02:00 2008
@@ -41,7 +41,6 @@
 #include <sstream>
 #include <sys/time.h>
 
-#define LDAP_DEPRECATED 1
 #include <ldap.h>
 #include <glib.h>
 
@@ -347,21 +346,17 @@
   int msgid = -1;
   int result = LDAP_SUCCESS;
   int ldap_version = LDAP_VERSION3;
-  std::vector<std::string> attributes_vector;
-  char **attributes = NULL;
-  int iscope = LDAP_SCOPE_SUBTREE;
-  std::string filter;
-
-  attributes_vector.push_back ("givenname");
-  attributes_vector.push_back (call_attribute);
+  char *ldap_uri = NULL;
 
   status = std::string (_("Refreshing"));
   updated.emit ();
 
-  ldap_context = ldap_init (hostname.c_str (), port);
-  if (ldap_context == NULL) {
+  ldap_uri = g_strdup_printf ("ldap://%s:%d";, hostname.c_str (), port);
+  result = ldap_initialize (&ldap_context, ldap_uri);
+  g_free (ldap_uri);
+  if (result != LDAP_SUCCESS) {
 
-    status = std::string (_("Could not contact server"));
+    status = std::string (_("Could not initialize server"));
     updated.emit ();
     return;
   }
@@ -373,13 +368,16 @@
 			 LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
 
 
-  result = ldap_bind_s (ldap_context, NULL, NULL, LDAP_AUTH_SIMPLE);
+  result = ldap_sasl_bind (ldap_context, NULL,
+			   LDAP_SASL_SIMPLE, NULL,
+			   NULL, NULL,
+			   &msgid);
   if (result != LDAP_SUCCESS) {
 
     status = std::string (_("Could not contact server"));
     updated.emit ();
 
-    ldap_unbind (ldap_context);
+    ldap_unbind_ext (ldap_context, NULL, NULL);
     ldap_context = NULL;
     return;
   }
@@ -387,6 +385,57 @@
   status = std::string (_("Contacted server"));
   updated.emit ();
 
+  patience = 3;
+  runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_bound), 3);
+}
+
+void
+OPENLDAP::Book::refresh_bound ()
+{
+  int result = LDAP_SUCCESS;
+  struct timeval timeout = { 1, 0}; /* block 1s */
+  LDAPMessage *msg_entry = NULL;
+  int msgid;
+  std::vector<std::string> attributes_vector;
+  char **attributes = NULL;
+  int iscope = LDAP_SCOPE_SUBTREE;
+  std::string filter;
+
+  result = ldap_result (ldap_context, LDAP_RES_ANY, LDAP_MSG_ALL,
+			&timeout, &msg_entry);
+
+  if (result <= 0) {
+
+    if (patience == 3) {
+      patience--;
+      runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_bound), 12);
+    } else if (patience == 2) {
+
+      patience--;
+      runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_bound), 21);
+    } else if (patience == 1) {
+
+      patience--;
+      runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_bound), 30);
+    } else { // patience == 0
+
+      status = std::string (_("Could not connect to server"));
+      updated.emit ();
+
+      ldap_unbind_ext (ldap_context, NULL, NULL);
+      ldap_context = NULL;
+    }
+
+    if (msg_entry != NULL)
+      ldap_msgfree (msg_entry);
+
+    return;
+  }
+
+
+  attributes_vector.push_back ("givenname");
+  attributes_vector.push_back (call_attribute);
+
   if (scope == "sub")
     iscope = LDAP_SCOPE_SUBTREE;
   else
@@ -405,12 +454,14 @@
   else
     filter = "(cn=*)";
 
-  msgid = ldap_search (ldap_context,
-		       base.c_str (),
-		       iscope,
-		       filter.c_str (),
-		       attributes,
-		       0); /* attrsonly */
+  msgid = ldap_search_ext (ldap_context,
+			   base.c_str (),
+			   iscope,
+			   filter.c_str (),
+			   attributes,
+			   0, /* attrsonly */
+			   NULL, NULL,
+			   NULL, 0, &msgid);
 
   for (unsigned int i = 0; i < attributes_vector.size (); i++)
     free (attributes[i]);
@@ -421,7 +472,7 @@
     status = std::string (_("Could not search"));
     updated.emit ();
 
-    ldap_unbind (ldap_context);
+    ldap_unbind_ext (ldap_context, NULL, NULL);
     ldap_context = NULL;
     return;
   } else {
@@ -431,11 +482,12 @@
   }
 
   patience = 3;
-  runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_end), 3);
+  runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_result), 3);
+
 }
 
 void
-OPENLDAP::Book::refresh_end ()
+OPENLDAP::Book::refresh_result ()
 {
   int result = LDAP_SUCCESS;
   int nbr = 0;
@@ -453,21 +505,21 @@
     if (patience == 3) {
 
       patience--;
-      runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_end), 12);
+      runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_result), 12);
     } else if (patience == 2) {
 
       patience--;
-      runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_end), 21);
+      runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_result), 21);
     } else if (patience == 1) {
 
       patience--;
-      runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_end), 30);
+      runtime.run_in_main (sigc::mem_fun (this, &OPENLDAP::Book::refresh_result), 30);
     } else { // patience == 0
 
       status = std::string (_("Could not search"));
       updated.emit ();
 
-      ldap_unbind (ldap_context);
+      ldap_unbind_ext (ldap_context, NULL, NULL);
       ldap_context = NULL;
     }
 
@@ -498,7 +550,7 @@
 
   (void)ldap_msgfree (msg_entry);
 
-  ldap_unbind (ldap_context);
+  ldap_unbind_ext (ldap_context, NULL, NULL);
   ldap_context = NULL;
 }
 

Modified: trunk/lib/engine/addressbook/ldap/ldap-book.h
==============================================================================
--- trunk/lib/engine/addressbook/ldap/ldap-book.h	(original)
+++ trunk/lib/engine/addressbook/ldap/ldap-book.h	Sat May  3 16:02:00 2008
@@ -93,7 +93,8 @@
   private:
 
     void refresh_start ();
-    void refresh_end ();
+    void refresh_bound ();
+    void refresh_result ();
 
     void edit ();
     void on_edit_form_submitted (Ekiga::Form &);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]