[Gurlchecker-commits] r760 - in trunk: . src

esaracco at users.labs.libre-entreprise.org esaracco at users.labs.libre-entreprise.org
Thu Jan 28 20:57:54 CET 2010


Author: esaracco
Date: 2010-01-28 19:57:54 +0000 (Thu, 28 Jan 2010)
New Revision: 760

Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/src/application.c
   trunk/src/check.c
   trunk/src/connection.c
   trunk/src/project.c
   trunk/src/project.h
Log:
Fixed a HTTP header detection bug in SSL mode, and code cleaning.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-01-28 12:28:33 UTC (rev 759)
+++ trunk/ChangeLog	2010-01-28 19:57:54 UTC (rev 760)
@@ -2,10 +2,16 @@
 
 	* Network:
 
+	  - Fixed a HTTP header detection bug in SSL mode.
+
 	  - Rewrote connect_thread function to avoid use of deprecated
 	    gethostbyname() function. By the way, it fixed a connection freeze
 	    problem when a lot of links were ignored by the end user.
 
+	* Other:
+
+	  - Code cleaning.
+
 2010-01-27 Emmanuel Saracco <esaracco at users.labs.libre-entreprise.org>
 
 	* GUI:

Modified: trunk/configure.in
===================================================================
--- trunk/configure.in	2010-01-28 12:28:33 UTC (rev 759)
+++ trunk/configure.in	2010-01-28 19:57:54 UTC (rev 760)
@@ -2,7 +2,7 @@
 AC_PREREQ(2.54)
 
 AC_INIT(configure.in)
-AM_INIT_AUTOMAKE(gurlchecker, 0.11.2svn2010012800)
+AM_INIT_AUTOMAKE(gurlchecker, 0.11.2svn2010012801)
 AM_CONFIG_HEADER(config.h)
 AC_CONFIG_MACRO_DIR([m4])
 

Modified: trunk/src/application.c
===================================================================
--- trunk/src/application.c	2010-01-28 12:28:33 UTC (rev 759)
+++ trunk/src/application.c	2010-01-28 19:57:54 UTC (rev 760)
@@ -901,47 +901,44 @@
 
   w = WGET ("auth_dialog");
   if (title)
-    {
-      gchar **real_title = g_strsplit (title, "=", 2);
-      tmp = g_strdup_printf (_("Enter login and password for %s at %s"),
-			     real_title[1], host);
+  {
+    gchar **real_title = g_strsplit (title, "=", 2);
+    tmp = g_strdup_printf (_("Enter login and password for %s at %s"),
+                           real_title[1], host);
 
-      widget = WGET ("ad_title");
-      gtk_label_set_text (GTK_LABEL (widget), tmp);
+    widget = WGET ("ad_title");
+    gtk_label_set_text (GTK_LABEL (widget), tmp);
 
-      g_free (tmp), tmp = NULL;
-      g_strfreev (real_title), real_title = NULL;
-    }
+    g_free (tmp), tmp = NULL;
+    g_strfreev (real_title), real_title = NULL;
+  }
 
-  widget = WGET ("ad_stop_display");
-
   gtk_widget_show_all (w);
 
 again:
+      
+  widget = WGET ("ad_stop_display");
+  uc_project_set_prompt_auth (
+    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)));
 
   if (gtk_dialog_run (GTK_DIALOG (w)) == GTK_RESPONSE_OK)
