[Gurlchecker-commits] r743 - trunk/src

esaracco at users.labs.libre-entreprise.org esaracco at users.labs.libre-entreprise.org
Mon Jan 25 21:05:49 CET 2010


Author: esaracco
Date: 2010-01-25 20:05:49 +0000 (Mon, 25 Jan 2010)
New Revision: 743

Modified:
   trunk/src/application.c
   trunk/src/check.c
   trunk/src/url.c
   trunk/src/utils.c
   trunk/src/web_site.c
Log:
Code cleaning.


Modified: trunk/src/application.c
===================================================================
--- trunk/src/application.c	2010-01-25 08:28:22 UTC (rev 742)
+++ trunk/src/application.c	2010-01-25 20:05:49 UTC (rev 743)
@@ -3668,7 +3668,6 @@
   /* This is a URL instead of a local file */
   if (uc_url_is_valid (file_real))
     {
-      gchar *proto = NULL;
       UCLinkProperties *prop = NULL;
       gchar *file_content = NULL;
       gchar *project_host = NULL;
@@ -3678,37 +3677,6 @@
       gchar *args = NULL;
       gchar *src = NULL;
 
-      proto = uc_url_get_protocol (file_real);
-
-      if (strcmp (proto, UC_PROTOCOL_HTTPS) != 0 &&
-	  strcmp (proto, UC_PROTOCOL_HTTP) != 0 &&
-	  strcmp (proto, UC_PROTOCOL_FTP) != 0)
-	{
-	  uc_application_dialog_show (_
-				      ("The URL you entered was not "
-				       "understoud. \n"
-				       "<i>For the moment gURLChecker only "
-				       "support a few protocols for bookmarks "
-				       "checking</i>."), GTK_MESSAGE_ERROR);
-
-	  g_free (proto), proto = NULL;
-	  g_free (file_real), file_real = NULL;
-
-	  return;
-	}
-
-      if (!uc_url_is_valid (file_real))
-	{
-	  uc_application_dialog_show (_
-				      ("Please, check URL syntax and try "
-				       "again."), GTK_MESSAGE_ERROR);
-
-	  g_free (proto), proto = NULL;
-	  g_free (file_real), file_real = NULL;
-
-	  return;
-	}
-
       /* Get the file on the network and save it on local */
       project_host = uc_url_get_hostname (NULL, file_real);
       uc_project_set_current_host (project_host);
@@ -3717,7 +3685,7 @@
       g_free (project_host), project_host = NULL;
 
       prop = uc_check_link_properties_node_new ();
-      prop->protocol = g_strdup (proto);
+      prop->protocol = uc_url_get_protocol (file_real);
       prop->h_name = host;
       prop->port = uc_url_get_port (file_real);
       prop->path = path;
@@ -3730,7 +3698,6 @@
 
       g_free (file_content), file_content = NULL;
       g_free (port), port = NULL;
-      g_free (proto), proto = NULL;
       g_free (file_real), file_real = NULL;
 
       src = uc_utils_convert_uid2file (prop->uid);
@@ -3743,11 +3710,9 @@
 	  uc_utils_copy (src, file_real);
 	}
       else
-	uc_application_dialog_show (_
-				    ("A problem occured when retrieving remote "
-				     "bookmarks file.\n"
-				     "<i>Try to pump up the timeout delay</i>."),
-				    GTK_MESSAGE_ERROR);
+	uc_application_dialog_show (
+          _("A problem occured when retrieving remote bookmarks file.\n"
+            "<i>Try to pump up the timeout delay</i>."), GTK_MESSAGE_ERROR);
 
       g_free (src), src = NULL;
 
@@ -3765,12 +3730,10 @@
   /* This is a local file */
   else if (!g_file_test (file_real, G_FILE_TEST_EXISTS))
     {
-      uc_application_dialog_show (_
-				  ("Either the file is not correct "
-				   "or your don't have appropriate "
-				   "rights on it.\n"
-				   "<b>Please choose a valid bookmarks "
-				   "file</b>."), GTK_MESSAGE_ERROR);
+      uc_application_dialog_show (
+        _("Either the file is not correct or your don't have appropriate "
+          "rights on it.\n"
+          "<b>Please choose a valid bookmarks file</b>."), GTK_MESSAGE_ERROR);
 
       g_free (file_real), file_real = NULL;
 

Modified: trunk/src/check.c
===================================================================
--- trunk/src/check.c	2010-01-25 08:28:22 UTC (rev 742)
+++ trunk/src/check.c	2010-01-25 20:05:49 UTC (rev 743)
@@ -2564,7 +2564,7 @@
       (uc_project_get_check_chroot ())? prop->path : NULL);
   }
 
