commit 97fed1eb9080dbcb5e14bd4e70cf92d3afd40a50
parent e75b991923cd538608e4f81f8b8b489a6aa3a21c
Author: FRIGN <dev@frign.de>
Date: Mon, 29 Sep 2014 21:48:17 +0200
Define FRIENDNAME-Macro for repetitive idiom
and fill up the missing cases.
Diffstat:
M | ratox.c | | | 50 | ++++++++++++++++++++------------------------------ |
1 file changed, 20 insertions(+), 30 deletions(-)
diff --git a/ratox.c b/ratox.c
@@ -121,6 +121,8 @@ static struct file ffiles[] = {
[FFILE_PENDING] = { .type = STATIC, .name = "file_pending", .flags = O_WRONLY | O_TRUNC | O_CREAT },
};
+#define FRIENDNAME (f->name[0] == '\0' ? "Anonymous" : f->name)
+
enum {
TRANSFER_NONE,
TRANSFER_INITIATED,
@@ -322,8 +324,7 @@ cbfriendmessage(Tox *m, int32_t frnum, const uint8_t *data, uint16_t len, void *
t = time(NULL);
strftime(buft, sizeof(buft), "%F %R", localtime(&t));
dprintf(f->fd[FTEXT_OUT], "%s %s\n", buft, msg);
- printout(": %s > %s\n",
- f->name[0] == '\0' ? "Anonymous" : f->name, msg);
+ printout(": %s > %s\n", FRIENDNAME, msg);
break;
}
}
@@ -376,8 +377,7 @@ cbnamechange(Tox *m, int32_t frnum, const uint8_t *data, uint16_t len, void *use
dprintf(f->fd[FNAME], "%s\n", name);
if (memcmp(f->name, name, len + 1) == 0)
break;
- printout(": %s : Name > %s\n", f->name[0] == '\0' ?
- "Anonymous" : f->name, name);
+ printout(": %s : Name > %s\n", FRIENDNAME, name);
memcpy(f->name, name, len + 1);
break;
}
@@ -398,8 +398,7 @@ cbstatusmessage(Tox *m, int32_t frnum, const uint8_t *data, uint16_t len, void *
if (f->num == frnum) {
ftruncate(f->fd[FSTATUS], 0);
dprintf(f->fd[FSTATUS], "%s\n", status);
- printout(": %s : Status > %s\n",
- f->name[0] == '\0' ? "Anonymous" : f->name, status);
+ printout(": %s : Status > %s\n", FRIENDNAME, status);
break;
}
}
@@ -419,9 +418,7 @@ cbuserstatus(Tox *m, int32_t frnum, uint8_t status, void *udata)
TAILQ_FOREACH(f, &friendhead, entry) {
if (f->num == frnum) {
- printout(": %s : State > %s\n",
- f->name[0] == '\0' ? "Anonymous" : f->name,
- statusstr[status]);
+ printout(": %s : State > %s\n", FRIENDNAME, statusstr[status]);
break;
}
}
@@ -443,7 +440,7 @@ cbfilecontrol(Tox *m, int32_t frnum, uint8_t rec_sen, uint8_t fnum, uint8_t ctrl
case TOX_FILECONTROL_ACCEPT:
if (rec_sen == 1) {
if (f->tx.state == TRANSFER_PAUSED) {
- printout(": %s : Tx > Resumed\n", f->name);
+ printout(": %s : Tx > Resumed\n", FRIENDNAME);
f->tx.state = TRANSFER_INPROGRESS;
} else {
f->tx.fnum = fnum;
@@ -454,38 +451,38 @@ cbfilecontrol(Tox *m, int32_t frnum, uint8_t rec_sen, uint8_t fnum, uint8_t ctrl
f->tx.n = 0;
f->tx.pendingbuf = 0;
f->tx.state = TRANSFER_INPROGRESS;
- printout(": %s : Tx > In Progress\n", f->name);
+ printout(": %s : Tx > In Progress\n", FRIENDNAME);
}
}
break;
case TOX_FILECONTROL_PAUSE:
if (rec_sen == 1) {
if (f->tx.state == TRANSFER_INPROGRESS) {
- printout(": %s : Tx > Paused\n", f->name);
+ printout(": %s : Tx > Paused\n", FRIENDNAME);
f->tx.state = TRANSFER_PAUSED;
}
}
break;
case TOX_FILECONTROL_KILL:
if (rec_sen == 1) {
- printout(": %s : Tx > Rejected\n", f->name);
+ printout(": %s : Tx > Rejected\n", FRIENDNAME);
f->tx.state = TRANSFER_NONE;
free(f->tx.buf);
f->tx.buf = NULL;
fiforeset(f->dirfd, &f->fd[FFILE_IN], ffiles[FFILE_IN]);
} else {
- printout(": %s : Rx > Cancelled by Sender\n", f->name);
+ printout(": %s : Rx > Cancelled by Sender\n", FRIENDNAME);
cancelrxtransfer(f);
}
break;
case TOX_FILECONTROL_FINISHED:
if (rec_sen == 1) {
- printout(": %s : Tx > Complete\n", f->name);
+ printout(": %s : Tx > Complete\n", FRIENDNAME);
f->tx.state = TRANSFER_NONE;
free(f->tx.buf);
f->tx.buf = NULL;
} else {
- printout(": %s : Rx > Complete\n", f->name);
+ printout(": %s : Rx > Complete\n", FRIENDNAME);
if (tox_file_send_control(tox, f->num, 1, 0, TOX_FILECONTROL_FINISHED, NULL, 0) < 0)
weprintf("Failed to signal file completion to the sender\n");
if (f->fd[FFILE_OUT] != -1) {
@@ -517,8 +514,7 @@ cbfilesendreq(Tox *m, int32_t frnum, uint8_t fnum, uint64_t fsz,
/* We only support a single transfer at a time */
if (f->rxstate == TRANSFER_INPROGRESS) {
- printout(": %s : Rx > Rejected, already one in progress\n",
- f->name[0] == '\0' ? "Anonymous" : f->name);
+ printout(": %s : Rx > Rejected, already one in progress\n", FRIENDNAME);
if (tox_file_send_control(tox, f->num, 1, fnum, TOX_FILECONTROL_KILL, NULL, 0) < 0)
weprintf("Failed to kill new Rx transfer\n");
return;
@@ -527,8 +523,7 @@ cbfilesendreq(Tox *m, int32_t frnum, uint8_t fnum, uint64_t fsz,
ftruncate(f->fd[FFILE_PENDING], 0);
dprintf(f->fd[FFILE_PENDING], "%d\n", 1);
f->rxstate = TRANSFER_INPROGRESS;
- printout(": %s : Rx > Pending\n",
- f->name[0] == '\0' ? "Anonymous" : f->name);
+ printout(": %s : Rx > Pending\n", FRIENDNAME);
}
static void
@@ -562,8 +557,7 @@ static void
canceltxtransfer(struct friend *f)
{
if (f->tx.state != TRANSFER_NONE) {
- printout(": %s : Tx > Cancelling\n",
- f->name[0] == '\0' ? "Anonymous" : f->name);
+ printout(": %s : Tx > Cancelling\n", FRIENDNAME);
if (tox_file_send_control(tox, f->num, 0, 0, TOX_FILECONTROL_KILL, NULL, 0) < 0)
weprintf("Failed to kill Tx transfer\n");
f->tx.state = TRANSFER_NONE;
@@ -577,8 +571,7 @@ static void
cancelrxtransfer(struct friend *f)
{
if (f->rxstate == TRANSFER_INPROGRESS) {
- printout(": %s : Rx > Cancelling\n",
- f->name[0] == '\0' ? "Anonymous" : f->name);
+ printout(": %s : Rx > Cancelling\n", FRIENDNAME);
if (tox_file_send_control(tox, f->num, 1, 0, TOX_FILECONTROL_KILL, NULL, 0) < 0)
weprintf("Failed to kill Rx transfer\n");
if (f->fd[FFILE_OUT] != -1) {
@@ -652,8 +645,7 @@ removefriend(struct friend *f)
return;
tox_del_friend(tox, f->num);
datasave();
- printout(": %s > Removed\n",
- f->name[0] == '\0' ? "Anonymous" : f->name);
+ printout(": %s > Removed\n", FRIENDNAME);
frienddestroy(f);
}
@@ -1217,8 +1209,7 @@ loop(void)
weprintf("Failed to accept transfer from receiver\n");
cancelrxtransfer(f);
} else {
- printout(": %s : Rx > Accepted\n",
- f->name[0] == '\0' ? "Anonymous" : f->name);
+ printout(": %s : Rx > Accepted\n", FRIENDNAME);
}
}
}
@@ -1273,8 +1264,7 @@ loop(void)
toilet, sizeof(toilet)));
} else {
f->tx.state = TRANSFER_INITIATED;
- printout(": %s : Tx > Initiated\n",
- f->name[0] == '\0' ? "Anonymous" : f->name);
+ printout(": %s : Tx > Initiated\n", FRIENDNAME);
}
break;
case TRANSFER_INPROGRESS: