From e72c9d0a087074c54d7084afa33a7ff60ba73a1e Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Tue, 12 Apr 2011 20:58:01 +0000 Subject: [PATCH] * Send known audio-only devices straight to the Music section on root requests. --- upnphttp.h | 2 ++ upnpsoap.c | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/upnphttp.h b/upnphttp.h index 91df730..64108e6 100644 --- a/upnphttp.h +++ b/upnphttp.h @@ -112,6 +112,8 @@ struct upnphttp { #define FLAG_MS_PFS 0x02000000 // Microsoft PlaysForSure client #define FLAG_AUDIO_ONLY 0x04000000 +#define FLAG_FREE_OBJECT_ID 0x00000001 + /* New_upnphttp() */ struct upnphttp * New_upnphttp(int); diff --git a/upnpsoap.c b/upnpsoap.c index 62dacb8..859521b 100644 --- a/upnpsoap.c +++ b/upnpsoap.c @@ -1023,22 +1023,19 @@ BrowseContentDirectory(struct upnphttp * h, const char * action) args.requested = RequestedCount; args.client = h->req_client; args.flags = h->reqflags; - if( h->reqflags & FLAG_MS_PFS ) + if( args.flags & FLAG_MS_PFS ) { - if( strchr(ObjectId, '$') || (strcmp(ObjectId, "0") == 0) ) - { - ObjectId = sqlite3_mprintf("%s", ObjectId); - } - else + if( !strchr(ObjectId, '$') && (strcmp(ObjectId, "0") != 0) ) { ptr = sql_get_text_field(db, "SELECT OBJECT_ID from OBJECTS" " where OBJECT_ID in " "('"MUSIC_ID"$%s', '"VIDEO_ID"$%s', '"IMAGE_ID"$%s')", ObjectId, ObjectId, ObjectId); if( ptr ) + { ObjectId = ptr; - else - ObjectId = sqlite3_mprintf("%s", ObjectId); + args.flags |= FLAG_FREE_OBJECT_ID; + } } } DPRINTF(E_DEBUG, L_HTTP, "Browsing ContentDirectory:\n" @@ -1051,6 +1048,12 @@ BrowseContentDirectory(struct upnphttp * h, const char * action) ObjectId, RequestedCount, StartingIndex, BrowseFlag, Filter, SortCriteria); + if( (args.flags & FLAG_AUDIO_ONLY) && (strcmp(ObjectId, "0") == 0) ) + { + ObjectId = sqlite3_mprintf("%s", MUSIC_ID); + args.flags |= FLAG_FREE_OBJECT_ID; + } + if( strcmp(BrowseFlag+6, "Metadata") == 0 ) { args.requested = 1; @@ -1082,13 +1085,12 @@ BrowseContentDirectory(struct upnphttp * h, const char * action) else asprintf(&orderBy, "order by length(OBJECT_ID), OBJECT_ID"); } - else if( strncmp(ObjectId, MUSIC_ID, strlen(MUSIC_ID)) == 0 ) + else if( args.client == ERokuSoundBridge ) { #ifdef __sparc__ if( totalMatches < 10000 ) #endif asprintf(&orderBy, "order by o.CLASS, d.DISC, d.TRACK, d.TITLE"); - } } /* If it's a DLNA client, return an error for bad sort criteria */ @@ -1134,11 +1136,9 @@ browse_error: ClearNameValueList(&data); if( orderBy ) free(orderBy); - free(resp); - if( h->reqflags & FLAG_MS_PFS ) - { + if( args.flags & FLAG_FREE_OBJECT_ID ) sqlite3_free(ObjectId); - } + free(resp); } static void