aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-10-10 16:56:55 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2021-10-10 16:56:55 +0200
commit242d75e5ceb10403e62abfb52c9381fc4351d9b5 (patch)
tree46999c6817fe74d74570f3f28160422fac6dac46
parent5e3ed6ef9f9d447a4ece18f79a4993c0630047c3 (diff)
downloadlibgnunetchat-242d75e5ceb10403e62abfb52c9381fc4351d9b5.tar.gz
libgnunetchat-242d75e5ceb10403e62abfb52c9381fc4351d9b5.zip
Merged callbacks and added meta messages
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--include/gnunet_chat_lib.h45
-rw-r--r--src/gnunet_chat_handle.c7
-rw-r--r--src/gnunet_chat_handle.h7
-rw-r--r--src/gnunet_chat_handle_intern.c11
-rw-r--r--src/gnunet_chat_lib.c16
-rw-r--r--src/gnunet_chat_message.c19
-rw-r--r--src/gnunet_chat_message.h20
7 files changed, 83 insertions, 42 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h
index cf53464..06b7478 100644
--- a/include/gnunet_chat_lib.h
+++ b/include/gnunet_chat_lib.h
@@ -45,39 +45,49 @@
45enum GNUNET_CHAT_MessageKind 45enum GNUNET_CHAT_MessageKind
46{ 46{
47 /** 47 /**
48 * The kind to inform that something went wrong.
49 */
50 GNUNET_CHAT_KIND_WARNING = 1, /**< GNUNET_CHAT_KIND_WARNING */
51
52 /**
53 * The kind to inform that the application can be used.
54 */
55 GNUNET_CHAT_KIND_LOGIN = 2, /**< GNUNET_CHAT_KIND_LOGIN */
56
57 /**
48 * The kind to inform that a contact has joined a chat. 58 * The kind to inform that a contact has joined a chat.
49 */ 59 */
50 GNUNET_CHAT_KIND_JOIN = 1, /**< GNUNET_CHAT_KIND_JOIN */ 60 GNUNET_CHAT_KIND_JOIN = 3, /**< GNUNET_CHAT_KIND_JOIN */
51 61
52 /** 62 /**
53 * The kind to inform that a contact has left a chat. 63 * The kind to inform that a contact has left a chat.
54 */ 64 */
55 GNUNET_CHAT_KIND_LEAVE = 2, /**< GNUNET_CHAT_KIND_LEAVE */ 65 GNUNET_CHAT_KIND_LEAVE = 4, /**< GNUNET_CHAT_KIND_LEAVE */
56 66
57 /** 67 /**
58 * The kind to inform that a contact has changed. 68 * The kind to inform that a contact has changed.
59 */ 69 */
60 GNUNET_CHAT_KIND_CONTACT = 3, /**< GNUNET_CHAT_KIND_CONTACT */ 70 GNUNET_CHAT_KIND_CONTACT = 5, /**< GNUNET_CHAT_KIND_CONTACT */
61 71
62 /** 72 /**
63 * The kind to describe an invitation to a different chat. 73 * The kind to describe an invitation to a different chat.
64 */ 74 */
65 GNUNET_CHAT_KIND_INVITATION = 4, /**< GNUNET_CHAT_KIND_INVITATION */ 75 GNUNET_CHAT_KIND_INVITATION = 6, /**< GNUNET_CHAT_KIND_INVITATION */
66 76
67 /** 77 /**
68 * The kind to describe a text message. 78 * The kind to describe a text message.
69 */ 79 */
70 GNUNET_CHAT_KIND_TEXT = 5, /**< GNUNET_CHAT_KIND_TEXT */ 80 GNUNET_CHAT_KIND_TEXT = 7, /**< GNUNET_CHAT_KIND_TEXT */
71 81
72 /** 82 /**
73 * The kind to describe a shared file. 83 * The kind to describe a shared file.
74 */ 84 */
75 GNUNET_CHAT_KIND_FILE = 6, /**< GNUNET_CHAT_KIND_FILE */ 85 GNUNET_CHAT_KIND_FILE = 8, /**< GNUNET_CHAT_KIND_FILE */
76 86
77 /** 87 /**
78 * The kind to inform about a deletion of a previous message. 88 * The kind to inform about a deletion of a previous message.
79 */ 89 */
80 GNUNET_CHAT_KIND_DELETION = 7, /**< GNUNET_CHAT_KIND_DELETION */ 90 GNUNET_CHAT_KIND_DELETION = 9, /**< GNUNET_CHAT_KIND_DELETION */
81 91
82 /** 92 /**
83 * An unknown kind of message. 93 * An unknown kind of message.
@@ -121,19 +131,6 @@ struct GNUNET_CHAT_File;
121struct GNUNET_CHAT_Invitation; 131struct GNUNET_CHAT_Invitation;
122 132
123/** 133/**
124 * Method called whenever an issue occurs regarding a certain chat context
125 * of a specific chat handle.
126 *
127 * @param[in,out] cls Closure from #GNUNET_CHAT_start
128 * @param[in,out] handle Chat handle
129 * @param[in,out] context Chat context
130 * @param[in] reason Reason indicating the issue
131 */
132typedef void
133(*GNUNET_CHAT_WarningCallback) (void *cls, struct GNUNET_CHAT_Handle *handle,
134 struct GNUNET_CHAT_Context *context, int reason);
135
136/**
137 * Iterator over chat contacts of a specific chat handle. 134 * Iterator over chat contacts of a specific chat handle.
138 * 135 *
139 * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_contacts 136 * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_contacts
@@ -173,7 +170,7 @@ typedef int
173 * Iterator over chat messages in a specific chat context. 170 * Iterator over chat messages in a specific chat context.
174 * 171 *
175 * @param[in,out] cls Closure from #GNUNET_CHAT_context_iterate_messages 172 * @param[in,out] cls Closure from #GNUNET_CHAT_context_iterate_messages
176 * @param[in,out] context Chat context 173 * @param[in,out] context Chat context or NULL
177 * @param[in] message Chat message 174 * @param[in] message Chat message
178 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. 175 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
179 */ 176 */
@@ -256,8 +253,6 @@ typedef void
256 * @param[in] cfg Configuration 253 * @param[in] cfg Configuration
257 * @param[in] directory Application directory path (optional) 254 * @param[in] directory Application directory path (optional)
258 * @param[in] name User name (optional) 255 * @param[in] name User name (optional)
259 * @param[in] warn_cb Callback for warnings (optional)
260 * @param[in,out] warn_cls Closure for warnings (optional)
261 * @param[in] msg_cb Callback for message events (optional) 256 * @param[in] msg_cb Callback for message events (optional)
262 * @param[in,out] msg_cls Closure for message events (optional) 257 * @param[in,out] msg_cls Closure for message events (optional)
263 * @return Chat handle 258 * @return Chat handle
@@ -266,7 +261,6 @@ struct GNUNET_CHAT_Handle*
266GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 261GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
267 const char *directory, 262 const char *directory,
268 const char *name, 263 const char *name,
269 GNUNET_CHAT_WarningCallback warn_cb, void *warn_cls,
270 GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls); 264 GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls);
271 265
272/** 266/**
@@ -675,7 +669,8 @@ GNUNET_CHAT_message_get_read_receipt (const struct GNUNET_CHAT_Message *message,
675 669
676/** 670/**
677 * Returns the text of a given <i>message</i> if its kind is 671 * Returns the text of a given <i>message</i> if its kind is
678 * #GNUNET_CHAT_KIND_TEXT, otherwise it returns NULL. 672 * #GNUNET_CHAT_KIND_TEXT or #GNUNET_CHAT_KIND_WARNING,
673 * otherwise it returns NULL.
679 * 674 *
680 * @param[in] message Message 675 * @param[in] message Message
681 * @return The text of message or NULL 676 * @return The text of message or NULL
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index 7c9e578..76454a5 100644
--- a/src/gnunet_chat_handle.c
+++ b/src/gnunet_chat_handle.c
@@ -31,9 +31,7 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
31 const char *directory, 31 const char *directory,
32 const char *name, 32 const char *name,
33 GNUNET_CHAT_ContextMessageCallback msg_cb, 33 GNUNET_CHAT_ContextMessageCallback msg_cb,
34 void *msg_cls, 34 void *msg_cls)
35 GNUNET_CHAT_WarningCallback warn_cb,
36 void *warn_cls)
37{ 35{
38 struct GNUNET_CHAT_Handle* handle = GNUNET_new(struct GNUNET_CHAT_Handle); 36 struct GNUNET_CHAT_Handle* handle = GNUNET_new(struct GNUNET_CHAT_Handle);
39 37
@@ -48,9 +46,6 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
48 handle->msg_cb = msg_cb; 46 handle->msg_cb = msg_cb;
49 handle->msg_cls = msg_cls; 47 handle->msg_cls = msg_cls;
50 48
51 handle->warn_cb = warn_cb;
52 handle->warn_cls = warn_cls;
53
54 handle->files = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); 49 handle->files = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO);
55 handle->contexts = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); 50 handle->contexts = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO);
56 handle->contacts = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); 51 handle->contacts = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO);
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index 07f39cb..2d3f8e8 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -45,9 +45,6 @@ struct GNUNET_CHAT_Handle
45 GNUNET_CHAT_ContextMessageCallback msg_cb; 45 GNUNET_CHAT_ContextMessageCallback msg_cb;
46 void *msg_cls; 46 void *msg_cls;
47 47
48 GNUNET_CHAT_WarningCallback warn_cb;
49 void *warn_cls;
50
51 struct GNUNET_CONTAINER_MultiHashMap *files; 48 struct GNUNET_CONTAINER_MultiHashMap *files;
52 struct GNUNET_CONTAINER_MultiHashMap *contexts; 49 struct GNUNET_CONTAINER_MultiHashMap *contexts;
53 struct GNUNET_CONTAINER_MultiShortmap *contacts; 50 struct GNUNET_CONTAINER_MultiShortmap *contacts;
@@ -65,9 +62,7 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
65 const char *directory, 62 const char *directory,
66 const char *name, 63 const char *name,
67 GNUNET_CHAT_ContextMessageCallback msg_cb, 64 GNUNET_CHAT_ContextMessageCallback msg_cb,
68 void *msg_cls, 65 void *msg_cls);
69 GNUNET_CHAT_WarningCallback warn_cb,
70 void *warn_cls);
71 66
72void 67void
73handle_destroy (struct GNUNET_CHAT_Handle* handle); 68handle_destroy (struct GNUNET_CHAT_Handle* handle);
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index 14dcbd0..10bea17 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -364,6 +364,17 @@ on_handle_identity(void *cls,
364 (0 < GNUNET_CONTAINER_multishortmap_size(handle->contacts))) 364 (0 < GNUNET_CONTAINER_multishortmap_size(handle->contacts)))
365 return; 365 return;
366 366
367 if (!handle->msg_cb)
368 goto skip_login;
369
370 struct GNUNET_CHAT_Message *msg = message_create_internally(
371 NULL, GNUNET_CHAT_FLAG_LOGIN, NULL
372 );
373
374 handle->msg_cb(handle->msg_cls, NULL, msg);
375 message_destroy(msg);
376
377skip_login:
367 GNUNET_MESSENGER_find_rooms( 378 GNUNET_MESSENGER_find_rooms(
368 handle->messenger, NULL, find_handle_rooms, handle 379 handle->messenger, NULL, find_handle_rooms, handle
369 ); 380 );
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index ab5da74..f985854 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -41,7 +41,6 @@ struct GNUNET_CHAT_Handle*
41GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 41GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
42 const char *directory, 42 const char *directory,
43 const char *name, 43 const char *name,
44 GNUNET_CHAT_WarningCallback warn_cb, void *warn_cls,
45 GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls) 44 GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls)
46{ 45{
47 if (!cfg) 46 if (!cfg)
@@ -49,8 +48,7 @@ GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
49 48
50 return handle_create_from_config( 49 return handle_create_from_config(
51 cfg, directory, name, 50 cfg, directory, name,
52 msg_cb, msg_cls, 51 msg_cb, msg_cls
53 warn_cb, warn_cls
54 ); 52 );
55} 53}
56 54
@@ -670,6 +668,16 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message)
670 if ((!message) || (!(message->msg))) 668 if ((!message) || (!(message->msg)))
671 return GNUNET_CHAT_KIND_UNKNOWN; 669 return GNUNET_CHAT_KIND_UNKNOWN;
672 670
671 switch (message->flag)
672 {
673 case GNUNET_CHAT_FLAG_WARNING:
674 return GNUNET_CHAT_KIND_WARNING;
675 case GNUNET_CHAT_FLAG_LOGIN:
676 return GNUNET_CHAT_KIND_LOGIN;
677 default:
678 break;
679 }
680
673 switch (message->msg->header.kind) 681 switch (message->msg->header.kind)
674 { 682 {
675 case GNUNET_MESSENGER_KIND_JOIN: 683 case GNUNET_MESSENGER_KIND_JOIN:
@@ -782,6 +790,8 @@ GNUNET_CHAT_message_get_text (const struct GNUNET_CHAT_Message *message)
782 if ((!message) || (!(message->msg))) 790 if ((!message) || (!(message->msg)))
783 return NULL; 791 return NULL;
784 792
793 if (GNUNET_CHAT_FLAG_WARNING == message->flag)
794 return message->warning;
785 if (GNUNET_MESSENGER_KIND_TEXT != message->msg->header.kind) 795 if (GNUNET_MESSENGER_KIND_TEXT != message->msg->header.kind)
786 return NULL; 796 return NULL;
787 797
diff --git a/src/gnunet_chat_message.c b/src/gnunet_chat_message.c
index b88edac..a396cf8 100644
--- a/src/gnunet_chat_message.c
+++ b/src/gnunet_chat_message.c
@@ -36,12 +36,31 @@ message_create_from_msg (struct GNUNET_CHAT_Context *context,
36 36
37 GNUNET_memcpy(&(message->hash), hash, sizeof(message->hash)); 37 GNUNET_memcpy(&(message->hash), hash, sizeof(message->hash));
38 message->flags = flags; 38 message->flags = flags;
39 message->flag = GNUNET_CHAT_FLAG_NONE;
39 40
40 message->msg = msg; 41 message->msg = msg;
41 42
42 return message; 43 return message;
43} 44}
44 45
46struct GNUNET_CHAT_Message*
47message_create_internally (struct GNUNET_CHAT_Context *context,
48 enum GNUNET_CHAT_MessageFlag flag,
49 const char *warning)
50{
51 struct GNUNET_CHAT_Message *message = GNUNET_new(struct GNUNET_CHAT_Message);
52
53 message->context = context;
54
55 memset(&(message->hash), 0, sizeof(message->hash));
56 message->flags = GNUNET_MESSENGER_FLAG_PRIVATE;
57 message->flag = flag;
58
59 message->warning = warning;
60
61 return message;
62}
63
45void 64void
46message_destroy (struct GNUNET_CHAT_Message* message) 65message_destroy (struct GNUNET_CHAT_Message* message)
47{ 66{
diff --git a/src/gnunet_chat_message.h b/src/gnunet_chat_message.h
index 4e2e504..21a4e15 100644
--- a/src/gnunet_chat_message.h
+++ b/src/gnunet_chat_message.h
@@ -41,14 +41,25 @@ struct GNUNET_CHAT_MessageList
41 struct GNUNET_CHAT_MessageList *next; 41 struct GNUNET_CHAT_MessageList *next;
42}; 42};
43 43
44enum GNUNET_CHAT_MessageFlag
45{
46 GNUNET_CHAT_FLAG_NONE = 0,
47 GNUNET_CHAT_FLAG_WARNING = 1,
48 GNUNET_CHAT_FLAG_LOGIN = 2
49};
50
44struct GNUNET_CHAT_Message 51struct GNUNET_CHAT_Message
45{ 52{
46 struct GNUNET_CHAT_Context *context; 53 struct GNUNET_CHAT_Context *context;
47 54
55 union {
56 const struct GNUNET_MESSENGER_Message *msg;
57 const char *warning;
58 };
59
48 struct GNUNET_HashCode hash; 60 struct GNUNET_HashCode hash;
49 enum GNUNET_MESSENGER_MessageFlags flags; 61 enum GNUNET_MESSENGER_MessageFlags flags;
50 62 enum GNUNET_CHAT_MessageFlag flag;
51 const struct GNUNET_MESSENGER_Message *msg;
52}; 63};
53 64
54struct GNUNET_CHAT_Message* 65struct GNUNET_CHAT_Message*
@@ -57,6 +68,11 @@ message_create_from_msg (struct GNUNET_CHAT_Context *context,
57 enum GNUNET_MESSENGER_MessageFlags flags, 68 enum GNUNET_MESSENGER_MessageFlags flags,
58 const struct GNUNET_MESSENGER_Message *msg); 69 const struct GNUNET_MESSENGER_Message *msg);
59 70
71struct GNUNET_CHAT_Message*
72message_create_internally (struct GNUNET_CHAT_Context *context,
73 enum GNUNET_CHAT_MessageFlag flag,
74 const char *warning);
75
60void 76void
61message_destroy (struct GNUNET_CHAT_Message* message); 77message_destroy (struct GNUNET_CHAT_Message* message);
62 78