diff --git a/include/libhttp.h b/include/libhttp.h index 8b8270c6..dbfab093 100644 --- a/include/libhttp.h +++ b/include/libhttp.h @@ -986,6 +986,7 @@ LIBHTTP_API void * XX_httplib_realloc_ex( void *memory, size_t newsize, const c LIBHTTP_API int httplib_atomic_dec( volatile int *addr ); LIBHTTP_API int httplib_atomic_inc( volatile int *addr ); +LIBHTTP_API int httplib_base64_encode( const unsigned char *src, int src_len, char *dst, int dst_len ); LIBHTTP_API int httplib_closedir( DIR *dir ); LIBHTTP_API int httplib_kill( pid_t pid, int sig_num ); LIBHTTP_API int httplib_mkdir( const char *path, int mode ); diff --git a/src/httplib_send_websocket_handshake.c b/src/httplib_send_websocket_handshake.c index 36db19a9..665a23aa 100644 --- a/src/httplib_send_websocket_handshake.c +++ b/src/httplib_send_websocket_handshake.c @@ -29,6 +29,8 @@ #include "httplib_string.h" #include "httplib_utils.h" +#define B64_SHA_LEN (sizeof(sha)*2) + /* * int XX_httplib_send_websocket_handshake( struct httplib_connection *conn, const char *websock_key ); * @@ -44,7 +46,7 @@ int XX_httplib_send_websocket_handshake( struct httplib_connection *conn, const const char *protocol; char buf[100]; char sha[20]; - char b64_sha[sizeof(sha) * 2]; + char b64_sha[B64_SHA_LEN]; SHA1_CTX sha_ctx; int truncated; @@ -65,7 +67,7 @@ int XX_httplib_send_websocket_handshake( struct httplib_connection *conn, const SHA1Update( & sha_ctx, (unsigned char *)buf, (uint32_t)strlen(buf) ); SHA1Final( (unsigned char *)sha, &sha_ctx ); - XX_httplib_base64_encode( (unsigned char *)sha, sizeof(sha), b64_sha ); + httplib_base64_encode( (unsigned char *)sha, sizeof(sha), b64_sha, B64_SHA_LEN ); httplib_printf( conn, "HTTP/1.1 101 Switching Protocols\r\n" "Upgrade: websocket\r\n" diff --git a/src/httplib_utils.h b/src/httplib_utils.h index a6f31c27..2f9240f1 100644 --- a/src/httplib_utils.h +++ b/src/httplib_utils.h @@ -23,7 +23,6 @@ #define LEAP_YEAR(x) ( ((x)%4) == 0 && ( ((x)%100) != 0 || ((x)%400) == 0 ) ) void XX_httplib_addenv( struct cgi_environment *env, PRINTF_FORMAT_STRING(const char *fmt), ... ) PRINTF_ARGS(2, 3); -void XX_httplib_base64_encode( const unsigned char *src, int src_len, char *dst ); double XX_httplib_difftimespec( const struct timespec *ts_now, const struct timespec *ts_before ); uint64_t XX_httplib_get_random( void ); void XX_httplib_gmt_time_string( char *buf, size_t buf_len, time_t *t );