summaryrefslogtreecommitdiff
path: root/ratox.c
diff options
context:
space:
mode:
authorFRIGN <dev@frign.de>2014-10-08 23:42:06 +0200
committersin <sin@2f30.org>2014-10-09 00:41:47 +0100
commit6ec82b9835037c4dc7938c434f667c4b5b8d8401 (patch)
tree017eca91057983fc77d6bc6119ad37139d8ea3b5 /ratox.c
parentaaffdbe1c2b529827994aa269ba555fe8a4137a5 (diff)
Fix request- and friend-management
When you got a request, but not accepted it via request/out/... and instead sent a request yourself, it would not remove the FIFO. This patch fixes this behaviour by iterating through the request- list and removing the FIFO if it's still existing. Additionally, actually make it possible to reject requests and re-add your friends later by managing the internal tox-state properly.
Diffstat (limited to 'ratox.c')
-rw-r--r--ratox.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/ratox.c b/ratox.c
index e30115e..2592ec3 100644
--- a/ratox.c
+++ b/ratox.c
@@ -630,6 +630,7 @@ static void
cbconnstatus(Tox *m, int32_t frnum, uint8_t status, void *udata)
{
struct friend *f;
+ struct request *req, *rtmp;
char name[TOX_MAX_NAME_LENGTH + 1];
int r;
@@ -650,11 +651,22 @@ cbconnstatus(Tox *m, int32_t frnum, uint8_t status, void *udata)
ftruncate(f->fd[FONLINE], 0);
lseek(f->fd[FONLINE], 0, SEEK_SET);
dprintf(f->fd[FONLINE], "%d\n", status);
- return;
+ break;
}
}
- friendcreate(frnum);
+ /* Remove the pending request-FIFO if it exists */
+ for (req = TAILQ_FIRST(&reqhead); req; req = rtmp) {
+ rtmp = TAILQ_NEXT(req, entry);
+
+ if (memcmp(f->id, req->id, TOX_CLIENT_ID_SIZE))
+ continue;
+ unlinkat(gslots[REQUEST].fd[OUT], req->idstr, 0);
+ close(req->fd);
+ TAILQ_REMOVE(&reqhead, req, entry);
+ free(req->msg);
+ free(req);
+ }
}
static void
@@ -1544,6 +1556,7 @@ out:
dprintf(gslots[REQUEST].fd[ERR], "%s\n", reqerr[-r]);
return;
}
+ friendcreate(r);
datasave();
printout("Request > Sent\n");
}
@@ -1795,11 +1808,13 @@ loop(void)
continue;
if (c != '0' && c != '1')
continue;
+ r = tox_add_friend_norequest(tox, req->id);
if (c == '1') {
- tox_add_friend_norequest(tox, req->id);
+ friendcreate(r);
printout("Request : %s > Accepted\n", req->idstr);
datasave();
} else {
+ tox_del_friend(tox, r);
printout("Request : %s > Rejected\n", req->idstr);
}
unlinkat(gslots[REQUEST].fd[OUT], req->idstr, 0);