-  // Ff we are in chroot mode (just this directory and its subdirectories,
+  // If we are in chroot mode (just this directory and its subdirectories,
   // or just local links)
   if (!uc_check_chroot_authorized (prop->h_name, prop->protocol, prop->path))
     goto error_handler;

Modified: trunk/src/url.c
===================================================================
--- trunk/src/url.c	2010-01-25 08:28:22 UTC (rev 742)
+++ trunk/src/url.c	2010-01-25 20:05:49 UTC (rev 743)
@@ -292,15 +292,20 @@
   else
     normalized_url = g_strdup (url);
 
-  g_free (host), host = NULL;
-  g_free (port), port = NULL;
-  g_free (path), path = NULL;
-  g_free (args), args = NULL;
+  if (host || port || path || args)
+  {
+    g_free (host), host = NULL;
+    g_free (port), port = NULL;
+    g_free (path), path = NULL;
+    g_free (args), args = NULL;
+  }
+
   g_free (protocol), protocol = NULL;
 
   return normalized_url;
 }
 
+
 /**
  * uc_url_add_protocol:
  * @proto: The protocol to add.
@@ -313,12 +318,11 @@
 gchar *
 uc_url_add_protocol (const gchar * proto, const gchar * host)
 {
-  if ((strstr (host, "://")))
-    return g_strdup (host);
-
-  return g_strconcat (proto, "://", host, NULL);
+  return (strstr (host, "://") != NULL) ?
+    g_strdup (host) : g_strconcat (proto, "://", host, NULL);
 }
 
+
 /**
  * uc_url_get_hostname:
  * @current_host: The current host.
@@ -332,21 +336,33 @@
 gchar *
 uc_url_get_hostname (const gchar * current_host, const gchar * url)
 {
-  const char *b = NULL;
-  const char *e = NULL;
+  const gchar *b = NULL;
+  const gchar *e = NULL;
+  gchar *ret = NULL;
 
-  if (!url || !(b = strstr (url, "://")))
-    return (current_host) ? g_strdup (current_host) :
-      (uc_project_get_type () == UC_PROJECT_TYPE_LOCAL_FILE) ?
-      g_strdup ("") : NULL;;
 
-  b += 3;
-  if (!(e = strpbrk (b, ":/")))
-    return strdup (b);
+  if (url == NULL || (b = strstr (url, "://")) == NULL)
+  {
+    if (current_host != NULL)
+      ret = g_strdup (current_host);
+    else if (uc_project_get_type () == UC_PROJECT_TYPE_LOCAL_FILE)
+      ret = g_strdup ("");
+    else
+      ret = NULL;
+  }
+  else
+  {
+    b += 3;
+    if ((e = strpbrk (b, ":/")) == NULL)
+      ret =  g_strdup (b);
+    else
+      ret = uc_utils_strdup_delim (b, e);
+  }
 
-  return uc_utils_strdup_delim (b, e);
+  return ret;
 }
 
+
 /**
  * uc_url_parse:
  * @current_host: The current host.
@@ -376,6 +392,7 @@
   gchar *url = NULL;
   gboolean ret = TRUE;
 
+
   url = uc_utils_replace (rurl, "&amp;", "&");
   project_host = uc_project_get_current_host ();
 
@@ -546,6 +563,7 @@
   return ret;
 }
 
+
 /**
  * uc_url_get_port:
  * @url: The URI.
@@ -559,24 +577,38 @@
 {
   gchar *p1 = NULL;
   gchar *p2 = NULL;
+  gchar *ret = NULL;
 
-  if (!(p1 = strstr (url, "://")))
-    return g_strdup (UC_URL_DEFAULT_PORT);
 
-  p1 += 3;
-  if (!(p2 = strchr (p1, ':')))
-    return g_strdup (((!g_ascii_strncasecmp (url, UC_PROTOCOL_HTTPS,
-					     strlen (UC_PROTOCOL_HTTPS))) ?
-		      UC_URL_DEFAULT_SSL_PORT : UC_URL_DEFAULT_PORT));
-  p2++;
+  if ((p1 = strstr (url, "://")) == NULL)
+    ret = g_strdup (UC_URL_DEFAULT_PORT);
+  else
+  {
+    p1 += 3;
+    if ((p2 = strchr (p1, ':')) == NULL)
+    {
+      if (g_ascii_strncasecmp (url, UC_PROTOCOL_HTTPS,
+                               strlen (UC_PROTOCOL_HTTPS)) == 0)
+        ret = g_strdup (UC_URL_DEFAULT_SSL_PORT);
+      else
+        ret = g_strdup (UC_URL_DEFAULT_PORT);
+    }
+    else
+    {
+      ++p2;
+  
+      p1 = p2;
+      while (isdigit ((gint) *p2))
+        ++p2;
+  
+      ret = uc_utils_strdup_delim (p1, p2);
+    }
+  }
+  
+  return ret;
+}
 
-  p1 = p2;
-  while (isdigit ((int) *p2))
-    p2++;
 
-  return uc_utils_strdup_delim (p1, p2);
-}
-
 /**
  * uc_url_get_protocol:
  * @url: The URI.
@@ -593,22 +625,27 @@
   gchar **split = NULL;
   gchar *ret = NULL;
 
-  /* search only for ":", and not "://" because we want also pseudo protocols
-   * like "mailto:" */
-  if (!strchr (url, ':'))
-    ret =
-      (!strcmp (uc_project_get_current_port (), UC_URL_DEFAULT_SSL_PORT)) ?
-      g_strdup (UC_PROTOCOL_HTTPS) : g_strdup (UC_PROTOCOL_HTTP);
+
+  // Search only for ":", and not "://" because we want also pseudo protocols
+  // like "mailto:"
+  if (strchr (url, ':') == NULL)
+  {
+    if (strcmp (uc_project_get_current_port (), UC_URL_DEFAULT_SSL_PORT) == 0)
+      ret = g_strdup (UC_PROTOCOL_HTTPS);
+    else
+      ret = g_strdup (UC_PROTOCOL_HTTP);
+  }
   else
