diff options
author | Jacki <jacki@thejackimonster.de> | 2024-01-04 22:40:48 +0100 |
---|---|---|
committer | Jacki <jacki@thejackimonster.de> | 2024-01-04 22:40:48 +0100 |
commit | 937d01213ab94cd0f4697b81cecc860f36cc7bfb (patch) | |
tree | 9bafc2951ecad8306b2a240310060d429a24b1fc | |
parent | f20fb24047d2416023425e657cb141acc08065c4 (diff) | |
download | libgnunetchat-937d01213ab94cd0f4697b81cecc860f36cc7bfb.tar.gz libgnunetchat-937d01213ab94cd0f4697b81cecc860f36cc7bfb.zip |
Add function to iterate through tickets from a contact
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r-- | include/gnunet/gnunet_chat_lib.h | 46 | ||||
-rw-r--r-- | src/gnunet_chat_contact.h | 11 | ||||
-rw-r--r-- | src/gnunet_chat_handle.h | 5 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 29 |
4 files changed, 84 insertions, 7 deletions
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h index 8881619..12bf244 100644 --- a/include/gnunet/gnunet_chat_lib.h +++ b/include/gnunet/gnunet_chat_lib.h | |||
@@ -172,6 +172,11 @@ struct GNUNET_CHAT_File; | |||
172 | struct GNUNET_CHAT_Invitation; | 172 | struct GNUNET_CHAT_Invitation; |
173 | 173 | ||
174 | /** | 174 | /** |
175 | * Struct of a chat ticket. | ||
176 | */ | ||
177 | struct GNUNET_CHAT_Ticket; | ||
178 | |||
179 | /** | ||
175 | * Iterator over chat accounts of a specific chat handle. | 180 | * Iterator over chat accounts of a specific chat handle. |
176 | * | 181 | * |
177 | * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_accounts | 182 | * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_accounts |
@@ -179,7 +184,7 @@ struct GNUNET_CHAT_Invitation; | |||
179 | * @param[in,out] account Chat account | 184 | * @param[in,out] account Chat account |
180 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. | 185 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. |
181 | */ | 186 | */ |
182 | typedef int | 187 | typedef enum GNUNET_GenericReturnValue |
183 | (*GNUNET_CHAT_AccountCallback) (void *cls, | 188 | (*GNUNET_CHAT_AccountCallback) (void *cls, |
184 | const struct GNUNET_CHAT_Handle *handle, | 189 | const struct GNUNET_CHAT_Handle *handle, |
185 | struct GNUNET_CHAT_Account *account); | 190 | struct GNUNET_CHAT_Account *account); |
@@ -202,12 +207,25 @@ typedef void | |||
202 | * @param[in,out] contact Chat contact | 207 | * @param[in,out] contact Chat contact |
203 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. | 208 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. |
204 | */ | 209 | */ |
205 | typedef int | 210 | typedef enum GNUNET_GenericReturnValue |
206 | (*GNUNET_CHAT_ContactCallback) (void *cls, | 211 | (*GNUNET_CHAT_ContactCallback) (void *cls, |
207 | struct GNUNET_CHAT_Handle *handle, | 212 | struct GNUNET_CHAT_Handle *handle, |
208 | struct GNUNET_CHAT_Contact *contact); | 213 | struct GNUNET_CHAT_Contact *contact); |
209 | 214 | ||
210 | /** | 215 | /** |
216 | * Iterator over chat tickets of a specific chat contact. | ||
217 | * | ||
218 | * @param[in,out] cls Closure | ||
219 | * @param[in] contact Chat contact | ||
220 | * @param[in,out] ticket Chat ticket | ||
221 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. | ||
222 | */ | ||
223 | typedef enum GNUNET_GenericReturnValue | ||
224 | (*GNUNET_CHAT_ContactTicketCallback) (void *cls, | ||
225 | const struct GNUNET_CHAT_Contact *contact, | ||
226 | struct GNUNET_CHAT_Ticket *ticket); | ||
227 | |||
228 | /** | ||
211 | * Iterator over chat groups of a specific chat handle. | 229 | * Iterator over chat groups of a specific chat handle. |
212 | * | 230 | * |
213 | * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_groups | 231 | * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_groups |
@@ -215,7 +233,7 @@ typedef int | |||
215 | * @param[in,out] group Chat group | 233 | * @param[in,out] group Chat group |
216 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. | 234 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. |
217 | */ | 235 | */ |
218 | typedef int | 236 | typedef enum GNUNET_GenericReturnValue |
219 | (*GNUNET_CHAT_GroupCallback) (void *cls, | 237 | (*GNUNET_CHAT_GroupCallback) (void *cls, |
220 | struct GNUNET_CHAT_Handle *handle, | 238 | struct GNUNET_CHAT_Handle *handle, |
221 | struct GNUNET_CHAT_Group *group); | 239 | struct GNUNET_CHAT_Group *group); |
@@ -228,7 +246,7 @@ typedef int | |||
228 | * @param[in,out] contact Chat contact | 246 | * @param[in,out] contact Chat contact |
229 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. | 247 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. |
230 | */ | 248 | */ |
231 | typedef int | 249 | typedef enum GNUNET_GenericReturnValue |
232 | (*GNUNET_CHAT_GroupContactCallback) (void *cls, | 250 | (*GNUNET_CHAT_GroupContactCallback) (void *cls, |
233 | const struct GNUNET_CHAT_Group *group, | 251 | const struct GNUNET_CHAT_Group *group, |
234 | struct GNUNET_CHAT_Contact *contact); | 252 | struct GNUNET_CHAT_Contact *contact); |
@@ -241,7 +259,7 @@ typedef int | |||
241 | * @param[in] message Chat message | 259 | * @param[in] message Chat message |
242 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. | 260 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. |
243 | */ | 261 | */ |
244 | typedef int | 262 | typedef enum GNUNET_GenericReturnValue |
245 | (*GNUNET_CHAT_ContextMessageCallback) (void *cls, | 263 | (*GNUNET_CHAT_ContextMessageCallback) (void *cls, |
246 | struct GNUNET_CHAT_Context *context, | 264 | struct GNUNET_CHAT_Context *context, |
247 | const struct GNUNET_CHAT_Message *message); | 265 | const struct GNUNET_CHAT_Message *message); |
@@ -254,7 +272,7 @@ typedef int | |||
254 | * @param[in,out] file Chat file | 272 | * @param[in,out] file Chat file |
255 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. | 273 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. |
256 | */ | 274 | */ |
257 | typedef int | 275 | typedef enum GNUNET_GenericReturnValue |
258 | (*GNUNET_CHAT_ContextFileCallback) (void *cls, | 276 | (*GNUNET_CHAT_ContextFileCallback) (void *cls, |
259 | struct GNUNET_CHAT_Context *context, | 277 | struct GNUNET_CHAT_Context *context, |
260 | struct GNUNET_CHAT_File *file); | 278 | struct GNUNET_CHAT_File *file); |
@@ -270,7 +288,7 @@ typedef int | |||
270 | * #GNUNET_NO otherwise | 288 | * #GNUNET_NO otherwise |
271 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. | 289 | * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. |
272 | */ | 290 | */ |
273 | typedef int | 291 | typedef enum GNUNET_GenericReturnValue |
274 | (*GNUNET_CHAT_MessageReadReceiptCallback) (void *cls, | 292 | (*GNUNET_CHAT_MessageReadReceiptCallback) (void *cls, |
275 | const struct GNUNET_CHAT_Message *message, | 293 | const struct GNUNET_CHAT_Message *message, |
276 | const struct GNUNET_CHAT_Contact *contact, | 294 | const struct GNUNET_CHAT_Contact *contact, |
@@ -718,6 +736,20 @@ enum GNUNET_GenericReturnValue | |||
718 | GNUNET_CHAT_contact_is_blocked (const struct GNUNET_CHAT_Contact *contact); | 736 | GNUNET_CHAT_contact_is_blocked (const struct GNUNET_CHAT_Contact *contact); |
719 | 737 | ||
720 | /** | 738 | /** |
739 | * Iterates through the tickets of a given <i>contact</i> with a selected | ||
740 | * callback and custom closure. | ||
741 | * | ||
742 | * @param[in,out] contact Contact | ||
743 | * @param[in] callback Callback for ticket iteration (optional) | ||
744 | * @param[in,out] cls Closure for ticket iteration (optional) | ||
745 | * @return Amount of tickets iterated | ||
746 | */ | ||
747 | int | ||
748 | GNUNET_CHAT_contact_iterate_tickets (const struct GNUNET_CHAT_Contact *contact, | ||
749 | GNUNET_CHAT_ContactTicketCallback callback, | ||
750 | void *cls); | ||
751 | |||
752 | /** | ||
721 | * Leaves a specific <i>group</i> chat and frees its memory if it is not shared | 753 | * Leaves a specific <i>group</i> chat and frees its memory if it is not shared |
722 | * with other groups or contacts. | 754 | * with other groups or contacts. |
723 | * | 755 | * |
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h index efd7997..b580841 100644 --- a/src/gnunet_chat_contact.h +++ b/src/gnunet_chat_contact.h | |||
@@ -31,6 +31,14 @@ | |||
31 | 31 | ||
32 | struct GNUNET_CHAT_Handle; | 32 | struct GNUNET_CHAT_Handle; |
33 | struct GNUNET_CHAT_Context; | 33 | struct GNUNET_CHAT_Context; |
34 | struct GNUNET_CHAT_Ticket; | ||
35 | |||
36 | struct GNUNET_CHAT_InternalTickets | ||
37 | { | ||
38 | struct GNUNET_CHAT_Ticket *ticket; | ||
39 | struct GNUNET_CHAT_InternalTickets *next; | ||
40 | struct GNUNET_CHAT_InternalTickets *prev; | ||
41 | }; | ||
34 | 42 | ||
35 | struct GNUNET_CHAT_Contact | 43 | struct GNUNET_CHAT_Contact |
36 | { | 44 | { |
@@ -39,6 +47,9 @@ struct GNUNET_CHAT_Contact | |||
39 | 47 | ||
40 | const struct GNUNET_MESSENGER_Contact *member; | 48 | const struct GNUNET_MESSENGER_Contact *member; |
41 | 49 | ||
50 | struct GNUNET_CHAT_InternalTickets *tickets_head; | ||
51 | struct GNUNET_CHAT_InternalTickets *tickets_tail; | ||
52 | |||
42 | char *public_key; | 53 | char *public_key; |
43 | void *user_pointer; | 54 | void *user_pointer; |
44 | 55 | ||
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h index f10c1e2..40667fe 100644 --- a/src/gnunet_chat_handle.h +++ b/src/gnunet_chat_handle.h | |||
@@ -345,6 +345,11 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle, | |||
345 | const struct GNUNET_GNSRECORD_Data *data); | 345 | const struct GNUNET_GNSRECORD_Data *data); |
346 | 346 | ||
347 | /** | 347 | /** |
348 | * Updates the tickets of a given chat <i>handle</i>, revoking | ||
349 | * all tickets of a <i>identity</i>. | ||
350 | * | ||
351 | * @param[in,out] handle Chat handle | ||
352 | * @param[in] identity Identity private key | ||
348 | */ | 353 | */ |
349 | void | 354 | void |
350 | handle_update_tickets (struct GNUNET_CHAT_Handle *handle, | 355 | handle_update_tickets (struct GNUNET_CHAT_Handle *handle, |
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index f2dd839..b922171 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -767,6 +767,35 @@ GNUNET_CHAT_contact_is_blocked (const struct GNUNET_CHAT_Contact *contact) | |||
767 | } | 767 | } |
768 | 768 | ||
769 | 769 | ||
770 | int | ||
771 | GNUNET_CHAT_contact_iterate_tickets (const struct GNUNET_CHAT_Contact *contact, | ||
772 | GNUNET_CHAT_ContactTicketCallback callback, | ||
773 | void *cls) | ||
774 | { | ||
775 | GNUNET_CHAT_VERSION_ASSERT(); | ||
776 | |||
777 | if (!contact) | ||
778 | return GNUNET_SYSERR; | ||
779 | |||
780 | struct GNUNET_CHAT_InternalTickets *tickets; | ||
781 | int result = 0; | ||
782 | |||
783 | tickets = contact->tickets_head; | ||
784 | |||
785 | while (tickets) | ||
786 | { | ||
787 | result++; | ||
788 | |||
789 | if ((callback) && (GNUNET_NO == callback(cls, contact, tickets->ticket))) | ||
790 | break; | ||
791 | |||
792 | tickets = tickets->next; | ||
793 | } | ||
794 | |||
795 | return result; | ||
796 | } | ||
797 | |||
798 | |||
770 | enum GNUNET_GenericReturnValue | 799 | enum GNUNET_GenericReturnValue |
771 | GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group) | 800 | GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group) |
772 | { | 801 | { |