summaryrefslogtreecommitdiff
path: root/src/skadns
diff options
context:
space:
mode:
Diffstat (limited to 'src/skadns')
-rw-r--r--src/skadns/skadns_cancel.c11
-rw-r--r--src/skadns/skadns_end.c4
-rw-r--r--src/skadns/skadns_send.c12
-rw-r--r--src/skadns/skadns_start.c4
-rw-r--r--src/skadns/skadns_startf.c6
-rw-r--r--src/skadns/skadns_update.c23
-rw-r--r--src/skadns/skadnsd.c52
7 files changed, 53 insertions, 59 deletions
diff --git a/src/skadns/skadns_cancel.c b/src/skadns/skadns_cancel.c
index 8a4ec7c..c5062f6 100644
--- a/src/skadns/skadns_cancel.c
+++ b/src/skadns/skadns_cancel.c
@@ -9,19 +9,20 @@
#include <skalibs/uint16.h>
#include <skalibs/error.h>
#include <skalibs/gensetdyn.h>
-#include <skalibs/skaclient.h>
+#include <skalibs/textclient.h>
#include <s6-dns/skadns.h>
int skadns_cancel (skadns_t *a, uint16_t id, tain_t const *deadline, tain_t *stamp)
{
+ int e = errno ;
char pack[3] = "--q" ;
- char err ;
skadnsanswer_t *p = GENSETDYN_P(skadnsanswer_t, &a->q, id) ;
if (!error_isagain(p->status)) return skadns_release(a, id) ;
uint16_pack_big(pack, id) ;
- if (!skaclient_send(&a->connection, pack, 3, &skaclient_default_cb, &err, deadline, stamp)) return 0 ;
- if (!err) return gensetdyn_delete(&a->q, id) ;
- if (err != ENOENT) return (errno = err, 0) ;
+ if (textclient_command(&a->connection, pack, 3, deadline, stamp))
+ return gensetdyn_delete(&a->q, id) ;
+ if (errno != ENOENT) return 0 ;
p->status = ECANCELED ;
+ errno = e ;
return 1 ;
}
diff --git a/src/skadns/skadns_end.c b/src/skadns/skadns_end.c
index 252e959..60ae9c9 100644
--- a/src/skadns/skadns_end.c
+++ b/src/skadns/skadns_end.c
@@ -4,7 +4,7 @@
#include <skalibs/alloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/gensetdyn.h>
-#include <skalibs/skaclient.h>
+#include <skalibs/textclient.h>
#include <s6-dns/skadns.h>
static int skadnsanswer_free (char *p, void *stuff)
@@ -17,7 +17,7 @@ static int skadnsanswer_free (char *p, void *stuff)
void skadns_end (skadns_t *a)
{
- skaclient_end(&a->connection) ;
+ textclient_end(&a->connection) ;
genalloc_free(uint16_t, &a->list) ;
gensetdyn_iter(&a->q, &skadnsanswer_free, 0) ;
gensetdyn_free(&a->q) ;
diff --git a/src/skadns/skadns_send.c b/src/skadns/skadns_send.c
index 9df39f0..69f533f 100644
--- a/src/skadns/skadns_send.c
+++ b/src/skadns/skadns_send.c
@@ -6,16 +6,15 @@
#include <errno.h>
#include <skalibs/uint16.h>
#include <skalibs/gensetdyn.h>
-#include <skalibs/skaclient.h>
+#include <skalibs/textclient.h>
#include <s6-dns/skadns.h>
-static skadnsanswer_t const skadnsanswer_initial = { .status = EAGAIN, .data = 0, .len = 0 } ;
int skadns_send (skadns_t *a, uint16_t *u, s6dns_domain_t const *d, uint16_t qtype, tain_t const *limit, tain_t const *deadline, tain_t *stamp)
{
+ static skadnsanswer_t const skadnsanswer_initial = { .status = EAGAIN, .data = 0, .len = 0 } ;
uint32_t i ;
char tmp[17] = "--Q" ;
- char err ;
struct iovec v[2] = { { .iov_base = tmp, .iov_len = 17 }, { .iov_base = (void *)d->s, .iov_len = d->len } } ;
if (!gensetdyn_new(&a->q, &i)) return 0 ;
if (i > UINT16_MAX)
@@ -26,18 +25,13 @@ int skadns_send (skadns_t *a, uint16_t *u, s6dns_domain_t const *d, uint16_t qty
uint16_pack_big(tmp, (uint16_t)i) ;
uint16_pack_big(tmp + 3, qtype) ;
if (limit) tain_pack(tmp + 5, limit) ; else memset(tmp + 5, 0, 12) ;
- if (!skaclient_sendv(&a->connection, v, 2, &skaclient_default_cb, &err, deadline, stamp))
+ if (!textclient_commandv(&a->connection, v, 2, deadline, stamp))
{
int e = errno ;
gensetdyn_delete(&a->q, i) ;
errno = e ;
return 0 ;
}
- if (err)
- {
- gensetdyn_delete(&a->q, i) ;
- return (errno = err, 0) ;
- }
*GENSETDYN_P(skadnsanswer_t, &a->q, i) = skadnsanswer_initial ;
*u = i ;
return 1 ;
diff --git a/src/skadns/skadns_start.c b/src/skadns/skadns_start.c
index f2376e2..dbb7f63 100644
--- a/src/skadns/skadns_start.c
+++ b/src/skadns/skadns_start.c
@@ -1,9 +1,9 @@
/* ISC license. */
-#include <skalibs/skaclient.h>
+#include <skalibs/textclient.h>
#include <s6-dns/skadns.h>
int skadns_start (skadns_t *a, char const *path, tain_t const *deadline, tain_t *stamp)
{
- return skaclient_start_b(&a->connection, &a->buffers, path, 0, SKADNS_BANNER1, SKADNS_BANNER1_LEN, SKADNS_BANNER2, SKADNS_BANNER2_LEN, deadline, stamp) ;
+ return textclient_start(&a->connection, path, 0, SKADNS_BANNER1, SKADNS_BANNER1_LEN, SKADNS_BANNER2, SKADNS_BANNER2_LEN, deadline, stamp) ;
}
diff --git a/src/skadns/skadns_startf.c b/src/skadns/skadns_startf.c
index 8dc1675..29c44bf 100644
--- a/src/skadns/skadns_startf.c
+++ b/src/skadns/skadns_startf.c
@@ -1,11 +1,11 @@
/* ISC license. */
-#include <skalibs/environ.h>
-#include <skalibs/skaclient.h>
+#include <skalibs/posixplz.h>
+#include <skalibs/textclient.h>
#include <s6-dns/skadns.h>
int skadns_startf (skadns_t *a, tain_t const *deadline, tain_t *stamp)
{
static char const *const cargv[2] = { SKADNSD_PROG, 0 } ;
- return skaclient_startf_b(&a->connection, &a->buffers, cargv[0], cargv, (char const *const *)environ, SKACLIENT_OPTION_WAITPID, SKADNS_BANNER1, SKADNS_BANNER1_LEN, SKADNS_BANNER2, SKADNS_BANNER2_LEN, deadline, stamp) ;
+ return textclient_startf(&a->connection, cargv, (char const *const *)environ, TEXTCLIENT_OPTION_WAITPID, SKADNS_BANNER1, SKADNS_BANNER1_LEN, SKADNS_BANNER2, SKADNS_BANNER2_LEN, deadline, stamp) ;
}
diff --git a/src/skadns/skadns_update.c b/src/skadns/skadns_update.c
index 39b1dd0..e26ead0 100644
--- a/src/skadns/skadns_update.c
+++ b/src/skadns/skadns_update.c
@@ -5,6 +5,7 @@
#define _BSD_SOURCE
#endif
+#include <sys/uio.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
@@ -13,17 +14,17 @@
#include <skalibs/alloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/gensetdyn.h>
-#include <skalibs/unixmessage.h>
-#include <skalibs/skaclient.h>
+#include <skalibs/textclient.h>
#include <s6-dns/skadns.h>
-static int msghandler (unixmessage_t const *m, void *context)
+static int msghandler (struct iovec const *v, void *context)
{
skadns_t *a = (skadns_t *)context ;
+ char const *s = v->iov_base ;
skadnsanswer_t *p ;
uint16_t id ;
- if (m->len < 3 || m->nfds) return (errno = EPROTO, 0) ;
- uint16_unpack_big(m->s, &id) ;
+ if (v->iov_len < 3) return (errno = EPROTO, 0) ;
+ uint16_unpack_big(s, &id) ;
p = GENSETDYN_P(skadnsanswer_t, &a->q, id) ;
if (p->status == ECANCELED)
{
@@ -32,14 +33,14 @@ static int msghandler (unixmessage_t const *m, void *context)
}
if (!error_isagain(p->status)) return (errno = EINVAL, 0) ;
if (!genalloc_readyplus(uint16_t, &a->list, 1)) return 0 ;
- if (!m->s[2])
+ if (!s[2])
{
- p->data = alloc(m->len-3) ;
+ p->data = alloc(v->iov_len-3) ;
if (!p->data) return 0 ;
- memcpy(p->data, m->s+3, m->len-3) ;
- p->len = m->len-3 ;
+ memcpy(p->data, s+3, v->iov_len-3) ;
+ p->len = v->iov_len-3 ;
}
- p->status = m->s[2] ;
+ p->status = s[2] ;
genalloc_append(uint16_t, &a->list, &id) ;
return 1 ;
}
@@ -47,5 +48,5 @@ static int msghandler (unixmessage_t const *m, void *context)
int skadns_update (skadns_t *a)
{
genalloc_setlen(uint16_t, &a->list, 0) ;
- return skaclient_update(&a->connection, &msghandler, a) ;
+ return textclient_update(&a->connection, &msghandler, a) ;
}
diff --git a/src/skadns/skadnsd.c b/src/skadns/skadnsd.c
index b1b0687..9f6a945 100644
--- a/src/skadns/skadnsd.c
+++ b/src/skadns/skadnsd.c
@@ -12,8 +12,8 @@
#include <skalibs/tai.h>
#include <skalibs/djbunix.h>
#include <skalibs/iopause.h>
-#include <skalibs/unixmessage.h>
-#include <skalibs/skaclient.h>
+#include <skalibs/textmessage.h>
+#include <skalibs/textclient.h>
#include <s6-dns/s6dns.h>
#include <s6-dns/skadns.h>
@@ -40,44 +40,43 @@ static void remove (unsigned int i)
static void fail (unsigned int i)
{
char pack[3] ;
- unixmessage_t m = { .s = pack, .len = 3, .fds = 0, .nfds = 0 } ;
uint16_pack_big(pack, a[i].id) ;
pack[2] = a[i].dt.status ;
s6dns_engine_recycle(&a[i].dt) ;
remove(i) ;
- if (!unixmessage_put(unixmessage_sender_x, &m))
- strerr_diefu1sys(111, "unixmessage_put") ;
+ if (!textmessage_put(textmessage_sender_x, pack, 3))
+ strerr_diefu1sys(111, "textmessage_put") ;
}
static void answer (char c)
{
- unixmessage_t m = { .s = &c, .len = 1, .fds = 0, .nfds = 0 } ;
- if (!unixmessage_put(unixmessage_sender_1, &m))
+ if (!textmessage_put(textmessage_sender_1, &c, 1))
strerr_diefu1sys(111, "unixmessage_put") ;
}
-static int parse_protocol (unixmessage_t const *m, void *context)
+static int parse_protocol (struct iovec const *v, void *context)
{
+ char const *s = v->iov_base ;
uint16_t id ;
- if (m->len < 3 || m->nfds) strerr_dief1x(100, "invalid client request") ;
- uint16_unpack_big(m->s, &id) ;
- switch (m->s[2]) /* protocol parsing */
+ if (v->iov_len < 3) strerr_dief1x(100, "invalid client request") ;
+ uint16_unpack_big(s, &id) ;
+ switch (s[2]) /* protocol parsing */
{
case 'Q' : /* send a query */
{
tain_t limit ;
uint16_t qtype ;
- if (m->len < 21) strerr_dief1x(100, "invalid client request") ;
+ if (v->iov_len < 21) strerr_dief1x(100, "invalid client request") ;
if (sp >= SKADNS_MAXCONCURRENCY)
{
answer(ENFILE) ;
break ;
}
- uint16_unpack_big(m->s + 3, &qtype) ;
- if (memcmp(m->s + 5, "\0\0\0\0\0\0\0\0\0\0\0", 12))
- tain_unpack(m->s + 5, &limit) ;
+ uint16_unpack_big(s + 3, &qtype) ;
+ if (memcmp(s + 5, "\0\0\0\0\0\0\0\0\0\0\0", 12))
+ tain_unpack(s + 5, &limit) ;
else tain_add_g(&limit, &tain_infinite_relative) ;
- if (!s6dns_engine_init_g(&a[sp].dt, &s6dns_rci_here.servers, 1, m->s + 17, m->len - 17, qtype, &limit))
+ if (!s6dns_engine_init_g(&a[sp].dt, &s6dns_rci_here.servers, 1, s + 17, v->iov_len - 17, qtype, &limit))
{
answer(errno) ;
break ;
@@ -119,7 +118,7 @@ int main (void)
{
tain_t deadline ;
tain_addsec_g(&deadline, 2) ;
- if (!skaclient_server_01x_init_g(SKADNS_BANNER1, SKADNS_BANNER1_LEN, SKADNS_BANNER2, SKADNS_BANNER2_LEN, &deadline))
+ if (!textclient_server_01x_init_g(SKADNS_BANNER1, SKADNS_BANNER1_LEN, SKADNS_BANNER2, SKADNS_BANNER2_LEN, &deadline))
strerr_diefu1sys(111, "sync with client") ;
}
{
@@ -134,9 +133,9 @@ int main (void)
int r ;
x[0].fd = 0 ; x[0].events = IOPAUSE_EXCEPT | IOPAUSE_READ ;
- x[1].fd = 1 ; x[1].events = IOPAUSE_EXCEPT | (unixmessage_sender_isempty(unixmessage_sender_1) ? 0 : IOPAUSE_WRITE) ;
- x[2].fd = unixmessage_sender_fd(unixmessage_sender_x) ;
- x[2].events = IOPAUSE_EXCEPT | (unixmessage_sender_isempty(unixmessage_sender_x) ? 0 : IOPAUSE_WRITE) ;
+ x[1].fd = 1 ; x[1].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_1) ? 0 : IOPAUSE_WRITE) ;
+ x[2].fd = textmessage_sender_fd(textmessage_sender_x) ;
+ x[2].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_x) ? 0 : IOPAUSE_WRITE) ;
{
tain_t deadline = TAIN_INFINITE ;
unsigned int i = 0 ;
@@ -162,10 +161,10 @@ int main (void)
}
if (x[1].revents & IOPAUSE_WRITE)
- if (!unixmessage_sender_flush(unixmessage_sender_1) && !error_isagain(errno))
+ if (!textmessage_sender_flush(textmessage_sender_1) && !error_isagain(errno))
strerr_diefu1sys(111, "flush stdout") ;
if (x[2].revents & IOPAUSE_WRITE)
- if (!unixmessage_sender_flush(unixmessage_sender_x) && !error_isagain(errno))
+ if (!textmessage_sender_flush(textmessage_sender_x) && !error_isagain(errno))
strerr_diefu1sys(111, "flush asyncout") ;
{
@@ -178,20 +177,19 @@ int main (void)
{
char pack[3] ;
struct iovec v[2] = { { .iov_base = pack, .iov_len = 3 }, { .iov_base = s6dns_engine_packet(&a[i].dt), .iov_len = s6dns_engine_packetlen(&a[i].dt) } } ;
- unixmessage_v_t mv = { .v = v, .vlen = 2, .fds = 0, .nfds = 0 } ;
uint16_pack_big(pack, a[i].id) ;
pack[2] = 0 ;
- if (!unixmessage_putv(unixmessage_sender_x, &mv))
- strerr_diefu1sys(111, "unixmessage_put") ;
+ if (!textmessage_putv(textmessage_sender_x, v, 2))
+ strerr_diefu1sys(111, "textmessage_put") ;
s6dns_engine_recycle(&a[i].dt) ;
remove(i--) ;
}
}
}
- if (!unixmessage_receiver_isempty(unixmessage_receiver_0) || x[0].revents & IOPAUSE_READ)
+ if (!textmessage_receiver_isempty(textmessage_receiver_0) || x[0].revents & IOPAUSE_READ)
{
- if (unixmessage_handle(unixmessage_receiver_0, &parse_protocol, 0) < 0)
+ if (textmessage_handle(textmessage_receiver_0, &parse_protocol, 0) < 0)
{
if (errno == EPIPE) break ; /* normal exit */
strerr_diefu1sys(111, "handle messages from client") ;