From 372cec7b53ce0959ba5756e1e51f1f15793a3663 Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Sat, 24 Feb 2007 22:30:12 +0000 Subject: [PATCH] Some clean up of the values sent for tget answers. Send values that makes sense instead of errors. Fix wrong type for IPC_TVAL_CSIZE, reported by Arnaud Bergeron. --- btpd/cli_if.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/btpd/cli_if.c b/btpd/cli_if.c index 017cbad..3765cf0 100644 --- a/btpd/cli_if.c +++ b/btpd/cli_if.c @@ -58,18 +58,11 @@ write_ans(struct io_buffer *iob, struct tlib *tl, enum ipc_tval val) enum ipc_tstate ts = IPC_TSTATE_INACTIVE; switch (val) { case IPC_TVAL_CGOT: - if (tl->tp == NULL) - buf_print(iob, "i%dei%llde", IPC_TYPE_NUM, tl->content_have); - else - buf_print(iob, "i%dei%llde", IPC_TYPE_NUM, - (long long)cm_content(tl->tp)); + buf_print(iob, "i%dei%llde", IPC_TYPE_NUM, + tl->tp == NULL ? tl->content_have : (long long)cm_content(tl->tp)); return; case IPC_TVAL_CSIZE: - if (tl->tp == NULL) - buf_print(iob, "i%dei%llde", IPC_TYPE_ERR, tl->content_size); - else - buf_print(iob, "i%dei%llde", IPC_TYPE_NUM, - (long long)tl->tp->total_length); + buf_print(iob, "i%dei%llde", IPC_TYPE_NUM, tl->content_size); return; case IPC_TVAL_PCCOUNT: if (tl->tp == NULL) @@ -87,7 +80,7 @@ write_ans(struct io_buffer *iob, struct tlib *tl, enum ipc_tval val) return; case IPC_TVAL_PCSEEN: if (tl->tp == NULL) - buf_print(iob, "i%dei%de", IPC_TYPE_ERR, IPC_ETINACTIVE); + buf_print(iob, "i%dei%de", IPC_TYPE_NUM, 0); else { unsigned long pcseen = 0; for (unsigned long i = 0; i < tl->tp->npieces; i++) @@ -97,31 +90,20 @@ write_ans(struct io_buffer *iob, struct tlib *tl, enum ipc_tval val) } return; case IPC_TVAL_RATEDWN: - if (tl->tp == NULL) - buf_print(iob, "i%dei%de", IPC_TYPE_ERR, IPC_ETINACTIVE); - else - buf_print(iob, "i%dei%lue", IPC_TYPE_NUM, - tl->tp->net->rate_dwn / RATEHISTORY); + buf_print(iob, "i%dei%lue", IPC_TYPE_NUM, + tl->tp == NULL ? 0UL : tl->tp->net->rate_dwn / RATEHISTORY); return; case IPC_TVAL_RATEUP: - if (tl->tp == NULL) - buf_print(iob, "i%dei%de", IPC_TYPE_ERR, IPC_ETINACTIVE); - else - buf_print(iob, "i%dei%lue", IPC_TYPE_NUM, - tl->tp->net->rate_up / RATEHISTORY); + buf_print(iob, "i%dei%lue", IPC_TYPE_NUM, + tl->tp == NULL ? 0UL : tl->tp->net->rate_up / RATEHISTORY); return; case IPC_TVAL_SESSDWN: - if (tl->tp == NULL) - buf_print(iob, "i%dei%de", IPC_TYPE_ERR, IPC_ETINACTIVE); - else - buf_print(iob, "i%dei%llde", IPC_TYPE_NUM, - tl->tp->net->downloaded); + buf_print(iob, "i%dei%llde", IPC_TYPE_NUM, + tl->tp == NULL ? 0LL : tl->tp->net->downloaded); return; case IPC_TVAL_SESSUP: - if (tl->tp == NULL) - buf_print(iob, "i%dei%de", IPC_TYPE_ERR, IPC_ETINACTIVE); - else - buf_print(iob, "i%dei%llde", IPC_TYPE_NUM, tl->tp->net->uploaded); + buf_print(iob, "i%dei%llde", IPC_TYPE_NUM, + tl->tp == NULL ? 0LL : tl->tp->net->uploaded); return; case IPC_TVAL_DIR: if (tl->dir != NULL)