Skip to content

Commit

Permalink
Use Dillo user agent for downloads too
Browse files Browse the repository at this point in the history
Send the user agent to the downloads DPI so we can use the same as
Dillo uses from the http_user_agent option.

See: https://lists.mailman3.com/hyperkitty/list/[email protected]/thread/A6IHJ4TBGHJ3CT2UOMEAROSG2WRTRO6U/
  • Loading branch information
rodarima committed Dec 10, 2024
1 parent 8169f76 commit 4700810
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
19 changes: 11 additions & 8 deletions dpi/downloads.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class DLItem {
Fl_Widget *prTitle, *prGot, *prSize, *prRate, *pr_Rate, *prETA, *prETAt;

public:
DLItem(const char *full_filename, const char *url);
DLItem(const char *full_filename, const char *url, const char *user_agent);
~DLItem();
void child_init();
void father_init();
Expand Down Expand Up @@ -174,7 +174,7 @@ class DLWin {

public:
DLWin(int ww, int wh);
void add(const char *full_filename, const char *url);
void add(const char *full_filename, const char *url, const char *user_agent);
void del(int n_item);
int num();
int num_running();
Expand Down Expand Up @@ -284,7 +284,7 @@ static void prButton_scb(Fl_Widget *, void *cb_data)
i->prButton_cb();
}

DLItem::DLItem(const char *full_filename, const char *url)
DLItem::DLItem(const char *full_filename, const char *url, const char *user_agent)
{
struct stat ss;
const char *p;
Expand Down Expand Up @@ -324,7 +324,6 @@ DLItem::DLItem(const char *full_filename, const char *url)
cookies_path = dStrconcat(dGethomedir(), "/.dillo/cookies.txt", NULL);
dl_argv = new char*[10];
int i = 0;
const char *user_agent = "Dillo/" VERSION;
dl_argv[i++] = (char*)"wget";
if (stat(fullname, &ss) == 0)
init_bytesize = (int)ss.st_size;
Expand Down Expand Up @@ -844,7 +843,7 @@ static void read_req_cb(int req_fd, void *)
int sock_fd;
socklen_t csz;
Dsh *sh = NULL;
char *dpip_tag = NULL, *cmd = NULL, *url = NULL, *dl_dest = NULL;
char *dpip_tag = NULL, *cmd = NULL, *url = NULL, *dl_dest = NULL, *ua = NULL;

/* Initialize the value-result parameter */
csz = sizeof(struct sockaddr_un);
Expand Down Expand Up @@ -898,7 +897,11 @@ static void read_req_cb(int req_fd, void *)
MSG("Failed to parse 'destination' in {%s}\n", dpip_tag);
goto end;
}
dl_win->add(dl_dest, url);
if (!(ua = a_Dpip_get_attr(dpip_tag, "user-agent"))){
MSG("Failed to parse 'user-agent' in {%s}\n", dpip_tag);
goto end;
}
dl_win->add(dl_dest, url, ua);

end:
dFree(cmd);
Expand Down Expand Up @@ -931,9 +934,9 @@ static void dlwin_esc_cb(Fl_Widget *, void *)
* Add a new download request to the main window and
* fork a child to do the job.
*/
void DLWin::add(const char *full_filename, const char *url)
void DLWin::add(const char *full_filename, const char *url, const char *user_agent)
{
DLItem *dl_item = new DLItem(full_filename, url);
DLItem *dl_item = new DLItem(full_filename, url, user_agent);
mDList->add(dl_item);
mPG->insert(*dl_item->get_widget(), 0);

Expand Down
8 changes: 5 additions & 3 deletions src/capi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* File: capi.c
*
* Copyright 2002-2007 Jorge Arellano Cid <[email protected]>
* Copyright 2023 Rodrigo Arias Mallo <[email protected]>
* Copyright 2023-2024 Rodrigo Arias Mallo <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -32,6 +32,7 @@
#include "uicmd.hh"
#include "domain.h"
#include "../dpip/dpip.h"
#include "prefs.h"

/* for testing dpi chat */
#include "bookmark.h"
Expand Down Expand Up @@ -305,8 +306,9 @@ 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",
"download", URL_STR(web->url), web->filename);
cmd = a_Dpip_build_cmd("cmd=%s url=%s destination=%s user-agent=%s",
"download", URL_STR(web->url), web->filename,
prefs.http_user_agent);

} else {
/* For everyone else, the url string is enough... */
Expand Down

0 comments on commit 4700810

Please sign in to comment.