changeset 1600:f50835ca545e

Fix "view source" for POST URLs
author Jorge Arellano Cid <jcid@dillo.org>
date Thu, 04 Mar 2010 15:00:15 -0300
parents ed63f7b3a242
children 262bb5afd0f1
files src/capi.c src/capi.h src/nav.c src/nav.h src/uicmd.cc
diffstat 5 files changed, 32 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/capi.c	Mon Mar 01 03:04:00 2010 +0000
+++ b/src/capi.c	Thu Mar 04 15:00:15 2010 -0300
@@ -57,7 +57,8 @@
 /* Data list for active dpi connections */
 static Dlist *CapiConns;      /* Data list for active connections; it holds
                                * pointers to capi_conn_t structures. */
-
+/* Last URL asked for view source */
+static DilloUrl *CapiVsUrl = NULL;
 
 /*
  * Forward declarations
@@ -212,6 +213,15 @@
 /* ------------------------------------------------------------------------- */
 
 /*
+ * Store the last URL requested by "view source"
+ */
+void a_Capi_set_vsource_url(const DilloUrl *url)
+{
+   a_Url_free(CapiVsUrl);
+   CapiVsUrl = a_Url_dup(url);
+}
+
+/*
  * Safety test: only allow GET|POST dpi-urls from dpi-generated pages.
  */
 int a_Capi_dpi_verify_request(BrowserWindow *bw, DilloUrl *url)
@@ -318,20 +328,17 @@
 }
 
 /*
- * Send this url's source to the "view source" dpi
+ * Send the requested URL's source to the "view source" dpi
  */
 static void Capi_dpi_send_source(BrowserWindow *bw,  DilloUrl *url)
 {
    char *p, *buf, *cmd, size_str[32], *server="vsource";
    int buf_size;
-   DilloUrl *s_url;
 
    if (!(p = strchr(URL_STR(url), ':')) || !(p = strchr(p + 1, ':')))
       return;
 
-   /* get the source DilloUrl */
-   s_url = a_Url_new(++p, NULL);
-   if (a_Capi_get_buf(s_url, &buf, &buf_size)) {
+   if (a_Capi_get_buf(CapiVsUrl, &buf, &buf_size)) {
       /* send the page's source to this dpi connection */
       snprintf(size_str, 32, "%d", buf_size);
       cmd = a_Dpip_build_cmd("cmd=%s url=%s data_size=%s",
@@ -343,7 +350,6 @@
                              "DpiError", "Page is NOT cached");
       a_Capi_dpi_send_cmd(NULL, bw, cmd, server, 0);
    }
-   a_Url_free(s_url);
    dFree(cmd);
 }
 
--- a/src/capi.h	Mon Mar 01 03:04:00 2010 +0000
+++ b/src/capi.h	Thu Mar 04 15:00:15 2010 -0300
@@ -35,6 +35,7 @@
                          char *data, int data_sz, char *server, int flags);
 int a_Capi_dpi_send_cmd(DilloUrl *url, void *bw, char *cmd, char *server,
                          int flags);
+void a_Capi_set_vsource_url(const DilloUrl *url);
 void a_Capi_stop_client(int Key, int force);
 void a_Capi_conn_abort_by_url(const DilloUrl *url);
 
--- a/src/nav.c	Mon Mar 01 03:04:00 2010 +0000
+++ b/src/nav.c	Thu Mar 04 15:00:15 2010 -0300
@@ -587,3 +587,10 @@
    a_Capi_unref_buf(Url);
 }
 
+/*
+ * Wrapper for a_Capi_set_vsource_url().
+ */
+void a_Nav_set_vsource_url(const DilloUrl *Url)
+{
+   a_Capi_set_vsource_url(Url);
+}
--- a/src/nav.h	Mon Mar 01 03:04:00 2010 +0000
+++ b/src/nav.h	Thu Mar 04 15:00:15 2010 -0300
@@ -34,6 +34,7 @@
                     const DilloUrl *url, const char *filename);
 int a_Nav_get_buf(const DilloUrl *Url, char **PBuf, int *BufSize);
 void a_Nav_unref_buf(const DilloUrl *Url);
+void a_Nav_set_vsource_url(const DilloUrl *Url);
 
 #ifdef __cplusplus
 }
--- a/src/uicmd.cc	Mon Mar 01 03:04:00 2010 +0000
+++ b/src/uicmd.cc	Thu Mar 04 15:00:15 2010 -0300
@@ -1004,15 +1004,24 @@
    int buf_size;
    Dstr *dstr_url;
    DilloUrl *vs_url;
+   static int post_id = 0;
+   char tag[8];
 
    if (a_Nav_get_buf(url, &buf, &buf_size)) {
+      a_Nav_set_vsource_url(url);
       dstr_url = dStr_new("dpi:/vsource/:");
       dStr_append(dstr_url, URL_STR(url));
-
+      if (URL_FLAGS(url) & URL_Post) {
+         /* append a custom string to differentiate POST URLs */
+         post_id = (post_id < 9999) ? post_id + 1 : 0;
+         snprintf(tag, 8, "_%.4d", post_id);
+         dStr_append(dstr_url, tag);
+      }
       vs_url = a_Url_new(dstr_url->str, NULL);
       a_UIcmd_open_url_nt(bw, vs_url, 1);
       a_Url_free(vs_url);
       dStr_free(dstr_url, 1);
+      a_Nav_unref_buf(url);
    }
 }