1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-30 00:00:16 +01:00

style-cleanups.patch

Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
Andy Green 2010-11-08 21:04:23 +00:00
parent 40a3a02190
commit 018d8eb44b
3 changed files with 36 additions and 23 deletions

View file

@ -21,7 +21,8 @@
#include "private-libwebsockets.h" #include "private-libwebsockets.h"
void md5(const unsigned char *input, int ilen, unsigned char output[16]); void libwebsockets_md5(const unsigned char *input, int ilen,
unsigned char output[16]);
static int interpret_key(const char *key, unsigned int *result) static int interpret_key(const char *key, unsigned int *result)
{ {
@ -191,7 +192,7 @@ libwebsocket_read(struct libwebsocket *wsi, unsigned char * buf, size_t len)
* payload after our headers * payload after our headers
*/ */
md5(sum, 16, (unsigned char *)p); libwebsockets_md5(sum, 16, (unsigned char *)p);
p += 16; p += 16;
/* it's complete: go ahead and send it */ /* it's complete: go ahead and send it */
@ -201,8 +202,8 @@ libwebsocket_read(struct libwebsocket *wsi, unsigned char * buf, size_t len)
#ifdef DEBUG #ifdef DEBUG
fwrite(response, 1, p - response, stderr); fwrite(response, 1, p - response, stderr);
#endif #endif
n = libwebsocket_write(wsi, (unsigned char *)response, p - response, n = libwebsocket_write(wsi, (unsigned char *)response,
LWS_WRITE_HTTP); p - response, LWS_WRITE_HTTP);
if (n < 0) { if (n < 0) {
fprintf(stderr, "ERROR writing to socket"); fprintf(stderr, "ERROR writing to socket");
goto bail; goto bail;

View file

@ -127,14 +127,14 @@ int libwebsocket_create_server(int port,
if (use_ssl) if (use_ssl)
fprintf(stderr, " Compiled with SSL support, using it\n"); fprintf(stderr, " Compiled with SSL support, using it\n");
else else
fprintf(stderr, " Compiled with SSL support, but not using it\n"); fprintf(stderr, " Compiled with SSL support, not using it\n");
#else #else
if (ssl_cert_filepath != NULL && ssl_private_key_filepath != NULL) { if (ssl_cert_filepath != NULL && ssl_private_key_filepath != NULL) {
fprintf(stderr, " Not compiled for OpenSSl support!\n"); fprintf(stderr, " Not compiled for OpenSSl support!\n");
return -1; return -1;
} }
fprintf(stderr, " Compiled without SSL support, listening unencrypted\n"); fprintf(stderr, " Compiled without SSL support, serving unencrypted\n");
#endif #endif
#ifdef LWS_OPENSSL_SUPPORT #ifdef LWS_OPENSSL_SUPPORT
@ -169,14 +169,17 @@ int libwebsocket_create_server(int port,
return -1; return -1;
} }
/* set the private key from KeyFile */ /* set the private key from KeyFile */
if (SSL_CTX_use_PrivateKey_file(ssl_ctx, ssl_private_key_filepath, if (SSL_CTX_use_PrivateKey_file(ssl_ctx,
ssl_private_key_filepath,
SSL_FILETYPE_PEM) != 1) { SSL_FILETYPE_PEM) != 1) {
fprintf(stderr, "ssl problem getting key '%s': %s\n", ssl_private_key_filepath, ERR_error_string(ERR_get_error(), ssl_err_buf)); fprintf(stderr, "ssl problem getting key '%s': %s\n",
ssl_private_key_filepath,
ERR_error_string(ERR_get_error(), ssl_err_buf));
return (-1); return (-1);
} }
/* verify private key */ /* verify private key */
if (!SSL_CTX_check_private_key(ssl_ctx)) { if (!SSL_CTX_check_private_key(ssl_ctx)) {
fprintf(stderr, "Private SSL key does not match cert\n"); fprintf(stderr, "Private SSL key doesn't match cert\n");
return (-1); return (-1);
} }
@ -294,29 +297,36 @@ int libwebsocket_create_server(int port,
#ifdef LWS_OPENSSL_SUPPORT #ifdef LWS_OPENSSL_SUPPORT
if (use_ssl) { if (use_ssl) {
wsi[fds_count]->ssl = SSL_new(ssl_ctx); // get new SSL state with context wsi[fds_count]->ssl = SSL_new(ssl_ctx);
if (wsi[fds_count]->ssl == NULL) { if (wsi[fds_count]->ssl == NULL) {
fprintf(stderr, "SSL_new failed: %s\n", fprintf(stderr, "SSL_new failed: %s\n",
ERR_error_string(SSL_get_error(wsi[fds_count]->ssl, 0), NULL)); ERR_error_string(SSL_get_error(
wsi[fds_count]->ssl, 0), NULL));
free(wsi[fds_count]); free(wsi[fds_count]);
continue; continue;
} }
SSL_set_fd(wsi[fds_count]->ssl, fd); // set SSL socket SSL_set_fd(wsi[fds_count]->ssl, fd);
n = SSL_accept(wsi[fds_count]->ssl); n = SSL_accept(wsi[fds_count]->ssl);
if (n != 1) { if (n != 1) {
/* browsers seem to probe with various ssl params which fail then retry */ /*
debug("SSL_accept failed for socket %u: %s\n", * browsers seem to probe with various
* ssl params which fail then retry
* and succeed
*/
debug("SSL_accept failed skt %u: %s\n",
fd, fd,
ERR_error_string(SSL_get_error(wsi[fds_count]->ssl, n), ERR_error_string(SSL_get_error(
NULL)); wsi[fds_count]->ssl, n), NULL));
SSL_free(wsi[fds_count]->ssl); SSL_free(wsi[fds_count]->ssl);
free(wsi[fds_count]); free(wsi[fds_count]);
continue; continue;
} }
debug("accepted new SSL conn port %u on fd=%d SSL ver %s\n", debug("accepted new SSL conn "
ntohs(cli_addr.sin_port), fd, SSL_get_version(wsi[fds_count]->ssl)); "port %u on fd=%d SSL ver %s\n",
ntohs(cli_addr.sin_port), fd,
SSL_get_version(wsi[fds_count]->ssl));
} else { } else {
// fprintf(stderr, "accepted new conn port %u on fd=%d\n", // fprintf(stderr, "accepted new conn port %u on fd=%d\n",
@ -352,7 +362,8 @@ int libwebsocket_create_server(int port,
fprintf(stderr, "Session Socket dead\n"); fprintf(stderr, "Session Socket dead\n");
libwebsocket_close_and_free_session(wsi[client]); libwebsocket_close_and_free_session(
wsi[client]);
goto nuke_this; goto nuke_this;
} }
@ -378,7 +389,8 @@ int libwebsocket_create_server(int port,
} }
if (!n) { if (!n) {
// fprintf(stderr, "POLLIN with 0 len waiting\n"); // fprintf(stderr, "POLLIN with 0 len waiting\n");
libwebsocket_close_and_free_session(wsi[client]); libwebsocket_close_and_free_session(
wsi[client]);
goto nuke_this; goto nuke_this;
} }

View file

@ -207,7 +207,7 @@ static const unsigned char md5_padding[64] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}; };
void md5(const unsigned char *input, int ilen, unsigned char output[16]) void libwebsockets_md5(const unsigned char *input, int ilen, unsigned char output[16])
{ {
struct md5_context ctx; struct md5_context ctx;
unsigned long last, padn; unsigned long last, padn;