aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet_chat_lib.c')
-rw-r--r--src/gnunet_chat_lib.c73
1 files changed, 45 insertions, 28 deletions
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index a835e48..cdce90c 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -374,7 +374,7 @@ GNUNET_CHAT_group_set_user_pointer (struct GNUNET_CHAT_Group *group,
374 374
375 375
376void* 376void*
377GNUNET_CHAT_group_get_user_pointer (struct GNUNET_CHAT_Group *group) 377GNUNET_CHAT_group_get_user_pointer (const struct GNUNET_CHAT_Group *group)
378{ 378{
379 if (!group) 379 if (!group)
380 return NULL; 380 return NULL;
@@ -475,7 +475,9 @@ GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context,
475 475
476int 476int
477GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, 477GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
478 const char *path) 478 const char *path,
479 GNUNET_CHAT_FileUploadCallback callback,
480 void *cls)
479{ 481{
480 if ((!context) || (!path)) 482 if ((!context) || (!path))
481 return GNUNET_SYSERR; 483 return GNUNET_SYSERR;
@@ -516,6 +518,8 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
516 518
517 GNUNET_free(p); 519 GNUNET_free(p);
518 520
521 file_bind_upload(file, callback, cls);
522
519 struct GNUNET_FS_BlockOptions bo; 523 struct GNUNET_FS_BlockOptions bo;
520 524
521 bo.anonymity_level = 1; 525 bo.anonymity_level = 1;
@@ -543,32 +547,11 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
543 ); 547 );
544 548
545 GNUNET_free(filename); 549 GNUNET_free(filename);
546
547 // TODO: share file
548
549 return GNUNET_OK; 550 return GNUNET_OK;
550} 551}
551 552
552 553
553int 554int
554GNUNET_CHAT_context_send_uri (struct GNUNET_CHAT_Context *context,
555 const char *uri)
556{
557 if ((!context) || (!uri))
558 return GNUNET_SYSERR;
559
560 struct GNUNET_FS_Uri *furi = GNUNET_FS_uri_parse(uri, NULL);
561
562 if (!furi)
563 return GNUNET_SYSERR;
564
565 // TODO: download file, hash file, share file
566
567 return GNUNET_SYSERR;
568}
569
570
571int
572GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context, 555GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context,
573 const struct GNUNET_CHAT_File *file) 556 const struct GNUNET_CHAT_File *file)
574{ 557{
@@ -833,9 +816,30 @@ GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file)
833} 816}
834 817
835 818
819void
820GNUNET_CHAT_file_set_user_pointer (struct GNUNET_CHAT_File *file,
821 void *user_pointer)
822{
823 if (!file)
824 return;
825
826 file->user_pointer = user_pointer;
827}
828
829
830void*
831GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file)
832{
833 if (!file)
834 return NULL;
835
836 return file->user_pointer;
837}
838
839
836int 840int
837GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, 841GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
838 GNUNET_CHAT_MessageFileDownloadCallback callback, 842 GNUNET_CHAT_FileDownloadCallback callback,
839 void *cls) 843 void *cls)
840{ 844{
841 if ((!file) || (!(file->uri))) 845 if ((!file) || (!(file->uri)))
@@ -843,8 +847,10 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
843 847
844 if (file->download) 848 if (file->download)
845 { 849 {
850 file_bind_downlaod(file, callback, cls);
851
846 GNUNET_FS_download_resume(file->download); 852 GNUNET_FS_download_resume(file->download);
847 return GNUNET_OK; 853 return GNUNET_NO;
848 } 854 }
849 855
850 const uint64_t size = GNUNET_FS_uri_chk_get_file_size(file->uri); 856 const uint64_t size = GNUNET_FS_uri_chk_get_file_size(file->uri);
@@ -859,7 +865,14 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
859 offset = 0; 865 offset = 0;
860 866
861 if (offset >= size) 867 if (offset >= size)
862 return GNUNET_OK; 868 {
869 if (callback)
870 callback(cls, file, size, size);
871
872 return GNUNET_YES;
873 }
874
875 file_bind_downlaod(file, callback, cls);
863 876
864 const uint64_t remaining = (size - offset); 877 const uint64_t remaining = (size - offset);
865 878
@@ -878,7 +891,7 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
878 ); 891 );
879 892
880 GNUNET_free(filename); 893 GNUNET_free(filename);
881 return GNUNET_OK; 894 return GNUNET_YES;
882} 895}
883 896
884 897
@@ -917,7 +930,9 @@ GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file)
917 930
918 931
919int 932int
920GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file) 933GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file,
934 GNUNET_CHAT_FileUnindexCallback callback,
935 void *cls)
921{ 936{
922 if (!file) 937 if (!file)
923 return GNUNET_SYSERR; 938 return GNUNET_SYSERR;
@@ -929,6 +944,8 @@ GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file)
929 return GNUNET_OK; 944 return GNUNET_OK;
930 } 945 }
931 946
947 file_bind_unindex(file, callback, cls);
948
932 if (file->unindex) 949 if (file->unindex)
933 return GNUNET_OK; 950 return GNUNET_OK;
934 951