1 /* pingpool.c -- Show the input/output of a PING operation.
3 * From: Rick van Rein <rick@openfortress.nl>
13 #include <tlspool/commands.h>
14 #include <tlspool/async.h>
17 void print_pioc_ping (pingpool_t *pp, char *prefix) {
18 char *date = pp->YYYYMMDD_producer;
19 char *producer = date + 8;
21 facil [0] = facil [1] = '\0';
22 if (pp->facilities & PIOF_FACILITY_STARTTLS) {
23 strcat (facil, ",starttls");
24 pp->facilities &= ~PIOF_FACILITY_STARTTLS;
26 if (pp->facilities & PIOF_FACILITY_STARTGSS) {
27 strcat (facil, ",startgss");
28 pp->facilities &= ~PIOF_FACILITY_STARTGSS;
30 if (pp->facilities & PIOF_FACILITY_STARTSSH) {
31 strcat (facil, ",startssh");
32 pp->facilities &= ~PIOF_FACILITY_STARTSSH;
35 sprintf (facil + strlen (facil), ",0%08x", pp->facilities);
37 printf ("%s specdate: %.4s-%.2s-%.2s\n", prefix, date, date+4, date+6);
38 printf ("%s specfrom: %s\n", prefix, producer);
39 printf ("%s facility: %s\n", prefix, facil + 1);
43 volatile bool callback_done = false;
45 void cb_ping_done (struct tlspool_async_request *cbdata, int opt_fd) {
51 int main (int argc, char *argv []) {
52 char *sockpath = NULL;
53 struct tlspool_async_pool mypool;
54 struct tlspool_async_request myreq;
55 pingpool_t *pp = &myreq.cmd.pio_data.pioc_ping;
58 fprintf (stderr, "Usage: %s [socketfile]\n", argv [0]);
64 assert (tlspool_async_open (&mypool, sizeof (struct tlspool_command),
65 TLSPOOL_IDENTITY_V2, PIOF_FACILITY_STARTTLS,
67 print_pioc_ping (&mypool.pingdata, "Initial ");
70 memset (&myreq, 0, sizeof (myreq));
71 strcpy (pp->YYYYMMDD_producer, TLSPOOL_IDENTITY_V2);
72 pp->facilities = PIOF_FACILITY_ALL_CURRENT;
74 print_pioc_ping (pp, "Client ");
77 // We now setup the request, and allow it to callback to us.
78 // We will loop until this has happened, which is not the best
79 // programming practice, but alright for a simple demonstration.
80 // In production use, we should of course use locks.
82 myreq.cmd.pio_cmd = PIOC_PING_V2;
83 myreq.cbfunc = cb_ping_done;
86 // What we do now is not what any normal program should do; we ask
87 // for all the facilities that the TLS Pool can provide. That may
88 // include things we never heard of, and may need to mention as an
89 // integer flag value. For a ping utility, that's useful, but for
90 // any sane program it would be a bad example to follow.
92 assert (tlspool_async_request (&mypool, &myreq, -1));
93 while (!callback_done) {
94 tlspool_async_process (&mypool);
96 print_pioc_ping (pp, "TLS Pool");
99 assert (tlspool_async_close (&mypool, true));