[httpd] Addendum to commit 017e09d: More fixing up of libevent warnings

This commit is contained in:
ejurgensen 2022-12-26 17:16:58 +01:00
parent fc83d807e0
commit c23c2fdc45
3 changed files with 22 additions and 13 deletions

View File

@ -1006,11 +1006,7 @@ httpd_request_parse(struct evhttp_request *req, struct httpd_uri_parsed *uri_par
evcon = evhttp_request_get_connection(req); evcon = evhttp_request_get_connection(req);
if (evcon) if (evcon)
#ifdef HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR httpd_peer_get(&hreq->peer_address, &hreq->peer_port, evcon);
evhttp_connection_get_peer(evcon, &hreq->peer_address, &hreq->peer_port);
#else
evhttp_connection_get_peer(evcon, (char **)&hreq->peer_address, &hreq->peer_port);
#endif
else else
DPRINTF(E_LOG, L_HTTPD, "Connection to client lost or missing\n"); DPRINTF(E_LOG, L_HTTPD, "Connection to client lost or missing\n");
@ -1500,7 +1496,7 @@ bool
httpd_admin_check_auth(struct evhttp_request *req) httpd_admin_check_auth(struct evhttp_request *req)
{ {
struct evhttp_connection *evcon; struct evhttp_connection *evcon;
char *addr; const char *addr;
uint16_t port; uint16_t port;
const char *passwd; const char *passwd;
int ret; int ret;
@ -1512,7 +1508,7 @@ httpd_admin_check_auth(struct evhttp_request *req)
return false; return false;
} }
evhttp_connection_get_peer(evcon, &addr, &port); httpd_peer_get(&addr, &port, evcon);
if (net_peer_address_is_trusted(addr)) if (net_peer_address_is_trusted(addr))
return true; return true;
@ -1641,6 +1637,16 @@ httpd_basic_auth(struct evhttp_request *req, const char *user, const char *passw
return -1; return -1;
} }
void
httpd_peer_get(const char **address, ev_uint16_t *port, struct evhttp_connection *evcon)
{
#ifdef HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR
evhttp_connection_get_peer(evcon, address, port);
#else
evhttp_connection_get_peer(evcon, (char **)address, port);
#endif
}
/* Thread: main */ /* Thread: main */
int int
httpd_init(const char *webroot) httpd_init(const char *webroot)

View File

@ -161,6 +161,9 @@ httpd_admin_check_auth(struct evhttp_request *req);
int int
httpd_basic_auth(struct evhttp_request *req, const char *user, const char *passwd, const char *realm); httpd_basic_auth(struct evhttp_request *req, const char *user, const char *passwd, const char *realm);
void
httpd_peer_get(const char **address, ev_uint16_t *port, struct evhttp_connection *evcon);
int int
httpd_init(const char *webroot); httpd_init(const char *webroot);

View File

@ -106,12 +106,12 @@ streaming_close_cb(struct evhttp_connection *evcon, void *arg)
struct streaming_session *this; struct streaming_session *this;
struct streaming_session *session; struct streaming_session *session;
struct streaming_session *prev; struct streaming_session *prev;
char *address; const char *address;
ev_uint16_t port; ev_uint16_t port;
this = (struct streaming_session *)arg; this = (struct streaming_session *)arg;
evhttp_connection_get_peer(evcon, &address, &port); httpd_peer_get(&address, &port, evcon);
DPRINTF(E_INFO, L_STREAMING, "Stopping mp3 streaming to %s:%d\n", address, (int)port); DPRINTF(E_INFO, L_STREAMING, "Stopping mp3 streaming to %s:%d\n", address, (int)port);
pthread_mutex_lock(&streaming_sessions_lck); pthread_mutex_lock(&streaming_sessions_lck);
@ -168,7 +168,7 @@ streaming_end(void)
{ {
struct streaming_session *session; struct streaming_session *session;
struct evhttp_connection *evcon; struct evhttp_connection *evcon;
char *address; const char *address;
ev_uint16_t port; ev_uint16_t port;
pthread_mutex_lock(&streaming_sessions_lck); pthread_mutex_lock(&streaming_sessions_lck);
@ -178,7 +178,7 @@ streaming_end(void)
if (evcon) if (evcon)
{ {
evhttp_connection_set_closecb(evcon, NULL, NULL); evhttp_connection_set_closecb(evcon, NULL, NULL);
evhttp_connection_get_peer(evcon, &address, &port); httpd_peer_get(&address, &port, evcon);
DPRINTF(E_INFO, L_STREAMING, "Force close stream to %s:%d\n", address, (int)port); DPRINTF(E_INFO, L_STREAMING, "Force close stream to %s:%d\n", address, (int)port);
} }
evhttp_send_reply_end(session->req); evhttp_send_reply_end(session->req);
@ -531,7 +531,7 @@ streaming_request(struct evhttp_request *req, struct httpd_uri_parsed *uri_parse
struct evkeyvalq *output_headers; struct evkeyvalq *output_headers;
cfg_t *lib; cfg_t *lib;
const char *name; const char *name;
char *address; const char *address;
ev_uint16_t port; ev_uint16_t port;
const char *param; const char *param;
bool require_icy = false; bool require_icy = false;
@ -546,7 +546,7 @@ streaming_request(struct evhttp_request *req, struct httpd_uri_parsed *uri_parse
} }
evcon = evhttp_request_get_connection(req); evcon = evhttp_request_get_connection(req);
evhttp_connection_get_peer(evcon, &address, &port); httpd_peer_get(&address, &port, evcon);
param = evhttp_find_header( evhttp_request_get_input_headers(req), "Icy-MetaData"); param = evhttp_find_header( evhttp_request_get_input_headers(req), "Icy-MetaData");
if (param && strcmp(param, "1") == 0) if (param && strcmp(param, "1") == 0)
require_icy = true; require_icy = true;