about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2007-02-24 22:30:12 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2007-02-24 22:30:12 +0000
commit372cec7b53ce0959ba5756e1e51f1f15793a3663 (patch)
tree8ee16652f2e514ecc88748af273c0add94e084de
parent02733b16ecd03a65fd76c551b06df879b45d6bb6 (diff)
downloadbtpd-372cec7b53ce0959ba5756e1e51f1f15793a3663.tar.gz
btpd-372cec7b53ce0959ba5756e1e51f1f15793a3663.zip
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.

-rw-r--r--btpd/cli_if.c42
1 files 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)