3
#include "../../testsuite/test.hpp"
9
THREAD_RETURN YASSL_API echoserver_test(void*);
10
int main(int argc, char** argv)
17
echoserver_test(&args);
20
return args.return_code;
23
#endif // NO_MAIN_DRIVER
27
void EchoError(SSL_CTX* ctx, SSL* ssl, SOCKET_T& s1, SOCKET_T& s2,
38
THREAD_RETURN YASSL_API echoserver_test(void* args)
42
WSAStartup(0x0002, &wsd);
49
set_args(argc, argv, *static_cast<func_args*>(args));
53
if (argc >= 2) fout = fopen(argv[1], "w");
54
if (!fout) err_sys("can't open output file");
59
SSL_METHOD* method = SSLv23_server_method();
60
SSL_CTX* ctx = SSL_CTX_new(method);
63
DH* dh = set_tmpDH(ctx);
67
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER)
68
// signal ready to tcp_accept
69
func_args& server_args = *((func_args*)args);
70
tcp_ready& ready = *server_args.signal_;
71
pthread_mutex_lock(&ready.mutex_);
73
pthread_cond_signal(&ready.cond_);
74
pthread_mutex_unlock(&ready.mutex_);
79
socklen_t client_len = sizeof(client);
80
SOCKET_T clientfd = accept(sockfd, (sockaddr*)&client,
81
(ACCEPT_THIRD_T)&client_len);
85
err_sys("tcp accept failed");
88
SSL* ssl = SSL_new(ctx);
89
SSL_set_fd(ssl, clientfd);
90
if (SSL_accept(ssl) != SSL_SUCCESS) {
91
printf("SSL_accept failed\n");
99
while ( (echoSz = SSL_read(ssl, command, sizeof(command))) > 0) {
101
if ( strncmp(command, "quit", 4) == 0) {
102
printf("client sent quit command: shutting down!\n");
106
else if ( strncmp(command, "GET", 3) == 0) {
107
char type[] = "HTTP/1.0 200 ok\r\nContent-type:"
108
" text/html\r\n\r\n";
109
char header[] = "<html><body BGCOLOR=\"#ffffff\">\n<pre>\n";
110
char body[] = "greetings from yaSSL\n";
111
char footer[] = "</body></html>\r\n\r\n";
113
strncpy(command, type, sizeof(type));
114
echoSz = sizeof(type) - 1;
116
strncpy(&command[echoSz], header, sizeof(header));
117
echoSz += sizeof(header) - 1;
118
strncpy(&command[echoSz], body, sizeof(body));
119
echoSz += sizeof(body) - 1;
120
strncpy(&command[echoSz], footer, sizeof(footer));
121
echoSz += sizeof(footer);
123
if (SSL_write(ssl, command, echoSz) != echoSz)
124
EchoError(ctx, ssl, sockfd, clientfd, "SSL_write failed");
131
fputs(command, fout);
134
if (SSL_write(ssl, command, echoSz) != echoSz)
135
EchoError(ctx, ssl, sockfd, clientfd, "SSL_write failed");
147
((func_args*)args)->return_code = 0;