summaryrefslogtreecommitdiffstats
path: root/src/api.c
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2022-01-31 19:16:55 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2022-01-31 19:16:55 +0100
commitf26b60718163cfe454df368099ca1901acafc047 (patch)
tree5446a485e682f281ee6b46e02ea41d397b05f186 /src/api.c
parentunicode queries now work 0.0.19 (diff)
downloadsear.c-f26b60718163cfe454df368099ca1901acafc047.tar
sear.c-f26b60718163cfe454df368099ca1901acafc047.tar.gz
sear.c-f26b60718163cfe454df368099ca1901acafc047.tar.bz2
sear.c-f26b60718163cfe454df368099ca1901acafc047.tar.lz
sear.c-f26b60718163cfe454df368099ca1901acafc047.tar.xz
sear.c-f26b60718163cfe454df368099ca1901acafc047.tar.zst
sear.c-f26b60718163cfe454df368099ca1901acafc047.zip
Diffstat (limited to '')
-rw-r--r--src/api.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/api.c b/src/api.c
index a366882..1a8c85a 100644
--- a/src/api.c
+++ b/src/api.c
@@ -124,7 +124,10 @@ int sc_fix_url (char ** h) { /* fixes a (result) URL in-place (removes tracking
} /* TODO: be pedantic and remove utm_source and other tracking bullshit */
return 1;
}
-struct sc_query * sc_query_google (const char * s, struct sc_cache * c, struct sc_query * q, SC_OPT_TYPE opt) { /* check4cachedB4 */
+enum sc_return sc_query_google (const char * s, /* breaking change: changed return type */
+ struct sc_cache * c,
+ struct sc_query * q,
+ SC_OPT_TYPE opt) { /* check4cachedB4 */
/* query is in most cases NULL. then it will be allocated and put into sc_cache. otherwise response will be put into passed q. */
/* if query is not NULL, it MUST be initialized */
/*
@@ -144,7 +147,7 @@ struct sc_query * sc_query_google (const char * s, struct sc_cache * c, struct s
* I couldn't find anything with ratings, so we won't parse thouse either yet
* captcha: google knows that this nokia phone we're pretending to be doesn't support javascript, but does not care, and loads an obfuscated captcha anyways that would be hard to defeat for now without some kind of chromium emulation we really don't want.
*/
- int rs = 1;
+ enum sc_return rs = 1;
char * xpath = NULL;
char * descclass = NULL;
char * titleclass = NULL;
@@ -152,7 +155,7 @@ struct sc_query * sc_query_google (const char * s, struct sc_cache * c, struct s
htmlDocPtr xmldoc = NULL;
char * txtdoc = NULL;
if (!s || !c) {
- rs = -1;
+ rs = SC_BADCALL;
goto rc;
}
int qwasgiven = 0;
@@ -168,15 +171,18 @@ struct sc_query * sc_query_google (const char * s, struct sc_cache * c, struct s
free(us);
if (!txtdoc) {
SC_LOG(SC_LOG_ERROR, c, "!txtdoc");
- rs = -2;
+ rs = SC_EMPTYRESPONSE;
+ goto rc;
+ }
+ if (!strstr(txtdoc, "In the meantime, solving the above CAPTCHA will let you continue")) {
+ rs = SC_CAPTCHA;
goto rc;
}
- /* TODO: check if response is asking for a captcha */
if (opt & SC_OPT_IMAGE) {
imageclass = sc_find_class(txtdoc, "{font-family:Roboto,Helvetica,Arial,sans-serif}");
if (!imageclass) {
SC_LOG(SC_LOG_ERROR, c, "!imageclass, txtdoc = %s", txtdoc);
- rs = -3;
+ rs = SC_NOIMGCLASS;
goto rc;
}
} else {
@@ -184,7 +190,7 @@ struct sc_query * sc_query_google (const char * s, struct sc_cache * c, struct s
descclass = sc_find_class(txtdoc, "{word-break:break-word}");
if (!titleclass || !descclass) {
SC_LOG(SC_LOG_ERROR, c, "!titleclass || !descclass, txtdoc = %s", txtdoc);
- rs = -4;
+ rs = SC_NOCLASS;
goto rc;
}
}
@@ -207,7 +213,7 @@ struct sc_query * sc_query_google (const char * s, struct sc_cache * c, struct s
char * hreflink = (char *) xmlGetProp(node, BAD_CAST "href"); /* xmlGetProp copies and allocates */
if (!hreflink) {
SC_LOG(SC_LOG_ERROR, c, "!hreflink");
- rs = -5;
+ rs = SC_NOHREF;
return;
}
if (opt & SC_OPT_IMAGE) {
@@ -218,7 +224,7 @@ struct sc_query * sc_query_google (const char * s, struct sc_cache * c, struct s
xmlFree(hreflink);
if (!imgurl && !imgrefurl) {
SC_LOG(SC_LOG_ERROR, c, "!imgurl && !imgrefurl, txtdoc = %s", txtdoc);
- /* rs = -6; */ /* we continue running not fail because of a single picture */
+ /* rs = -7; */ /* we continue running not fail because of a single picture */
free(imgurl);
free(imgrefurl);
return; /* check! */
@@ -313,5 +319,5 @@ rc:
free(descclass);
free(imageclass);
free(xpath);
- return (rs < 0) ? NULL : q;
+ return rs;
}