X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;ds=sidebyside;f=sbr%2Fm_getfld2.c;h=6d96bdd42c38c5985f1e93ca46c3753c1c80ce82;hb=c4de1023b3141b9a89038012b246fa74205752cd;hp=91164f3c1a47a7b596b4f137720bb6076b200d9d;hpb=f5df6f250dc5862488efb0198823c68f5b573ccc;p=mmh diff --git a/sbr/m_getfld2.c b/sbr/m_getfld2.c index 91164f3..6d96bdd 100644 --- a/sbr/m_getfld2.c +++ b/sbr/m_getfld2.c @@ -26,8 +26,18 @@ static size_t copyname(char *, char *); /* -** For the states FLD2, BODY2 and FMTERR2 memory is allocated for f->value. -** For the states LENERR2, ERR2 and FILEEOF2 no memory is allocated. +** FLD2: We read a (complete) header field +** BODY2: We read a body line +** LENERR2: Line is too long (>998, as defined by RFC 822) +** FMTERR2: Header field invalid +** IOERR2: Failure to read +** FILEEOF2: We're at the end of the file +** +** f->name is only filled in FLD2. +** +** In FLD2, f->value contains the field's (complete) value only; +** in BODY2, LENERR2 and FMTERR2 f->value contains the whole line; +** in IOERR2 and FILEEOF2 f->value is not set. */ enum state m_getfld2(enum state s, struct field *f, FILE *msg) @@ -42,18 +52,22 @@ m_getfld2(enum state s, struct field *f, FILE *msg) if (feof(msg)) { return FILEEOF2; } else { - return ERR2; + return IOERR2; } } + *f->name = '\0'; + f->namelen = 0; + if (nchars >= NAMESZ) { - free(tmpline); + if (f->value) { + free(f->value); + } + f->value = tmpline; + f->valuelen = nchars; return LENERR2; } - *f->name = '\0'; - f->namelen = 0; - switch (s) { case FLD2: if (*(tmpline + nchars - 1) != '\n') { @@ -95,11 +109,15 @@ m_getfld2(enum state s, struct field *f, FILE *msg) nchars = getline(&tmpline, &len, msg); if (nchars <= 0) { free(tmpline); - return ERR2; + return IOERR2; } if (nchars >= NAMESZ) { - free(tmpline); + if (f->value) { + free(f->value); + } + f->value = tmpline; + f->valuelen = nchars; return LENERR2; } @@ -125,7 +143,7 @@ m_getfld2(enum state s, struct field *f, FILE *msg) if (falted == FAIL) { free(tmpline); - return ERR2; + return IOERR2; } free(tmpline); @@ -175,11 +193,17 @@ static size_t copyname(char *dst, char *src) { size_t len; - char *sep = strchr(src, ':'); + char *cp, *sep; - if (!sep) { + if (!(sep = strchr(src, ':'))) { return 0; } + /* whitespace is forbidden in name */ + for (cp=src; cp= NAMESZ) {