diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | config.mk | 2 | ||||
-rw-r--r-- | ratox.c | 73 | ||||
-rw-r--r-- | tests/README | 15 | ||||
-rw-r--r-- | tests/common | 77 | ||||
-rwxr-xr-x | tests/test-ratox | 15 |
6 files changed, 62 insertions, 124 deletions
@@ -63,8 +63,4 @@ clean: @echo cleaning @rm -f $(BIN) $(OBJ) $(LIB) util.a -check: all - @echo testing - @cd tests; sh test-ratox - .PHONY: all binlib bin install uninstall clean check @@ -1,5 +1,5 @@ # ratox version -VERSION = 0.2.1 +VERSION = 0.3 # paths PREFIX = /usr/local @@ -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 *); @@ -531,6 +532,33 @@ sendfriendcalldata(struct friend *f) } 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) { struct friend *f; @@ -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); @@ -1426,6 +1453,22 @@ frienddestroy(struct friend *f) } static void +confdestroy(struct conference *c) +{ + size_t i; + + for (i = 0; i <LEN(cfiles); i++) { + if(c->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) { size_t sz; @@ -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); diff --git a/tests/README b/tests/README deleted file mode 100644 index e491c53..0000000 --- a/tests/README +++ /dev/null @@ -1,15 +0,0 @@ -ratox[0] text suite. - -0. move this folder in the ratox source dir -1. build ratox -2. run your tests - -WARNING: spawing a test creates two throw-away IDs, and opens two -connections by default. If starting too much test, it could make it to -the point your router might not be able to forward traffic correctly to -the DHT, rendering your users incapable of seeing each others online. - -In case it happens, simply wait for the stale connections to close -themselves, or reboot your computer. - -[0] http://git.z3bra.org/ratox/log.html diff --git a/tests/common b/tests/common deleted file mode 100644 index 3dd9628..0000000 --- a/tests/common +++ /dev/null @@ -1,77 +0,0 @@ -BIN="$(cd ..; pwd)/ratox" -test -x $BIN || exit 1 - -echolor() { - printf '[1;3%dm%s[0m\n' "$1" "$2" -} - -cleanup() { - echo ":: cleaning" - kill $(pgrep -f 'abduco -n test-u1') - kill $(pgrep -f 'abduco -n test-u2') - rm -rf u1 u2 -} - -trap cleanup INT - -spawn_users() { - for u in u1 u2; do - echo ":: creating user $u" - mkdir -p $u - abduco -n test-$u sh -c "cd $u;$BIN 2>&1|tee LOG" - done - sleep 1 -} - -add_friends() { - echo ":: send u2 a friend request from u1" - id1=$(cut -b-64 < u1/id) - id2=$(cut -b-64 < u2/id) - cat u2/id > u1/request/in - while [ ! -p u2/request/out/$id1 ]; do sleep 1; done - echo ":: accepting request from $id1" - echo 1 > u2/request/out/$id1 - while [ ! -d u2/$id1 ]; do sleep 1; done - echo ":: u1: waiting for u2 to come online" - while [ $(cat u1/$id2/online) -eq 0 ]; do sleep 1; done -} - -change_name() { - NAME=$(dd bs=64 count=1 if=/dev/urandom 2>/dev/null|tr -cd '\11\12\15\40-\176\n'|sed 's/$/\n/') - id1=$(cut -b-64 < u1/id) - echo ":: changing name of u1" - echo "$NAME" >u1/name/in - while ! grep -Fq -- "$NAME" u2/$id1/name; do sleep 1; done -} - -change_status() { - STATUS=$(dd bs=128 count=1 if=/dev/urandom 2>/dev/null|tr -cd '\11\12\15\40-\176\n'|sed 's/$/\n/') - id1=$(cut -b-64 < u1/id) - echo ":: changing status of u1" - echo "$STATUS" >u1/name/in - while ! grep -Fq -- "$STATUS" u2/$id1/name; do sleep 1; done -} - -send_text() { - RND=$(tr -cd 'A-F0-9' </dev/urandom|fold -w16|head -n1) - id1=$(cut -b-64 < u1/id) - id2=$(cut -b-64 < u2/id) - echo ":: sending text to u2" - echo "$RND" > u1/$id2/text_in - while ! grep -q -- "$RND" u2/$id1/text_out; do sleep 1; done -} - -send_file() { - TMP1=$(mktemp) - TMP2=$(mktemp) - </dev/urandom base64 | dd bs=1K count=2048 of=$TMP1 2>/dev/null - id1=$(cut -b-64 < u1/id) - id2=$(cut -b-64 < u2/id) - echo ":: u1: sending file $TMP1" - cat $TMP1 > u1/$id2/file_in & - while [ $(wc -c <u2/$id1/file_pending) -eq 0 ]; do sleep 1; done - echo ":: u2: saving file to $TMP2" - cat u2/$id1/file_out > $TMP2 - echo ":: verifying $TMP1 and $TMP2" - sha1sum $TMP1 | sed "s,$TMP1,$TMP2," | sha1sum -c -} diff --git a/tests/test-ratox b/tests/test-ratox deleted file mode 100755 index b478ef7..0000000 --- a/tests/test-ratox +++ /dev/null @@ -1,15 +0,0 @@ -. ./common - -spawn_users -add_friends -for i in $(seq 1 16); do - change_name - change_status - send_text - send_file -done - -echo :: $(basename $0) - $(echolor 2 OK) - -cleanup -exit 0 |