Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-4]: src/dist/bind/lib/isc Pull up revisions 1.1-1.2 (new) (requ...



details:   https://anonhg.NetBSD.org/src/rev/7ce1ffa36f14
branches:  netbsd-1-4
changeset: 469800:7ce1ffa36f14
user:      he <he%NetBSD.org@localhost>
date:      Sat Dec 04 17:05:36 1999 +0000

description:
Pull up revisions 1.1-1.2 (new) (requested by christos and veego):
  Update to BIND 8.2.2-P5.

diffstat:

 dist/bind/lib/isc/ctl_clnt.c |  583 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 583 insertions(+), 0 deletions(-)

diffs (truncated from 587 to 300 lines):

diff -r 24afbafe7d41 -r 7ce1ffa36f14 dist/bind/lib/isc/ctl_clnt.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/dist/bind/lib/isc/ctl_clnt.c      Sat Dec 04 17:05:36 1999 +0000
@@ -0,0 +1,583 @@
+/*     $NetBSD: ctl_clnt.c,v 1.2.2.2 1999/12/04 17:05:36 he Exp $      */
+
+#if !defined(lint) && !defined(SABER)
+static const char rcsid[] = "Id: ctl_clnt.c,v 8.14 1999/10/13 16:39:33 vixie Exp";
+#endif /* not lint */
+
+/*
+ * Copyright (c) 1998,1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/* Extern. */
+
+#include "port_before.h"
+
+#include <sys/param.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <arpa/inet.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <isc/assertions.h>
+#include <isc/ctl.h>
+#include <isc/eventlib.h>
+#include <isc/list.h>
+#include <isc/memcluster.h>
+
+#include "ctl_p.h"
+
+#include "port_after.h"
+
+/* Constants. */
+
+
+/* Macros. */
+
+#define donefunc_p(ctx) ((ctx).donefunc != NULL)
+#define arpacode_p(line) (isdigit(line[0]) && isdigit(line[1]) && \
+                         isdigit(line[2]))
+#define arpacont_p(line) (line[3] == '-')
+#define arpadone_p(line) (line[3] == ' ' || line[3] == '\t' || \
+                         line[3] == '\r' || line[3] == '\0')
+
+/* Types. */
+
+enum state {
+       initializing = 0, connecting, connected, destroyed
+};
+
+struct ctl_tran {
+       LINK(struct ctl_tran)   link;
+       LINK(struct ctl_tran)   wlink;
+       struct ctl_cctx *       ctx;
+       struct ctl_buf          outbuf;
+       ctl_clntdone            donefunc;
+       void *                  uap;
+};
+
+struct ctl_cctx {
+       enum state              state;
+       evContext               ev;
+       int                     sock;
+       ctl_logfunc             logger;
+       ctl_clntdone            donefunc;
+       void *                  uap;
+       evConnID                coID;
+       evTimerID               tiID;
+       evFileID                rdID;
+       evStreamID              wrID;
+       struct ctl_buf          inbuf;
+       struct timespec         timeout;
+       LIST(struct ctl_tran)   tran;
+       LIST(struct ctl_tran)   wtran;
+};
+
+/* Forward. */
+
+static struct ctl_tran *new_tran(struct ctl_cctx *, ctl_clntdone, void *, int);
+static void            start_write(struct ctl_cctx *);
+static void            destroy(struct ctl_cctx *, int);
+static void            error(struct ctl_cctx *);
+static void            new_state(struct ctl_cctx *, enum state);
+static void            conn_done(evContext, void *, int,
+                                 const void *, int,
+                                 const void *, int);
+static void            write_done(evContext, void *, int, int);
+static void            start_read(struct ctl_cctx *);
+static void            stop_read(struct ctl_cctx *);
+static void            readable(evContext, void *, int, int);
+static void            start_timer(struct ctl_cctx *);
+static void            stop_timer(struct ctl_cctx *);
+static void            touch_timer(struct ctl_cctx *);
+static void            timer(evContext, void *,
+                             struct timespec, struct timespec);
+
+/* Private data. */
+
+static const char * const state_names[] = {
+       "initializing", "connecting", "connected", "destroyed"
+};
+
+/* Public. */
+
+/*
+ * void
+ * ctl_client()
+ *     create, condition, and connect to a listener on the control port.
+ */
+struct ctl_cctx *
+ctl_client(evContext lev, const struct sockaddr *cap, size_t cap_len,
+          const struct sockaddr *sap, size_t sap_len,
+          ctl_clntdone donefunc, void *uap,
+          u_int timeout, ctl_logfunc logger)
+{
+       static const char me[] = "ctl_client";
+       static const int on = 1;
+       struct ctl_cctx *ctx;
+
+       if (logger == NULL)
+               logger = ctl_logger;
+       ctx = memget(sizeof *ctx);
+       if (ctx == NULL) {
+               (*logger)(ctl_error, "%s: getmem: %s", me, strerror(errno));
+               goto fatal;
+       }
+       ctx->state = initializing;
+       ctx->ev = lev;
+       ctx->logger = logger;
+       ctx->timeout = evConsTime(timeout, 0);
+       ctx->donefunc = donefunc;
+       ctx->uap = uap;
+       ctx->coID.opaque = NULL;
+       ctx->tiID.opaque = NULL;
+       ctx->rdID.opaque = NULL;
+       ctx->wrID.opaque = NULL;
+       buffer_init(ctx->inbuf);
+       INIT_LIST(ctx->tran);
+       INIT_LIST(ctx->wtran);
+       ctx->sock = socket(sap->sa_family, SOCK_STREAM, PF_UNSPEC);
+       if (ctx->sock > evHighestFD(ctx->ev)) {
+               ctx->sock = -1;
+               errno = ENOTSOCK;
+       }
+       if (ctx->sock < 0) {
+               (*ctx->logger)(ctl_error, "%s: socket: %s",
+                              me, strerror(errno));
+               goto fatal;
+       }
+       if (cap != NULL) {
+               if (setsockopt(ctx->sock, SOL_SOCKET, SO_REUSEADDR,
+                              (char *)&on, sizeof on) != 0) {
+                       (*ctx->logger)(ctl_warning,
+                                      "%s: setsockopt(REUSEADDR): %s",
+                                      me, strerror(errno));
+               }
+               if (bind(ctx->sock, cap, cap_len) < 0) {
+                       (*ctx->logger)(ctl_error, "%s: bind: %s", me,
+                                      strerror(errno));
+                       goto fatal;
+               }
+       }
+       if (evConnect(lev, ctx->sock, (struct sockaddr *)sap, sap_len,
+                     conn_done, ctx, &ctx->coID) < 0) {
+               (*ctx->logger)(ctl_error, "%s: evConnect(fd %d): %s",
+                              me, ctx->sock, strerror(errno));
+ fatal:
+               if (ctx != NULL) {
+                       if (ctx->sock >= 0)
+                               close(ctx->sock);
+                       memput(ctx, sizeof *ctx);
+               }
+               return (NULL);
+       }
+       new_state(ctx, connecting);
+       return (ctx);
+}
+
+/*
+ * void
+ * ctl_endclient(ctx)
+ *     close a client and release all of its resources.
+ */
+void
+ctl_endclient(struct ctl_cctx *ctx) {
+       if (ctx->state != destroyed)
+               destroy(ctx, 0);
+       memput(ctx, sizeof *ctx);
+}
+
+/*
+ * int
+ * ctl_command(ctx, cmd, len, donefunc, uap)
+ *     Queue a transaction, which will begin with sending cmd
+ *     and complete by calling donefunc with the answer.
+ */
+int
+ctl_command(struct ctl_cctx *ctx, const char *cmd, size_t len,
+           ctl_clntdone donefunc, void *uap)
+{
+       struct ctl_tran *tran;
+       char *pc;
+       int n;
+
+       switch (ctx->state) {
+       case destroyed:
+               errno = ENOTCONN;
+               return (-1);
+       case connecting:
+       case connected:
+               break;
+       default:
+               abort();
+       }
+       if (len >= MAX_LINELEN) {
+               errno = EMSGSIZE;
+               return (-1);
+       }
+       tran = new_tran(ctx, donefunc, uap, 1);
+       if (tran == NULL)
+               return (-1);
+       if (ctl_bufget(&tran->outbuf, ctx->logger) < 0)
+               return (-1);
+       memcpy(tran->outbuf.text, cmd, len);
+       tran->outbuf.used = len;
+       for (pc = tran->outbuf.text, n = 0; n < tran->outbuf.used; pc++, n++)
+               if (!isascii(*pc) || !isprint(*pc))
+                       *pc = '\040';
+       start_write(ctx);
+       return (0);
+}
+
+/* Private. */
+
+static struct ctl_tran *
+new_tran(struct ctl_cctx *ctx, ctl_clntdone donefunc, void *uap, int w) {
+       struct ctl_tran *new = memget(sizeof *new);
+
+       if (new == NULL)
+               return (NULL);
+       new->ctx = ctx;
+       buffer_init(new->outbuf);
+       new->donefunc = donefunc;
+       new->uap = uap;
+       APPEND(ctx->tran, new, link);
+       if (w)
+               APPEND(ctx->wtran, new, wlink);
+       else
+               INIT_LINK(new, wlink);
+       return (new);
+}
+
+static void
+start_write(struct ctl_cctx *ctx) {
+       static const char me[] = "isc/ctl_clnt::start_write";
+       struct ctl_tran *tran;
+       struct iovec iov[2], *iovp = iov;
+
+       REQUIRE(ctx->state == connecting || ctx->state == connected);
+       /* If there is a write in progress, don't try to write more yet. */
+       if (ctx->wrID.opaque != NULL)
+               return;
+       /* If there are no trans, make sure timer is off, and we're done. */
+       if (EMPTY(ctx->wtran)) {
+               if (ctx->tiID.opaque != NULL)
+                       stop_timer(ctx);
+               return;
+       }
+       /* Pull it off the head of the write queue. */
+       tran = HEAD(ctx->wtran);
+       UNLINK(ctx->wtran, tran, wlink);
+       /* Since there are some trans, make sure timer is successfully "on". */
+       if (ctx->tiID.opaque != NULL)
+               touch_timer(ctx);
+       else



Home | Main Index | Thread Index | Old Index