libeech

BitTorrent library
git clone git://z3bra.org/libeech.git
Log | Files | Refs | README | LICENSE

commit 30c885bf1a9870d5d0d983ad719511eaccd052d4
parent a9b0348be67fa7baacce53c098b659e7e24b0268
Author: z3bra <contactatz3bradotorg>
Date:   Sun Oct 22 08:56:34 +0200

Have bekstr() return a bencoding structure

Diffstat:
be.c | 19++++++++++---------
be.h | 2+-
libeech.c | 8++++----
3 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/be.c b/be.c @@ -311,22 +311,23 @@ bekint(struct be *b, char *k, size_t kl) return n; } -char * -bekstr(struct be *b, char *k, size_t kl) +int +bekstr(struct be *b, char *k, size_t kl, struct be *s) { char *sp; size_t vl; struct be v; - static char s[LINE_MAX]; - memset(s, 0, LINE_MAX); if (bekv(b, k, kl, &v) < 0) - return NULL; + return -1; if (bestr(&v, &sp, &vl) < 0) - return NULL; + return -1; - memcpy(s, sp, MIN(vl, LINE_MAX)); - s[MIN(vl, LINE_MAX - 1)] = 0; + if (s) { + s->start = v.start; + s->off = sp; + s->end = sp + vl; + } - return s; + return 0; } diff --git a/be.h b/be.h @@ -25,6 +25,6 @@ char betype(struct be *); int bekv(struct be *, char *, size_t, struct be *); int bepath(struct be *, char **, size_t); long bekint(struct be *, char *, size_t); -char * bekstr(struct be *, char *, size_t); +int bekstr(struct be *, char *, size_t, struct be *); #endif diff --git a/libeech.c b/libeech.c @@ -65,12 +65,12 @@ torrentsize(struct torrent *t) static int loadtracker(struct torrent *t) { - char *sp; + struct be v; - sp = bekstr(&t->be, "announce", 8); - if (!sp) + if (bekstr(&t->be, "announce", 8, &v) < 0) return -1; - memcpy(t->tr, sp, strlen(sp)); + + memcpy(t->tr, v.off, v.end - v.off); return 0; }