-    {
-      split = g_strsplit (url, ":", 0);
-      ret = g_utf8_strdown (split[0], -1);
-      g_strfreev (split), split = NULL;
-    }
+  {
+    split = g_strsplit (url, ":", 0);
+    ret = g_utf8_strdown (split[0], -1);
+    g_strfreev (split), split = NULL;
+  }
 
   return ret;
 }
 
+
 /**
  * uc_url_extract_url_from_local_path:
  * @path: The path from which to extract URL.
@@ -623,50 +660,47 @@
 {
   const gchar *begin = NULL;
 
-  if (!(begin = strstr (path, UC_PROTOCOL_HTTPS "://")) &&
-      !(begin = strstr (path, UC_PROTOCOL_HTTP "://")) &&
-      !(begin = strstr (path, UC_PROTOCOL_FTP "://")))
+
+  if ((begin = strstr (path, UC_PROTOCOL_HTTPS "://")) == NULL &&
+      (begin = strstr (path, UC_PROTOCOL_HTTP "://")) == NULL &&
+      (begin = strstr (path, UC_PROTOCOL_FTP "://")) == NULL)
     return NULL;
 
   return uc_utils_strdup_delim (begin, &path[strlen (path)]);
 }
 
+
 /**
  * uc_url_is_valid:
  * @url: The URI.
  * 
- * Check the validity of a given url.
+ * Quikly (loosly) check the validity of a given url.
  *
  * Returns: %TRUE if the given URI is valid.
  */
 gboolean
 uc_url_is_valid (const gchar * url)
 {
-  gchar *test = NULL;
-  gchar *host = NULL;
-  gchar *proto = NULL;
+  GURI *uri = NULL;
+  gchar *ip = NULL;
   gboolean ret = FALSE;
 
-  proto = uc_url_get_protocol (url);
-  if (!strcmp (proto, UC_PROTOCOL_FILE))
-    {
-      ret = TRUE;
-      goto end;
-    }
 
-  if (url == NULL || strlen (url) == 0 ||
-      !(host = uc_url_get_hostname (NULL, url)))
-    goto end;
+  uri = gnet_uri_new (url);
 
-  if (!(test = uc_utils_get_ip (host)))
-    goto end;
+  if (uri->scheme != NULL &&
+      g_ascii_strcasecmp (uri->scheme, UC_PROTOCOL_FILE) == 0)
+    ret = TRUE;
+  else if (uri->hostname == NULL)
+    ret = FALSE;
+  else if (g_ascii_strcasecmp (uri->scheme, UC_PROTOCOL_HTTP) != 0 &&
+           g_ascii_strcasecmp (uri->scheme, UC_PROTOCOL_HTTPS) != 0 &&
+           g_ascii_strcasecmp (uri->scheme, UC_PROTOCOL_FTP) != 0)
+    ret = FALSE;
+  else if ((ret = ((ip = uc_utils_get_ip (uri->hostname)) != NULL)))
+    g_free (ip), ip = NULL;
 
-  ret = TRUE;
+  gnet_uri_delete (uri);
 
-end:
-  g_free (proto), proto = NULL;
-  g_free (host), host = NULL;
-  g_free (test), test = NULL;
-
   return ret;
 }

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2010-01-25 08:28:22 UTC (rev 742)
+++ trunk/src/utils.c	2010-01-25 20:05:49 UTC (rev 743)
@@ -936,6 +936,7 @@
   return ret;
 }
 
