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 <[email protected]>
This commit is contained in:
PulkoMandy
2023-02-08 18:42:37 +00:00
committed by waddlesplash
parent a780ec8653
commit 5a369046a3
2 changed files with 7 additions and 29 deletions
@@ -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"
@@ -31,20 +31,14 @@ int dbgstep = 0;
#define PRST {}
#endif
//old
//#define G_BEGIN_URL "<p class=g><a class=l href=\""
//#define G_BEGIN_URL "<div class=g><a class=l href=\""
//#define G_BEGIN_URL "<div class=g><a href=\""
#define G_BEGIN_URL "<h3 class=\"r\"><a href=\""
//#define G_END_URL "\">"
#define G_BEGIN_URL "<a rel=\"nofollow\" class=\"result__a\" href=\""
#define G_END_URL "\">"
//#define G_BEGIN_NAME
#define G_END_NAME "</a>"
#define G_BEGIN_SNIPSET /*"<td class=j>"*/"<font size=-1>"
#define G_END_SNIPSET "<br>"
#define G_BEGIN_SNIPSET "<a class=\"result__snippet\""
#define G_END_SNIPSET "</a>"
#define G_BEGIN_CACHESIM " <a class=fl href=\""
#define G_END_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 <!doctype html><head> sometimes... */
if (strstr(html, "<!doctype html><head>") != html) {
if (strstr(html, "<html><head>") != html) {
if (strstr(html, "<!doctype html><html ") != html)
return EINVAL;
}
if (strstr(html, "<!DOCTYPE html PUBLIC") != html) {
return EINVAL;
}
PRST;
// p = strstr(html, "<title>Google Search:");
p = strstr(html, "Google");
p = strstr(html, "DuckDuckGo");
if (!p) return EINVAL;
PRST;
p = strstr(html, "<body");
@@ -124,12 +114,6 @@ int google_parse_results(const char *html, size_t htmlsize, long *nextid, struct
//printf(DBG"[%ld] found token 2\n", numres);
itemlen = GR_MAX_URL-1;
urlp = nres->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';