From 3f4877cf2fb17fa1e736f91cd1394b247f594fe0 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Tue, 7 Jan 2014 11:30:15 -0800 Subject: [PATCH] Add a new force_sort_criteria option, to globally override the SortCriteria value sent by the client. --- minidlna.c | 3 +++ minidlna.conf | 3 +++ minidlna.conf.5 | 13 +++++++++++-- options.c | 3 ++- options.h | 3 ++- upnpglobalvars.c | 5 +++-- upnpglobalvars.h | 3 ++- upnpsoap.c | 11 ++++++++++- 8 files changed, 36 insertions(+), 8 deletions(-) diff --git a/minidlna.c b/minidlna.c index b10a360..1ebd124 100644 --- a/minidlna.c +++ b/minidlna.c @@ -694,6 +694,9 @@ init(int argc, char **argv) uid = entry->pw_uid; } break; + case FORCE_SORT_CRITERIA: + force_sort_criteria = ary_options[i].value; + break; default: DPRINTF(E_ERROR, L_GENERAL, "Unknown option in file %s\n", optionsfile); diff --git a/minidlna.conf b/minidlna.conf index bfb71d5..42698ff 100644 --- a/minidlna.conf +++ b/minidlna.conf @@ -69,3 +69,6 @@ model_number=1 # + "P" - "Pictures" # if you specify "B" and client device is audio-only then "Music/Folders" will be used as root #root_container=. + +# always force SortCriteria to this value, regardless of the SortCriteria passed by the client +#force_sort_criteria=+upnp:class,+upnp:originalTrackNumber,+dc:title diff --git a/minidlna.conf.5 b/minidlna.conf.5 index 4b29a6c..cfc5611 100644 --- a/minidlna.conf.5 +++ b/minidlna.conf.5 @@ -12,7 +12,7 @@ configuration file. .SH OPTIONS .PP -The following are user configurable options in /etc/minidlna.conf +The following are user configurable options in /etc/minidlna.conf. minidlna runs by default as user nobody, so make sure system permissions are set correctly for read access to media and write access to cache and log dirs. @@ -132,7 +132,7 @@ to automatically discover new files. Set to 'no' to disable inotify. .IP "\fBalbum_art_names\fP" This should be a list of file names to check for when searching for album art -and names should be delimited with a forward slash ("/") +and names should be delimited with a forward slash ("/"). .nf Example @@ -158,6 +158,15 @@ The possible values are: "Music/Folders" will be used as root container and you wont see Videos. .fi +.IP "\fBforce_sort_criteria\fP" +Always force SortCriteria to this value, regardless of the SortCriteria passed by the client. +.nf + +Example +force_sort_criteria=+upnp:class,+upnp:originalTrackNumber,+dc:title + +.fi + .SH VERSION diff --git a/options.c b/options.c index 842335b..1030ba4 100644 --- a/options.c +++ b/options.c @@ -61,7 +61,8 @@ static const struct { { ENABLE_TIVO, "enable_tivo" }, { ENABLE_DLNA_STRICT, "strict_dlna" }, { ROOT_CONTAINER, "root_container" }, - { USER_ACCOUNT, "user" } + { USER_ACCOUNT, "user" }, + { FORCE_SORT_CRITERIA, "force_sort_criteria" } }; int diff --git a/options.h b/options.h index 609b5db..14060ee 100644 --- a/options.h +++ b/options.h @@ -55,7 +55,8 @@ enum upnpconfigoptions { ENABLE_TIVO, /* enable support for streaming images and music to TiVo */ ENABLE_DLNA_STRICT, /* strictly adhere to DLNA specs */ ROOT_CONTAINER, /* root ObjectID (instead of "0") */ - USER_ACCOUNT /* user account to run as */ + USER_ACCOUNT, /* user account to run as */ + FORCE_SORT_CRITERIA /* force sorting by a given sort criteria */ }; /* readoptionsfile() diff --git a/upnpglobalvars.c b/upnpglobalvars.c index c51f5f8..d7cd586 100644 --- a/upnpglobalvars.c +++ b/upnpglobalvars.c @@ -62,7 +62,7 @@ time_t startup_time = 0; struct runtime_vars_s runtime_vars; uint32_t runtime_flags = INOTIFY_MASK; -const char * pidfilename = "/var/run/minidlna/minidlna.pid"; +const char *pidfilename = "/var/run/minidlna/minidlna.pid"; char uuidvalue[] = "uuid:00000000-0000-0000-0000-000000000000"; char modelname[MODELNAME_MAX_LEN] = ROOTDEV_MODELNAME; @@ -83,7 +83,7 @@ struct lan_addr_s lan_addr[MAX_LAN_ADDR]; const char * minissdpdsocketpath = "/var/run/minissdpd.sock"; /* UPnP-A/V [DLNA] */ -sqlite3 * db; +sqlite3 *db; char friendly_name[FRIENDLYNAME_MAX_LEN]; char db_path[PATH_MAX] = {'\0'}; char log_path[PATH_MAX] = {'\0'}; @@ -92,3 +92,4 @@ struct album_art_name_s * album_art_names = NULL; short int scanning = 0; volatile short int quitting = 0; volatile uint32_t updateID = 0; +const char *force_sort_criteria = NULL; diff --git a/upnpglobalvars.h b/upnpglobalvars.h index 8db7b4b..e5266be 100644 --- a/upnpglobalvars.h +++ b/upnpglobalvars.h @@ -220,7 +220,7 @@ extern char pnpx_hwid[]; extern int n_lan_addr; extern struct lan_addr_s lan_addr[]; -extern const char * minissdpdsocketpath; +extern const char *minissdpdsocketpath; /* UPnP-A/V [DLNA] */ extern sqlite3 *db; @@ -233,5 +233,6 @@ extern struct album_art_name_s *album_art_names; extern short int scanning; extern volatile short int quitting; extern volatile uint32_t updateID; +extern const char *force_sort_criteria; #endif diff --git a/upnpsoap.c b/upnpsoap.c index 3b76aae..3fee379 100644 --- a/upnpsoap.c +++ b/upnpsoap.c @@ -490,7 +490,9 @@ parse_sort_criteria(char *sortCriteria, int *error) struct string_s str; *error = 0; - if( !sortCriteria ) + if( force_sort_criteria ) + sortCriteria = strdup(force_sort_criteria); + else if( !sortCriteria ) return NULL; if( (item = strtok_r(sortCriteria, ",", &saveptr)) ) @@ -563,12 +565,17 @@ parse_sort_criteria(char *sortCriteria, int *error) if( i <= 0 ) { free(order); + if( force_sort_criteria ) + free(sortCriteria); return NULL; } /* Add a "tiebreaker" sort order */ if( !title_sorted ) strcatf(&str, ", TITLE ASC"); + if( force_sort_criteria ) + free(sortCriteria); + return order; } @@ -1211,6 +1218,8 @@ BrowseContentDirectory(struct upnphttp * h, const char * action) #endif ret = asprintf(&orderBy, "order by o.CLASS, d.DISC, d.TRACK, d.TITLE"); } + else + orderBy = parse_sort_criteria(SortCriteria, &ret); if( ret == -1 ) { orderBy = NULL;