aboutsummaryrefslogtreecommitdiff
path: root/dbfp.h
blob: 82d380114696468b859971949e8efc9bbb0cef2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * Copyright (C) 2016 Robin Krahl <robin.krahl@ireas.org>
 *
 * dbfp.h -- provides access to the timetable API of the Deutsche Bahn
 */

#ifndef DBFP_H_
#define DBFP_H_

#include <curl/curl.h>
#include <stddef.h>
#include <time.h>

#define DBFP_VERSION_MAJOR 0
#define DBFP_VERSION_MINOR 1
#define DBFP_VERSION_PATCH 0

enum dbfp_error {
	DBFP_ERROR_CURL = -1,
	DBFP_ERROR_FORMAT = -2,
	DBFP_ERROR_STRUCTURE = -3,
	DBFP_ERROR_API = -4,
	DBFP_ERROR_PARSE = -5
};

struct dbfp {
	char *key;
	CURL *curl;
};

struct dbfp_location {
	char *name;
	char *id;
	float lon;
	float lat;
};

struct dbfp_departure {
	char *name;
	char *type;
	char *stopid;
	char *stop;
	time_t time;
	char *direction;
	char *track;
};

int dbfp_init(struct dbfp *dbfp, char *key);
void dbfp_close(struct dbfp *dbfp);

void dbfp_location_close(struct dbfp_location *location);
int dbfp_query_location(struct dbfp *dbfp, char *input, size_t *n,
		struct dbfp_location **locations);

void dbfp_departure_close(struct dbfp_departure *departure);
int dbfp_query_departure(struct dbfp *dbfp, struct dbfp_location *location,
		char *location_id, time_t time, size_t *n,
		struct dbfp_departure **departures);

#endif  /* DBFP_H_ */