aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-publish.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-publish.c')
-rw-r--r--src/fs/gnunet-publish.c62
1 files changed, 54 insertions, 8 deletions
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c
index b6b9199d0..a30b36c9e 100644
--- a/src/fs/gnunet-publish.c
+++ b/src/fs/gnunet-publish.c
@@ -27,8 +27,6 @@
27 * 27 *
28 * TODO: 28 * TODO:
29 * - support for some options is still missing (uri argument) 29 * - support for some options is still missing (uri argument)
30 * - progress callbacks not implemented (and need verbosity option)
31 * - clean shutdown is not implemented (stop ctx, etc.)
32 */ 30 */
33#include "platform.h" 31#include "platform.h"
34#include "gnunet_fs_service.h" 32#include "gnunet_fs_service.h"
@@ -37,14 +35,14 @@
37 35
38static int ret; 36static int ret;
39 37
38static int verbose;
39
40static const struct GNUNET_CONFIGURATION_Handle *cfg; 40static const struct GNUNET_CONFIGURATION_Handle *cfg;
41 41
42static struct GNUNET_FS_Handle *ctx; 42static struct GNUNET_FS_Handle *ctx;
43 43
44static struct GNUNET_FS_PublishContext *pc; 44static struct GNUNET_FS_PublishContext *pc;
45 45
46static struct GNUNET_TIME_Absolute start_time;
47
48static struct GNUNET_CONTAINER_MetaData *meta; 46static struct GNUNET_CONTAINER_MetaData *meta;
49 47
50static struct GNUNET_FS_Uri *topKeywords; 48static struct GNUNET_FS_Uri *topKeywords;
@@ -89,7 +87,43 @@ static void *
89progress_cb (void *cls, 87progress_cb (void *cls,
90 const struct GNUNET_FS_ProgressInfo *info) 88 const struct GNUNET_FS_ProgressInfo *info)
91{ 89{
92 return NULL; 90 switch (info->status)
91 {
92 case GNUNET_FS_STATUS_PUBLISH_START:
93 break;
94 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
95 if (verbose)
96 fprintf (stdout,
97 _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
98 info->value.publish.filename,
99 (unsigned long long) info->value.publish.completed,
100 (unsigned long long) info->value.publish.size,
101 GNUNET_STRINGS_relative_time_to_string(info->value.publish.eta));
102 break;
103 case GNUNET_FS_STATUS_PUBLISH_ERROR:
104 fprintf (stderr,
105 _("Error publishing: %s.\n"),
106 info->value.publish.specifics.error.message);
107 GNUNET_FS_publish_stop (pc);
108 break;
109 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
110 fprintf (stdout,
111 _("Publishing `%s' done.\n"),
112 info->value.publish.filename);
113 if (info->value.publish.pctx == NULL)
114 GNUNET_FS_publish_stop (pc);
115 break;
116 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
117 if (info->value.publish.sc == pc)
118 GNUNET_FS_stop (ctx);
119 return NULL;
120 default:
121 fprintf (stderr,
122 _("Unexpected status: %d\n"),
123 info->status);
124 return NULL;
125 }
126 return ""; /* non-null */
93} 127}
94 128
95 129
@@ -302,7 +336,9 @@ run (void *cls,
302 cfg, 336 cfg,
303 "gnunet-publish", 337 "gnunet-publish",
304 &progress_cb, 338 &progress_cb,
305 NULL); 339 NULL,
340 GNUNET_FS_FLAGS_NONE,
341 GNUNET_FS_OPTIONS_END);
306 if (NULL == ctx) 342 if (NULL == ctx)
307 { 343 {
308 fprintf (stderr, 344 fprintf (stderr,
@@ -331,7 +367,6 @@ run (void *cls,
331 // FIXME -- implement! 367 // FIXME -- implement!
332 return; 368 return;
333 } 369 }
334 start_time = GNUNET_TIME_absolute_get ();
335 370
336 l = NULL; 371 l = NULL;
337 if (! disable_extractor) 372 if (! disable_extractor)
@@ -389,6 +424,14 @@ run (void *cls,
389 (do_simulate) 424 (do_simulate)
390 ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY 425 ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
391 : GNUNET_FS_PUBLISH_OPTION_NONE); 426 : GNUNET_FS_PUBLISH_OPTION_NONE);
427 if (NULL == pc)
428 {
429 fprintf (stderr,
430 _("Could not start publishing.\n"));
431 GNUNET_FS_stop (ctx);
432 ret = 1;
433 return;
434 }
392} 435}
393 436
394 437
@@ -449,7 +492,10 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
449 {'u', "uri", "URI", 492 {'u', "uri", "URI",
450 gettext_noop ("URI to be published (can be used instead of passing a " 493 gettext_noop ("URI to be published (can be used instead of passing a "
451 "file to add keywords to the file with the respective URI)"), 494 "file to add keywords to the file with the respective URI)"),
452 1, &GNUNET_GETOPT_set_string, &uri_string}, 495 1, &GNUNET_GETOPT_set_string, &uri_string},
496 {'V', "verbose", NULL,
497 gettext_noop ("be verbose (print progress information)"),
498 0, &GNUNET_GETOPT_set_one, &verbose},
453 GNUNET_GETOPT_OPTION_END 499 GNUNET_GETOPT_OPTION_END
454}; 500};
455 501