X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/blobdiff_plain/37941236c18baccbf89f5842ca63aee471d79256..452bf3f6897b8c6a22b51e1ef228da39136d51a7:/servutil.c diff --git a/servutil.c b/servutil.c index f4ab92e3..92a5f775 100644 --- a/servutil.c +++ b/servutil.c @@ -91,32 +91,6 @@ const char *timestr(time_t t) return ((const char *)buf_t); } -/* --- @b64_encode@ --- * - * - * Arguments: @const void *p@ = pointer to some gorp - * @size_t sz@ = size of the gorp - * - * Returns: Pointer to base64-encoded version in @buf_t@. - */ - -const char *b64_encode(const void *p, size_t sz) -{ - base64_ctx b64; - dstr d = DSTR_INIT; - - base64_init(&b64); - b64.indent = ""; - b64.maxline = 0; - base64_encode(&b64, p, sz, &d); - base64_encode(&b64, 0, 0, &d); - while (d.len && d.buf[d.len - 1] == '=') d.len--; - assert(d.len < sizeof(buf_t)); - memcpy(buf_t, d.buf, d.len); - buf_t[d.len] = 0; - dstr_destroy(&d); - return ((const char *)buf_t); -} - /* --- @seq_reset@ --- * * * Arguments: @seqwin *s@ = sequence-checking window @@ -132,20 +106,23 @@ void seq_reset(seqwin *s) { s->seq = 0; s->win = 0; } * * Arguments: @seqwin *s@ = sequence-checking window * @uint32 q@ = sequence number to check + * @const char *service@ = service to report message from * - * Returns: A @SEQ_@ code. + * Returns: Zero on success, nonzero if the sequence number was bad. * * Use: Checks a sequence number against the window, updating things * as necessary. */ -int seq_check(seqwin *s, uint32 q) +int seq_check(seqwin *s, uint32 q, const char *service) { uint32 qbit; uint32 n; - if (q < s->seq) - return (SEQ_OLD); + if (q < s->seq) { + a_warn(service, "replay", "old-sequence", A_END); + return (-1); + } if (q >= s->seq + SEQ_WINSZ) { n = q - (s->seq + SEQ_WINSZ - 1); if (n < SEQ_WINSZ) @@ -155,8 +132,10 @@ int seq_check(seqwin *s, uint32 q) s->seq += n; } qbit = 1 << (q - s->seq); - if (s->win & qbit) - return (SEQ_REPLAY); + if (s->win & qbit) { + a_warn(service, "replay", "duplicated-sequence", A_END); + return (-1); + } s->win |= qbit; return (0); }