mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-08 21:55:52 -04:00
Cleanup libevent 2 calls in httpd_daap.c/.h
This commit is contained in:
parent
684de40be2
commit
6df734f497
@ -53,8 +53,10 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
#ifdef HAVE_LIBEVENT2
|
||||||
# include <event2/util.h>
|
# include <event2/event.h>
|
||||||
# include <event2/http_struct.h>
|
# include <event2/http_struct.h>
|
||||||
|
#else
|
||||||
|
# include <event.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* httpd event base, from httpd.c */
|
/* httpd event base, from httpd.c */
|
||||||
@ -86,7 +88,7 @@ struct daap_update_request {
|
|||||||
struct evhttp_request *req;
|
struct evhttp_request *req;
|
||||||
|
|
||||||
/* Refresh tiemout */
|
/* Refresh tiemout */
|
||||||
struct event timeout;
|
struct event *timeout;
|
||||||
|
|
||||||
struct daap_update_request *next;
|
struct daap_update_request *next;
|
||||||
};
|
};
|
||||||
@ -112,14 +114,20 @@ static struct timeval daap_session_timeout_tv = { DAAP_SESSION_TIMEOUT, 0 };
|
|||||||
/* Update requests */
|
/* Update requests */
|
||||||
static int current_rev;
|
static int current_rev;
|
||||||
static struct daap_update_request *update_requests;
|
static struct daap_update_request *update_requests;
|
||||||
|
static struct timeval daap_update_refresh_tv = { DAAP_UPDATE_REFRESH, 0 };
|
||||||
|
|
||||||
|
|
||||||
/* Session handling */
|
/* Session handling */
|
||||||
static void
|
static void
|
||||||
daap_session_free(struct daap_session *s)
|
daap_session_free(struct daap_session *s)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_LIBEVENT2
|
||||||
if (s->timeout)
|
if (s->timeout)
|
||||||
event_free(s->timeout);
|
event_free(s->timeout);
|
||||||
|
#else
|
||||||
|
if (s->timeout)
|
||||||
|
free(s->timeout);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (s->user_agent)
|
if (s->user_agent)
|
||||||
free(s->user_agent);
|
free(s->user_agent);
|
||||||
@ -219,6 +227,7 @@ daap_session_add(const char *user_agent, int request_session_id)
|
|||||||
|
|
||||||
daap_sessions = s;
|
daap_sessions = s;
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBEVENT2
|
||||||
if (DAAP_SESSION_TIMEOUT > 0)
|
if (DAAP_SESSION_TIMEOUT > 0)
|
||||||
{
|
{
|
||||||
s->timeout = evtimer_new(evbase_httpd, daap_session_timeout_cb, s);
|
s->timeout = evtimer_new(evbase_httpd, daap_session_timeout_cb, s);
|
||||||
@ -227,6 +236,7 @@ daap_session_add(const char *user_agent, int request_session_id)
|
|||||||
else
|
else
|
||||||
evtimer_add(s->timeout, &daap_session_timeout_tv);
|
evtimer_add(s->timeout, &daap_session_timeout_tv);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -275,8 +285,14 @@ daap_session_find(struct evhttp_request *req, struct evkeyvalq *query, struct ev
|
|||||||
static void
|
static void
|
||||||
update_free(struct daap_update_request *ur)
|
update_free(struct daap_update_request *ur)
|
||||||
{
|
{
|
||||||
if (event_initialized(&ur->timeout))
|
#ifdef HAVE_LIBEVENT2
|
||||||
evtimer_del(&ur->timeout);
|
if (ur->timeout)
|
||||||
|
event_free(ur->timeout);
|
||||||
|
#else
|
||||||
|
if (ur->timeout)
|
||||||
|
free(ur->timeout);
|
||||||
|
#endif
|
||||||
|
|
||||||
free(ur);
|
free(ur);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -997,7 +1013,6 @@ daap_reply_logout(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
|
|||||||
static int
|
static int
|
||||||
daap_reply_update(struct evhttp_request *req, struct evbuffer *evbuf, char **uri, struct evkeyvalq *query, const char *ua)
|
daap_reply_update(struct evhttp_request *req, struct evbuffer *evbuf, char **uri, struct evkeyvalq *query, const char *ua)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
|
||||||
struct daap_session *s;
|
struct daap_session *s;
|
||||||
struct daap_update_request *ur;
|
struct daap_update_request *ur;
|
||||||
struct evhttp_connection *evcon;
|
struct evhttp_connection *evcon;
|
||||||
@ -1059,24 +1074,25 @@ daap_reply_update(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
|
|||||||
}
|
}
|
||||||
memset(ur, 0, sizeof(struct daap_update_request));
|
memset(ur, 0, sizeof(struct daap_update_request));
|
||||||
|
|
||||||
if (DAAP_UPDATE_REFRESH > 0) {
|
#ifdef HAVE_LIBEVENT2
|
||||||
evtimer_set(&ur->timeout, update_refresh_cb, ur);
|
if (DAAP_UPDATE_REFRESH > 0)
|
||||||
event_base_set(evbase_httpd, &ur->timeout);
|
{
|
||||||
|
ur->timeout = evtimer_new(evbase_httpd, update_refresh_cb, ur);
|
||||||
evutil_timerclear(&tv);
|
if (ur->timeout)
|
||||||
tv.tv_sec = DAAP_UPDATE_REFRESH;
|
ret = evtimer_add(ur->timeout, &daap_update_refresh_tv);
|
||||||
|
else
|
||||||
ret = evtimer_add(&ur->timeout, &tv);
|
ret = -1;
|
||||||
if (ret < 0)
|
|
||||||
{
|
if (ret < 0)
|
||||||
DPRINTF(E_LOG, L_DAAP, "Could not add update timeout event\n");
|
{
|
||||||
|
DPRINTF(E_LOG, L_DAAP, "Out of memory for update request event\n");
|
||||||
dmap_send_error(req, "mupd", "Could not register timer");
|
|
||||||
|
dmap_send_error(req, "mupd", "Could not register timer");
|
||||||
update_free(ur);
|
update_free(ur);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* NOTE: we may need to keep reqd_rev in there too */
|
/* NOTE: we may need to keep reqd_rev in there too */
|
||||||
ur->req = req;
|
ur->req = req;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#ifndef __HTTPD_DAAP_H__
|
#ifndef __HTTPD_DAAP_H__
|
||||||
#define __HTTPD_DAAP_H__
|
#define __HTTPD_DAAP_H__
|
||||||
|
|
||||||
#include <event.h>
|
|
||||||
#ifdef HAVE_LIBEVENT2
|
#ifdef HAVE_LIBEVENT2
|
||||||
# include <event2/http.h>
|
# include <event2/http.h>
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user