From 08c86a69b964ca5183fbf93bf29d9a2fa9cb7663 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 8 Jun 2016 19:29:23 +0200 Subject: dbfp: add man pages for dbfp_location_close, dbfp_query_location --- man/dbfp_query_location.pod | 119 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 man/dbfp_query_location.pod (limited to 'man/dbfp_query_location.pod') diff --git a/man/dbfp_query_location.pod b/man/dbfp_query_location.pod new file mode 100644 index 0000000..6aa586d --- /dev/null +++ b/man/dbfp_query_location.pod @@ -0,0 +1,119 @@ +=head1 NAME + +dbfp_query_loation - get a list of stations matching a string from the DB +timetable API + +=head1 SYNOPSIS + + #include + + int dbfp_query_location(struct dbfp *dbfp, char *input, size_t *n, + struct dbfp_location **locations); + +=head1 DESCRIPTION + +B queries a list of locations matching the query string +I from the DB timetable API using the connection metadata stored in +I. The number of results is stored in I. The results are stored in +I. The memory for the I is allocated by the function. +The stored array contains exactly I elements, and is not NULL terminated. + +I, I, I and I must not be NULL. I must have +been initialized with I. The elements in I should be +closed with I. I should be freed by the +caller. + +If the query fails, the values of I and I are set to 0 and NULL +respectively. + +The B structure is defined as: + + struct dbfp_location { + char *name; + char *id; + float lon; + float lat; + }; + +I is the name of the station. I is the DB id of the station. It +seems to be an integer, but this is not guaranteed. I and I are the +coordinates of the station. + +=head1 RETURN VALUE + +B returns zero if successful, or a non-zero error code. +Positive error codes are from I, negative error codes are specific +to dbfp. + +=head1 ERRORS + +=over + +=item EINVAL + +if I, I, I or I is NULL + +=item ENOMEM + +if there is not enough memory to store the results of the query + +=item DBFP_ERROR_CURL + +if an error occured during the preparation or execution of the network request + +=item DBFP_ERROR_FORMAT + +if an error occurs during the formatting of the URL + +=item DBFP_ERROR_PARSE + +if an error occurs during the parsing of the XML response + +=item DBFP_ERROR_STRUCTURE + +if the API response has not the expected structure + +=back + +=head1 EXAMPLE + + #include + #include + #include + #include + + int main(int argc, char **argv) + { + int err = 0; + struct dbfp dbfp; + struct dbfp_location *locations = NULL; + size_t n = 0; + size_t i; + + err = dbfp_init(&dbfp, "API key"); + if (err) + goto cleanup; + err = dbfp_query_location(&dbfp, "Freibu", &n, &locations); + if (err) + goto cleanup; + + printf("Number of matches: %zu\n", n); + for (i = 0; i < n; i++) + printf("%s: %s (%.2f, %.2f)", locations[i].id, + locations[i].name, locations[i].lon, + locations[i].lat); + + cleanup: + if (err) + printf("An error occured: %s\n", strerror(err)); + for (i = 0; i < n; i++) + dbfp_location_close(&locations[i]); + free(locations); + dbfp_close(&dbfp); + + return err ? EXIT_FAILURE : EXIT_SUCCESS; + } + +=head1 SEE ALSO + +L, L -- cgit v1.2.1