From b3ebdb3213c020501fd8d3f47151fa5eb6fdb40b Mon Sep 17 00:00:00 2001 From: Jorge Arellano Cid Date: Tue, 23 Feb 2010 15:03:10 -0300 Subject: Handle vsource dpi inside a_Capi_open_url(); more orthogonality. Also added better error handling. --- src/capi.c | 49 +++++++++++++++++++++++++++++++++---------------- src/capi.h | 2 -- src/nav.c | 24 ------------------------ src/nav.h | 1 - src/uicmd.cc | 17 +++++++++++++++-- 5 files changed, 48 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/capi.c b/src/capi.c index af48d664..494c6f88 100644 --- a/src/capi.c +++ b/src/capi.c @@ -312,6 +312,35 @@ static char *Capi_dpi_build_cmd(DilloWeb *web, char *server) return cmd; } +/* + * 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 @@ -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; } @@ -523,22 +556,6 @@ int a_Capi_dpi_send_cmd(DilloUrl *url, void *bw, char *cmd, char *server, return a_Capi_dpi_send_data(url, bw, cmd, strlen(cmd), server, flags); } -/* - * 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. diff --git a/src/capi.h b/src/capi.h index 73556026..d4fae570 100644 --- a/src/capi.h +++ b/src/capi.h @@ -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); diff --git a/src/nav.c b/src/nav.c index 9d668804..107cdd09 100644 --- a/src/nav.c +++ b/src/nav.c @@ -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); - } -} diff --git a/src/nav.h b/src/nav.h index 03948ba7..13439ad0 100644 --- a/src/nav.h +++ b/src/nav.h @@ -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); + } } /* -- cgit v1.2.3