2dfef9432eb93a602236246e84762cc89141a09b
[oweals/gnunet.git] / src / fs / gnunet-unindex.c
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 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 2, 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-unindex.c
22  * @brief unindex files published on GNUnet
23  * @author Christian Grothoff
24  * @author Krista Bennett
25  * @author James Blackwell
26  * @author Igor Wronsky
27  *
28  * TODO:
29  * - progress callback
30  * - error checking
31  */
32 #include "platform.h"
33 #include "gnunet_fs_service.h"
34
35 static int ret;
36
37 static const struct GNUNET_CONFIGURATION_Handle *cfg;
38
39 static struct GNUNET_FS_Handle *ctx;
40
41 static struct GNUNET_FS_UnindexContext *uc;
42
43 static struct GNUNET_TIME_Absolute start_time;
44
45
46 /**
47  * Called by FS client to give information about the progress of an 
48  * operation.
49  *
50  * @param cls closure
51  * @param info details about the event, specifying the event type
52  *        and various bits about the event
53  * @return client-context (for the next progress call
54  *         for this operation; should be set to NULL for
55  *         SUSPEND and STOPPED events).  The value returned
56  *         will be passed to future callbacks in the respective
57  *         field in the GNUNET_FS_ProgressInfo struct.
58  */
59 static void *
60 progress_cb (void *cls,
61              const struct GNUNET_FS_ProgressInfo *info)
62 {
63   return NULL;
64 }
65
66
67 /**
68  * Main function that will be run by the scheduler.
69  *
70  * @param cls closure
71  * @param sched the scheduler to use
72  * @param args remaining command-line arguments
73  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
74  * @param cfg configuration
75  */
76 static void
77 run (void *cls,
78      struct GNUNET_SCHEDULER_Handle *sched,
79      char *const *args,
80      const char *cfgfile,
81      const struct GNUNET_CONFIGURATION_Handle *c)
82 {
83   /* check arguments */
84   if ( (args[0] == NULL) || (args[1] != NULL) ) 
85     {
86       printf (_
87               ("You must specify one and only one filename for unindexing.\n"));
88       ret = -1;
89       return;
90     }
91   cfg = c;
92   ctx = GNUNET_FS_start (sched,
93                          cfg,
94                          "gnunet-unindex",
95                          &progress_cb,
96                          NULL);
97   if (NULL == ctx)
98     {
99       fprintf (stderr,
100                _("Could not initialize `%s' subsystem.\n"),
101                "FS");
102       ret = 1;
103       return;
104     }
105   start_time = GNUNET_TIME_absolute_get ();
106   uc = GNUNET_FS_unindex (ctx,
107                           args[0]);
108 }
109
110
111 /**
112  * gnunet-unindex command line options
113  */
114 static struct GNUNET_GETOPT_CommandLineOption options[] = {
115   GNUNET_GETOPT_OPTION_END
116 };
117
118
119 /**
120  * The main function to unindex content.
121  *
122  * @param argc number of arguments from the command line
123  * @param argv command line arguments
124  * @return 0 ok, 1 on error
125  */
126 int
127 main (int argc, char *const *argv)
128 {
129   return (GNUNET_OK ==
130           GNUNET_PROGRAM_run (argc,
131                               argv,
132                               "gnunet-unindex",
133                               gettext_noop
134                               ("Unindex files."),
135                               options, &run, NULL)) ? ret : 1;
136 }
137
138 /* end of gnunet-unindex.c */