35da32299264c7885691f58dfcaacd2f6c51e4b6
[dockapps.git] / wmbiff / wmbiff / test_tlscomm.c
blob35da32299264c7885691f58dfcaacd2f6c51e4b6
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <sys/time.h>
6 #include <unistd.h>
8 int debug_default = 2;
9 int SkipCertificateCheck = 0;
10 const char *certificate_filename = NULL;
11 int exists(const char *filename __attribute__ ((unused)))
13 return (0);
15 void ProcessPendingEvents(void)
17 return;
20 int x_socket(void)
22 return (0);
25 int print_info(void *state __attribute__((unused)))
27 return (0);
30 int Relax = 1;
33 int indices[12];
34 const char *sequence[][4] = {
35 {NULL, NULL, NULL, NULL},
36 {"prefix", " hello", NULL},
37 {"pre", "fix", " hello", NULL},
38 {"\r\n", ")\r\n", "prefix", NULL},
39 {NULL, NULL, NULL, NULL},
42 /* trick tlscomm into believing it can read. */
43 ssize_t read(int s, void *buf, size_t buflen)
45 int val = indices[s]++;
47 if (sequence[s][val] == NULL) {
48 indices[s]--; /* make it stay */
49 return 0;
50 } else {
51 strncpy(buf, sequence[s][val], buflen);
52 printf("read: %s\n", sequence[s][val]);
53 return (strlen(sequence[s][val]));
57 int
58 select(int nfds, fd_set * r,
59 fd_set * w __attribute__ ((unused)),
60 fd_set * x __attribute__ ((unused)),
61 struct timeval *tv __attribute__ ((unused)))
63 int i;
64 int ready = 0;
65 for (i = 0; i < nfds; i++) {
66 if (FD_ISSET(i, r) && sequence[i][indices[i]] != NULL) {
67 ready++;
68 } else {
69 FD_CLR(i, r);
72 if (ready == 0) {
73 printf("botched.\n");
75 return ready;
78 #define BUF_SIZE 1024
80 struct connection_state {
81 int sd;
82 char *name;
83 /*@null@ */ void *tls_state;
84 /*@null@ */ void *xcred;
85 char unprocessed[BUF_SIZE];
86 void *pc; /* mailbox handle for debugging messages */
89 int
90 main(int argc __attribute__ ((unused)), char **argv
91 __attribute__ ((unused)))
93 char buf[255];
94 struct connection_state scs;
95 scs.name = strdup("test");
96 scs.unprocessed[0] = '\0';
97 scs.pc = NULL;
98 scs.tls_state = NULL;
99 scs.xcred = NULL;
100 alarm(10);
102 for (scs.sd = 1; sequence[scs.sd][0] != NULL; scs.sd++) {
103 memset(scs.unprocessed, 0, BUF_SIZE);
104 printf("%d\n", tlscomm_expect(&scs, "prefix", buf, 255));
106 return 0;