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