commit 0a06974c54171bcaea834021a11cdb7f33116953
parent 6da3a96adab9adda3bbc7b61b27f2ac0aa76cba3
Author: Kyle Milz <kmilz@ucalgary.ca>
Date: Mon, 15 Oct 2012 21:47:19 -0600
add cool way to visualize redirects
if any portion of the suffix or prefix matches with the other string of
a redirect, show the similarities and show the differences.
Diffstat:
1 file changed, 38 insertions(+), 9 deletions(-)
diff --git a/src/callbacks.c b/src/callbacks.c
@@ -873,15 +873,44 @@ hist_nav_cb(const Evas_Object *view, Ewk_Navigation_Data *nav_data, void *data)
}
static void
-hist_client_redir_cb(const Evas_Object *vew, const char *source_url, const char *dest_url, void *data)
+hist_redir_cb(const Evas_Object *vew, const char *source_url, const char *dest_url, void *data)
{
- printf("client_redirecion() from %s to %s\n", source_url, dest_url);
-}
+ int prefix, min, suffix, src_len, dest_len;
+
+ src_len = strlen(source_url);
+ dest_len = strlen(dest_url);
+
+ if (src_len < dest_len)
+ min = src_len;
+ else
+ min = dest_len;
+
+ prefix = 0;
+ while (source_url[prefix] == dest_url[prefix] && prefix < min)
+ prefix++;
+
+ suffix = 0;
+ while (source_url[src_len - suffix - 1] == dest_url[dest_len - suffix - 1] && suffix < min)
+ suffix++;
+
+ // printf("redir: prefix = %i, suffix = %i, min = %i\n", prefix, suffix, min);
+
+ if (min - suffix - prefix < 0) {
+ printf("redirecion() from %s to %s\n", source_url, dest_url);
+ return;
+ }
+
+ Eina_Strbuf *buf = eina_strbuf_new();
+ eina_strbuf_append_n(buf, source_url, prefix);
+ eina_strbuf_append(buf, "{");
+ eina_strbuf_append_n(buf, source_url + prefix, src_len - suffix - prefix);
+ eina_strbuf_append(buf, " => ");
+ eina_strbuf_append_n(buf, dest_url + prefix, dest_len - suffix - prefix);
+ eina_strbuf_append(buf, "}");
+ eina_strbuf_append_n(buf, source_url + src_len - suffix, suffix);
+
+ printf("redirection() %s\n", eina_strbuf_string_steal(buf));
-static void
-hist_server_redir_cb(const Evas_Object *vew, const char *source_url, const char *dest_url, void *data)
-{
- printf("server_redirecion() from %s to %s\n", source_url, dest_url);
}
static void
@@ -1075,8 +1104,8 @@ setup_main_callbacks(App_Data *ad, const char *cookie_path)
ewk_context_history_callbacks_set(
context,
hist_nav_cb,
- hist_client_redir_cb,
- hist_server_redir_cb,
+ hist_redir_cb,
+ hist_redir_cb,
hist_title_updated_cb,
hist_visited_cb,
ad