Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix upnpsoap.c inconsistencies after 1.3.0 update #22

Merged
merged 1 commit into from
Aug 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 68 additions & 81 deletions upnpsoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1569,118 +1569,104 @@ BrowseContentDirectory(struct upnphttp * h, const char * action)
}
else
{
if (isPasswd) {
if (isPasswd) {
DPRINTF(E_INFO, L_PASSWORD, "Is Password %s\n", ObjectID);
createPasswordContainer(&args, ObjectID, 0);
totalMatches = args.returned;
if (h->req_client) {
if (h->req_client) {
DPRINTF(E_INFO, L_PASSWORD, "Passwords %s\n", args.password);
h->req_client->password = args.password;
}
} else {
magic = check_magic_container(ObjectID, args.flags);
if (magic)
}
else
{
if (magic->objectid && *(magic->objectid))
ObjectID = *(magic->objectid);
if (magic->objectid_sql)
objectid_sql = magic->objectid_sql;
if (magic->parentid_sql)
parentid_sql = magic->parentid_sql;
if (magic->refid_sql)
refid_sql = magic->refid_sql;
if (magic->where)
strncpyt(where, magic->where, sizeof(where));
if (magic->orderby && !GETFLAG(DLNA_STRICT_MASK))
orderBy = strdup(magic->orderby);
if (magic->max_count > 0)
magic = check_magic_container(ObjectID, args.flags);
if (magic)
{
int limit = MAX(magic->max_count - StartingIndex, 0);
ret = get_child_count(ObjectID, magic, args.password);
totalMatches = MIN(ret, limit);
if (RequestedCount > limit || RequestedCount < 0)
RequestedCount = limit;
if (magic->objectid && *(magic->objectid))
ObjectID = *(magic->objectid);
if (magic->objectid_sql)
objectid_sql = magic->objectid_sql;
if (magic->parentid_sql)
parentid_sql = magic->parentid_sql;
if (magic->refid_sql)
refid_sql = magic->refid_sql;
if (magic->where)
strncpyt(where, magic->where, sizeof(where));
if (magic->orderby && !GETFLAG(DLNA_STRICT_MASK))
orderBy = strdup(magic->orderby);
if (magic->max_count > 0)
{
int limit = MAX(magic->max_count - StartingIndex, 0);
ret = get_child_count(ObjectID, magic, args.password);
totalMatches = MIN(ret, limit);
if (RequestedCount > limit || RequestedCount < 0)
RequestedCount = limit;
}
}
}
if (!where[0]) {
if (!where[0]) {
if (strcmp(ObjectID, "0") == 0 || strcmp(ObjectID, MUSIC_ID) == 0 || strcmp(ObjectID, BROWSEDIR_ID) == 0 ||
strcmp(ObjectID, VIDEO_ID) == 0 || strcmp(ObjectID, IMAGE_ID) == 0) {
createPasswordPrimaryContainer(&args, ObjectID);
AddedPasswordContainer=1;
}

sqlite3_snprintf(sizeof(where), where, "PARENT_ID = '%q'", ObjectID);
}

if (!totalMatches) {
totalMatches = get_child_count(ObjectID, magic, args.password) + AddedPasswordContainer;
}

ret = 0;
if (SortCriteria && !orderBy)
{
__SORT_LIMIT
orderBy = parse_sort_criteria(SortCriteria, &ret);
}
else if (!orderBy)
{
if( strncmp(ObjectID, MUSIC_PLIST_ID, strlen(MUSIC_PLIST_ID)) == 0 )
{
if( strcmp(ObjectID, MUSIC_PLIST_ID) == 0 )
ret = xasprintf(&orderBy, "order by d.TITLE");
else
ret = xasprintf(&orderBy, "order by length(OBJECT_ID), OBJECT_ID");
}
else if( args.flags & FLAG_FORCE_SORT )

if (!totalMatches)
totalMatches = get_child_count(ObjectID, magic, args.password) + AddedPasswordContainer;
ret = 0;
if (SortCriteria && !orderBy)
{
__SORT_LIMIT
ret = xasprintf(&orderBy, "order by o.CLASS, d.DISC, d.TRACK, d.TITLE");
}
/* LG TV ordering bug */
else if( args.client == ELGDevice )
ret = xasprintf(&orderBy, "order by o.CLASS, d.TITLE");
else
orderBy = parse_sort_criteria(SortCriteria, &ret);
if( ret == -1 )
}
else if (!orderBy)
{
free(orderBy);
orderBy = NULL;
ret = 0;
if( strncmp(ObjectID, MUSIC_PLIST_ID, strlen(MUSIC_PLIST_ID)) == 0 )
{
if( strcmp(ObjectID, MUSIC_PLIST_ID) == 0 )
ret = xasprintf(&orderBy, "order by d.TITLE");
else
ret = xasprintf(&orderBy, "order by length(OBJECT_ID), OBJECT_ID");
}
else if( args.flags & FLAG_FORCE_SORT )
{
__SORT_LIMIT
ret = xasprintf(&orderBy, "order by o.CLASS, d.DISC, d.TRACK, d.TITLE");
}
/* LG TV ordering bug */
else if( args.client == ELGDevice )
ret = xasprintf(&orderBy, "order by o.CLASS, d.TITLE");
else
orderBy = parse_sort_criteria(SortCriteria, &ret);
if( ret == -1 )
{
free(orderBy);
orderBy = NULL;
ret = 0;
}
}
}
/* If it's a DLNA client, return an error for bad sort criteria */
if( ret < 0 && ((args.flags & FLAG_DLNA) || GETFLAG(DLNA_STRICT_MASK)) )
{
SoapError(h, 709, "Unsupported or invalid sort criteria");
goto browse_error;
}
if( ret < 0 && ((args.flags & FLAG_DLNA) || GETFLAG(DLNA_STRICT_MASK)) )
{
SoapError(h, 709, "Unsupported or invalid sort criteria");
goto browse_error;
}

sql = sqlite3_mprintf("SELECT %s, %s, %s, " COLUMNS
"from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)"
"from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)"
" where (%s and (o.password is null or o.password = '' or o.password in (%s))) %s limit %d, %d;",
objectid_sql, parentid_sql, refid_sql,
where, args.password ? args.password : "''", THISORNUL(orderBy), StartingIndex, RequestedCount);
where, args.password ? args.password : "''", THISORNUL(orderBy), StartingIndex, RequestedCount);
DPRINTF(E_DEBUG, L_HTTP, "Browse SQL: %s\n", sql);
ret = sqlite3_exec(db, sql, callback, (void *) &args, &zErrMsg);
}
}
if (!isPasswd) {
if( (ret != SQLITE_OK) && (zErrMsg != NULL) )
{
DPRINTF(E_WARN, L_HTTP, "SQL error: %s\nBAD SQL: %s\n", zErrMsg, sql);
sqlite3_free(zErrMsg);
SoapError(h, 709, "Unsupported or invalid sort criteria");
goto browse_error;
}

sql = sqlite3_mprintf("SELECT %s, %s, %s, " COLUMNS
"from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)"
" where %s %s limit %d, %d;",
objectid_sql, parentid_sql, refid_sql,
where, THISORNUL(orderBy), StartingIndex, RequestedCount);
DPRINTF(E_DEBUG, L_HTTP, "Browse SQL: %s\n", sql);
ret = sqlite3_exec(db, sql, callback, (void *) &args, &zErrMsg);

if (!isPasswd)
{
if( ret != SQLITE_OK )
{
if( args.flags & RESPONSE_TRUNCATED )
Expand All @@ -1695,7 +1681,9 @@ BrowseContentDirectory(struct upnphttp * h, const char * action)
goto browse_error;
}
}

sqlite3_free(sql);

/* Does the object even exist? */
if( !totalMatches )
{
Expand All @@ -1706,7 +1694,6 @@ BrowseContentDirectory(struct upnphttp * h, const char * action)
}
}
}


ret = strcatf(&str, "&lt;/DIDL-Lite&gt;</Result>\n"
"<NumberReturned>%u</NumberReturned>\n"
Expand Down