21 #include "../../testsuite/test.hpp" 
   24 #ifndef NO_MAIN_DRIVER 
   27     THREAD_RETURN YASSL_API echoserver_test(
void*);
 
   28     int main(
int argc, 
char** argv)
 
   35         echoserver_test(&args);
 
   38         return args.return_code;
 
   41 #endif // NO_MAIN_DRIVER 
   45 void EchoError(
SSL_CTX* ctx, 
SSL* ssl, SOCKET_T& s1, SOCKET_T& s2,
 
   56 THREAD_RETURN YASSL_API echoserver_test(
void* args)
 
   60     WSAStartup(0x0002, &wsd);
 
   67     set_args(argc, argv, *static_cast<func_args*>(args));
 
   71     if (argc >= 2) fout = fopen(argv[1], 
"w");
 
   72     if (!fout) err_sys(
"can't open output file");
 
   78     SSL_CTX*    ctx    = SSL_CTX_new(method);
 
   81     DH* dh = set_tmpDH(ctx);
 
   85 #if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) 
   89     pthread_mutex_lock(&ready.mutex_);
 
   91     pthread_cond_signal(&ready.cond_);
 
   92     pthread_mutex_unlock(&ready.mutex_);
 
   97         socklen_t   client_len = 
sizeof(client);
 
   98         SOCKET_T    clientfd   = accept(sockfd, (sockaddr*)&client,
 
   99                                       (ACCEPT_THIRD_T)&client_len);
 
  100         if (clientfd == (SOCKET_T) -1) {
 
  103             err_sys(
"tcp accept failed");
 
  106         SSL* ssl = SSL_new(ctx);
 
  107         SSL_set_fd(ssl, clientfd);
 
  108         if (SSL_accept(ssl) != SSL_SUCCESS) {
 
  109             printf(
"SSL_accept failed\n");
 
  117         while ( (echoSz = SSL_read(ssl, command, 
sizeof(command))) > 0) {
 
  119             if ( strncmp(command, 
"quit", 4) == 0) {
 
  120                 printf(
"client sent quit command: shutting down!\n");
 
  124             else if ( strncmp(command, 
"GET", 3) == 0) {
 
  125                 char type[]   = 
"HTTP/1.0 200 ok\r\nContent-type:" 
  126                                 " text/html\r\n\r\n";
 
  127                 char header[] = 
"<html><body BGCOLOR=\"#ffffff\">\n<pre>\n";
 
  128                 char body[]   = 
"greetings from yaSSL\n";
 
  129                 char footer[] = 
"</body></html>\r\n\r\n";
 
  131                 strncpy(command, type, 
sizeof(type));
 
  132                 echoSz = 
sizeof(
type) - 1;
 
  134                 strncpy(&command[echoSz], header, 
sizeof(header));
 
  135                 echoSz += 
sizeof(header) - 1;
 
  136                 strncpy(&command[echoSz], body, 
sizeof(body));
 
  137                 echoSz += 
sizeof(body) - 1;
 
  138                 strncpy(&command[echoSz], footer, 
sizeof(footer));
 
  139                 echoSz += 
sizeof(footer);
 
  141                 if (SSL_write(ssl, command, echoSz) != echoSz)
 
  142                     EchoError(ctx, ssl, sockfd, clientfd, 
"SSL_write failed");
 
  149             fputs(command, fout);
 
  152             if (SSL_write(ssl, command, echoSz) != echoSz)
 
  153                 EchoError(ctx, ssl, sockfd, clientfd, 
"SSL_write failed");