From eaf22dff1e5acc5eed22d18f3264e804e7b7262b Mon Sep 17 00:00:00 2001 From: pranomostro Date: Mon, 28 Nov 2016 15:25:53 +0100 Subject: Update to the toktok API. --- ratox.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 9a2b9f6..070a5e1 100644 --- a/ratox.c +++ b/ratox.c @@ -1157,16 +1157,16 @@ toxinit(void) framesize = (AUDIOSAMPLERATE * AUDIOFRAME * AUDIOCHANNELS) / 1000; - tox_callback_friend_connection_status(tox, cbconnstatus, NULL); - tox_callback_friend_message(tox, cbfriendmessage, NULL); - tox_callback_friend_request(tox, cbfriendrequest, NULL); - tox_callback_friend_name(tox, cbnamechange, NULL); - tox_callback_friend_status_message(tox, cbstatusmessage, NULL); - tox_callback_friend_status(tox, cbfriendstate, NULL); - tox_callback_file_recv_control(tox, cbfilecontrol, NULL); - tox_callback_file_recv(tox, cbfilesendreq, NULL); - tox_callback_file_recv_chunk(tox, cbfiledata, NULL); - tox_callback_file_chunk_request(tox, cbfiledatareq, NULL); + tox_callback_friend_connection_status(tox, cbconnstatus); + tox_callback_friend_message(tox, cbfriendmessage); + tox_callback_friend_request(tox, cbfriendrequest); + tox_callback_friend_name(tox, cbnamechange); + tox_callback_friend_status_message(tox, cbstatusmessage); + tox_callback_friend_status(tox, cbfriendstate); + tox_callback_file_recv_control(tox, cbfilecontrol); + tox_callback_file_recv(tox, cbfilesendreq); + tox_callback_file_recv_chunk(tox, cbfiledata); + tox_callback_file_chunk_request(tox, cbfiledatareq); toxav_callback_call(toxav, cbcallinvite, NULL); toxav_callback_call_state(toxav, cbcallstate, NULL); @@ -1584,7 +1584,7 @@ loop(void) toxconnect(); } } - tox_iterate(tox); + tox_iterate(tox, NULL); toxav_iterate(toxav); /* Prepare select-fd-set */ -- cgit v1.2.3 From cb904cf59e4c1650ce5109850822ce658b6ac439 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Mon, 28 Nov 2016 15:36:09 +0100 Subject: Remove converting nospam values because toxcore does that for us now. --- ratox.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 070a5e1..7d6a5b1 100644 --- a/ratox.c +++ b/ratox.c @@ -3,8 +3,6 @@ #include #include -#include - #include #include #include @@ -1119,7 +1117,7 @@ localinit(void) /* Dump Nospam */ ftruncate(gslots[NOSPAM].fd[OUT], 0); - dprintf(gslots[NOSPAM].fd[OUT], "%08X\n", ntohl(tox_self_get_nospam(tox))); + dprintf(gslots[NOSPAM].fd[OUT], "%08X\n", tox_self_get_nospam(tox)); return 0; } @@ -1527,7 +1525,7 @@ setnospam(void *data) } nsval = strtoul((char *)nospam, NULL, 16); - tox_self_set_nospam(tox, htonl(nsval)); + tox_self_set_nospam(tox, nsval); datasave(); logmsg("Nospam > %08X\n", nsval); ftruncate(gslots[NOSPAM].fd[OUT], 0); -- cgit v1.2.3 From e00b398d645a019eefb65be0c01e3b3cb7f15f9d Mon Sep 17 00:00:00 2001 From: pranomostro Date: Thu, 1 Dec 2016 20:42:46 +0100 Subject: Data model and adding function for conferences. --- ratox.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 7d6a5b1..266524e 100644 --- a/ratox.c +++ b/ratox.c @@ -87,8 +87,9 @@ static void setstatus(void *); static void setuserstate(void *); static void sendfriendreq(void *); static void setnospam(void *); +static void newconf(void *); -enum { NAME, STATUS, STATE, REQUEST, NOSPAM }; +enum { NAME, STATUS, STATE, REQUEST, NOSPAM, CONF }; static struct slot gslots[] = { [NAME] = { .name = "name", .cb = setname, .outisfolder = 0, .dirfd = -1, .fd = {-1, -1, -1} }, @@ -96,6 +97,7 @@ static struct slot gslots[] = { [STATE] = { .name = "state", .cb = setuserstate, .outisfolder = 0, .dirfd = -1, .fd = {-1, -1, -1} }, [REQUEST] = { .name = "request", .cb = sendfriendreq, .outisfolder = 1, .dirfd = -1, .fd = {-1, -1, -1} }, [NOSPAM] = { .name = "nospam", .cb = setnospam, .outisfolder = 0, .dirfd = -1, .fd = {-1, -1, -1} }, + [CONF] = { .name = "conf", .cb = newconf, .outisfolder = 1, .dirfd = -1, .fd = {-1, -1, -1} }, }; enum { FTEXT_IN, FFILE_IN, FCALL_IN, FTEXT_OUT, FFILE_OUT, FCALL_OUT, @@ -117,6 +119,18 @@ static struct file ffiles[] = { [FCALL_STATE] = { .type = STATIC, .name = "call_state", .flags = O_WRONLY | O_TRUNC | O_CREAT }, }; +enum { CMEMBERS, CINVITE, CLEAVE, CTITLE_IN, CTITLE_OUT, CTEXT_IN, CTEXT_OUT }; + +static struct file cfiles[] = { + [CMEMBERS] = { .type = STATIC, .name = "members", .flags = O_WRONLY | O_TRUNC | O_CREAT }, + [CINVITE] = { .type = FIFO, .name = "invite", .flags = O_RDONLY | O_NONBLOCK }, + [CLEAVE] = { .type = FIFO, .name = "leave", .flags = O_RDONLY | O_NONBLOCK }, + [CTITLE_OUT] = { .type = STATIC, .name = "title_out", .flags = O_WRONLY | O_TRUNC | O_CREAT }, + [CTITLE_IN] = { .type = FIFO, .name = "title_in", .flags = O_RDONLY | O_NONBLOCK }, + [CTEXT_IN] = { .type = FIFO, .name = "text_in", .flags = O_RDONLY | O_NONBLOCK }, + [CTEXT_OUT] = { .type = STATIC, .name = "text_out", .flags = O_WRONLY | O_APPEND | O_CREAT }, +}; + static char *ustate[] = { [TOX_USER_STATUS_NONE] = "available", [TOX_USER_STATUS_AWAY] = "away", @@ -161,6 +175,14 @@ struct friend { TAILQ_ENTRY(friend) entry; }; +struct conference { + uint32_t num; + char numstr[2 * sizeof(uint32_t)]; + int dirfd; + int fd[LEN(gfiles)]; + TAILQ_ENTRY(conference) entry; +}; + struct request { uint8_t id[TOX_PUBLIC_KEY_SIZE]; char idstr[2 * TOX_PUBLIC_KEY_SIZE + 1]; @@ -170,6 +192,7 @@ struct request { }; static TAILQ_HEAD(friendhead, friend) friendhead = TAILQ_HEAD_INITIALIZER(friendhead); +static TAILQ_HEAD(confhead, conference) confhead = TAILQ_HEAD_INITIALIZER(confhead); static TAILQ_HEAD(reqhead, request) reqhead = TAILQ_HEAD_INITIALIZER(reqhead); static Tox *tox; @@ -220,6 +243,7 @@ static int toxconnect(void); static void id2str(uint8_t *, char *); static void str2id(char *, uint8_t *); static struct friend *friendcreate(uint32_t); +static struct conference * confcreate(uint32_t); static void friendload(void); static void frienddestroy(struct friend *); static void loop(void); @@ -1324,6 +1348,61 @@ friendcreate(uint32_t frnum) return f; } +static struct conference * +confcreate(uint32_t cnum) +{ + struct conference *c; + DIR *d; + size_t i; + int r; + uint8_t title[TOX_MAX_NAME_LENGTH + 1]; + TOX_ERR_CONFERENCE_TITLE err; + + c = calloc(1, sizeof(*c)); + if(!c) + eprintf("calloc:"); + c->num = cnum; + sprintf(c->numstr, "%08X", c->num); + r = mkdir(c->numstr, 0777); + if(r < 0 && errno != EEXIST) + eprintf("mkdir %s:", c->numstr); + + d = opendir(c->numstr); + if (!d) + eprintf("opendir %s:", c->numstr); + + r = dirfd(d); + if (r < 0) + eprintf("dirfd %s:", c->numstr); + c->dirfd = r; + + for (i = 0; i < LEN(cfiles); i++) { + c->fd[i] = -1; + if (cfiles[i].type == FIFO) { + fiforeset(c->dirfd, &c->fd[i], cfiles[i]); + } else if (cfiles[i].type == STATIC) { + c->fd[i] = fifoopen(c->dirfd, cfiles[i]); + } + } + + /*The peer list is written when we invite the members by the callback*/ + ftruncate(c->fd[CMEMBERS], 0); + + i = tox_conference_get_title_size(tox, cnum, &err); + if (err != TOX_ERR_CONFERENCE_TITLE_OK) { + weprintf("Unable to obtain conference title for %d\n", cnum); + } else { + tox_conference_get_title(tox, cnum, title, NULL); + title[i] = '\0'; + ftruncate(c->fd[CTITLE_OUT], 0); + dprintf(c->fd[CTITLE_OUT], "%s\n", title); + } + + TAILQ_INSERT_TAIL(&confhead, c, entry); + + return c; +} + static void frienddestroy(struct friend *f) { @@ -1542,6 +1621,30 @@ end: fiforeset(gslots[NOSPAM].dirfd, &gslots[NOSPAM].fd[IN], gfiles[IN]); } +static void +newconf(void *data) +{ + uint32_t cnum; + size_t n; + char title[TOX_MAX_NAME_LENGTH + 1]; + + n = fiforead(gslots[CONF].dirfd, &gslots[NAME].fd[IN], gfiles[IN], + title, sizeof(title) - 1); + if (n <= 0) + return; + if (title[n - 1] == '\n') + n--; + title[n] = '\0'; + cnum = tox_conference_new(tox, NULL); + if (cnum == UINT32_MAX) { + weprintf("Failed to create new conference\n"); + return; + } + if (!tox_conference_set_title(tox, cnum, (uint8_t *)title, n, NULL)) + weprintf("Failed to set conference title to \"%s\"", title); + confcreate(cnum); +} + static void loop(void) { -- cgit v1.2.3 From 340488b7f3615a48f7464f596754514653112fd6 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Fri, 2 Dec 2016 11:09:23 +0100 Subject: Fix issue with endianness in confcreate(). --- ratox.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 266524e..36a98cf 100644 --- a/ratox.c +++ b/ratox.c @@ -3,6 +3,8 @@ #include #include +#include + #include #include #include @@ -1362,7 +1364,7 @@ confcreate(uint32_t cnum) if(!c) eprintf("calloc:"); c->num = cnum; - sprintf(c->numstr, "%08X", c->num); + sprintf(c->numstr, "%08X", ntohl(c->num)); r = mkdir(c->numstr, 0777); if(r < 0 && errno != EEXIST) eprintf("mkdir %s:", c->numstr); -- cgit v1.2.3 From 41f7619d0241d5e673138d7adc3badece42b7d2f Mon Sep 17 00:00:00 2001 From: pranomostro Date: Thu, 29 Dec 2016 15:45:07 +0100 Subject: Fixed removal of conference directories and files. --- ratox.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 12 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 36a98cf..73b9b3c 100644 --- a/ratox.c +++ b/ratox.c @@ -179,7 +179,7 @@ struct friend { struct conference { uint32_t num; - char numstr[2 * sizeof(uint32_t)]; + char numstr[2 * sizeof(uint32_t) + 1]; int dirfd; int fd[LEN(gfiles)]; TAILQ_ENTRY(conference) entry; @@ -221,6 +221,7 @@ static void cbcalldata(ToxAV *, uint32_t, const int16_t *, size_t, uint8_t, uint static void cancelcall(struct friend *, char *); static void sendfriendcalldata(struct friend *); +static void writemembers(struct conference *); static void cbconnstatus(Tox *, uint32_t, TOX_CONNECTION, void *); static void cbfriendmessage(Tox *, uint32_t, TOX_MESSAGE_TYPE, const uint8_t *, size_t, void *); @@ -530,6 +531,33 @@ sendfriendcalldata(struct friend *f) weprintf("Failed to send audio frame: %s\n", callerr[err]); } +static void +writemembers(struct conference *c) +{ + size_t i; + uint32_t peers, pnum; + uint8_t name[TOX_MAX_NAME_LENGTH + 1]; + TOX_ERR_CONFERENCE_PEER_QUERY err; + + /*The peer list is written when we invite the members by the callback*/ + ftruncate(c->fd[CMEMBERS], 0); + peers = tox_conference_peer_count(tox, c->num, &err); + + if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) { + weprintf("Unable to obtain peer count for conference %d\n", c->num); + return; + } + for (pnum = 0; pnum < peers; pnum++) { + if (!tox_conference_peer_get_name(tox, c->num, pnum, name, NULL)) { + weprintf("Unable to obtain the name for peer %d\n", pnum); + } else { + i = tox_conference_peer_get_name_size(tox, c->num, pnum, NULL); + name[i] = '\0'; + dprintf(c->fd[CMEMBERS], "%s\n", name); + } + } +} + static void cbconnstatus(Tox *m, uint32_t frnum, TOX_CONNECTION status, void *udata) { @@ -1354,17 +1382,17 @@ static struct conference * confcreate(uint32_t cnum) { struct conference *c; - DIR *d; - size_t i; - int r; - uint8_t title[TOX_MAX_NAME_LENGTH + 1]; + DIR *d; + size_t i; + int r; + uint8_t title[TOX_MAX_NAME_LENGTH + 1]; TOX_ERR_CONFERENCE_TITLE err; c = calloc(1, sizeof(*c)); if(!c) eprintf("calloc:"); c->num = cnum; - sprintf(c->numstr, "%08X", ntohl(c->num)); + sprintf(c->numstr, "%08X", c->num); r = mkdir(c->numstr, 0777); if(r < 0 && errno != EEXIST) eprintf("mkdir %s:", c->numstr); @@ -1387,14 +1415,13 @@ confcreate(uint32_t cnum) } } - /*The peer list is written when we invite the members by the callback*/ - ftruncate(c->fd[CMEMBERS], 0); + writemembers(c); - i = tox_conference_get_title_size(tox, cnum, &err); + i = tox_conference_get_title_size(tox, c->num, &err); if (err != TOX_ERR_CONFERENCE_TITLE_OK) { weprintf("Unable to obtain conference title for %d\n", cnum); } else { - tox_conference_get_title(tox, cnum, title, NULL); + tox_conference_get_title(tox, c->num, title, NULL); title[i] = '\0'; ftruncate(c->fd[CTITLE_OUT], 0); dprintf(c->fd[CTITLE_OUT], "%s\n", title); @@ -1425,6 +1452,22 @@ frienddestroy(struct friend *f) TAILQ_REMOVE(&friendhead, f, entry); } +static void +confdestroy(struct conference *c) +{ + size_t i; + + for (i = 0; i dirfd != -1) { + unlinkat(c->dirfd, cfiles[i].name, 0); + if (c->fd[i] != -1) + close(c->fd[i]); + } + } + rmdir(c->numstr); + TAILQ_REMOVE(&confhead, c, entry); +} + static void friendload(void) { @@ -1630,7 +1673,7 @@ newconf(void *data) size_t n; char title[TOX_MAX_NAME_LENGTH + 1]; - n = fiforead(gslots[CONF].dirfd, &gslots[NAME].fd[IN], gfiles[IN], + n = fiforead(gslots[CONF].dirfd, &gslots[CONF].fd[IN], gfiles[IN], title, sizeof(title) - 1); if (n <= 0) return; @@ -1780,7 +1823,6 @@ loop(void) if (f->av.state == TRANSMITTING) cancelcall(f, "Hung up"); - if (f->av.state & RINGING) { if (f->av.state & OUTGOING) { c1 = time(NULL); @@ -1903,6 +1945,7 @@ toxshutdown(void) { struct friend *f, *ftmp; struct request *r, *rtmp; + struct conference *c, *ctmp; size_t i, m; logmsg("Shutdown\n"); @@ -1915,6 +1958,12 @@ toxshutdown(void) frienddestroy(f); } + /* Conferences */ + for (c = TAILQ_FIRST(&confhead); c; c=ctmp) { + ctmp = TAILQ_NEXT(c, entry); + confdestroy(c); + } + /* Requests */ for (r = TAILQ_FIRST(&reqhead); r; r = rtmp) { rtmp = TAILQ_NEXT(r, entry); -- cgit v1.2.3 From a2dc1e8abbad2dd9c014de56d26b8855fab1ec78 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Sat, 31 Dec 2016 00:53:36 +0100 Subject: Begin writing functions for the invitation callback. --- ratox.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 95 insertions(+), 12 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 73b9b3c..a6d11de 100644 --- a/ratox.c +++ b/ratox.c @@ -49,7 +49,6 @@ const char *callerr[] = { [TOXAV_ERR_SEND_FRAME_RTP_FAILED] = "Failed to push frame through rtp interface" }; - struct node { char *addr4; char *addr6; @@ -181,7 +180,7 @@ struct conference { uint32_t num; char numstr[2 * sizeof(uint32_t) + 1]; int dirfd; - int fd[LEN(gfiles)]; + int fd[LEN(cfiles)]; TAILQ_ENTRY(conference) entry; }; @@ -193,9 +192,18 @@ struct request { TAILQ_ENTRY(request) entry; }; +struct invite { + char *fifoname; + char *cookie; + size_t cookielen; + int fd; + TAILQ_ENTRY(invite) entry; +}; + static TAILQ_HEAD(friendhead, friend) friendhead = TAILQ_HEAD_INITIALIZER(friendhead); static TAILQ_HEAD(confhead, conference) confhead = TAILQ_HEAD_INITIALIZER(confhead); static TAILQ_HEAD(reqhead, request) reqhead = TAILQ_HEAD_INITIALIZER(reqhead); +static TAILQ_HEAD(invhead, invite) invhead = TAILQ_HEAD_INITIALIZER(invhead); static Tox *tox; static ToxAV *toxav; @@ -233,6 +241,11 @@ static void cbfilecontrol(Tox *, uint32_t, uint32_t, TOX_FILE_CONTROL, void *); static void cbfilesendreq(Tox *, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *); static void cbfiledata(Tox *, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *); +static void cbconfinvite(Tox *, uint32_t, TOX_CONFERENCE_TYPE, const uint8_t *, size_t, void *); +static void cbconfmessage(Tox *, uint32_t, uint32_t, TOX_MESSAGE_TYPE, const uint8_t *, size_t, void *); +static void cbconftitle(Tox *, uint32_t, uint32_t, const uint8_t *, size_t, void *); +static void cbconfmembers(Tox *, uint32_t, uint32_t, TOX_CONFERENCE_STATE_CHANGE, void *); + static void canceltxtransfer(struct friend *); static void cancelrxtransfer(struct friend *); static void sendfriendtext(struct friend *); @@ -245,8 +258,8 @@ static int toxinit(void); static int toxconnect(void); static void id2str(uint8_t *, char *); static void str2id(char *, uint8_t *); -static struct friend *friendcreate(uint32_t); -static struct conference * confcreate(uint32_t); +static void friendcreate(uint32_t); +static void confcreate(uint32_t); static void friendload(void); static void frienddestroy(struct friend *); static void loop(void); @@ -468,6 +481,75 @@ cbcalldata(ToxAV *av, uint32_t fnum, const int16_t *data, size_t len, } } +static void +cbconfinvite(Tox *m, uint32_t frnum, TOX_CONFERENCE_TYPE type, const uint8_t *cookie, size_t clen, void * udata) +{ + printf("called function %s\n", __func__); + + size_t i, j, namelen; + struct file invfifo; + struct invite *inv; + uint8_t id[TOX_PUBLIC_KEY_SIZE]; + + if (!tox_friend_get_public_key(tox, frnum, id, NULL)) { + weprintf(": %d: Key: Failed to get for invite\n", frnum); + return; + } + + inv = calloc(1, sizeof(*inv)); + if (!inv) + eprintf("calloc:"); + inv->fd = -1; + + inv->cookielen = clen; + inv->cookie = malloc(inv->cookielen); + if (!inv->cookie) + eprintf("malloc:"); + + namelen = 2 * TOX_PUBLIC_KEY_SIZE + 1 + 2 * clen + 1; + inv->fifoname = malloc(namelen); + if (!inv->fifoname) + eprintf("malloc:"); + + memcpy(inv->cookie, cookie, clen); + + i = 0; + id2str(id, inv->fifoname); + i += 2 * TOX_PUBLIC_KEY_SIZE; + inv->fifoname[i] = '_'; + i++; + for(j = 0; j < clen; i+=2, j++) + sprintf(inv->fifoname + i, "%02X", cookie[j]); + i++; + inv->fifoname[i] = '\0'; + + invfifo.name = inv->fifoname; + invfifo.flags = O_RDONLY | O_NONBLOCK; + fiforeset(gslots[CONF].fd[OUT], &inv->fd, invfifo); + + TAILQ_INSERT_TAIL(&invhead, inv, entry); + + logmsg("Invite: %s\n", inv->fifoname); +} + +static void +cbconfmessage(Tox *m, uint32_t cnum, uint32_t pnum, TOX_MESSAGE_TYPE type, const uint8_t *msg, size_t len, void *udata) +{ + printf("called function %s\n", __func__); +} + +static void +cbconftitle(Tox *m, uint32_t cnum, uint32_t pnum, const uint8_t *title, size_t len, void * udata) +{ + printf("called function %s\n", __func__); +} + +static void +cbconfmembers(Tox *m, uint32_t cnum, uint32_t pnum, TOX_CONFERENCE_STATE_CHANGE type, void *udata) +{ + printf("called function %s\n", __func__); +} + static void cancelcall(struct friend *f, char *action) { @@ -1225,6 +1307,11 @@ toxinit(void) toxav_callback_audio_receive_frame(toxav, cbcalldata, NULL); + tox_callback_conference_invite(tox, cbconfinvite); + tox_callback_conference_message(tox, cbconfmessage); + tox_callback_conference_title(tox, cbconftitle); + tox_callback_conference_namelist_change(tox, cbconfmembers); + if (toxopt.savedata_data) free((void *)toxopt.savedata_data); @@ -1287,7 +1374,7 @@ str2id(char *idstr, uint8_t *id) sscanf(p, "%2hhx", &id[i]); } -static struct friend * +static void friendcreate(uint32_t frnum) { struct friend *f; @@ -1304,7 +1391,7 @@ friendcreate(uint32_t frnum) i = tox_friend_get_name_size(tox, frnum, &err); if (err != TOX_ERR_FRIEND_QUERY_OK) { weprintf(": %ld : Name : Failed to get\n", (long)frnum); - return NULL; + return; } else if (i == 0) { snprintf(f->name, sizeof(f->name), "Anonymous"); } else { @@ -1315,7 +1402,7 @@ friendcreate(uint32_t frnum) f->num = frnum; if (!tox_friend_get_public_key(tox, f->num, f->id, NULL)) { weprintf(": %s: Key : Failed to get\n", f->name); - return NULL; + return; } id2str(f->id, f->idstr); @@ -1374,11 +1461,9 @@ friendcreate(uint32_t frnum) f->av.state = 0; TAILQ_INSERT_TAIL(&friendhead, f, entry); - - return f; } -static struct conference * +static void confcreate(uint32_t cnum) { struct conference *c; @@ -1428,8 +1513,6 @@ confcreate(uint32_t cnum) } TAILQ_INSERT_TAIL(&confhead, c, entry); - - return c; } static void -- cgit v1.2.3 From 37fa2e3d14cb5c86c0f2b789be1517dafdb25dda Mon Sep 17 00:00:00 2001 From: pranomostro Date: Fri, 13 Jan 2017 11:54:29 +0100 Subject: Remove conference slots as well. Fix some naming. --- ratox.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index a6d11de..52f9848 100644 --- a/ratox.c +++ b/ratox.c @@ -484,8 +484,6 @@ cbcalldata(ToxAV *av, uint32_t fnum, const int16_t *data, size_t len, static void cbconfinvite(Tox *m, uint32_t frnum, TOX_CONFERENCE_TYPE type, const uint8_t *cookie, size_t clen, void * udata) { - printf("called function %s\n", __func__); - size_t i, j, namelen; struct file invfifo; struct invite *inv; @@ -2029,7 +2027,8 @@ toxshutdown(void) struct friend *f, *ftmp; struct request *r, *rtmp; struct conference *c, *ctmp; - size_t i, m; + struct invite *i, *itmp; + size_t s, m; logmsg("Shutdown\n"); @@ -2061,18 +2060,33 @@ toxshutdown(void) free(r); } + /* Invites */ + for (i = TAILQ_FIRST(&invhead); i; i = itmp) { + itmp = TAILQ_NEXT(i, entry); + + if(gslots[CONF].fd[OUT] != -1) { + unlinkat(gslots[CONF].fd[OUT], i->fifoname, 0); + if (i->fd != -1) + close(i->fd); + } + TAILQ_REMOVE(&invhead, i, entry); + free(i->fifoname); + free(i->cookie); + free(i); + } + /* Global files and slots */ - for (i = 0; i < LEN(gslots); i++) { + for (s = 0; s < LEN(gslots); s++) { for (m = 0; m < LEN(gfiles); m++) { - if (gslots[i].dirfd != -1) { - unlinkat(gslots[i].dirfd, gfiles[m].name, - (gslots[i].outisfolder && m == OUT) + if (gslots[s].dirfd != -1) { + unlinkat(gslots[s].dirfd, gfiles[m].name, + (gslots[s].outisfolder && m == OUT) ? AT_REMOVEDIR : 0); - if (gslots[i].fd[m] != -1) - close(gslots[i].fd[m]); + if (gslots[s].fd[m] != -1) + close(gslots[s].fd[m]); } - } - rmdir(gslots[i].name); + } + rmdir(gslots[s].name); } unlink("id"); if (idfd != -1) -- cgit v1.2.3 From d6d3c59c4185f6eab5564b059760fd59a7bc430b Mon Sep 17 00:00:00 2001 From: pranomostro Date: Fri, 13 Jan 2017 14:14:59 +0100 Subject: Incorporated changes from master. --- ratox.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 52f9848..18015a2 100644 --- a/ratox.c +++ b/ratox.c @@ -64,7 +64,7 @@ struct file { int flags; }; -enum { NONE, FIFO, STATIC, FOLDER }; +enum { NONE, FIFO, STATIC }; enum { IN, OUT, ERR }; static struct file gfiles[] = { @@ -1058,7 +1058,7 @@ readpass(const char *prompt, uint8_t **target, uint32_t *len) return -1; *target = realloc(*target, strlen(p)); /* not null-terminated */ if (!*target) - eprintf("malloc:"); + eprintf("realloc:"); memcpy(*target, p, strlen(p)); *len = strlen(p); return 0; @@ -1157,14 +1157,14 @@ datasave(void) tox_get_savedata(tox, intermediate); + sz += encryptsavefile ? TOX_PASS_ENCRYPTION_EXTRA_LENGTH : 0; + data = malloc(sz); + if (!data) + eprintf("malloc:"); + if (encryptsavefile){ - sz += TOX_PASS_ENCRYPTION_EXTRA_LENGTH; - data = malloc(sz); - if (!intermediate) - eprintf("malloc:"); tox_pass_encrypt(intermediate, sz - TOX_PASS_ENCRYPTION_EXTRA_LENGTH, passphrase, pplen, data, NULL); } else { - data = malloc(sz); memcpy(data, intermediate, sz); } if (write(fd, data, sz) != sz) -- cgit v1.2.3 From 893fbea98ef99451884a99be856fdfd77d87200b Mon Sep 17 00:00:00 2001 From: pranomostro Date: Fri, 13 Jan 2017 17:25:49 +0100 Subject: Added implementations for the different conference callbacks. --- ratox.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 18015a2..361a452 100644 --- a/ratox.c +++ b/ratox.c @@ -531,21 +531,62 @@ cbconfinvite(Tox *m, uint32_t frnum, TOX_CONFERENCE_TYPE type, const uint8_t *co } static void -cbconfmessage(Tox *m, uint32_t cnum, uint32_t pnum, TOX_MESSAGE_TYPE type, const uint8_t *msg, size_t len, void *udata) +cbconfmessage(Tox *m, uint32_t cnum, uint32_t pnum, TOX_MESSAGE_TYPE type, const uint8_t *data, size_t len, void *udata) { - printf("called function %s\n", __func__); + struct conference *c; + time_t t; + uint8_t msg[len + 1], namt[TOX_MAX_NAME_LENGTH + 1]; + char buft[64]; + + memcpy(msg, data, len); + msg[len] = '\0'; + + TAILQ_FOREACH(c, &confhead, entry) { + if (c->num == cnum) { + t = time(NULL); + strftime(buft, sizeof(buft), "%F %R", localtime(&t)); + if (!tox_conference_peer_get_name(tox, c->num, pnum, namt, NULL)) { + weprintf("Unable to obtain name for peer %d in conference %s\n", pnum, c->numstr); + return; + } + namt[tox_conference_peer_get_name_size(tox, c->num, pnum, NULL)] = '\0'; + dprintf(c->fd[CTEXT_OUT], "%s <%s> %s\n", buft, namt, msg); + break; + } + } } static void -cbconftitle(Tox *m, uint32_t cnum, uint32_t pnum, const uint8_t *title, size_t len, void * udata) +cbconftitle(Tox *m, uint32_t cnum, uint32_t pnum, const uint8_t *data, size_t len, void * udata) { - printf("called function %s\n", __func__); + struct conference *c; + char title[TOX_MAX_NAME_LENGTH + 1]; + + memcpy(title, data, len); + title[len] = '\0'; + + TAILQ_FOREACH(c, &confhead, entry) { + if (c->num == cnum) { + ftruncate(c->fd[CTITLE_OUT], 0); + lseek(c->fd[CTITLE_OUT], 0, SEEK_SET); + dprintf(c->fd[CTITLE_OUT], "%s\n", title); + logmsg(": %s : Title > %s\n", c->numstr, title); + break; + } + } } static void cbconfmembers(Tox *m, uint32_t cnum, uint32_t pnum, TOX_CONFERENCE_STATE_CHANGE type, void *udata) { - printf("called function %s\n", __func__); + struct conference *c; + + TAILQ_FOREACH(c, &confhead, entry) { + if (c->num == cnum) { + writemembers(c); + break; + } + } } static void -- cgit v1.2.3 From b194c09a7048582adc30dfae62c18c816191500c Mon Sep 17 00:00:00 2001 From: pranomostro Date: Fri, 10 Feb 2017 21:55:59 +0100 Subject: Add handling of joining conferences in loop(). --- ratox.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 361a452..212a243 100644 --- a/ratox.c +++ b/ratox.c @@ -196,6 +196,7 @@ struct invite { char *fifoname; char *cookie; size_t cookielen; + uint32_t inviter; int fd; TAILQ_ENTRY(invite) entry; }; @@ -499,6 +500,7 @@ cbconfinvite(Tox *m, uint32_t frnum, TOX_CONFERENCE_TYPE type, const uint8_t *co eprintf("calloc:"); inv->fd = -1; + inv->inviter = frnum; inv->cookielen = clen; inv->cookie = malloc(inv->cookielen); if (!inv->cookie) @@ -1815,16 +1817,18 @@ newconf(void *data) static void loop(void) { - struct file reqfifo; + struct file reqfifo, invfifo; struct friend *f, *ftmp; struct request *req, *rtmp; + struct conference *c; + struct invite *inv, *itmp; struct timeval tv; fd_set rfds; time_t t0, t1, c0, c1; size_t i; int connected = 0, n, r, fd, fdmax; - char tstamp[64], c; - uint32_t frnum; + char tstamp[64], ch; + uint32_t frnum, cnum; t0 = time(NULL); logmsg("DHT > Connecting\n"); @@ -1865,6 +1869,9 @@ loop(void) TAILQ_FOREACH(req, &reqhead, entry) FD_APPEND(req->fd); + TAILQ_FOREACH(inv, &invhead, entry) + FD_APPEND(inv->fd); + TAILQ_FOREACH(f, &friendhead, entry) { /* Only monitor friends that are online */ if (tox_friend_get_connection_status(tox, f->num, NULL) != TOX_CONNECTION_NONE) { @@ -1878,6 +1885,12 @@ loop(void) FD_APPEND(f->fd[FREMOVE]); } + TAILQ_FOREACH(c, &confhead, entry) { + FD_APPEND(c->fd[CLEAVE]); + FD_APPEND(c->fd[CTITLE_IN]); + FD_APPEND(c->fd[CTEXT_IN]); + } + tv.tv_sec = 0; tv.tv_usec = interval(tox, toxav) * 1000; n = select(fdmax + 1, &rfds, NULL, NULL, &tv); @@ -1924,6 +1937,7 @@ loop(void) } } + /* Answer pending calls */ TAILQ_FOREACH(f, &friendhead, entry) { if (tox_friend_get_connection_status(tox, f->num, NULL) == TOX_CONNECTION_NONE) @@ -1980,9 +1994,9 @@ loop(void) reqfifo.name = req->idstr; reqfifo.flags = O_RDONLY | O_NONBLOCK; if (fiforead(gslots[REQUEST].fd[OUT], &req->fd, reqfifo, - &c, 1) != 1) + &ch, 1) != 1) continue; - if (c != '0' && c != '1') + if (ch != '0' && ch != '1') continue; frnum = tox_friend_add_norequest(tox, req->id, NULL); if (frnum == UINT32_MAX) { @@ -1990,7 +2004,7 @@ loop(void) fiforeset(gslots[REQUEST].fd[OUT], &req->fd, reqfifo); continue; } - if (c == '1') { + if (ch == '1') { friendcreate(frnum); logmsg("Request : %s > Accepted\n", req->idstr); datasave(); @@ -2005,6 +2019,35 @@ loop(void) free(req); } + for (inv = TAILQ_FIRST(&invhead); inv; inv = itmp) { + itmp = TAILQ_NEXT(inv, entry); + if (FD_ISSET(inv->fd, &rfds) == 0) + continue; + invfifo.name = inv->fifoname; + invfifo.flags = O_RDONLY | O_NONBLOCK; + if (fiforead(gslots[CONF].fd[OUT], &inv->fd, invfifo, + &ch, 1) != 1) + continue; + if (ch != '0' && ch != '1') + continue; + else if (ch == '1'){ + cnum = tox_conference_join(tox, inv->inviter, (uint8_t *)inv->cookie, + inv->cookielen, NULL); + if(cnum == UINT32_MAX) { + weprintf("Failed to join conference\n"); + fiforeset(gslots[CONF].fd[OUT], &inv->fd, invfifo); + continue; + } else { + logmsg("Invite : %d > Accepted\n", cnum); + } + confcreate(cnum); + } + unlinkat(gslots[CONF].fd[OUT], inv->fifoname, 0); + close(inv->fd); + free(inv->fifoname); + free(inv->cookie); + } + for (f = TAILQ_FIRST(&friendhead); f; f = ftmp) { ftmp = TAILQ_NEXT(f, entry); if (FD_ISSET(f->fd[FTEXT_IN], &rfds)) -- cgit v1.2.3 From a365337cb9d934742f609e274d751fda63212f80 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Sat, 11 Feb 2017 01:00:02 +0100 Subject: Remove unnecessary include. --- ratox.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 212a243..88967e3 100644 --- a/ratox.c +++ b/ratox.c @@ -3,8 +3,6 @@ #include #include -#include - #include #include #include -- cgit v1.2.3 From 97695371f061993f008fcc46b4baf3e1265ad82b Mon Sep 17 00:00:00 2001 From: pranomostro Date: Thu, 16 Feb 2017 13:22:20 +0100 Subject: Free invite structures after accepting. --- ratox.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 88967e3..8a3a2c6 100644 --- a/ratox.c +++ b/ratox.c @@ -2042,8 +2042,10 @@ loop(void) } unlinkat(gslots[CONF].fd[OUT], inv->fifoname, 0); close(inv->fd); + TAILQ_REMOVE(&invhead, inv, entry); free(inv->fifoname); free(inv->cookie); + free(inv); } for (f = TAILQ_FIRST(&friendhead); f; f = ftmp) { -- cgit v1.2.3 From 2b874bae58664cb87728769b682837b22670b0a0 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Thu, 16 Feb 2017 20:08:47 +0100 Subject: Finish conferences that can be left, joined, and used for sending messages. --- ratox.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 6 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 8a3a2c6..a221496 100644 --- a/ratox.c +++ b/ratox.c @@ -249,6 +249,8 @@ static void canceltxtransfer(struct friend *); static void cancelrxtransfer(struct friend *); static void sendfriendtext(struct friend *); static void removefriend(struct friend *); +static void invitefriend(struct conference *); +static void sendconftext(struct conference *); static int readpass(const char *, uint8_t **, uint32_t *); static void dataload(struct Tox_Options *); static void datasave(void); @@ -261,6 +263,7 @@ static void friendcreate(uint32_t); static void confcreate(uint32_t); static void friendload(void); static void frienddestroy(struct friend *); +static void confdestroy(struct conference *); static void loop(void); static void initshutdown(int); static void toxshutdown(void); @@ -504,7 +507,7 @@ cbconfinvite(Tox *m, uint32_t frnum, TOX_CONFERENCE_TYPE type, const uint8_t *co if (!inv->cookie) eprintf("malloc:"); - namelen = 2 * TOX_PUBLIC_KEY_SIZE + 1 + 2 * clen + 1; + namelen = 2 * TOX_PUBLIC_KEY_SIZE + 1 + 2 * clen + 2; inv->fifoname = malloc(namelen); if (!inv->fifoname) eprintf("malloc:"); @@ -527,7 +530,7 @@ cbconfinvite(Tox *m, uint32_t frnum, TOX_CONFERENCE_TYPE type, const uint8_t *co TAILQ_INSERT_TAIL(&invhead, inv, entry); - logmsg("Invite: %s\n", inv->fifoname); + logmsg("Conference > Invite: %s\n", inv->fifoname); } static void @@ -983,7 +986,8 @@ cbfilesendreq(Tox *m, uint32_t frnum, uint32_t fnum, uint32_t kind, uint64_t fsz } static void -cbfiledata(Tox *m, uint32_t frnum, uint32_t fnum, uint64_t pos, const uint8_t *data, size_t len, void *udata) +cbfiledata(Tox *m, uint32_t frnum, uint32_t fnum, uint64_t pos, + const uint8_t *data, size_t len, void *udata) { struct friend *f; ssize_t n; @@ -1085,6 +1089,51 @@ removefriend(struct friend *f) frienddestroy(f); } +static void +invitefriend(struct conference *c) +{ + ssize_t n; + char buf[2 * TOX_ADDRESS_SIZE + 1]; + struct friend *f; + TOX_ERR_CONFERENCE_INVITE err; + + n = fiforead(c->dirfd, &c->fd[CINVITE], cfiles[CINVITE], buf, sizeof(buf)); + + if (n > sizeof(buf) || n <= 0) + return; + if (buf[n - 1] == '\n') + buf[n - 1] = '\0'; + + TAILQ_FOREACH(f, &friendhead, entry) + if (!memcmp(buf, f->idstr, sizeof(f->idstr))) + break; + if (!f) { + logmsg("Conference > no friend with id %s found\n", buf); + return; + } + if (!tox_conference_invite(tox, f->num, c->num, &err)) + weprintf("Failed to invite %s, error %d\n", buf, err); + else + logmsg("Conference > Invite %s\n", buf); +} + +static void +sendconftext(struct conference *c) +{ + ssize_t n; + uint8_t buf[TOX_MAX_MESSAGE_LENGTH]; + TOX_ERR_CONFERENCE_SEND_MESSAGE err; + + n = fiforead(c->dirfd, &c->fd[CTEXT_IN], cfiles[CTEXT_IN], buf, sizeof(buf)); + if (n <= 0) + return; + if (buf[n - 1] == '\n' && n > 1) + n--; + if (!tox_conference_send_message(tox, c->num, TOX_MESSAGE_TYPE_NORMAL, + buf, n, &err)) + weprintf("Failed to send message to conference %s, error %d\n", c->numstr, err); +} + static int readpass(const char *prompt, uint8_t **target, uint32_t *len) { @@ -1552,6 +1601,8 @@ confcreate(uint32_t cnum) } TAILQ_INSERT_TAIL(&confhead, c, entry); + + logmsg("Conference > Created %s\n", c->numstr); } static void @@ -1818,7 +1869,7 @@ loop(void) struct file reqfifo, invfifo; struct friend *f, *ftmp; struct request *req, *rtmp; - struct conference *c; + struct conference *c, *ctmp; struct invite *inv, *itmp; struct timeval tv; fd_set rfds; @@ -1887,6 +1938,7 @@ loop(void) FD_APPEND(c->fd[CLEAVE]); FD_APPEND(c->fd[CTITLE_IN]); FD_APPEND(c->fd[CTEXT_IN]); + FD_APPEND(c->fd[CINVITE]); } tv.tv_sec = 0; @@ -2035,8 +2087,6 @@ loop(void) weprintf("Failed to join conference\n"); fiforeset(gslots[CONF].fd[OUT], &inv->fd, invfifo); continue; - } else { - logmsg("Invite : %d > Accepted\n", cnum); } confcreate(cnum); } @@ -2048,6 +2098,20 @@ loop(void) free(inv); } + for (c = TAILQ_FIRST(&confhead); c; c = ctmp) { + ctmp = TAILQ_NEXT(c, entry); + if (FD_ISSET(c->fd[CINVITE], &rfds)) + invitefriend(c); + if (FD_ISSET(c->fd[CLEAVE], &rfds)) { + logmsg("Conference > leave %s\n", c->numstr); + if (!tox_conference_delete(tox, c->num, NULL)) + weprintf("Failed to leave conference %d\n", c->num); + confdestroy(c); + } + if (FD_ISSET(c->fd[CTEXT_IN], &rfds)) + sendconftext(c); + } + for (f = TAILQ_FIRST(&friendhead); f; f = ftmp) { ftmp = TAILQ_NEXT(f, entry); if (FD_ISSET(f->fd[FTEXT_IN], &rfds)) -- cgit v1.2.3 From 0c97a43e51d3960d9d296438701c4e37f5472f77 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Thu, 16 Feb 2017 20:29:57 +0100 Subject: Added ability to change the title of a conference. --- ratox.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index a221496..548456b 100644 --- a/ratox.c +++ b/ratox.c @@ -251,6 +251,7 @@ static void sendfriendtext(struct friend *); static void removefriend(struct friend *); static void invitefriend(struct conference *); static void sendconftext(struct conference *); +static void updatetitle(struct conference *); static int readpass(const char *, uint8_t **, uint32_t *); static void dataload(struct Tox_Options *); static void datasave(void); @@ -1095,7 +1096,6 @@ invitefriend(struct conference *c) ssize_t n; char buf[2 * TOX_ADDRESS_SIZE + 1]; struct friend *f; - TOX_ERR_CONFERENCE_INVITE err; n = fiforead(c->dirfd, &c->fd[CINVITE], cfiles[CINVITE], buf, sizeof(buf)); @@ -1111,8 +1111,8 @@ invitefriend(struct conference *c) logmsg("Conference > no friend with id %s found\n", buf); return; } - if (!tox_conference_invite(tox, f->num, c->num, &err)) - weprintf("Failed to invite %s, error %d\n", buf, err); + if (!tox_conference_invite(tox, f->num, c->num, NULL)) + weprintf("Failed to invite %s\n", buf); else logmsg("Conference > Invite %s\n", buf); } @@ -1122,7 +1122,6 @@ sendconftext(struct conference *c) { ssize_t n; uint8_t buf[TOX_MAX_MESSAGE_LENGTH]; - TOX_ERR_CONFERENCE_SEND_MESSAGE err; n = fiforead(c->dirfd, &c->fd[CTEXT_IN], cfiles[CTEXT_IN], buf, sizeof(buf)); if (n <= 0) @@ -1130,8 +1129,27 @@ sendconftext(struct conference *c) if (buf[n - 1] == '\n' && n > 1) n--; if (!tox_conference_send_message(tox, c->num, TOX_MESSAGE_TYPE_NORMAL, - buf, n, &err)) - weprintf("Failed to send message to conference %s, error %d\n", c->numstr, err); + buf, n, NULL)) + weprintf("Failed to send message to conference %s, error %d\n", c->numstr); +} + +static void +updatetitle(struct conference *c) +{ + ssize_t n; + uint8_t title[TOX_MAX_STATUS_MESSAGE_LENGTH + 1]; + + n = fiforead(c->dirfd, &c->fd[CTITLE_IN], cfiles[CTITLE_IN], title, sizeof(title) - 1); + if (n <= 0) + return; + if (title[n - 1] == '\n') + n--; + title[n] = '\0'; + if (!tox_conference_set_title(tox, c->num, title, n, NULL)) { + weprintf("Failed to set title to \"%s\" for %s\n", title, c->numstr); + return; + } + logmsg("Conference %s > Title > \"%s\"\n", c->numstr, title); } static int @@ -1602,7 +1620,7 @@ confcreate(uint32_t cnum) TAILQ_INSERT_TAIL(&confhead, c, entry); - logmsg("Conference > Created %s\n", c->numstr); + logmsg("Conference %s > Created\n", c->numstr); } static void @@ -2103,13 +2121,14 @@ loop(void) if (FD_ISSET(c->fd[CINVITE], &rfds)) invitefriend(c); if (FD_ISSET(c->fd[CLEAVE], &rfds)) { - logmsg("Conference > leave %s\n", c->numstr); - if (!tox_conference_delete(tox, c->num, NULL)) - weprintf("Failed to leave conference %d\n", c->num); + logmsg("Conference %s > Leave\n", c->numstr); + tox_conference_delete(tox, c->num, NULL); confdestroy(c); } if (FD_ISSET(c->fd[CTEXT_IN], &rfds)) sendconftext(c); + if (FD_ISSET(c->fd[CTITLE_IN], &rfds)) + updatetitle(c); } for (f = TAILQ_FIRST(&friendhead); f; f = ftmp) { -- cgit v1.2.3 From e66d4bff86cb9e4832c98968f1751097ed57ede0 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Thu, 16 Feb 2017 20:50:20 +0100 Subject: Update documentation with group-chats. --- README | 14 +++++++++++++- ratox.1 | 24 ++++++++++++++++++++++++ ratox.c | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) (limited to 'ratox.c') diff --git a/README b/README index 6b5288e..32d3f22 100644 --- a/README +++ b/README @@ -53,6 +53,15 @@ to help explain the semantics of the individual files. | |-- text_in # 'echo yo dude > text_in' to send a text to this friend | `-- text_out # 'tail -f text_out' to dump to stdout any text received | +|-- 00000000 +| |-- members # list of people in the conference +| |-- invite # 'echo 0A734CBA717CEB7883D.... >invite' to invite +| |-- leave # 'echo 1 >leave' to leave the conference +| |-- title_in # 'echo new-title >title_in' to update the conference title +| |-- title_out # contains the current title +| |-- text_in # 'echo blablahumbla >text_in' to message the other conference members +| |-- text_out # contains the messages sent so far in the conference +| |-- id # 'cat id' to show your own ID, you can give this to your friends | |-- name # changing your nick @@ -86,7 +95,7 @@ Features 1 v 1 messaging: Yes File transfer: Yes -Group chat: No +Group chat: Yes Audio: Yes Video: No DNS discovery: No @@ -115,6 +124,9 @@ NOTE: Some of these features are not intended to be developed in ratox itself but rather in external scripts[1] that are built upon ratox. +Group chats do not have file transfers or audio, but will be updated +in the near future. + Examples ======== diff --git a/ratox.1 b/ratox.1 index 07053ef..a59e04f 100644 --- a/ratox.1 +++ b/ratox.1 @@ -58,6 +58,10 @@ Status message slot. Request slot. Send a friend request by piping the Tox ID to \fBin\fR. Incoming requests are listed as FIFOs in \fBout/\fR. Echo \fB1\fR | \fB0\fR to accept | reject them. +.It Ar conf/ +Conference management slot. A conference is created by writing it's title to in. Invites +to conferences are FIFOs in \fBout/\fR. Their name is id_cookie (the cookie is random data). +They behave like request FIFOs. .El .Ss Friend slots Each friend is represented with a folder in the base-directory named after @@ -107,6 +111,26 @@ Send a text message by piping data to this FIFO. .It Ar text_out Contains text messages from the friend. .El +.Ss Conference slots +Each conference is represented with a folder in the directory named after the +8-digit conference number. The files in the conference folder are an interface +for the respective conference. +.Bl -tag -width 13n +.It Ar members +Contains a list of members of the conference. +.It Ar invite +Write the ID of a friend to this FIFO to invite him to the conference. +.It Ar leave +Write to this file to leave the conference. +.It Ar title_in +Write here to change the title of the conference. +.It Ar title_out +Contains the title of the conference. +.It Ar text_in +Echo \fBmessage\fR to send a text message to the conference. +.It Ar text_out +Contains the messages send in the conference so far. +.El .Ss Misc files .Bl -tag -width 13n .It Ar id diff --git a/ratox.c b/ratox.c index 548456b..0e98303 100644 --- a/ratox.c +++ b/ratox.c @@ -124,8 +124,8 @@ static struct file cfiles[] = { [CMEMBERS] = { .type = STATIC, .name = "members", .flags = O_WRONLY | O_TRUNC | O_CREAT }, [CINVITE] = { .type = FIFO, .name = "invite", .flags = O_RDONLY | O_NONBLOCK }, [CLEAVE] = { .type = FIFO, .name = "leave", .flags = O_RDONLY | O_NONBLOCK }, - [CTITLE_OUT] = { .type = STATIC, .name = "title_out", .flags = O_WRONLY | O_TRUNC | O_CREAT }, [CTITLE_IN] = { .type = FIFO, .name = "title_in", .flags = O_RDONLY | O_NONBLOCK }, + [CTITLE_OUT] = { .type = STATIC, .name = "title_out", .flags = O_WRONLY | O_TRUNC | O_CREAT }, [CTEXT_IN] = { .type = FIFO, .name = "text_in", .flags = O_RDONLY | O_NONBLOCK }, [CTEXT_OUT] = { .type = STATIC, .name = "text_out", .flags = O_WRONLY | O_APPEND | O_CREAT }, }; -- cgit v1.2.3 From c567ccfbe4f75beb10a063d3db0999195d141774 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Fri, 17 Feb 2017 12:48:47 +0100 Subject: Add ability to toggle message logging to stdout in config.h. --- config.def.h | 3 +++ ratox.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'ratox.c') diff --git a/config.def.h b/config.def.h index aa95a0e..e98c1ed 100644 --- a/config.def.h +++ b/config.def.h @@ -20,6 +20,9 @@ #define VIDEOHEIGHT 720 #define VIDEOBITRATE 2500 +static int friendmsg_log = 1; +static int confmsg_log = 0; + static char *savefile = ".ratox.tox"; static int encryptsavefile = 0; diff --git a/ratox.c b/ratox.c index 0e98303..0e24908 100644 --- a/ratox.c +++ b/ratox.c @@ -555,6 +555,8 @@ cbconfmessage(Tox *m, uint32_t cnum, uint32_t pnum, TOX_MESSAGE_TYPE type, const } namt[tox_conference_peer_get_name_size(tox, c->num, pnum, NULL)] = '\0'; dprintf(c->fd[CTEXT_OUT], "%s <%s> %s\n", buft, namt, msg); + if (confmsg_log) + logmsg("%s <%s> %s\n", buft, namt, msg); break; } } @@ -744,7 +746,8 @@ cbfriendmessage(Tox *m, uint32_t frnum, TOX_MESSAGE_TYPE type, const uint8_t *da t = time(NULL); strftime(buft, sizeof(buft), "%F %R", localtime(&t)); dprintf(f->fd[FTEXT_OUT], "%s %s\n", buft, msg); - logmsg(": %s > %s\n", f->name, msg); + if (friendmsg_log) + logmsg(": %s > %s\n", f->name, msg); break; } } -- cgit v1.2.3 From 52f5a24779eb885232bebe6652bc212ed8dd286b Mon Sep 17 00:00:00 2001 From: pranomostro Date: Fri, 17 Feb 2017 19:09:17 +0100 Subject: Fix warnings. The title of a conference is apparently not known immediately after joining the conference, so don't print a warning in confcreate(), just wait for the cbconftitle() callback immediately afterwards. Friends that are not online can't be invited to conferences, logmsg' in that case. Print the name of the conference before messages in cbconfmessage(). --- ratox.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 0e24908..2fb9e5b 100644 --- a/ratox.c +++ b/ratox.c @@ -531,7 +531,7 @@ cbconfinvite(Tox *m, uint32_t frnum, TOX_CONFERENCE_TYPE type, const uint8_t *co TAILQ_INSERT_TAIL(&invhead, inv, entry); - logmsg("Conference > Invite: %s\n", inv->fifoname); + logmsg("Invite > %s\n", inv->fifoname); } static void @@ -556,7 +556,7 @@ cbconfmessage(Tox *m, uint32_t cnum, uint32_t pnum, TOX_MESSAGE_TYPE type, const namt[tox_conference_peer_get_name_size(tox, c->num, pnum, NULL)] = '\0'; dprintf(c->fd[CTEXT_OUT], "%s <%s> %s\n", buft, namt, msg); if (confmsg_log) - logmsg("%s <%s> %s\n", buft, namt, msg); + logmsg("%s: %s <%s> %s\n", c->numstr, buft, namt, msg); break; } } @@ -1111,13 +1111,17 @@ invitefriend(struct conference *c) if (!memcmp(buf, f->idstr, sizeof(f->idstr))) break; if (!f) { - logmsg("Conference > no friend with id %s found\n", buf); + logmsg("Conference %s > no friend with id %s found\n", c->numstr, buf); + return; + } + if (tox_friend_get_connection_status(tox, f->num, NULL) == TOX_CONNECTION_NONE) { + logmsg("Conference %s > %s not online, can't be invited\n", c->numstr, buf); return; } if (!tox_conference_invite(tox, f->num, c->num, NULL)) weprintf("Failed to invite %s\n", buf); else - logmsg("Conference > Invite %s\n", buf); + logmsg("Conference %s > Invite %s\n", c->numstr, buf); } static void @@ -1611,15 +1615,19 @@ confcreate(uint32_t cnum) writemembers(c); + /* No warning is printed here in the case of an error + * because this always fails when joining after an invite, + * but cbconftitle() is called in the next iteration afterwards, + * so it doesn't matter after all. + */ + i = tox_conference_get_title_size(tox, c->num, &err); - if (err != TOX_ERR_CONFERENCE_TITLE_OK) { - weprintf("Unable to obtain conference title for %d\n", cnum); - } else { - tox_conference_get_title(tox, c->num, title, NULL); - title[i] = '\0'; - ftruncate(c->fd[CTITLE_OUT], 0); - dprintf(c->fd[CTITLE_OUT], "%s\n", title); - } + if (err != TOX_ERR_CONFERENCE_TITLE_OK) + i = 0; + tox_conference_get_title(tox, c->num, title, NULL); + title[i] = '\0'; + ftruncate(c->fd[CTITLE_OUT], 0); + dprintf(c->fd[CTITLE_OUT], "%s\n", title); TAILQ_INSERT_TAIL(&confhead, c, entry); -- cgit v1.2.3 From 0cf60b85c697629f834ea20c7c22011359bb3850 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Fri, 3 Mar 2017 13:31:50 +0100 Subject: Small fixes. Update type of cookie. Unify error messages. Delete invite-fifo if joining fails. --- ratox.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 2fb9e5b..d7d683d 100644 --- a/ratox.c +++ b/ratox.c @@ -192,7 +192,7 @@ struct request { struct invite { char *fifoname; - char *cookie; + uint8_t *cookie; size_t cookielen; uint32_t inviter; int fd; @@ -508,13 +508,13 @@ cbconfinvite(Tox *m, uint32_t frnum, TOX_CONFERENCE_TYPE type, const uint8_t *co if (!inv->cookie) eprintf("malloc:"); + memcpy(inv->cookie, cookie, clen); + namelen = 2 * TOX_PUBLIC_KEY_SIZE + 1 + 2 * clen + 2; inv->fifoname = malloc(namelen); if (!inv->fifoname) eprintf("malloc:"); - memcpy(inv->cookie, cookie, clen); - i = 0; id2str(id, inv->fifoname); i += 2 * TOX_PUBLIC_KEY_SIZE; @@ -1137,7 +1137,7 @@ sendconftext(struct conference *c) n--; if (!tox_conference_send_message(tox, c->num, TOX_MESSAGE_TYPE_NORMAL, buf, n, NULL)) - weprintf("Failed to send message to conference %s, error %d\n", c->numstr); + weprintf("%s: Message : Failed to send, error %d\n", c->numstr); } static void @@ -1153,10 +1153,10 @@ updatetitle(struct conference *c) n--; title[n] = '\0'; if (!tox_conference_set_title(tox, c->num, title, n, NULL)) { - weprintf("Failed to set title to \"%s\" for %s\n", title, c->numstr); + weprintf("%s : Title : Failed to set to \"%s\"\n", title, c->numstr); return; } - logmsg("Conference %s > Title > \"%s\"\n", c->numstr, title); + logmsg("Conference %s > Title > %s\n", c->numstr, title); } static int @@ -2112,12 +2112,10 @@ loop(void) else if (ch == '1'){ cnum = tox_conference_join(tox, inv->inviter, (uint8_t *)inv->cookie, inv->cookielen, NULL); - if(cnum == UINT32_MAX) { + if(cnum == UINT32_MAX) weprintf("Failed to join conference\n"); - fiforeset(gslots[CONF].fd[OUT], &inv->fd, invfifo); - continue; - } - confcreate(cnum); + else + confcreate(cnum); } unlinkat(gslots[CONF].fd[OUT], inv->fifoname, 0); close(inv->fd); -- cgit v1.2.3 From e8f046c0e616a7a0b10d1bb85abe887c1a374179 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Fri, 3 Mar 2017 15:12:01 +0100 Subject: Now aborting when invited to audio conferences. --- ratox.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index d7d683d..27487de 100644 --- a/ratox.c +++ b/ratox.c @@ -492,8 +492,13 @@ cbconfinvite(Tox *m, uint32_t frnum, TOX_CONFERENCE_TYPE type, const uint8_t *co struct invite *inv; uint8_t id[TOX_PUBLIC_KEY_SIZE]; + if(type != TOX_CONFERENCE_TYPE_TEXT) { + weprintf(": %d : Only text conference supported at the moment\n"); + return; + } + if (!tox_friend_get_public_key(tox, frnum, id, NULL)) { - weprintf(": %d: Key: Failed to get for invite\n", frnum); + weprintf(": %d : Key: Failed to get for invite\n", frnum); return; } -- cgit v1.2.3