diff options
-rw-r--r-- | include/gnunet_chat_lib.h | 87 | ||||
-rw-r--r-- | src/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 index 10e36a4..b1810d5 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h | |||
@@ -116,6 +116,16 @@ struct GNUNET_CHAT_Handle; | |||
116 | struct GNUNET_CHAT_Account; | 116 | struct GNUNET_CHAT_Account; |
117 | 117 | ||
118 | /** | 118 | /** |
119 | * Struct of a chat URI. | ||
120 | */ | ||
121 | struct GNUNET_CHAT_Uri; | ||
122 | |||
123 | /** | ||
124 | * Struct of a chat lobby. | ||
125 | */ | ||
126 | struct GNUNET_CHAT_Lobby; | ||
127 | |||
128 | /** | ||
119 | * Struct of a chat contact. | 129 | * Struct of a chat contact. |
120 | */ | 130 | */ |
121 | struct GNUNET_CHAT_Contact; | 131 | struct GNUNET_CHAT_Contact; |
@@ -159,6 +169,16 @@ typedef int | |||
159 | struct GNUNET_CHAT_Account *account); | 169 | struct GNUNET_CHAT_Account *account); |
160 | 170 | ||
161 | /** | 171 | /** |
172 | * Method called when a lobby is opened to share with others via a chat URI. | ||
173 | * | ||
174 | * @param[in,out] cls Closure from #GNUNET_CHAT_lobby_open | ||
175 | * @param[in] uri Chat URI of the lobby | ||
176 | */ | ||
177 | typedef void | ||
178 | (*GNUNET_CHAT_LobbyCallback) (void *cls, | ||
179 | const struct GNUNET_CHAT_Uri *uri); | ||
180 | |||
181 | /** | ||
162 | * Iterator over chat contacts of a specific chat handle. | 182 | * Iterator over chat contacts of a specific chat handle. |
163 | * | 183 | * |
164 | * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_contacts | 184 | * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_contacts |
@@ -299,7 +319,8 @@ typedef void | |||
299 | struct GNUNET_CHAT_Handle* | 319 | struct GNUNET_CHAT_Handle* |
300 | GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 320 | GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
301 | const char *directory, | 321 | const char *directory, |
302 | GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls); | 322 | GNUNET_CHAT_ContextMessageCallback msg_cb, |
323 | void *msg_cls); | ||
303 | 324 | ||
304 | /** | 325 | /** |
305 | * Stops a chat handle closing all its remaining resources and frees the | 326 | * Stops a chat handle closing all its remaining resources and frees the |
@@ -410,6 +431,68 @@ const char* | |||
410 | GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle); | 431 | GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle); |
411 | 432 | ||
412 | /** | 433 | /** |
434 | * Convert an UTF-8 String to a chat URI which will be newly allocated. | ||
435 | * | ||
436 | * @param[in] uri UTF-8 string to parse | ||
437 | * @param[out] emsg Where to store the parser error message (if any) | ||
438 | * @return NULL on error | ||
439 | */ | ||
440 | struct GNUNET_CHAT_Uri* | ||
441 | GNUNET_CHAT_uri_parse (const char *uri, | ||
442 | char **emsg); | ||
443 | |||
444 | /** | ||
445 | * Convert a chat URI to a UTF-8 String. | ||
446 | * | ||
447 | * @param[in] uri Chat URI | ||
448 | * @return The UTF-8 string representing the URI | ||
449 | */ | ||
450 | char* | ||
451 | GNUNET_CHAT_uri_to_string (const struct GNUNET_CHAT_Uri *uri); | ||
452 | |||
453 | /** | ||
454 | * Free an allocated chat URI. | ||
455 | * | ||
456 | * @param[in,out] uri Chat URI | ||
457 | */ | ||
458 | void | ||
459 | GNUNET_CHAT_uri_destroy (struct GNUNET_CHAT_Uri *uri); | ||
460 | |||
461 | /** | ||
462 | * Opens an empty chat lobby which will expire after a custom <i>delay</i>. | ||
463 | * | ||
464 | * @param[in,out] handle Chat handle | ||
465 | * @param[in] delay Expiration delay | ||
466 | * @param[in] callback Callback for the lobby opening | ||
467 | * @param[in,out] cls Closure for the lobby opening (optional) | ||
468 | * @return Chat lobby | ||
469 | */ | ||
470 | struct GNUNET_CHAT_Lobby* | ||
471 | GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle, | ||
472 | struct GNUNET_TIME_Relative delay, | ||
473 | GNUNET_CHAT_LobbyCallback callback, | ||
474 | void *cls); | ||
475 | |||
476 | /** | ||
477 | * Closes a chat <i>lobby</i> overriding the expiration to be now. | ||
478 | * | ||
479 | * @param[in,out] lobby Chat lobby | ||
480 | */ | ||
481 | void | ||
482 | GNUNET_CHAT_lobby_close (struct GNUNET_CHAT_Lobby *lobby); | ||
483 | |||
484 | /** | ||
485 | * Joins an open lobby via URI with a given chat <i>handle</i> if it can still | ||
486 | * be resolved (depends on connection and expiration of the lobby). | ||
487 | * | ||
488 | * @param[in,out] handle Chat handle | ||
489 | * @param[in] uri Chat URI | ||
490 | */ | ||
491 | void | ||
492 | GNUNET_CHAT_lobby_join (struct GNUNET_CHAT_Handle *handle, | ||
493 | const struct GNUNET_CHAT_Uri *uri); | ||
494 | |||
495 | /** | ||
413 | * Iterates through the contacts of a given chat <i>handle</i> with a selected | 496 | * Iterates through the contacts of a given chat <i>handle</i> with a selected |
414 | * callback and custom closure. | 497 | * callback and custom closure. |
415 | * | 498 | * |
@@ -426,7 +509,7 @@ GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle, | |||
426 | /** | 509 | /** |
427 | * Returns the provided name of a given <i>account</i> or NULL on failure. | 510 | * Returns the provided name of a given <i>account</i> or NULL on failure. |
428 | * | 511 | * |
429 | * @param account Chat account | 512 | * @param[in] account Chat account |
430 | * @return Name or NULL | 513 | * @return Name or NULL |
431 | */ | 514 | */ |
432 | const char* | 515 | const char* |
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index 3dce0c5..f9daa45 100644 --- 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) | |||
208 | } | 208 | } |
209 | 209 | ||
210 | 210 | ||
211 | struct GNUNET_CHAT_Uri* | ||
212 | GNUNET_CHAT_uri_parse (const char *uri, | ||
213 | char **emsg) | ||
214 | { | ||
215 | if (!uri) | ||
216 | return NULL; | ||
217 | |||
218 | // TODO | ||
219 | |||
220 | return NULL; | ||
221 | } | ||
222 | |||
223 | |||
224 | char* | ||
225 | GNUNET_CHAT_uri_to_string (const struct GNUNET_CHAT_Uri *uri) | ||
226 | { | ||
227 | if (!uri) | ||
228 | return NULL; | ||
229 | |||
230 | // TODO | ||
231 | |||
232 | return NULL; | ||
233 | } | ||
234 | |||
235 | |||
236 | void | ||
237 | GNUNET_CHAT_uri_destroy (struct GNUNET_CHAT_Uri *uri) | ||
238 | { | ||
239 | if (!uri) | ||
240 | return; | ||
241 | |||
242 | GNUNET_free(uri); | ||
243 | } | ||
244 | |||
245 | |||
246 | struct GNUNET_CHAT_Lobby* | ||
247 | GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle, | ||
248 | struct GNUNET_TIME_Relative delay, | ||
249 | GNUNET_CHAT_LobbyCallback callback, | ||
250 | void *cls) | ||
251 | { | ||
252 | // TODO | ||
253 | |||
254 | return NULL; | ||
255 | } | ||
256 | |||
257 | |||
258 | void | ||
259 | GNUNET_CHAT_lobby_close (struct GNUNET_CHAT_Lobby *lobby) | ||
260 | { | ||
261 | // TODO | ||
262 | } | ||
263 | |||
264 | |||
265 | void | ||
266 | GNUNET_CHAT_lobby_join (struct GNUNET_CHAT_Handle *handle, | ||
267 | const struct GNUNET_CHAT_Uri *uri) | ||
268 | { | ||
269 | // TODO | ||
270 | } | ||
271 | |||
272 | |||
211 | void | 273 | void |
212 | GNUNET_CHAT_set_user_pointer (struct GNUNET_CHAT_Handle *handle, | 274 | GNUNET_CHAT_set_user_pointer (struct GNUNET_CHAT_Handle *handle, |
213 | void *user_pointer) | 275 | void *user_pointer) |
@@ -613,7 +675,8 @@ GNUNET_CHAT_context_get_status (const struct GNUNET_CHAT_Context *context) | |||
613 | if ((!context) || (!(context->room))) | 675 | if ((!context) || (!(context->room))) |
614 | return GNUNET_SYSERR; | 676 | return GNUNET_SYSERR; |
615 | 677 | ||
616 | if (1 >= GNUNET_MESSENGER_iterate_members(context->room, NULL, NULL)) | 678 | if ((GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN == context->type) || |
679 | (1 >= GNUNET_MESSENGER_iterate_members(context->room, NULL, NULL))) | ||
617 | return GNUNET_NO; | 680 | return GNUNET_NO; |
618 | 681 | ||
619 | return GNUNET_OK; | 682 | return GNUNET_OK; |