-    {
-      gchar *auth_user = NULL;
-      gchar *auth_password = NULL;
-      gchar *auth_line = NULL;
+  {
+    gchar *auth_user = NULL;
+    gchar *auth_password = NULL;
+    gchar *auth_line = NULL;
 
 
-      if (uc_utils_get_auth_fields (glade,
-				    WGET ("ad_auth_user"),
-				    WGET ("ad_auth_password"),
-				    &auth_user, &auth_password, &auth_line))
-	{
-	  uc_project_set_auth_user (auth_user);
-	  uc_project_set_auth_password (auth_password);
-	  uc_project_set_auth_line (auth_line);
-	  g_free (auth_line), auth_line = NULL;
-	  ret = TRUE;
-	}
-      else if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
-	goto again;
-      else
-	uc_project_set_prompt_auth (FALSE);
+    if (uc_utils_get_auth_fields (glade, WGET ("ad_auth_user"),
+                                  WGET ("ad_auth_password"), &auth_user,
+                                  &auth_password, &auth_line))
+    {
+       uc_project_set_auth_line (auth_line);
+       g_free (auth_line), auth_line = NULL;
+       ret = TRUE;
     }
+    else if (uc_project_get_prompt_auth ())
+      goto again;
+  }
 
   gtk_widget_hide (w);
 
@@ -3566,9 +3563,7 @@
                   gnome_entry_append_history (GNOME_ENTRY (widget), TRUE,
                                               tmp_url);
 
-		  /* manage authentication */
-		  uc_project_set_auth_user (NULL);
-		  uc_project_set_auth_password (NULL);
+		  // Manage authentication
 		  uc_project_set_auth_line (NULL);
 		  if (uc_utils_get_auth_fields (glade,
 						WGET ("nwpd_auth_user"),
@@ -3576,8 +3571,6 @@
 						&auth_user, &auth_password,
 						&auth_line))
 		    {
-		      uc_project_set_auth_user (auth_user);
-		      uc_project_set_auth_password (auth_password);
 		      uc_project_set_auth_line (auth_line);
 		      g_free (auth_line), auth_line = NULL;
 		    }
@@ -4132,8 +4125,6 @@
 	{
 	  gchar *auth_line = NULL;
 
-	  uc_project_set_auth_user (auth_user);
-	  uc_project_set_auth_password (auth_password);
 	  auth_line = uc_utils_build_auth_line (auth_user, auth_password);
 	  uc_project_set_auth_line (auth_line);
 	  g_free (auth_line), auth_line = NULL;

Modified: trunk/src/check.c
===================================================================
--- trunk/src/check.c	2010-01-28 12:28:33 UTC (rev 759)
+++ trunk/src/check.c	2010-01-28 19:57:54 UTC (rev 760)
@@ -2759,13 +2759,11 @@
   prop->status_icon = sc->icon_file;
   prop->label = g_strdup (tag->label);
 
-  // If authentication needed
+  // If authentication needed (works only for main URL)
   if (uc_project_get_prompt_auth () &&
       strcmp (g_hash_table_lookup (prop->header, UC_HEADER_STATUS),
-	      UC_STATUS_CODE_RESTRICTED) == 0
-      // FIXME is it really necessary?
-      //&&    !strcmp (uc_project_get_current_host (), prop->h_name)
-     )
+	      UC_STATUS_CODE_RESTRICTED) == 0 &&
+      strcmp (uc_project_get_current_host (), prop->h_name) == 0)
     {
       if (uc_application_auth_dialog_show (
             g_hash_table_lookup (prop->header, UC_WWW_AUTHENTICATE),

Modified: trunk/src/connection.c
===================================================================
--- trunk/src/connection.c	2010-01-28 12:28:33 UTC (rev 759)
+++ trunk/src/connection.c	2010-01-28 19:57:54 UTC (rev 760)
@@ -260,11 +260,8 @@
 static gboolean
 uc_conn_timeout_cb (gpointer data)
 {
-  UCConn *conn = (UCConn *) data;
+  ((UCConn *)data)->thread_end = TRUE;
 
-  pthread_cancel (conn->thread_id);
-  conn->thread_end = TRUE;
-
   return FALSE;
 }
 
@@ -302,6 +299,7 @@
     }
 }
 
+
 /**
  * uc_server_get_response:
  * @proto: The protocol.
@@ -325,6 +323,7 @@
   GArray *array = NULL;
   guint timeout_id = 0;
 
+
   uc_check_ignore_item_set_value (FALSE);
   if (uc_check_cancel_get_value ())
     return NULL;
@@ -333,30 +332,26 @@
       && (g_ascii_strcasecmp (host, "localhost") != 0
 	  && strstr (host, "127.0.0.") == NULL))
 
-    {
-      host_real = uc_project_get_proxy_host ();
-      port_real = uc_project_get_proxy_port ();
-    }
+  {
+    host_real = uc_project_get_proxy_host ();
+    port_real = uc_project_get_proxy_port ();
+  }
   else
-    {
-      host_real = host;
-      port_real = port;
-    }
+  {
+    host_real = host;
+    port_real = port;
+  }
 
+  // Connect
   conn = uc_conn_new (proto, host_real, port_real, buffer, header_request);
-
-  /* connect */
   conn->thread_end = FALSE;
   pthread_create (&conn->thread_id, NULL, connect_thread, conn);
   pthread_detach (conn->thread_id);
 
   UC_THREAD_WAIT (conn->thread_end, FALSE);
 
-  /* check was cancelled */
-  if (UC_CHECK_CANCELED)
-    pthread_cancel (conn->thread_id);
-  /* send client request and read server response */
-  else if (conn->tcp_status == UC_TCP_STATUS_OK)
+  // Connection OK : send client request and read server response
+  if (!UC_CHECK_CANCELED && conn->tcp_status == UC_TCP_STATUS_OK)
     {
       conn->thread_end = FALSE;
       pthread_create (&conn->thread_id, NULL, read_thread, conn);
@@ -369,11 +364,8 @@
       if (timeout_id != 0)
 	g_source_remove (timeout_id), timeout_id = 0;
 
-      /* check was cancelled */
-      if (UC_CHECK_CANCELED)
-	pthread_cancel (conn->thread_id);
-      /* ok, get fill array with the server response */
-      else if (conn->tcp_status == UC_TCP_STATUS_OK)
+      // Read OK : get fill array with the server response
+      if (!UC_CHECK_CANCELED && conn->tcp_status == UC_TCP_STATUS_OK)
 	{
 	  array = g_array_new (FALSE, TRUE, 1);
 	  g_array_append_vals (array, conn->array->data, conn->array->len);
@@ -385,6 +377,8 @@
   return array;
 }
 
+
+// FIXME rewrite all this function
 /**
  * read_thread:
  * @data: Pointer on a #UCConn structure.
@@ -409,7 +403,17 @@
 			  strlen (conn->request));
       while ((nb_read = gnutls_record_recv (conn->session_gnutls, buffer,
 					    UC_BUFFER_LEN)) > 0)
+      {
+        if (conn->header_request && (tmp = strstr (buffer, "\r\n\r\n")))
+        {
+          *tmp = '\0';
+          g_array_append_vals (conn->array, buffer, strlen (buffer));
+          nb_read = 0;
+          break;
+        }
+
 	g_array_append_vals (conn->array, buffer, nb_read);
+      }
 
       conn->tcp_status = (nb_read == 0) ?
 	UC_TCP_STATUS_OK : UC_TCP_STATUS_ERROR;
@@ -733,9 +737,9 @@
   UCConn *conn = (UCConn *) data;
   struct addrinfo hints; 
   struct addrinfo *res = NULL; 
-  gint err = 0;
   gint *sock = NULL;
   gchar *port = NULL;
+  gint ret = 0;
 
 
   if (conn->ftp_passive)
@@ -756,12 +760,12 @@
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_family = PF_UNSPEC;
 
-  if ((err = getaddrinfo (conn->hostname, port, &hints, &res)) != 0 ||
+  if ((ret = getaddrinfo (conn->hostname, port, &hints, &res)) != 0 ||
       res == NULL)
   {
     /* FIXME conn->tcp_status = UC_TCP_STATUS_BAD_HOSTNAME; */
     g_warning ("Problem with getaddrinfo(): %s:%s\n\t-> %s",
-               conn->hostname, port, gai_strerror (err));
+               conn->hostname, port, gai_strerror (ret));
     conn->tcp_status = UC_TCP_STATUS_ERROR;
   }
   // TODO check all returned addresses for the hostname
