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