diff options
author | Robin Krahl <me@robin-krahl.de> | 2016-02-26 01:40:47 +0100 |
---|---|---|
committer | Robin Krahl <me@robin-krahl.de> | 2016-02-26 01:40:47 +0100 |
commit | 745c643c2f900c8efeb0ac0a8ea3a519b3a790ac (patch) | |
tree | 1cd84b4666b1ba13b5d81699cc940db52c1f6ee8 | |
download | dbfp-745c643c2f900c8efeb0ac0a8ea3a519b3a790ac.tar.gz dbfp-745c643c2f900c8efeb0ac0a8ea3a519b3a790ac.tar.bz2 |
initial commit
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | LICENSE | 21 | ||||
-rw-r--r-- | Makefile | 38 | ||||
-rw-r--r-- | README | 40 | ||||
-rw-r--r-- | dbfp.c | 31 | ||||
-rw-r--r-- | dbfp.h | 19 | ||||
-rw-r--r-- | dbfp_check.c | 43 |
7 files changed, 195 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0aa9426 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.swp +*.o +*.so @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Robin Krahl <robin.krahl@ireas.org> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7b67ed2 --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +CFLAGS = -std=c99 -pedantic -Wall -fPIC +CPPFLAGS = -D_XOPEN_SOURCE=700 + +ifneq ($(DEBUG), 1) + CFLAGS += -O2 + CPPFLAGS += -DNDEBUG +else + CFLAGS += -g + CPPFLAGS += -DDEBUG +endif + +CHECK_CFLAGS = $(shell pkg-config check --cflags) +CHECK_LDLIBS = $(shell pkg-config check --libs) + +.PHONY: all check clean + +all: libdbfp.so + +check: libdbfp.so dbfp_check + LD_LIBRARY_PATH=. ./dbfp_check + +clean: + $(RM) libdbfp.so + $(RM) dbfp_check + $(RM) dbfp.o dbfp_check.o + +libdbfp.so: LDFLAGS = -shared +libdbfp.so: dbfp.o + $(CC) $(LDFLAGS) -o $@ $^ + +dbfp_check: LDLIBS += $(CHECK_LDLIBS) +dbfp_check: LDLIBS += -ldbfp -L. +dbfp_check: dbfp_check.o + +dbfp.o: dbfp.c dbfp.h + +dbfp_check.o: CFLAGS += $(CHECK_CFLAGS) +dbfp_check.o: dbfp_check.c dbfp.h dbfp.c @@ -0,0 +1,40 @@ +dbfp -- DB timetable API +======================== + +This C library provides an interface to the timetable API of the Deutsche Bahn +(*Fahrplan-API*). This API exposes information on stations, departures, +arrivals and routes. + +Compiling and installation +-------------------------- + +Build dbfp with `make`. You can run the test suite with `make check`. + +Usage +----- + +*missing* + +Data +---- + +The DB timetable API was released on February 25th, 2016. At the moment, you +need an API key to access the data. For more information on the API, have a +look at the [API description][api] and at the [technical documentation][doc]. + +Bugs and hacking +---------------- + +If you encouter a bug or if you want to contribute to dbfp, please send an +email to <dbfp-dev@ireas.org>. + +License +------- + +The library is published under the terms of the MIT/X11 license (see LICENSE). +The timetable data is published under the terms of the [Creative Commons +Attribution 4.0 International license][cc-by-sa-4.0]. + +[api]: http://data.deutschebahn.com/apis/fahrplan/ +[doc]: http://data.deutschebahn.com/apis/fahrplan/Fpl-API-Doku-Open-Data-BETA-0_81.pdf +[cc-by-sa-4.0]: https://creativecommons.org/licenses/by/4.0/ @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2016 Robin Krahl <robin.krahl@ireas.org> + * + * dbfp.c + */ + +#include "dbfp.h" + +#include <errno.h> +#include <stdlib.h> +#include <string.h> + +int dbfp_init(struct dbfp *dbfp, char *key) +{ + if (!dbfp || !key) + return EINVAL; + + dbfp->key = strdup(key); + if (!dbfp->key) + return ENOMEM; + + return 0; +} + +void dbfp_close(struct dbfp *dbfp) +{ + if (!dbfp) + return; + + free(dbfp->key); +} @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2016 Robin Krahl <robin.krahl@ireas.org> + * + * dbfp.h + */ + +#ifndef DBFP_H_ +#define DBFP_H_ + +#define DBFP_BASE_URL "http://open-api.bahn.de/bin/rest.exe" + +struct dbfp { + char *key; +}; + +int dbfp_init(struct dbfp *dbfp, char *key); +void dbfp_close(struct dbfp *dbfp); + +#endif /* DBFP_H_ */ diff --git a/dbfp_check.c b/dbfp_check.c new file mode 100644 index 0000000..35daaef --- /dev/null +++ b/dbfp_check.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2016 Robin Krahl <robin.krahl@ireas.org> + * + * dbfp_check.c + */ + +#include <check.h> +#include <stdlib.h> + +#include "dbfp.h" + +START_TEST(test_dbfp_create) +{ + struct dbfp dbfp; + int err; + + err = dbfp_init(&dbfp, "test-key"); + ck_assert_int_eq(err, 0); + ck_assert_str_eq(dbfp.key, "test-key"); + dbfp_close(&dbfp); +} +END_TEST + +int main(int argc, char **argv) +{ + int num_failed = 0; + Suite *s; + SRunner *sr; + TCase *tc_basic; + + s = suite_create("dbfp"); + sr = srunner_create(s); + + tc_basic = tcase_create("basic"); + tcase_add_test(tc_basic, test_dbfp_create); + suite_add_tcase(s, tc_basic); + + srunner_run_all(sr, CK_ENV); + num_failed = srunner_ntests_failed(sr); + srunner_free(sr); + + return (num_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} |