pluto and scepclient use the curl and ldap fetcher plugins
[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 * HTTP header to be sent with with the fetch request.
50 * Additional argument is a char*.
51 */
52 FETCH_REQUEST_HEADER,
53
54 /**
55 * Use HTTP Version 1.0 instead of 1.1.
56 * No additional argument is needed.
57 */
58 FETCH_HTTP_VERSION_1_0,
59
60 /**
61 * Timeout to use for fetch, in seconds.
62 * Additional argument is u_int
63 */
64 FETCH_TIMEOUT,
65
66 /**
67 * end of fetching options
68 */
69 FETCH_END,
70 };
71
72 /**
73 * Constructor function which creates fetcher instances.
74 *
75 * @return fetcher instance
76 */
77 typedef fetcher_t* (*fetcher_constructor_t)();
78
79 /**
80 * Fetcher interface, an implementation fetches data from an URL.
81 */
82 struct fetcher_t {
83
84 /**
85 * Fetch data from URI into chunk.
86 *
87 * The fetcher returns NOT_SUPPORTED to indicate that it is uncappable
88 * to handle such URLs. Other return values indicate a failure, and
89 * fetching of that URL gets cancelled.
90 *
91 * @param uri URI to fetch from
92 * @param result chunk which receives allocated data
93 * @return
94 * - SUCCESS if fetch was successful
95 * - NOT_SUPPORTED if fetcher does not support such URLs
96 * - FAILED, NOT_FOUND, PARSE_ERROR on failure
97 */
98 status_t (*fetch)(fetcher_t *this, char *uri, chunk_t *result);
99
100 /**
101 * Set a fetcher option, as defined in fetcher_option_t.
102 *
103 * Arguments passed to options must stay in memory until fetch() returns.
104 *
105 * @param option option to set
106 * @param ... variable argument(s) to option
107 * @return TRUE if option supported, FALSE otherwise
108 */
109 bool (*set_option)(fetcher_t *this, fetcher_option_t option, ...);
110
111 /**
112 * Destroy the fetcher instance.
113 */
114 void (*destroy)(fetcher_t *this);
115 };
116
117 #endif /** FETCHER_H_ @}*/