4fc37e35ed1322eaf642b4f4e2a1492e34f5be0e
[strongswan.git] / src / libstrongswan / fetcher / fetcher.h
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup fetcheri fetcher
18 * @{ @ingroup fetcher
19 */
20
21 #ifndef FETCHER_H_
22 #define FETCHER_H_
23
24 typedef struct fetcher_t fetcher_t;
25 typedef enum fetcher_option_t fetcher_option_t;
26
27 #include <stdarg.h>
28
29 #include <library.h>
30
31 /**
32 * Fetching options to use for fetcher_t.fetch() call.
33 */
34 enum fetcher_option_t {
35
36 /**
37 * Data to include in fetch request, e.g. on a HTTP post.
38 * Additional argument is a chunk_t
39 */
40 FETCH_REQUEST_DATA,
41
42 /**
43 * Mime-Type of data included in FETCH_REQUEST_DATA.
44 * Additional argument is a char*.
45 */
46 FETCH_REQUEST_TYPE,
47
48 /**
49 * Timeout to use for fetch, in seconds.
50 * Additional argument is u_int
51 */
52 FETCH_TIMEOUT,
53
54 /**
55 * end of fetching options
56 */
57 FETCH_END,
58 };
59
60 /**
61 * Constructor function which creates fetcher instances.
62 *
63 * @return fetcher instance
64 */
65 typedef fetcher_t* (*fetcher_constructor_t)();
66
67 /**
68 * Fetcher interface, an implementation fetches data from an URL.
69 */
70 struct fetcher_t {
71
72 /**
73 * Fetch data from URI into chunk.
74 *
75 * The fetcher returns NOT_SUPPORTED to indicate that it is uncappable
76 * to handle such URLs. Other return values indicate a failure, and
77 * fetching of that URL gets cancelled.
78 *
79 * @param uri URI to fetch from
80 * @param result chunk which receives allocated data
81 * @return
82 * - SUCCESS if fetch was successful
83 * - NOT_SUPPORTED if fetcher does not support such URLs
84 * - FAILED, NOT_FOUND, PARSE_ERROR on failure
85 */
86 status_t (*fetch)(fetcher_t *this, char *uri, chunk_t *result);
87
88 /**
89 * Set a fetcher option, as defined in fetcher_option_t.
90 *
91 * Arguments passed to options must stay in memory until fetch() returns.
92 *
93 * @param option option to set
94 * @param ... variable argument(s) to option
95 * @return TRUE if option supported, FALSE otherwise
96 */
97 bool (*set_option)(fetcher_t *this, fetcher_option_t option, ...);
98
99 /**
100 * Destroy the fetcher instance.
101 */
102 void (*destroy)(fetcher_t *this);
103 };
104
105 #endif /* FETCHER_H_ @}*/