aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJorge Arellano Cid <jcid@dillo.org>2010-03-04 15:00:15 -0300
committerJorge Arellano Cid <jcid@dillo.org>2010-03-04 15:00:15 -0300
commitc3b2aac9a1bd180a2289dbea0a396b195c552fdf (patch)
tree34ba0b7c21f702e66190f0d5893ccc16753f8e7a /src
parent7e200117f6e4156a0375ef7eb3deaa9f2d626847 (diff)
Fix "view source" for POST URLs
Diffstat (limited to 'src')
-rw-r--r--src/capi.c20
-rw-r--r--src/capi.h1
-rw-r--r--src/nav.c7
-rw-r--r--src/nav.h1
-rw-r--r--src/uicmd.cc11
5 files changed, 32 insertions, 8 deletions
diff --git a/src/capi.c b/src/capi.c
index 8c170f7a..987efc3d 100644
--- a/src/capi.c
+++ b/src/capi.c
@@ -57,7 +57,8 @@ enum {
/* 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 @@ void a_Capi_conn_abort_by_url(const DilloUrl *url)
/* ------------------------------------------------------------------------- */
/*
+ * 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 @@ static char *Capi_dpi_build_cmd(DilloWeb *web, char *server)
}
/*
- * 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 @@ static void Capi_dpi_send_source(BrowserWindow *bw, DilloUrl *url)
"DpiError", "Page is NOT cached");
a_Capi_dpi_send_cmd(NULL, bw, cmd, server, 0);
}
- a_Url_free(s_url);
dFree(cmd);
}
diff --git a/src/capi.h b/src/capi.h
index 4472baa4..8a0c7095 100644
--- a/src/capi.h
+++ b/src/capi.h
@@ -35,6 +35,7 @@ int a_Capi_dpi_send_data(const DilloUrl *url, void *bw,
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);
diff --git a/src/nav.c b/src/nav.c
index 107cdd09..57fdad48 100644
--- a/src/nav.c
+++ b/src/nav.c
@@ -587,3 +587,10 @@ void a_Nav_unref_buf(const DilloUrl *Url)
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);
+}
diff --git a/src/nav.h b/src/nav.h
index 13439ad0..b557be2e 100644
--- a/src/nav.h
+++ b/src/nav.h
@@ -34,6 +34,7 @@ void a_Nav_save_url(BrowserWindow *bw,
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
}
diff --git a/src/uicmd.cc b/src/uicmd.cc
index a4e1f372..dd5478cc 100644
--- a/src/uicmd.cc
+++ b/src/uicmd.cc
@@ -1004,15 +1004,24 @@ void a_UIcmd_view_page_source(BrowserWindow *bw, const DilloUrl *url)
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);
}
}