aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-04 09:45:03 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-04 09:45:03 +0000
commit7301211bb756c4119d370b6f5f79a9054f2cbe92 (patch)
tree31b5a7d069cf0e00619a91330f84d1dde53ef859 /src/fs
parentb3909bc84fbce46df1dc4b3df4140bf1bfa3ae78 (diff)
downloadgnunet-7301211bb756c4119d370b6f5f79a9054f2cbe92.tar.gz
gnunet-7301211bb756c4119d370b6f5f79a9054f2cbe92.zip
implementing last part of #1107: #1806
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/Makefile.am11
-rw-r--r--src/fs/gnunet-fs.c142
2 files changed, 153 insertions, 0 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index 3e94e9182..264bb45d6 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -58,6 +58,7 @@ bin_PROGRAMS = \
58 gnunet-pseudonym \ 58 gnunet-pseudonym \
59 gnunet-search \ 59 gnunet-search \
60 gnunet-service-fs \ 60 gnunet-service-fs \
61 gnunet-fs \
61 gnunet-unindex 62 gnunet-unindex
62 63
63gnunet_directory_SOURCES = \ 64gnunet_directory_SOURCES = \
@@ -70,6 +71,16 @@ gnunet_directory_LDADD = \
70gnunet_directory_DEPENDENCIES = \ 71gnunet_directory_DEPENDENCIES = \
71 libgnunetfs.la 72 libgnunetfs.la
72 73
74gnunet_fs_SOURCES = \
75 gnunet-fs.c
76gnunet_fs_LDADD = \
77 $(top_builddir)/src/fs/libgnunetfs.la \
78 $(top_builddir)/src/util/libgnunetutil.la \
79 -lextractor \
80 $(GN_LIBINTL)
81gnunet_fs_DEPENDENCIES = \
82 libgnunetfs.la
83
73gnunet_download_SOURCES = \ 84gnunet_download_SOURCES = \
74 gnunet-download.c 85 gnunet-download.c
75gnunet_download_LDADD = \ 86gnunet_download_LDADD = \
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 */
31static int ret;
32
33/**
34 * Handle to FS service.
35 */
36static struct GNUNET_FS_Handle *fs;
37
38/**
39 * Option -i given?
40 */
41static int list_indexed_files;
42
43/**
44 * Option -v given?
45 */
46static int verbose;
47
48
49/**
50 * Shutdown this process.
51 *
52 * @param cls unused
53 * @param tc unused
54 */
55static void
56do_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 */
72static int
73print_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 */
97static void
98run (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 */
125int
126main (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 */