summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2020-01-20 18:43:23 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2020-01-20 18:43:23 +0000
commit341c02896d7ac6476221ea673d225b2baa74bce1 (patch)
treef69125f1a935949317f0dd4df0436876d24846c1 /usr.sbin
parentf53025f14cd9add10ba1a0816557c11c3747bdf6 (diff)
We are not using json, xml nor httpd.
OK millert
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bind/lib/isc/Makefile.in4
-rw-r--r--usr.sbin/bind/lib/isc/httpd.c1129
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/Makefile.in7
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/httpd.h86
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/json.h49
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/mem.h20
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/socket.h22
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/task.h16
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/xml.h41
-rw-r--r--usr.sbin/bind/lib/isc/mem.c327
-rw-r--r--usr.sbin/bind/lib/isc/task.c206
-rw-r--r--usr.sbin/bind/lib/isc/unix/socket.c281
12 files changed, 19 insertions, 2169 deletions
diff --git a/usr.sbin/bind/lib/isc/Makefile.in b/usr.sbin/bind/lib/isc/Makefile.in
index 890d26b100f..5b0d12321a2 100644
--- a/usr.sbin/bind/lib/isc/Makefile.in
+++ b/usr.sbin/bind/lib/isc/Makefile.in
@@ -49,7 +49,7 @@ OBJS = @ISC_EXTRA_OBJS@ @ISC_PK11_O@ @ISC_PK11_RESULT_O@ \
bind9.@O@ buffer.@O@ bufferlist.@O@ \
commandline.@O@ counter.@O@ crc64.@O@ error.@O@ event.@O@ \
hash.@O@ heap.@O@ hex.@O@ hmacmd5.@O@ hmacsha.@O@ \
- httpd.@O@ inet_aton.@O@ iterated_hash.@O@ \
+ inet_aton.@O@ iterated_hash.@O@ \
lex.@O@ lfsr.@O@ lib.@O@ log.@O@ \
md5.@O@ mem.@O@ mutexblock.@O@ \
netaddr.@O@ netscope.@O@ pool.@O@ ondestroy.@O@ \
@@ -66,7 +66,7 @@ SRCS = @ISC_EXTRA_SRCS@ @ISC_PK11_C@ @ISC_PK11_RESULT_C@ \
aes.c assertions.c base32.c base64.c bind9.c \
buffer.c bufferlist.c commandline.c counter.c crc64.c \
error.c event.c heap.c hex.c hmacmd5.c hmacsha.c \
- httpd.c inet_aton.c iterated_hash.c \
+ inet_aton.c iterated_hash.c \
lex.c lfsr.c lib.c log.c \
md5.c mem.c mutexblock.c \
netaddr.c netscope.c pool.c ondestroy.c \
diff --git a/usr.sbin/bind/lib/isc/httpd.c b/usr.sbin/bind/lib/isc/httpd.c
deleted file mode 100644
index 4b33468bcb5..00000000000
--- a/usr.sbin/bind/lib/isc/httpd.c
+++ /dev/null
@@ -1,1129 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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.
- */
-
-/* $Id: httpd.c,v 1.4 2020/01/09 18:17:19 florian Exp $ */
-
-/*! \file */
-
-#include <config.h>
-
-#include <isc/buffer.h>
-#include <isc/httpd.h>
-#include <isc/mem.h>
-
-#include <isc/socket.h>
-#include <isc/string.h>
-#include <isc/task.h>
-#include <isc/time.h>
-#include <isc/util.h>
-
-#include <string.h>
-
-/*%
- * TODO:
- *
- * o Put in better checks to make certain things are passed in correctly.
- * This includes a magic number for externally-visible structures,
- * checking for NULL-ness before dereferencing, etc.
- * o Make the URL processing external functions which will fill-in a buffer
- * structure we provide, or return an error and we will render a generic
- * page and close the client.
- */
-
-#define MSHUTTINGDOWN(cm) ((cm->flags & ISC_HTTPDMGR_FLAGSHUTTINGDOWN) != 0)
-#define MSETSHUTTINGDOWN(cm) (cm->flags |= ISC_HTTPDMGR_FLAGSHUTTINGDOWN)
-
-#ifdef DEBUG_HTTPD
-#define ENTER(x) do { fprintf(stderr, "ENTER %s\n", (x)); } while (0)
-#define EXIT(x) do { fprintf(stderr, "EXIT %s\n", (x)); } while (0)
-#define NOTICE(x) do { fprintf(stderr, "NOTICE %s\n", (x)); } while (0)
-#else
-#define ENTER(x) do { } while(0)
-#define EXIT(x) do { } while(0)
-#define NOTICE(x) do { } while(0)
-#endif
-
-#define HTTP_RECVLEN 1024
-#define HTTP_SENDGROW 1024
-#define HTTP_SEND_MAXLEN 10240
-
-#define HTTPD_CLOSE 0x0001 /* Got a Connection: close header */
-#define HTTPD_FOUNDHOST 0x0002 /* Got a Host: header */
-#define HTTPD_KEEPALIVE 0x0004 /* Got a Connection: Keep-Alive */
-
-/*% http client */
-struct isc_httpd {
- isc_httpdmgr_t *mgr; /*%< our parent */
- ISC_LINK(isc_httpd_t) link;
- unsigned int state;
- isc_socket_t *sock;
-
- /*%
- * Received data state.
- */
- char recvbuf[HTTP_RECVLEN]; /*%< receive buffer */
- uint32_t recvlen; /*%< length recv'd */
- char *headers; /*%< set in process_request() */
- unsigned int method;
- char *url;
- char *querystring;
- char *protocol;
-
- /*
- * Flags on the httpd client.
- */
- int flags;
-
- /*%
- * Transmit data state.
- *
- * This is the data buffer we will transmit.
- *
- * This free function pointer is filled in by the rendering function
- * we call. The free function is called after the data is transmitted
- * to the client.
- *
- * The bufflist is the list of buffers we are currently transmitting.
- * The headerdata is where we render our headers to. If we run out of
- * space when rendering a header, we will change the size of our
- * buffer. We will not free it until we are finished, and will
- * allocate an additional HTTP_SENDGROW bytes per header space grow.
- *
- * We currently use two buffers total, one for the headers (which
- * we manage) and another for the client to fill in (which it manages,
- * it provides the space for it, etc) -- we will pass that buffer
- * structure back to the caller, who is responsible for managing the
- * space it may have allocated as backing store for it. This second
- * buffer is bodybuffer, and we only allocate the buffer itself, not
- * the backing store.
- */
- isc_bufferlist_t bufflist;
- char *headerdata; /*%< send header buf */
- unsigned int headerlen; /*%< current header buffer size */
- isc_buffer_t headerbuffer;
-
- const char *mimetype;
- unsigned int retcode;
- const char *retmsg;
- isc_buffer_t bodybuffer;
- isc_httpdfree_t *freecb;
- void *freecb_arg;
-};
-
-/*% lightweight socket manager for httpd output */
-struct isc_httpdmgr {
- isc_mem_t *mctx;
- isc_socket_t *sock; /*%< listening socket */
- isc_task_t *task; /*%< owning task */
- isc_timermgr_t *timermgr;
-
- isc_httpdclientok_t *client_ok; /*%< client validator */
- isc_httpdondestroy_t *ondestroy; /*%< cleanup callback */
- void *cb_arg; /*%< argument for the above */
-
- unsigned int flags;
- ISC_LIST(isc_httpd_t) running; /*%< running clients */
-
- isc_mutex_t lock;
-
- ISC_LIST(isc_httpdurl_t) urls; /*%< urls we manage */
- isc_httpdaction_t *render_404;
- isc_httpdaction_t *render_500;
-};
-
-/*%
- * HTTP methods.
- */
-#define ISC_HTTPD_METHODUNKNOWN 0
-#define ISC_HTTPD_METHODGET 1
-#define ISC_HTTPD_METHODPOST 2
-
-/*%
- * Client states.
- *
- * _IDLE The client is not doing anything at all. This state should
- * only occur just after creation, and just before being
- * destroyed.
- *
- * _RECV The client is waiting for data after issuing a socket recv().
- *
- * _RECVDONE Data has been received, and is being processed.
- *
- * _SEND All data for a response has completed, and a reply was
- * sent via a socket send() call.
- *
- * _SENDDONE Send is completed.
- *
- * Badly formatted state table:
- *
- * IDLE -> RECV when client has a recv() queued.
- *
- * RECV -> RECVDONE when recvdone event received.
- *
- * RECVDONE -> SEND if the data for a reply is at hand.
- *
- * SEND -> RECV when a senddone event was received.
- *
- * At any time -> RECV on error. If RECV fails, the client will
- * self-destroy, closing the socket and freeing memory.
- */
-#define ISC_HTTPD_STATEIDLE 0
-#define ISC_HTTPD_STATERECV 1
-#define ISC_HTTPD_STATERECVDONE 2
-#define ISC_HTTPD_STATESEND 3
-#define ISC_HTTPD_STATESENDDONE 4
-
-#define ISC_HTTPD_ISRECV(c) ((c)->state == ISC_HTTPD_STATERECV)
-#define ISC_HTTPD_ISRECVDONE(c) ((c)->state == ISC_HTTPD_STATERECVDONE)
-#define ISC_HTTPD_ISSEND(c) ((c)->state == ISC_HTTPD_STATESEND)
-#define ISC_HTTPD_ISSENDDONE(c) ((c)->state == ISC_HTTPD_STATESENDDONE)
-
-/*%
- * Overall magic test that means we're not idle.
- */
-#define ISC_HTTPD_SETRECV(c) ((c)->state = ISC_HTTPD_STATERECV)
-#define ISC_HTTPD_SETRECVDONE(c) ((c)->state = ISC_HTTPD_STATERECVDONE)
-#define ISC_HTTPD_SETSEND(c) ((c)->state = ISC_HTTPD_STATESEND)
-#define ISC_HTTPD_SETSENDDONE(c) ((c)->state = ISC_HTTPD_STATESENDDONE)
-
-static void isc_httpd_accept(isc_task_t *, isc_event_t *);
-static void isc_httpd_recvdone(isc_task_t *, isc_event_t *);
-static void isc_httpd_senddone(isc_task_t *, isc_event_t *);
-static void destroy_client(isc_httpd_t **);
-static isc_result_t process_request(isc_httpd_t *, int);
-static void httpdmgr_destroy(isc_httpdmgr_t *);
-static isc_result_t grow_headerspace(isc_httpd_t *);
-static void reset_client(isc_httpd_t *httpd);
-
-static isc_httpdaction_t render_404;
-static isc_httpdaction_t render_500;
-
-static void
-destroy_client(isc_httpd_t **httpdp) {
- isc_httpd_t *httpd = *httpdp;
- isc_httpdmgr_t *httpdmgr = httpd->mgr;
-
- *httpdp = NULL;
-
- LOCK(&httpdmgr->lock);
-
- isc_socket_detach(&httpd->sock);
- ISC_LIST_UNLINK(httpdmgr->running, httpd, link);
-
- if (httpd->headerlen > 0)
- isc_mem_put(httpdmgr->mctx, httpd->headerdata,
- httpd->headerlen);
-
- isc_mem_put(httpdmgr->mctx, httpd, sizeof(isc_httpd_t));
-
- UNLOCK(&httpdmgr->lock);
-
- httpdmgr_destroy(httpdmgr);
-}
-
-isc_result_t
-isc_httpdmgr_create(isc_mem_t *mctx, isc_socket_t *sock, isc_task_t *task,
- isc_httpdclientok_t *client_ok,
- isc_httpdondestroy_t *ondestroy, void *cb_arg,
- isc_timermgr_t *tmgr, isc_httpdmgr_t **httpdmgrp)
-{
- isc_result_t result;
- isc_httpdmgr_t *httpdmgr;
-
- REQUIRE(mctx != NULL);
- REQUIRE(sock != NULL);
- REQUIRE(task != NULL);
- REQUIRE(tmgr != NULL);
- REQUIRE(httpdmgrp != NULL && *httpdmgrp == NULL);
-
- httpdmgr = isc_mem_get(mctx, sizeof(isc_httpdmgr_t));
- if (httpdmgr == NULL)
- return (ISC_R_NOMEMORY);
-
- result = isc_mutex_init(&httpdmgr->lock);
- if (result != ISC_R_SUCCESS) {
- isc_mem_put(mctx, httpdmgr, sizeof(isc_httpdmgr_t));
- return (result);
- }
- httpdmgr->mctx = NULL;
- isc_mem_attach(mctx, &httpdmgr->mctx);
- httpdmgr->sock = NULL;
- isc_socket_attach(sock, &httpdmgr->sock);
- httpdmgr->task = NULL;
- isc_task_attach(task, &httpdmgr->task);
- httpdmgr->timermgr = tmgr; /* XXXMLG no attach function? */
- httpdmgr->client_ok = client_ok;
- httpdmgr->ondestroy = ondestroy;
- httpdmgr->cb_arg = cb_arg;
- httpdmgr->flags = 0;
-
- ISC_LIST_INIT(httpdmgr->running);
- ISC_LIST_INIT(httpdmgr->urls);
-
- /* XXXMLG ignore errors on isc_socket_listen() */
- result = isc_socket_listen(sock, SOMAXCONN);
- if (result != ISC_R_SUCCESS) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_socket_listen() failed: %s",
- isc_result_totext(result));
- goto cleanup;
- }
-
- (void)isc_socket_filter(sock, "httpready");
-
- result = isc_socket_accept(sock, task, isc_httpd_accept, httpdmgr);
- if (result != ISC_R_SUCCESS)
- goto cleanup;
-
- httpdmgr->render_404 = render_404;
- httpdmgr->render_500 = render_500;
-
- *httpdmgrp = httpdmgr;
- return (ISC_R_SUCCESS);
-
- cleanup:
- isc_task_detach(&httpdmgr->task);
- isc_socket_detach(&httpdmgr->sock);
- isc_mem_detach(&httpdmgr->mctx);
- (void)isc_mutex_destroy(&httpdmgr->lock);
- isc_mem_put(mctx, httpdmgr, sizeof(isc_httpdmgr_t));
- return (result);
-}
-
-static void
-httpdmgr_destroy(isc_httpdmgr_t *httpdmgr) {
- isc_mem_t *mctx;
- isc_httpdurl_t *url;
-
- ENTER("httpdmgr_destroy");
-
- LOCK(&httpdmgr->lock);
-
- if (!MSHUTTINGDOWN(httpdmgr)) {
- NOTICE("httpdmgr_destroy not shutting down yet");
- UNLOCK(&httpdmgr->lock);
- return;
- }
-
- /*
- * If all clients are not shut down, don't do anything yet.
- */
- if (!ISC_LIST_EMPTY(httpdmgr->running)) {
- NOTICE("httpdmgr_destroy clients still active");
- UNLOCK(&httpdmgr->lock);
- return;
- }
-
- NOTICE("httpdmgr_destroy detaching socket, task, and timermgr");
-
- isc_socket_detach(&httpdmgr->sock);
- isc_task_detach(&httpdmgr->task);
- httpdmgr->timermgr = NULL;
-
- /*
- * Clear out the list of all actions we know about. Just free the
- * memory.
- */
- url = ISC_LIST_HEAD(httpdmgr->urls);
- while (url != NULL) {
- isc_mem_free(httpdmgr->mctx, url->url);
- ISC_LIST_UNLINK(httpdmgr->urls, url, link);
- isc_mem_put(httpdmgr->mctx, url, sizeof(isc_httpdurl_t));
- url = ISC_LIST_HEAD(httpdmgr->urls);
- }
-
- UNLOCK(&httpdmgr->lock);
- (void)isc_mutex_destroy(&httpdmgr->lock);
-
- if (httpdmgr->ondestroy != NULL)
- (httpdmgr->ondestroy)(httpdmgr->cb_arg);
-
- mctx = httpdmgr->mctx;
- isc_mem_putanddetach(&mctx, httpdmgr, sizeof(isc_httpdmgr_t));
-
- EXIT("httpdmgr_destroy");
-}
-
-#define LENGTHOK(s) (httpd->recvbuf - (s) < (int)httpd->recvlen)
-#define BUFLENOK(s) (httpd->recvbuf - (s) < HTTP_RECVLEN)
-
-/*
- * Look for the given header in headers.
- * If value is specified look for it terminated with a character in eov.
- */
-static isc_boolean_t
-have_header(isc_httpd_t *httpd, const char *header, const char *value,
- const char *eov)
-{
- char *cr, *nl, *h;
- size_t hlen, vlen = 0;
-
- h = httpd->headers;
- hlen = strlen(header);
- if (value != NULL) {
- INSIST(eov != NULL);
- vlen = strlen(value);
- }
-
- for (;;) {
- if (strncasecmp(h, header, hlen) != 0) {
- /*
- * Skip to next line;
- */
- cr = strchr(h, '\r');
- if (cr != NULL && cr[1] == '\n')
- cr++;
- nl = strchr(h, '\n');
-
- /* last header? */
- h = cr;
- if (h == NULL || (nl != NULL && nl < h))
- h = nl;
- if (h == NULL)
- return (ISC_FALSE);
- h++;
- continue;
- }
-
- if (value == NULL)
- return (ISC_TRUE);
-
- /*
- * Skip optional leading white space.
- */
- h += hlen;
- while (*h == ' ' || *h == '\t')
- h++;
- /*
- * Terminate token search on NULL or EOL.
- */
- while (*h != 0 && *h != '\r' && *h != '\n') {
- if (strncasecmp(h, value, vlen) == 0)
- if (strchr(eov, h[vlen]) != NULL)
- return (ISC_TRUE);
- /*
- * Skip to next token.
- */
- h += strcspn(h, eov);
- if (h[0] == '\r' && h[1] == '\n')
- h++;
- if (h[0] != 0)
- h++;
- }
- return (ISC_FALSE);
- }
-}
-
-static isc_result_t
-process_request(isc_httpd_t *httpd, int length) {
- char *s;
- char *p;
- int delim;
-
- ENTER("request");
-
- httpd->recvlen += length;
-
- httpd->recvbuf[httpd->recvlen] = 0;
- httpd->headers = NULL;
-
- /*
- * If we don't find a blank line in our buffer, return that we need
- * more data.
- */
- s = strstr(httpd->recvbuf, "\r\n\r\n");
- delim = 2;
- if (s == NULL) {
- s = strstr(httpd->recvbuf, "\n\n");
- delim = 1;
- }
- if (s == NULL)
- return (ISC_R_NOTFOUND);
-
- /*
- * NUL terminate request at the blank line.
- */
- s[delim] = 0;
-
- /*
- * Determine if this is a POST or GET method. Any other values will
- * cause an error to be returned.
- */
- if (strncmp(httpd->recvbuf, "GET ", 4) == 0) {
- httpd->method = ISC_HTTPD_METHODGET;
- p = httpd->recvbuf + 4;
- } else if (strncmp(httpd->recvbuf, "POST ", 5) == 0) {
- httpd->method = ISC_HTTPD_METHODPOST;
- p = httpd->recvbuf + 5;
- } else {
- return (ISC_R_RANGE);
- }
-
- /*
- * From now on, p is the start of our buffer.
- */
-
- /*
- * Extract the URL.
- */
- s = p;
- while (LENGTHOK(s) && BUFLENOK(s) &&
- (*s != '\n' && *s != '\r' && *s != '\0' && *s != ' '))
- s++;
- if (!LENGTHOK(s))
- return (ISC_R_NOTFOUND);
- if (!BUFLENOK(s))
- return (ISC_R_NOMEMORY);
- *s = 0;
-
- /*
- * Make the URL relative.
- */
- if ((strncmp(p, "http:/", 6) == 0)
- || (strncmp(p, "https:/", 7) == 0)) {
- /* Skip first / */
- while (*p != '/' && *p != 0)
- p++;
- if (*p == 0)
- return (ISC_R_RANGE);
- p++;
- /* Skip second / */
- while (*p != '/' && *p != 0)
- p++;
- if (*p == 0)
- return (ISC_R_RANGE);
- p++;
- /* Find third / */
- while (*p != '/' && *p != 0)
- p++;
- if (*p == 0) {
- p--;
- *p = '/';
- }
- }
-
- httpd->url = p;
- p = s + 1;
- s = p;
-
- /*
- * Now, see if there is a ? mark in the URL. If so, this is
- * part of the query string, and we will split it from the URL.
- */
- httpd->querystring = strchr(httpd->url, '?');
- if (httpd->querystring != NULL) {
- *(httpd->querystring) = 0;
- httpd->querystring++;
- }
-
- /*
- * Extract the HTTP/1.X protocol. We will bounce on anything but
- * HTTP/1.0 or HTTP/1.1 for now.
- */
- while (LENGTHOK(s) && BUFLENOK(s) &&
- (*s != '\n' && *s != '\r' && *s != '\0'))
- s++;
- if (!LENGTHOK(s))
- return (ISC_R_NOTFOUND);
- if (!BUFLENOK(s))
- return (ISC_R_NOMEMORY);
- /*
- * Check that we have the expected eol delimiter.
- */
- if (strncmp(s, delim == 1 ? "\n" : "\r\n", delim) != 0)
- return (ISC_R_RANGE);
- *s = 0;
- if ((strncmp(p, "HTTP/1.0", 8) != 0)
- && (strncmp(p, "HTTP/1.1", 8) != 0))
- return (ISC_R_RANGE);
- httpd->protocol = p;
- p = s + delim; /* skip past eol */
- s = p;
-
- httpd->headers = s;
-
- if (have_header(httpd, "Connection:", "close", ", \t\r\n"))
- httpd->flags |= HTTPD_CLOSE;
-
- if (have_header(httpd, "Host:", NULL, NULL))
- httpd->flags |= HTTPD_FOUNDHOST;
-
- if (strncmp(httpd->protocol, "HTTP/1.0", 8) == 0) {
- if (have_header(httpd, "Connection:", "Keep-Alive",
- ", \t\r\n"))
- httpd->flags |= HTTPD_KEEPALIVE;
- else
- httpd->flags |= HTTPD_CLOSE;
- }
-
- /*
- * Standards compliance hooks here.
- */
- if (strcmp(httpd->protocol, "HTTP/1.1") == 0
- && ((httpd->flags & HTTPD_FOUNDHOST) == 0))
- return (ISC_R_RANGE);
-
- EXIT("request");
-
- return (ISC_R_SUCCESS);
-}
-
-static void
-isc_httpd_accept(isc_task_t *task, isc_event_t *ev) {
- isc_result_t result;
- isc_httpdmgr_t *httpdmgr = ev->ev_arg;
- isc_httpd_t *httpd;
- isc_region_t r;
- isc_socket_newconnev_t *nev = (isc_socket_newconnev_t *)ev;
- isc_sockaddr_t peeraddr;
-
- ENTER("accept");
-
- LOCK(&httpdmgr->lock);
- if (MSHUTTINGDOWN(httpdmgr)) {
- NOTICE("accept shutting down, goto out");
- goto out;
- }
-
- if (nev->result == ISC_R_CANCELED) {
- NOTICE("accept canceled, goto out");
- goto out;
- }
-
- if (nev->result != ISC_R_SUCCESS) {
- /* XXXMLG log failure */
- NOTICE("accept returned failure, goto requeue");
- goto requeue;
- }
-
- (void)isc_socket_getpeername(nev->newsocket, &peeraddr);
- if (httpdmgr->client_ok != NULL &&
- !(httpdmgr->client_ok)(&peeraddr, httpdmgr->cb_arg)) {
- isc_socket_detach(&nev->newsocket);
- goto requeue;
- }
-
- httpd = isc_mem_get(httpdmgr->mctx, sizeof(isc_httpd_t));
- if (httpd == NULL) {
- /* XXXMLG log failure */
- NOTICE("accept failed to allocate memory, goto requeue");
- isc_socket_detach(&nev->newsocket);
- goto requeue;
- }
-
- httpd->mgr = httpdmgr;
- ISC_LINK_INIT(httpd, link);
- ISC_LIST_APPEND(httpdmgr->running, httpd, link);
- ISC_HTTPD_SETRECV(httpd);
- httpd->sock = nev->newsocket;
- isc_socket_setname(httpd->sock, "httpd", NULL);
- httpd->flags = 0;
-
- /*
- * Initialize the buffer for our headers.
- */
- httpd->headerdata = isc_mem_get(httpdmgr->mctx, HTTP_SENDGROW);
- if (httpd->headerdata == NULL) {
- isc_mem_put(httpdmgr->mctx, httpd, sizeof(isc_httpd_t));
- isc_socket_detach(&nev->newsocket);
- goto requeue;
- }
- httpd->headerlen = HTTP_SENDGROW;
- isc_buffer_init(&httpd->headerbuffer, httpd->headerdata,
- httpd->headerlen);
-
- ISC_LIST_INIT(httpd->bufflist);
-
- isc_buffer_initnull(&httpd->bodybuffer);
- reset_client(httpd);
-
- r.base = (unsigned char *)httpd->recvbuf;
- r.length = HTTP_RECVLEN - 1;
- result = isc_socket_recv(httpd->sock, &r, 1, task, isc_httpd_recvdone,
- httpd);
- /* FIXME!!! */
- POST(result);
- NOTICE("accept queued recv on socket");
-
- requeue:
- result = isc_socket_accept(httpdmgr->sock, task, isc_httpd_accept,
- httpdmgr);
- if (result != ISC_R_SUCCESS) {
- /* XXXMLG what to do? Log failure... */
- NOTICE("accept could not reaccept due to failure");
- }
-
- out:
- UNLOCK(&httpdmgr->lock);
-
- httpdmgr_destroy(httpdmgr);
-
- isc_event_free(&ev);
-
- EXIT("accept");
-}
-
-static isc_result_t
-render_404(const char *url, isc_httpdurl_t *urlinfo,
- const char *querystring, const char *headers, void *arg,
- unsigned int *retcode, const char **retmsg,
- const char **mimetype, isc_buffer_t *b,
- isc_httpdfree_t **freecb, void **freecb_args)
-{
- static char msg[] = "No such URL.\r\n";
-
- UNUSED(url);
- UNUSED(urlinfo);
- UNUSED(querystring);
- UNUSED(headers);
- UNUSED(arg);
-
- *retcode = 404;
- *retmsg = "No such URL";
- *mimetype = "text/plain";
- isc_buffer_reinit(b, msg, strlen(msg));
- isc_buffer_add(b, strlen(msg));
- *freecb = NULL;
- *freecb_args = NULL;
-
- return (ISC_R_SUCCESS);
-}
-
-static isc_result_t
-render_500(const char *url, isc_httpdurl_t *urlinfo,
- const char *querystring, const char *headers, void *arg,
- unsigned int *retcode, const char **retmsg,
- const char **mimetype, isc_buffer_t *b,
- isc_httpdfree_t **freecb, void **freecb_args)
-{
- static char msg[] = "Internal server failure.\r\n";
-
- UNUSED(url);
- UNUSED(urlinfo);
- UNUSED(querystring);
- UNUSED(headers);
- UNUSED(arg);
-
- *retcode = 500;
- *retmsg = "Internal server failure";
- *mimetype = "text/plain";
- isc_buffer_reinit(b, msg, strlen(msg));
- isc_buffer_add(b, strlen(msg));
- *freecb = NULL;
- *freecb_args = NULL;
-
- return (ISC_R_SUCCESS);
-}
-
-static void
-isc_httpd_recvdone(isc_task_t *task, isc_event_t *ev) {
- isc_region_t r;
- isc_result_t result;
- isc_httpd_t *httpd = ev->ev_arg;
- isc_socketevent_t *sev = (isc_socketevent_t *)ev;
- isc_httpdurl_t *url;
- isc_time_t now;
- char datebuf[ISC_FORMATHTTPTIMESTAMP_SIZE];
-
- ENTER("recv");
-
- INSIST(ISC_HTTPD_ISRECV(httpd));
-
- if (sev->result != ISC_R_SUCCESS) {
- NOTICE("recv destroying client");
- destroy_client(&httpd);
- goto out;
- }
-
- result = process_request(httpd, sev->n);
- if (result == ISC_R_NOTFOUND) {
- if (httpd->recvlen >= HTTP_RECVLEN - 1) {
- destroy_client(&httpd);
- goto out;
- }
- r.base = (unsigned char *)httpd->recvbuf + httpd->recvlen;
- r.length = HTTP_RECVLEN - httpd->recvlen - 1;
- /* check return code? */
- (void)isc_socket_recv(httpd->sock, &r, 1, task,
- isc_httpd_recvdone, httpd);
- goto out;
- } else if (result != ISC_R_SUCCESS) {
- destroy_client(&httpd);
- goto out;
- }
-
- ISC_HTTPD_SETSEND(httpd);
-
- /*
- * XXXMLG Call function here. Provide an add-header function
- * which will append the common headers to a response we generate.
- */
- isc_buffer_initnull(&httpd->bodybuffer);
- isc_time_now(&now);
- isc_time_formathttptimestamp(&now, datebuf, sizeof(datebuf));
- url = ISC_LIST_HEAD(httpd->mgr->urls);
- while (url != NULL) {
- if (strcmp(httpd->url, url->url) == 0)
- break;
- url = ISC_LIST_NEXT(url, link);
- }
- if (url == NULL)
- result = httpd->mgr->render_404(httpd->url, NULL,
- httpd->querystring,
- NULL, NULL,
- &httpd->retcode,
- &httpd->retmsg,
- &httpd->mimetype,
- &httpd->bodybuffer,
- &httpd->freecb,
- &httpd->freecb_arg);
- else
- result = url->action(httpd->url, url,
- httpd->querystring,
- httpd->headers,
- url->action_arg,
- &httpd->retcode, &httpd->retmsg,
- &httpd->mimetype, &httpd->bodybuffer,
- &httpd->freecb, &httpd->freecb_arg);
- if (result != ISC_R_SUCCESS) {
- result = httpd->mgr->render_500(httpd->url, url,
- httpd->querystring,
- NULL, NULL,
- &httpd->retcode,
- &httpd->retmsg,
- &httpd->mimetype,
- &httpd->bodybuffer,
- &httpd->freecb,
- &httpd->freecb_arg);
- RUNTIME_CHECK(result == ISC_R_SUCCESS);
- }
-
- isc_httpd_response(httpd);
- if ((httpd->flags & HTTPD_KEEPALIVE) != 0)
- isc_httpd_addheader(httpd, "Connection", "Keep-Alive");
- isc_httpd_addheader(httpd, "Content-Type", httpd->mimetype);
- isc_httpd_addheader(httpd, "Date", datebuf);
- isc_httpd_addheader(httpd, "Expires", datebuf);
-
- if (url != NULL && url->isstatic) {
- char loadbuf[ISC_FORMATHTTPTIMESTAMP_SIZE];
- isc_time_formathttptimestamp(&url->loadtime,
- loadbuf, sizeof(loadbuf));
- isc_httpd_addheader(httpd, "Last-Modified", loadbuf);
- isc_httpd_addheader(httpd, "Cache-Control: public", NULL);
- } else {
- isc_httpd_addheader(httpd, "Last-Modified", datebuf);
- isc_httpd_addheader(httpd, "Pragma: no-cache", NULL);
- isc_httpd_addheader(httpd, "Cache-Control: no-cache", NULL);
- }
-
- isc_httpd_addheader(httpd, "Server: libisc", NULL);
- isc_httpd_addheaderuint(httpd, "Content-Length",
- isc_buffer_usedlength(&httpd->bodybuffer));
- isc_httpd_endheaders(httpd); /* done */
-
- ISC_LIST_APPEND(httpd->bufflist, &httpd->headerbuffer, link);
- /*
- * Link the data buffer into our send queue, should we have any data
- * rendered into it. If no data is present, we won't do anything
- * with the buffer.
- */
- if (isc_buffer_length(&httpd->bodybuffer) > 0)
- ISC_LIST_APPEND(httpd->bufflist, &httpd->bodybuffer, link);
-
- /* check return code? */
- (void)isc_socket_sendv(httpd->sock, &httpd->bufflist, task,
- isc_httpd_senddone, httpd);
-
- out:
- isc_event_free(&ev);
- EXIT("recv");
-}
-
-void
-isc_httpdmgr_shutdown(isc_httpdmgr_t **httpdmgrp) {
- isc_httpdmgr_t *httpdmgr;
- isc_httpd_t *httpd;
- httpdmgr = *httpdmgrp;
- *httpdmgrp = NULL;
-
- ENTER("isc_httpdmgr_shutdown");
-
- LOCK(&httpdmgr->lock);
-
- MSETSHUTTINGDOWN(httpdmgr);
-
- isc_socket_cancel(httpdmgr->sock, httpdmgr->task, ISC_SOCKCANCEL_ALL);
-
- httpd = ISC_LIST_HEAD(httpdmgr->running);
- while (httpd != NULL) {
- isc_socket_cancel(httpd->sock, httpdmgr->task,
- ISC_SOCKCANCEL_ALL);
- httpd = ISC_LIST_NEXT(httpd, link);
- }
-
- UNLOCK(&httpdmgr->lock);
-
- EXIT("isc_httpdmgr_shutdown");
-}
-
-static isc_result_t
-grow_headerspace(isc_httpd_t *httpd) {
- char *newspace;
- unsigned int newlen;
- isc_region_t r;
-
- newlen = httpd->headerlen + HTTP_SENDGROW;
- if (newlen > HTTP_SEND_MAXLEN)
- return (ISC_R_NOSPACE);
-
- newspace = isc_mem_get(httpd->mgr->mctx, newlen);
- if (newspace == NULL)
- return (ISC_R_NOMEMORY);
- isc_buffer_region(&httpd->headerbuffer, &r);
- isc_buffer_reinit(&httpd->headerbuffer, newspace, newlen);
-
- isc_mem_put(httpd->mgr->mctx, r.base, r.length);
-
- return (ISC_R_SUCCESS);
-}
-
-isc_result_t
-isc_httpd_response(isc_httpd_t *httpd) {
- isc_result_t result;
- unsigned int needlen;
-
- needlen = strlen(httpd->protocol) + 1; /* protocol + space */
- needlen += 3 + 1; /* room for response code, always 3 bytes */
- needlen += strlen(httpd->retmsg) + 2; /* return msg + CRLF */
-
- while (isc_buffer_availablelength(&httpd->headerbuffer) < needlen) {
- result = grow_headerspace(httpd);
- if (result != ISC_R_SUCCESS)
- return (result);
- }
-
- snprintf(isc_buffer_used(&httpd->headerbuffer),
- (int)isc_buffer_availablelength(&httpd->headerbuffer),
- "%s %03u %s\r\n", httpd->protocol, httpd->retcode,
- httpd->retmsg);
- isc_buffer_add(&httpd->headerbuffer, needlen);
-
- return (ISC_R_SUCCESS);
-}
-
-isc_result_t
-isc_httpd_addheader(isc_httpd_t *httpd, const char *name,
- const char *val)
-{
- isc_result_t result;
- unsigned int needlen;
-
- needlen = strlen(name); /* name itself */
- if (val != NULL)
- needlen += 2 + strlen(val); /* :<space> and val */
- needlen += 2; /* CRLF */
-
- while (isc_buffer_availablelength(&httpd->headerbuffer) < needlen) {
- result = grow_headerspace(httpd);
- if (result != ISC_R_SUCCESS)
- return (result);
- }
-
- if (val != NULL)
- snprintf(isc_buffer_used(&httpd->headerbuffer),
- isc_buffer_availablelength(&httpd->headerbuffer),
- "%s: %s\r\n", name, val);
- else
- snprintf(isc_buffer_used(&httpd->headerbuffer),
- isc_buffer_availablelength(&httpd->headerbuffer),
- "%s\r\n", name);
-
- isc_buffer_add(&httpd->headerbuffer, needlen);
-
- return (ISC_R_SUCCESS);
-}
-
-isc_result_t
-isc_httpd_endheaders(isc_httpd_t *httpd) {
- isc_result_t result;
-
- while (isc_buffer_availablelength(&httpd->headerbuffer) < 2) {
- result = grow_headerspace(httpd);
- if (result != ISC_R_SUCCESS)
- return (result);
- }
-
- snprintf(isc_buffer_used(&httpd->headerbuffer),
- isc_buffer_availablelength(&httpd->headerbuffer), "\r\n");
- isc_buffer_add(&httpd->headerbuffer, 2);
-
- return (ISC_R_SUCCESS);
-}
-
-isc_result_t
-isc_httpd_addheaderuint(isc_httpd_t *httpd, const char *name, int val) {
- isc_result_t result;
- unsigned int needlen;
- char buf[sizeof "18446744073709551616"];
-
- snprintf(buf, sizeof(buf), "%d", val);
-
- needlen = strlen(name); /* name itself */
- needlen += 2 + strlen(buf); /* :<space> and val */
- needlen += 2; /* CRLF */
-
- while (isc_buffer_availablelength(&httpd->headerbuffer) < needlen) {
- result = grow_headerspace(httpd);
- if (result != ISC_R_SUCCESS)
- return (result);
- }
-
- snprintf(isc_buffer_used(&httpd->headerbuffer),
- isc_buffer_availablelength(&httpd->headerbuffer),
- "%s: %s\r\n", name, buf);
-
- isc_buffer_add(&httpd->headerbuffer, needlen);
-
- return (ISC_R_SUCCESS);
-}
-
-static void
-isc_httpd_senddone(isc_task_t *task, isc_event_t *ev) {
- isc_httpd_t *httpd = ev->ev_arg;
- isc_region_t r;
- isc_socketevent_t *sev = (isc_socketevent_t *)ev;
-
- ENTER("senddone");
- INSIST(ISC_HTTPD_ISSEND(httpd));
-
- /*
- * First, unlink our header buffer from the socket's bufflist. This
- * is sort of an evil hack, since we know our buffer will be there,
- * and we know it's address, so we can just remove it directly.
- */
- NOTICE("senddone unlinked header");
- ISC_LIST_UNLINK(sev->bufferlist, &httpd->headerbuffer, link);
-
- /*
- * We will always want to clean up our receive buffer, even if we
- * got an error on send or we are shutting down.
- *
- * We will pass in the buffer only if there is data in it. If
- * there is no data, we will pass in a NULL.
- */
- if (httpd->freecb != NULL) {
- isc_buffer_t *b = NULL;
- if (isc_buffer_length(&httpd->bodybuffer) > 0) {
- b = &httpd->bodybuffer;
- httpd->freecb(b, httpd->freecb_arg);
- }
- NOTICE("senddone free callback performed");
- }
- if (ISC_LINK_LINKED(&httpd->bodybuffer, link)) {
- ISC_LIST_UNLINK(sev->bufferlist, &httpd->bodybuffer, link);
- NOTICE("senddone body buffer unlinked");
- }
-
- if (sev->result != ISC_R_SUCCESS) {
- destroy_client(&httpd);
- goto out;
- }
-
- if ((httpd->flags & HTTPD_CLOSE) != 0) {
- destroy_client(&httpd);
- goto out;
- }
-
- ISC_HTTPD_SETRECV(httpd);
-
- NOTICE("senddone restarting recv on socket");
-
- reset_client(httpd);
-
- r.base = (unsigned char *)httpd->recvbuf;
- r.length = HTTP_RECVLEN - 1;
- /* check return code? */
- (void)isc_socket_recv(httpd->sock, &r, 1, task,
- isc_httpd_recvdone, httpd);
-
-out:
- isc_event_free(&ev);
- EXIT("senddone");
-}
-
-static void
-reset_client(isc_httpd_t *httpd) {
- /*
- * Catch errors here. We MUST be in RECV mode, and we MUST NOT have
- * any outstanding buffers. If we have buffers, we have a leak.
- */
- INSIST(ISC_HTTPD_ISRECV(httpd));
- INSIST(!ISC_LINK_LINKED(&httpd->headerbuffer, link));
- INSIST(!ISC_LINK_LINKED(&httpd->bodybuffer, link));
-
- httpd->recvbuf[0] = 0;
- httpd->recvlen = 0;
- httpd->headers = NULL;
- httpd->method = ISC_HTTPD_METHODUNKNOWN;
- httpd->url = NULL;
- httpd->querystring = NULL;
- httpd->protocol = NULL;
- httpd->flags = 0;
-
- isc_buffer_clear(&httpd->headerbuffer);
- isc_buffer_invalidate(&httpd->bodybuffer);
-}
-
-isc_result_t
-isc_httpdmgr_addurl(isc_httpdmgr_t *httpdmgr, const char *url,
- isc_httpdaction_t *func, void *arg)
-{
- return (isc_httpdmgr_addurl2(httpdmgr, url, ISC_FALSE, func, arg));
-}
-
-isc_result_t
-isc_httpdmgr_addurl2(isc_httpdmgr_t *httpdmgr, const char *url,
- isc_boolean_t isstatic,
- isc_httpdaction_t *func, void *arg)
-{
- isc_httpdurl_t *item;
-
- if (url == NULL) {
- httpdmgr->render_404 = func;
- return (ISC_R_SUCCESS);
- }
-
- item = isc_mem_get(httpdmgr->mctx, sizeof(isc_httpdurl_t));
- if (item == NULL)
- return (ISC_R_NOMEMORY);
-
- item->url = isc_mem_strdup(httpdmgr->mctx, url);
- if (item->url == NULL) {
- isc_mem_put(httpdmgr->mctx, item, sizeof(isc_httpdurl_t));
- return (ISC_R_NOMEMORY);
- }
-
- item->action = func;
- item->action_arg = arg;
- item->isstatic = isstatic;
- isc_time_now(&item->loadtime);
-
- ISC_LINK_INIT(item, link);
- ISC_LIST_APPEND(httpdmgr->urls, item, link);
-
- return (ISC_R_SUCCESS);
-}
diff --git a/usr.sbin/bind/lib/isc/include/isc/Makefile.in b/usr.sbin/bind/lib/isc/include/isc/Makefile.in
index 8c68da3d283..6ef03649dea 100644
--- a/usr.sbin/bind/lib/isc/include/isc/Makefile.in
+++ b/usr.sbin/bind/lib/isc/include/isc/Makefile.in
@@ -27,8 +27,8 @@ HEADERS = aes.h app.h assertions.h base32.h base64.h \
bind9.h boolean.h buffer.h bufferlist.h \
commandline.h counter.h crc64.h errno.h error.h \
event.h eventclass.h file.h formatcheck.h fsaccess.h \
- hash.h heap.h hex.h hmacmd5.h hmacsha.h httpd.h \
- @ISC_IPV6_H@ iterated_hash.h json.h \
+ hash.h heap.h hex.h hmacmd5.h hmacsha.h \
+ @ISC_IPV6_H@ iterated_hash.h \
lang.h lex.h lfsr.h lib.h likely.h list.h log.h \
magic.h md5.h mem.h msgcat.h msgs.h mutexblock.h \
netaddr.h netscope.h ondestroy.h parseint.h \
@@ -37,8 +37,7 @@ HEADERS = aes.h app.h assertions.h base32.h base64.h \
region.h result.h resultclass.h rwlock.h \
safe.h serial.h sha1.h sha2.h sockaddr.h socket.h \
stdio.h stdlib.h string.h symtab.h task.h \
- taskpool.h timer.h tm.h types.h util.h version.h \
- xml.h
+ taskpool.h timer.h tm.h types.h util.h version.h
SUBDIRS =
TARGETS =
diff --git a/usr.sbin/bind/lib/isc/include/isc/httpd.h b/usr.sbin/bind/lib/isc/include/isc/httpd.h
deleted file mode 100644
index 145627d1dff..00000000000
--- a/usr.sbin/bind/lib/isc/include/isc/httpd.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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.
- */
-
-/* $Id: httpd.h,v 1.2 2019/12/17 01:46:35 sthen Exp $ */
-
-#ifndef ISC_HTTPD_H
-#define ISC_HTTPD_H 1
-
-/*! \file */
-
-#include <isc/event.h>
-#include <isc/eventclass.h>
-#include <isc/types.h>
-#include <isc/mutex.h>
-#include <isc/task.h>
-#include <isc/time.h>
-
-/*%
- * HTTP urls. These are the URLs we manage, and the function to call to
- * provide the data for it. We pass in the base url (so the same function
- * can handle multiple requests), and a structure to fill in to return a
- * result to the client. We also pass in a pointer to be filled in for
- * the data cleanup function.
- */
-struct isc_httpdurl {
- char *url;
- isc_httpdaction_t *action;
- void *action_arg;
- isc_boolean_t isstatic;
- isc_time_t loadtime;
- ISC_LINK(isc_httpdurl_t) link;
-};
-
-#define HTTPD_EVENTCLASS ISC_EVENTCLASS(4300)
-#define HTTPD_SHUTDOWN (HTTPD_EVENTCLASS + 0x0001)
-
-#define ISC_HTTPDMGR_FLAGSHUTTINGDOWN 0x00000001
-
-/*
- * Create a new http daemon which will send, once every time period,
- * a http-like header followed by HTTP data.
- */
-isc_result_t
-isc_httpdmgr_create(isc_mem_t *mctx, isc_socket_t *sock, isc_task_t *task,
- isc_httpdclientok_t *client_ok,
- isc_httpdondestroy_t *ondestory, void *cb_arg,
- isc_timermgr_t *tmgr, isc_httpdmgr_t **httpdp);
-
-void
-isc_httpdmgr_shutdown(isc_httpdmgr_t **httpdp);
-
-isc_result_t
-isc_httpdmgr_addurl(isc_httpdmgr_t *httpdmgr, const char *url,
- isc_httpdaction_t *func, void *arg);
-
-isc_result_t
-isc_httpdmgr_addurl2(isc_httpdmgr_t *httpdmgr, const char *url,
- isc_boolean_t isstatic,
- isc_httpdaction_t *func, void *arg);
-
-isc_result_t
-isc_httpd_response(isc_httpd_t *httpd);
-
-isc_result_t
-isc_httpd_addheader(isc_httpd_t *httpd, const char *name,
- const char *val);
-
-isc_result_t
-isc_httpd_addheaderuint(isc_httpd_t *httpd, const char *name, int val);
-
-isc_result_t isc_httpd_endheaders(isc_httpd_t *httpd);
-
-#endif /* ISC_HTTPD_H */
diff --git a/usr.sbin/bind/lib/isc/include/isc/json.h b/usr.sbin/bind/lib/isc/include/isc/json.h
deleted file mode 100644
index 487e174dfe8..00000000000
--- a/usr.sbin/bind/lib/isc/include/isc/json.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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.
- */
-
-#ifndef ISC_JSON_H
-#define ISC_JSON_H 1
-
-#ifdef HAVE_JSON
-/*
- * This file is here mostly to make it easy to add additional libjson header
- * files as needed across all the users of this file. Rather than place
- * these libjson includes in each file, one include makes it easy to handle
- * the ifdef as well as adding the ability to add additional functions
- * which may be useful.
- */
-#ifdef HAVE_JSON_C
-/*
- * We don't include <json-c/json.h> as the subsequent includes do not
- * prefix the header file names with "json-c/" and using
- * -I <prefix>/include/json-c results in too many filename collisions.
- */
-#include <json-c/linkhash.h>
-#include <json-c/json_util.h>
-#include <json-c/json_object.h>
-#include <json-c/json_tokener.h>
-#include <json-c/json_object_iterator.h>
-#include <json-c/json_c_version.h>
-#else
-#include <json/json.h>
-#endif
-#endif
-
-#define ISC_JSON_RENDERCONFIG 0x00000001 /* render config data */
-#define ISC_JSON_RENDERSTATS 0x00000002 /* render stats */
-#define ISC_JSON_RENDERALL 0x000000ff /* render everything */
-
-#endif /* ISC_JSON_H */
diff --git a/usr.sbin/bind/lib/isc/include/isc/mem.h b/usr.sbin/bind/lib/isc/include/isc/mem.h
index 9a017059ba3..d5d3c6cd473 100644
--- a/usr.sbin/bind/lib/isc/include/isc/mem.h
+++ b/usr.sbin/bind/lib/isc/include/isc/mem.h
@@ -21,12 +21,12 @@
#include <stdio.h>
-#include <isc/json.h>
+
#include <isc/lang.h>
#include <isc/mutex.h>
#include <isc/platform.h>
#include <isc/types.h>
-#include <isc/xml.h>
+
ISC_LANG_BEGINDECLS
@@ -550,22 +550,6 @@ isc_mem_gettag(isc_mem_t *ctx);
*\li 'ctx' is a valid task.
*/
-#ifdef HAVE_LIBXML2
-int
-isc_mem_renderxml(xmlTextWriterPtr writer);
-/*%<
- * Render all contexts' statistics and status in XML for writer.
- */
-#endif /* HAVE_LIBXML2 */
-
-#ifdef HAVE_JSON
-isc_result_t
-isc_mem_renderjson(json_object *memobj);
-/*%<
- * Render all contexts' statistics and status in JSON.
- */
-#endif /* HAVE_JSON */
-
/*
* Memory pools
diff --git a/usr.sbin/bind/lib/isc/include/isc/socket.h b/usr.sbin/bind/lib/isc/include/isc/socket.h
index a01d509679e..47b3b3549f8 100644
--- a/usr.sbin/bind/lib/isc/include/isc/socket.h
+++ b/usr.sbin/bind/lib/isc/include/isc/socket.h
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: socket.h,v 1.9 2020/01/09 18:17:19 florian Exp $ */
+/* $Id: socket.h,v 1.10 2020/01/20 18:43:21 florian Exp $ */
#ifndef ISC_SOCKET_H
#define ISC_SOCKET_H 1
@@ -59,12 +59,12 @@
#include <isc/event.h>
#include <isc/eventclass.h>
#include <isc/lang.h>
-#include <isc/json.h>
+
#include <isc/region.h>
#include <isc/sockaddr.h>
#include <isc/time.h>
#include <isc/types.h>
-#include <isc/xml.h>
+
ISC_LANG_BEGINDECLS
@@ -1179,22 +1179,6 @@ isc__socketmgr_maxudp(isc_socketmgr_t *mgr, int maxudp);
* Test interface. Drop UDP packet > 'maxudp'.
*/
-#ifdef HAVE_LIBXML2
-int
-isc_socketmgr_renderxml(isc_socketmgr_t *mgr, xmlTextWriterPtr writer);
-/*%<
- * Render internal statistics and other state into the XML document.
- */
-#endif /* HAVE_LIBXML2 */
-
-#ifdef HAVE_JSON
-isc_result_t
-isc_socketmgr_renderjson(isc_socketmgr_t *mgr, json_object *stats);
-/*%<
- * Render internal statistics and other state into JSON format.
- */
-#endif /* HAVE_JSON */
-
/*%<
* See isc_socketmgr_create() above.
*/
diff --git a/usr.sbin/bind/lib/isc/include/isc/task.h b/usr.sbin/bind/lib/isc/include/isc/task.h
index b85f2c85d3e..d10dd9cfb4e 100644
--- a/usr.sbin/bind/lib/isc/include/isc/task.h
+++ b/usr.sbin/bind/lib/isc/include/isc/task.h
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: task.h,v 1.3 2019/12/17 01:46:35 sthen Exp $ */
+/* $Id: task.h,v 1.4 2020/01/20 18:43:21 florian Exp $ */
#ifndef ISC_TASK_H
#define ISC_TASK_H 1
@@ -80,11 +80,11 @@
***/
#include <isc/eventclass.h>
-#include <isc/json.h>
+
#include <isc/lang.h>
#include <isc/stdtime.h>
#include <isc/types.h>
-#include <isc/xml.h>
+
#define ISC_TASKEVENT_FIRSTEVENT (ISC_EVENTCLASS_TASK + 0)
#define ISC_TASKEVENT_SHUTDOWN (ISC_EVENTCLASS_TASK + 1)
@@ -786,16 +786,6 @@ isc_taskmgr_excltask(isc_taskmgr_t *mgr, isc_task_t **taskp);
*/
-#ifdef HAVE_LIBXML2
-int
-isc_taskmgr_renderxml(isc_taskmgr_t *mgr, xmlTextWriterPtr writer);
-#endif
-
-#ifdef HAVE_JSON
-isc_result_t
-isc_taskmgr_renderjson(isc_taskmgr_t *mgr, json_object *tasksobj);
-#endif
-
/*%<
* See isc_taskmgr_create() above.
*/
diff --git a/usr.sbin/bind/lib/isc/include/isc/xml.h b/usr.sbin/bind/lib/isc/include/isc/xml.h
deleted file mode 100644
index 9be4e154708..00000000000
--- a/usr.sbin/bind/lib/isc/include/isc/xml.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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.
- */
-
-/* $Id: xml.h,v 1.2 2019/12/17 01:46:35 sthen Exp $ */
-
-#ifndef ISC_XML_H
-#define ISC_XML_H 1
-
-/*
- * This file is here mostly to make it easy to add additional libxml header
- * files as needed across all the users of this file. Rather than place
- * these libxml includes in each file, one include makes it easy to handle
- * the ifdef as well as adding the ability to add additional functions
- * which may be useful.
- */
-
-#ifdef HAVE_LIBXML2
-#include <libxml/encoding.h>
-#include <libxml/xmlwriter.h>
-#endif
-
-#define ISC_XMLCHAR (const xmlChar *)
-
-#define ISC_XML_RENDERCONFIG 0x00000001 /* render config data */
-#define ISC_XML_RENDERSTATS 0x00000002 /* render stats */
-#define ISC_XML_RENDERALL 0x000000ff /* render everything */
-
-#endif /* ISC_XML_H */
diff --git a/usr.sbin/bind/lib/isc/mem.c b/usr.sbin/bind/lib/isc/mem.c
index a03dfb0a99a..eec2360fefc 100644
--- a/usr.sbin/bind/lib/isc/mem.c
+++ b/usr.sbin/bind/lib/isc/mem.c
@@ -25,7 +25,7 @@
#include <limits.h>
#include <isc/bind9.h>
-#include <isc/json.h>
+
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/msgs.h>
@@ -35,7 +35,7 @@
#include <isc/mutex.h>
#include <isc/util.h>
-#include <isc/xml.h>
+
#define MCTXLOCK(m, l) if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) LOCK(l)
#define MCTXUNLOCK(m, l) if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) UNLOCK(l)
@@ -2331,329 +2331,6 @@ typedef struct summarystat {
uint64_t contextsize;
} summarystat_t;
-#ifdef HAVE_LIBXML2
-#define TRY0(a) do { xmlrc = (a); if (xmlrc < 0) goto error; } while(0)
-static int
-xml_renderctx(isc__mem_t *ctx, summarystat_t *summary,
- xmlTextWriterPtr writer)
-{
- int xmlrc;
-
- REQUIRE(VALID_CONTEXT(ctx));
-
- MCTXLOCK(ctx, &ctx->lock);
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "context"));
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "id"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%p", ctx));
- TRY0(xmlTextWriterEndElement(writer)); /* id */
-
- if (ctx->name[0] != 0) {
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "name"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%s", ctx->name));
- TRY0(xmlTextWriterEndElement(writer)); /* name */
- }
-
- summary->contextsize += sizeof(*ctx) +
- (ctx->max_size + 1) * sizeof(struct stats) +
- ctx->max_size * sizeof(element *) +
- ctx->basic_table_count * sizeof(char *);
-#if ISC_MEM_TRACKLINES
- if (ctx->debuglist != NULL) {
- summary->contextsize +=
- (ctx->max_size + 1) * sizeof(debuglist_t) +
- ctx->debuglistcnt * sizeof(debuglink_t);
- }
-#endif
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "references"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%d", ctx->references));
- TRY0(xmlTextWriterEndElement(writer)); /* references */
-
- summary->total += ctx->total;
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "total"));
- TRY0(xmlTextWriterWriteFormatString(writer,
- "%llu",
- (uint64_t)ctx->total));
- TRY0(xmlTextWriterEndElement(writer)); /* total */
-
- summary->inuse += ctx->inuse;
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "inuse"));
- TRY0(xmlTextWriterWriteFormatString(writer,
- "%llu",
- (uint64_t)ctx->inuse));
- TRY0(xmlTextWriterEndElement(writer)); /* inuse */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "maxinuse"));
- TRY0(xmlTextWriterWriteFormatString(writer,
- "%llu",
- (uint64_t)ctx->maxinuse));
- TRY0(xmlTextWriterEndElement(writer)); /* maxinuse */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "blocksize"));
- if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
- summary->blocksize += ctx->basic_table_count *
- NUM_BASIC_BLOCKS * ctx->mem_target;
- TRY0(xmlTextWriterWriteFormatString(writer,
- "%llu",
- (uint64_t)
- ctx->basic_table_count *
- NUM_BASIC_BLOCKS *
- ctx->mem_target));
- } else
- TRY0(xmlTextWriterWriteFormatString(writer, "%s", "-"));
- TRY0(xmlTextWriterEndElement(writer)); /* blocksize */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "pools"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%u", ctx->poolcnt));
- TRY0(xmlTextWriterEndElement(writer)); /* pools */
- summary->contextsize += ctx->poolcnt * sizeof(isc_mempool_t);
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "hiwater"));
- TRY0(xmlTextWriterWriteFormatString(writer,
- "%llu",
- (uint64_t)ctx->hi_water));
- TRY0(xmlTextWriterEndElement(writer)); /* hiwater */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "lowater"));
- TRY0(xmlTextWriterWriteFormatString(writer,
- "%llu",
- (uint64_t)ctx->lo_water));
- TRY0(xmlTextWriterEndElement(writer)); /* lowater */
-
- TRY0(xmlTextWriterEndElement(writer)); /* context */
-
- error:
- MCTXUNLOCK(ctx, &ctx->lock);
-
- return (xmlrc);
-}
-
-int
-isc_mem_renderxml(xmlTextWriterPtr writer) {
- isc__mem_t *ctx;
- summarystat_t summary;
- uint64_t lost;
- int xmlrc;
-
- memset(&summary, 0, sizeof(summary));
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "contexts"));
-
- RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
-
- LOCK(&contextslock);
- lost = totallost;
- for (ctx = ISC_LIST_HEAD(contexts);
- ctx != NULL;
- ctx = ISC_LIST_NEXT(ctx, link)) {
- xmlrc = xml_renderctx(ctx, &summary, writer);
- if (xmlrc < 0) {
- UNLOCK(&contextslock);
- goto error;
- }
- }
- UNLOCK(&contextslock);
-
- TRY0(xmlTextWriterEndElement(writer)); /* contexts */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "summary"));
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "TotalUse"));
- TRY0(xmlTextWriterWriteFormatString(writer,
- "%llu",
- summary.total));
- TRY0(xmlTextWriterEndElement(writer)); /* TotalUse */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "InUse"));
- TRY0(xmlTextWriterWriteFormatString(writer,
- "%llu",
- summary.inuse));
- TRY0(xmlTextWriterEndElement(writer)); /* InUse */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "BlockSize"));
- TRY0(xmlTextWriterWriteFormatString(writer,
- "%llu",
- summary.blocksize));
- TRY0(xmlTextWriterEndElement(writer)); /* BlockSize */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "ContextSize"));
- TRY0(xmlTextWriterWriteFormatString(writer,
- "%llu",
- summary.contextsize));
- TRY0(xmlTextWriterEndElement(writer)); /* ContextSize */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "Lost"));
- TRY0(xmlTextWriterWriteFormatString(writer,
- "%llu",
- lost));
- TRY0(xmlTextWriterEndElement(writer)); /* Lost */
-
- TRY0(xmlTextWriterEndElement(writer)); /* summary */
- error:
- return (xmlrc);
-}
-
-#endif /* HAVE_LIBXML2 */
-
-#ifdef HAVE_JSON
-#define CHECKMEM(m) do { \
- if (m == NULL) { \
- result = ISC_R_NOMEMORY;\
- goto error;\
- } \
-} while(0)
-
-static isc_result_t
-json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) {
- isc_result_t result = ISC_R_FAILURE;
- json_object *ctxobj, *obj;
- char buf[1024];
-
- REQUIRE(VALID_CONTEXT(ctx));
- REQUIRE(summary != NULL);
- REQUIRE(array != NULL);
-
- MCTXLOCK(ctx, &ctx->lock);
-
- summary->contextsize += sizeof(*ctx) +
- (ctx->max_size + 1) * sizeof(struct stats) +
- ctx->max_size * sizeof(element *) +
- ctx->basic_table_count * sizeof(char *);
- summary->total += ctx->total;
- summary->inuse += ctx->inuse;
- if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0)
- summary->blocksize += ctx->basic_table_count *
- NUM_BASIC_BLOCKS * ctx->mem_target;
-#if ISC_MEM_TRACKLINES
- if (ctx->debuglist != NULL) {
- summary->contextsize +=
- (ctx->max_size + 1) * sizeof(debuglist_t) +
- ctx->debuglistcnt * sizeof(debuglink_t);
- }
-#endif
-
- ctxobj = json_object_new_object();
- CHECKMEM(ctxobj);
-
- snprintf(buf, sizeof(buf), "%p", ctx);
- obj = json_object_new_string(buf);
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "id", obj);
-
- if (ctx->name[0] != 0) {
- obj = json_object_new_string(ctx->name);
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "name", obj);
- }
-
- obj = json_object_new_int64(ctx->references);
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "references", obj);
-
- obj = json_object_new_int64(ctx->total);
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "total", obj);
-
- obj = json_object_new_int64(ctx->inuse);
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "inuse", obj);
-
- obj = json_object_new_int64(ctx->maxinuse);
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "maxinuse", obj);
-
- if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
- uint64_t blocksize;
- blocksize = ctx->basic_table_count * NUM_BASIC_BLOCKS *
- ctx->mem_target;
- obj = json_object_new_int64(blocksize);
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "blocksize", obj);
- }
-
- obj = json_object_new_int64(ctx->poolcnt);
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "pools", obj);
-
- summary->contextsize += ctx->poolcnt * sizeof(isc_mempool_t);
-
- obj = json_object_new_int64(ctx->hi_water);
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "hiwater", obj);
-
- obj = json_object_new_int64(ctx->lo_water);
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "lowater", obj);
-
- MCTXUNLOCK(ctx, &ctx->lock);
- json_object_array_add(array, ctxobj);
- return (ISC_R_SUCCESS);
-
- error:
- MCTXUNLOCK(ctx, &ctx->lock);
- if (ctxobj != NULL)
- json_object_put(ctxobj);
- return (result);
-}
-
-isc_result_t
-isc_mem_renderjson(json_object *memobj) {
- isc_result_t result = ISC_R_SUCCESS;
- isc__mem_t *ctx;
- summarystat_t summary;
- uint64_t lost;
- json_object *ctxarray, *obj;
-
- memset(&summary, 0, sizeof(summary));
- RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
-
- ctxarray = json_object_new_array();
- CHECKMEM(ctxarray);
-
- LOCK(&contextslock);
- lost = totallost;
- for (ctx = ISC_LIST_HEAD(contexts);
- ctx != NULL;
- ctx = ISC_LIST_NEXT(ctx, link)) {
- result = json_renderctx(ctx, &summary, ctxarray);
- if (result != ISC_R_SUCCESS) {
- UNLOCK(&contextslock);
- goto error;
- }
- }
- UNLOCK(&contextslock);
-
- obj = json_object_new_int64(summary.total);
- CHECKMEM(obj);
- json_object_object_add(memobj, "TotalUse", obj);
-
- obj = json_object_new_int64(summary.inuse);
- CHECKMEM(obj);
- json_object_object_add(memobj, "InUse", obj);
-
- obj = json_object_new_int64(summary.blocksize);
- CHECKMEM(obj);
- json_object_object_add(memobj, "BlockSize", obj);
-
- obj = json_object_new_int64(summary.contextsize);
- CHECKMEM(obj);
- json_object_object_add(memobj, "ContextSize", obj);
-
- obj = json_object_new_int64(lost);
- CHECKMEM(obj);
- json_object_object_add(memobj, "Lost", obj);
-
- json_object_object_add(memobj, "contexts", ctxarray);
- return (ISC_R_SUCCESS);
-
- error:
- if (ctxarray != NULL)
- json_object_put(ctxarray);
- return (result);
-}
-#endif /* HAVE_JSON */
-
static isc_memcreatefunc_t mem_createfunc = NULL;
isc_result_t
diff --git a/usr.sbin/bind/lib/isc/task.c b/usr.sbin/bind/lib/isc/task.c
index ce0d3023ef5..afbdf7b5cc5 100644
--- a/usr.sbin/bind/lib/isc/task.c
+++ b/usr.sbin/bind/lib/isc/task.c
@@ -28,7 +28,7 @@
#include <isc/app.h>
#include <isc/condition.h>
#include <isc/event.h>
-#include <isc/json.h>
+
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/msgs.h>
@@ -39,7 +39,7 @@
#include <isc/task.h>
#include <isc/thread.h>
#include <isc/util.h>
-#include <isc/xml.h>
+
/*%
* For BIND9 internal applications:
@@ -79,12 +79,6 @@ typedef enum {
task_state_done
} task_state_t;
-#if defined(HAVE_LIBXML2) || defined(HAVE_JSON)
-static const char *statenames[] = {
- "idle", "ready", "running", "done",
-};
-#endif
-
#define TASK_MAGIC ISC_MAGIC('T', 'A', 'S', 'K')
#define VALID_TASK(t) ISC_MAGIC_VALID(t, TASK_MAGIC)
@@ -1770,202 +1764,6 @@ isc_task_exiting(isc_task_t *t) {
}
-#ifdef HAVE_LIBXML2
-#define TRY0(a) do { xmlrc = (a); if (xmlrc < 0) goto error; } while(0)
-int
-isc_taskmgr_renderxml(isc_taskmgr_t *mgr0, xmlTextWriterPtr writer) {
- isc__taskmgr_t *mgr = (isc__taskmgr_t *)mgr0;
- isc__task_t *task = NULL;
- int xmlrc;
-
- LOCK(&mgr->lock);
-
- /*
- * Write out the thread-model, and some details about each depending
- * on which type is enabled.
- */
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "thread-model"));
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "type"));
- TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR "non-threaded"));
- TRY0(xmlTextWriterEndElement(writer)); /* type */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "references"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%d", mgr->refs));
- TRY0(xmlTextWriterEndElement(writer)); /* references */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "default-quantum"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%d",
- mgr->default_quantum));
- TRY0(xmlTextWriterEndElement(writer)); /* default-quantum */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "tasks-running"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%d", mgr->tasks_running));
- TRY0(xmlTextWriterEndElement(writer)); /* tasks-running */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "tasks-ready"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%d", mgr->tasks_ready));
- TRY0(xmlTextWriterEndElement(writer)); /* tasks-ready */
-
- TRY0(xmlTextWriterEndElement(writer)); /* thread-model */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "tasks"));
- task = ISC_LIST_HEAD(mgr->tasks);
- while (task != NULL) {
- LOCK(&task->lock);
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "task"));
-
- if (task->name[0] != 0) {
- TRY0(xmlTextWriterStartElement(writer,
- ISC_XMLCHAR "name"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%s",
- task->name));
- TRY0(xmlTextWriterEndElement(writer)); /* name */
- }
-
- TRY0(xmlTextWriterStartElement(writer,
- ISC_XMLCHAR "references"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%d",
- task->references));
- TRY0(xmlTextWriterEndElement(writer)); /* references */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "id"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%p", task));
- TRY0(xmlTextWriterEndElement(writer)); /* id */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "state"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%s",
- statenames[task->state]));
- TRY0(xmlTextWriterEndElement(writer)); /* state */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "quantum"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%d",
- task->quantum));
- TRY0(xmlTextWriterEndElement(writer)); /* quantum */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "events"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%d",
- task->nevents));
- TRY0(xmlTextWriterEndElement(writer)); /* events */
-
- TRY0(xmlTextWriterEndElement(writer));
-
- UNLOCK(&task->lock);
- task = ISC_LIST_NEXT(task, link);
- }
- TRY0(xmlTextWriterEndElement(writer)); /* tasks */
-
- error:
- if (task != NULL)
- UNLOCK(&task->lock);
- UNLOCK(&mgr->lock);
-
- return (xmlrc);
-}
-#endif /* HAVE_LIBXML2 */
-
-#ifdef HAVE_JSON
-#define CHECKMEM(m) do { \
- if (m == NULL) { \
- result = ISC_R_NOMEMORY;\
- goto error;\
- } \
-} while(0)
-
-isc_result_t
-isc_taskmgr_renderjson(isc_taskmgr_t *mgr0, json_object *tasks) {
- isc_result_t result = ISC_R_SUCCESS;
- isc__taskmgr_t *mgr = (isc__taskmgr_t *)mgr0;
- isc__task_t *task = NULL;
- json_object *obj = NULL, *array = NULL, *taskobj = NULL;
-
- LOCK(&mgr->lock);
-
- /*
- * Write out the thread-model, and some details about each depending
- * on which type is enabled.
- */
- obj = json_object_new_string("non-threaded");
- CHECKMEM(obj);
- json_object_object_add(tasks, "thread-model", obj);
-
- obj = json_object_new_int(mgr->refs);
- CHECKMEM(obj);
- json_object_object_add(tasks, "references", obj);
-
- obj = json_object_new_int(mgr->default_quantum);
- CHECKMEM(obj);
- json_object_object_add(tasks, "default-quantum", obj);
-
- obj = json_object_new_int(mgr->tasks_running);
- CHECKMEM(obj);
- json_object_object_add(tasks, "tasks-running", obj);
-
- obj = json_object_new_int(mgr->tasks_ready);
- CHECKMEM(obj);
- json_object_object_add(tasks, "tasks-ready", obj);
-
- array = json_object_new_array();
- CHECKMEM(array);
-
- for (task = ISC_LIST_HEAD(mgr->tasks);
- task != NULL;
- task = ISC_LIST_NEXT(task, link))
- {
- char buf[255];
-
- LOCK(&task->lock);
-
- taskobj = json_object_new_object();
- CHECKMEM(taskobj);
- json_object_array_add(array, taskobj);
-
- snprintf(buf, sizeof(buf), "%p", task);
- obj = json_object_new_string(buf);
- CHECKMEM(obj);
- json_object_object_add(taskobj, "id", obj);
-
- if (task->name[0] != 0) {
- obj = json_object_new_string(task->name);
- CHECKMEM(obj);
- json_object_object_add(taskobj, "name", obj);
- }
-
- obj = json_object_new_int(task->references);
- CHECKMEM(obj);
- json_object_object_add(taskobj, "references", obj);
-
- obj = json_object_new_string(statenames[task->state]);
- CHECKMEM(obj);
- json_object_object_add(taskobj, "state", obj);
-
- obj = json_object_new_int(task->quantum);
- CHECKMEM(obj);
- json_object_object_add(taskobj, "quantum", obj);
-
- obj = json_object_new_int(task->nevents);
- CHECKMEM(obj);
- json_object_object_add(taskobj, "events", obj);
-
- UNLOCK(&task->lock);
- }
-
- json_object_object_add(tasks, "tasks", array);
- array = NULL;
- result = ISC_R_SUCCESS;
-
- error:
- if (array != NULL)
- json_object_put(array);
-
- if (task != NULL)
- UNLOCK(&task->lock);
- UNLOCK(&mgr->lock);
-
- return (result);
-}
-#endif
-
-
static isc_mutex_t createlock;
static isc_once_t once = ISC_ONCE_INIT;
static isc_taskmgrcreatefunc_t taskmgr_createfunc = NULL;
diff --git a/usr.sbin/bind/lib/isc/unix/socket.c b/usr.sbin/bind/lib/isc/unix/socket.c
index df38446f9c2..b86f62990e8 100644
--- a/usr.sbin/bind/lib/isc/unix/socket.c
+++ b/usr.sbin/bind/lib/isc/unix/socket.c
@@ -44,7 +44,7 @@
#include <isc/bufferlist.h>
#include <isc/condition.h>
#include <isc/formatcheck.h>
-#include <isc/json.h>
+
#include <isc/list.h>
#include <isc/log.h>
#include <isc/mem.h>
@@ -62,7 +62,7 @@
#include <isc/task.h>
#include <isc/thread.h>
#include <isc/util.h>
-#include <isc/xml.h>
+
#include <sys/un.h>
#include <sys/event.h>
@@ -551,15 +551,6 @@ isc__socket_getname(isc_socket_t *socket0);
void *
isc__socket_gettag(isc_socket_t *socket0);
-#ifdef HAVE_LIBXML2
-void
-isc__socketmgr_renderxml(isc_socketmgr_t *mgr0, xmlTextWriterPtr writer);
-#endif
-#ifdef HAVE_JSON
-isc_result_t
-isc__socketmgr_renderjson(isc_socketmgr_t *mgr0, json_object *stats);
-#endif
-
static struct {
isc_socketmethods_t methods;
@@ -5415,272 +5406,4 @@ isc__socket_getfd(isc_socket_t *socket0) {
return ((short) sock->fd);
}
-#if defined(HAVE_LIBXML2) || defined(HAVE_JSON)
-static const char *
-_socktype(isc_sockettype_t type)
-{
- if (type == isc_sockettype_udp)
- return ("udp");
- else if (type == isc_sockettype_tcp)
- return ("tcp");
- else if (type == isc_sockettype_unix)
- return ("unix");
- else if (type == isc_sockettype_fdwatch)
- return ("fdwatch");
- else
- return ("not-initialized");
-}
-#endif
-
-#ifdef HAVE_LIBXML2
-#define TRY0(a) do { xmlrc = (a); if (xmlrc < 0) goto error; } while(0)
-int
-isc_socketmgr_renderxml(isc_socketmgr_t *mgr0, xmlTextWriterPtr writer) {
- isc__socketmgr_t *mgr = (isc__socketmgr_t *)mgr0;
- isc__socket_t *sock = NULL;
- char peerbuf[ISC_SOCKADDR_FORMATSIZE];
- isc_sockaddr_t addr;
- ISC_SOCKADDR_LEN_T len;
- int xmlrc;
-
- LOCK(&mgr->lock);
-
-#ifdef USE_SHARED_MANAGER
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "references"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%d", mgr->refs));
- TRY0(xmlTextWriterEndElement(writer));
-#endif /* USE_SHARED_MANAGER */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "sockets"));
- sock = ISC_LIST_HEAD(mgr->socklist);
- while (sock != NULL) {
- LOCK(&sock->lock);
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "socket"));
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "id"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%p", sock));
- TRY0(xmlTextWriterEndElement(writer));
-
- if (sock->name[0] != 0) {
- TRY0(xmlTextWriterStartElement(writer,
- ISC_XMLCHAR "name"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%s",
- sock->name));
- TRY0(xmlTextWriterEndElement(writer)); /* name */
- }
-
- TRY0(xmlTextWriterStartElement(writer,
- ISC_XMLCHAR "references"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%d",
- sock->references));
- TRY0(xmlTextWriterEndElement(writer));
-
- TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "type",
- ISC_XMLCHAR _socktype(sock->type)));
-
- if (sock->connected) {
- isc_sockaddr_format(&sock->peer_address, peerbuf,
- sizeof(peerbuf));
- TRY0(xmlTextWriterWriteElement(writer,
- ISC_XMLCHAR "peer-address",
- ISC_XMLCHAR peerbuf));
- }
-
- len = sizeof(addr);
- if (getsockname(sock->fd, &addr.type.sa, (void *)&len) == 0) {
- isc_sockaddr_format(&addr, peerbuf, sizeof(peerbuf));
- TRY0(xmlTextWriterWriteElement(writer,
- ISC_XMLCHAR "local-address",
- ISC_XMLCHAR peerbuf));
- }
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "states"));
- if (sock->pending_recv)
- TRY0(xmlTextWriterWriteElement(writer,
- ISC_XMLCHAR "state",
- ISC_XMLCHAR "pending-receive"));
- if (sock->pending_send)
- TRY0(xmlTextWriterWriteElement(writer,
- ISC_XMLCHAR "state",
- ISC_XMLCHAR "pending-send"));
- if (sock->pending_accept)
- TRY0(xmlTextWriterWriteElement(writer,
- ISC_XMLCHAR "state",
- ISC_XMLCHAR "pending_accept"));
- if (sock->listener)
- TRY0(xmlTextWriterWriteElement(writer,
- ISC_XMLCHAR "state",
- ISC_XMLCHAR "listener"));
- if (sock->connected)
- TRY0(xmlTextWriterWriteElement(writer,
- ISC_XMLCHAR "state",
- ISC_XMLCHAR "connected"));
- if (sock->connecting)
- TRY0(xmlTextWriterWriteElement(writer,
- ISC_XMLCHAR "state",
- ISC_XMLCHAR "connecting"));
- if (sock->bound)
- TRY0(xmlTextWriterWriteElement(writer,
- ISC_XMLCHAR "state",
- ISC_XMLCHAR "bound"));
-
- TRY0(xmlTextWriterEndElement(writer)); /* states */
-
- TRY0(xmlTextWriterEndElement(writer)); /* socket */
-
- UNLOCK(&sock->lock);
- sock = ISC_LIST_NEXT(sock, link);
- }
- TRY0(xmlTextWriterEndElement(writer)); /* sockets */
-
- error:
- if (sock != NULL)
- UNLOCK(&sock->lock);
-
- UNLOCK(&mgr->lock);
-
- return (xmlrc);
-}
-#endif /* HAVE_LIBXML2 */
-
-#ifdef HAVE_JSON
-#define CHECKMEM(m) do { \
- if (m == NULL) { \
- result = ISC_R_NOMEMORY;\
- goto error;\
- } \
-} while(0)
-
-isc_result_t
-isc_socketmgr_renderjson(isc_socketmgr_t *mgr0, json_object *stats) {
- isc_result_t result = ISC_R_SUCCESS;
- isc__socketmgr_t *mgr = (isc__socketmgr_t *)mgr0;
- isc__socket_t *sock = NULL;
- char peerbuf[ISC_SOCKADDR_FORMATSIZE];
- isc_sockaddr_t addr;
- ISC_SOCKADDR_LEN_T len;
- json_object *obj, *array = json_object_new_array();
-
- CHECKMEM(array);
-
- LOCK(&mgr->lock);
-
-#ifdef USE_SHARED_MANAGER
- obj = json_object_new_int(mgr->refs);
- CHECKMEM(obj);
- json_object_object_add(stats, "references", obj);
-#endif /* USE_SHARED_MANAGER */
-
- sock = ISC_LIST_HEAD(mgr->socklist);
- while (sock != NULL) {
- json_object *states, *entry = json_object_new_object();
- char buf[255];
-
- CHECKMEM(entry);
- json_object_array_add(array, entry);
-
- LOCK(&sock->lock);
-
- snprintf(buf, sizeof(buf), "%p", sock);
- obj = json_object_new_string(buf);
- CHECKMEM(obj);
- json_object_object_add(entry, "id", obj);
-
- if (sock->name[0] != 0) {
- obj = json_object_new_string(sock->name);
- CHECKMEM(obj);
- json_object_object_add(entry, "name", obj);
- }
-
- obj = json_object_new_int(sock->references);
- CHECKMEM(obj);
- json_object_object_add(entry, "references", obj);
-
- obj = json_object_new_string(_socktype(sock->type));
- CHECKMEM(obj);
- json_object_object_add(entry, "type", obj);
-
- if (sock->connected) {
- isc_sockaddr_format(&sock->peer_address, peerbuf,
- sizeof(peerbuf));
- obj = json_object_new_string(peerbuf);
- CHECKMEM(obj);
- json_object_object_add(entry, "peer-address", obj);
- }
-
- len = sizeof(addr);
- if (getsockname(sock->fd, &addr.type.sa, (void *)&len) == 0) {
- isc_sockaddr_format(&addr, peerbuf, sizeof(peerbuf));
- obj = json_object_new_string(peerbuf);
- CHECKMEM(obj);
- json_object_object_add(entry, "local-address", obj);
- }
-
- states = json_object_new_array();
- CHECKMEM(states);
- json_object_object_add(entry, "states", states);
-
- if (sock->pending_recv) {
- obj = json_object_new_string("pending-receive");
- CHECKMEM(obj);
- json_object_array_add(states, obj);
- }
-
- if (sock->pending_send) {
- obj = json_object_new_string("pending-send");
- CHECKMEM(obj);
- json_object_array_add(states, obj);
- }
-
- if (sock->pending_accept) {
- obj = json_object_new_string("pending-accept");
- CHECKMEM(obj);
- json_object_array_add(states, obj);
- }
-
- if (sock->listener) {
- obj = json_object_new_string("listener");
- CHECKMEM(obj);
- json_object_array_add(states, obj);
- }
-
- if (sock->connected) {
- obj = json_object_new_string("connected");
- CHECKMEM(obj);
- json_object_array_add(states, obj);
- }
-
- if (sock->connecting) {
- obj = json_object_new_string("connecting");
- CHECKMEM(obj);
- json_object_array_add(states, obj);
- }
-
- if (sock->bound) {
- obj = json_object_new_string("bound");
- CHECKMEM(obj);
- json_object_array_add(states, obj);
- }
-
- UNLOCK(&sock->lock);
- sock = ISC_LIST_NEXT(sock, link);
- }
-
- json_object_object_add(stats, "sockets", array);
- array = NULL;
- result = ISC_R_SUCCESS;
-
- error:
- if (array != NULL)
- json_object_put(array);
-
- if (sock != NULL)
- UNLOCK(&sock->lock);
-
- UNLOCK(&mgr->lock);
-
- return (result);
-}
-#endif /* HAVE_JSON */
-
#include "../socket_api.c"