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