diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-04-24 23:50:08 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-04-24 23:50:08 +0200 |
commit | 0baa5c7cbee79f3c36eba8a097e091ffd023e65d (patch) | |
tree | efd45f75ce5126f80a248d18e810894ea6359182 /sys | |
parent | b7b734bd5987b34bada728e103b0732153cbb784 (diff) |
ip/torrent: alphabetically order dictionary keys when producing torrent
Diffstat (limited to 'sys')
-rw-r--r-- | sys/src/cmd/ip/torrent.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/sys/src/cmd/ip/torrent.c b/sys/src/cmd/ip/torrent.c index d144387b7..b8034e20a 100644 --- a/sys/src/cmd/ip/torrent.c +++ b/sys/src/cmd/ip/torrent.c @@ -850,8 +850,11 @@ mktorrent(int fd, Dict *alist, Dict *wlist) if(npieces <= 8*1024 || blocksize >= 2*1024*1024) break; } - print("d"); - print("8:announce%ld:%s", strlen(alist->str), alist->str); + + /* + * keys in dictionaries have to be ordered alphabetically + */ + print("d8:announce%ld:%s", strlen(alist->str), alist->str); if(alist->next){ print("13:announce-listl"); print("l%ld:%se", strlen(alist->str), alist->str); @@ -859,19 +862,10 @@ mktorrent(int fd, Dict *alist, Dict *wlist) print("l%ld:%se", strlen(alist->str), alist->str); print("e"); } - if(wlist){ - if(wlist->next){ - print("8:url-listl"); - for(; wlist; wlist = wlist->next) - print("%ld:%s", strlen(wlist->str), wlist->str); - print("e"); - } else - print("8:url-list%ld:%s", strlen(wlist->str), wlist->str); - } - print("4:info"); - print("d"); - print("4:name%ld:%s", strlen(d->name), d->name); + + print("4:infod"); print("6:lengthi%llde", d->length); + print("4:name%ld:%s", strlen(d->name), d->name); print("12:piece lengthi%de", blocksize); print("6:pieces%d:", npieces*sizeof(h)); free(d); @@ -884,13 +878,24 @@ mktorrent(int fd, Dict *alist, Dict *wlist) } npieces--; } - free(b); if(npieces){ werrstr("read failed: %r"); return -1; } + free(b); print("e"); + + if(wlist){ + if(wlist->next){ + print("8:url-listl"); + for(; wlist; wlist = wlist->next) + print("%ld:%s", strlen(wlist->str), wlist->str); + print("e"); + } else + print("8:url-list%ld:%s", strlen(wlist->str), wlist->str); + } print("e"); + return 0; } |