diff options
author | Robin Krahl <me@robin-krahl.de> | 2016-06-01 21:51:12 +0200 |
---|---|---|
committer | Robin Krahl <me@robin-krahl.de> | 2016-06-01 21:51:12 +0200 |
commit | 2c1fe44e10b64ed402412c22e1f920833fe34e43 (patch) | |
tree | 8014fccbcac7db98f2855e9d59d68fef616f75c1 | |
parent | 852d0f1cffd53d9327aa38630c295a552a2b0a8e (diff) | |
download | dbfp-2c1fe44e10b64ed402412c22e1f920833fe34e43.tar.gz dbfp-2c1fe44e10b64ed402412c22e1f920833fe34e43.tar.bz2 |
dbfp: move handling of parse_data to dbfp_request
-rw-r--r-- | dbfp.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -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); |