From ece7c0d07188f2a9544e7a5ceb938863b51c2ba8 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Sun, 7 Mar 2010 11:11:09 +0100 Subject: [PATCH] Handle DAAP extra_data requests for groups/items artwork --- src/httpd_daap.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/src/httpd_daap.c b/src/httpd_daap.c index 8e704b50..c9acd3fb 100644 --- a/src/httpd_daap.c +++ b/src/httpd_daap.c @@ -44,6 +44,7 @@ #include "misc.h" #include "httpd.h" #include "transcode.h" +#include "artwork.h" #include "httpd_daap.h" #include "daap_query.h" #include "dmap_helpers.h" @@ -2254,16 +2255,87 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri evhttp_send_reply(req, HTTP_OK, "OK", evbuf); } +/* NOTE: We only handle artwork at the moment */ static void daap_reply_extra_data(struct evhttp_request *req, struct evbuffer *evbuf, char **uri, struct evkeyvalq *query) { + char clen[32]; struct daap_session *s; + const char *param; + int id; + int max_w; + int max_h; + int ret; s = daap_session_find(req, query, evbuf); if (!s) return; - /* Sorry, we have no artwork */ + ret = safe_atoi32(uri[3], &id); + if (ret < 0) + { + evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request"); + return; + } + + param = evhttp_find_header(query, "mw"); + if (!param) + { + DPRINTF(E_LOG, L_DAAP, "Request for artwork without mw parameter\n"); + + evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request"); + return; + } + + ret = safe_atoi32(param, &max_w); + if (ret < 0) + { + DPRINTF(E_LOG, L_DAAP, "Could not convert mw parameter to integer\n"); + + evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request"); + return; + } + + param = evhttp_find_header(query, "mh"); + if (!param) + { + DPRINTF(E_LOG, L_DAAP, "Request for artwork without mh parameter\n"); + + evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request"); + return; + } + + ret = safe_atoi32(param, &max_h); + if (ret < 0) + { + DPRINTF(E_LOG, L_DAAP, "Could not convert mh parameter to integer\n"); + + evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request"); + return; + } + + if (strcmp(uri[2], "groups") == 0) + ret = artwork_get_group(id, max_w, max_h, evbuf); + else if (strcmp(uri[2], "items") == 0) + ret = artwork_get_item(id, max_w, max_h, evbuf); + + if (ret < 0) + { + if (EVBUFFER_LENGTH(evbuf) > 0) + evbuffer_drain(evbuf, EVBUFFER_LENGTH(evbuf)); + + goto no_artwork; + } + + evhttp_remove_header(req->output_headers, "Content-Type"); + evhttp_add_header(req->output_headers, "Content-Type", "image/png"); + snprintf(clen, sizeof(clen), "%ld", EVBUFFER_LENGTH(evbuf)); + evhttp_add_header(req->output_headers, "Content-Length", clen); + + evhttp_send_reply(req, HTTP_OK, "OK", evbuf); + return; + + no_artwork: evhttp_send_reply(req, HTTP_NOCONTENT, "No Content", evbuf); }