Index: ossp-pkg/lmtp2nntp/lmtp2nntp.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v rcsdiff -q -kk '-r1.74' '-r1.75' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v' 2>/dev/null --- lmtp2nntp.c 2001/10/09 10:34:10 1.74 +++ lmtp2nntp.c 2001/10/09 12:08:58 1.75 @@ -120,6 +120,7 @@ sa_t *sa; /* socket abstraction */ nntp_t *nntp; nntp_rc_t rc; + l2_stream_t *l2; }; typedef struct { @@ -230,7 +231,7 @@ log0(ctx, TRACE, "LMTP read error: %m"); else log3(ctx, TRACE, "LMTP %5d << \"%{text}D\"", rc, buf, rc); - log1(ctx, DEBUG, "trace_lmtp_read() return, rc=%d", rc); + log1(ctx, DEBUG, "hook_lmtp_read() return, rc=%d", rc); return rc; } @@ -255,12 +256,17 @@ return rc; } -static ssize_t trace_nntp_read(void *_ctx, int d, void *buf, size_t nbytes) +static ssize_t hook_nntp_read(void *_ctx, void *buf, size_t nbytes) { - lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx; + struct ns *ctx = (struct ns *)_ctx; ssize_t rc; + size_t n; + sa_rc_t rv; - rc = read(d, buf, nbytes); + if ((rv = sa_read(ctx->sa, buf, nbytes, &n)) != SA_OK) + rc = -1; + else + rc = (ssize_t)n; if (rc == -1) log0(ctx, TRACE, "NNTP read error: %m"); else @@ -268,13 +274,18 @@ return rc; } -static ssize_t trace_nntp_write(void *_ctx, int d, const void *buf, size_t nbytes) +static ssize_t hook_nntp_write(void *_ctx, const void *buf, size_t nbytes) { - lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx; + struct ns *ctx = (struct ns *)_ctx; ssize_t rc; + size_t n; + sa_rc_t rv; log3(ctx, TRACE, "NNTP %5d >> \"%{text}D\"", nbytes, buf, nbytes); - rc = write(d, buf, nbytes); + if ((rv = sa_write(ctx->sa, buf, nbytes, &n)) != SA_OK) + rc = -1; + else + rc = (ssize_t)n; if (rc == -1) log0(ctx, TRACE, "NNTP write error: %m"); return rc; @@ -405,6 +416,7 @@ ctx->ns[i].sa = NULL; ctx->ns[i].nntp = NULL; ctx->ns[i].rc = LMTP_ERR_UNKNOWN; + ctx->ns[i].l2 = NULL; } ctx->azGroupargs = NULL; ctx->asGroupargs = 0; @@ -981,15 +993,9 @@ int bOk; int i; nntp_io_t nntp_io; - int s; log1(ctx, INFO, "LMTP service executing LHLO command < %s", req->msg); - nntp_io.ctx = ctx; - nntp_io.select = NULL; - nntp_io.read = trace_nntp_read; - nntp_io.write = trace_nntp_write; - /* RFC0821 4.2.1. REPLY CODES BY FUNCTION GROUPS 503 Bad sequence of commands * RFC1893 2. Status Codes 5.X.X Permanent Failure * RFC1893 3.5 Network and Routing Status X.0.0 Other undefined Status @@ -1038,6 +1044,8 @@ bOk = TRUE; log2(ctx, TRACE, "try %s:%s", ctx->ns[i].h, ctx->ns[i].p); + ctx->ns[i].l2 = ctx->l2; + if (bOk && (ctx->saaBind != NULL)) { log2(ctx, DEBUG, "bind local socket to %s:%s", ctx->cpBindh, ctx->cpBindp); if (sa_bind(ctx->ns[i].sa, ctx->saaBind) != SA_OK) { @@ -1062,20 +1070,15 @@ if (bOk) { log0(ctx, DEBUG, "nntp_create"); - sa_getfd(ctx->ns[i].sa, &s); - if ((ctx->ns[i].nntp = nntp_create(s, s, - (ctx->option_logfile && (ctx->option_levelmask >= L2_LEVEL_TRACE)) ? - &nntp_io : NULL)) == NULL) { + nntp_io.ctx = &ctx->ns[i]; + nntp_io.read = hook_nntp_read; + nntp_io.write = hook_nntp_write; + if ((ctx->ns[i].nntp = nntp_create(&nntp_io)) == NULL) { bOk = FALSE; log0(ctx, ERROR, "creation of NNTP context failed"); } } - if (bOk && ctx->option_timeout_nntp_connect >= 0) { - log1(ctx, DEBUG, "nntp_timeout with %d", ctx->option_timeout_nntp_connect); - nntp_timeout(ctx->ns[i].nntp, ctx->option_timeout_nntp_connect); - } - if (bOk) { log0(ctx, DEBUG, "nntp_init"); if ((rc = nntp_init(ctx->ns[i].nntp)) != NNTP_OK) { @@ -1730,8 +1733,7 @@ bSuccess = NNTP_OK; if ( bSuccess != NNTP_OK && ( - (ctx->ns[i].rc == NNTP_TIMEOUT) - || (ctx->ns[i].rc == NNTP_ERR_SYSTEM) + (ctx->ns[i].rc == NNTP_ERR_SYSTEM) || (ctx->ns[i].rc == NNTP_DEFER) ) ) Index: ossp-pkg/lmtp2nntp/nntp.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/nntp.c,v rcsdiff -q -kk '-r1.25' '-r1.26' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/nntp.c,v' 2>/dev/null --- nntp.c 2001/09/11 13:38:07 1.25 +++ nntp.c 2001/10/09 12:08:59 1.26 @@ -63,66 +63,44 @@ } nntp_readline_t; struct nntp_st { - int rfd; - int wfd; nntp_io_t io; nntp_readline_t rl; struct timeval tv; int kludgeinn441dup; }; -static int nntp_select(void *ctx, int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv) +ssize_t nntp_fd_read(void *_ctx, void *buf, size_t buflen) { - return select(nfds, rfds, wfds, efds, tv); + nntp_fd_t *ctx = (nntp_fd_t *)_ctx; + return read(ctx->fd, buf, buflen); } -static ssize_t nntp_read(void *ctx, int fd, void *buf, size_t buflen) +ssize_t nntp_fd_write(void *_ctx, const void *buf, size_t buflen) { - return read(fd, buf, buflen); + nntp_fd_t *ctx = (nntp_fd_t *)_ctx; + return write(ctx->fd, buf, buflen); } -static ssize_t nntp_write(void *ctx, int fd, const void *buf, size_t buflen) -{ - return write(fd, buf, buflen); -} - -nntp_t *nntp_create(int rfd, int wfd, nntp_io_t *io) +nntp_t *nntp_create(nntp_io_t *io) { nntp_t *nntp; if ((nntp = (nntp_t *)malloc(sizeof(nntp_t))) == NULL) return NULL; - if (io == NULL) { - nntp->io.ctx = NULL; - nntp->io.select = nntp_select; - nntp->io.read = nntp_read; - nntp->io.write = nntp_write; - } else { - nntp->io.ctx = io->ctx; - nntp->io.select = io->select ? io->select : nntp_select; - nntp->io.read = io->read ? io->read : nntp_read; - nntp->io.write = io->write ? io->write : nntp_write; - } - - nntp->rfd = rfd; - nntp->wfd = wfd; + if (io == NULL) + return NULL; + nntp->io.ctx = io->ctx; + nntp->io.read = io->read; + nntp->io.write = io->write; nntp->rl.rl_cnt = 0; nntp->rl.rl_bufptr = NULL; nntp->rl.rl_buf[0] = NUL; - nntp_timeout(nntp, 3); nntp->kludgeinn441dup = FALSE; return nntp; } -nntp_rc_t nntp_timeout(nntp_t *nntp, long timeout) -{ - nntp->tv.tv_sec = timeout; - nntp->tv.tv_usec = 0; - return NNTP_OK; -} - nntp_rc_t nntp_init(nntp_t *nntp) { nntp_rc_t rc; @@ -182,9 +160,6 @@ size_t n; char c; nntp_readline_t *rl = &nntp->rl; - struct timeval tv; - fd_set fds; - int rc; if (nntp == NULL) return NNTP_ERR_ARG; @@ -192,17 +167,8 @@ /* fetch one character (but read more) */ if (rl->rl_cnt <= 0) { - FD_ZERO(&fds); - FD_SET(nntp->rfd, &fds); - tv.tv_sec = nntp->tv.tv_sec; - tv.tv_usec = nntp->tv.tv_usec; - rc = nntp->io.select(nntp->io.ctx, nntp->rfd + 1, &fds, NULL, NULL, &tv); - if (rc == 0) - return NNTP_TIMEOUT; - else if (rc == -1) - return NNTP_ERR_SYSTEM; do { - rl->rl_cnt = nntp->io.read(nntp->io.ctx, nntp->rfd, rl->rl_buf, NNTP_LINE_MAXLEN); + rl->rl_cnt = nntp->io.read(nntp->io.ctx, rl->rl_buf, NNTP_LINE_MAXLEN); } while (rl->rl_cnt == -1 && errno == EINTR); if (rl->rl_cnt == -1) return NNTP_ERR_SYSTEM; @@ -235,7 +201,7 @@ return NNTP_ERR_ARG; strncpy(tmp, buf, NNTP_LINE_MAXLEN-3); strcat(tmp, "\r\n"); - if (nntp->io.write(nntp->io.ctx, nntp->wfd, tmp, strlen(tmp)) < 0) + if (nntp->io.write(nntp->io.ctx, tmp, strlen(tmp)) < 0) return NNTP_ERR_SYSTEM; return NNTP_OK; } @@ -350,7 +316,7 @@ return NNTP_ERR_DELIVERY; do { - rc = nntp->io.write(nntp->io.ctx, nntp->wfd, msg->cpMsg, strlen(msg->cpMsg)); + rc = nntp->io.write(nntp->io.ctx, msg->cpMsg, strlen(msg->cpMsg)); } while (rc == -1 && errno == EINTR); if (rc == -1) return NNTP_ERR_SYSTEM; @@ -417,7 +383,7 @@ return NNTP_ERR_DELIVERY; do { - rc = nntp->io.write(nntp->io.ctx, nntp->wfd, msg->cpMsg, strlen(msg->cpMsg)); + rc = nntp->io.write(nntp->io.ctx, msg->cpMsg, strlen(msg->cpMsg)); } while (rc == -1 && errno == EINTR); if (rc == -1) return NNTP_ERR_SYSTEM; @@ -440,7 +406,6 @@ str = "NNTP: errorcode has no description"; if (rc == NNTP_OK ) str = "NNTP: no error"; else if (rc == NNTP_EOF ) str = "NNTP: end of file"; - else if (rc == NNTP_TIMEOUT ) str = "NNTP: timeout"; else if (rc == NNTP_DEFER ) str = "NNTP: transmission deferred"; else if (rc == NNTP_FAKE ) str = "NNTP: fake status not real"; else if (rc == NNTP_ERR_SYSTEM ) str = "NNTP: see errno"; Index: ossp-pkg/lmtp2nntp/nntp.h RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/nntp.h,v rcsdiff -q -kk '-r1.11' '-r1.12' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/nntp.h,v' 2>/dev/null --- nntp.h 2001/09/10 14:11:33 1.11 +++ nntp.h 2001/10/09 12:08:59 1.12 @@ -38,15 +38,13 @@ typedef struct { void *ctx; - int (*select)(void *, int, fd_set *, fd_set *, fd_set *, struct timeval *); - ssize_t (*read)(void *, int, void *, size_t); - ssize_t (*write)(void *, int, const void *, size_t); + ssize_t (*read)(void *, void *, size_t); + ssize_t (*write)(void *, const void *, size_t); } nntp_io_t; typedef enum { NNTP_OK, NNTP_EOF, - NNTP_TIMEOUT, NNTP_DEFER, NNTP_FAKE, NNTP_ERR_SYSTEM, @@ -57,8 +55,11 @@ NNTP_ERR_UNKNOWN } nntp_rc_t; -nntp_t *nntp_create (int, int, nntp_io_t *); -nntp_rc_t nntp_timeout (nntp_t *nntp, long); +typedef struct { + int fd; +} nntp_fd_t; + +nntp_t *nntp_create (nntp_io_t *); nntp_rc_t nntp_init (nntp_t *); void nntp_destroy (nntp_t *); nntp_rc_t nntp_readline (nntp_t *, char *, size_t); @@ -66,6 +67,8 @@ nntp_rc_t nntp_post (nntp_t *, msg_t *msg); nntp_rc_t nntp_feed (nntp_t *, msg_t *msg); char *nntp_error (nntp_rc_t); +ssize_t nntp_fd_read (void *, void *, size_t); +ssize_t nntp_fd_write (void *, const void *, size_t); #endif /* __NNTP_H__ */