Add a new force_sort_criteria option, to globally override the SortCriteria value sent by the client.

This commit is contained in:
Justin Maggard 2014-01-07 11:30:15 -08:00
parent a75bdadce1
commit 3f4877cf2f
8 changed files with 36 additions and 8 deletions

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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;

View File

@ -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

View File

@ -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;