summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/nTox.c16
-rw-r--r--testing/nTox.h1
-rw-r--r--toxcore/tox.c75
-rw-r--r--toxcore/tox.h53
4 files changed, 136 insertions, 9 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index d6e25ac0..fa3b5b8c 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -354,7 +354,7 @@ void line_eval(Tox *m, char *line)
354 new_lines(idstring); 354 new_lines(idstring);
355 } else if (inpt_command == 'g') { //create new group chat 355 } else if (inpt_command == 'g') { //create new group chat
356 char msg[256]; 356 char msg[256];
357 sprintf(msg, "[g] Created new group chat with number: %u", add_groupchat(m)); 357 sprintf(msg, "[g] Created new group chat with number: %u", tox_add_groupchat(m));
358 new_lines(msg); 358 new_lines(msg);
359 } else if (inpt_command == 'i') { //invite friendnum to groupnum 359 } else if (inpt_command == 'i') { //invite friendnum to groupnum
360 char *posi[1]; 360 char *posi[1];
@@ -362,7 +362,7 @@ void line_eval(Tox *m, char *line)
362 int groupnumber = strtoul(*posi + 1, NULL, 0); 362 int groupnumber = strtoul(*posi + 1, NULL, 0);
363 char msg[256]; 363 char msg[256];
364 sprintf(msg, "[g] Invited friend number %u to group number %u, returned: %u (0 means success)", friendnumber, 364 sprintf(msg, "[g] Invited friend number %u to group number %u, returned: %u (0 means success)", friendnumber,
365 groupnumber, invite_friend(m, friendnumber, groupnumber)); 365 groupnumber, tox_invite_friend(m, friendnumber, groupnumber));
366 new_lines(msg); 366 new_lines(msg);
367 } else if (inpt_command == 'z') { //send message to groupnum 367 } else if (inpt_command == 'z') { //send message to groupnum
368 char *posi[1]; 368 char *posi[1];
@@ -371,7 +371,7 @@ void line_eval(Tox *m, char *line)
371 if (**posi != 0) { 371 if (**posi != 0) {
372 char msg[256 + 1024]; 372 char msg[256 + 1024];
373 sprintf(msg, "[g] sent message: %s to group num: %u returned: %u (0 means success)", *posi + 1, groupnumber, 373 sprintf(msg, "[g] sent message: %s to group num: %u returned: %u (0 means success)", *posi + 1, groupnumber,
374 group_message_send(m, groupnumber, (uint8_t *)*posi + 1, strlen(*posi + 1) + 1)); 374 tox_group_message_send(m, groupnumber, (uint8_t *)*posi + 1, strlen(*posi + 1) + 1));
375 new_lines(msg); 375 new_lines(msg);
376 } 376 }
377 377
@@ -556,15 +556,15 @@ void print_help(void)
556 puts("\t-f\t-\tSpecify a keyfile to read (or write to) from."); 556 puts("\t-f\t-\tSpecify a keyfile to read (or write to) from.");
557} 557}
558 558
559void print_invite(Messenger *m, int friendnumber, uint8_t *group_public_key, void *userdata) 559void print_invite(Tox *m, int friendnumber, uint8_t *group_public_key, void *userdata)
560{ 560{
561 char msg[256]; 561 char msg[256];
562 sprintf(msg, "[i] recieved group chat invite from: %u, auto accepting and joining. group number: %u", friendnumber, 562 sprintf(msg, "[i] recieved group chat invite from: %u, auto accepting and joining. group number: %u", friendnumber,
563 join_groupchat(m, friendnumber, group_public_key)); 563 tox_join_groupchat(m, friendnumber, group_public_key));
564 new_lines(msg); 564 new_lines(msg);
565} 565}
566 566
567void print_groupmessage(Messenger *m, int groupnumber, uint8_t *message, uint16_t length, void *userdata) 567void print_groupmessage(Tox *m, int groupnumber, uint8_t *message, uint16_t length, void *userdata)
568{ 568{
569 char msg[256 + length]; 569 char msg[256 + length];
570 sprintf(msg, "[g] %u: %s", groupnumber, message); 570 sprintf(msg, "[g] %u: %s", groupnumber, message);
@@ -616,8 +616,8 @@ int main(int argc, char *argv[])
616 tox_callback_friendmessage(m, print_message, NULL); 616 tox_callback_friendmessage(m, print_message, NULL);
617 tox_callback_namechange(m, print_nickchange, NULL); 617 tox_callback_namechange(m, print_nickchange, NULL);
618 tox_callback_statusmessage(m, print_statuschange, NULL); 618 tox_callback_statusmessage(m, print_statuschange, NULL);
619 m_callback_group_invite(m, print_invite, NULL); 619 tox_callback_group_invite(m, print_invite, NULL);
620 m_callback_group_message(m, print_groupmessage, NULL); 620 tox_callback_group_message(m, print_groupmessage, NULL);
621 621
622 initscr(); 622 initscr();
623 noecho(); 623 noecho();
diff --git a/testing/nTox.h b/testing/nTox.h
index 8a41965b..2cd5db09 100644
--- a/testing/nTox.h
+++ b/testing/nTox.h
@@ -31,7 +31,6 @@
31#include <ctype.h> 31#include <ctype.h>
32 32
33#include "../toxcore/tox.h" 33#include "../toxcore/tox.h"
34#include "../toxcore/Messenger.h" //TODO: remove this
35#define STRING_LENGTH 256 34#define STRING_LENGTH 256
36#define HISTORY 50 35#define HISTORY 50
37#define PUB_KEY_BYTES 32 36#define PUB_KEY_BYTES 32
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 54bbd9f0..417f1af3 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -366,6 +366,81 @@ void tox_callback_connectionstatus(void *tox, void (*function)(Messenger *tox, i
366 m_callback_connectionstatus(m, function, userdata); 366 m_callback_connectionstatus(m, function, userdata);
367} 367}
368 368
369/**********GROUP CHAT FUNCTIONS: WARNING WILL BREAK A LOT************/
370
371/* Set the callback for group invites.
372 *
373 * Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata)
374 */
375void tox_callback_group_invite(void *tox, void (*function)(Messenger *tox, int, uint8_t *, void *), void *userdata)
376{
377 Messenger *m = tox;
378 m_callback_group_invite(m, function, userdata);
379}
380/* Set the callback for group messages.
381 *
382 * Function(Tox *tox, int groupnumber, uint8_t * message, uint16_t length, void *userdata)
383 */
384void tox_callback_group_message(void *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *),
385 void *userdata)
386{
387 Messenger *m = tox;
388 m_callback_group_message(m, function, userdata);
389}
390/* Creates a new groupchat and puts it in the chats array.
391 *
392 * return group number on success.
393 * return -1 on failure.
394 */
395int tox_add_groupchat(void *tox)
396{
397 Messenger *m = tox;
398 return add_groupchat(m);
399}
400/* Delete a groupchat from the chats array.
401 *
402 * return 0 on success.
403 * return -1 if failure.
404 */
405int tox_del_groupchat(void *tox, int groupnumber)
406{
407 Messenger *m = tox;
408 return del_groupchat(m, groupnumber);
409}
410/* invite friendnumber to groupnumber
411 * return 0 on success
412 * return -1 on failure
413 */
414int tox_invite_friend(void *tox, int friendnumber, int groupnumber)
415{
416 Messenger *m = tox;
417 return invite_friend(m, friendnumber, groupnumber);
418}
419/* Join a group (you need to have been invited first.)
420 *
421 * returns group number on success
422 * returns -1 on failure.
423 */
424int tox_join_groupchat(void *tox, int friendnumber, uint8_t *friend_group_public_key)
425{
426 Messenger *m = tox;
427 return join_groupchat(m, friendnumber, friend_group_public_key);
428}
429
430/* send a group message
431 * return 0 on success
432 * return -1 on failure
433 */
434int tox_group_message_send(void *tox, int groupnumber, uint8_t *message, uint32_t length)
435{
436 Messenger *m = tox;
437 return group_message_send(m, groupnumber, message, length);
438}
439
440
441
442/******************END OF GROUP CHAT FUNCTIONS************************/
443
369/* Use this function to bootstrap the client. 444/* Use this function to bootstrap the client.
370 * Sends a get nodes request to the given node with ip port and public_key. 445 * Sends a get nodes request to the given node with ip port and public_key.
371 */ 446 */
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 811e798b..6d5db49f 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -289,6 +289,59 @@ void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int, uint32_
289 */ 289 */
290void tox_callback_connectionstatus(Tox *tox, void (*function)(Tox *tox, int, uint8_t, void *), void *userdata); 290void tox_callback_connectionstatus(Tox *tox, void (*function)(Tox *tox, int, uint8_t, void *), void *userdata);
291 291
292/**********GROUP CHAT FUNCTIONS: WARNING WILL BREAK A LOT************/
293
294/* Set the callback for group invites.
295 *
296 * Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata)
297 */
298void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, void *), void *userdata);
299
300/* Set the callback for group messages.
301 *
302 * Function(Tox *tox, int groupnumber, uint8_t * message, uint16_t length, void *userdata)
303 */
304void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *),
305 void *userdata);
306
307/* Creates a new groupchat and puts it in the chats array.
308 *
309 * return group number on success.
310 * return -1 on failure.
311 */
312int tox_add_groupchat(Tox *tox);
313
314/* Delete a groupchat from the chats array.
315 *
316 * return 0 on success.
317 * return -1 if failure.
318 */
319int tox_del_groupchat(Tox *tox, int groupnumber);
320
321/* invite friendnumber to groupnumber
322 * return 0 on success
323 * return -1 on failure
324 */
325int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber);
326
327/* Join a group (you need to have been invited first.)
328 *
329 * returns group number on success
330 * returns -1 on failure.
331 */
332int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key);
333
334
335/* send a group message
336 * return 0 on success
337 * return -1 on failure
338 */
339int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length);
340
341
342
343/******************END OF GROUP CHAT FUNCTIONS************************/
344
292/* Use this function to bootstrap the client. 345/* Use this function to bootstrap the client.
293 * Sends a get nodes request to the given node with ip port and public_key. 346 * Sends a get nodes request to the given node with ip port and public_key.
294 */ 347 */