diff --git a/src/IO/http.cc b/src/IO/http.cc index 9187750..f422bf6 100644 --- a/src/IO/http.cc +++ b/src/IO/http.cc @@ -386,7 +386,7 @@ static Dstr *Http_make_content_type(const DilloUrl *url) static Dstr *Http_make_query_str(DilloWeb *web, bool_t use_proxy, bool_t use_tls) { char *ptr, *cookies, *referer, *auth; - const DilloUrl *url = web->url; + const DilloUrl *url = web->url.get(); Dstr *query = dStr_new(""), *request_uri = dStr_new(""), *proxy_auth = dStr_new(""); @@ -416,7 +416,7 @@ static Dstr *Http_make_query_str(DilloWeb *web, bool_t use_proxy, bool_t use_tls URL_QUERY(url)); } - cookies = a_Cookies_get_query(url, web->requester); + cookies = a_Cookies_get_query(url, web->requester.get()); auth = a_Auth_get_auth_str(url, request_uri->str); referer = Http_get_referer(url); if (URL_FLAGS(url) & URL_Post) { @@ -807,15 +807,15 @@ static int Http_get(ChainLink *Info, void *Data1) S->Info = Info; /* Proxy support */ - if (Http_must_use_proxy(URL_HOST(S->web->url))) { + if (Http_must_use_proxy(URL_HOST(S->web->url.get()))) { url = HTTP_Proxy; S->flags |= HTTP_SOCKET_USE_PROXY; } else { - url = S->web->url; + url = S->web->url.get(); } hostname = dStrdup(URL_HOST(url)); S->connect_port = URL_PORT(url); - S->url = a_Url_dup(S->web->url).release(); + S->url = a_Url_dup(S->web->url.get()).release(); if (!dStrAsciiCasecmp(URL_SCHEME(S->url), "https")) S->flags |= HTTP_SOCKET_TLS; diff --git a/src/cache.cc b/src/cache.cc index b1412ab..ae8d42c 100644 --- a/src/cache.cc +++ b/src/cache.cc @@ -377,7 +377,7 @@ int a_Cache_open_url(void *web, CA_Callback_t Call, void *CbData) int ClientKey; CacheEntry_t *entry; DilloWeb *Web = reinterpret_cast< DilloWeb * >( web ); - DilloUrl *Url = Web->url; + DilloUrl *Url = Web->url.get(); if (URL_FLAGS(Url) & URL_E2EQuery) { /* remove current entry */ diff --git a/src/capi.cc b/src/capi.cc index d8760dd..5098c85 100644 --- a/src/capi.cc +++ b/src/capi.cc @@ -307,12 +307,12 @@ static char *Capi_dpi_build_cmd(DilloWeb *web, char *server) if (strcmp(server, "downloads") == 0) { /* let the downloads server get it */ cmd = a_Dpip_build_cmd("cmd=%s url=%s destination=%s user-agent=%s", - "download", URL_STR(web->url), web->filename, + "download", URL_STR(web->url.get()), web->filename.value().c_str(), prefs.http_user_agent); } else { /* For everyone else, the url string is enough... */ - cmd = a_Dpip_build_cmd("cmd=%s url=%s", "open_url", URL_STR(web->url)); + cmd = a_Dpip_build_cmd("cmd=%s url=%s", "open_url", URL_STR(web->url.get())); } return cmd; } @@ -371,13 +371,13 @@ static bool_t Capi_request_permitted(DilloWeb *web) */ if (dStrAsciiCasecmp(s, "https") && dStrAsciiCasecmp(s, "data")) { MSG("capi: Blocked mixed content: %s -> %s\n", - URL_STR(web->requester), URL_STR(web->url)); + URL_STR(web->requester.get()), URL_STR(web->url.get())); return FALSE; } } - if (a_Capi_get_flags(web->url) & CAPI_IsCached || - a_Domain_permit(web->requester, web->url)) { + if (a_Capi_get_flags(web->url.get()) & CAPI_IsCached || + a_Domain_permit(web->requester.get(), web->url.get())) { permit = TRUE; } return permit; @@ -401,53 +401,53 @@ int a_Capi_open_url(DilloWeb *web, CA_Callback_t Call, void *CbData) if (Capi_request_permitted(web)) { /* reload test */ - reload = (!(a_Capi_get_flags(web->url) & CAPI_IsCached) || - (URL_FLAGS(web->url) & URL_E2EQuery)); + reload = (!(a_Capi_get_flags(web->url.get()) & CAPI_IsCached) || + (URL_FLAGS(web->url.get()) & URL_E2EQuery)); if (web->flags & WEB_Download) { /* download request: if cached save from cache, else * for http, ftp or https, use the downloads dpi */ - if (a_Capi_get_flags_with_redirection(web->url) & CAPI_IsCached) { - if (web->filename) { - if ((web->stream = fopen(web->filename, "w"))) { + if (a_Capi_get_flags_with_redirection(web->url.get()) & CAPI_IsCached) { + if (web->filename.has_value()) { + if ((web->stream = fopen(web->filename.value().c_str(), "w"))) { use_cache = 1; } else { MSG_WARN("Cannot open \"%s\" for writing: %s.\n", - web->filename, dStrerror(errno)); + web->filename.value().c_str(), dStrerror(errno)); } } - } else if (a_Cache_download_enabled(web->url)) { + } else if (a_Cache_download_enabled(web->url.get())) { server = const_cast< char * >( "downloads" ); cmd = Capi_dpi_build_cmd(web, server); - a_Capi_dpi_send_cmd(web->url, web->bw, cmd, server, 1); + a_Capi_dpi_send_cmd(web->url.get(), web->bw, cmd, server, 1); dFree(cmd); } else { MSG_WARN("Ignoring download request for '%s': " "not in cache and not downloadable.\n", - URL_STR(web->url)); + URL_STR(web->url.get())); } - } else if (Capi_url_uses_dpi(web->url, &server)) { + } else if (Capi_url_uses_dpi(web->url.get(), &server)) { /* dpi request */ - if ((safe = a_Capi_dpi_verify_request(web->bw, web->url))) { + if ((safe = a_Capi_dpi_verify_request(web->bw, web->url.get()))) { if (dStrAsciiCasecmp(scheme, "dpi") == 0) { if (strcmp(server, "vsource") == 0) { /* allow "view source" reload upon user request */ } else { /* make the other "dpi:/" prefixed urls always reload. */ - a_Url_set_flags(web->url, URL_FLAGS(web->url) |URL_E2EQuery); + a_Url_set_flags(web->url.get(), URL_FLAGS(web->url.get()) |URL_E2EQuery); reload = 1; } } if (reload) { - a_Capi_conn_abort_by_url(web->url); + a_Capi_conn_abort_by_url(web->url.get()); /* Send dpip command */ - _MSG("a_Capi_open_url, reload url='%s'\n", URL_STR(web->url)); + _MSG("a_Capi_open_url, reload url='%s'\n", URL_STR(web->url.get())); cmd = Capi_dpi_build_cmd(web, server); - a_Capi_dpi_send_cmd(web->url, web->bw, cmd, server, 1); + a_Capi_dpi_send_cmd(web->url.get(), web->bw, cmd, server, 1); dFree(cmd); if (strcmp(server, "vsource") == 0) { - Capi_dpi_send_source(web->bw, web->url); + Capi_dpi_send_source(web->bw, web->url.get()); } } use_cache = 1; @@ -468,9 +468,9 @@ int a_Capi_open_url(DilloWeb *web, CA_Callback_t Call, void *CbData) } #endif if (reload) { - a_Capi_conn_abort_by_url(web->url); + a_Capi_conn_abort_by_url(web->url.get()); /* create a new connection and start the CCC operations */ - conn = Capi_conn_new(web->url, web->bw, const_cast< char * >( "http" ), const_cast< char * >( "none" )); + conn = Capi_conn_new(web->url.get(), web->bw, const_cast< char * >( "http" ), const_cast< char * >( "none" )); /* start the reception branch before the query one because the DNS * may callback immediately. This may avoid a race condition. */ a_Capi_ccc(OpStart, 2, BCK, a_Chain_new(), conn, const_cast< char * >( "http" )); diff --git a/src/dicache.cc b/src/dicache.cc index 697d07a..5123bb5 100644 --- a/src/dicache.cc +++ b/src/dicache.cc @@ -402,10 +402,10 @@ static void *Dicache_image(int ImgType, const char *MimeType, void *Ptr, a_Image_ref(web->Image); } - DicEntry = a_Dicache_get_entry(web->url, DIC_Last); + DicEntry = a_Dicache_get_entry(web->url.get(), DIC_Last); if (!DicEntry) { /* Create an entry for this image... */ - DicEntry = Dicache_add_entry(web->url); + DicEntry = Dicache_add_entry(web->url.get()); /* Attach a decoder */ if (ImgType == DIC_Jpeg) { DicEntry->Decoder = (CA_Callback_t)a_Jpeg_callback; @@ -494,7 +494,7 @@ void a_Dicache_callback(int Op, CacheClient_t *Client) uint_t i; DilloWeb *Web = reinterpret_cast< DilloWeb * >( Client->Web ); DilloImage *Image = Web->Image; - DICacheEntry *DicEntry = a_Dicache_get_entry(Web->url, DIC_Last); + DICacheEntry *DicEntry = a_Dicache_get_entry(Web->url.get(), DIC_Last); dReturn_if_fail ( DicEntry != NULL ); diff --git a/src/html.cc b/src/html.cc index 70350cd..836eff1 100644 --- a/src/html.cc +++ b/src/html.cc @@ -223,7 +223,7 @@ std::unique_ptr< DilloUrl > a_Html_url_new(DilloHtml *html, void *a_Html_text(const char *Type, void *P, CA_Callback_t *Call, void **Data) { DilloWeb *web = (DilloWeb*)P; - DilloHtml *html = new DilloHtml(web->bw, web->url, Type); + DilloHtml *html = new DilloHtml(web->bw, web->url.get(), Type); *Data = (void*)html; *Call = (CA_Callback_t)Html_callback; diff --git a/src/nav.cc b/src/nav.cc index 264b4fd..fc2e878 100644 --- a/src/nav.cc +++ b/src/nav.cc @@ -551,7 +551,7 @@ void a_Nav_save_url(BrowserWindow *bw, const DilloUrl *url, const char *filename) { DilloWeb *Web = a_Web_new(bw, url, NULL); - Web->filename = dStrdup(filename); + Web->filename = filename; Web->flags |= WEB_Download; /* TODO: keep track of this client */ a_Capi_open_url(Web, Nav_save_cb, Web); diff --git a/src/web.cc b/src/web.cc index 82c94d4..97cad60 100644 --- a/src/web.cc +++ b/src/web.cc @@ -73,7 +73,7 @@ int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web, style::createPerLength (0)); /* Set a style for the widget */ - StyleEngine styleEngine (layout, Web->url, Web->url, bw->zoom); + StyleEngine styleEngine (layout, Web->url.get(), Web->url.get(), bw->zoom); styleEngine.startElement ("body", Web->bw); std::unique_ptr< Widget > dw( reinterpret_cast< Widget* >( viewer(Type, Web, Call, Data) ) ); @@ -87,10 +87,10 @@ int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web, /* Set the page title with the bare filename (e.g. for images), * HTML pages with a tag will overwrite it later */ - const char *p = strrchr(URL_STR(Web->url), '/'); + const char *p = strrchr(URL_STR(Web->url.get()), '/'); a_UIcmd_set_page_title(Web->bw, p ? p+1 : ""); - a_UIcmd_set_location_text(Web->bw, URL_STR(Web->url)); + a_UIcmd_set_location_text(Web->bw, URL_STR(Web->url.get())); /* Reset both progress bars */ a_UIcmd_set_page_prog(Web->bw, 0, 2); a_UIcmd_set_img_prog(Web->bw, 0, 0, 2); @@ -111,7 +111,7 @@ int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web, } MSG_HTTP("'%s' cannot be displayed as image; has media type '%s'\n", - URL_STR(Web->url), Type); + URL_STR(Web->url.get()), Type); return -1; } @@ -125,12 +125,11 @@ DilloWeb* a_Web_new(BrowserWindow *bw, const DilloUrl *url, DilloWeb *web= new DilloWeb; _MSG(" a_Web_new: ValidWebs ==> %d\n", dList_length(ValidWebs)); - web->url = a_Url_dup(url).release(); - web->requester = a_Url_dup(requester).release(); + web->url = a_Url_dup(url); + web->requester = a_Url_dup(requester); web->bw = bw; web->flags = 0; web->Image = NULL; - web->filename = NULL; web->stream = NULL; web->SavedBytes = 0; web->bgColor = 0x000000; /* Dummy value will be overwritten @@ -153,10 +152,7 @@ int a_Web_valid(DilloWeb *web) void a_Web_free(DilloWeb *web) { if (!web) return; - delete web->url; - delete web->requester; a_Image_unref(web->Image); - dFree(web->filename); dList_remove(ValidWebs, (void *)web); _MSG("a_Web_free: ValidWebs=%d\n", dList_length(ValidWebs)); delete web; diff --git a/src/web.hh b/src/web.hh index b687aeb..61fafdc 100644 --- a/src/web.hh +++ b/src/web.hh @@ -20,16 +20,16 @@ extern "C" { struct DilloWeb { - DilloUrl *url; /**< Requested URL */ - DilloUrl *requester; /**< URL that caused this request, or - **< NULL if user-initiated. */ + std::unique_ptr< DilloUrl > url; /**< Requested URL */ + std::unique_ptr< DilloUrl > requester; /**< URL that caused this request, or + **< NULL if user-initiated. */ BrowserWindow *bw; /**< The requesting browser window [reference] */ int flags; /**< Additional info */ DilloImage *Image; /**< For image urls [reference] */ int32_t bgColor; /**< for image backgrounds */ - char *filename; /**< Variables for Local saving */ + std::optional< std::string > filename; /**< Variables for Local saving */ FILE *stream; int SavedBytes; };