Improvements in Python support and installation of Python and includes
[tlspool] / tool / pingpool.c
1 /* pingpool.c -- Show the input/output of a PING operation.
2  *
3  * From: Rick van Rein <rick@openfortress.nl>
4  */
5
6
7 #include <unistd.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <stdio.h>
11
12 #include <tlspool/commands.h>
13 #include <tlspool/starttls.h>
14
15
16 void print_pioc_ping (pingpool_t *pp, char *prefix) {
17         char *date = pp->YYYYMMDD_producer;
18         char *producer = date + 8;
19         char facil [256];
20         *facil = '\0';
21         if (pp->facilities & PIOF_FACILITY_STARTTLS) {
22                 strcat (facil, ",starttls");
23                 pp->facilities &= ~PIOF_FACILITY_STARTTLS;
24         }
25         if (pp->facilities & PIOF_FACILITY_STARTGSS) {
26                 strcat (facil, ",startgss");
27                 pp->facilities &= ~PIOF_FACILITY_STARTGSS;
28         }
29         if (pp->facilities & PIOF_FACILITY_STARTSSH) {
30                 strcat (facil, ",startssh");
31                 pp->facilities &= ~PIOF_FACILITY_STARTSSH;
32         }
33         if (pp->facilities) {
34                 sprintf (facil + strlen (facil), ",0%08x", pp->facilities);
35         }
36         printf ("%s specdate: %.4s-%.2s-%.2s\n", prefix, date, date+4, date+6);
37         printf ("%s specfrom: %s\n", prefix, producer);
38         printf ("%s facility: %s\n", prefix, facil + 1);
39 }
40
41 int main (int argc, char *argv []) {
42         char *sockpath = NULL;
43         pingpool_t pp;
44
45         if (argc > 2) {
46                 fprintf (stderr, "Usage: %s [socketfile]\n", argv [0]);
47                 exit (1);
48         }
49         if (argc == 2) {
50                 sockpath = argv [1];
51         }
52         (void) tlspool_open_poolhandle (sockpath);
53
54         memset (&pp, 0, sizeof (pp));
55         strcpy (pp.YYYYMMDD_producer, TLSPOOL_IDENTITY_V2);
56         pp.facilities = PIOF_FACILITY_ALL_CURRENT;
57         printf ("\n");
58         print_pioc_ping (&pp, "Client  ");
59         printf ("\n");
60         //
61         // What we do now is not what any normal program should do; we ask
62         // for all the facilities that the TLS Pool can provide.  That may
63         // include things we never heard of, and may need to mention as an
64         // integer flag value.  For a ping utility, that's useful, but for
65         // any sane program it would be a bad example to follow.
66         //
67         pp.facilities = ~0L;
68         if (tlspool_ping (&pp) < 0) {
69                 perror ("Failed to ping TLS Pool");
70                 exit (1);
71         }
72         print_pioc_ping (&pp, "TLS Pool");
73         printf ("\n");
74 }
75