wmclockmon: update change-log
[dockapps.git] / wmbiff / wmbiff / test_tlscomm.c
blob7370b5ba7207614b1f58d9f4aa496e7c389a8ac0
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <sys/types.h>
9 #include <sys/time.h>
10 #include <unistd.h>
11 #ifdef USE_GNUTLS
12 #include <gnutls/gnutls.h>
13 #endif
15 #include "Client.h"
16 #include "tlsComm.h"
17 #include "wmbiff.h"
19 int debug_default = 2;
20 int SkipCertificateCheck = 0;
21 const char *certificate_filename = NULL;
22 const char *tls = "NORMAL";
24 int exists(UNUSED(const char *filename))
26 return (0);
28 void ProcessPendingEvents(void)
30 return;
33 int x_socket(void)
35 return (0);
38 #ifdef USE_GNUTLS
39 #include "gnutls-common.h"
40 int print_info(UNUSED(gnutls_session_t state), UNUSED(const char* hostname))
42 return (0);
44 #endif
46 int Relax = 1;
49 int indices[12];
50 const char *sequence[][4] = {
51 {NULL, NULL, NULL, NULL},
52 {"prefix", " hello", NULL},
53 {"pre", "fix", " hello", NULL},
54 {"\r\n", ")\r\n", "prefix", NULL},
55 {NULL, NULL, NULL, NULL},
58 /* trick tlscomm into believing it can read. */
59 ssize_t read(int s, void *buf, size_t buflen)
61 int val = indices[s]++;
63 if (sequence[s][val] == NULL) {
64 indices[s]--; /* make it stay */
65 return 0;
66 } else {
67 strncpy(buf, sequence[s][val], buflen);
68 printf("read: %s\n", sequence[s][val]);
69 return (strlen(sequence[s][val]));
73 int
74 select(int nfds, fd_set * r,
75 fd_set * w __attribute__ ((unused)),
76 fd_set * x __attribute__ ((unused)),
77 struct timeval *tv __attribute__ ((unused)))
79 int i;
80 int ready = 0;
81 for (i = 0; i < nfds; i++) {
82 if (FD_ISSET(i, r) && sequence[i][indices[i]] != NULL) {
83 ready++;
84 } else {
85 FD_CLR(i, r);
88 if (ready == 0) {
89 printf("botched.\n");
91 return ready;
94 #define BUF_SIZE 1024
96 struct connection_state {
97 int sd;
98 char *name;
99 /*@null@ */ void *tls_state;
100 /*@null@ */ void *xcred;
101 char unprocessed[BUF_SIZE];
102 void *pc; /* mailbox handle for debugging messages */
106 main(int argc __attribute__ ((unused)), char **argv
107 __attribute__ ((unused)))
109 char buf[255];
110 struct connection_state scs;
111 scs.name = strdup("test");
112 scs.unprocessed[0] = '\0';
113 scs.pc = NULL;
114 scs.tls_state = NULL;
115 scs.xcred = NULL;
116 alarm(10);
118 for (scs.sd = 1; sequence[scs.sd][0] != NULL; scs.sd++) {
119 memset(scs.unprocessed, 0, BUF_SIZE);
120 printf("%d\n", tlscomm_expect(&scs, "prefix", buf, 255));
122 free(scs.name);
123 return 0;