ekiga r7245 - trunk/lib/engine/components/xcap



Author: jpuydt
Date: Thu Oct 16 19:56:16 2008
New Revision: 7245
URL: http://svn.gnome.org/viewvc/ekiga?rev=7245&view=rev

Log:
Added basic auth support to XCAP::Core

Modified:
   trunk/lib/engine/components/xcap/xcap-core.cpp
   trunk/lib/engine/components/xcap/xcap-path.cpp
   trunk/lib/engine/components/xcap/xcap-path.h

Modified: trunk/lib/engine/components/xcap/xcap-core.cpp
==============================================================================
--- trunk/lib/engine/components/xcap/xcap-core.cpp	(original)
+++ trunk/lib/engine/components/xcap/xcap-core.cpp	Thu Oct 16 19:56:16 2008
@@ -54,23 +54,38 @@
 
   void read (gmref_ptr<XCAP::Path> path,
 	     sigc::slot<void,XCAP::Core::ResultType,std::string> callback);
-
-private:
-
-  SoupSession* session;
 };
 
-/* soup callback */
+/* soup callbacks */
 
 struct cb_data
 {
+  gmref_ptr<XCAP::Path> path;
+  SoupSession* session;
   sigc::slot<void,XCAP::Core::ResultType, std::string> callback;
 };
 
 static void
-soup_callback (G_GNUC_UNUSED SoupSession* session,
-	       SoupMessage* message,
-	       gpointer data)
+authenticate_callback (G_GNUC_UNUSED SoupSession* session,
+		       G_GNUC_UNUSED SoupMessage* message,
+		       SoupAuth* auth,
+		       gboolean retrying,
+		       gpointer data)
+{
+  cb_data* cb = (cb_data*)data;
+
+  if ( !retrying) {
+
+    soup_auth_authenticate (auth,
+			    cb->path->get_username ().c_str (),
+			    cb->path->get_password ().c_str ());
+  }
+}
+
+static void
+result_callback (G_GNUC_UNUSED SoupSession* session,
+		 SoupMessage* message,
+		 gpointer data)
 {
   cb_data* cb = (cb_data*)data;
 
@@ -87,20 +102,18 @@
     break;
   }
 
-  delete (cb_data*)data;
+  g_object_unref (cb->session);
+  delete cb;
 }
 
 /* implementation of XCAP::CoreImpl */
 
 XCAP::CoreImpl::CoreImpl ()
 {
-  session = soup_session_async_new_with_options ("user-agent", "ekiga",
-						 NULL);
 }
 
 XCAP::CoreImpl::~CoreImpl ()
 {
-  g_object_unref (session);
 }
 
 void
@@ -112,10 +125,16 @@
 
   message = soup_message_new ("GET", path->to_uri ().c_str ());
   data = new cb_data;
+  data->path = path;
+  data->session = soup_session_async_new_with_options ("user-agent", "ekiga",
+						       NULL);
   data->callback = callback;
 
-  soup_session_queue_message (session, message,
-			      soup_callback, data);
+  g_signal_connect (data->session, "authenticate",
+		    G_CALLBACK (authenticate_callback), data);
+
+  soup_session_queue_message (data->session, message,
+			      result_callback, data);
 }
 
 

Modified: trunk/lib/engine/components/xcap/xcap-path.cpp
==============================================================================
--- trunk/lib/engine/components/xcap/xcap-path.cpp	(original)
+++ trunk/lib/engine/components/xcap/xcap-path.cpp	Thu Oct 16 19:56:16 2008
@@ -66,6 +66,18 @@
   return uri;
 }
 
+const std::string
+XCAP::Path::get_username () const
+{
+  return username;
+}
+
+const std::string
+XCAP::Path::get_password () const
+{
+  return password;
+}
+
 void
 XCAP::Path::set_credentials (std::string username_,
 			     std::string password_)

Modified: trunk/lib/engine/components/xcap/xcap-path.h
==============================================================================
--- trunk/lib/engine/components/xcap/xcap-path.h	(original)
+++ trunk/lib/engine/components/xcap/xcap-path.h	Thu Oct 16 19:56:16 2008
@@ -58,6 +58,10 @@
 
     std::string to_uri () const;
 
+    const std::string get_username () const;
+
+    const std::string get_password () const;
+
     /* this sets what you need to connect to the server */
     void set_credentials (std::string username,
 			  std::string password);



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