diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2012-06-01 09:24:59 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2012-06-01 09:24:59 +0000 |
commit | e07351a1a792c2ea87bf8f77d38a0a02e5023a2a (patch) | |
tree | 8996f78ae6bfda5b8829c85bbe75900939d35a0d /usr.sbin | |
parent | 74f92142e165799acff614cb9314ba6a14220d40 (diff) |
move envelope dump/load functions to envelope.c
ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/envelope.c | 175 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_fsqueue.c | 179 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 8 |
3 files changed, 181 insertions, 181 deletions
diff --git a/usr.sbin/smtpd/envelope.c b/usr.sbin/smtpd/envelope.c index 6264f1bfd6d..5a2014b3f13 100644 --- a/usr.sbin/smtpd/envelope.c +++ b/usr.sbin/smtpd/envelope.c @@ -1,4 +1,4 @@ -/* $OpenBSD: envelope.c,v 1.4 2012/01/15 16:47:49 chl Exp $ */ +/* $OpenBSD: envelope.c,v 1.5 2012/06/01 09:24:58 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -87,6 +87,179 @@ envelope_set_errormsg(struct envelope *e, char *fmt, ...) strlcpy(e->errorline + (sizeof(e->errorline) - 4), "...", 4); } +int +envelope_load_file(struct envelope *ep, FILE *fp) +{ + char *buf, *lbuf; + char *field; + size_t len; + enum envelope_field fields[] = { + EVP_VERSION, + EVP_ID, + EVP_HOSTNAME, + EVP_SOCKADDR, + EVP_HELO, + EVP_SENDER, + EVP_RCPT, + EVP_DEST, + EVP_TYPE, + EVP_CTIME, + EVP_EXPIRE, + EVP_RETRY, + EVP_LASTTRY, + EVP_FLAGS, + EVP_ERRORLINE, + EVP_MDA_METHOD, + EVP_MDA_BUFFER, + EVP_MDA_USER, + EVP_MTA_RELAY_HOST, + EVP_MTA_RELAY_PORT, + EVP_MTA_RELAY_CERT, + EVP_MTA_RELAY_FLAGS, + EVP_MTA_RELAY_AUTHMAP + }; + int i; + int n; + int ret; + + n = sizeof(fields) / sizeof(enum envelope_field); + bzero(ep, sizeof (*ep)); + lbuf = NULL; + while ((buf = fgetln(fp, &len))) { + if (buf[len - 1] == '\n') + buf[len - 1] = '\0'; + else { + if ((lbuf = malloc(len + 1)) == NULL) + err(1, NULL); + memcpy(lbuf, buf, len); + lbuf[len] = '\0'; + buf = lbuf; + } + + for (i = 0; i < n; ++i) { + field = envelope_ascii_field_name(fields[i]); + len = strlen(field); + if (! strncasecmp(field, buf, len)) { + /* skip kw and tailing whitespaces */ + buf += len; + while (*buf && isspace(*buf)) + buf++; + + /* we *want* ':' */ + if (*buf != ':') + continue; + buf++; + + /* skip whitespaces after separator */ + while (*buf && isspace(*buf)) + buf++; + + ret = envelope_ascii_load(fields[i], ep, buf); + if (ret == 0) + goto err; + break; + } + } + + /* unknown keyword */ + if (i == n) + goto err; + } + free(lbuf); + return 1; + +err: + free(lbuf); + return 0; +} + +int +envelope_dump_file(struct envelope *ep, FILE *fp) +{ + char buf[8192]; + + enum envelope_field fields[] = { + EVP_VERSION, + EVP_ID, + EVP_TYPE, + EVP_HELO, + EVP_HOSTNAME, + EVP_ERRORLINE, + EVP_SOCKADDR, + EVP_SENDER, + EVP_RCPT, + EVP_DEST, + EVP_CTIME, + EVP_LASTTRY, + EVP_EXPIRE, + EVP_RETRY, + EVP_FLAGS + }; + enum envelope_field mda_fields[] = { + EVP_MDA_METHOD, + EVP_MDA_BUFFER, + EVP_MDA_USER + }; + enum envelope_field mta_fields[] = { + EVP_MTA_RELAY_HOST, + EVP_MTA_RELAY_PORT, + EVP_MTA_RELAY_CERT, + EVP_MTA_RELAY_AUTHMAP, + EVP_MTA_RELAY_FLAGS + }; + enum envelope_field *pfields = NULL; + int i; + int n; + + n = sizeof(fields) / sizeof(enum envelope_field); + for (i = 0; i < n; ++i) { + bzero(buf, sizeof buf); + if (! envelope_ascii_dump(fields[i], ep, buf, sizeof buf)) + goto err; + if (buf[0] == '\0') + continue; + fprintf(fp, "%s: %s\n", + envelope_ascii_field_name(fields[i]), buf); + } + + switch (ep->type) { + case D_MDA: + pfields = mda_fields; + n = sizeof(mda_fields) / sizeof(enum envelope_field); + break; + case D_MTA: + pfields = mta_fields; + n = sizeof(mta_fields) / sizeof(enum envelope_field); + break; + case D_BOUNCE: + /* nothing ! */ + break; + default: + goto err; + } + + if (pfields) { + for (i = 0; i < n; ++i) { + bzero(buf, sizeof buf); + if (! envelope_ascii_dump(pfields[i], ep, buf, + sizeof buf)) + goto err; + if (buf[0] == '\0') + continue; + fprintf(fp, "%s: %s\n", + envelope_ascii_field_name(pfields[i]), buf); + } + } + + if (fflush(fp) != 0) + goto err; + + return 1; + +err: + return 0; +} + char * envelope_ascii_field_name(enum envelope_field field) { diff --git a/usr.sbin/smtpd/queue_fsqueue.c b/usr.sbin/smtpd/queue_fsqueue.c index c57505009d4..7158da0d4e2 100644 --- a/usr.sbin/smtpd/queue_fsqueue.c +++ b/usr.sbin/smtpd/queue_fsqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_fsqueue.c,v 1.39 2012/03/07 22:54:49 gilles Exp $ */ +/* $OpenBSD: queue_fsqueue.c,v 1.40 2012/06/01 09:24:58 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -155,7 +155,7 @@ fsqueue_envelope_dump_atomic(char *dest, struct envelope *ep) fatal("fsqueue_envelope_dump_atomic: open"); } - if (! fsqueue_dump_envelope_ascii(fp, ep)) { + if (! envelope_dump_file(ep, fp)) { if (errno == ENOSPC) goto tempfail; fatal("fsqueue_envelope_dump_atomic: fwrite"); @@ -221,7 +221,7 @@ fsqueue_envelope_load(enum queue_kind qkind, struct envelope *ep) return 0; fatal("fsqueue_envelope_load: fopen"); } - ret = fsqueue_load_envelope_ascii(fp, ep); + ret = envelope_load_file(ep, fp); fclose(fp); @@ -660,176 +660,3 @@ walk_queue_nobucket(struct qwalk *q, char *fname) return (-1); } - -int -fsqueue_load_envelope_ascii(FILE *fp, struct envelope *ep) -{ - char *buf, *lbuf; - char *field; - size_t len; - enum envelope_field fields[] = { - EVP_VERSION, - EVP_ID, - EVP_HOSTNAME, - EVP_SOCKADDR, - EVP_HELO, - EVP_SENDER, - EVP_RCPT, - EVP_DEST, - EVP_TYPE, - EVP_CTIME, - EVP_EXPIRE, - EVP_RETRY, - EVP_LASTTRY, - EVP_FLAGS, - EVP_ERRORLINE, - EVP_MDA_METHOD, - EVP_MDA_BUFFER, - EVP_MDA_USER, - EVP_MTA_RELAY_HOST, - EVP_MTA_RELAY_PORT, - EVP_MTA_RELAY_CERT, - EVP_MTA_RELAY_FLAGS, - EVP_MTA_RELAY_AUTHMAP - }; - int i; - int n; - int ret; - - n = sizeof(fields) / sizeof(enum envelope_field); - bzero(ep, sizeof (*ep)); - lbuf = NULL; - while ((buf = fgetln(fp, &len))) { - if (buf[len - 1] == '\n') - buf[len - 1] = '\0'; - else { - if ((lbuf = malloc(len + 1)) == NULL) - err(1, NULL); - memcpy(lbuf, buf, len); - lbuf[len] = '\0'; - buf = lbuf; - } - - for (i = 0; i < n; ++i) { - field = envelope_ascii_field_name(fields[i]); - len = strlen(field); - if (! strncasecmp(field, buf, len)) { - /* skip kw and tailing whitespaces */ - buf += len; - while (*buf && isspace(*buf)) - buf++; - - /* we *want* ':' */ - if (*buf != ':') - continue; - buf++; - - /* skip whitespaces after separator */ - while (*buf && isspace(*buf)) - buf++; - - ret = envelope_ascii_load(fields[i], ep, buf); - if (ret == 0) - goto err; - break; - } - } - - /* unknown keyword */ - if (i == n) - goto err; - } - free(lbuf); - return 1; - -err: - free(lbuf); - return 0; -} - -int -fsqueue_dump_envelope_ascii(FILE *fp, struct envelope *ep) -{ - char buf[8192]; - - enum envelope_field fields[] = { - EVP_VERSION, - EVP_ID, - EVP_TYPE, - EVP_HELO, - EVP_HOSTNAME, - EVP_ERRORLINE, - EVP_SOCKADDR, - EVP_SENDER, - EVP_RCPT, - EVP_DEST, - EVP_CTIME, - EVP_LASTTRY, - EVP_EXPIRE, - EVP_RETRY, - EVP_FLAGS - }; - enum envelope_field mda_fields[] = { - EVP_MDA_METHOD, - EVP_MDA_BUFFER, - EVP_MDA_USER - }; - enum envelope_field mta_fields[] = { - EVP_MTA_RELAY_HOST, - EVP_MTA_RELAY_PORT, - EVP_MTA_RELAY_CERT, - EVP_MTA_RELAY_AUTHMAP, - EVP_MTA_RELAY_FLAGS - }; - enum envelope_field *pfields = NULL; - int i; - int n; - - n = sizeof(fields) / sizeof(enum envelope_field); - for (i = 0; i < n; ++i) { - bzero(buf, sizeof buf); - if (! envelope_ascii_dump(fields[i], ep, buf, sizeof buf)) - goto err; - if (buf[0] == '\0') - continue; - fprintf(fp, "%s: %s\n", - envelope_ascii_field_name(fields[i]), buf); - } - - switch (ep->type) { - case D_MDA: - pfields = mda_fields; - n = sizeof(mda_fields) / sizeof(enum envelope_field); - break; - case D_MTA: - pfields = mta_fields; - n = sizeof(mta_fields) / sizeof(enum envelope_field); - break; - case D_BOUNCE: - /* nothing ! */ - break; - default: - goto err; - } - - if (pfields) { - for (i = 0; i < n; ++i) { - bzero(buf, sizeof buf); - if (! envelope_ascii_dump(pfields[i], ep, buf, - sizeof buf)) - goto err; - if (buf[0] == '\0') - continue; - fprintf(fp, "%s: %s\n", - envelope_ascii_field_name(pfields[i]), buf); - } - } - - if (fflush(fp) != 0) - goto err; - - return 1; - -err: - return 0; -} diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 247935474f0..76e76fa5d82 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.295 2012/05/29 19:53:10 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.296 2012/06/01 09:24:58 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -1052,9 +1052,9 @@ int enqueue_offline(int, char **); void envelope_set_errormsg(struct envelope *, char *, ...); char *envelope_ascii_field_name(enum envelope_field); int envelope_ascii_load(enum envelope_field, struct envelope *, char *); -int envelope_ascii_dump(enum envelope_field, struct envelope *, char *, - size_t); - +int envelope_ascii_dump(enum envelope_field, struct envelope *, char *, size_t); +int envelope_load_file(struct envelope *, FILE *); +int envelope_dump_file(struct envelope *, FILE *); /* expand.c */ int expand_cmp(struct expandnode *, struct expandnode *); |