Mercurial > dillo_port1.3
changeset 1577:404899a37226
Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Also added better error handling.
author | Jorge Arellano Cid <jcid@dillo.org> |
---|---|
date | Tue, 23 Feb 2010 15:03:10 -0300 |
parents | d2cd9e3c5ba5 |
children | 31b53c47cf74 |
files | dpi/vsource.c src/capi.c src/capi.h src/nav.c src/nav.h src/uicmd.cc |
diffstat | 6 files changed, 64 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/dpi/vsource.c Sun Feb 21 19:14:47 2010 +0000 +++ b/dpi/vsource.c Tue Feb 23 15:03:10 2010 -0300 @@ -150,7 +150,7 @@ { 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 @@ 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);
--- a/src/capi.c Sun Feb 21 19:14:47 2010 +0000 +++ b/src/capi.c Tue Feb 23 15:03:10 2010 -0300 @@ -313,6 +313,35 @@ } /* + * 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 @@ 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 @@ } /* - * 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. */
--- a/src/capi.h Sun Feb 21 19:14:47 2010 +0000 +++ b/src/capi.h Tue Feb 23 15:03:10 2010 -0300 @@ -35,8 +35,6 @@ 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);
--- a/src/nav.c Sun Feb 21 19:14:47 2010 +0000 +++ b/src/nav.c Tue Feb 23 15:03:10 2010 -0300 @@ -587,27 +587,3 @@ 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); - } -}
--- a/src/nav.h Sun Feb 21 19:14:47 2010 +0000 +++ b/src/nav.h Tue Feb 23 15:03:10 2010 -0300 @@ -34,7 +34,6 @@ 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 }
--- a/src/uicmd.cc Sun Feb 21 19:14:47 2010 +0000 +++ b/src/uicmd.cc Tue Feb 23 15:03:10 2010 -0300 @@ -997,11 +997,24 @@ } /* - * 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); + } } /*