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 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'src/capi.c') 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. -- cgit v1.2.3