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