+
 /**
  * uc_utils_get_ip:
  * @host: Host to work with.
@@ -951,15 +952,17 @@
   struct hostent *serverHostEnt = NULL;
   gchar *buffer = NULL;
 
+
   if ((serverHostEnt = gethostbyname (host)) != NULL)
-    buffer = g_strdup (inet_ntoa
-		       (*((struct in_addr *) serverHostEnt->h_addr_list[0])));
-  else
-    buffer = (inet_addr (host) != -1) ? g_strdup (host) : g_strdup ("");
+    buffer = g_strdup (
+      inet_ntoa (*((struct in_addr *) serverHostEnt->h_addr_list[0])));
+  else if (inet_addr (host) != -1)
+    buffer = g_strdup (host);
 
   return buffer;
 }
 
+
 /**
  * uc_utils_string_format4display:
  * @label: Label to format.

Modified: trunk/src/web_site.c
===================================================================
--- trunk/src/web_site.c	2010-01-25 08:28:22 UTC (rev 742)
+++ trunk/src/web_site.c	2010-01-25 20:05:49 UTC (rev 743)
@@ -102,9 +102,9 @@
 
       if (lp != NULL && accept)
       {
+        lp->normalized_url = normalized_url;
         list = g_list_append (list,
                                uc_check_register_link (normalized_url, lp));
-        lp->normalized_url = normalized_url;
 
         // Run security tests if requested */
         if (uc_project_get_security_checks ("any"))
@@ -213,17 +213,19 @@
 {
   GList *item = NULL;
 
+
   item = g_list_first (list);
   while (UC_CHECK_PARSER_WHILE_CONDITION)
     {
       UCLinkProperties *prop = (UCLinkProperties *) item->data;
 
+
+      item = g_list_next (item);
+
       uc_web_site_refresh_link_real (prop);
 
       if (prop->childs != NULL && !uc_check_is_main_page (prop))
 	uc_web_site_refresh_branch_real (prop->childs);
-
-      item = g_list_next (item);
     }
 }
 
@@ -345,6 +347,7 @@
   if (new_prop != NULL && accept)
     {
       new_prop->normalized_url = g_strdup (prop->url);
+// FIXME
       (gpointer) uc_check_register_link (uc_project_get_url (), prop);
 
       list = uc_web_site_get_links_real (new_prop, new_prop->h_name, 0);
@@ -429,6 +432,7 @@
 	      GList *item2 = NULL;
 	      g_list_free (lp->childs), lp->childs = NULL;
 	      lp->childs = lp1->childs;
+              // FIXME
 	      lp->depth_level = 0;
 
 	      /* on parcours les anciens enfant et on leur donne le
@@ -438,6 +442,7 @@
 		{
 		  UCLinkProperties *lp2 = (UCLinkProperties *) item2->data;
 		  lp2->parent = lp;
+                  // FIXME
 		  lp2->depth_level = 1;
 		  item2 = g_list_next (item2);
 		}
@@ -620,6 +625,7 @@
       new_status = g_hash_table_lookup (new_prop->header, UC_HEADER_STATUS);
 
       new_prop->normalized_url = normalized_url;
+// FIXME
       (gpointer) uc_check_register_link (normalized_url, prop);
 
       /* we do not check other site that the main site */



More information about the Gurlchecker-commits mailing list