@@ -779,9 +783,6 @@
 #ifdef ENABLE_GNUTLS
       if (conn->use_gnutls)
       {
-        gint ret = 0;
-
-
         gnutls_transport_set_ptr (conn->session_gnutls,
                                    (gnutls_transport_ptr) conn->socket);
         do
@@ -796,6 +797,7 @@
       }
 #endif
     }
+
     pthread_cleanup_pop (1); // freeaddrinfo (res)
   }
 

Modified: trunk/src/project.c
===================================================================
--- trunk/src/project.c	2010-01-28 12:28:33 UTC (rev 759)
+++ trunk/src/project.c	2010-01-28 19:57:54 UTC (rev 760)
@@ -100,8 +100,6 @@
   gboolean auth_save;
   gboolean no_urls_args;
   gchar *auth_line;
-  gchar *auth_user;
-  gchar *auth_password;
   GHashTable *cookies;
 }
 static project;
@@ -1618,8 +1616,6 @@
 
   g_free (project.proxy_host), project.proxy_host = NULL;
   g_free (project.auth_line), project.auth_line = NULL;
-  g_free (project.auth_user), project.auth_user = NULL;
-  g_free (project.auth_password), project.auth_password = NULL;
   g_free (project.chroot_path), project.chroot_path = NULL;
 
   uc_project_projects_list_free ();
