aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-publish.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-23 09:08:06 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-23 09:08:06 +0000
commit15bec1f951708a370e2c6cc2ffd48286ca68015b (patch)
treebd15e673e26c7f05da5c33370e4d1c131aba6a3e /src/fs/gnunet-publish.c
parentfdc3349eb0fb3ad4aa0554deb84ebd94f55793cd (diff)
downloadgnunet-15bec1f951708a370e2c6cc2ffd48286ca68015b.tar.gz
gnunet-15bec1f951708a370e2c6cc2ffd48286ca68015b.zip
-fix URI test to handle new encoder, print both SKS and CHK URIs when publishing to namespace
Diffstat (limited to 'src/fs/gnunet-publish.c')
-rw-r--r--src/fs/gnunet-publish.c147
1 files changed, 104 insertions, 43 deletions
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c
index f192a0a90..f8396416c 100644
--- a/src/fs/gnunet-publish.c
+++ b/src/fs/gnunet-publish.c
@@ -154,11 +154,17 @@ static struct GNUNET_IDENTITY_Handle *identity;
154 * @param tc scheduler context 154 * @param tc scheduler context
155 */ 155 */
156static void 156static void
157do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 157do_stop_task (void *cls,
158 const struct GNUNET_SCHEDULER_TaskContext *tc)
158{ 159{
159 struct GNUNET_FS_PublishContext *p; 160 struct GNUNET_FS_PublishContext *p;
160 161
161 kill_task = GNUNET_SCHEDULER_NO_TASK; 162 kill_task = GNUNET_SCHEDULER_NO_TASK;
163 if (NULL != identity)
164 {
165 GNUNET_IDENTITY_disconnect (identity);
166 identity = NULL;
167 }
162 if (NULL != pc) 168 if (NULL != pc)
163 { 169 {
164 p = pc; 170 p = pc;
@@ -213,7 +219,8 @@ stop_scanner_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
213 * field in the GNUNET_FS_ProgressInfo struct. 219 * field in the GNUNET_FS_ProgressInfo struct.
214 */ 220 */
215static void * 221static void *
216progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) 222progress_cb (void *cls,
223 const struct GNUNET_FS_ProgressInfo *info)
217{ 224{
218 const char *s; 225 const char *s;
219 char *suri; 226 char *suri;
@@ -257,19 +264,28 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
257 kill_task = GNUNET_SCHEDULER_add_now (&do_stop_task, NULL); 264 kill_task = GNUNET_SCHEDULER_add_now (&do_stop_task, NULL);
258 break; 265 break;
259 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 266 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
260 FPRINTF (stdout, _("Publishing `%s' done.\n"), 267 FPRINTF (stdout,
268 _("Publishing `%s' done.\n"),
261 info->value.publish.filename); 269 info->value.publish.filename);
262 suri = GNUNET_FS_uri_to_string (info->value.publish.specifics. 270 suri = GNUNET_FS_uri_to_string (info->value.publish.specifics.
263 completed.chk_uri); 271 completed.chk_uri);
264 FPRINTF (stdout, _("URI is `%s'.\n"), suri); 272 FPRINTF (stdout,
273 _("URI is `%s'.\n"),
274 suri);
265 GNUNET_free (suri); 275 GNUNET_free (suri);
276 if (NULL != info->value.publish.specifics.completed.sks_uri)
277 {
278 suri = GNUNET_FS_uri_to_string (info->value.publish.specifics.
279 completed.sks_uri);
280 FPRINTF (stdout,
281 _("Namespace URI is `%s'.\n"),
282 suri);
283 GNUNET_free (suri);
284 }
266 if (NULL == info->value.publish.pctx) 285 if (NULL == info->value.publish.pctx)
267 { 286 {
268 if (GNUNET_SCHEDULER_NO_TASK != kill_task) 287 if (GNUNET_SCHEDULER_NO_TASK != kill_task)
269 {
270 GNUNET_SCHEDULER_cancel (kill_task); 288 GNUNET_SCHEDULER_cancel (kill_task);
271 kill_task = GNUNET_SCHEDULER_NO_TASK;
272 }
273 kill_task = GNUNET_SCHEDULER_add_now (&do_stop_task, NULL); 289 kill_task = GNUNET_SCHEDULER_add_now (&do_stop_task, NULL);
274 } 290 }
275 ret = 0; 291 ret = 0;
@@ -280,7 +296,9 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
280 case GNUNET_FS_STATUS_UNINDEX_PROGRESS: 296 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
281 return NULL; 297 return NULL;
282 case GNUNET_FS_STATUS_UNINDEX_COMPLETED: 298 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
283 FPRINTF (stderr, "%s", _("Cleanup after abort complete.\n")); 299 FPRINTF (stderr,
300 "%s",
301 _("Cleanup after abort complete.\n"));
284 return NULL; 302 return NULL;
285 default: 303 default:
286 FPRINTF (stderr, _("Unexpected status: %d\n"), info->status); 304 FPRINTF (stderr, _("Unexpected status: %d\n"), info->status);
@@ -300,12 +318,15 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
300 * @param format format of data 318 * @param format format of data
301 * @param data_mime_type mime type of data 319 * @param data_mime_type mime type of data
302 * @param data value of the meta data 320 * @param data value of the meta data
303 * @param data_size number of bytes in data 321 * @param data_size number of bytes in @a data
304 * @return always 0 322 * @return always 0
305 */ 323 */
306static int 324static int
307meta_printer (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type, 325meta_printer (void *cls,
308 enum EXTRACTOR_MetaFormat format, const char *data_mime_type, 326 const char *plugin_name,
327 enum EXTRACTOR_MetaType type,
328 enum EXTRACTOR_MetaFormat format,
329 const char *data_mime_type,
309 const char *data, size_t data_size) 330 const char *data, size_t data_size)
310{ 331{
311 if ((EXTRACTOR_METAFORMAT_UTF8 != format) && 332 if ((EXTRACTOR_METAFORMAT_UTF8 != format) &&
@@ -324,10 +345,12 @@ meta_printer (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type,
324 * @param cls closure 345 * @param cls closure
325 * @param keyword the keyword 346 * @param keyword the keyword
326 * @param is_mandatory is the keyword mandatory (in a search) 347 * @param is_mandatory is the keyword mandatory (in a search)
327 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort 348 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort
328 */ 349 */
329static int 350static int
330keyword_printer (void *cls, const char *keyword, int is_mandatory) 351keyword_printer (void *cls,
352 const char *keyword,
353 int is_mandatory)
331{ 354{
332 FPRINTF (stdout, "\t%s\n", keyword); 355 FPRINTF (stdout, "\t%s\n", keyword);
333 return GNUNET_OK; 356 return GNUNET_OK;
@@ -347,15 +370,18 @@ keyword_printer (void *cls, const char *keyword, int is_mandatory)
347 * @param bo block options 370 * @param bo block options
348 * @param do_index should we index? 371 * @param do_index should we index?
349 * @param client_info pointer to client context set upon creation (can be modified) 372 * @param client_info pointer to client context set upon creation (can be modified)
350 * @return GNUNET_OK to continue, GNUNET_NO to remove 373 * @return #GNUNET_OK to continue, #GNUNET_NO to remove
351 * this entry from the directory, GNUNET_SYSERR 374 * this entry from the directory, #GNUNET_SYSERR
352 * to abort the iteration 375 * to abort the iteration
353 */ 376 */
354static int 377static int
355publish_inspector (void *cls, struct GNUNET_FS_FileInformation *fi, 378publish_inspector (void *cls,
356 uint64_t length, struct GNUNET_CONTAINER_MetaData *m, 379 struct GNUNET_FS_FileInformation *fi,
380 uint64_t length,
381 struct GNUNET_CONTAINER_MetaData *m,
357 struct GNUNET_FS_Uri **uri, 382 struct GNUNET_FS_Uri **uri,
358 struct GNUNET_FS_BlockOptions *bo, int *do_index, 383 struct GNUNET_FS_BlockOptions *bo,
384 int *do_index,
359 void **client_info) 385 void **client_info)
360{ 386{
361 char *fn; 387 char *fn;
@@ -423,7 +449,8 @@ publish_inspector (void *cls, struct GNUNET_FS_FileInformation *fi,
423 * @param emsg error message, NULL on success 449 * @param emsg error message, NULL on success
424 */ 450 */
425static void 451static void
426uri_sks_continuation (void *cls, const struct GNUNET_FS_Uri *sks_uri, 452uri_sks_continuation (void *cls,
453 const struct GNUNET_FS_Uri *sks_uri,
427 const char *emsg) 454 const char *emsg)
428{ 455{
429 if (NULL != emsg) 456 if (NULL != emsg)
@@ -540,7 +567,9 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result)
540 GNUNET_FS_share_tree_free (directory_scan_result); 567 GNUNET_FS_share_tree_free (directory_scan_result);
541 if (NULL == fi) 568 if (NULL == fi)
542 { 569 {
543 FPRINTF (stderr, "%s", _("Could not publish\n")); 570 FPRINTF (stderr,
571 "%s",
572 _("Could not publish\n"));
544 GNUNET_SCHEDULER_shutdown (); 573 GNUNET_SCHEDULER_shutdown ();
545 ret = 1; 574 ret = 1;
546 return; 575 return;
@@ -563,7 +592,9 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result)
563 GNUNET_FS_PUBLISH_OPTION_NONE); 592 GNUNET_FS_PUBLISH_OPTION_NONE);
564 if (NULL == pc) 593 if (NULL == pc)
565 { 594 {
566 FPRINTF (stderr, "%s", _("Could not start publishing.\n")); 595 FPRINTF (stderr,
596 "%s",
597 _("Could not start publishing.\n"));
567 GNUNET_SCHEDULER_shutdown (); 598 GNUNET_SCHEDULER_shutdown ();
568 ret = 1; 599 ret = 1;
569 return; 600 return;
@@ -577,9 +608,9 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result)
577 * 608 *
578 * @param cls closure 609 * @param cls closure
579 * @param filename which file we are making progress on 610 * @param filename which file we are making progress on
580 * @param is_directory GNUNET_YES if this is a directory, 611 * @param is_directory #GNUNET_YES if this is a directory,
581 * GNUNET_NO if this is a file 612 * #GNUNET_NO if this is a file
582 * GNUNET_SYSERR if it is neither (or unknown) 613 * #GNUNET_SYSERR if it is neither (or unknown)
583 * @param reason kind of progress we are making 614 * @param reason kind of progress we are making
584 */ 615 */
585static void 616static void
@@ -596,9 +627,13 @@ directory_scan_cb (void *cls,
596 if (verbose > 1) 627 if (verbose > 1)
597 { 628 {
598 if (is_directory == GNUNET_YES) 629 if (is_directory == GNUNET_YES)
599 FPRINTF (stdout, _("Scanning directory `%s'.\n"), filename); 630 FPRINTF (stdout,
631 _("Scanning directory `%s'.\n"),
632 filename);
600 else 633 else
601 FPRINTF (stdout, _("Scanning file `%s'.\n"), filename); 634 FPRINTF (stdout,
635 _("Scanning file `%s'.\n"),
636 filename);
602 } 637 }
603 break; 638 break;
604 case GNUNET_FS_DIRSCANNER_FILE_IGNORED: 639 case GNUNET_FS_DIRSCANNER_FILE_IGNORED:
@@ -608,22 +643,30 @@ directory_scan_cb (void *cls,
608 break; 643 break;
609 case GNUNET_FS_DIRSCANNER_ALL_COUNTED: 644 case GNUNET_FS_DIRSCANNER_ALL_COUNTED:
610 if (verbose) 645 if (verbose)
611 FPRINTF (stdout, "%s", _("Preprocessing complete.\n")); 646 FPRINTF (stdout,
647 "%s",
648 _("Preprocessing complete.\n"));
612 break; 649 break;
613 case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED: 650 case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED:
614 if (verbose > 2) 651 if (verbose > 2)
615 FPRINTF (stdout, _("Extracting meta data from file `%s' complete.\n"), filename); 652 FPRINTF (stdout,
653 _("Extracting meta data from file `%s' complete.\n"),
654 filename);
616 break; 655 break;
617 case GNUNET_FS_DIRSCANNER_FINISHED: 656 case GNUNET_FS_DIRSCANNER_FINISHED:
618 if (verbose > 1) 657 if (verbose > 1)
619 FPRINTF (stdout, "%s", _("Meta data extraction has finished.\n")); 658 FPRINTF (stdout,
659 "%s",
660 _("Meta data extraction has finished.\n"));
620 directory_scan_result = GNUNET_FS_directory_scan_get_result (ds); 661 directory_scan_result = GNUNET_FS_directory_scan_get_result (ds);
621 ds = NULL; 662 ds = NULL;
622 GNUNET_FS_share_tree_trim (directory_scan_result); 663 GNUNET_FS_share_tree_trim (directory_scan_result);
623 directory_trim_complete (directory_scan_result); 664 directory_trim_complete (directory_scan_result);
624 break; 665 break;
625 case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: 666 case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR:
626 FPRINTF (stdout, "%s", _("Internal error scanning directory.\n")); 667 FPRINTF (stdout,
668 "%s",
669 _("Internal error scanning directory.\n"));
627 if (kill_task != GNUNET_SCHEDULER_NO_TASK) 670 if (kill_task != GNUNET_SCHEDULER_NO_TASK)
628 { 671 {
629 GNUNET_SCHEDULER_cancel (kill_task); 672 GNUNET_SCHEDULER_cancel (kill_task);
@@ -654,7 +697,9 @@ identity_continuation (const char *args0)
654 if ( (NULL != pseudonym) && 697 if ( (NULL != pseudonym) &&
655 (NULL == namespace) ) 698 (NULL == namespace) )
656 { 699 {
657 FPRINTF (stderr, _("Selected pseudonym `%s' unknown\n"), pseudonym); 700 FPRINTF (stderr,
701 _("Selected pseudonym `%s' unknown\n"),
702 pseudonym);
658 GNUNET_SCHEDULER_shutdown (); 703 GNUNET_SCHEDULER_shutdown ();
659 return; 704 return;
660 } 705 }
@@ -663,14 +708,19 @@ identity_continuation (const char *args0)
663 emsg = NULL; 708 emsg = NULL;
664 if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg))) 709 if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg)))
665 { 710 {
666 FPRINTF (stderr, _("Failed to parse URI: %s\n"), emsg); 711 FPRINTF (stderr,
712 _("Failed to parse URI: %s\n"),
713 emsg);
667 GNUNET_free (emsg); 714 GNUNET_free (emsg);
668 GNUNET_SCHEDULER_shutdown (); 715 GNUNET_SCHEDULER_shutdown ();
669 ret = 1; 716 ret = 1;
670 return; 717 return;
671 } 718 }
672 GNUNET_FS_publish_ksk (ctx, topKeywords, meta, uri, &bo, 719 GNUNET_FS_publish_ksk (ctx, topKeywords,
673 GNUNET_FS_PUBLISH_OPTION_NONE, &uri_ksk_continuation, 720 meta, uri,
721 &bo,
722 GNUNET_FS_PUBLISH_OPTION_NONE,
723 &uri_ksk_continuation,
674 NULL); 724 NULL);
675 return; 725 return;
676 } 726 }
@@ -693,7 +743,8 @@ identity_continuation (const char *args0)
693 if (NULL == ds) 743 if (NULL == ds)
694 { 744 {
695 FPRINTF (stderr, 745 FPRINTF (stderr,
696 "%s", _("Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n")); 746 "%s",
747 _("Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n"));
697 GNUNET_free_non_null (ex); 748 GNUNET_free_non_null (ex);
698 return; 749 return;
699 } 750 }
@@ -725,6 +776,8 @@ identity_cb (void *cls,
725 identity_continuation (args0); 776 identity_continuation (args0);
726 return; 777 return;
727 } 778 }
779 if (NULL == name)
780 return;
728 if (0 == strcmp (name, pseudonym)) 781 if (0 == strcmp (name, pseudonym))
729 namespace = ego; 782 namespace = ego;
730} 783}
@@ -739,7 +792,9 @@ identity_cb (void *cls,
739 * @param c configuration 792 * @param c configuration
740 */ 793 */
741static void 794static void
742run (void *cls, char *const *args, const char *cfgfile, 795run (void *cls,
796 char *const *args,
797 const char *cfgfile,
743 const struct GNUNET_CONFIGURATION_Handle *c) 798 const struct GNUNET_CONFIGURATION_Handle *c)
744{ 799{
745 /* check arguments */ 800 /* check arguments */
@@ -776,14 +831,16 @@ run (void *cls, char *const *args, const char *cfgfile,
776 { /* ordinary insertion checks */ 831 { /* ordinary insertion checks */
777 if (NULL != next_id) 832 if (NULL != next_id)
778 { 833 {
779 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"), 834 FPRINTF (stderr,
835 _("Option `%s' makes no sense without option `%s'.\n"),
780 "-N", "-P"); 836 "-N", "-P");
781 ret = -1; 837 ret = -1;
782 return; 838 return;
783 } 839 }
784 if (NULL != this_id) 840 if (NULL != this_id)
785 { 841 {
786 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"), 842 FPRINTF (stderr,
843 _("Option `%s' makes no sense without option `%s'.\n"),
787 "-t", "-P"); 844 "-t", "-P");
788 ret = -1; 845 ret = -1;
789 return; 846 return;
@@ -795,16 +852,20 @@ run (void *cls, char *const *args, const char *cfgfile,
795 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); 852 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
796 if (NULL == ctx) 853 if (NULL == ctx)
797 { 854 {
798 FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); 855 FPRINTF (stderr,
856 _("Could not initialize `%s' subsystem.\n"),
857 "FS");
799 ret = 1; 858 ret = 1;
800 return; 859 return;
801 } 860 }
802 kill_task = 861 kill_task =
803 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task, 862 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
804 NULL); 863 &do_stop_task,
864 NULL);
805 if (NULL != pseudonym) 865 if (NULL != pseudonym)
806 identity = GNUNET_IDENTITY_connect (cfg, 866 identity = GNUNET_IDENTITY_connect (cfg,
807 &identity_cb, args[0]); 867 &identity_cb,
868 args[0]);
808 else 869 else
809 identity_continuation (args[0]); 870 identity_continuation (args[0]);
810} 871}