diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-04 09:45:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-04 09:45:03 +0000 |
commit | 7301211bb756c4119d370b6f5f79a9054f2cbe92 (patch) | |
tree | 31b5a7d069cf0e00619a91330f84d1dde53ef859 /src/fs/gnunet-fs.c | |
parent | b3909bc84fbce46df1dc4b3df4140bf1bfa3ae78 (diff) | |
download | gnunet-7301211bb756c4119d370b6f5f79a9054f2cbe92.tar.gz gnunet-7301211bb756c4119d370b6f5f79a9054f2cbe92.zip |
Diffstat (limited to 'src/fs/gnunet-fs.c')
-rw-r--r-- | src/fs/gnunet-fs.c | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/fs/gnunet-fs.c b/src/fs/gnunet-fs.c new file mode 100644 index 000000000..9b3602d73 --- /dev/null +++ b/src/fs/gnunet-fs.c | |||
@@ -0,0 +1,142 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file fs/gnunet-fs.c | ||
22 | * @brief special file-sharing functions | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_fs_service.h" | ||
27 | |||
28 | /** | ||
29 | * Return value. | ||
30 | */ | ||
31 | static int ret; | ||
32 | |||
33 | /** | ||
34 | * Handle to FS service. | ||
35 | */ | ||
36 | static struct GNUNET_FS_Handle *fs; | ||
37 | |||
38 | /** | ||
39 | * Option -i given? | ||
40 | */ | ||
41 | static int list_indexed_files; | ||
42 | |||
43 | /** | ||
44 | * Option -v given? | ||
45 | */ | ||
46 | static int verbose; | ||
47 | |||
48 | |||
49 | /** | ||
50 | * Shutdown this process. | ||
51 | * | ||
52 | * @param cls unused | ||
53 | * @param tc unused | ||
54 | */ | ||
55 | static void | ||
56 | do_shutdown (void *cls, | ||
57 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
58 | { | ||
59 | GNUNET_FS_stop (fs); | ||
60 | fs = NULL; | ||
61 | } | ||
62 | |||
63 | |||
64 | /** | ||
65 | * Print indexed filenames to stdout. | ||
66 | * | ||
67 | * @param cls closure | ||
68 | * @param filename the name of the file | ||
69 | * @param file_id hash of the contents of the indexed file | ||
70 | * @return GNUNET_OK to continue iteration | ||
71 | */ | ||
72 | static int | ||
73 | print_indexed (void *cls, const char *filename, | ||
74 | const GNUNET_HashCode * file_id) | ||
75 | { | ||
76 | if (verbose) | ||
77 | fprintf (stdout, | ||
78 | "%s: %s\n", | ||
79 | GNUNET_h2s (file_id), | ||
80 | filename); | ||
81 | else | ||
82 | fprintf (stdout, | ||
83 | "%s\n", | ||
84 | filename); | ||
85 | return GNUNET_OK; | ||
86 | } | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Main function that will be run by the scheduler. | ||
91 | * | ||
92 | * @param cls closure | ||
93 | * @param args remaining command-line arguments | ||
94 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
95 | * @param cfg configuration | ||
96 | */ | ||
97 | static void | ||
98 | run (void *cls, char *const *args, const char *cfgfile, | ||
99 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
100 | { | ||
101 | if (list_indexed_files) | ||
102 | { | ||
103 | fs = GNUNET_FS_start (cfg, | ||
104 | "gnunet-fs", | ||
105 | NULL, NULL, | ||
106 | GNUNET_FS_FLAGS_NONE); | ||
107 | if (NULL == fs) | ||
108 | { | ||
109 | ret = 1; | ||
110 | return; | ||
111 | } | ||
112 | GNUNET_FS_get_indexed_files (fs, | ||
113 | &print_indexed, NULL, | ||
114 | &do_shutdown, NULL); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * The main function to access special file-sharing functions. | ||
120 | * | ||
121 | * @param argc number of arguments from the command line | ||
122 | * @param argv command line arguments | ||
123 | * @return 0 ok, 1 on error | ||
124 | */ | ||
125 | int | ||
126 | main (int argc, char *const *argv) | ||
127 | { | ||
128 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
129 | {'i', "list-indexed", NULL, | ||
130 | gettext_noop ("print a list of all indexed files"), 0, | ||
131 | &GNUNET_GETOPT_set_one, &list_indexed_files}, | ||
132 | GNUNET_GETOPT_OPTION_VERBOSE (&verbose), | ||
133 | GNUNET_GETOPT_OPTION_END | ||
134 | }; | ||
135 | return (GNUNET_OK == | ||
136 | GNUNET_PROGRAM_run (argc, argv, "gnunet-fs [OPTIONS]", | ||
137 | gettext_noop | ||
138 | ("Special file-sharing operations"), | ||
139 | options, &run, NULL)) ? ret : 1; | ||
140 | } | ||
141 | |||
142 | /* end of gnunet-fs.c */ | ||