Remove libevent 1 support in httpd_daap

This commit is contained in:
ejurgensen 2015-07-29 23:05:47 +02:00
parent 7e9cf80ec0
commit 3ba76e8f40
2 changed files with 53 additions and 52 deletions

View File

@ -52,12 +52,9 @@
#include "dmap_common.h" #include "dmap_common.h"
#include "cache.h" #include "cache.h"
#ifdef HAVE_LIBEVENT2 #include <event2/event.h>
# include <event2/event.h> #include <event2/buffer.h>
# include <event2/http_struct.h> #include <event2/http_struct.h>
#else
# include <event.h>
#endif
/* httpd event base, from httpd.c */ /* httpd event base, from httpd.c */
extern struct event_base *evbase_httpd; extern struct event_base *evbase_httpd;
@ -123,13 +120,8 @@ static struct timeval daap_update_refresh_tv = { DAAP_UPDATE_REFRESH, 0 };
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);
@ -229,7 +221,6 @@ 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);
@ -238,7 +229,6 @@ 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;
} }
@ -287,13 +277,8 @@ 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)
{ {
#ifdef HAVE_LIBEVENT2
if (ur->timeout) if (ur->timeout)
event_free(ur->timeout); event_free(ur->timeout);
#else
if (ur->timeout)
free(ur->timeout);
#endif
free(ur); free(ur);
} }
@ -784,6 +769,7 @@ daap_reply_server_info(struct evhttp_request *req, struct evbuffer *evbuf, char
char *name; char *name;
char *passwd; char *passwd;
const char *clientver; const char *clientver;
size_t len;
int mpro; int mpro;
int apro; int apro;
@ -874,7 +860,8 @@ daap_reply_server_info(struct evhttp_request *req, struct evbuffer *evbuf, char
// dmap_add_int(content, "msto", ); // dmap.utcoffset // dmap_add_int(content, "msto", ); // dmap.utcoffset
// Create container // Create container
dmap_add_container(evbuf, "msrv", EVBUFFER_LENGTH(content)); len = evbuffer_get_length(content);
dmap_add_container(evbuf, "msrv", len);
evbuffer_add_buffer(evbuf, content); evbuffer_add_buffer(evbuf, content);
evbuffer_free(content); evbuffer_free(content);
@ -887,9 +874,9 @@ static int
daap_reply_content_codes(struct evhttp_request *req, struct evbuffer *evbuf, char **uri, struct evkeyvalq *query, const char *ua) daap_reply_content_codes(struct evhttp_request *req, struct evbuffer *evbuf, char **uri, struct evkeyvalq *query, const char *ua)
{ {
const struct dmap_field *dmap_fields; const struct dmap_field *dmap_fields;
size_t len;
int nfields; int nfields;
int i; int i;
int len;
int ret; int ret;
dmap_fields = dmap_get_fields_table(&nfields); dmap_fields = dmap_get_fields_table(&nfields);
@ -1080,7 +1067,6 @@ 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));
#ifdef HAVE_LIBEVENT2
if (DAAP_UPDATE_REFRESH > 0) if (DAAP_UPDATE_REFRESH > 0)
{ {
ur->timeout = evtimer_new(evbase_httpd, update_refresh_cb, ur); ur->timeout = evtimer_new(evbase_httpd, update_refresh_cb, ur);
@ -1098,7 +1084,6 @@ daap_reply_update(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
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;
@ -1134,6 +1119,7 @@ daap_reply_dblist(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
cfg_t *lib; cfg_t *lib;
char *name; char *name;
char *name_radio; char *name_radio;
size_t len;
int count; int count;
s = daap_session_find(req, query, evbuf); s = daap_session_find(req, query, evbuf);
@ -1176,7 +1162,8 @@ daap_reply_dblist(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
dmap_add_int(item, "meds", 3); dmap_add_int(item, "meds", 3);
// Create container for library db // Create container for library db
dmap_add_container(content, "mlit", EVBUFFER_LENGTH(item)); len = evbuffer_get_length(item);
dmap_add_container(content, "mlit", len);
evbuffer_add_buffer(content, item); evbuffer_add_buffer(content, item);
evbuffer_free(item); evbuffer_free(item);
@ -1202,17 +1189,19 @@ daap_reply_dblist(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
dmap_add_int(item, "meds", 3); dmap_add_int(item, "meds", 3);
// Create container for radio db // Create container for radio db
dmap_add_container(content, "mlit", EVBUFFER_LENGTH(item)); len = evbuffer_get_length(item);
dmap_add_container(content, "mlit", len);
evbuffer_add_buffer(content, item); evbuffer_add_buffer(content, item);
evbuffer_free(item); evbuffer_free(item);
// Create container // Create container
dmap_add_container(evbuf, "avdb", EVBUFFER_LENGTH(content) + 53); len = evbuffer_get_length(content);
dmap_add_container(evbuf, "avdb", len + 53);
dmap_add_int(evbuf, "mstt", 200); /* 12 */ dmap_add_int(evbuf, "mstt", 200); /* 12 */
dmap_add_char(evbuf, "muty", 0); /* 9 */ dmap_add_char(evbuf, "muty", 0); /* 9 */
dmap_add_int(evbuf, "mtco", 2); /* 12 */ dmap_add_int(evbuf, "mtco", 2); /* 12 */
dmap_add_int(evbuf, "mrco", 2); /* 12 */ dmap_add_int(evbuf, "mrco", 2); /* 12 */
dmap_add_container(evbuf, "mlcl", EVBUFFER_LENGTH(content)); /* 8 */ dmap_add_container(evbuf, "mlcl", len); /* 8 */
evbuffer_add_buffer(evbuf, content); evbuffer_add_buffer(evbuf, content);
evbuffer_free(content); evbuffer_free(content);
@ -1236,6 +1225,7 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf,
const char *client_codecs; const char *client_codecs;
char *last_codectype; char *last_codectype;
char *tag; char *tag;
size_t len;
int nmeta; int nmeta;
int sort_headers; int sort_headers;
int nsongs; int nsongs;
@ -1457,18 +1447,19 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf,
} }
/* Add header to evbuf, add songlist to evbuf */ /* Add header to evbuf, add songlist to evbuf */
len = evbuffer_get_length(songlist);
if (sort_headers) if (sort_headers)
{ {
daap_sort_finalize(sctx); daap_sort_finalize(sctx);
dmap_add_container(evbuf, tag, EVBUFFER_LENGTH(songlist) + EVBUFFER_LENGTH(sctx->headerlist) + 61); dmap_add_container(evbuf, tag, len + evbuffer_get_length(sctx->headerlist) + 61);
} }
else else
dmap_add_container(evbuf, tag, EVBUFFER_LENGTH(songlist) + 53); dmap_add_container(evbuf, tag, len + 53);
dmap_add_int(evbuf, "mstt", 200); /* 12 */ dmap_add_int(evbuf, "mstt", 200); /* 12 */
dmap_add_char(evbuf, "muty", 0); /* 9 */ dmap_add_char(evbuf, "muty", 0); /* 9 */
dmap_add_int(evbuf, "mtco", qp.results); /* 12 */ dmap_add_int(evbuf, "mtco", qp.results); /* 12 */
dmap_add_int(evbuf, "mrco", nsongs); /* 12 */ dmap_add_int(evbuf, "mrco", nsongs); /* 12 */
dmap_add_container(evbuf, "mlcl", EVBUFFER_LENGTH(songlist)); /* 8 */ dmap_add_container(evbuf, "mlcl", len); /* 8 */
db_query_end(&qp); db_query_end(&qp);
@ -1488,7 +1479,8 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf,
if (sort_headers) if (sort_headers)
{ {
dmap_add_container(evbuf, "mshl", EVBUFFER_LENGTH(sctx->headerlist)); /* 8 */ len = evbuffer_get_length(sctx->headerlist);
dmap_add_container(evbuf, "mshl", len); /* 8 */
ret = evbuffer_add_buffer(evbuf, sctx->headerlist); ret = evbuffer_add_buffer(evbuf, sctx->headerlist);
daap_sort_context_free(sctx); daap_sort_context_free(sctx);
@ -1558,6 +1550,7 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
const struct dmap_field **meta; const struct dmap_field **meta;
const char *param; const char *param;
char **strval; char **strval;
size_t len;
int database; int database;
int cfg_radiopl; int cfg_radiopl;
int nmeta; int nmeta;
@ -1756,7 +1749,8 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
DPRINTF(E_DBG, L_DAAP, "Done with playlist\n"); DPRINTF(E_DBG, L_DAAP, "Done with playlist\n");
dmap_add_container(playlistlist, "mlit", EVBUFFER_LENGTH(playlist)); len = evbuffer_get_length(playlist);
dmap_add_container(playlistlist, "mlit", len);
ret = evbuffer_add_buffer(playlistlist, playlist); ret = evbuffer_add_buffer(playlistlist, playlist);
if (ret < 0) if (ret < 0)
{ {
@ -1790,12 +1784,13 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
} }
/* Add header to evbuf, add playlistlist to evbuf */ /* Add header to evbuf, add playlistlist to evbuf */
dmap_add_container(evbuf, "aply", EVBUFFER_LENGTH(playlistlist) + 53); len = evbuffer_get_length(playlistlist);
dmap_add_container(evbuf, "aply", len + 53);
dmap_add_int(evbuf, "mstt", 200); /* 12 */ dmap_add_int(evbuf, "mstt", 200); /* 12 */
dmap_add_char(evbuf, "muty", 0); /* 9 */ dmap_add_char(evbuf, "muty", 0); /* 9 */
dmap_add_int(evbuf, "mtco", qp.results); /* 12 */ dmap_add_int(evbuf, "mtco", qp.results); /* 12 */
dmap_add_int(evbuf,"mrco", npls); /* 12 */ dmap_add_int(evbuf,"mrco", npls); /* 12 */
dmap_add_container(evbuf, "mlcl", EVBUFFER_LENGTH(playlistlist)); dmap_add_container(evbuf, "mlcl", len);
db_query_end(&qp); db_query_end(&qp);
@ -1841,13 +1836,14 @@ daap_reply_groups(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
struct sort_ctx *sctx; struct sort_ctx *sctx;
const char *param; const char *param;
char **strval; char **strval;
char *tag;
size_t len;
int nmeta; int nmeta;
int sort_headers; int sort_headers;
int ngrp; int ngrp;
int32_t val; int32_t val;
int i; int i;
int ret; int ret;
char *tag;
s = daap_session_find(req, query, evbuf); s = daap_session_find(req, query, evbuf);
if (!s && req) if (!s && req)
@ -2024,7 +2020,8 @@ daap_reply_groups(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
DPRINTF(E_SPAM, L_DAAP, "Done with group\n"); DPRINTF(E_SPAM, L_DAAP, "Done with group\n");
dmap_add_container(grouplist, "mlit", EVBUFFER_LENGTH(group)); len = evbuffer_get_length(group);
dmap_add_container(grouplist, "mlit", len);
ret = evbuffer_add_buffer(grouplist, group); ret = evbuffer_add_buffer(grouplist, group);
if (ret < 0) if (ret < 0)
{ {
@ -2065,19 +2062,20 @@ daap_reply_groups(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
} }
/* Add header to evbuf, add grouplist to evbuf */ /* Add header to evbuf, add grouplist to evbuf */
len = evbuffer_get_length(grouplist);
if (sort_headers) if (sort_headers)
{ {
daap_sort_finalize(sctx); daap_sort_finalize(sctx);
dmap_add_container(evbuf, tag, EVBUFFER_LENGTH(grouplist) + EVBUFFER_LENGTH(sctx->headerlist) + 61); dmap_add_container(evbuf, tag, len + evbuffer_get_length(sctx->headerlist) + 61);
} }
else else
dmap_add_container(evbuf, tag, EVBUFFER_LENGTH(grouplist) + 53); dmap_add_container(evbuf, tag, len + 53);
dmap_add_int(evbuf, "mstt", 200); /* 12 */ dmap_add_int(evbuf, "mstt", 200); /* 12 */
dmap_add_char(evbuf, "muty", 0); /* 9 */ dmap_add_char(evbuf, "muty", 0); /* 9 */
dmap_add_int(evbuf, "mtco", qp.results); /* 12 */ dmap_add_int(evbuf, "mtco", qp.results); /* 12 */
dmap_add_int(evbuf,"mrco", ngrp); /* 12 */ dmap_add_int(evbuf,"mrco", ngrp); /* 12 */
dmap_add_container(evbuf, "mlcl", EVBUFFER_LENGTH(grouplist)); /* 8 */ dmap_add_container(evbuf, "mlcl", len); /* 8 */
db_query_end(&qp); db_query_end(&qp);
@ -2097,7 +2095,8 @@ daap_reply_groups(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
if (sort_headers) if (sort_headers)
{ {
dmap_add_container(evbuf, "mshl", EVBUFFER_LENGTH(sctx->headerlist)); /* 8 */ len = evbuffer_get_length(sctx->headerlist);
dmap_add_container(evbuf, "mshl", len); /* 8 */
ret = evbuffer_add_buffer(evbuf, sctx->headerlist); ret = evbuffer_add_buffer(evbuf, sctx->headerlist);
daap_sort_context_free(sctx); daap_sort_context_free(sctx);
@ -2139,6 +2138,7 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
char *browse_item; char *browse_item;
char *sort_item; char *sort_item;
char *tag; char *tag;
size_t len;
int sort_headers; int sort_headers;
int nitems; int nitems;
int ret; int ret;
@ -2272,19 +2272,20 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
goto out_sort_headers_free; goto out_sort_headers_free;
} }
len = evbuffer_get_length(itemlist);
if (sort_headers) if (sort_headers)
{ {
daap_sort_finalize(sctx); daap_sort_finalize(sctx);
dmap_add_container(evbuf, "abro", EVBUFFER_LENGTH(itemlist) + EVBUFFER_LENGTH(sctx->headerlist) + 52); dmap_add_container(evbuf, "abro", len + evbuffer_get_length(sctx->headerlist) + 52);
} }
else else
dmap_add_container(evbuf, "abro", EVBUFFER_LENGTH(itemlist) + 44); dmap_add_container(evbuf, "abro", len + 44);
dmap_add_int(evbuf, "mstt", 200); /* 12 */ dmap_add_int(evbuf, "mstt", 200); /* 12 */
dmap_add_int(evbuf, "mtco", qp.results); /* 12 */ dmap_add_int(evbuf, "mtco", qp.results); /* 12 */
dmap_add_int(evbuf, "mrco", nitems); /* 12 */ dmap_add_int(evbuf, "mrco", nitems); /* 12 */
dmap_add_container(evbuf, tag, EVBUFFER_LENGTH(itemlist)); /* 8 */ dmap_add_container(evbuf, tag, len); /* 8 */
db_query_end(&qp); db_query_end(&qp);
@ -2300,7 +2301,8 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
if (sort_headers) if (sort_headers)
{ {
dmap_add_container(evbuf, "mshl", EVBUFFER_LENGTH(sctx->headerlist)); /* 8 */ len = evbuffer_get_length(sctx->headerlist);
dmap_add_container(evbuf, "mshl", len); /* 8 */
ret = evbuffer_add_buffer(evbuf, sctx->headerlist); ret = evbuffer_add_buffer(evbuf, sctx->headerlist);
if (ret < 0) if (ret < 0)
@ -2340,6 +2342,7 @@ daap_reply_extra_data(struct evhttp_request *req, struct evbuffer *evbuf, char *
struct evkeyvalq *headers; struct evkeyvalq *headers;
const char *param; const char *param;
char *ctype; char *ctype;
size_t len;
int id; int id;
int max_w; int max_w;
int max_h; int max_h;
@ -2391,6 +2394,8 @@ daap_reply_extra_data(struct evhttp_request *req, struct evbuffer *evbuf, char *
else if (strcmp(uri[2], "items") == 0) else if (strcmp(uri[2], "items") == 0)
ret = artwork_get_item(evbuf, id, max_w, max_h); ret = artwork_get_item(evbuf, id, max_w, max_h);
len = evbuffer_get_length(evbuf);
switch (ret) switch (ret)
{ {
case ART_FMT_PNG: case ART_FMT_PNG:
@ -2402,8 +2407,8 @@ daap_reply_extra_data(struct evhttp_request *req, struct evbuffer *evbuf, char *
break; break;
default: default:
if (EVBUFFER_LENGTH(evbuf) > 0) if (len > 0)
evbuffer_drain(evbuf, EVBUFFER_LENGTH(evbuf)); evbuffer_drain(evbuf, len);
goto no_artwork; goto no_artwork;
} }
@ -2411,7 +2416,7 @@ daap_reply_extra_data(struct evhttp_request *req, struct evbuffer *evbuf, char *
headers = evhttp_request_get_output_headers(req); headers = evhttp_request_get_output_headers(req);
evhttp_remove_header(headers, "Content-Type"); evhttp_remove_header(headers, "Content-Type");
evhttp_add_header(headers, "Content-Type", ctype); evhttp_add_header(headers, "Content-Type", ctype);
snprintf(clen, sizeof(clen), "%ld", (long)EVBUFFER_LENGTH(evbuf)); snprintf(clen, sizeof(clen), "%ld", (long)len);
evhttp_add_header(headers, "Content-Length", clen); evhttp_add_header(headers, "Content-Length", clen);
/* No gzip compression for artwork */ /* No gzip compression for artwork */
@ -2561,7 +2566,7 @@ daap_reply_dmap_test(struct evhttp_request *req, struct evbuffer *evbuf, char **
dmap_add_field(test, &dmap_TST8, buf, 0); dmap_add_field(test, &dmap_TST8, buf, 0);
dmap_add_field(test, &dmap_TST9, buf, 0); dmap_add_field(test, &dmap_TST9, buf, 0);
dmap_add_container(evbuf, dmap_TEST.tag, EVBUFFER_LENGTH(test)); dmap_add_container(evbuf, dmap_TEST.tag, evbuffer_get_length(test));
ret = evbuffer_add_buffer(evbuf, test); ret = evbuffer_add_buffer(evbuf, test);
evbuffer_free(test); evbuffer_free(test);

View File

@ -2,11 +2,7 @@
#ifndef __HTTPD_DAAP_H__ #ifndef __HTTPD_DAAP_H__
#define __HTTPD_DAAP_H__ #define __HTTPD_DAAP_H__
#ifdef HAVE_LIBEVENT2 #include <event2/http.h>
# include <event2/http.h>
#else
# include "evhttp/evhttp_compat.h"
#endif
int int
daap_init(void); daap_init(void);