summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--btpd/cli_if.c14
-rw-r--r--btpd/tlib.c18
-rw-r--r--btpd/tlib.h4
3 files changed, 22 insertions, 14 deletions
diff --git a/btpd/cli_if.c b/btpd/cli_if.c
index 7069977..dd5ddcb 100644
--- a/btpd/cli_if.c
+++ b/btpd/cli_if.c
@@ -189,16 +189,16 @@ cmd_tget(struct cli *cli, int argc, const char *args)
     p = benc_dget_any(args, "from");
     if (benc_isint(p)) {
         enum ipc_twc from = benc_int(p, NULL);
-        struct tlib *tlv[tlib_count()];
-        tlib_put_all(tlv);
-        for (int i = 0; i < sizeof(tlv) / sizeof(tlv[0]); i++) {
-            if (!torrent_haunting(tlv[i]) && (
+        struct htbl_iter it;
+        struct tlib *tl;
+        for (tl = tlib_iter_first(&it); tl != NULL; tl = tlib_iter_next(&it)) {
+            if (!torrent_haunting(tl) && (
                     from == IPC_TWC_ALL ||
-                    (!torrent_active(tlv[i]) && from == IPC_TWC_INACTIVE) ||
-                    (torrent_active(tlv[i]) && from == IPC_TWC_ACTIVE))) {
+                    (!torrent_active(tl) && from == IPC_TWC_INACTIVE) ||
+                    (torrent_active(tl) && from == IPC_TWC_ACTIVE))) {
                 iobuf_swrite(&iob, "l");
                 for (int k = 0; k < nkeys; k++)
-                    write_ans(&iob, tlv[i], opts[k]);
+                    write_ans(&iob, tl, opts[k]);
                 iobuf_swrite(&iob, "e");
             }
         }
diff --git a/btpd/tlib.c b/btpd/tlib.c
index 963931b..12f786e 100644
--- a/btpd/tlib.c
+++ b/btpd/tlib.c
@@ -30,6 +30,18 @@ tlib_by_hash(const uint8_t *hash)
     return hashtbl_find(m_hashtbl, hash);
 }
 
+struct tlib *
+tlib_iter_first(struct htbl_iter *it)
+{
+    return numtbl_iter_first(m_numtbl, it);
+}
+
+struct tlib *
+tlib_iter_next(struct htbl_iter *it)
+{
+    return numtbl_iter_next(it);
+}
+
 void
 tlib_kill(struct tlib *tl)
 {
@@ -296,12 +308,6 @@ id_hash(const void *k)
 }
 
 void
-tlib_put_all(struct tlib **v)
-{
-    hashtbl_tov(m_hashtbl, v);
-}
-
-void
 tlib_init(void)
 {
     DIR *dirp;
diff --git a/btpd/tlib.h b/btpd/tlib.h
index 51eacbb..c0b3aca 100644
--- a/btpd/tlib.h
+++ b/btpd/tlib.h
@@ -22,7 +22,9 @@ struct file_time_size {
 };
 
 void tlib_init(void);
-void tlib_put_all(struct tlib **v);
+
+struct tlib *tlib_iter_first(struct htbl_iter *it);
+struct tlib *tlib_iter_next(struct htbl_iter *it);
 
 struct tlib *tlib_add(const uint8_t *hash, const char *mi, size_t mi_size,
     const char *content, char *name);