Added simple fetcher tool to test fetcher implementations
[strongswan.git] / scripts / fetch.c
1 /*
2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
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 #include <stdio.h>
17 #include <unistd.h>
18
19 #include <library.h>
20 #include <debug.h>
21
22 int main(int argc, char *argv[])
23 {
24 chunk_t res;
25
26 library_init(NULL);
27 atexit(library_deinit);
28 lib->plugins->load(lib->plugins, NULL, PLUGINS);
29
30 if (argc != 2)
31 {
32 fprintf(stderr, "usage: %s <url>\n", argv[0]);
33 }
34 if (lib->fetcher->fetch(lib->fetcher, argv[1], &res, FETCH_END) == SUCCESS)
35 {
36 ignore_result(write(1, res.ptr, res.len));
37 free(res.ptr);
38 return 0;
39 }
40 return 1;
41 }