aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-publish.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/fs/gnunet-publish.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/fs/gnunet-publish.c')
-rw-r--r--src/fs/gnunet-publish.c121
1 files changed, 45 insertions, 76 deletions
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c
index 326fed3c6..a67886f7d 100644
--- a/src/fs/gnunet-publish.c
+++ b/src/fs/gnunet-publish.c
@@ -112,8 +112,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
112 if (verbose) 112 if (verbose)
113 { 113 {
114 s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta); 114 s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta);
115 fprintf (stdout, 115 fprintf (stdout, _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
116 _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
117 info->value.publish.filename, 116 info->value.publish.filename,
118 (unsigned long long) info->value.publish.completed, 117 (unsigned long long) info->value.publish.completed,
119 (unsigned long long) info->value.publish.size, s); 118 (unsigned long long) info->value.publish.size, s);
@@ -121,23 +120,21 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
121 } 120 }
122 break; 121 break;
123 case GNUNET_FS_STATUS_PUBLISH_ERROR: 122 case GNUNET_FS_STATUS_PUBLISH_ERROR:
124 fprintf (stderr, 123 fprintf (stderr, _("Error publishing: %s.\n"),
125 _("Error publishing: %s.\n"),
126 info->value.publish.specifics.error.message); 124 info->value.publish.specifics.error.message);
127 if (kill_task != GNUNET_SCHEDULER_NO_TASK) 125 if (kill_task != GNUNET_SCHEDULER_NO_TASK)
128 { 126 {
129 GNUNET_SCHEDULER_cancel (kill_task); 127 GNUNET_SCHEDULER_cancel (kill_task);
130 kill_task = GNUNET_SCHEDULER_NO_TASK; 128 kill_task = GNUNET_SCHEDULER_NO_TASK;
131 } 129 }
132 GNUNET_SCHEDULER_add_continuation (&do_stop_task, 130 GNUNET_SCHEDULER_add_continuation (&do_stop_task, NULL,
133 NULL,
134 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 131 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
135 break; 132 break;
136 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 133 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
137 fprintf (stdout, 134 fprintf (stdout, _("Publishing `%s' done.\n"),
138 _("Publishing `%s' done.\n"), info->value.publish.filename); 135 info->value.publish.filename);
139 s = GNUNET_FS_uri_to_string (info->value.publish.specifics. 136 s = GNUNET_FS_uri_to_string (info->value.publish.specifics.completed.
140 completed.chk_uri); 137 chk_uri);
141 fprintf (stdout, _("URI is `%s'.\n"), s); 138 fprintf (stdout, _("URI is `%s'.\n"), s);
142 GNUNET_free (s); 139 GNUNET_free (s);
143 if (info->value.publish.pctx == NULL) 140 if (info->value.publish.pctx == NULL)
@@ -147,8 +144,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
147 GNUNET_SCHEDULER_cancel (kill_task); 144 GNUNET_SCHEDULER_cancel (kill_task);
148 kill_task = GNUNET_SCHEDULER_NO_TASK; 145 kill_task = GNUNET_SCHEDULER_NO_TASK;
149 } 146 }
150 GNUNET_SCHEDULER_add_continuation (&do_stop_task, 147 GNUNET_SCHEDULER_add_continuation (&do_stop_task, NULL,
151 NULL,
152 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 148 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
153 } 149 }
154 break; 150 break;
@@ -177,11 +173,9 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
177 * @return always 0 173 * @return always 0
178 */ 174 */
179static int 175static int
180meta_printer (void *cls, 176meta_printer (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type,
181 const char *plugin_name, 177 enum EXTRACTOR_MetaFormat format, const char *data_mime_type,
182 enum EXTRACTOR_MetaType type, 178 const char *data, size_t data_size)
183 enum EXTRACTOR_MetaFormat format,
184 const char *data_mime_type, const char *data, size_t data_size)
185{ 179{
186 if ((format != EXTRACTOR_METAFORMAT_UTF8) && 180 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
187 (format != EXTRACTOR_METAFORMAT_C_STRING)) 181 (format != EXTRACTOR_METAFORMAT_C_STRING))
@@ -228,13 +222,11 @@ keyword_printer (void *cls, const char *keyword, int is_mandatory)
228 * to abort the iteration 222 * to abort the iteration
229 */ 223 */
230static int 224static int
231publish_inspector (void *cls, 225publish_inspector (void *cls, struct GNUNET_FS_FileInformation *fi,
232 struct GNUNET_FS_FileInformation *fi, 226 uint64_t length, struct GNUNET_CONTAINER_MetaData *m,
233 uint64_t length,
234 struct GNUNET_CONTAINER_MetaData *m,
235 struct GNUNET_FS_Uri **uri, 227 struct GNUNET_FS_Uri **uri,
236 struct GNUNET_FS_BlockOptions *bo, 228 struct GNUNET_FS_BlockOptions *bo, int *do_index,
237 int *do_index, void **client_info) 229 void **client_info)
238{ 230{
239 char *fn; 231 char *fn;
240 char *fs; 232 char *fs;
@@ -286,8 +278,8 @@ publish_inspector (void *cls,
286 278
287 279
288static void 280static void
289uri_sks_continuation (void *cls, 281uri_sks_continuation (void *cls, const struct GNUNET_FS_Uri *ksk_uri,
290 const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) 282 const char *emsg)
291{ 283{
292 if (emsg != NULL) 284 if (emsg != NULL)
293 { 285 {
@@ -302,8 +294,8 @@ uri_sks_continuation (void *cls,
302 294
303 295
304static void 296static void
305uri_ksk_continuation (void *cls, 297uri_ksk_continuation (void *cls, const struct GNUNET_FS_Uri *ksk_uri,
306 const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) 298 const char *emsg)
307{ 299{
308 struct GNUNET_FS_Namespace *ns; 300 struct GNUNET_FS_Namespace *ns;
309 301
@@ -322,13 +314,7 @@ uri_ksk_continuation (void *cls,
322 } 314 }
323 else 315 else
324 { 316 {
325 GNUNET_FS_publish_sks (ctx, 317 GNUNET_FS_publish_sks (ctx, ns, this_id, next_id, meta, uri, &bo,
326 ns,
327 this_id,
328 next_id,
329 meta,
330 uri,
331 &bo,
332 GNUNET_FS_PUBLISH_OPTION_NONE, 318 GNUNET_FS_PUBLISH_OPTION_NONE,
333 uri_sks_continuation, NULL); 319 uri_sks_continuation, NULL);
334 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_NO)); 320 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_NO));
@@ -351,9 +337,8 @@ uri_ksk_continuation (void *cls,
351 * @param c configuration 337 * @param c configuration
352 */ 338 */
353static void 339static void
354run (void *cls, 340run (void *cls, char *const *args, const char *cfgfile,
355 char *const *args, 341 const struct GNUNET_CONFIGURATION_Handle *c)
356 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
357{ 342{
358 struct GNUNET_FS_FileInformation *fi; 343 struct GNUNET_FS_FileInformation *fi;
359 struct GNUNET_FS_Namespace *namespace; 344 struct GNUNET_FS_Namespace *namespace;
@@ -370,8 +355,8 @@ run (void *cls,
370 ret = -1; 355 ret = -1;
371 return; 356 return;
372 } 357 }
373 if (((uri_string == NULL) || (extract_only)) 358 if (((uri_string == NULL) || (extract_only)) &&
374 && ((args[0] == NULL) || (args[1] != NULL))) 359 ((args[0] == NULL) || (args[1] != NULL)))
375 { 360 {
376 printf (_("You must specify one and only one filename for insertion.\n")); 361 printf (_("You must specify one and only one filename for insertion.\n"));
377 ret = -1; 362 ret = -1;
@@ -387,8 +372,7 @@ run (void *cls,
387 { 372 {
388 if (NULL == this_id) 373 if (NULL == this_id)
389 { 374 {
390 fprintf (stderr, 375 fprintf (stderr, _("Option `%s' is required when using option `%s'.\n"),
391 _("Option `%s' is required when using option `%s'.\n"),
392 "-t", "-P"); 376 "-t", "-P");
393 ret = -1; 377 ret = -1;
394 return; 378 return;
@@ -398,26 +382,23 @@ run (void *cls,
398 { /* ordinary insertion checks */ 382 { /* ordinary insertion checks */
399 if (NULL != next_id) 383 if (NULL != next_id)
400 { 384 {
401 fprintf (stderr, 385 fprintf (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
402 _("Option `%s' makes no sense without option `%s'.\n"),
403 "-N", "-P"); 386 "-N", "-P");
404 ret = -1; 387 ret = -1;
405 return; 388 return;
406 } 389 }
407 if (NULL != this_id) 390 if (NULL != this_id)
408 { 391 {
409 fprintf (stderr, 392 fprintf (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
410 _("Option `%s' makes no sense without option `%s'.\n"),
411 "-t", "-P"); 393 "-t", "-P");
412 ret = -1; 394 ret = -1;
413 return; 395 return;
414 } 396 }
415 } 397 }
416 cfg = c; 398 cfg = c;
417 ctx = GNUNET_FS_start (cfg, 399 ctx =
418 "gnunet-publish", 400 GNUNET_FS_start (cfg, "gnunet-publish", &progress_cb, NULL,
419 &progress_cb, 401 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
420 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
421 if (NULL == ctx) 402 if (NULL == ctx)
422 { 403 {
423 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); 404 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
@@ -450,13 +431,9 @@ run (void *cls,
450 ret = 1; 431 ret = 1;
451 return; 432 return;
452 } 433 }
453 GNUNET_FS_publish_ksk (ctx, 434 GNUNET_FS_publish_ksk (ctx, topKeywords, meta, uri, &bo,
454 topKeywords, 435 GNUNET_FS_PUBLISH_OPTION_NONE, &uri_ksk_continuation,
455 meta, 436 NULL);
456 uri,
457 &bo,
458 GNUNET_FS_PUBLISH_OPTION_NONE,
459 &uri_ksk_continuation, NULL);
460 if (namespace != NULL) 437 if (namespace != NULL)
461 GNUNET_FS_namespace_delete (namespace, GNUNET_NO); 438 GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
462 return; 439 return;
@@ -484,12 +461,9 @@ run (void *cls,
484 } 461 }
485 else if (S_ISDIR (sbuf.st_mode)) 462 else if (S_ISDIR (sbuf.st_mode))
486 { 463 {
487 fi = GNUNET_FS_file_information_create_from_directory (ctx, 464 fi = GNUNET_FS_file_information_create_from_directory (ctx, NULL, args[0],
488 NULL,
489 args[0],
490 &GNUNET_FS_directory_scanner_default, 465 &GNUNET_FS_directory_scanner_default,
491 plugins, 466 plugins, !do_insert,
492 !do_insert,
493 &bo, &emsg); 467 &bo, &emsg);
494 } 468 }
495 else 469 else
@@ -498,11 +472,9 @@ run (void *cls,
498 meta = GNUNET_CONTAINER_meta_data_create (); 472 meta = GNUNET_CONTAINER_meta_data_create ();
499 GNUNET_FS_meta_data_extract_from_file (meta, args[0], plugins); 473 GNUNET_FS_meta_data_extract_from_file (meta, args[0], plugins);
500 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta); 474 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
501 fi = GNUNET_FS_file_information_create_from_file (ctx, 475 fi = GNUNET_FS_file_information_create_from_file (ctx, NULL, args[0],
502 NULL, 476 keywords, NULL,
503 args[0], 477 !do_insert, &bo);
504 keywords,
505 NULL, !do_insert, &bo);
506 GNUNET_break (fi != NULL); 478 GNUNET_break (fi != NULL);
507 GNUNET_FS_uri_destroy (keywords); 479 GNUNET_FS_uri_destroy (keywords);
508 } 480 }
@@ -526,14 +498,10 @@ run (void *cls,
526 GNUNET_FS_stop (ctx); 498 GNUNET_FS_stop (ctx);
527 return; 499 return;
528 } 500 }
529 pc = GNUNET_FS_publish_start (ctx, 501 pc = GNUNET_FS_publish_start (ctx, fi, namespace, this_id, next_id,
530 fi, 502 (do_simulate) ?
531 namespace, 503 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY :
532 this_id, 504 GNUNET_FS_PUBLISH_OPTION_NONE);
533 next_id,
534 (do_simulate)
535 ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
536 : GNUNET_FS_PUBLISH_OPTION_NONE);
537 if (NULL == pc) 505 if (NULL == pc)
538 { 506 {
539 fprintf (stderr, _("Could not start publishing.\n")); 507 fprintf (stderr, _("Could not start publishing.\n"));
@@ -541,8 +509,9 @@ run (void *cls,
541 ret = 1; 509 ret = 1;
542 return; 510 return;
543 } 511 }
544 kill_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 512 kill_task =
545 &do_stop_task, NULL); 513 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task,
514 NULL);
546} 515}
547 516
548 517