diff --git a/.gitignore b/.gitignore index b13215b0..8a076ef7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ - libhttp +libhttpserver testmime *-cache *.dmg @@ -9,6 +9,7 @@ testmime [oO]utput [tT]esting *~ +*.core obj/*.o obj/*.obj diff --git a/Makefile b/Makefile index 67cd070f..5aff1541 100644 --- a/Makefile +++ b/Makefile @@ -150,12 +150,13 @@ ${OBJDIR}%${OBJEXT} : ${SRCDIR}%.c ${TSTDIR}${OBJDIR}%${OBJEXT} : ${TSTDIR}%.c ${CC} -c ${CPPFLAGS} ${CFLAGS} ${DFLAGS} ${OFLAG}$@ $< -all: ${LIBDIR}libhttp${LIBEXT} testmime${EXEEXT} +all: ${LIBDIR}libhttp${LIBEXT} testmime${EXEEXT} libhttpserver${EXEEXT} clean: ${RM} ${OBJDIR}*${OBJEXT} ${RM} ${LIBDIR}libhttp${LIBEXT} ${RM} testmime${EXEEXT} + ${RM} libhttpserver${EXEEXT} testmime${EXEEXT} : \ ${TSTDIR}${OBJDIR}testmime${OBJEXT} \ @@ -167,6 +168,17 @@ testmime${EXEEXT} : \ ${STRIP} testmime${EXEEXT} +libhttpserver${EXEEXT} : \ + ${OBJDIR}main${OBJEXT} \ + ${LIBDIR}libhttp${LIBEXT} \ + Makefile + ${LINK} ${XFLAG}libhttpserver${EXEEXT} \ + ${OBJDIR}main${OBJEXT} \ + ${LIBDIR}libhttp${LIBEXT} \ + ${LIBS} + ${STRIP} libhttpserver${EXEEXT} + + OBJLIST = \ ${OBJDIR}extern_md5${OBJEXT} \ ${OBJDIR}extern_sha1${OBJEXT} \ @@ -413,6 +425,9 @@ ${LIBDIR}libhttp${LIBEXT} : \ ${TSTDIR}${OBJDIR}testmime${OBJEXT} : ${TSTDIR}testmime.c \ ${INCDIR}libhttp.h +${OBJDIR}main${OBJEXT} : ${SRCDIR}main.c \ + ${INCDIR}libhttp.h + ${OBJDIR}extern_md5${OBJEXT} : ${SRCDIR}extern_md5.c \ ${INCDIR}libhttp.h diff --git a/src/httplib_accept_new_connection.c b/src/httplib_accept_new_connection.c index fb83eb46..a90bddba 100644 --- a/src/httplib_accept_new_connection.c +++ b/src/httplib_accept_new_connection.c @@ -50,7 +50,7 @@ void XX_httplib_accept_new_connection( const struct socket *listener, struct htt so.sock = accept( listener->sock, &so.rsa.sa, &len ); if ( so.sock == INVALID_SOCKET ) return; - + if ( ! XX_httplib_check_acl( ctx, ntohl(*(uint32_t *)&so.rsa.sin.sin_addr )) ) { XX_httplib_sockaddr_to_string( src_addr, sizeof(src_addr), &so.rsa ); @@ -60,6 +60,7 @@ void XX_httplib_accept_new_connection( const struct socket *listener, struct htt } else { + /* * Put so socket structure into the queue */ diff --git a/src/httplib_config_options.c b/src/httplib_config_options.c index 64d59b33..a600d3bc 100644 --- a/src/httplib_config_options.c +++ b/src/httplib_config_options.c @@ -71,9 +71,7 @@ struct httplib_option XX_httplib_config_options[] = { { "error_pages", CONFIG_TYPE_DIRECTORY, NULL }, { "tcp_nodelay", CONFIG_TYPE_NUMBER, "0" }, { "static_file_max_age", CONFIG_TYPE_NUMBER, NULL }, -#if defined(__linux__) { "allow_sendfile_call", CONFIG_TYPE_BOOLEAN, "yes" }, -#endif { NULL, CONFIG_TYPE_UNKNOWN, NULL } }; diff --git a/src/httplib_handle_directory_request.c b/src/httplib_handle_directory_request.c index 68140d54..f6efebe4 100644 --- a/src/httplib_handle_directory_request.c +++ b/src/httplib_handle_directory_request.c @@ -36,7 +36,7 @@ void XX_httplib_handle_directory_request( struct httplib_connection *conn, const char date[64]; time_t curtime; - if ( conn == NULL ) return; + if ( conn == NULL || conn->ctx == NULL ) return; if ( dir == NULL ) { XX_httplib_send_http_error( conn, 500, "Internal server error\nOpening NULL directory" ); return; } if ( ! XX_httplib_scan_directory( conn, dir, & data, XX_httplib_dir_scan_callback ) ) { diff --git a/src/httplib_handle_request.c b/src/httplib_handle_request.c index ca2c6755..e3988007 100644 --- a/src/httplib_handle_request.c +++ b/src/httplib_handle_request.c @@ -67,7 +67,7 @@ void XX_httplib_handle_request( struct httplib_connection *conn ) { char * var; } ptr; - if ( conn == NULL ) return; + if ( conn == NULL || conn->ctx == NULL ) return; ri = & conn->request_info; is_found = false; @@ -98,7 +98,7 @@ void XX_httplib_handle_request( struct httplib_connection *conn ) { ptr.var = strchr( ri->request_uri, '?' ); if ( ptr.var != NULL ) *(ptr.var++) = '\0'; - conn->request_info.query_string = ptr.var; + ri->query_string = ptr.var; /* * 1.2. do a https redirect, if required. Do not decode URIs yet. @@ -386,13 +386,13 @@ no_callback_resource: return; } - + /* * 9. This request is either for a static file or resource handled * by a script file. Thus, a DOCUMENT_ROOT must exist. */ - else if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) { + if ( conn->ctx->cfg[DOCUMENT_ROOT] == NULL ) { XX_httplib_send_http_error( conn, 404, "%s", "Not Found" ); return; diff --git a/src/httplib_main.h b/src/httplib_main.h index 32afdc64..492a1528 100644 --- a/src/httplib_main.h +++ b/src/httplib_main.h @@ -432,12 +432,9 @@ enum { WEBSOCKET_ROOT, ACCESS_CONTROL_ALLOW_ORIGIN, ERROR_PAGES, - CONFIG_TCP_NODELAY, /* Prepended CONFIG_ to avoid conflict with the socket option typedef TCP_NODELAY. */ + CONFIG_TCP_NODELAY, STATIC_FILE_MAX_AGE, -#if defined(__linux__) ALLOW_SENDFILE_CALL, -#endif - NUM_OPTIONS }; diff --git a/src/httplib_process_new_connection.c b/src/httplib_process_new_connection.c index a64420e6..12c70ca9 100644 --- a/src/httplib_process_new_connection.c +++ b/src/httplib_process_new_connection.c @@ -61,6 +61,7 @@ void XX_httplib_process_new_connection( struct httplib_connection *conn ) { */ conn->data_len = 0; + do { if ( ! XX_httplib_getreq( conn, ebuf, sizeof(ebuf), &reqerr ) ) { @@ -122,14 +123,14 @@ void XX_httplib_process_new_connection( struct httplib_connection *conn ) { if ( ebuf[0] == '\0' ) { - if ( conn->request_info.local_uri ) { + if ( conn->request_info.local_uri != NULL ) { /* * handle request to local server */ XX_httplib_handle_request( conn ); - if (conn->ctx->callbacks.end_request != NULL) conn->ctx->callbacks.end_request(conn, conn->status_code); + if ( conn->ctx->callbacks.end_request != NULL ) conn->ctx->callbacks.end_request( conn, conn->status_code ); XX_httplib_log_access(conn); } diff --git a/src/httplib_produce_socket.c b/src/httplib_produce_socket.c index 95c61330..bdf3490c 100644 --- a/src/httplib_produce_socket.c +++ b/src/httplib_produce_socket.c @@ -53,7 +53,7 @@ void XX_httplib_produce_socket( struct httplib_context *ctx, const struct socket ctx->client_socks[i] = *sp; ctx->client_socks[i].in_use = 1; - event_signal(ctx->client_wait_events[i]); + event_signal( ctx->client_wait_events[i] ); return; } @@ -74,7 +74,7 @@ void XX_httplib_produce_socket( struct httplib_context *ctx, const struct socket * Master thread adds accepted socket to a queue */ -void XX_httplib_produce_socket(struct httplib_context *ctx, const struct socket *sp) { +void XX_httplib_produce_socket( struct httplib_context *ctx, const struct socket *sp ) { #define QUEUE_SIZE(ctx) ((int)(ARRAY_SIZE(ctx->queue))) diff --git a/src/httplib_push_all.c b/src/httplib_push_all.c index 2c48fcd8..f347c0ee 100644 --- a/src/httplib_push_all.c +++ b/src/httplib_push_all.c @@ -62,8 +62,7 @@ static int64_t push( struct httplib_context *ctx, FILE *fp, SOCKET sock, SSL *ss if ( ssl != NULL ) return -1; #endif /* NO_SSL */ - if ( len > (int64_t)SIZE_T_MAX ) len = SIZE_T_MAX; - if ( len > (int64_t)INT_MAX ) len = INT_MAX; + if ( len > INT_MAX ) len = INT_MAX; if ( timeout > 0.0 ) clock_gettime( CLOCK_MONOTONIC, &start ); diff --git a/src/httplib_worker_thread.c b/src/httplib_worker_thread.c index cea68b75..32bce71e 100644 --- a/src/httplib_worker_thread.c +++ b/src/httplib_worker_thread.c @@ -132,6 +132,7 @@ static void *worker_thread_run( struct worker_thread_args *thread_args ) { conn->request_info.has_ssl = conn->client.has_ssl; if ( conn->client.has_ssl ) { + #ifndef NO_SSL /* * HTTPS connection @@ -167,7 +168,9 @@ static void *worker_thread_run( struct worker_thread_args *thread_args ) { } } #endif - } else XX_httplib_process_new_connection( conn ); + } + + else XX_httplib_process_new_connection( conn ); XX_httplib_close_connection( conn ); } diff --git a/src/main.c b/src/main.c index ac5f1811..77fc7aaa 100644 --- a/src/main.c +++ b/src/main.c @@ -683,7 +683,7 @@ static void set_absolute_path(char *options[], const char *option_name, const ch be the relative directory for everything. Extract libhttp executable directory into path. */ if ((p = strrchr(path_to_libhttp_exe, DIRSEP)) == NULL) { - IGNORE_UNUSED_RESULT(getcwd(path, sizeof(path))); + getcwd(path, sizeof(path)); } else { snprintf(path, sizeof(path) - 1, "%.*s", (int)(p - path_to_libhttp_exe), path_to_libhttp_exe); path[sizeof(path) - 1] = 0; @@ -693,7 +693,7 @@ static void set_absolute_path(char *options[], const char *option_name, const ch strncat(path, option_value, sizeof(path) - strlen(path) - 1); /* Absolutize the path, and set the option */ - IGNORE_UNUSED_RESULT(abs_path(path, absolute, sizeof(absolute))); + abs_path(path, absolute, sizeof(absolute)); set_option(options, option_name, absolute); } }