libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit afd5d7cb5fdb8d2cf20f50d3942f553be78ca0ca
parent 59f4fc5b4ea2a5426446f9c81a1acaf104e71a8f
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Fri, 11 Mar 2022 02:44:35 +0100

Added new declarations of functions for lobbies

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
Minclude/gnunet_chat_lib.h | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/gnunet_chat_lib.c | 65++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 149 insertions(+), 3 deletions(-)

diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h @@ -116,6 +116,16 @@ struct GNUNET_CHAT_Handle; struct GNUNET_CHAT_Account; /** + * Struct of a chat URI. + */ +struct GNUNET_CHAT_Uri; + +/** + * Struct of a chat lobby. + */ +struct GNUNET_CHAT_Lobby; + +/** * Struct of a chat contact. */ struct GNUNET_CHAT_Contact; @@ -159,6 +169,16 @@ typedef int struct GNUNET_CHAT_Account *account); /** + * Method called when a lobby is opened to share with others via a chat URI. + * + * @param[in,out] cls Closure from #GNUNET_CHAT_lobby_open + * @param[in] uri Chat URI of the lobby + */ +typedef void +(*GNUNET_CHAT_LobbyCallback) (void *cls, + const struct GNUNET_CHAT_Uri *uri); + +/** * Iterator over chat contacts of a specific chat handle. * * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_contacts @@ -299,7 +319,8 @@ typedef void struct GNUNET_CHAT_Handle* GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *directory, - GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls); + GNUNET_CHAT_ContextMessageCallback msg_cb, + void *msg_cls); /** * Stops a chat handle closing all its remaining resources and frees the @@ -410,6 +431,68 @@ const char* GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle); /** + * Convert an UTF-8 String to a chat URI which will be newly allocated. + * + * @param[in] uri UTF-8 string to parse + * @param[out] emsg Where to store the parser error message (if any) + * @return NULL on error + */ +struct GNUNET_CHAT_Uri* +GNUNET_CHAT_uri_parse (const char *uri, + char **emsg); + +/** + * Convert a chat URI to a UTF-8 String. + * + * @param[in] uri Chat URI + * @return The UTF-8 string representing the URI + */ +char* +GNUNET_CHAT_uri_to_string (const struct GNUNET_CHAT_Uri *uri); + +/** + * Free an allocated chat URI. + * + * @param[in,out] uri Chat URI + */ +void +GNUNET_CHAT_uri_destroy (struct GNUNET_CHAT_Uri *uri); + +/** + * Opens an empty chat lobby which will expire after a custom <i>delay</i>. + * + * @param[in,out] handle Chat handle + * @param[in] delay Expiration delay + * @param[in] callback Callback for the lobby opening + * @param[in,out] cls Closure for the lobby opening (optional) + * @return Chat lobby + */ +struct GNUNET_CHAT_Lobby* +GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle, + struct GNUNET_TIME_Relative delay, + GNUNET_CHAT_LobbyCallback callback, + void *cls); + +/** + * Closes a chat <i>lobby</i> overriding the expiration to be now. + * + * @param[in,out] lobby Chat lobby + */ +void +GNUNET_CHAT_lobby_close (struct GNUNET_CHAT_Lobby *lobby); + +/** + * Joins an open lobby via URI with a given chat <i>handle</i> if it can still + * be resolved (depends on connection and expiration of the lobby). + * + * @param[in,out] handle Chat handle + * @param[in] uri Chat URI + */ +void +GNUNET_CHAT_lobby_join (struct GNUNET_CHAT_Handle *handle, + const struct GNUNET_CHAT_Uri *uri); + +/** * Iterates through the contacts of a given chat <i>handle</i> with a selected * callback and custom closure. * @@ -426,7 +509,7 @@ GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle, /** * Returns the provided name of a given <i>account</i> or NULL on failure. * - * @param account Chat account + * @param[in] account Chat account * @return Name or NULL */ const char* diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -208,6 +208,68 @@ GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle) } +struct GNUNET_CHAT_Uri* +GNUNET_CHAT_uri_parse (const char *uri, + char **emsg) +{ + if (!uri) + return NULL; + + // TODO + + return NULL; +} + + +char* +GNUNET_CHAT_uri_to_string (const struct GNUNET_CHAT_Uri *uri) +{ + if (!uri) + return NULL; + + // TODO + + return NULL; +} + + +void +GNUNET_CHAT_uri_destroy (struct GNUNET_CHAT_Uri *uri) +{ + if (!uri) + return; + + GNUNET_free(uri); +} + + +struct GNUNET_CHAT_Lobby* +GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle, + struct GNUNET_TIME_Relative delay, + GNUNET_CHAT_LobbyCallback callback, + void *cls) +{ + // TODO + + return NULL; +} + + +void +GNUNET_CHAT_lobby_close (struct GNUNET_CHAT_Lobby *lobby) +{ + // TODO +} + + +void +GNUNET_CHAT_lobby_join (struct GNUNET_CHAT_Handle *handle, + const struct GNUNET_CHAT_Uri *uri) +{ + // TODO +} + + void GNUNET_CHAT_set_user_pointer (struct GNUNET_CHAT_Handle *handle, void *user_pointer) @@ -613,7 +675,8 @@ GNUNET_CHAT_context_get_status (const struct GNUNET_CHAT_Context *context) if ((!context) || (!(context->room))) return GNUNET_SYSERR; - if (1 >= GNUNET_MESSENGER_iterate_members(context->room, NULL, NULL)) + if ((GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN == context->type) || + (1 >= GNUNET_MESSENGER_iterate_members(context->room, NULL, NULL))) return GNUNET_NO; return GNUNET_OK;