googlefs: fix parsing
This commit is contained in:
@@ -35,7 +35,7 @@
|
|||||||
#define FMT_Q "&q=%s"
|
#define FMT_Q "&q=%s"
|
||||||
|
|
||||||
/* parse_google_html.c */
|
/* parse_google_html.c */
|
||||||
extern int google_parse_results(const char *html, size_t htmlsize, struct google_result **results);
|
extern int google_parse_results(const char *html, size_t htmlsize, long *nextid, struct google_result **results);
|
||||||
|
|
||||||
// move that to ksocket inlined
|
// move that to ksocket inlined
|
||||||
static int kinet_aton(const char *in, struct in_addr *addr)
|
static int kinet_aton(const char *in, struct in_addr *addr)
|
||||||
@@ -150,7 +150,7 @@ status_t google_request_process(struct google_request *req)
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
#endif /* FAKE_INPUT */
|
#endif /* FAKE_INPUT */
|
||||||
err = count = google_parse_results(req->cnx->data, req->cnx->datalen, &req->results);
|
err = count = google_parse_results(req->cnx->data, req->cnx->datalen, &req->nextid, &req->results);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto err_get;
|
goto err_get;
|
||||||
#ifdef DO_PUBLISH
|
#ifdef DO_PUBLISH
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ struct google_request {
|
|||||||
char *query_string;
|
char *query_string;
|
||||||
struct http_cnx *cnx;
|
struct http_cnx *cnx;
|
||||||
struct google_result *results;
|
struct google_result *results;
|
||||||
|
long nextid;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* those are quite arbitrary values */
|
/* those are quite arbitrary values */
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ int dbgstep = 0;
|
|||||||
//#define G_BEGIN_URL "<p class=g><a class=l href=\""
|
//#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 class=l href=\""
|
||||||
//#define G_BEGIN_URL "<div class=g><a href=\""
|
//#define G_BEGIN_URL "<div class=g><a href=\""
|
||||||
#define G_BEGIN_URL "<li class=g><h3 class=r><a href=\""
|
#define G_BEGIN_URL "<h3 class=\"r\"><a href=\""
|
||||||
//#define G_END_URL "\">"
|
//#define G_END_URL "\">"
|
||||||
#define G_END_URL "\" class=l>"
|
#define G_END_URL "\">"
|
||||||
//#define G_BEGIN_NAME
|
//#define G_BEGIN_NAME
|
||||||
#define G_END_NAME "</a>"
|
#define G_END_NAME "</a>"
|
||||||
#define G_BEGIN_SNIPSET /*"<td class=j>"*/"<font size=-1>"
|
#define G_BEGIN_SNIPSET /*"<td class=j>"*/"<font size=-1>"
|
||||||
@@ -44,15 +44,14 @@ int dbgstep = 0;
|
|||||||
#define G_BEGIN_CACHESIM " <a class=fl href=\""
|
#define G_BEGIN_CACHESIM " <a class=fl href=\""
|
||||||
#define G_END_CACHESIM "\">"
|
#define G_END_CACHESIM "\">"
|
||||||
|
|
||||||
int google_parse_results(const char *html, size_t htmlsize, struct google_result **results)
|
int google_parse_results(const char *html, size_t htmlsize, long *nextid, struct google_result **results)
|
||||||
{
|
{
|
||||||
struct google_result *res = NULL, *nres = NULL, *prev = NULL;
|
struct google_result *res = NULL, *nres = NULL, *prev = NULL;
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
char *nextresult = NULL;
|
char *nextresult = NULL;
|
||||||
long numres = 0;
|
long numres = 0;
|
||||||
long maxres = 0;
|
long maxres = 1000;
|
||||||
long startid = 0;
|
//long startid = 0;
|
||||||
long lastid = 0;
|
|
||||||
int done = 0;
|
int done = 0;
|
||||||
int err = ENOMEM;
|
int err = ENOMEM;
|
||||||
|
|
||||||
@@ -63,8 +62,10 @@ int google_parse_results(const char *html, size_t htmlsize, struct google_result
|
|||||||
PRST;
|
PRST;
|
||||||
/* google now sends <!doctype html><head> sometimes... */
|
/* google now sends <!doctype html><head> sometimes... */
|
||||||
if (strstr(html, "<!doctype html><head>") != html) {
|
if (strstr(html, "<!doctype html><head>") != html) {
|
||||||
if (strstr(html, "<html><head>") != html)
|
if (strstr(html, "<html><head>") != html) {
|
||||||
return EINVAL;
|
if (strstr(html, "<!doctype html><html ") != html)
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PRST;
|
PRST;
|
||||||
// p = strstr(html, "<title>Google Search:");
|
// p = strstr(html, "<title>Google Search:");
|
||||||
@@ -74,26 +75,12 @@ int google_parse_results(const char *html, size_t htmlsize, struct google_result
|
|||||||
p = strstr(html, "<body");
|
p = strstr(html, "<body");
|
||||||
if (!p) return EINVAL;
|
if (!p) return EINVAL;
|
||||||
PRST;
|
PRST;
|
||||||
p = strstr(html, "> Results <b>");
|
|
||||||
if (!p) return EINVAL;
|
|
||||||
PRST;
|
|
||||||
p+= strlen("> Results <b>");
|
|
||||||
startid = strtol(p, &p, 10);
|
|
||||||
if (!p) return EINVAL;
|
|
||||||
PRST;
|
|
||||||
p = strstr(html, "</b> - <b>");
|
|
||||||
p+= strlen("</b> - <b>");
|
|
||||||
if (!p) return EINVAL;
|
|
||||||
PRST;
|
|
||||||
lastid = strtol(p, &p, 10);
|
|
||||||
if (!p) return EINVAL;
|
|
||||||
PRST;
|
|
||||||
maxres = lastid - startid + 1;
|
|
||||||
printf(DBG"getting %ld results (%ld to %ld)\n", maxres, startid, lastid);
|
|
||||||
|
|
||||||
|
/*
|
||||||
p = strstr(html, "Search Results<");
|
p = strstr(html, "Search Results<");
|
||||||
if (!p) return EINVAL;
|
if (!p) return EINVAL;
|
||||||
PRST;
|
PRST;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
printf(DBG"parsing...\n");
|
printf(DBG"parsing...\n");
|
||||||
@@ -111,7 +98,7 @@ int google_parse_results(const char *html, size_t htmlsize, struct google_result
|
|||||||
goto err0;
|
goto err0;
|
||||||
}
|
}
|
||||||
memset(nres, 0, sizeof(struct google_result));
|
memset(nres, 0, sizeof(struct google_result));
|
||||||
nres->id = startid + numres; //- 1;
|
nres->id = (*nextid)++; //- 1;
|
||||||
|
|
||||||
PRST;
|
PRST;
|
||||||
/* find url */
|
/* find url */
|
||||||
@@ -273,13 +260,14 @@ int main(int argc, char **argv)
|
|||||||
size_t len;
|
size_t len;
|
||||||
char *p;
|
char *p;
|
||||||
int err;
|
int err;
|
||||||
|
long nextid = 0;
|
||||||
|
|
||||||
p = malloc(BUFSZ+8);
|
p = malloc(BUFSZ+8);
|
||||||
len = read(0, p+4, BUFSZ);
|
len = read(0, p+4, BUFSZ);
|
||||||
p[BUFSZ+4-1] = '\0';
|
p[BUFSZ+4-1] = '\0';
|
||||||
*(uint32 *)p = 0xa5a5a5a5;
|
*(uint32 *)p = 0xa5a5a5a5;
|
||||||
*(uint32 *)(&p[BUFSZ+4]) = 0x5a5a5a5a;
|
*(uint32 *)(&p[BUFSZ+4]) = 0x5a5a5a5a;
|
||||||
err = google_parse_results(p+4, len, &results);
|
err = google_parse_results(p+4, len, &nextid, &results);
|
||||||
printf("error 0x%08lx\n", err);
|
printf("error 0x%08lx\n", err);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user