X-Git-Url: https://git.distorted.org.uk/~mdw/fwd/blobdiff_plain/48bb1f76fd805b19aa32a374a8a9d8106ab7f420..096c89c34505cadba1fc6e7a5367273d5c5bea47:/file.c diff --git a/file.c b/file.c index 300ac04..8b4f533 100644 --- a/file.c +++ b/file.c @@ -1,68 +1,30 @@ /* -*-c-*- * - * $Id: file.c,v 1.1 1999/07/26 23:33:32 mdw Exp $ - * * File source and target * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * - * This file is part of the `fw' port forwarder. + * This file is part of the `fwd' port forwarder. * - * `fw' is free software; you can redistribute it and/or modify + * `fwd' is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * - * `fw' is distributed in the hope that it will be useful, + * + * `fwd' is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License - * along with `fw'; if not, write to the Free Software Foundation, + * along with `fwd'; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: file.c,v $ - * Revision 1.1 1999/07/26 23:33:32 mdw - * New sources and targets. - * - */ - -/*----- Header files ------------------------------------------------------*/ - -#include "config.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "conf.h" -#include "endpt.h" -#include "fattr.h" -#include "file.h" -#include "fw.h" -#include "reffd.h" -#include "scan.h" -#include "source.h" -#include "target.h" +#include "fwd.h" /*----- Data structures ---------------------------------------------------*/ @@ -100,7 +62,7 @@ typedef struct fdata { typedef struct fsource { source s; fdata f; -} fsource; +} fsource; /* --- File target block --- */ @@ -142,7 +104,7 @@ static void fept_close(endpt *e) /* --- Endpoint operations table --- */ -static endpt_ops fept_ops = { 0, fept_wclose, fept_close }; +static endpt_ops fept_ops = { 0, 0, fept_wclose, fept_close }; /*----- General operations on sources and targets -------------------------*/ @@ -178,7 +140,7 @@ static reffd *file_nullref(void) else { int n; if ((n = open("/dev/null", O_RDWR)) < 0) { - fw_log(-1, "couldn't open `/dev/null': %s", strerror(errno)); + fw_log(NOW, "couldn't open `/dev/null': %s", strerror(errno)); return (0); } fdflags(n, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC); @@ -186,7 +148,7 @@ static reffd *file_nullref(void) reffd_handler(rnull, file_null, 0); } return (rnull); -} +} /* --- @file_fspec@ --- * * @@ -260,7 +222,7 @@ static void file_fspec(fspec *f, scanner *sc) else if (fd) { f->type = FTYPE_FD; f->u.fd = fd; - token(sc); + token(sc); } else if (type == FTYPE_FD) { if (sc->t == CTOK_WORD) error(sc, "bad file descriptor `%s'", sc->d.buf); @@ -268,7 +230,7 @@ static void file_fspec(fspec *f, scanner *sc) error(sc, "parse error, expected file descriptor"); } else { dstr d = DSTR_INIT; - conf_name(sc, '/', &d); + conf_fname(sc, &d); f->type = FTYPE_NAME; f->u.name = xstrdup(d.buf); dstr_destroy(&d); @@ -280,13 +242,15 @@ static void file_fspec(fspec *f, scanner *sc) static void file_read(fdata *f, scanner *sc) { file_fspec(&f->in, sc); - if (sc->t != ',') { + if (sc->t == ',') { + token(sc); + file_fspec(&f->out, sc); + } else { f->out = f->in; if (f->out.type == FTYPE_FD && f->out.u.fd == rstdin) f->out.u.fd = rstdout; - } else { - token(sc); - file_fspec(&f->out, sc); + else if (f->out.type == FTYPE_NAME) + f->out.u.name = xstrdup(f->in.u.name); } f->fa = fattr_global; f->fo = file_opts; @@ -316,7 +280,7 @@ static void file_pfspec(fspec *f, dstr *d) case FTYPE_NULL: dstr_puts(d, "null"); break; - } + } } static void file_desc(fdata *f, dstr *d) @@ -395,7 +359,7 @@ static endpt *file_endpt(fdata *f, const char *desc) case FTYPE_NAME: { int fd; if ((fd = open(f->in.u.name, O_RDONLY | O_NONBLOCK)) < 0) { - fw_log(-1, "[%s] couldn't open `%s' for reading: %s", + fw_log(NOW, "[%s] couldn't open `%s' for reading: %s", desc, f->in.u.name, strerror(errno)); return (0); } @@ -427,7 +391,7 @@ static endpt *file_endpt(fdata *f, const char *desc) if ((m & O_CREAT) && (fd = open(f->out.u.name, m | O_EXCL, f->fa.mode)) < 0 && (errno != EEXIST || (m & O_EXCL))) { - fw_log(-1, "[%s] couldn't create `%s': %s", + fw_log(NOW, "[%s] couldn't create `%s': %s", desc, f->out.u.name, strerror(errno)); REFFD_DEC(in); return (0); @@ -435,11 +399,11 @@ static endpt *file_endpt(fdata *f, const char *desc) if (fd != -1) { if (fattr_apply(f->out.u.name, &f->fa)) { - fw_log(-1, "[%s] couldn't apply file attributes: %s", + fw_log(NOW, "[%s] couldn't apply file attributes to `%s': %s", desc, f->out.u.name, strerror(errno)); } } else if ((fd = open(f->out.u.name, m & ~O_CREAT)) < 0) { - fw_log(-1, "[%s] couldn't open `%s': %s", + fw_log(NOW, "[%s] couldn't open `%s': %s", desc, f->out.u.name, strerror(errno)); REFFD_DEC(in); return (0); @@ -468,9 +432,9 @@ static endpt *file_endpt(fdata *f, const char *desc) static void file_destroy(fdata *f) { if (f->in.type == FTYPE_NAME) - free(f->in.u.name); + xfree(f->in.u.name); if (f->out.type == FTYPE_NAME) - free(f->out.u.name); + xfree(f->out.u.name); } /*----- File source description -------------------------------------------*/ @@ -526,7 +490,7 @@ static void fsource_attach(source *s, scanner *sc, target *t) ee->ops->close(ee); goto tidy; } - endpt_join(e, ee); + endpt_join(e, ee, fs->s.desc); /* --- Dispose of the source and target now --- */ @@ -540,8 +504,7 @@ tidy: static void fsource_destroy(source *s) { fsource *fs = (fsource *)s; - - /* free(fs->s.desc); */ + xfree(fs->s.desc); file_destroy(&fs->f); DESTROY(fs); } @@ -596,7 +559,7 @@ static void ftarget_destroy(target *t) { ftarget *ft = (ftarget *)t; file_destroy(&ft->f); - /* free(ft->t.desc); */ + xfree(ft->t.desc); DESTROY(ft); } @@ -604,7 +567,7 @@ static void ftarget_destroy(target *t) target_ops ftarget_ops = { "file", - ftarget_option, ftarget_read, ftarget_create, ftarget_destroy + ftarget_option, ftarget_read, 0, ftarget_create, ftarget_destroy }; /*----- That's all, folks -------------------------------------------------*/