diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-19 02:30:27 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-19 02:30:27 +0100 |
commit | 9cb19e10c1912fa3140098e86763ecd042997d03 (patch) | |
tree | 8ae6334a78ad96bc9d5f6b87ca0bdba7cae849ee | |
parent | 6bbc30ef71cf23267937a73e34e185410ed73a10 (diff) | |
download | libgnunetchat-9cb19e10c1912fa3140098e86763ecd042997d03.tar.gz libgnunetchat-9cb19e10c1912fa3140098e86763ecd042997d03.zip |
Fixed updating room and loading groups
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | include/gnunet_chat_lib.h | 19 | ||||
-rw-r--r-- | src/gnunet_chat_context.c | 83 | ||||
-rw-r--r-- | src/gnunet_chat_context.h | 8 | ||||
-rw-r--r-- | src/gnunet_chat_handle.c | 122 | ||||
-rw-r--r-- | src/gnunet_chat_handle.h | 17 | ||||
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 16 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 34 | ||||
-rw-r--r-- | src/gnunet_chat_lib_intern.c | 21 | ||||
-rw-r--r-- | src/gnunet_chat_message.h | 3 | ||||
-rw-r--r-- | src/gnunet_chat_util.c | 14 |
10 files changed, 237 insertions, 100 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h index 2eec1d6..aa9b456 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h | |||
@@ -55,39 +55,44 @@ enum GNUNET_CHAT_MessageKind | |||
55 | GNUNET_CHAT_KIND_LOGIN = 2, /**< GNUNET_CHAT_KIND_LOGIN */ | 55 | GNUNET_CHAT_KIND_LOGIN = 2, /**< GNUNET_CHAT_KIND_LOGIN */ |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * The kind to inform that a context was updated. | ||
59 | */ | ||
60 | GNUNET_CHAT_KIND_UPDATE = 3, /**< GNUNET_CHAT_KIND_UPDATE */ | ||
61 | |||
62 | /** | ||
58 | * The kind to inform that a contact has joined a chat. | 63 | * The kind to inform that a contact has joined a chat. |
59 | */ | 64 | */ |
60 | GNUNET_CHAT_KIND_JOIN = 3, /**< GNUNET_CHAT_KIND_JOIN */ | 65 | GNUNET_CHAT_KIND_JOIN = 4, /**< GNUNET_CHAT_KIND_JOIN */ |
61 | 66 | ||
62 | /** | 67 | /** |
63 | * The kind to inform that a contact has left a chat. | 68 | * The kind to inform that a contact has left a chat. |
64 | */ | 69 | */ |
65 | GNUNET_CHAT_KIND_LEAVE = 4, /**< GNUNET_CHAT_KIND_LEAVE */ | 70 | GNUNET_CHAT_KIND_LEAVE = 5, /**< GNUNET_CHAT_KIND_LEAVE */ |
66 | 71 | ||
67 | /** | 72 | /** |
68 | * The kind to inform that a contact has changed. | 73 | * The kind to inform that a contact has changed. |
69 | */ | 74 | */ |
70 | GNUNET_CHAT_KIND_CONTACT = 5, /**< GNUNET_CHAT_KIND_CONTACT */ | 75 | GNUNET_CHAT_KIND_CONTACT = 6, /**< GNUNET_CHAT_KIND_CONTACT */ |
71 | 76 | ||
72 | /** | 77 | /** |
73 | * The kind to describe an invitation to a different chat. | 78 | * The kind to describe an invitation to a different chat. |
74 | */ | 79 | */ |
75 | GNUNET_CHAT_KIND_INVITATION = 6, /**< GNUNET_CHAT_KIND_INVITATION */ | 80 | GNUNET_CHAT_KIND_INVITATION = 7, /**< GNUNET_CHAT_KIND_INVITATION */ |
76 | 81 | ||
77 | /** | 82 | /** |
78 | * The kind to describe a text message. | 83 | * The kind to describe a text message. |
79 | */ | 84 | */ |
80 | GNUNET_CHAT_KIND_TEXT = 7, /**< GNUNET_CHAT_KIND_TEXT */ | 85 | GNUNET_CHAT_KIND_TEXT = 8, /**< GNUNET_CHAT_KIND_TEXT */ |
81 | 86 | ||
82 | /** | 87 | /** |
83 | * The kind to describe a shared file. | 88 | * The kind to describe a shared file. |
84 | */ | 89 | */ |
85 | GNUNET_CHAT_KIND_FILE = 8, /**< GNUNET_CHAT_KIND_FILE */ | 90 | GNUNET_CHAT_KIND_FILE = 9, /**< GNUNET_CHAT_KIND_FILE */ |
86 | 91 | ||
87 | /** | 92 | /** |
88 | * The kind to inform about a deletion of a previous message. | 93 | * The kind to inform about a deletion of a previous message. |
89 | */ | 94 | */ |
90 | GNUNET_CHAT_KIND_DELETION = 9, /**< GNUNET_CHAT_KIND_DELETION */ | 95 | GNUNET_CHAT_KIND_DELETION = 10, /**< GNUNET_CHAT_KIND_DELETION */ |
91 | 96 | ||
92 | /** | 97 | /** |
93 | * An unknown kind of message. | 98 | * An unknown kind of message. |
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c index f2fadc3..929e6ac 100644 --- a/src/gnunet_chat_context.c +++ b/src/gnunet_chat_context.c | |||
@@ -81,7 +81,7 @@ context_create_from_contact (struct GNUNET_CHAT_Handle *handle, | |||
81 | } | 81 | } |
82 | 82 | ||
83 | void | 83 | void |
84 | context_destroy (struct GNUNET_CHAT_Context* context) | 84 | context_destroy (struct GNUNET_CHAT_Context *context) |
85 | { | 85 | { |
86 | GNUNET_assert((context) && | 86 | GNUNET_assert((context) && |
87 | (context->timestamps) && | 87 | (context->timestamps) && |
@@ -113,6 +113,56 @@ context_destroy (struct GNUNET_CHAT_Context* context) | |||
113 | } | 113 | } |
114 | 114 | ||
115 | void | 115 | void |
116 | context_update_room (struct GNUNET_CHAT_Context *context, | ||
117 | struct GNUNET_MESSENGER_Room *room) | ||
118 | { | ||
119 | GNUNET_assert(context); | ||
120 | |||
121 | if (room == context->room) | ||
122 | return; | ||
123 | |||
124 | GNUNET_CONTAINER_multishortmap_iterate( | ||
125 | context->timestamps, it_destroy_context_timestamps, NULL | ||
126 | ); | ||
127 | |||
128 | GNUNET_CONTAINER_multihashmap_iterate( | ||
129 | context->messages, it_destroy_context_messages, NULL | ||
130 | ); | ||
131 | |||
132 | GNUNET_CONTAINER_multihashmap_iterate( | ||
133 | context->invites, it_destroy_context_invites, NULL | ||
134 | ); | ||
135 | |||
136 | GNUNET_CONTAINER_multishortmap_destroy(context->timestamps); | ||
137 | context->timestamps = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); | ||
138 | |||
139 | GNUNET_CONTAINER_multihashmap_clear(context->messages); | ||
140 | GNUNET_CONTAINER_multihashmap_clear(context->invites); | ||
141 | GNUNET_CONTAINER_multihashmap_clear(context->files); | ||
142 | |||
143 | context->room = room; | ||
144 | } | ||
145 | |||
146 | void | ||
147 | context_update_nick (struct GNUNET_CHAT_Context *context, | ||
148 | const char *nick) | ||
149 | { | ||
150 | GNUNET_assert(context); | ||
151 | |||
152 | util_set_name_field(nick, &(context->nick)); | ||
153 | |||
154 | if (!context->handle) | ||
155 | return; | ||
156 | |||
157 | handle_send_internal_message( | ||
158 | context->handle, | ||
159 | context, | ||
160 | GNUNET_CHAT_FLAG_UPDATE, | ||
161 | NULL | ||
162 | ); | ||
163 | } | ||
164 | |||
165 | void | ||
116 | context_load_config (struct GNUNET_CHAT_Context *context) | 166 | context_load_config (struct GNUNET_CHAT_Context *context) |
117 | { | 167 | { |
118 | GNUNET_assert((context) && | 168 | GNUNET_assert((context) && |
@@ -143,11 +193,27 @@ context_load_config (struct GNUNET_CHAT_Context *context) | |||
143 | 193 | ||
144 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string( | 194 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string( |
145 | config, "chat", "name", &name)) | 195 | config, "chat", "name", &name)) |
146 | util_set_name_field(name, &(context->nick)); | 196 | context_update_nick(context, name); |
147 | 197 | ||
148 | if (name) | 198 | if (name) |
149 | GNUNET_free(name); | 199 | GNUNET_free(name); |
150 | 200 | ||
201 | unsigned long long type_number; | ||
202 | |||
203 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number( | ||
204 | config, "chat", "type", &type_number)) | ||
205 | switch (type_number) { | ||
206 | case GNUNET_CHAT_CONTEXT_TYPE_CONTACT: | ||
207 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; | ||
208 | break; | ||
209 | case GNUNET_CHAT_CONTEXT_TYPE_GROUP: | ||
210 | context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; | ||
211 | break; | ||
212 | default: | ||
213 | context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; | ||
214 | break; | ||
215 | } | ||
216 | |||
151 | destroy_config: | 217 | destroy_config: |
152 | GNUNET_CONFIGURATION_destroy(config); | 218 | GNUNET_CONFIGURATION_destroy(config); |
153 | 219 | ||
@@ -183,6 +249,11 @@ context_save_config (const struct GNUNET_CHAT_Context *context) | |||
183 | config, "chat", "name", context->nick | 249 | config, "chat", "name", context->nick |
184 | ); | 250 | ); |
185 | 251 | ||
252 | if (GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN != context->type) | ||
253 | GNUNET_CONFIGURATION_set_value_number( | ||
254 | config, "chat", "type", context->type | ||
255 | ); | ||
256 | |||
186 | char* filename; | 257 | char* filename; |
187 | util_get_filename(directory, "chats", key, &filename); | 258 | util_get_filename(directory, "chats", key, &filename); |
188 | 259 | ||
@@ -219,9 +290,11 @@ callback_scan_for_configs (void *cls, | |||
219 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string( | 290 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string( |
220 | config, "chat", "key", &key_value)) && | 291 | config, "chat", "key", &key_value)) && |
221 | (GNUNET_OK == GNUNET_CRYPTO_hash_from_string(key_value, &key))) | 292 | (GNUNET_OK == GNUNET_CRYPTO_hash_from_string(key_value, &key))) |
222 | GNUNET_MESSENGER_enter_room( | 293 | { |
223 | handle->messenger, &door, &key | 294 | handle_send_room_name(handle, GNUNET_MESSENGER_enter_room( |
224 | ); | 295 | handle->messenger, &door, &key |
296 | )); | ||
297 | } | ||
225 | 298 | ||
226 | if (key_value) | 299 | if (key_value) |
227 | GNUNET_free(key_value); | 300 | GNUNET_free(key_value); |
diff --git a/src/gnunet_chat_context.h b/src/gnunet_chat_context.h index 7880e1a..f68ecb8 100644 --- a/src/gnunet_chat_context.h +++ b/src/gnunet_chat_context.h | |||
@@ -71,6 +71,14 @@ void | |||
71 | context_destroy (struct GNUNET_CHAT_Context* context); | 71 | context_destroy (struct GNUNET_CHAT_Context* context); |
72 | 72 | ||
73 | void | 73 | void |
74 | context_update_room (struct GNUNET_CHAT_Context *context, | ||
75 | struct GNUNET_MESSENGER_Room *room); | ||
76 | |||
77 | void | ||
78 | context_update_nick (struct GNUNET_CHAT_Context *context, | ||
79 | const char *nick); | ||
80 | |||
81 | void | ||
74 | context_load_config (struct GNUNET_CHAT_Context *context); | 82 | context_load_config (struct GNUNET_CHAT_Context *context); |
75 | 83 | ||
76 | void | 84 | void |
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c index 03d2e26..0a0b743 100644 --- a/src/gnunet_chat_handle.c +++ b/src/gnunet_chat_handle.c | |||
@@ -115,7 +115,7 @@ handle_update_key (struct GNUNET_CHAT_Handle *handle) | |||
115 | } | 115 | } |
116 | 116 | ||
117 | void | 117 | void |
118 | handle_destroy (struct GNUNET_CHAT_Handle* handle) | 118 | handle_destroy (struct GNUNET_CHAT_Handle *handle) |
119 | { | 119 | { |
120 | GNUNET_assert((handle) && | 120 | GNUNET_assert((handle) && |
121 | (handle->groups) && | 121 | (handle->groups) && |
@@ -165,6 +165,46 @@ handle_destroy (struct GNUNET_CHAT_Handle* handle) | |||
165 | GNUNET_free(handle); | 165 | GNUNET_free(handle); |
166 | } | 166 | } |
167 | 167 | ||
168 | void | ||
169 | handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, | ||
170 | struct GNUNET_CHAT_Context *context, | ||
171 | enum GNUNET_CHAT_MessageFlag flag, | ||
172 | const char *warning) | ||
173 | { | ||
174 | GNUNET_assert((handle) && (GNUNET_CHAT_FLAG_NONE != flag)); | ||
175 | |||
176 | if (!handle->msg_cb) | ||
177 | return; | ||
178 | |||
179 | struct GNUNET_CHAT_Message *msg = message_create_internally( | ||
180 | context, flag, warning | ||
181 | ); | ||
182 | |||
183 | handle->msg_cb(handle->msg_cls, context, msg); | ||
184 | message_destroy(msg); | ||
185 | } | ||
186 | |||
187 | void | ||
188 | handle_send_room_name (struct GNUNET_CHAT_Handle *handle, | ||
189 | struct GNUNET_MESSENGER_Room *room) | ||
190 | { | ||
191 | GNUNET_assert((handle) && (handle->messenger) && (room)); | ||
192 | |||
193 | const char *name = GNUNET_MESSENGER_get_name(handle->messenger); | ||
194 | |||
195 | if (!name) | ||
196 | return; | ||
197 | |||
198 | struct GNUNET_MESSENGER_Message msg; | ||
199 | |||
200 | msg.header.kind = GNUNET_MESSENGER_KIND_NAME; | ||
201 | msg.body.name.name = GNUNET_strdup(name); | ||
202 | |||
203 | GNUNET_MESSENGER_send_message(room, &msg, NULL); | ||
204 | |||
205 | GNUNET_free(msg.body.name.name); | ||
206 | } | ||
207 | |||
168 | int | 208 | int |
169 | handle_request_context_by_room (struct GNUNET_CHAT_Handle *handle, | 209 | handle_request_context_by_room (struct GNUNET_CHAT_Handle *handle, |
170 | struct GNUNET_MESSENGER_Room *room) | 210 | struct GNUNET_MESSENGER_Room *room) |
@@ -181,9 +221,7 @@ handle_request_context_by_room (struct GNUNET_CHAT_Handle *handle, | |||
181 | 221 | ||
182 | struct GNUNET_CHAT_CheckHandleRoomMembers check; | 222 | struct GNUNET_CHAT_CheckHandleRoomMembers check; |
183 | 223 | ||
184 | if ((context) && (GNUNET_CHAT_CONTEXT_TYPE_GROUP != context->type)) | 224 | if (context) |
185 | goto check_context_type; | ||
186 | else if (context) | ||
187 | return GNUNET_OK; | 225 | return GNUNET_OK; |
188 | 226 | ||
189 | context = context_create_from_room(handle, room); | 227 | context = context_create_from_room(handle, room); |
@@ -197,7 +235,9 @@ handle_request_context_by_room (struct GNUNET_CHAT_Handle *handle, | |||
197 | return GNUNET_SYSERR; | 235 | return GNUNET_SYSERR; |
198 | } | 236 | } |
199 | 237 | ||
200 | check_context_type: | 238 | if (GNUNET_CHAT_CONTEXT_TYPE_GROUP == context->type) |
239 | goto setup_group; | ||
240 | |||
201 | check.ignore_key = GNUNET_MESSENGER_get_key(handle->messenger); | 241 | check.ignore_key = GNUNET_MESSENGER_get_key(handle->messenger); |
202 | check.contact = NULL; | 242 | check.contact = NULL; |
203 | 243 | ||
@@ -205,13 +245,6 @@ check_context_type: | |||
205 | room, check_handle_room_members, &check | 245 | room, check_handle_room_members, &check |
206 | ); | 246 | ); |
207 | 247 | ||
208 | if (GNUNET_SYSERR == checks) | ||
209 | { | ||
210 | GNUNET_CONTAINER_multihashmap_remove(handle->contexts, key, context); | ||
211 | context_destroy(context); | ||
212 | return GNUNET_SYSERR; | ||
213 | } | ||
214 | |||
215 | if ((check.contact) && | 248 | if ((check.contact) && |
216 | (GNUNET_OK == intern_provide_contact_for_member(handle, | 249 | (GNUNET_OK == intern_provide_contact_for_member(handle, |
217 | check.contact, | 250 | check.contact, |
@@ -219,8 +252,9 @@ check_context_type: | |||
219 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; | 252 | context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; |
220 | else if (checks >= 2) | 253 | else if (checks >= 2) |
221 | { | 254 | { |
222 | if ((context->contact) && | 255 | context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; |
223 | (context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT)) | 256 | |
257 | if (context->contact) | ||
224 | { | 258 | { |
225 | struct GNUNET_CHAT_Contact *contact = handle_get_contact_from_messenger( | 259 | struct GNUNET_CHAT_Contact *contact = handle_get_contact_from_messenger( |
226 | handle, check.contact | 260 | handle, check.contact |
@@ -232,32 +266,42 @@ check_context_type: | |||
232 | context->contact = NULL; | 266 | context->contact = NULL; |
233 | } | 267 | } |
234 | 268 | ||
235 | context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; | 269 | goto setup_group; |
270 | } | ||
236 | 271 | ||
237 | GNUNET_MESSENGER_iterate_members(room, scan_handle_room_members, handle); | 272 | return GNUNET_OK; |
238 | 273 | ||
239 | struct GNUNET_CHAT_Group *group = group_create_from_context( | 274 | setup_group: |
240 | handle, context | 275 | GNUNET_MESSENGER_iterate_members(room, scan_handle_room_members, handle); |
241 | ); | ||
242 | 276 | ||
243 | group_load_config(group); | 277 | struct GNUNET_CHAT_Group *group = group_create_from_context( |
278 | handle, context | ||
279 | ); | ||
244 | 280 | ||
245 | if (group->topic) | 281 | group_load_config(group); |
246 | group_publish(group); | ||
247 | 282 | ||
248 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( | 283 | if (group->topic) |
249 | handle->groups, key, group, | 284 | group_publish(group); |
250 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
251 | return GNUNET_OK; | ||
252 | 285 | ||
253 | group_destroy(group); | 286 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( |
287 | handle->groups, key, group, | ||
288 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
289 | { | ||
290 | handle_send_internal_message( | ||
291 | handle, | ||
292 | context, | ||
293 | GNUNET_CHAT_FLAG_UPDATE, | ||
294 | NULL | ||
295 | ); | ||
254 | 296 | ||
255 | GNUNET_CONTAINER_multihashmap_remove(handle->contexts, key, context); | 297 | return GNUNET_OK; |
256 | context_destroy(context); | ||
257 | return GNUNET_SYSERR; | ||
258 | } | 298 | } |
259 | 299 | ||
260 | return GNUNET_OK; | 300 | group_destroy(group); |
301 | |||
302 | GNUNET_CONTAINER_multihashmap_remove(handle->contexts, key, context); | ||
303 | context_destroy(context); | ||
304 | return GNUNET_SYSERR; | ||
261 | } | 305 | } |
262 | 306 | ||
263 | struct GNUNET_CHAT_Contact* | 307 | struct GNUNET_CHAT_Contact* |
@@ -273,3 +317,19 @@ handle_get_contact_from_messenger (const struct GNUNET_CHAT_Handle *handle, | |||
273 | handle->contacts, &shorthash | 317 | handle->contacts, &shorthash |
274 | ); | 318 | ); |
275 | } | 319 | } |
320 | |||
321 | struct GNUNET_CHAT_Group* | ||
322 | handle_get_group_from_messenger (const struct GNUNET_CHAT_Handle *handle, | ||
323 | const struct GNUNET_MESSENGER_Room *room) | ||
324 | { | ||
325 | GNUNET_assert((handle) && (handle->groups) && (room)); | ||
326 | |||
327 | const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(room); | ||
328 | |||
329 | if (!key) | ||
330 | return NULL; | ||
331 | |||
332 | return GNUNET_CONTAINER_multihashmap_get( | ||
333 | handle->groups, key | ||
334 | ); | ||
335 | } | ||
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h index 399de6b..5faa2da 100644 --- a/src/gnunet_chat_handle.h +++ b/src/gnunet_chat_handle.h | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <gnunet/gnunet_util_lib.h> | 36 | #include <gnunet/gnunet_util_lib.h> |
37 | 37 | ||
38 | #include "gnunet_chat_lib.h" | 38 | #include "gnunet_chat_lib.h" |
39 | #include "gnunet_chat_message.h" | ||
39 | 40 | ||
40 | struct GNUNET_CHAT_Handle | 41 | struct GNUNET_CHAT_Handle |
41 | { | 42 | { |
@@ -71,7 +72,17 @@ void | |||
71 | handle_update_key (struct GNUNET_CHAT_Handle *handle); | 72 | handle_update_key (struct GNUNET_CHAT_Handle *handle); |
72 | 73 | ||
73 | void | 74 | void |
74 | handle_destroy (struct GNUNET_CHAT_Handle* handle); | 75 | handle_destroy (struct GNUNET_CHAT_Handle *handle); |
76 | |||
77 | void | ||
78 | handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, | ||
79 | struct GNUNET_CHAT_Context *context, | ||
80 | enum GNUNET_CHAT_MessageFlag flag, | ||
81 | const char *warning); | ||
82 | |||
83 | void | ||
84 | handle_send_room_name (struct GNUNET_CHAT_Handle *handle, | ||
85 | struct GNUNET_MESSENGER_Room *room); | ||
75 | 86 | ||
76 | int | 87 | int |
77 | handle_request_context_by_room (struct GNUNET_CHAT_Handle *handle, | 88 | handle_request_context_by_room (struct GNUNET_CHAT_Handle *handle, |
@@ -81,4 +92,8 @@ struct GNUNET_CHAT_Contact* | |||
81 | handle_get_contact_from_messenger (const struct GNUNET_CHAT_Handle *handle, | 92 | handle_get_contact_from_messenger (const struct GNUNET_CHAT_Handle *handle, |
82 | const struct GNUNET_MESSENGER_Contact *contact); | 93 | const struct GNUNET_MESSENGER_Contact *contact); |
83 | 94 | ||
95 | struct GNUNET_CHAT_Group* | ||
96 | handle_get_group_from_messenger (const struct GNUNET_CHAT_Handle *handle, | ||
97 | const struct GNUNET_MESSENGER_Room *room); | ||
98 | |||
84 | #endif /* GNUNET_CHAT_HANDLE_H_ */ | 99 | #endif /* GNUNET_CHAT_HANDLE_H_ */ |
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index 70e4da4..2200e8e 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -266,7 +266,8 @@ check_handle_room_members (void* cls, | |||
266 | GNUNET_MESSENGER_contact_get_key(member) | 266 | GNUNET_MESSENGER_contact_get_key(member) |
267 | ); | 267 | ); |
268 | 268 | ||
269 | if ((member_key) && (0 == GNUNET_memcmp(member_key, check->ignore_key))) | 269 | if ((member_key) && (check->ignore_key) && |
270 | (0 == GNUNET_memcmp(member_key, check->ignore_key))) | ||
270 | return GNUNET_YES; | 271 | return GNUNET_YES; |
271 | 272 | ||
272 | if (check->contact) | 273 | if (check->contact) |
@@ -313,15 +314,12 @@ on_handle_identity(void *cls, | |||
313 | GNUNET_assert(handle->messenger); | 314 | GNUNET_assert(handle->messenger); |
314 | context_scan_configs(handle); | 315 | context_scan_configs(handle); |
315 | 316 | ||
316 | if (!handle->msg_cb) | 317 | handle_send_internal_message( |
317 | return; | 318 | handle, |
318 | 319 | NULL, | |
319 | struct GNUNET_CHAT_Message *msg = message_create_internally( | 320 | GNUNET_CHAT_FLAG_LOGIN, |
320 | NULL, GNUNET_CHAT_FLAG_LOGIN, NULL | 321 | NULL |
321 | ); | 322 | ); |
322 | |||
323 | handle->msg_cb(handle->msg_cls, NULL, msg); | ||
324 | message_destroy(msg); | ||
325 | } | 323 | } |
326 | 324 | ||
327 | void | 325 | void |
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index f1421af..87692ec 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -172,10 +172,10 @@ GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle, | |||
172 | if (!room) | 172 | if (!room) |
173 | return NULL; | 173 | return NULL; |
174 | 174 | ||
175 | intern_room_send_name(handle->messenger, room); | ||
176 | |||
177 | struct GNUNET_CHAT_Context *context = context_create_from_room(handle, room); | 175 | struct GNUNET_CHAT_Context *context = context_create_from_room(handle, room); |
178 | 176 | ||
177 | handle_send_room_name(handle, room); | ||
178 | |||
179 | context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; | 179 | context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; |
180 | 180 | ||
181 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | 181 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( |
@@ -260,7 +260,7 @@ GNUNET_CHAT_contact_set_name (struct GNUNET_CHAT_Contact *contact, | |||
260 | if ((!contact) || (!(contact->context))) | 260 | if ((!contact) || (!(contact->context))) |
261 | return; | 261 | return; |
262 | 262 | ||
263 | util_set_name_field(name, &(contact->context->nick)); | 263 | context_update_nick(contact->context, name); |
264 | } | 264 | } |
265 | 265 | ||
266 | 266 | ||
@@ -425,7 +425,7 @@ GNUNET_CHAT_group_invite_contact (struct GNUNET_CHAT_Group *group, | |||
425 | group->context->room | 425 | group->context->room |
426 | ); | 426 | ); |
427 | 427 | ||
428 | intern_room_send_name(group->handle->messenger, GNUNET_MESSENGER_open_room( | 428 | handle_send_room_name(group->handle, GNUNET_MESSENGER_open_room( |
429 | group->handle->messenger, key | 429 | group->handle->messenger, key |
430 | )); | 430 | )); |
431 | 431 | ||
@@ -519,7 +519,8 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context) | |||
519 | if (!room) | 519 | if (!room) |
520 | return; | 520 | return; |
521 | 521 | ||
522 | intern_room_send_name(handle->messenger, room); | 522 | context_update_room(context, room); |
523 | handle_send_room_name(handle, room); | ||
523 | 524 | ||
524 | struct GNUNET_MESSENGER_Message msg; | 525 | struct GNUNET_MESSENGER_Message msg; |
525 | msg.header.kind = GNUNET_MESSENGER_KIND_INVITE; | 526 | msg.header.kind = GNUNET_MESSENGER_KIND_INVITE; |
@@ -527,7 +528,6 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context) | |||
527 | GNUNET_memcpy(&(msg.body.invite.key), &key, sizeof(msg.body.invite.key)); | 528 | GNUNET_memcpy(&(msg.body.invite.key), &key, sizeof(msg.body.invite.key)); |
528 | 529 | ||
529 | GNUNET_MESSENGER_send_message(other->room, &msg, context->contact); | 530 | GNUNET_MESSENGER_send_message(other->room, &msg, context->contact); |
530 | context->room = room; | ||
531 | } | 531 | } |
532 | 532 | ||
533 | 533 | ||
@@ -546,13 +546,13 @@ GNUNET_CHAT_context_get_contact (const struct GNUNET_CHAT_Context *context) | |||
546 | find.ignore_key = GNUNET_MESSENGER_get_key(context->handle->messenger); | 546 | find.ignore_key = GNUNET_MESSENGER_get_key(context->handle->messenger); |
547 | find.contact = NULL; | 547 | find.contact = NULL; |
548 | 548 | ||
549 | GNUNET_MESSENGER_iterate_members( | 549 | int member_count = GNUNET_MESSENGER_iterate_members( |
550 | room, | 550 | room, |
551 | it_room_find_contact, | 551 | it_room_find_contact, |
552 | &find | 552 | &find |
553 | ); | 553 | ); |
554 | 554 | ||
555 | if (!find.contact) | 555 | if ((!find.contact) || (member_count > 2)) |
556 | return NULL; | 556 | return NULL; |
557 | 557 | ||
558 | return handle_get_contact_from_messenger(context->handle, find.contact); | 558 | return handle_get_contact_from_messenger(context->handle, find.contact); |
@@ -565,19 +565,10 @@ GNUNET_CHAT_context_get_group (const struct GNUNET_CHAT_Context *context) | |||
565 | if ((!context) || (GNUNET_CHAT_CONTEXT_TYPE_GROUP != context->type)) | 565 | if ((!context) || (GNUNET_CHAT_CONTEXT_TYPE_GROUP != context->type)) |
566 | return NULL; | 566 | return NULL; |
567 | 567 | ||
568 | const struct GNUNET_MESSENGER_Room *room = context->room; | 568 | if (!context->room) |
569 | const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(room); | ||
570 | |||
571 | if (!key) | ||
572 | return NULL; | 569 | return NULL; |
573 | 570 | ||
574 | const struct GNUNET_CHAT_Group *group; | 571 | return handle_get_group_from_messenger(context->handle, context->room); |
575 | group = GNUNET_CONTAINER_multihashmap_get( | ||
576 | context->handle->groups, key | ||
577 | ); | ||
578 | |||
579 | GNUNET_assert((group == NULL) || (group->context == context)); | ||
580 | return group; | ||
581 | } | 572 | } |
582 | 573 | ||
583 | 574 | ||
@@ -770,6 +761,8 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message) | |||
770 | return GNUNET_CHAT_KIND_WARNING; | 761 | return GNUNET_CHAT_KIND_WARNING; |
771 | case GNUNET_CHAT_FLAG_LOGIN: | 762 | case GNUNET_CHAT_FLAG_LOGIN: |
772 | return GNUNET_CHAT_KIND_LOGIN; | 763 | return GNUNET_CHAT_KIND_LOGIN; |
764 | case GNUNET_CHAT_FLAG_UPDATE: | ||
765 | return GNUNET_CHAT_KIND_UPDATE; | ||
773 | default: | 766 | default: |
774 | break; | 767 | break; |
775 | } | 768 | } |
@@ -814,7 +807,8 @@ GNUNET_CHAT_message_get_timestamp (const struct GNUNET_CHAT_Message *message) | |||
814 | struct GNUNET_CHAT_Contact* | 807 | struct GNUNET_CHAT_Contact* |
815 | GNUNET_CHAT_message_get_sender (const struct GNUNET_CHAT_Message *message) | 808 | GNUNET_CHAT_message_get_sender (const struct GNUNET_CHAT_Message *message) |
816 | { | 809 | { |
817 | if ((!message) || (!(message->context))) | 810 | if ((!message) || (GNUNET_CHAT_FLAG_NONE != message->flag) || |
811 | (!message->context) || (!message->context->room)) | ||
818 | return NULL; | 812 | return NULL; |
819 | 813 | ||
820 | const struct GNUNET_MESSENGER_Contact *sender = GNUNET_MESSENGER_get_sender( | 814 | const struct GNUNET_MESSENGER_Contact *sender = GNUNET_MESSENGER_get_sender( |
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c index 8010401..d19b0eb 100644 --- a/src/gnunet_chat_lib_intern.c +++ b/src/gnunet_chat_lib_intern.c | |||
@@ -48,27 +48,6 @@ it_handle_iterate_contacts (void *cls, | |||
48 | return it->cb(it->cls, it->handle, contact); | 48 | return it->cb(it->cls, it->handle, contact); |
49 | } | 49 | } |
50 | 50 | ||
51 | void | ||
52 | intern_room_send_name (struct GNUNET_MESSENGER_Handle *handle, | ||
53 | struct GNUNET_MESSENGER_Room *room) | ||
54 | { | ||
55 | GNUNET_assert((handle) && (room)); | ||
56 | |||
57 | const char *name = GNUNET_MESSENGER_get_name(handle); | ||
58 | |||
59 | if (!name) | ||
60 | return; | ||
61 | |||
62 | struct GNUNET_MESSENGER_Message msg; | ||
63 | |||
64 | msg.header.kind = GNUNET_MESSENGER_KIND_NAME; | ||
65 | msg.body.name.name = GNUNET_strdup(name); | ||
66 | |||
67 | GNUNET_MESSENGER_send_message(room, &msg, NULL); | ||
68 | |||
69 | GNUNET_free(msg.body.name.name); | ||
70 | } | ||
71 | |||
72 | struct GNUNET_CHAT_HandleIterateGroups | 51 | struct GNUNET_CHAT_HandleIterateGroups |
73 | { | 52 | { |
74 | struct GNUNET_CHAT_Handle *handle; | 53 | struct GNUNET_CHAT_Handle *handle; |
diff --git a/src/gnunet_chat_message.h b/src/gnunet_chat_message.h index 21a4e15..9df2b67 100644 --- a/src/gnunet_chat_message.h +++ b/src/gnunet_chat_message.h | |||
@@ -45,7 +45,8 @@ enum GNUNET_CHAT_MessageFlag | |||
45 | { | 45 | { |
46 | GNUNET_CHAT_FLAG_NONE = 0, | 46 | GNUNET_CHAT_FLAG_NONE = 0, |
47 | GNUNET_CHAT_FLAG_WARNING = 1, | 47 | GNUNET_CHAT_FLAG_WARNING = 1, |
48 | GNUNET_CHAT_FLAG_LOGIN = 2 | 48 | GNUNET_CHAT_FLAG_LOGIN = 2, |
49 | GNUNET_CHAT_FLAG_UPDATE = 3 | ||
49 | }; | 50 | }; |
50 | 51 | ||
51 | struct GNUNET_CHAT_Message | 52 | struct GNUNET_CHAT_Message |
diff --git a/src/gnunet_chat_util.c b/src/gnunet_chat_util.c index f8d98f2..775e856 100644 --- a/src/gnunet_chat_util.c +++ b/src/gnunet_chat_util.c | |||
@@ -213,13 +213,17 @@ util_get_filename (const char *directory, | |||
213 | (subdir) && | 213 | (subdir) && |
214 | (hash)); | 214 | (hash)); |
215 | 215 | ||
216 | return GNUNET_asprintf ( | 216 | char* dirname; |
217 | util_get_dirname(directory, subdir, &dirname); | ||
218 | |||
219 | int result = GNUNET_asprintf ( | ||
217 | filename, | 220 | filename, |
218 | "%s%c%s%c%s", | 221 | "%s%c%s", |
219 | directory, | 222 | dirname, |
220 | DIR_SEPARATOR, | ||
221 | subdir, | ||
222 | DIR_SEPARATOR, | 223 | DIR_SEPARATOR, |
223 | GNUNET_h2s_full(hash) | 224 | GNUNET_h2s_full(hash) |
224 | ); | 225 | ); |
226 | |||
227 | GNUNET_free(dirname); | ||
228 | return result; | ||
225 | } | 229 | } |