@@ -2222,18 +2218,6 @@
 }
 
 gchar *
-uc_project_get_auth_user (void)
-{
-  return project.auth_user;
-}
-
-gchar *
-uc_project_get_auth_password (void)
-{
-  return project.auth_password;
-}
-
-gchar *
 uc_project_get_chroot_path (void)
 {
   return project.chroot_path;
@@ -2692,20 +2676,6 @@
 }
 
 void
-uc_project_set_auth_user (const gchar * value)
-{
-  g_free (project.auth_user), project.auth_user = NULL;
-  project.auth_user = g_strdup (value);
-}
-
-void
-uc_project_set_auth_password (const gchar * value)
-{
-  g_free (project.auth_password), project.auth_password = NULL;
-  project.auth_password = g_strdup (value);
-}
-
-void
 uc_project_set_chroot_path (const gchar * value)
 {
   g_free (project.chroot_path), project.chroot_path = NULL;

Modified: trunk/src/project.h
===================================================================
--- trunk/src/project.h	2010-01-28 12:28:33 UTC (rev 759)
+++ trunk/src/project.h	2010-01-28 19:57:54 UTC (rev 760)
@@ -124,8 +124,6 @@
 gboolean uc_project_get_use_proxy (void);
 guint uc_project_get_proxy_port (void);
 gchar *uc_project_get_auth_line (void);
-gchar *uc_project_get_auth_user (void);
-gchar *uc_project_get_auth_password (void);
 gboolean uc_project_get_download_images_content (void);
 gboolean uc_project_get_no_urls_args (void);
 gboolean uc_project_get_download_archives_content (void);
@@ -184,8 +182,6 @@
 void uc_project_set_proxy_host (const gchar * value);
 void uc_project_set_proxy_port (const guint value);
 void uc_project_set_auth_line (const gchar * value);
-void uc_project_set_auth_user (const gchar * value);
-void uc_project_set_auth_password (const gchar * value);
 void uc_project_set_chroot_path (const gchar * value);
 void uc_project_set_no_urls_args (const gboolean value);
 void uc_project_set_download_images_content (const gboolean value);



More information about the Gurlchecker-commits mailing list