libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit abecdd0f228230eb87fb26ff7c82616155932c55
parent ee326112b37d884aad27e52a367c8505e11b2894
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Fri, 25 Apr 2025 14:27:36 +0200

Fixed compiler warnings

Diffstat:
Msrc/include/d_options.rec | 7+++++--
Msrc/mhd2/auth_basic.c | 4+++-
Msrc/mhd2/auth_digest.c | 18+++++++++---------
Msrc/mhd2/conn_data_recv.c | 5++++-
Msrc/mhd2/daemon_add_conn.c | 15+++++++++------
Msrc/mhd2/daemon_funcs.c | 2+-
Msrc/mhd2/daemon_set_options.c | 7+++++--
Msrc/mhd2/daemon_start.c | 6+++---
Msrc/mhd2/mhd_mempool.c | 30+++++++++++++++---------------
Msrc/mhd2/mhd_send.c | 2+-
Msrc/mhd2/mhd_threads.c | 3++-
Msrc/mhd2/post_parser_funcs.c | 4+++-
Msrc/mhd2/response_from.c | 16++++++++++++----
Msrc/mhd2/stream_funcs.c | 28++++++++++++++--------------
Msrc/mhd2/stream_process_reply.c | 3++-
Msrc/mhd2/stream_process_request.c | 22+++++++++++++---------
Msrc/mhd2/tls_gnu_funcs.c | 12++++++++----
Msrc/mhd2/tls_open_funcs.c | 2+-
18 files changed, 110 insertions(+), 76 deletions(-)

