[empathy] Add empathy_make_absolute_url_len to limit the lenght of url string



commit 74a34883df84726ad94359675f3c65a624619dc9
Author: Pierre-Luc Beaudoin <pierre-luc beaudoin collabora co uk>
Date:   Fri Aug 28 10:49:07 2009 -0400

    Add empathy_make_absolute_url_len to limit the lenght of url string
    
    Related to http://bugzilla.gnome.org/show_bug.cgi?id=593207

 libempathy-gtk/empathy-theme-adium.c |    2 +-
 libempathy-gtk/empathy-ui-utils.c    |   37 +++++++++++++++++++++++-----------
 libempathy-gtk/empathy-ui-utils.h    |    2 +
 3 files changed, 28 insertions(+), 13 deletions(-)
---
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c
index f557d07..d7fd017 100644
--- a/libempathy-gtk/empathy-theme-adium.c
+++ b/libempathy-gtk/empathy-theme-adium.c
@@ -328,7 +328,7 @@ theme_adium_parse_body (EmpathyThemeAdium *theme,
 			}
 
 			/* Append the link inside <a href=""></a> tag */
-			real_url = empathy_make_absolute_url (text + s);
+			real_url = empathy_make_absolute_url_len (text + s, e - s);
 
 			g_string_append (string, "<a href=\"");
 			g_string_append (string, real_url);
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index c12cbd1..3089c46 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -1321,33 +1321,46 @@ empathy_get_toplevel_window (GtkWidget *widget)
 	return NULL;
 }
 
-/** empathy_make_absolute_url:
+/** empathy_make_absolute_url_len:
  * @url: an url
+ * @len: a length
  *
- * The URL opening code can't handle schemeless strings, so we try to be
- * smart and add http if there is no scheme or doesn't look like a mail
- * address. This should work in most cases, and let us click on strings
- * like "www.gnome.org".
- *
- * Returns: a newly allocated url with proper mailto: or http:// prefix, use
- * g_free when your are done with it
+ * Same as #empathy_make_absolute_url but for a limited string length
  */
 gchar *
-empathy_make_absolute_url (const gchar *url)
+empathy_make_absolute_url_len (const gchar *url,
+			       guint len)
 {
 	g_return_val_if_fail (url != NULL, NULL);
 
 	if (g_str_has_prefix (url, "ghelp:") ||
 	    g_str_has_prefix (url, "mailto:";) ||
 	    strstr (url, ":/")) {
-		return g_strdup (url);
+		return g_strndup (url, len);
 	}
 
 	if (strstr (url, "@")) {
-		return g_strdup_printf ("mailto:%s";, url);
+		return g_strdup_printf ("mailto:%.*s";, len, url);
 	}
 
-	return g_strdup_printf ("http://%s";, url);
+	return g_strdup_printf ("http://%.*s";, len, url);
+}
+
+/** empathy_make_absolute_url:
+ * @url: an url
+ *
+ * The URL opening code can't handle schemeless strings, so we try to be
+ * smart and add http if there is no scheme or doesn't look like a mail
+ * address. This should work in most cases, and let us click on strings
+ * like "www.gnome.org".
+ *
+ * Returns: a newly allocated url with proper mailto: or http:// prefix, use
+ * g_free when your are done with it
+ */
+gchar *
+empathy_make_absolute_url (const gchar *url)
+{
+	return empathy_make_absolute_url_len (url, strlen (url));
 }
 
 void
diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h
index afb409a..39baeaf 100644
--- a/libempathy-gtk/empathy-ui-utils.h
+++ b/libempathy-gtk/empathy-ui-utils.h
@@ -110,6 +110,8 @@ void        empathy_send_file_with_file_chooser         (EmpathyContact   *conta
 void        empathy_receive_file_with_file_chooser      (EmpathyFTHandler *handler);
 
 gchar *     empathy_make_absolute_url                   (const gchar *url);
+gchar *     empathy_make_absolute_url_len               (const gchar *url,
+							 guint len);
 
 G_END_DECLS
 



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