aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacki <jacki@thejackimonster.de>2024-04-19 17:06:39 +0200
committerJacki <jacki@thejackimonster.de>2024-04-19 17:06:39 +0200
commit3190e88262a22b847b6f2c73ebf01ceae726c153 (patch)
tree6857b38882fd6f45ebace4952cbd553dc28f2143
parent6e68e9f9b50685a715e6ed73253de14c5ba0995b (diff)
downloadlibgnunetchat-master.tar.gz
libgnunetchat-master.zip
Implement function to iterate through all filesHEADmaster
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r--include/gnunet/gnunet_chat_lib.h27
-rw-r--r--src/gnunet_chat_lib.c23
-rw-r--r--src/gnunet_chat_lib_intern.c27
3 files changed, 77 insertions, 0 deletions
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
index 979a1a6..9620b61 100644
--- a/include/gnunet/gnunet_chat_lib.h
+++ b/include/gnunet/gnunet_chat_lib.h
@@ -248,6 +248,19 @@ typedef void
248 const struct GNUNET_CHAT_Uri *uri); 248 const struct GNUNET_CHAT_Uri *uri);
249 249
250/** 250/**
251 * Iterator over chat files of a specific chat handle.
252 *
253 * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_files
254 * @param[in,out] handle Chat handle
255 * @param[in,out] file Chat file
256 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
257 */
258typedef enum GNUNET_GenericReturnValue
259(*GNUNET_CHAT_FileCallback) (void *cls,
260 struct GNUNET_CHAT_Handle *handle,
261 struct GNUNET_CHAT_File *file);
262
263/**
251 * Iterator over chat contacts of a specific chat handle. 264 * Iterator over chat contacts of a specific chat handle.
252 * 265 *
253 * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_contacts 266 * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_contacts
@@ -714,6 +727,20 @@ GNUNET_CHAT_upload_file (struct GNUNET_CHAT_Handle *handle,
714 void *cls); 727 void *cls);
715 728
716/** 729/**
730 * Iterates through the files of a given chat <i>handle</i> with a selected
731 * callback and custom closure.
732 *
733 * @param[in,out] handle Chat handle
734 * @param[in] callback Callback for file iteration (optional)
735 * @param[in,out] cls Closure for file iteration (optional)
736 * @return Amount of files iterated or #GNUNET_SYSERR on failure
737 */
738int
739GNUNET_CHAT_iterate_files (struct GNUNET_CHAT_Handle *handle,
740 GNUNET_CHAT_FileCallback callback,
741 void *cls);
742
743/**
717 * Sets a custom <i>user pointer</i> to a given chat <i>handle</i> so it can 744 * Sets a custom <i>user pointer</i> to a given chat <i>handle</i> so it can
718 * be accessed in all handle related callbacks. 745 * be accessed in all handle related callbacks.
719 * 746 *
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index 182f241..f6a0379 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -899,6 +899,29 @@ file_binding:
899} 899}
900 900
901 901
902int
903GNUNET_CHAT_iterate_files (struct GNUNET_CHAT_Handle *handle,
904 GNUNET_CHAT_FileCallback callback,
905 void *cls)
906{
907 GNUNET_CHAT_VERSION_ASSERT();
908
909 if ((!handle) || (handle->destruction))
910 return GNUNET_SYSERR;
911
912 struct GNUNET_CHAT_IterateFiles it;
913 it.handle = handle;
914 it.cb = callback;
915 it.cls = cls;
916
917 return GNUNET_CONTAINER_multihashmap_iterate(
918 handle->files,
919 it_iterate_files,
920 &it
921 );
922}
923
924
902void 925void
903GNUNET_CHAT_set_user_pointer (struct GNUNET_CHAT_Handle *handle, 926GNUNET_CHAT_set_user_pointer (struct GNUNET_CHAT_Handle *handle,
904 void *user_pointer) 927 void *user_pointer)
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
index ead5b51..fbdd99a 100644
--- a/src/gnunet_chat_lib_intern.c
+++ b/src/gnunet_chat_lib_intern.c
@@ -125,6 +125,33 @@ drop_lookup:
125 GNUNET_free(lookups); 125 GNUNET_free(lookups);
126} 126}
127 127
128struct GNUNET_CHAT_IterateFiles
129{
130 struct GNUNET_CHAT_Handle *handle;
131 GNUNET_CHAT_FileCallback cb;
132 void *cls;
133};
134
135enum GNUNET_GenericReturnValue
136it_iterate_files (void *cls,
137 GNUNET_UNUSED const struct GNUNET_HashCode *key,
138 void *value)
139{
140 GNUNET_assert((cls) && (key));
141
142 struct GNUNET_CHAT_IterateFiles *it = cls;
143
144 if (!(it->cb))
145 return GNUNET_YES;
146
147 struct GNUNET_CHAT_File *file = (struct GNUNET_CHAT_File*) value;
148
149 if (!file)
150 return GNUNET_YES;
151
152 return it->cb(it->cls, it->handle, file);
153}
154
128struct GNUNET_CHAT_HandleIterateContacts 155struct GNUNET_CHAT_HandleIterateContacts
129{ 156{
130 struct GNUNET_CHAT_Handle *handle; 157 struct GNUNET_CHAT_Handle *handle;