sacc

sacc (saccomys): simple gopher client.
Log | Files | Refs | LICENSE

commit 3d2081c17810cae6607b3a265f848e5031002d0a
parent bab7585c38f70040c68865455e3fafa552cf9f6c
Author: Leonardo Taccari <iamleot@gmail.com>
Date:   Sat, 18 Aug 2018 15:18:32 +0200

Ignore possible extra tab delimited fields

According RFC 1436:

> [...] If there are yet other tab delimited fields, the basic
> Gopher client should ignore them. [...]

Diffstat:
sacc.c | 16+++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/sacc.c b/sacc.c @@ -283,11 +283,11 @@ displaytextitem(Item *item) } static char * -pickfield(char **raw, char sep) +pickfield(char **raw, const char *sep) { char *c, *f = *raw; - for (c = *raw; *c && *c != sep; ++c) + for (c = *raw; *c && strchr(sep, *c) == NULL; ++c) ; *c = '\0'; @@ -309,7 +309,7 @@ invaliditem(char *raw) if (c) *raw++ = '\0'; - return (tabs == 3) ? NULL : raw; + return (tabs >= 3) ? NULL : raw; } static void @@ -327,10 +327,12 @@ molditem(Item *item, char **raw) } item->type = *raw[0]++; - item->username = pickfield(raw, '\t'); - item->selector = pickfield(raw, '\t'); - item->host = pickfield(raw, '\t'); - item->port = pickfield(raw, '\r'); + item->username = pickfield(raw, "\t"); + item->selector = pickfield(raw, "\t"); + item->host = pickfield(raw, "\t"); + item->port = pickfield(raw, "\t\r"); + while (*raw[0] != '\0') + ++*raw; if (!*raw[0]) ++*raw; }