From 2c1fe44e10b64ed402412c22e1f920833fe34e43 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 1 Jun 2016 21:51:12 +0200 Subject: dbfp: move handling of parse_data to dbfp_request --- dbfp.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dbfp.c b/dbfp.c index 57fbcad..d1fd29c 100644 --- a/dbfp.c +++ b/dbfp.c @@ -35,7 +35,7 @@ struct object_data { static int dbfp_parse(void *contents, size_t len, size_t n, void *data); static int dbfp_request(struct dbfp *dbfp, char *service, char *query, - XML_Parser parser); + XML_Parser parser, struct parse_data *pd); static int dbfp_url(struct dbfp *dbfp, char *service, char *query, char **url); static int dbfp_format_url(struct dbfp *dbfp, char **out, const char *format, ...); @@ -135,12 +135,9 @@ int dbfp_query_location_name(struct dbfp *dbfp, char *input, goto cleanup; parser = XML_ParserCreateNS(NULL, '\0'); - XML_SetUserData(parser, &pd); XML_SetElementHandler(parser, location_start, location_end); - err = dbfp_request(dbfp, "location.name", query, parser); - if (pd.error) - err = pd.error; + err = dbfp_request(dbfp, "location.name", query, parser, &pd); if (err) goto cleanup; @@ -187,7 +184,7 @@ static int dbfp_parse(void *contents, size_t len, size_t n, void *data) } static int dbfp_request(struct dbfp *dbfp, char *service, char *query, - XML_Parser parser) + XML_Parser parser, struct parse_data *pd) { int err = 0; char *url = NULL; @@ -196,6 +193,8 @@ static int dbfp_request(struct dbfp *dbfp, char *service, char *query, if (err) goto cleanup; + XML_SetUserData(parser, pd); + curl_easy_setopt(dbfp->curl, CURLOPT_URL, url); curl_easy_setopt(dbfp->curl, CURLOPT_WRITEFUNCTION, dbfp_parse); curl_easy_setopt(dbfp->curl, CURLOPT_WRITEDATA, (void *)parser); @@ -203,6 +202,9 @@ static int dbfp_request(struct dbfp *dbfp, char *service, char *query, if (curl_easy_perform(dbfp->curl) != CURLE_OK) err = DBFP_ERROR_CURL; + if (pd->error) + err = pd->error; + cleanup: free(url); -- cgit v1.2.3