- clean up the receive switch case
[oweals/gnunet.git] / src / fs / gnunet-publish.c
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009, 2010, 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-publish.c
22  * @brief publishing files on GNUnet
23  * @author Christian Grothoff
24  * @author Krista Bennett
25  * @author James Blackwell
26  * @author Igor Wronsky
27  */
28 #include "platform.h"
29 #include "gnunet_fs_service.h"
30
31 static int ret;
32
33 static int verbose;
34
35 static const struct GNUNET_CONFIGURATION_Handle *cfg;
36
37 static struct GNUNET_FS_Handle *ctx;
38
39 static struct GNUNET_FS_PublishContext *pc;
40
41 static struct GNUNET_CONTAINER_MetaData *meta;
42
43 static struct GNUNET_FS_Uri *topKeywords;
44
45 static struct GNUNET_FS_Uri *uri;
46
47 static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 };
48
49 static char *uri_string;
50
51 static char *next_id;
52
53 static char *this_id;
54
55 static char *pseudonym;
56
57 static int do_insert;
58
59 static int disable_extractor;
60
61 static int do_simulate;
62
63 static int extract_only;
64
65 static int do_disable_creation_time;
66
67 static GNUNET_SCHEDULER_TaskIdentifier kill_task;
68
69 static struct GNUNET_FS_DirScanner *ds;
70
71 static struct GNUNET_FS_ShareTreeItem * directory_scan_result;
72
73 static struct GNUNET_FS_Namespace *namespace;
74
75 /**
76  * FIXME: docu
77  */
78 static void
79 do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
80 {
81   struct GNUNET_FS_PublishContext *p;
82
83   kill_task = GNUNET_SCHEDULER_NO_TASK;
84   if (pc != NULL)
85   {
86     p = pc;
87     pc = NULL;
88     GNUNET_FS_publish_stop (p);
89   }
90   if (NULL != meta)
91   {
92     GNUNET_CONTAINER_meta_data_destroy (meta);
93     meta = NULL;
94   }  
95 }
96
97
98 /**
99  * Called by FS client to give information about the progress of an
100  * operation.
101  *
102  * @param cls closure
103  * @param info details about the event, specifying the event type
104  *        and various bits about the event
105  * @return client-context (for the next progress call
106  *         for this operation; should be set to NULL for
107  *         SUSPEND and STOPPED events).  The value returned
108  *         will be passed to future callbacks in the respective
109  *         field in the GNUNET_FS_ProgressInfo struct.
110  */
111 static void *
112 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
113 {
114   char *s;
115
116   switch (info->status)
117   {
118   case GNUNET_FS_STATUS_PUBLISH_START:
119     break;
120   case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
121     if (verbose)
122     {
123       s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta);
124       FPRINTF (stdout, _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
125                info->value.publish.filename,
126                (unsigned long long) info->value.publish.completed,
127                (unsigned long long) info->value.publish.size, s);
128       GNUNET_free (s);
129     }
130     break;
131   case GNUNET_FS_STATUS_PUBLISH_ERROR:
132     FPRINTF (stderr, _("Error publishing: %s.\n"),
133              info->value.publish.specifics.error.message);
134     if (kill_task != GNUNET_SCHEDULER_NO_TASK)
135     {
136       GNUNET_SCHEDULER_cancel (kill_task);
137       kill_task = GNUNET_SCHEDULER_NO_TASK;
138     }
139     kill_task = GNUNET_SCHEDULER_add_now (&do_stop_task, NULL);
140     break;
141   case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
142     FPRINTF (stdout, _("Publishing `%s' done.\n"),
143              info->value.publish.filename);
144     s = GNUNET_FS_uri_to_string (info->value.publish.specifics.
145                                  completed.chk_uri);
146     FPRINTF (stdout, _("URI is `%s'.\n"), s);
147     GNUNET_free (s);
148     if (info->value.publish.pctx == NULL)
149     {
150       if (kill_task != GNUNET_SCHEDULER_NO_TASK)
151       {
152         GNUNET_SCHEDULER_cancel (kill_task);
153         kill_task = GNUNET_SCHEDULER_NO_TASK;
154       }
155       kill_task = GNUNET_SCHEDULER_add_now (&do_stop_task, NULL);
156     }
157     break;
158   case GNUNET_FS_STATUS_PUBLISH_STOPPED:
159     GNUNET_break (NULL == pc);
160     return NULL;
161   case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
162     return NULL;
163   case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
164     FPRINTF (stderr, "%s",  _("Cleanup after abort complete.\n"));
165     return NULL;
166   default:
167     FPRINTF (stderr, _("Unexpected status: %d\n"), info->status);
168     return NULL;
169   }
170   return "";                    /* non-null */
171 }
172
173
174 /**
175  * Print metadata entries (except binary
176  * metadata and the filename).
177  *
178  * @param cls closure
179  * @param plugin_name name of the plugin that generated the meta data
180  * @param type type of the meta data
181  * @param format format of data
182  * @param data_mime_type mime type of data
183  * @param data value of the meta data
184  * @param data_size number of bytes in data
185  * @return always 0
186  */
187 static int
188 meta_printer (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type,
189               enum EXTRACTOR_MetaFormat format, const char *data_mime_type,
190               const char *data, size_t data_size)
191 {
192   if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
193       (format != EXTRACTOR_METAFORMAT_C_STRING))
194     return 0;
195   if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
196     return 0;
197   FPRINTF (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data);
198   return 0;
199 }
200
201
202 /**
203  * Iterator printing keywords
204  *
205  * @param cls closure
206  * @param keyword the keyword
207  * @param is_mandatory is the keyword mandatory (in a search)
208  * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
209  */
210 static int
211 keyword_printer (void *cls, const char *keyword, int is_mandatory)
212 {
213   FPRINTF (stdout, "\t%s\n", keyword);
214   return GNUNET_OK;
215 }
216
217
218 /**
219  * Function called on all entries before the publication.  This is
220  * where we perform modifications to the default based on command-line
221  * options.
222  *
223  * @param cls closure
224  * @param fi the entry in the publish-structure
225  * @param length length of the file or directory
226  * @param m metadata for the file or directory (can be modified)
227  * @param uri pointer to the keywords that will be used for this entry (can be modified)
228  * @param bo block options
229  * @param do_index should we index?
230  * @param client_info pointer to client context set upon creation (can be modified)
231  * @return GNUNET_OK to continue, GNUNET_NO to remove
232  *         this entry from the directory, GNUNET_SYSERR
233  *         to abort the iteration
234  */
235 static int
236 publish_inspector (void *cls, struct GNUNET_FS_FileInformation *fi,
237                    uint64_t length, struct GNUNET_CONTAINER_MetaData *m,
238                    struct GNUNET_FS_Uri **uri,
239                    struct GNUNET_FS_BlockOptions *bo, int *do_index,
240                    void **client_info)
241 {
242   char *fn;
243   char *fs;
244   struct GNUNET_FS_Uri *new_uri;
245
246   if (cls == fi)
247     return GNUNET_OK;
248   if (NULL != topKeywords)
249   {
250     if (*uri != NULL)
251     {
252       new_uri = GNUNET_FS_uri_ksk_merge (topKeywords, *uri);
253       GNUNET_FS_uri_destroy (*uri);
254       *uri = new_uri;
255       GNUNET_FS_uri_destroy (topKeywords);
256     }
257     else
258     {
259       *uri = topKeywords;
260     }
261     topKeywords = NULL;
262   }
263   if (NULL != meta)
264   {
265     GNUNET_CONTAINER_meta_data_merge (m, meta);
266     GNUNET_CONTAINER_meta_data_destroy (meta);
267     meta = NULL;
268   }
269   if (!do_disable_creation_time)
270     GNUNET_CONTAINER_meta_data_add_publication_date (m);
271   if (extract_only)
272   {
273     fn = GNUNET_CONTAINER_meta_data_get_by_type (m,
274                                                  EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
275     fs = GNUNET_STRINGS_byte_size_fancy (length);
276     FPRINTF (stdout, _("Meta data for file `%s' (%s)\n"), fn, fs);
277     GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL);
278     FPRINTF (stdout, _("Keywords for file `%s' (%s)\n"), fn, fs);
279     GNUNET_free (fn);
280     GNUNET_free (fs);
281     if (NULL != *uri)
282       GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL);
283     FPRINTF (stdout, "%s",  "\n");
284   }
285   if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m))
286     GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi);
287   return GNUNET_OK;
288 }
289
290
291 /**
292  * FIXME: docu
293  */
294 static void
295 uri_sks_continuation (void *cls, const struct GNUNET_FS_Uri *ksk_uri,
296                       const char *emsg)
297 {
298   if (emsg != NULL)
299   {
300     FPRINTF (stderr, "%s\n", emsg);
301     ret = 1;
302   }
303   GNUNET_FS_uri_destroy (uri);
304   uri = NULL;
305   GNUNET_FS_stop (ctx);
306   ctx = NULL;
307 }
308
309
310 /**
311  * FIXME: docu
312  */
313 static void
314 uri_ksk_continuation (void *cls, const struct GNUNET_FS_Uri *ksk_uri,
315                       const char *emsg)
316 {
317   struct GNUNET_FS_Namespace *ns;
318
319   if (emsg != NULL)
320   {
321     FPRINTF (stderr, "%s\n", emsg);
322     ret = 1;
323   }
324   if (pseudonym != NULL)
325   {
326     ns = GNUNET_FS_namespace_create (ctx, pseudonym);
327     if (ns == NULL)
328     {
329       FPRINTF (stderr, _("Failed to create namespace `%s'\n"), pseudonym);
330       ret = 1;
331     }
332     else
333     {
334       GNUNET_FS_publish_sks (ctx, ns, this_id, next_id, meta, uri, &bo,
335                              GNUNET_FS_PUBLISH_OPTION_NONE,
336                              uri_sks_continuation, NULL);
337       GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_NO));
338       return;
339     }
340   }
341   GNUNET_FS_uri_destroy (uri);
342   uri = NULL;
343   GNUNET_FS_stop (ctx);
344   ctx = NULL;
345 }
346
347
348 /**
349  * FIXME: docu
350  */
351 static struct GNUNET_FS_FileInformation *
352 get_file_information (struct GNUNET_FS_ShareTreeItem *item)
353 {
354   struct GNUNET_FS_FileInformation *fi;
355   struct GNUNET_FS_FileInformation *fic;
356   struct GNUNET_FS_ShareTreeItem *child;
357
358   if (item->is_directory)
359   {
360     GNUNET_CONTAINER_meta_data_delete (item->meta,
361         EXTRACTOR_METATYPE_MIMETYPE, NULL, 0);
362     GNUNET_FS_meta_data_make_directory (item->meta);
363     if (NULL == item->ksk_uri)
364     {
365       const char *mime = GNUNET_FS_DIRECTORY_MIME;
366       item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &mime);
367     }
368     else
369       GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri, GNUNET_FS_DIRECTORY_MIME,
370         GNUNET_NO);
371     fi = GNUNET_FS_file_information_create_empty_directory (
372         ctx, NULL, item->ksk_uri,
373         item->meta, &bo, item->filename);
374     for (child = item->children_head; child; child = child->next)
375     {
376       fic = get_file_information (child);
377       GNUNET_break (GNUNET_OK == GNUNET_FS_file_information_add (fi, fic));
378     }
379   }
380   else
381   {
382     fi = GNUNET_FS_file_information_create_from_file (
383         ctx, NULL, item->filename,
384         item->ksk_uri, item->meta, !do_insert,
385         &bo);
386   }
387   return fi;
388 }
389
390
391 /**
392  * FIXME: docu
393  */
394 static void
395 directory_trim_complete ()
396 {
397   struct GNUNET_FS_FileInformation *fi;
398
399   fi = get_file_information (directory_scan_result);
400   GNUNET_FS_share_tree_free (directory_scan_result);
401   directory_scan_result = NULL;
402   if (fi == NULL)
403   {
404     FPRINTF (stderr, "%s", _("Could not publish\n"));
405     if (namespace != NULL)
406       GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
407     GNUNET_FS_stop (ctx);
408     ret = 1;
409     return;
410   }
411   GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL);
412   if (extract_only)
413   {
414     if (namespace != NULL)
415       GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
416     GNUNET_FS_file_information_destroy (fi, NULL, NULL);
417     GNUNET_FS_stop (ctx);
418     return;
419   }
420   pc = GNUNET_FS_publish_start (ctx, fi, namespace, this_id, next_id,
421                                 (do_simulate) ?
422                                 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY :
423                                 GNUNET_FS_PUBLISH_OPTION_NONE);
424   if (NULL == pc)
425   {
426     FPRINTF (stderr, "%s",  _("Could not start publishing.\n"));
427     GNUNET_FS_stop (ctx);
428     ret = 1;
429     return;
430   }
431 }
432
433
434 /**
435  * Function called by the directory scanner as we build the tree
436  * that we will need to publish later.
437  *
438  * @param cls closure
439  * @param filename which file we are making progress on
440  * @param is_directory GNUNET_YES if this is a directory,
441  *                     GNUNET_NO if this is a file
442  *                     GNUNET_SYSERR if it is neither (or unknown)
443  * @param reason kind of progress we are making
444  */
445 static void
446 directory_scan_cb (void *cls, 
447                    const char *filename, 
448                    int is_directory,
449                    enum GNUNET_FS_DirScannerProgressUpdateReason reason)
450 {
451   switch (reason)
452   {
453   case GNUNET_FS_DIRSCANNER_FILE_START:
454     if (verbose > 1)
455     {
456       if (is_directory)
457         FPRINTF (stdout, _("Scanning directory `%s'.\n"), filename);
458       else
459         FPRINTF (stdout, _("Scanning file `%s'.\n"), filename);      
460     }
461     break;
462   case GNUNET_FS_DIRSCANNER_FILE_IGNORED:
463     FPRINTF (stderr, 
464              _("There was trouble processing file `%s', skipping it.\n"),
465              filename);
466     break;
467   case GNUNET_FS_DIRSCANNER_ALL_COUNTED:
468     if (verbose)
469       FPRINTF (stdout, "%s", _("Preprocessing complete.\n"));      
470     break;
471   case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED:
472     if (verbose > 2)
473       FPRINTF (stdout, _("Extracting meta data from file `%s' complete.\n"), filename);      
474     break;
475   case GNUNET_FS_DIRSCANNER_FINISHED:
476     if (verbose > 1)
477       FPRINTF (stdout, "%s", _("Meta data extraction has finished.\n"));
478     directory_scan_result = GNUNET_FS_directory_scan_get_result (ds);
479     ds = NULL;
480     GNUNET_FS_share_tree_trim (directory_scan_result);
481     directory_trim_complete ();
482     break;
483   case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR:
484     FPRINTF (stdout, "%s", _("Internal error scanning directory.\n"));
485     GNUNET_FS_directory_scan_abort (ds);
486     ds = NULL;
487     if (namespace != NULL)
488       GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
489     GNUNET_FS_stop (ctx);
490     if (kill_task != GNUNET_SCHEDULER_NO_TASK)
491     {
492       GNUNET_SCHEDULER_cancel (kill_task);
493       kill_task = GNUNET_SCHEDULER_NO_TASK;
494     }
495     ret = 1;
496     break;
497   default:
498     GNUNET_assert (0);
499     break;
500   }
501   fflush (stdout);
502 }
503
504
505 /**
506  * Main function that will be run by the scheduler.
507  *
508  * @param cls closure
509  * @param args remaining command-line arguments
510  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
511  * @param c configuration
512  */
513 static void
514 run (void *cls, char *const *args, const char *cfgfile,
515      const struct GNUNET_CONFIGURATION_Handle *c)
516 {
517   char *ex;
518   char *emsg;
519
520   /* check arguments */
521   if ((uri_string != NULL) && (extract_only))
522   {
523     printf (_("Cannot extract metadata from a URI!\n"));
524     ret = -1;
525     return;
526   }
527   if (((uri_string == NULL) || (extract_only)) &&
528       ((args[0] == NULL) || (args[1] != NULL)))
529   {
530     printf (_("You must specify one and only one filename for insertion.\n"));
531     ret = -1;
532     return;
533   }
534   if ((uri_string != NULL) && (args[0] != NULL))
535   {
536     printf (_("You must NOT specify an URI and a filename.\n"));
537     ret = -1;
538     return;
539   }
540   if (pseudonym != NULL)
541   {
542     if (NULL == this_id)
543     {
544       FPRINTF (stderr, _("Option `%s' is required when using option `%s'.\n"),
545                "-t", "-P");
546       ret = -1;
547       return;
548     }
549   }
550   else
551   {                             /* ordinary insertion checks */
552     if (NULL != next_id)
553     {
554       FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
555                "-N", "-P");
556       ret = -1;
557       return;
558     }
559     if (NULL != this_id)
560     {
561       FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
562                "-t", "-P");
563       ret = -1;
564       return;
565     }
566   }
567   cfg = c;
568   ctx =
569       GNUNET_FS_start (cfg, "gnunet-publish", &progress_cb, NULL,
570                        GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
571   if (NULL == ctx)
572   {
573     FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
574     ret = 1;
575     return;
576   }
577   namespace = NULL;
578   if (NULL != pseudonym)
579   {
580     namespace = GNUNET_FS_namespace_create (ctx, pseudonym);
581     if (NULL == namespace)
582     {
583       FPRINTF (stderr, _("Could not create namespace `%s'\n"), pseudonym);
584       GNUNET_FS_stop (ctx);
585       ret = 1;
586       return;
587     }
588   }
589   if (NULL != uri_string)
590   {
591     emsg = NULL;
592     uri = GNUNET_FS_uri_parse (uri_string, &emsg);
593     if (uri == NULL)
594     {
595       FPRINTF (stderr, _("Failed to parse URI: %s\n"), emsg);
596       GNUNET_free (emsg);
597       if (namespace != NULL)
598         GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
599       GNUNET_FS_stop (ctx);
600       ret = 1;
601       return;
602     }
603     GNUNET_FS_publish_ksk (ctx, topKeywords, meta, uri, &bo,
604                            GNUNET_FS_PUBLISH_OPTION_NONE, &uri_ksk_continuation,
605                            NULL);
606     if (namespace != NULL)
607       GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
608     return;
609   }
610   if (GNUNET_OK !=
611       GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex))
612     ex = NULL;
613   if (0 != ACCESS (args[0], R_OK))
614   {
615     FPRINTF (stderr,
616              _("Failed to access `%s': %s\n"),
617              args[0],
618              STRERROR (errno));
619     return;
620   }
621   ds = GNUNET_FS_directory_scan_start (args[0],
622                                        disable_extractor, 
623                                        ex, 
624                                        &directory_scan_cb, NULL);
625   if (NULL == ds)
626   {
627     FPRINTF (stderr,
628              "%s", _("Failed to start meta directory scanner.  Is gnunet-helper-publish-fs installed?\n"));
629     return;
630   }
631   kill_task =
632       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task,
633                                     NULL);
634 }
635
636
637 /**
638  * The main function to publish content to GNUnet.
639  *
640  * @param argc number of arguments from the command line
641  * @param argv command line arguments
642  * @return 0 ok, 1 on error
643  */
644 int
645 main (int argc, char *const *argv)
646 {
647   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
648     {'a', "anonymity", "LEVEL",
649      gettext_noop ("set the desired LEVEL of sender-anonymity"),
650      1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level},
651     {'d', "disable-creation-time", NULL,
652      gettext_noop
653      ("disable adding the creation time to the metadata of the uploaded file"),
654      0, &GNUNET_GETOPT_set_one, &do_disable_creation_time},
655     {'D', "disable-extractor", NULL,
656      gettext_noop ("do not use libextractor to add keywords or metadata"),
657      0, &GNUNET_GETOPT_set_one, &disable_extractor},
658     {'e', "extract", NULL,
659      gettext_noop
660      ("print list of extracted keywords that would be used, but do not perform upload"),
661      0, &GNUNET_GETOPT_set_one, &extract_only},
662     {'k', "key", "KEYWORD",
663      gettext_noop
664      ("add an additional keyword for the top-level file or directory"
665       " (this option can be specified multiple times)"),
666      1, &GNUNET_FS_getopt_set_keywords, &topKeywords},
667     {'m', "meta", "TYPE:VALUE",
668      gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
669      1, &GNUNET_FS_getopt_set_metadata, &meta},
670     {'n', "noindex", NULL,
671      gettext_noop ("do not index, perform full insertion (stores entire "
672                    "file in encrypted form in GNUnet database)"),
673      0, &GNUNET_GETOPT_set_one, &do_insert},
674     {'N', "next", "ID",
675      gettext_noop
676      ("specify ID of an updated version to be published in the future"
677       " (for namespace insertions only)"),
678      1, &GNUNET_GETOPT_set_string, &next_id},
679     {'p', "priority", "PRIORITY",
680      gettext_noop ("specify the priority of the content"),
681      1, &GNUNET_GETOPT_set_uint, &bo.content_priority},
682     {'P', "pseudonym", "NAME",
683      gettext_noop
684      ("publish the files under the pseudonym NAME (place file into namespace)"),
685      1, &GNUNET_GETOPT_set_string, &pseudonym},
686     {'r', "replication", "LEVEL",
687      gettext_noop ("set the desired replication LEVEL"),
688      1, &GNUNET_GETOPT_set_uint, &bo.replication_level},
689     {'s', "simulate-only", NULL,
690      gettext_noop ("only simulate the process but do not do any "
691                    "actual publishing (useful to compute URIs)"),
692      0, &GNUNET_GETOPT_set_one, &do_simulate},
693     {'t', "this", "ID",
694      gettext_noop ("set the ID of this version of the publication"
695                    " (for namespace insertions only)"),
696      1, &GNUNET_GETOPT_set_string, &this_id},
697     {'u', "uri", "URI",
698      gettext_noop ("URI to be published (can be used instead of passing a "
699                    "file to add keywords to the file with the respective URI)"),
700      1, &GNUNET_GETOPT_set_string, &uri_string},
701     {'V', "verbose", NULL,
702      gettext_noop ("be verbose (print progress information)"),
703      0, &GNUNET_GETOPT_set_one, &verbose},
704     GNUNET_GETOPT_OPTION_END
705   };
706   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
707               "GNUnet publish starts\n");
708   bo.expiration_time =
709       GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
710   return (GNUNET_OK ==
711           GNUNET_PROGRAM_run (argc, argv, "gnunet-publish [OPTIONS] FILENAME",
712                               gettext_noop
713                               ("Publish a file or directory on GNUnet"),
714                               options, &run, NULL)) ? ret : 1;
715 }
716
717 /* end of gnunet-publish.c */