commit 937d01213ab94cd0f4697b81cecc860f36cc7bfb
parent f20fb24047d2416023425e657cb141acc08065c4
Author: Jacki <jacki@thejackimonster.de>
Date: Thu, 4 Jan 2024 22:40:48 +0100
Add function to iterate through tickets from a contact
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
4 files changed, 84 insertions(+), 7 deletions(-)
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
@@ -172,6 +172,11 @@ struct GNUNET_CHAT_File;
struct GNUNET_CHAT_Invitation;
/**
+ * Struct of a chat ticket.
+ */
+struct GNUNET_CHAT_Ticket;
+
+/**
* Iterator over chat accounts of a specific chat handle.
*
* @param[in,out] cls Closure from #GNUNET_CHAT_iterate_accounts
@@ -179,7 +184,7 @@ struct GNUNET_CHAT_Invitation;
* @param[in,out] account Chat account
* @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
*/
-typedef int
+typedef enum GNUNET_GenericReturnValue
(*GNUNET_CHAT_AccountCallback) (void *cls,
const struct GNUNET_CHAT_Handle *handle,
struct GNUNET_CHAT_Account *account);
@@ -202,12 +207,25 @@ typedef void
* @param[in,out] contact Chat contact
* @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
*/
-typedef int
+typedef enum GNUNET_GenericReturnValue
(*GNUNET_CHAT_ContactCallback) (void *cls,
struct GNUNET_CHAT_Handle *handle,
struct GNUNET_CHAT_Contact *contact);
/**
+ * Iterator over chat tickets of a specific chat contact.
+ *
+ * @param[in,out] cls Closure
+ * @param[in] contact Chat contact
+ * @param[in,out] ticket Chat ticket
+ * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
+ */
+typedef enum GNUNET_GenericReturnValue
+(*GNUNET_CHAT_ContactTicketCallback) (void *cls,
+ const struct GNUNET_CHAT_Contact *contact,
+ struct GNUNET_CHAT_Ticket *ticket);
+
+/**
* Iterator over chat groups of a specific chat handle.
*
* @param[in,out] cls Closure from #GNUNET_CHAT_iterate_groups
@@ -215,7 +233,7 @@ typedef int
* @param[in,out] group Chat group
* @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
*/
-typedef int
+typedef enum GNUNET_GenericReturnValue
(*GNUNET_CHAT_GroupCallback) (void *cls,
struct GNUNET_CHAT_Handle *handle,
struct GNUNET_CHAT_Group *group);
@@ -228,7 +246,7 @@ typedef int
* @param[in,out] contact Chat contact
* @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
*/
-typedef int
+typedef enum GNUNET_GenericReturnValue
(*GNUNET_CHAT_GroupContactCallback) (void *cls,
const struct GNUNET_CHAT_Group *group,
struct GNUNET_CHAT_Contact *contact);
@@ -241,7 +259,7 @@ typedef int
* @param[in] message Chat message
* @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
*/
-typedef int
+typedef enum GNUNET_GenericReturnValue
(*GNUNET_CHAT_ContextMessageCallback) (void *cls,
struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_Message *message);
@@ -254,7 +272,7 @@ typedef int
* @param[in,out] file Chat file
* @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
*/
-typedef int
+typedef enum GNUNET_GenericReturnValue
(*GNUNET_CHAT_ContextFileCallback) (void *cls,
struct GNUNET_CHAT_Context *context,
struct GNUNET_CHAT_File *file);
@@ -270,7 +288,7 @@ typedef int
* #GNUNET_NO otherwise
* @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
*/
-typedef int
+typedef enum GNUNET_GenericReturnValue
(*GNUNET_CHAT_MessageReadReceiptCallback) (void *cls,
const struct GNUNET_CHAT_Message *message,
const struct GNUNET_CHAT_Contact *contact,
@@ -718,6 +736,20 @@ enum GNUNET_GenericReturnValue
GNUNET_CHAT_contact_is_blocked (const struct GNUNET_CHAT_Contact *contact);
/**
+ * Iterates through the tickets of a given <i>contact</i> with a selected
+ * callback and custom closure.
+ *
+ * @param[in,out] contact Contact
+ * @param[in] callback Callback for ticket iteration (optional)
+ * @param[in,out] cls Closure for ticket iteration (optional)
+ * @return Amount of tickets iterated
+ */
+int
+GNUNET_CHAT_contact_iterate_tickets (const struct GNUNET_CHAT_Contact *contact,
+ GNUNET_CHAT_ContactTicketCallback callback,
+ void *cls);
+
+/**
* Leaves a specific <i>group</i> chat and frees its memory if it is not shared
* with other groups or contacts.
*
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h
@@ -31,6 +31,14 @@
struct GNUNET_CHAT_Handle;
struct GNUNET_CHAT_Context;
+struct GNUNET_CHAT_Ticket;
+
+struct GNUNET_CHAT_InternalTickets
+{
+ struct GNUNET_CHAT_Ticket *ticket;
+ struct GNUNET_CHAT_InternalTickets *next;
+ struct GNUNET_CHAT_InternalTickets *prev;
+};
struct GNUNET_CHAT_Contact
{
@@ -39,6 +47,9 @@ struct GNUNET_CHAT_Contact
const struct GNUNET_MESSENGER_Contact *member;
+ struct GNUNET_CHAT_InternalTickets *tickets_head;
+ struct GNUNET_CHAT_InternalTickets *tickets_tail;
+
char *public_key;
void *user_pointer;
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
@@ -345,6 +345,11 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle,
const struct GNUNET_GNSRECORD_Data *data);
/**
+ * Updates the tickets of a given chat <i>handle</i>, revoking
+ * all tickets of a <i>identity</i>.
+ *
+ * @param[in,out] handle Chat handle
+ * @param[in] identity Identity private key
*/
void
handle_update_tickets (struct GNUNET_CHAT_Handle *handle,
diff --git 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)
}
+int
+GNUNET_CHAT_contact_iterate_tickets (const struct GNUNET_CHAT_Contact *contact,
+ GNUNET_CHAT_ContactTicketCallback callback,
+ void *cls)
+{
+ GNUNET_CHAT_VERSION_ASSERT();
+
+ if (!contact)
+ return GNUNET_SYSERR;
+
+ struct GNUNET_CHAT_InternalTickets *tickets;
+ int result = 0;
+
+ tickets = contact->tickets_head;
+
+ while (tickets)
+ {
+ result++;
+
+ if ((callback) && (GNUNET_NO == callback(cls, contact, tickets->ticket)))
+ break;
+
+ tickets = tickets->next;
+ }
+
+ return result;
+}
+
+
enum GNUNET_GenericReturnValue
GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group)
{