diff options
| author | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-09-13 07:02:07 +0000 |
|---|---|---|
| committer | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-09-13 07:02:07 +0000 |
| commit | 86754d7d53b59ce52de51a32f865d4916c119bdb (patch) | |
| tree | f017a8199a94e675fb50f55876119fe9e9d1944b /cli/btinfo.c | |
| parent | 763cbbb59f40bdfb2478e58a685acfc262876af6 (diff) | |
| download | btpd-86754d7d53b59ce52de51a32f865d4916c119bdb.tar.gz btpd-86754d7d53b59ce52de51a32f865d4916c119bdb.zip | |
btpd now has a library of torrents indexed by number and info hash.
The add and del commands adds or removes torrents from this library. The start and stop commands are used to active or deactivate torrents. Also, a mechanism for qeurying data on torrents has been added. It's only used by the btcli list and stat commands yet though. btcli has been split into different files for each command. Both btpd and btcli now use misc/btpd_if.h for all ipc definitions. Misc changes: - struct metainfo is gone. Use the new mi_* functions. - Add printf format type checking where appropriate.
Diffstat (limited to 'cli/btinfo.c')
| -rw-r--r-- | cli/btinfo.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/cli/btinfo.c b/cli/btinfo.c index f451c85..cfd1991 100644 --- a/cli/btinfo.c +++ b/cli/btinfo.c @@ -8,6 +8,7 @@ #include <stdlib.h> #include "metainfo.h" +#include "subr.h" static void usage() @@ -21,11 +22,38 @@ static struct option longopts[] = { { NULL, 0, NULL, 0 } }; +static void +print_metainfo(const char *mi) +{ + uint8_t hash[20]; + char hex[SHAHEXSIZE]; + char *name = mi_name(mi); + unsigned nfiles = mi_nfiles(mi); + struct mi_file *files = mi_files(mi); + struct mi_announce *ann = mi_announce(mi); + for (int i = 0; i < ann->ntiers; i++) + for (int j = 0; j < ann->tiers[i].nurls; j++) + printf("%d: %s\n", i, ann->tiers[i].urls[j]); + printf("\n"); + mi_free_announce(ann); + mi_info_hash(mi, hash); + bin2hex(hash, hex, 20); + printf("name: %s\n", name); + printf("info hash: %s\n", hex); + printf("length: %jd\n", (intmax_t)mi_total_length(mi)); + printf("piece length: %jd\n", (intmax_t)mi_piece_length(mi)); + printf("files: %u\n", nfiles); + for (unsigned i = 0; i < nfiles; i++) + printf("%s(%jd)\n", files[i].path, (intmax_t)files[i].length); + free(name); +} + int main(int argc, char **argv) { int ch; + srandom(time(NULL)); while ((ch = getopt_long(argc, argv, "", longopts, NULL)) != -1) usage(); @@ -36,13 +64,12 @@ main(int argc, char **argv) usage(); while (argc > 0) { - struct metainfo *mi; + char *mi = NULL; - if ((errno = load_metainfo(*argv, -1, 1, &mi)) != 0) - err(1, "load_metainfo: %s", *argv); + if ((mi = mi_load(*argv, NULL)) == NULL) + err(1, "mi_load: %s", *argv); print_metainfo(mi); - clear_metainfo(mi); free(mi); argc--; |