Update gnutls code (require at least 2.2.0).
[dockapps.git] / wmbiff / wmbiff / test_tlscomm.c
blob5b895309030f9525244e57b48c9fbc1a5e8f98e7
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>
7 #include <tlsComm.h>
9 int debug_default = 2;
10 int SkipCertificateCheck = 0;
11 const char *certificate_filename = NULL;
12 const char *tls = "NORMAL";
14 int exists(const char *filename __attribute__ ((unused)))
16 return (0);
18 void ProcessPendingEvents(void)
20 return;
23 int x_socket(void)
25 return (0);
28 int print_info(void *state __attribute__((unused)))
30 return (0);
33 int Relax = 1;
36 int indices[12];
37 const char *sequence[][4] = {
38 {NULL, NULL, NULL, NULL},
39 {"prefix", " hello", NULL},
40 {"pre", "fix", " hello", NULL},
41 {"\r\n", ")\r\n", "prefix", NULL},
42 {NULL, NULL, NULL, NULL},
45 /* trick tlscomm into believing it can read. */
46 ssize_t read(int s, void *buf, size_t buflen)
48 int val = indices[s]++;
50 if (sequence[s][val] == NULL) {
51 indices[s]--; /* make it stay */
52 return 0;
53 } else {
54 strncpy(buf, sequence[s][val], buflen);
55 printf("read: %s\n", sequence[s][val]);
56 return (strlen(sequence[s][val]));
60 int
61 select(int nfds, fd_set * r,
62 fd_set * w __attribute__ ((unused)),
63 fd_set * x __attribute__ ((unused)),
64 struct timeval *tv __attribute__ ((unused)))
66 int i;
67 int ready = 0;
68 for (i = 0; i < nfds; i++) {
69 if (FD_ISSET(i, r) && sequence[i][indices[i]] != NULL) {
70 ready++;
71 } else {
72 FD_CLR(i, r);
75 if (ready == 0) {
76 printf("botched.\n");
78 return ready;
81 #define BUF_SIZE 1024
83 struct connection_state {
84 int sd;
85 char *name;
86 /*@null@ */ void *tls_state;
87 /*@null@ */ void *xcred;
88 char unprocessed[BUF_SIZE];
89 void *pc; /* mailbox handle for debugging messages */
92 int
93 main(int argc __attribute__ ((unused)), char **argv
94 __attribute__ ((unused)))
96 char buf[255];
97 struct connection_state scs;
98 scs.name = strdup("test");
99 scs.unprocessed[0] = '\0';
100 scs.pc = NULL;
101 scs.tls_state = NULL;
102 scs.xcred = NULL;
103 alarm(10);
105 for (scs.sd = 1; sequence[scs.sd][0] != NULL; scs.sd++) {
106 memset(scs.unprocessed, 0, BUF_SIZE);
107 printf("%d\n", tlscomm_expect(&scs, "prefix", buf, 255));
109 return 0;