&& uri.chr (-1, ' ') == null
&& (URI.is_location (uri) || uri.chr (-1, '.') != null);
}
+ public static GLib.ChecksumType get_fingerprint (string uri,
+ out string checksum, out string label) {
+
+ /* http://foo.bar/baz/spam.eggs#!algo!123456 */
+ unowned string delimiter = "#!md5!";
+ unowned string display = _("MD5-Checksum:");
+ GLib.ChecksumType type = GLib.ChecksumType.MD5;
+ unowned string? fragment = uri.str (delimiter);
+ if (fragment == null) {
+ delimiter = "#!sha1!";
+ display = _("SHA1-Checksum:");
+ type = GLib.ChecksumType.SHA1;
+ fragment = uri.str (delimiter);
+ }
+ if (fragment == null) {
+ type = (GLib.ChecksumType)int.MAX;
+ display = null;
+ }
+
+ if (&checksum != null)
+ checksum = fragment != null
+ ? fragment.offset (delimiter.length) : null;
+ if (&label != null)
+ label = display;
+ return type;
+ }
}
}
WebKitWebDataSource* datasource;
WebKitNetworkRequest* original_request;
const gchar* original_uri;
- gchar** fingerprint;
+ gchar* fingerprint;
+ gchar* fplabel;
#if GTK_CHECK_VERSION (2, 14, 0)
GIcon* icon;
GtkWidget* image;
datasource = webkit_web_frame_get_provisional_data_source (web_frame);
original_request = webkit_web_data_source_get_initial_request (datasource);
original_uri = webkit_network_request_get_uri (original_request);
- fingerprint = g_strsplit (original_uri, "#!md5!", 2);
- if (fingerprint && fingerprint[0] && fingerprint[1])
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s\n%s %s", file_type, _("MD5-Checksum:"), fingerprint[1]);
- else
- {
- g_strfreev (fingerprint);
- fingerprint = g_strsplit (original_uri, "#!sha1!", 2);
- if (fingerprint && fingerprint[0] && fingerprint[1])
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s\n%s %s", file_type, _("SHA1-Checksum:"), fingerprint[1]);
- else
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", file_type);
- }
- g_strfreev (fingerprint);
+ midori_uri_get_fingerprint (original_uri, &fingerprint, &fplabel);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s\n%s %s", file_type, fplabel ? fplabel : "", fingerprint ? fingerprint : "");
+ g_free (fingerprint);
+ g_free (fplabel);
g_free (file_type);
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
g_print ("\nTime needed for URI tests: %f ", g_test_timer_elapsed ());
}
+static void
+magic_uri_fingerprint (void)
+{
+ const gchar* uri;
+ uri = "http://midori-0.4.1.tar.bz2#!md5!33dde203cd71ae2b1d2adcc7f5739f65";
+ g_assert_cmpint (midori_uri_get_fingerprint (uri, NULL, NULL), ==, G_CHECKSUM_MD5);
+ uri = "http://midori-0.4.1.tar.bz2#!md5!33DDE203CD71AE2B1D2ADCC7F5739F65";
+ g_assert_cmpint (midori_uri_get_fingerprint (uri, NULL, NULL), ==, G_CHECKSUM_MD5);
+ uri = "http://midori-0.4.1.tar.bz2#!sha1!0c499459b1049feabf86dce89f49020139a9efd9";
+ g_assert_cmpint (midori_uri_get_fingerprint (uri, NULL, NULL), ==, G_CHECKSUM_SHA1);
+ uri = "http://midori-0.4.1.tar.bz2#!sha256!123456";
+ g_assert_cmpint (midori_uri_get_fingerprint (uri, NULL, NULL), ==, G_MAXINT);
+ uri = "http://midori-0.4.1.tar.bz2#abcdefg";
+ g_assert_cmpint (midori_uri_get_fingerprint (uri, NULL, NULL), ==, G_MAXINT);
+}
+
static void
magic_uri_format (void)
{
g_test_add_func ("/magic-uri/search", magic_uri_search);
g_test_add_func ("/magic-uri/pseudo", magic_uri_pseudo);
g_test_add_func ("/magic-uri/performance", magic_uri_performance);
+ g_test_add_func ("/magic-uri/fingerprint", magic_uri_fingerprint);
g_test_add_func ("/magic-uri/format", magic_uri_format);
g_test_add_func ("/magic-uri/prefetch", magic_uri_prefetch);
#include "midori-transferbar.h"
#include "midori-browser.h"
+#include "midori-core.h"
#include "sokoke.h"
#include <glib/gi18n.h>
MidoriBrowser* browser = midori_browser_get_for_widget (button);
WebKitNetworkRequest* request;
const gchar* original_uri;
- gchar** fingerprint;
+ GChecksumType checksum_type;
+ gchar* fingerprint;
gboolean verified = TRUE;
icon = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
original_uri = g_object_get_data (G_OBJECT (request), "midori-original-uri");
if (!original_uri)
original_uri = webkit_download_get_uri (download);
- fingerprint = g_strsplit (original_uri, "#!md5!", 2);
- if (fingerprint && fingerprint[0] && fingerprint[1])
+ checksum_type = midori_uri_get_fingerprint (original_uri, &fingerprint, NULL);
+ if (fingerprint != NULL)
{
gchar* filename = g_filename_from_uri (
webkit_download_get_destination_uri (download), NULL, NULL);
gchar* contents;
gsize length;
gboolean y = g_file_get_contents (filename, &contents, &length, NULL);
- gchar* checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5,
+ gchar* checksum = g_compute_checksum_for_data (checksum_type,
(guchar*)contents, length);
g_free (filename);
g_free (contents);
/* Checksums are case-insensitive */
- if (!y || g_ascii_strcasecmp (fingerprint[1], checksum) != 0)
+ if (!y || g_ascii_strcasecmp (fingerprint, checksum) != 0)
verified = FALSE;
g_free (checksum);
}
- else
- {
- gchar* filename = g_filename_from_uri (
- webkit_download_get_destination_uri (download), NULL, NULL);
- g_strfreev (fingerprint);
- fingerprint = g_strsplit (original_uri, "#!sha1!", 2);
- if (fingerprint && fingerprint[0] && fingerprint[1])
- {
- gchar* contents;
- gsize length;
- gboolean y = g_file_get_contents (filename, &contents, &length, NULL);
- gchar* checksum = g_compute_checksum_for_data (G_CHECKSUM_SHA1,
- (guchar*)contents, length);
- g_free (contents);
- /* Checksums are case-insensitive */
- if (!y || g_ascii_strcasecmp (fingerprint[1], checksum) != 0)
- verified = FALSE;
- g_free (checksum);
- }
- g_free (filename);
- }
- g_strfreev (fingerprint);
+ g_free (fingerprint);
if (verified)
{
if (!sokoke_is_app_or_private ())