Fix problems with iTunes 12.1, see issue #100

- don't announce group support to iTunes
    - support for absolute http url streaming requests
This commit is contained in:
ejurgensen 2015-02-06 22:14:26 +01:00
parent 907c1725f2
commit ebfff85afa

View File

@ -822,7 +822,15 @@ daap_reply_server_info(struct evhttp_request *req, struct evbuffer *evbuf, char
dmap_add_int(content, "aeSV", apro); // com.apple.itunes.music-sharing-version (determines if itunes shows share types) dmap_add_int(content, "aeSV", apro); // com.apple.itunes.music-sharing-version (determines if itunes shows share types)
dmap_add_short(content, "ated", 7); // daap.supportsextradata dmap_add_short(content, "ated", 7); // daap.supportsextradata
dmap_add_short(content, "asgr", 3); // daap.supportsgroups
/* Sub-optimal user-agent sniffing to solve the problem that iTunes 12.1
* does not work if we announce support for groups.
*/
ua = evhttp_find_header(headers, "User-Agent");
if (ua && (strncmp(ua, "iTunes", strlen("iTunes")) == 0))
dmap_add_short(content, "asgr", 0); // daap.supportsgroups (1=artists, 2=albums, 3=both)
else
dmap_add_short(content, "asgr", 3); // daap.supportsgroups (1=artists, 2=albums, 3=both)
// dmap_add_long(content, "asse", 0x80000); // unknown - used by iTunes // dmap_add_long(content, "asse", 0x80000); // unknown - used by iTunes
@ -857,6 +865,9 @@ daap_reply_server_info(struct evhttp_request *req, struct evbuffer *evbuf, char
dmap_add_int(content, "msdc", 1); // dmap.databasescount dmap_add_int(content, "msdc", 1); // dmap.databasescount
// dmap_add_int(content, "mstc", ); // dmap.utctime
// dmap_add_int(content, "msto", ); // dmap.utcoffset
// Create container // Create container
dmap_add_container(evbuf, "msrv", EVBUFFER_LENGTH(content)); dmap_add_container(evbuf, "msrv", EVBUFFER_LENGTH(content));
evbuffer_add_buffer(evbuf, content); evbuffer_add_buffer(evbuf, content);
@ -2331,14 +2342,9 @@ daap_reply_extra_data(struct evhttp_request *req, struct evbuffer *evbuf, char *
static int static int
daap_stream(struct evhttp_request *req, struct evbuffer *evbuf, char **uri, struct evkeyvalq *query, const char *ua) daap_stream(struct evhttp_request *req, struct evbuffer *evbuf, char **uri, struct evkeyvalq *query, const char *ua)
{ {
struct daap_session *s;
int id; int id;
int ret; int ret;
s = daap_session_find(req, query, evbuf);
if (!s)
return -1;
ret = safe_atoi32(uri[3], &id); ret = safe_atoi32(uri[3], &id);
if (ret < 0) if (ret < 0)
evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request"); evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
@ -2348,6 +2354,23 @@ daap_stream(struct evhttp_request *req, struct evbuffer *evbuf, char **uri, stru
return ret; return ret;
} }
static char *
uri_relative(char *uri, const char *protocol)
{
char *ret;
if (strncmp(uri, protocol, strlen(protocol)) != 0)
return NULL;
ret = strchr(uri + strlen(protocol), '/');
if (!ret)
{
DPRINTF(E_LOG, L_DAAP, "Malformed DAAP Request URI '%s'\n", uri);
return NULL;
}
return ret;
}
static char * static char *
daap_fix_request_uri(struct evhttp_request *req, char *uri) daap_fix_request_uri(struct evhttp_request *req, char *uri)
@ -2356,25 +2379,21 @@ daap_fix_request_uri(struct evhttp_request *req, char *uri)
/* iTunes 9 gives us an absolute request-uri like /* iTunes 9 gives us an absolute request-uri like
* daap://10.1.1.20:3689/server-info * daap://10.1.1.20:3689/server-info
* iTunes 12.1 gives us an absolute request-uri for streaming like
* http://10.1.1.20:3689/databases/1/items/1.mp3
*/ */
if (strncmp(uri, "daap://", strlen("daap://")) != 0) if ( (ret = uri_relative(uri, "daap://")) || (ret = uri_relative(uri, "http://")) )
return uri;
/* Clear the proxy request flag set by evhttp
* due to the request URI being absolute.
* It has side-effects on Connection: keep-alive
*/
req->flags &= ~EVHTTP_PROXY_REQUEST;
ret = strchr(uri + strlen("daap://"), '/');
if (!ret)
{ {
DPRINTF(E_LOG, L_DAAP, "Malformed DAAP Request URI '%s'\n", uri); /* Clear the proxy request flag set by evhttp
return NULL; * due to the request URI being absolute.
* It has side-effects on Connection: keep-alive
*/
req->flags &= ~EVHTTP_PROXY_REQUEST;
return ret;
} }
return ret; return uri;
} }