Hi, Here is a patch which allows wget called from downloads.dpi to use the user agent provided in dillorc, and fallback to the hardcoded Dillo/version agent if not defined. Regards, Alex diff -upr a/dlib/dlib.c b/dlib/dlib.c --- a/dlib/dlib.c Sun Aug 11 22:21:59 2024 +++ b/dlib/dlib.c Tue Sep 3 13:49:00 2024 @@ -922,6 +922,45 @@ char *dGethomedir (void) } /** + * Return the http_user_agent value in a static string + */ +char *dGetuseragent (void) +{ + static char *dillorc = NULL; + dillorc = dStrconcat(dGethomedir(), "/", ".dillo/dillorc", NULL); + FILE *In; + int len; + char *rcline = NULL, *value = NULL, *p; + if ((In = fopen(dillorc, "r")) == NULL) { + DLIB_MSG("dGetuseragent: unable to open dillorc.\n"); + return ("Dillo/" VERSION); + } + while ((rcline = dGetline(In)) != NULL) { + if (strncmp(rcline, "http_user_agent", 15) == 0) + break; + dFree(rcline); + } + fclose(In); + if (!rcline) { + value = ("Dillo/" VERSION); + DLIB_MSG("dGetuseragent: no 'http_user_agent' in dillorc.\n"); + } else { + len = (int) strlen(rcline); + if (len && rcline[len - 1] == '\n') + rcline[len - 1] = 0; + if ((p = strchr(rcline, '='))) { + while (*++p == ' '); + value = dStrdup(p); + } else { + value = ("Dillo/" VERSION); + DLIB_MSG("dGetuseragent: error parsing value in dillorc.\n"); + } + } + dFree(rcline); + return (value); +} + +/** * Get a line from a FILE stream. * Return value: read line on success, NULL on EOF. */ diff -upr a/dlib/dlib.h b/dlib/dlib.h --- a/dlib/dlib.h Sun Aug 11 22:21:59 2024 +++ b/dlib/dlib.h Tue Sep 3 13:49:00 2024 @@ -175,6 +175,7 @@ void dLib_show_messages(bool_t show); */ char *dGetcwd(void); char *dGethomedir(void); +char *dGetuseragent(void); char *dGetline(FILE *stream); int dClose(int fd); int dUsleep(unsigned long us); diff -upr a/dpi/downloads.cc b/dpi/downloads.cc --- a/dpi/downloads.cc Sun Aug 11 22:21:59 2024 +++ b/dpi/downloads.cc Tue Sep 3 13:49:06 2024 @@ -45,6 +45,7 @@ #include "config.h" #include "dpiutil.h" #include "../dpip/dpip.h" +#include "../dlib/dlib.h" /* * Debugging macros @@ -324,7 +325,7 @@ DLItem::DLItem(const char *full_filename, const char * cookies_path = dStrconcat(dGethomedir(), "/.dillo/cookies.txt", NULL); dl_argv = new char*[10]; int i = 0; - const char *user_agent = "Dillo/" VERSION; + const char *user_agent = dGetuseragent(); dl_argv[i++] = (char*)"wget"; if (stat(fullname, &ss) == 0) init_bytesize = (int)ss.st_size;
On Tue, Sep 03, 2024 at 01:51:18PM +0200, a1ex@dismail.de wrote:
Hi,
Here is a patch which allows wget called from downloads.dpi to use the user agent provided in dillorc, and fallback to the hardcoded Dillo/version agent if not defined.
Thanks Alex!, I'll queue it. Best, Rodrigo.
Hi, I wanted to remind about this patch. Is there anything preventing it from going in? This can be considered a privacy leak, since Dillo does not honor the user-specified agent for downloads. Thanks, Alex PS: I'm still maintaining this directory of Dillo-friendly services if anyone has any suggestions or sites to add: https://alex.envs.net/dillectory <a1ex@dismail.de> wrote:
Hi,
Here is a patch which allows wget called from downloads.dpi to use the user agent provided in dillorc, and fallback to the hardcoded Dillo/version agent if not defined.
Regards, Alex
diff -upr a/dlib/dlib.c b/dlib/dlib.c --- a/dlib/dlib.c Sun Aug 11 22:21:59 2024 +++ b/dlib/dlib.c Tue Sep 3 13:49:00 2024 @@ -922,6 +922,45 @@ char *dGethomedir (void) }
/** + * Return the http_user_agent value in a static string + */ +char *dGetuseragent (void) +{ + static char *dillorc = NULL; + dillorc = dStrconcat(dGethomedir(), "/", ".dillo/dillorc", NULL); + FILE *In; + int len; + char *rcline = NULL, *value = NULL, *p; + if ((In = fopen(dillorc, "r")) == NULL) { + DLIB_MSG("dGetuseragent: unable to open dillorc.\n"); + return ("Dillo/" VERSION); + } + while ((rcline = dGetline(In)) != NULL) { + if (strncmp(rcline, "http_user_agent", 15) == 0) + break; + dFree(rcline); + } + fclose(In); + if (!rcline) { + value = ("Dillo/" VERSION); + DLIB_MSG("dGetuseragent: no 'http_user_agent' in dillorc.\n"); + } else { + len = (int) strlen(rcline); + if (len && rcline[len - 1] == '\n') + rcline[len - 1] = 0; + if ((p = strchr(rcline, '='))) { + while (*++p == ' '); + value = dStrdup(p); + } else { + value = ("Dillo/" VERSION); + DLIB_MSG("dGetuseragent: error parsing value in dillorc.\n"); + } + } + dFree(rcline); + return (value); +} + +/** * Get a line from a FILE stream. * Return value: read line on success, NULL on EOF. */ diff -upr a/dlib/dlib.h b/dlib/dlib.h --- a/dlib/dlib.h Sun Aug 11 22:21:59 2024 +++ b/dlib/dlib.h Tue Sep 3 13:49:00 2024 @@ -175,6 +175,7 @@ void dLib_show_messages(bool_t show); */ char *dGetcwd(void); char *dGethomedir(void); +char *dGetuseragent(void); char *dGetline(FILE *stream); int dClose(int fd); int dUsleep(unsigned long us); diff -upr a/dpi/downloads.cc b/dpi/downloads.cc --- a/dpi/downloads.cc Sun Aug 11 22:21:59 2024 +++ b/dpi/downloads.cc Tue Sep 3 13:49:06 2024 @@ -45,6 +45,7 @@ #include "config.h" #include "dpiutil.h" #include "../dpip/dpip.h" +#include "../dlib/dlib.h"
/* * Debugging macros @@ -324,7 +325,7 @@ DLItem::DLItem(const char *full_filename, const char * cookies_path = dStrconcat(dGethomedir(), "/.dillo/cookies.txt", NULL); dl_argv = new char*[10]; int i = 0; - const char *user_agent = "Dillo/" VERSION; + const char *user_agent = dGetuseragent(); dl_argv[i++] = (char*)"wget"; if (stat(fullname, &ss) == 0) init_bytesize = (int)ss.st_size;
Hi, On Thu, Nov 28, 2024 at 07:02:01PM +0100, Rodrigo Arias wrote:
Hi,
I wanted to remind about this patch. Is there anything preventing it from going in?
Mostly, lack of time. I wanted to move the prefs logic so it can be used from the dpis, and we don't need to reimplement the parsing. But not sure how hard that would be.
What about this: https://github.com/dillo-browser/dillo/pull/319 Patch: https://github.com/dillo-browser/dillo/pull/319.patch So we avoid parsing the preferences again. It works fine with UA with spaces, even if the %s looks like it won't. Best, Rodrigo.
participants (2)
-
a1ex@dismail.de
-
Rodrigo Arias