aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet_chat_lib.c')
-rw-r--r--src/gnunet_chat_lib.c125
1 files changed, 116 insertions, 9 deletions
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index f9daa45..bac539d 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -32,7 +32,9 @@
32#include "gnunet_chat_group.h" 32#include "gnunet_chat_group.h"
33#include "gnunet_chat_handle.h" 33#include "gnunet_chat_handle.h"
34#include "gnunet_chat_invitation.h" 34#include "gnunet_chat_invitation.h"
35#include "gnunet_chat_lobby.h"
35#include "gnunet_chat_message.h" 36#include "gnunet_chat_message.h"
37
36#include "gnunet_chat_util.h" 38#include "gnunet_chat_util.h"
37 39
38#include "gnunet_chat_lib_intern.c" 40#include "gnunet_chat_lib_intern.c"
@@ -215,9 +217,44 @@ GNUNET_CHAT_uri_parse (const char *uri,
215 if (!uri) 217 if (!uri)
216 return NULL; 218 return NULL;
217 219
218 // TODO 220 const size_t prefix_len = strlen(GNUNET_CHAT_URI_PREFIX);
219 221
220 return NULL; 222 if (0 != strncmp(GNUNET_CHAT_URI_PREFIX, uri, prefix_len))
223 {
224 if (emsg)
225 *emsg = GNUNET_strdup (_ ("CHAT URI malformed (invalid prefix)"));
226
227 return NULL;
228 }
229
230 struct GNUNET_IDENTITY_PublicKey zone;
231
232 const char *data = uri + prefix_len;
233 char *end = strchr(data, '.');
234
235 if (!end)
236 {
237 if (emsg)
238 *emsg = GNUNET_strdup (_ ("CHAT URI malformed (zone key missing)"));
239
240 return NULL;
241 }
242
243 char *zone_data = GNUNET_strndup(data, (size_t) (end - data));
244
245 if (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string(zone_data, &zone))
246 {
247 GNUNET_free(zone_data);
248
249 if (emsg)
250 *emsg = GNUNET_strdup (_ ("CHAT URI malformed (zone key invalid)"));
251
252 return NULL;
253 }
254
255 GNUNET_free(zone_data);
256
257 return uri_create(&zone, end + 1);
221} 258}
222 259
223 260
@@ -227,9 +264,18 @@ GNUNET_CHAT_uri_to_string (const struct GNUNET_CHAT_Uri *uri)
227 if (!uri) 264 if (!uri)
228 return NULL; 265 return NULL;
229 266
230 // TODO 267 char *key_string = GNUNET_IDENTITY_public_key_to_string(&(uri->zone));
231 268
232 return NULL; 269 char *string;
270 GNUNET_asprintf(
271 &string,
272 "gnunet://chat/%s.%s",
273 key_string,
274 uri->label
275 );
276
277 GNUNET_free(key_string);
278 return string;
233} 279}
234 280
235 281
@@ -239,7 +285,7 @@ GNUNET_CHAT_uri_destroy (struct GNUNET_CHAT_Uri *uri)
239 if (!uri) 285 if (!uri)
240 return; 286 return;
241 287
242 GNUNET_free(uri); 288 uri_destroy(uri);
243} 289}
244 290
245 291
@@ -249,16 +295,53 @@ GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle,
249 GNUNET_CHAT_LobbyCallback callback, 295 GNUNET_CHAT_LobbyCallback callback,
250 void *cls) 296 void *cls)
251{ 297{
252 // TODO 298 if (!handle)
299 return NULL;
253 300
254 return NULL; 301 struct GNUNET_CHAT_InternalLobbies *lobbies = GNUNET_new(
302 struct GNUNET_CHAT_InternalLobbies
303 );
304
305 lobbies->lobby = lobby_create(handle);
306
307 GNUNET_CONTAINER_DLL_insert(
308 handle->lobbies_head,
309 handle->lobbies_tail,
310 lobbies
311 );
312
313 lobby_open(lobbies->lobby, delay, callback, cls);
314
315 return lobbies->lobby;
255} 316}
256 317
257 318
258void 319void
259GNUNET_CHAT_lobby_close (struct GNUNET_CHAT_Lobby *lobby) 320GNUNET_CHAT_lobby_close (struct GNUNET_CHAT_Lobby *lobby)
260{ 321{
261 // TODO 322 if (!lobby)
323 return;
324
325 struct GNUNET_CHAT_InternalLobbies *lobbies = lobby->handle->lobbies_head;
326
327 while (lobbies)
328 {
329 if (lobbies->lobby == lobby)
330 {
331 GNUNET_CONTAINER_DLL_remove(
332 lobby->handle->lobbies_head,
333 lobby->handle->lobbies_tail,
334 lobbies
335 );
336
337 GNUNET_free(lobbies);
338 break;
339 }
340
341 lobbies = lobbies->next;
342 }
343
344 lobby_destroy(lobby);
262} 345}
263 346
264 347
@@ -266,7 +349,31 @@ void
266GNUNET_CHAT_lobby_join (struct GNUNET_CHAT_Handle *handle, 349GNUNET_CHAT_lobby_join (struct GNUNET_CHAT_Handle *handle,
267 const struct GNUNET_CHAT_Uri *uri) 350 const struct GNUNET_CHAT_Uri *uri)
268{ 351{
269 // TODO 352 if ((!handle) || (!uri) || (!(handle->gns)))
353 return;
354
355 struct GNUNET_CHAT_UriLookups *lookups = GNUNET_new(
356 struct GNUNET_CHAT_UriLookups
357 );
358
359 lookups->handle = handle;
360 lookups->uri = uri_create(&(uri->zone), uri->label);
361
362 lookups->request = GNUNET_GNS_lookup(
363 handle->gns,
364 lookups->uri->label,
365 &(uri->zone),
366 GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY,
367 GNUNET_GNS_LO_DEFAULT,
368 cb_lobby_lookup,
369 lookups
370 );
371
372 GNUNET_CONTAINER_DLL_insert(
373 handle->lookups_head,
374 handle->lookups_tail,
375 lookups
376 );
270} 377}
271 378
272 379