Fixed SSL communication

SVN revision: 2100
This commit is contained in:
Stefan Ritt 2008-04-10 11:06:15 +00:00
parent f3e0392b9e
commit b45e9ec46b

View File

@ -383,14 +383,19 @@ INT retrieve_elog(char *host, int port, char *subdir, int ssl, char *experiment,
SSL *ssl_con; SSL *ssl_con;
#endif #endif
if (ssl) /* avoid compiler warning */
sock = 0;
sock = elog_connect(host, port); sock = elog_connect(host, port);
if (sock < 0) if (sock < 0)
return sock; return sock;
#ifdef HAVE_SSL #ifdef HAVE_SSL
if (ssl) if (ssl)
if (ssl_connect(sock, &ssl_con) < 0) if (ssl_connect(sock, &ssl_con) < 0) {
printf("elogd server does not run SSL protocol\n");
return -1; return -1;
}
#endif #endif
/* compose request */ /* compose request */
@ -439,6 +444,11 @@ INT retrieve_elog(char *host, int port, char *subdir, int ssl, char *experiment,
strcat(request, "\r\n"); strcat(request, "\r\n");
/* send request */ /* send request */
#ifdef HAVE_SSL
if (ssl)
SSL_write(ssl_con, request, strlen(request));
else
#endif
send(sock, request, strlen(request), 0); send(sock, request, strlen(request), 0);
if (verbose) { if (verbose) {
printf("Request sent to host:\n"); printf("Request sent to host:\n");
@ -446,7 +456,13 @@ INT retrieve_elog(char *host, int port, char *subdir, int ssl, char *experiment,
} }
/* receive response */ /* receive response */
i = recv(sock, response, sizeof(response), 0); memset(response, 0, sizeof(response));
#ifdef HAVE_SSL
if (ssl)
i = SSL_read(ssl_con, response, sizeof(response)-1);
else
#endif
i = recv(sock, response, sizeof(response)-1, 0);
if (i < 0) { if (i < 0) {
perror("Cannot receive response"); perror("Cannot receive response");
return -1; return -1;
@ -454,12 +470,24 @@ INT retrieve_elog(char *host, int port, char *subdir, int ssl, char *experiment,
n = i; n = i;
while (i > 0) { while (i > 0) {
i = recv(sock, response + n, sizeof(response) - n, 0); #ifdef HAVE_SSL
if (ssl)
i = SSL_read(ssl_con, response + n, sizeof(response)-1-n);
else
#endif
i = recv(sock, response + n, sizeof(response)-1-n, 0);
if (i > 0) if (i > 0)
n += i; n += i;
} }
response[n] = 0; response[n] = 0;
#ifdef HAVE_SSL
if (ssl) {
SSL_shutdown(ssl_con);
SSL_free(ssl_con);
}
#endif
closesocket(sock); closesocket(sock);
if (verbose) { if (verbose) {
@ -740,8 +768,10 @@ INT submit_elog(char *host, int port, int ssl, char *subdir, char *experiment,
#ifdef HAVE_SSL #ifdef HAVE_SSL
if (ssl) if (ssl)
if (ssl_connect(sock, &ssl_con) < 0) if (ssl_connect(sock, &ssl_con) < 0) {
printf("elogd server does not run SSL protocol\n");
return -1; return -1;
}
#endif #endif
content_length = 100000; content_length = 100000;