diff --git a/src/include/d_options.rec b/src/include/d_options.rec @@ -95,7 +95,8 @@ CustomSetter: /* custom setter */ + { + if (NULL != settings->bind_sa.v_sa) + free (settings->bind_sa.v_sa); -+ settings->bind_sa.v_sa = malloc (option->val.bind_sa.v_sa_len); ++ settings->bind_sa.v_sa = (struct sockaddr *) ++ malloc (option->val.bind_sa.v_sa_len); + if (NULL == settings->bind_sa.v_sa) + return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; + memcpy (settings->bind_sa.v_sa, option->val.bind_sa.v_sa, @@ -203,7 +204,9 @@ CustomSetter: /* custom setter */ + ++pass_size; /* Space for zero-termination */ + if (NULL != settings->tls_cert_key.v_mem_cert) + free (settings->tls_cert_key.v_mem_cert); // TODO: Support multiple certificates!! -+ settings->tls_cert_key.v_mem_cert = malloc (cert_size + key_size + pass_size); ++ settings->tls_cert_key.v_mem_cert = (char *) malloc (cert_size ++ + key_size ++ + pass_size); + if (NULL == settings->tls_cert_key.v_mem_cert) + return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; + memcpy (settings->tls_cert_key.v_mem_cert, diff --git a/src/mhd2/auth_basic.c b/src/mhd2/auth_basic.c @@ -94,7 +94,9 @@ find_and_parse_auth_basic (struct MHD_Request *restrict req) dec_buf[dec_size] = 0; /* Zero-terminate the result */ req->auth.basic.intr.username.cstr = dec_buf; - colon_ptr = memchr (dec_buf, ':', dec_size); + colon_ptr = (char *) memchr (dec_buf, + ':', + dec_size); if (NULL == colon_ptr) { /* No password provided. Only username. */ diff --git a/src/mhd2/auth_digest.c b/src/mhd2/auth_digest.c @@ -303,17 +303,17 @@ gen_new_nonce (struct MHD_Daemon *restrict d, mhd_SHA512_256_init_one_time (&(d_ctx.sha512_256_ctx)); mhd_SHA512_256_update (&(d_ctx.sha512_256_ctx), d->auth_dg.entropy.size, - (const void*) d->auth_dg.entropy.data); + (const uint8_t*) d->auth_dg.entropy.data); mhd_SHA512_256_update (&(d_ctx.sha512_256_ctx), sizeof(gen_num), - (const void*) &gen_num); + (const uint8_t*) &gen_num); if (0 != c->sk.addr.size) mhd_SHA512_256_update (&(d_ctx.sha512_256_ctx), c->sk.addr.size, - (const void*) c->sk.addr.data); + (const uint8_t*) c->sk.addr.data); mhd_SHA512_256_update (&(d_ctx.sha512_256_ctx), sizeof(expiration), - (const void*) &expiration); + (const uint8_t*) &expiration); mhd_SHA512_256_finish_deinit (&(d_ctx.sha512_256_ctx), \ out_buf); if (mhd_SHA512_256_has_err (&(d_ctx.sha512_256_ctx))) @@ -2010,7 +2010,7 @@ MHD_digest_auth_calc_userdigest (enum MHD_DigestAuthAlgo algo, realm, strlen (realm), password, - userdigest_bin); + (uint8_t *) userdigest_bin); ret = digest_has_error (&da) ? MHD_SC_HASH_FAILED : MHD_SC_OK; } digest_deinit (&da); @@ -2074,7 +2074,7 @@ MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo algo, username, strlen (realm), realm, - userhash_bin); + (uint8_t *) userhash_bin); ret = digest_has_error (&da) ? MHD_SC_HASH_FAILED : MHD_SC_OK; } @@ -2428,9 +2428,9 @@ check_uri_match (struct MHD_Request *restrict req, return false; uri[uri_len] = 0; - qmark = memchr (uri, - '?', - uri_len); + qmark = (char *) memchr (uri, + '?', + uri_len); if (NULL != qmark) { *qmark = 0; diff --git a/src/mhd2/conn_data_recv.c b/src/mhd2/conn_data_recv.c @@ -60,7 +60,10 @@ mhd_conn_data_recv (struct MHD_Connection *restrict c, buf = c->read_buffer + c->read_buffer_offset; buf_size = c->read_buffer_size - c->read_buffer_offset; - res = mhd_recv (c,buf_size, buf, &received); + res = mhd_recv (c, + buf_size, + (char *) buf, + &received); if ((mhd_SOCKET_ERR_NO_ERROR != res) || has_err) { diff --git a/src/mhd2/daemon_add_conn.c b/src/mhd2/daemon_add_conn.c @@ -132,9 +132,9 @@ connection_set_initial_state (struct MHD_Connection *restrict c) c->read_buffer_offset = 0; read_buf_size = c->daemon->conns.cfg.mem_pool_size / 2; c->read_buffer - = mhd_pool_allocate (c->pool, - read_buf_size, - false); + = (char *) mhd_pool_allocate (c->pool, + read_buf_size, + false); c->read_buffer_size = read_buf_size; } @@ -197,7 +197,9 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon, tls_data_size = mhd_tls_conn_get_tls_size (daemon->tls); #endif - c = mhd_calloc (1, sizeof (struct MHD_Connection) + tls_data_size); + c = (struct MHD_Connection *) + mhd_calloc (1, + sizeof (struct MHD_Connection) + tls_data_size); if (NULL == c) { mhd_LOG_MSG (daemon, \ @@ -434,8 +436,9 @@ new_connection_process_inner (struct MHD_Daemon *restrict daemon, false); if (0) // TODO: implement turbo { - connection->sk.ready = mhd_SOCKET_NET_STATE_RECV_READY - | mhd_SOCKET_NET_STATE_SEND_READY; + connection->sk.ready = + (enum mhd_SocketNetState) (mhd_SOCKET_NET_STATE_RECV_READY + | mhd_SOCKET_NET_STATE_SEND_READY); mhd_conn_mark_ready (connection, daemon); } return MHD_SC_OK; /* *** Function success exit point *** */ diff --git a/src/mhd2/daemon_funcs.c b/src/mhd2/daemon_funcs.c @@ -230,7 +230,7 @@ mhd_daemon_extend_lbuf_up_to (struct MHD_Daemon *restrict d, if (NULL != new_alloc) { mhd_assert (0 != grow_size); - buf->data = new_alloc; + buf->data = (char *) new_alloc; buf->size += grow_size; } diff --git a/src/mhd2/daemon_set_options.c b/src/mhd2/daemon_set_options.c @@ -61,7 +61,8 @@ MHD_daemon_set_options ( { if (NULL != settings->bind_sa.v_sa) free (settings->bind_sa.v_sa); - settings->bind_sa.v_sa = malloc (option->val.bind_sa.v_sa_len); + settings->bind_sa.v_sa = (struct sockaddr *) + malloc (option->val.bind_sa.v_sa_len); if (NULL == settings->bind_sa.v_sa) return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; memcpy (settings->bind_sa.v_sa, option->val.bind_sa.v_sa, @@ -114,7 +115,9 @@ MHD_daemon_set_options ( ++pass_size; /* Space for zero-termination */ if (NULL != settings->tls_cert_key.v_mem_cert) free (settings->tls_cert_key.v_mem_cert); // TODO: Support multiple certificates!! - settings->tls_cert_key.v_mem_cert = malloc (cert_size + key_size + pass_size); + settings->tls_cert_key.v_mem_cert = (char *) malloc (cert_size + + key_size + + pass_size); if (NULL == settings->tls_cert_key.v_mem_cert) return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; memcpy (settings->tls_cert_key.v_mem_cert, diff --git a/src/mhd2/daemon_start.c b/src/mhd2/daemon_start.c @@ -1590,7 +1590,7 @@ daemon_init_auth_digest (struct MHD_Daemon *restrict d, else { /* Move ownership of the entropy buffer */ - d->auth_dg.entropy.data = s->random_entropy.v_buf; + d->auth_dg.entropy.data = (char *) s->random_entropy.v_buf; d->auth_dg.entropy.size = s->random_entropy.v_buf_size; s->random_entropy.v_buf = NULL; s->random_entropy.v_buf_size = 0; @@ -1628,7 +1628,6 @@ daemon_deinit_auth_digest (struct MHD_Daemon *restrict d) mhd_atomic_counter_deinit (&(d->auth_dg.num_gen_nonces)); mhd_mutex_destroy_chk (&(d->auth_dg.nonces_lock)); mhd_assert (NULL != d->auth_dg.nonces); - mhd_assert (0 != d->auth_dg.nonces); free (d->auth_dg.nonces); } @@ -2785,7 +2784,8 @@ init_workers_pool (struct MHD_Daemon *restrict d, mhd_thread_handle_ID_set_invalid (&(d->threading.tid)); #endif - d->threading.hier.pool.workers = malloc (workers_pool_size); + d->threading.hier.pool.workers = (struct MHD_Daemon *) + malloc (workers_pool_size); if (NULL == d->threading.hier.pool.workers) { mhd_LOG_MSG ( \ diff --git a/src/mhd2/mhd_mempool.c b/src/mhd2/mhd_mempool.c @@ -288,14 +288,14 @@ mdh_pool_create (size_t max) mhd_assert (max > 0); alloc_size = 0; - pool = malloc (sizeof (struct mhd_MemoryPool)); + pool = (struct mhd_MemoryPool *) malloc (sizeof (struct mhd_MemoryPool)); if (NULL == pool) return NULL; #if defined(MAP_ANONYMOUS) || defined(_WIN32) if ( (max <= 32 * 1024) || (max < MHD_sys_page_size_ * 4 / 3) ) { - pool->memory = MAP_FAILED; + pool->memory = (uint8_t *) MAP_FAILED; } else { @@ -303,27 +303,27 @@ mdh_pool_create (size_t max) alloc_size = max + MHD_sys_page_size_ - 1; alloc_size -= alloc_size % MHD_sys_page_size_; #if defined(MAP_ANONYMOUS) && ! defined(_WIN32) - pool->memory = mmap (NULL, - alloc_size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, - -1, - 0); + pool->memory = (uint8_t *) mmap (NULL, + alloc_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + -1, + 0); #elif defined(_WIN32) - pool->memory = VirtualAlloc (NULL, - alloc_size, - MEM_COMMIT | MEM_RESERVE, - PAGE_READWRITE); + pool->memory = (uint8_t *) VirtualAlloc (NULL, + alloc_size, + MEM_COMMIT | MEM_RESERVE, + PAGE_READWRITE); #endif /* _WIN32 */ } #else /* ! _WIN32 && ! MAP_ANONYMOUS */ - pool->memory = MAP_FAILED; + pool->memory = (uint8_t *) MAP_FAILED; #endif /* ! _WIN32 && ! MAP_ANONYMOUS */ if (MAP_FAILED == pool->memory) { alloc_size = mhd_ROUND_TO_ALIGN (max); - pool->memory = malloc (alloc_size); - if (NULL == pool->memory) + pool->memory = (uint8_t *) malloc (alloc_size); + if (((uint8_t *) NULL) == pool->memory) { free (pool); return NULL; diff --git a/src/mhd2/mhd_send.c b/src/mhd2/mhd_send.c @@ -1594,7 +1594,7 @@ send_iov_emu (struct MHD_Connection *restrict connection, res = mhd_send_data (connection, r_iov->iov[r_iov->sent].iov_len, - r_iov->iov[r_iov->sent].iov_base, + (const char *) r_iov->iov[r_iov->sent].iov_base, push_data && (r_iov->cnt == r_iov->sent + 1), &sent_el_size); if (mhd_SOCKET_ERR_NO_ERROR == res) diff --git a/src/mhd2/mhd_threads.c b/src/mhd2/mhd_threads.c @@ -395,7 +395,8 @@ mhd_create_named_thread (mhd_thread_handle_ID *handle_id, return false; } - param = malloc (sizeof (struct mhd_named_helper_param)); + param = (struct mhd_named_helper_param *) + malloc (sizeof (struct mhd_named_helper_param)); if (NULL == param) return false; diff --git a/src/mhd2/post_parser_funcs.c b/src/mhd2/post_parser_funcs.c @@ -151,7 +151,9 @@ process_mpart_header (struct MHD_Connection *restrict c, mhd_assert (2 <= mpart_bound.size); /* At least one char and at least one '\' */ - buf = mhd_stream_alloc_memory (c, mpart_bound.size); + buf = (char *) + mhd_stream_alloc_memory (c, + mpart_bound.size); if (NULL == buf) { /* It is very low probability that pool would not have memory just diff --git a/src/mhd2/response_from.c b/src/mhd2/response_from.c @@ -60,10 +60,14 @@ response_create_basic (enum MHD_HTTP_StatusCode sc, if ((100 > sc) || (999 < sc)) return NULL; - r = mhd_calloc (1, sizeof(struct MHD_Response)); + r = (struct MHD_Response *) + mhd_calloc (1, + sizeof(struct MHD_Response)); if (NULL != r) { - s = mhd_calloc (1, sizeof(struct ResponseOptions)); + s = (struct ResponseOptions *) + mhd_calloc (1, + sizeof(struct ResponseOptions)); if (NULL != s) { #ifndef HAVE_NULL_PTR_ALL_ZEROS @@ -269,7 +273,9 @@ MHD_response_from_iovec ( mhd_iovec *iov_copy; size_t num_copy_elements = i_cp; - iov_copy = mhd_calloc (num_copy_elements, sizeof(mhd_iovec)); + iov_copy = (mhd_iovec *) + mhd_calloc (num_copy_elements, + sizeof(mhd_iovec)); if (NULL == iov_copy) return NULL; @@ -392,7 +398,9 @@ mhd_response_special_for_error (unsigned int sc, mhd_assert ((NULL != cntn) || (0 == cntn_len)); mhd_assert ((NULL != spec_hdr) || (0 == spec_hdr_len)); - res = mhd_calloc (1, sizeof(struct MHD_Response)); + res = (struct MHD_Response *) + mhd_calloc (1, + sizeof(struct MHD_Response)); if (NULL == res) return NULL; diff --git a/src/mhd2/stream_funcs.c b/src/mhd2/stream_funcs.c @@ -89,10 +89,10 @@ mhd_stream_alloc_memory (struct MHD_Connection *restrict c, { char *buf; const size_t new_buf_size = c->write_buffer_size - need_to_be_freed; - buf = mhd_pool_reallocate (pool, - c->write_buffer, - c->write_buffer_size, - new_buf_size); + buf = (char *) mhd_pool_reallocate (pool, + c->write_buffer, + c->write_buffer_size, + new_buf_size); mhd_assert (c->write_buffer == buf); mhd_assert (c->write_buffer_append_offset <= new_buf_size); mhd_assert (c->write_buffer_send_offset <= new_buf_size); @@ -110,10 +110,10 @@ mhd_stream_alloc_memory (struct MHD_Connection *restrict c, { char *buf; const size_t new_buf_size = c->read_buffer_size - need_to_be_freed; - buf = mhd_pool_reallocate (pool, - c->read_buffer, - c->read_buffer_size, - new_buf_size); + buf = (char *) mhd_pool_reallocate (pool, + c->read_buffer, + c->read_buffer_size, + new_buf_size); mhd_assert (c->read_buffer == buf); mhd_assert (c->read_buffer_offset <= new_buf_size); c->read_buffer_size = new_buf_size; @@ -160,7 +160,7 @@ mhd_stream_shrink_read_buffer (struct MHD_Connection *restrict c) new_buf = mhd_pool_reallocate (c->pool, c->read_buffer, c->read_buffer_size, c->read_buffer_offset); mhd_assert (c->read_buffer == new_buf); - c->read_buffer = new_buf; + c->read_buffer = (char *) new_buf; c->read_buffer_size = c->read_buffer_offset; } } @@ -194,7 +194,7 @@ mhd_stream_maximize_write_buffer (struct MHD_Connection *restrict c) c->write_buffer_size, new_size); mhd_assert ((c->write_buffer == new_buf) || (NULL == c->write_buffer)); - c->write_buffer = new_buf; + c->write_buffer = (char *) new_buf; c->write_buffer_size = new_size; if (c->write_buffer_send_offset == c->write_buffer_append_offset) { @@ -610,10 +610,10 @@ mhd_stream_finish_req_serving (struct MHD_Connection *restrict c, new_read_buf_size = c->read_buffer_offset; c->read_buffer - = mhd_pool_reset (c->pool, - c->read_buffer, - c->read_buffer_offset, - new_read_buf_size); + = (char *) mhd_pool_reset (c->pool, + c->read_buffer, + c->read_buffer_offset, + new_read_buf_size); c->read_buffer_size = new_read_buf_size; } c->rq.app_context = NULL; diff --git a/src/mhd2/stream_process_reply.c b/src/mhd2/stream_process_reply.c @@ -1198,7 +1198,8 @@ mhd_stream_prep_unchunked_body (struct MHD_Connection *restrict c) mhd_assert (mhd_RESPONSE_CONTENT_DATA_IOVEC == r->cntn_dtype); copy_size = r->cntn.iovec.cnt * sizeof(mhd_iovec); - c->rp.resp_iov.iov = mhd_stream_alloc_memory (c, + c->rp.resp_iov.iov = (mhd_iovec *) + mhd_stream_alloc_memory (c, copy_size); if (NULL == c->rp.resp_iov.iov) { diff --git a/src/mhd2/stream_process_request.c b/src/mhd2/stream_process_request.c @@ -1345,7 +1345,8 @@ send_redirect_fixed_rq_target (struct MHD_Connection *restrict c) + 2 * c->rq.hdrs.rq_line.num_ws_in_uri; if ( (fixed_uri_len + 200 > c->daemon->conns.cfg.mem_pool_size) || (fixed_uri_len > MHD_MAX_FIXED_URI_LEN) || - (NULL == (hdr_line = malloc (fixed_uri_len + 1 + hdr_prefix_len))) ) + (NULL == + (hdr_line = (char *) malloc (fixed_uri_len + 1 + hdr_prefix_len))) ) { mhd_STREAM_ABORT (c, mhd_CONN_CLOSE_CLIENT_HTTP_ERR_ABORT_CONN, \ "The request has whitespace character is " \ @@ -2482,8 +2483,8 @@ parse_cookie_header (struct MHD_Connection *restrict connection, if (0 == cookie_val->len) return MHD_PARSE_COOKIE_OK; - cpy = mhd_stream_alloc_memory (connection, - cookie_val->len + 1); + cpy = (char *) mhd_stream_alloc_memory (connection, + cookie_val->len + 1); if (NULL == cpy) parse_res = MHD_PARSE_COOKIE_NO_MEMORY; else @@ -3607,7 +3608,10 @@ handle_req_chunk_size_line_no_space (struct MHD_Connection *c, { const char *semicol; /* Check for chunk extension */ - semicol = memchr (chunk_size_line, ';', chunk_size_line_size); + semicol = (const char *) + memchr (chunk_size_line, + ';', + chunk_size_line_size); if (NULL != semicol) { /* Chunk extension present. It could be removed without any loss of the details of the request. */ @@ -3763,7 +3767,7 @@ try_grow_read_buffer (struct MHD_Connection *restrict connection, size_t new_size; size_t avail_size; const size_t def_grow_size = 1536; // TODO: remove hardcoded increment - void *rb; + char *rb; avail_size = mhd_pool_get_free (connection->pool); if (0 == avail_size) @@ -3810,10 +3814,10 @@ try_grow_read_buffer (struct MHD_Connection *restrict connection, return false; } /* we can actually grow the buffer, do it! */ - rb = mhd_pool_reallocate (connection->pool, - connection->read_buffer, - connection->read_buffer_size, - new_size); + rb = (char *) mhd_pool_reallocate (connection->pool, + connection->read_buffer, + connection->read_buffer_size, + new_size); if (NULL == rb) { /* This should NOT be possible: we just computed 'new_size' so that diff --git a/src/mhd2/tls_gnu_funcs.c b/src/mhd2/tls_gnu_funcs.c @@ -256,9 +256,11 @@ daemon_init_credentials (struct MHD_Daemon *restrict d, gnutls_datum_t key_data; int res; - cert_data.data = mhd_DROP_CONST (s->tls_cert_key.v_mem_cert); + cert_data.data = + (unsigned char *) mhd_DROP_CONST (s->tls_cert_key.v_mem_cert); cert_data.size = (unsigned int) cert_len; - key_data.data = mhd_DROP_CONST (s->tls_cert_key.v_mem_key); + key_data.data = + (unsigned char *) mhd_DROP_CONST (s->tls_cert_key.v_mem_key); key_data.size = (unsigned int) key_len; res = gnutls_certificate_set_x509_key_mem2 (d_tls->cred, &cert_data, @@ -533,9 +535,11 @@ mhd_tls_gnu_conn_init (const struct mhd_TlsGnuDaemonData *restrict d_tls, static const char alpn_http_3[] = "h3"; /* Registered value for HTTP/3 */ # endif gnutls_datum_t prots[] = { - { mhd_DROP_CONST (alpn_http_1_1), mhd_SSTR_LEN (alpn_http_1_1) } + { (unsigned char *) mhd_DROP_CONST (alpn_http_1_1), + mhd_SSTR_LEN (alpn_http_1_1) } , - { mhd_DROP_CONST (alpn_http_1_0), mhd_SSTR_LEN (alpn_http_1_0) } + { (unsigned char *) mhd_DROP_CONST (alpn_http_1_0), + mhd_SSTR_LEN (alpn_http_1_0) } }; unsigned int alpn_flags; int alpn_res; diff --git a/src/mhd2/tls_open_funcs.c b/src/mhd2/tls_open_funcs.c @@ -404,7 +404,7 @@ select_alpn_prot (SSL *sess, { (void) sess; (void) cls; /* Unused */ if (OPENSSL_NPN_NEGOTIATED == - SSL_select_next_proto (mhd_DROP_CONST (out), + SSL_select_next_proto ((unsigned char **) mhd_DROP_CONST (out), outlen, in, inlen,