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