From 5a369046a3ea63b062cb373e73c5ab6e4f4bce74 Mon Sep 17 00:00:00 2001 From: PulkoMandy Date: Sat, 23 Jul 2022 23:05:23 +0200 Subject: [PATCH] googlefs: use DuckDuckGo HTML search page This is much easier to parse. The only downside is it is HTTPS only, so we can't do this in the kernel. But it works well as a userlandfs filesystem. TODO: rename and replace the icon. Make it clear that the replies are generated by DuckDuckGo (we can add this in the README file exposed by the filesystem for example) Change-Id: I7cdbe7d71d63f3ab742f21dc55fb9df7b16da7df Reviewed-on: https://review.haiku-os.org/c/haiku/+/5495 Reviewed-by: Adrien Destugues --- .../file_systems/googlefs/google_request.cpp | 8 +----- .../file_systems/googlefs/parse_google_html.c | 28 ++++--------------- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/src/add-ons/kernel/file_systems/googlefs/google_request.cpp b/src/add-ons/kernel/file_systems/googlefs/google_request.cpp index 0bae9ddd20..99dba0e8d2 100644 --- a/src/add-ons/kernel/file_systems/googlefs/google_request.cpp +++ b/src/add-ons/kernel/file_systems/googlefs/google_request.cpp @@ -27,14 +27,8 @@ using namespace BPrivate::Network; #define DO_PUBLISH //#define FAKE_INPUT "/boot/home/devel/drivers/googlefs/log2.html" -//#define TESTURL "http://www.google.com/search?as_q=google+api+&num=50&hl=en&ie=ISO-8859-1&btnG=Google+Search&as_epq=frequently+asked&as_oq=help&as_eq=plop&lr=lang_en&as_ft=i&as_filetype=&as_qdr=m3&as_nlo=&as_nhi=&as_occt=any&as_dt=i&as_sitesearch=" - -//#define BASEURL "http://www.google.com/search?as_q=" -//#define Q "google+api+" -//#define EXTRAURL "&num=50&hl=en&ie=ISO-8859-1&btnG=Google+Search&as_epq=frequently+asked&as_oq=help&as_eq=plop&lr=lang_en&as_ft=i&as_filetype=&as_qdr=m3&as_nlo=&as_nhi=&as_occt=any&as_dt=i&as_sitesearch=" - #define TESTURL "http://www.google.com/search?hl=en&ie=UTF-8&num=50&q=beos" -#define BASEURL "https://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&gws_rd=cr" +#define BASEURL "https://html.duckduckgo.com/html/?kd=-1" #define FMT_NUM "&num=%u" #define FMT_Q "&q=%s" diff --git a/src/add-ons/kernel/file_systems/googlefs/parse_google_html.c b/src/add-ons/kernel/file_systems/googlefs/parse_google_html.c index 314b294ccd..20cde3bfa2 100644 --- a/src/add-ons/kernel/file_systems/googlefs/parse_google_html.c +++ b/src/add-ons/kernel/file_systems/googlefs/parse_google_html.c @@ -31,20 +31,14 @@ int dbgstep = 0; #define PRST {} #endif -//old -//#define G_BEGIN_URL "

" +#define G_BEGIN_URL "" //#define G_BEGIN_NAME #define G_END_NAME "" -#define G_BEGIN_SNIPSET /*""*/"" -#define G_END_SNIPSET "
" +#define G_BEGIN_SNIPSET "" #define G_BEGIN_CACHESIM " " -#define G_URL_PREFIX "http://www.google.com" int google_parse_results(const char *html, size_t htmlsize, long *nextid, struct google_result **results) { @@ -62,16 +56,12 @@ int google_parse_results(const char *html, size_t htmlsize, long *nextid, struct /* sanity checks */ printf(DBG"sanity check...\n"); PRST; - /* google now sends sometimes... */ - if (strstr(html, "") != html) { - if (strstr(html, "") != html) { - if (strstr(html, "Google Search:"); - p = strstr(html, "Google"); + p = strstr(html, "DuckDuckGo"); if (!p) return EINVAL; PRST; p = strstr(html, "url; - if (!strncmp(item, "/url?", 5)) { - strcpy(urlp, G_URL_PREFIX); - itemlen -= strlen(G_URL_PREFIX); - urlp += strlen(G_URL_PREFIX); - printf("plop\n"); - } itemlen = MIN(itemlen, p - item - strlen(G_END_URL)); strncpy(urlp, item, itemlen); urlp[itemlen] = '\0';