commit 7ef674b52c2bdf9f65abdcc738be8cbd588cf4aa
parent 11cd8effe7b6f6f8766dea5501b948f0b8990e82
Author: Jacki <jacki@thejackimonster.de>
Date: Wed, 3 Apr 2024 02:42:16 +0200
Change function to iterate through ticket attributes
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
7 files changed, 49 insertions(+), 115 deletions(-)
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
@@ -179,11 +179,6 @@ 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
@@ -197,14 +192,15 @@ typedef enum GNUNET_GenericReturnValue
struct GNUNET_CHAT_Account *account);
/**
- * Method called for each attribute of a specific chat handle.
+ * Iterator over attributes of a specific chat handle.
*
* @param[in,out] cls Closure from #GNUNET_CHAT_get_attributes
* @param[in] handle Chat handle
* @param[in] name Attribute name
* @param[in] value Attribute value
+ * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
*/
-typedef void
+typedef enum GNUNET_GenericReturnValue
(*GNUNET_CHAT_AttributeCallback) (void *cls,
struct GNUNET_CHAT_Handle *handle,
const char *name,
@@ -234,17 +230,19 @@ typedef enum GNUNET_GenericReturnValue
struct GNUNET_CHAT_Contact *contact);
/**
- * Iterator over chat tickets of a specific chat contact.
+ * Iterator over accessible attributes of a specific chat contact.
*
* @param[in,out] cls Closure
* @param[in] contact Chat contact
- * @param[in,out] ticket Chat ticket
+ * @param[in] name Attribute name
+ * @param[in] value Attribute value
* @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);
+(*GNUNET_CHAT_ContactAttributeCallback) (void *cls,
+ const struct GNUNET_CHAT_Contact *contact,
+ const char *name,
+ const char *value);
/**
* Iterator over chat groups of a specific chat handle.
@@ -370,20 +368,6 @@ typedef void
uint64_t size);
/**
- * Method called during a chat ticket consumption for each of its attributes.
- *
- * @param[in,out] cls Closure from #GNUNET_CHAT_ticket_consume
- * @param[in] ticket Chat ticket
- * @param[in] name Attribute name
- * @param[in] value Attribute value
- */
-typedef void
-(*GNUNET_CHAT_TicketAttributeCallback) (void *cls,
- const struct GNUNET_CHAT_Ticket *ticket,
- const char *name,
- const char *value);
-
-/**
* Start a chat handle with a certain configuration.
*
* A custom callback for warnings and message events can be provided optionally
@@ -855,18 +839,17 @@ GNUNET_CHAT_contact_is_tagged (const struct GNUNET_CHAT_Contact *contact,
const char *tag);
/**
- * Iterates through the tickets of a given <i>contact</i> with a selected
- * callback and custom closure.
+ * Calls an optional <i>callback</i> for each attribute of a given chat
+ * <i>contact</i>.
*
- * @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
+ * @param[in,out] contact Chat contact
+ * @param[in] callback Callback for attribute iteration (optional)
+ * @param[in,out] cls Closure for attribute iteration (optional)
*/
-int
-GNUNET_CHAT_contact_iterate_tickets (const struct GNUNET_CHAT_Contact *contact,
- GNUNET_CHAT_ContactTicketCallback callback,
- void *cls);
+void
+GNUNET_CHAT_contact_get_attributes (struct GNUNET_CHAT_Contact *contact,
+ GNUNET_CHAT_ContactAttributeCallback callback,
+ void *cls);
/**
* Leaves a specific <i>group</i> chat and frees its memory if it is not shared
@@ -1520,28 +1503,6 @@ GNUNET_CHAT_invitation_is_accepted (const struct GNUNET_CHAT_Invitation *invitat
enum GNUNET_GenericReturnValue
GNUNET_CHAT_invitation_is_rejected (const struct GNUNET_CHAT_Invitation *invitation);
-/**
- * Returns the contact of the issuer from a given chat <i>ticket</i>.
- *
- * @param[in] invitation Chat invitation
- * @return Chat contact
- */
-const struct GNUNET_CHAT_Contact*
-GNUNET_CHAT_ticket_get_contact (const struct GNUNET_CHAT_Ticket *ticket);
-
-/**
- * Consumes a given chat <i>ticket</i> and calls an optional <i>callback</i>
- * for each of its attributes.
- *
- * @param[in,out] ticket Chat ticket
- * @param[in] callback Callback for ticket consumption (optional)
- * @param[in,out] cls Closure for ticket consumption (optional)
- */
-void
-GNUNET_CHAT_ticket_consume (struct GNUNET_CHAT_Ticket *ticket,
- GNUNET_CHAT_TicketAttributeCallback callback,
- void *cls);
-
/**@}*/
#endif /* GNUNET_CHAT_LIB_H_ */
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h
@@ -29,13 +29,17 @@
#include <gnunet/gnunet_messenger_service.h>
#include <gnunet/gnunet_util_lib.h>
+#include "gnunet_chat_lib.h"
+
struct GNUNET_CHAT_Handle;
+struct GNUNET_CHAT_Contact;
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;
};
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
@@ -961,7 +961,7 @@ skip_msg_handing:
break;
tickets->ticket = ticket_create_from_message(
- handle, sender, &(message->msg->body.ticket)
+ handle, contact, &(message->msg->body.ticket)
);
if (!tickets->ticket)
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -31,7 +31,6 @@
#include <gnunet/gnunet_scheduler_lib.h>
#include <gnunet/gnunet_time_lib.h>
#include <libgen.h>
-#include <limits.h>
#include <strings.h>
#define _(String) ((const char*) String)
@@ -1041,32 +1040,29 @@ GNUNET_CHAT_contact_is_tagged (const struct GNUNET_CHAT_Contact *contact,
}
-int
-GNUNET_CHAT_contact_iterate_tickets (const struct GNUNET_CHAT_Contact *contact,
- GNUNET_CHAT_ContactTicketCallback callback,
- void *cls)
+void
+GNUNET_CHAT_contact_get_attributes (struct GNUNET_CHAT_Contact *contact,
+ GNUNET_CHAT_ContactAttributeCallback callback,
+ void *cls)
{
GNUNET_CHAT_VERSION_ASSERT();
if (!contact)
- return GNUNET_SYSERR;
+ return;
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;
+ ticket_consume(
+ tickets->ticket,
+ callback,
+ cls
+ );
tickets = tickets->next;
}
-
- return result;
}
@@ -2409,34 +2405,3 @@ GNUNET_CHAT_invitation_is_rejected (const struct GNUNET_CHAT_Invitation *invitat
else
return GNUNET_NO;
}
-
-
-const struct GNUNET_CHAT_Contact*
-GNUNET_CHAT_ticket_get_contact (const struct GNUNET_CHAT_Ticket *ticket)
-{
- GNUNET_CHAT_VERSION_ASSERT();
-
- if (!ticket)
- return NULL;
-
- struct GNUNET_ShortHashCode shorthash;
- util_shorthash_from_member(ticket->issuer, &shorthash);
-
- return GNUNET_CONTAINER_multishortmap_get(
- ticket->handle->contacts, &shorthash
- );
-}
-
-
-void
-GNUNET_CHAT_ticket_consume (struct GNUNET_CHAT_Ticket *ticket,
- GNUNET_CHAT_TicketAttributeCallback callback,
- void *cls)
-{
- GNUNET_CHAT_VERSION_ASSERT();
-
- if (!ticket)
- return;
-
- ticket_consume(ticket, callback, cls);
-}
diff --git a/src/gnunet_chat_ticket.c b/src/gnunet_chat_ticket.c
@@ -24,15 +24,17 @@
#include "gnunet_chat_ticket.h"
+#include "gnunet_chat_contact.h"
#include "gnunet_chat_ticket_intern.c"
#include "gnunet_chat_handle.h"
+
#include <gnunet/gnunet_messenger_service.h>
#include <gnunet/gnunet_reclaim_service.h>
#include <string.h>
struct GNUNET_CHAT_Ticket*
ticket_create_from_message (struct GNUNET_CHAT_Handle *handle,
- const struct GNUNET_MESSENGER_Contact *issuer,
+ const struct GNUNET_CHAT_Contact *issuer,
const struct GNUNET_MESSENGER_MessageTicket *message)
{
GNUNET_assert((handle) && (issuer) && (message));
@@ -40,7 +42,7 @@ ticket_create_from_message (struct GNUNET_CHAT_Handle *handle,
const struct GNUNET_CRYPTO_PublicKey *identity;
const struct GNUNET_CRYPTO_PublicKey *audience;
- identity = GNUNET_MESSENGER_contact_get_key(issuer);
+ identity = contact_get_key(issuer);
audience = GNUNET_MESSENGER_get_key(handle->messenger);
if ((!identity) || (!audience))
@@ -65,7 +67,7 @@ ticket_create_from_message (struct GNUNET_CHAT_Handle *handle,
void
ticket_consume(struct GNUNET_CHAT_Ticket *ticket,
- GNUNET_CHAT_TicketAttributeCallback callback,
+ GNUNET_CHAT_ContactAttributeCallback callback,
void *cls)
{
GNUNET_assert(ticket);
diff --git a/src/gnunet_chat_ticket.h b/src/gnunet_chat_ticket.h
@@ -31,15 +31,13 @@
#include "gnunet_chat_lib.h"
-struct GNUNET_CHAT_Handle;
-
struct GNUNET_CHAT_Ticket
{
struct GNUNET_CHAT_Handle *handle;
- const struct GNUNET_MESSENGER_Contact *issuer;
+ const struct GNUNET_CHAT_Contact *issuer;
- GNUNET_CHAT_TicketAttributeCallback callback;
+ GNUNET_CHAT_ContactAttributeCallback callback;
void *closure;
struct GNUNET_RECLAIM_Operation *op;
@@ -59,17 +57,21 @@ struct GNUNET_CHAT_Ticket
*/
struct GNUNET_CHAT_Ticket*
ticket_create_from_message (struct GNUNET_CHAT_Handle *handle,
- const struct GNUNET_MESSENGER_Contact *issuer,
+ const struct GNUNET_CHAT_Contact *issuer,
const struct GNUNET_MESSENGER_MessageTicket *message);
/**
- * Consumes a chat <i>ticket</i>.
+ * Consumes a chat <i>ticket</i> and calls a selected
+ * <i>callback</i> for each of its attributes using
+ * a custom closure.
*
* @param[in,out] ticket Chat ticket
+ * @param[in] callback Attribute callback
+ * @param[in,out] cls Closure
*/
void
ticket_consume(struct GNUNET_CHAT_Ticket *ticket,
- GNUNET_CHAT_TicketAttributeCallback callback,
+ GNUNET_CHAT_ContactAttributeCallback callback,
void *cls);
/**
diff --git a/src/gnunet_chat_ticket_intern.c b/src/gnunet_chat_ticket_intern.c
@@ -45,5 +45,5 @@ cb_ticket_consume_attribute (void *cls,
);
if (ticket->callback)
- ticket->callback(ticket->closure, ticket, attribute->name, value);
+ ticket->callback(ticket->closure, ticket->issuer, attribute->name, value);
}