diff options
-rw-r--r-- | dpi/vsource.c | 24 | ||||
-rw-r--r-- | src/capi.c | 49 | ||||
-rw-r--r-- | src/capi.h | 2 | ||||
-rw-r--r-- | src/nav.c | 24 | ||||
-rw-r--r-- | src/nav.h | 1 | ||||
-rw-r--r-- | src/uicmd.cc | 17 |
6 files changed, 64 insertions, 53 deletions
diff --git a/dpi/vsource.c b/dpi/vsource.c index e7c89ab2..f1d6384c 100644 --- a/dpi/vsource.c +++ b/dpi/vsource.c @@ -150,7 +150,7 @@ int main(void) { Dsh *sh; int data_size; - char *dpip_tag, *cmd = NULL, *url = NULL, *size_str = NULL; + char *dpip_tag, *cmd = NULL, *cmd2 = NULL, *url = NULL, *size_str = NULL; char *d_cmd; _MSG("starting...\n"); @@ -193,13 +193,21 @@ int main(void) dFree(d_cmd); dpip_tag = a_Dpip_dsh_read_token(sh, 1); - size_str = a_Dpip_get_attr(dpip_tag, "data_size"); - data_size = strtol(size_str, NULL, 10); - - /* Choose your flavour */ - //send_plain_text(sh, data_size); - //send_numbered_text(sh, data_size); - send_html_text(sh, data_size); + cmd2 = a_Dpip_get_attr(dpip_tag, "cmd"); + if (cmd2) { + if (strcmp(cmd2, "start_send_page") == 0 && + (size_str = a_Dpip_get_attr(dpip_tag, "data_size"))) { + data_size = strtol(size_str, NULL, 10); + /* Choose your flavour */ + //send_plain_text(sh, data_size); + //send_numbered_text(sh, data_size); + send_html_text(sh, data_size); + } else if (strcmp(cmd2, "DpiError") == 0) { + /* Dillo detected an error (other failures just close the socket) */ + a_Dpip_dsh_printf(sh, 0, "Content-type: text/plain\n\n"); + a_Dpip_dsh_printf(sh, 1, "[vsource dpi]: ERROR: Page not cached.\n"); + } + } dFree(cmd); dFree(url); @@ -313,6 +313,35 @@ static char *Capi_dpi_build_cmd(DilloWeb *web, char *server) } /* + * Send this 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)) { + /* 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", + "start_send_page", URL_STR(url), size_str); + a_Capi_dpi_send_cmd(NULL, bw, cmd, server, 0); + a_Capi_dpi_send_data(url, bw, buf, buf_size, server, 0); + } else { + cmd = a_Dpip_build_cmd("cmd=%s msg=%s", + "DpiError", "Page is NOT cached"); + a_Capi_dpi_send_cmd(NULL, bw, cmd, server, 0); + } + a_Url_free(s_url); +} + +/* * Most used function for requesting a URL. * TODO: clean up the ad-hoc bindings with an API that allows dynamic * addition of new plugins. @@ -365,9 +394,13 @@ int a_Capi_open_url(DilloWeb *web, CA_Callback_t Call, void *CbData) if (reload) { a_Capi_conn_abort_by_url(web->url); /* Send dpip command */ + _MSG("a_Capi_open_url, reload url='%s'\n", URL_STR(web->url)); cmd = Capi_dpi_build_cmd(web, server); a_Capi_dpi_send_cmd(web->url, web->bw, cmd, server, 1); dFree(cmd); + if (strcmp(server, "vsource") == 0) { + Capi_dpi_send_source(web->bw, web->url); + } } use_cache = 1; } @@ -524,22 +557,6 @@ int a_Capi_dpi_send_cmd(DilloUrl *url, void *bw, char *cmd, char *server, } /* - * Send this url's source to the "view source" dpi - */ -void a_Capi_dpi_send_source(BrowserWindow *bw, const DilloUrl *url, - char *buf, int buf_size) -{ - char *cmd, size_str[32]; - - /* 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", - "start_send_page", URL_STR(url), size_str); - a_Capi_dpi_send_cmd(NULL, bw, cmd, "vsource", 0); - a_Capi_dpi_send_data(url, bw, buf, buf_size, "vsource", 0); -} - -/* * Remove a client from the cache client queue. * force = also abort the CCC if this is the last client. */ @@ -35,8 +35,6 @@ 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_dpi_send_source(BrowserWindow *bw, const DilloUrl *url, - char *buf, int buf_size); void a_Capi_stop_client(int Key, int force); void a_Capi_conn_abort_by_url(const DilloUrl *url); @@ -587,27 +587,3 @@ void a_Nav_unref_buf(const DilloUrl *Url) a_Capi_unref_buf(Url); } -/* - * Send source to a dpi - */ -void a_Nav_send_source(BrowserWindow *bw, const DilloUrl *url) -{ - char *buf; - int buf_size; - DilloUrl *vs_url; - Dstr *dstr_url; - - if (a_Nav_get_buf(url, &buf, &buf_size)) { - dstr_url = dStr_new("dpi:/vsource/:"); - dStr_append(dstr_url, URL_STR(url)); - - 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); - - /* send the page's source to this dpi connection */ - a_Capi_dpi_send_source(bw, url, buf, buf_size); - a_Nav_unref_buf(url); - } -} @@ -34,7 +34,6 @@ 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_send_source(BrowserWindow *bw, const DilloUrl *url); #ifdef __cplusplus } diff --git a/src/uicmd.cc b/src/uicmd.cc index a93daa25..541122a5 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -997,11 +997,24 @@ void a_UIcmd_copy_urlstr(BrowserWindow *bw, const char *urlstr) } /* - * Show a text window with the URL's source + * Ask the vsource dpi to show this URL's source */ void a_UIcmd_view_page_source(BrowserWindow *bw, const DilloUrl *url) { - a_Nav_send_source(bw, url); + char *buf; + int buf_size; + Dstr *dstr_url; + DilloUrl *vs_url; + + if (a_Nav_get_buf(url, &buf, &buf_size)) { + dstr_url = dStr_new("dpi:/vsource/:"); + dStr_append(dstr_url, URL_STR(url)); + + 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); + } } /* |