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;