mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-28 08:05:56 -05:00
index support, closes ticket #1
This commit is contained in:
parent
0d4882ae8e
commit
1cca7d3a53
@ -127,7 +127,7 @@ int db_sql_open_sqlite3(char **pe, char *parameters) {
|
|||||||
* escape a sql string, returning it the supplied buffer.
|
* escape a sql string, returning it the supplied buffer.
|
||||||
* note that this uses the sqlite escape format -- use %q for quoted
|
* note that this uses the sqlite escape format -- use %q for quoted
|
||||||
* sql.
|
* sql.
|
||||||
*
|
*
|
||||||
* @param buffer buffer to throw the escaped sql into
|
* @param buffer buffer to throw the escaped sql into
|
||||||
* @param size size of buffer (or size required, if DB_E_SIZE)
|
* @param size size of buffer (or size required, if DB_E_SIZE)
|
||||||
* @param fmt printf style format
|
* @param fmt printf style format
|
||||||
@ -1125,7 +1125,7 @@ int db_sql_enum_start(char **pe, DBQUERYINFO *pinfo) {
|
|||||||
/* Apply any index */
|
/* Apply any index */
|
||||||
switch(pinfo->index_type) {
|
switch(pinfo->index_type) {
|
||||||
case indexTypeFirst:
|
case indexTypeFirst:
|
||||||
sprintf(scratch," limit %d",pinfo->index_high);
|
sprintf(scratch," limit %d",pinfo->index_low);
|
||||||
break;
|
break;
|
||||||
case indexTypeLast:
|
case indexTypeLast:
|
||||||
if(pinfo->index_low >= results) {
|
if(pinfo->index_low >= results) {
|
||||||
@ -1135,7 +1135,8 @@ int db_sql_enum_start(char **pe, DBQUERYINFO *pinfo) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case indexTypeSub:
|
case indexTypeSub:
|
||||||
sprintf(scratch," limit %d offset %d",pinfo->index_high - pinfo->index_low,
|
sprintf(scratch," limit %d offset %d",
|
||||||
|
pinfo->index_high - pinfo->index_low + 1,
|
||||||
pinfo->index_low);
|
pinfo->index_low);
|
||||||
break;
|
break;
|
||||||
case indexTypeNone:
|
case indexTypeNone:
|
||||||
@ -1250,7 +1251,7 @@ int db_sql_get_size(DBQUERYINFO *pinfo, SQL_ROW valarray) {
|
|||||||
case queryTypeBrowseAlbums:
|
case queryTypeBrowseAlbums:
|
||||||
case queryTypeBrowseGenres:
|
case queryTypeBrowseGenres:
|
||||||
case queryTypeBrowseComposers:
|
case queryTypeBrowseComposers:
|
||||||
return valarray[0] ? (8 + (int) strlen(valarray[0])) : 0;
|
return valarray[0] ? (8 + (int) strlen(valarray[0])) : 0;
|
||||||
case queryTypePlaylists:
|
case queryTypePlaylists:
|
||||||
size = 8; /* mlit */
|
size = 8; /* mlit */
|
||||||
size += 12; /* mimc - you get it whether you want it or not */
|
size += 12; /* mimc - you get it whether you want it or not */
|
||||||
|
@ -159,7 +159,8 @@ int daap_auth(char *username, char *password) {
|
|||||||
void daap_handler(WS_CONNINFO *pwsc) {
|
void daap_handler(WS_CONNINFO *pwsc) {
|
||||||
DBQUERYINFO *pqi;
|
DBQUERYINFO *pqi;
|
||||||
char *token, *string, *save;
|
char *token, *string, *save;
|
||||||
char *query;
|
char *query, *index, *ptr;
|
||||||
|
int l,h;
|
||||||
|
|
||||||
pqi=(DBQUERYINFO*)malloc(sizeof(DBQUERYINFO));
|
pqi=(DBQUERYINFO*)malloc(sizeof(DBQUERYINFO));
|
||||||
if(!pqi) {
|
if(!pqi) {
|
||||||
@ -184,6 +185,42 @@ void daap_handler(WS_CONNINFO *pwsc) {
|
|||||||
DPRINTF(E_DBG,L_DAAP,"Parsed query successfully\n");
|
DPRINTF(E_DBG,L_DAAP,"Parsed query successfully\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set up the index stuff -- this will be in the format
|
||||||
|
* index = l, index=l-h, index=l- or index=-h
|
||||||
|
*/
|
||||||
|
|
||||||
|
pqi->index_type=indexTypeNone;
|
||||||
|
|
||||||
|
index=ws_getvar(pwsc,"index");
|
||||||
|
if(index) {
|
||||||
|
DPRINTF(E_DBG,L_DAAP,"Indexed query: %s\n",index);
|
||||||
|
|
||||||
|
/* we have some kind of index string... */
|
||||||
|
l=strtol(index,&ptr,10);
|
||||||
|
if(l<0) { /* "-h"... tail range, last "h" entries */
|
||||||
|
pqi->index_type = indexTypeLast;
|
||||||
|
pqi->index_low = l * -1;
|
||||||
|
DPRINTF(E_DBG,L_DAAP,"Index type last %d\n",l);
|
||||||
|
} else if(*ptr == '\0') { /* single item */
|
||||||
|
pqi->index_type = indexTypeSub;
|
||||||
|
pqi->index_low = l;
|
||||||
|
pqi->index_high = l;
|
||||||
|
DPRINTF(E_DBG,L_DAAP,"Index type single item %d\n",l);
|
||||||
|
} else if(*ptr == '-') {
|
||||||
|
pqi->index_type = indexTypeSub;
|
||||||
|
pqi->index_low = l;
|
||||||
|
|
||||||
|
if(*++ptr == '\0') { /* l- */
|
||||||
|
/* we don't handle this */
|
||||||
|
DPRINTF(E_LOG,L_DAAP,"unhandled index: %s\n",index);
|
||||||
|
pqi->index_high = 999999;
|
||||||
|
} else {
|
||||||
|
h = strtol(ptr, &ptr, 10);
|
||||||
|
pqi->index_high=h;
|
||||||
|
}
|
||||||
|
DPRINTF(E_DBG,L_DAAP,"Index type range %d-%d\n",l,h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Add some default headers */
|
/* Add some default headers */
|
||||||
ws_addresponseheader(pwsc,"Accept-Ranges","bytes");
|
ws_addresponseheader(pwsc,"Accept-Ranges","bytes");
|
||||||
@ -1123,7 +1160,6 @@ void dispatch_playlistitems(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pqi->query_type = queryTypePlaylistItems;
|
pqi->query_type = queryTypePlaylistItems;
|
||||||
pqi->index_type=indexTypeNone;
|
|
||||||
|
|
||||||
/* FIXME: Error handling */
|
/* FIXME: Error handling */
|
||||||
if(db_enum_start(NULL,pqi)) {
|
if(db_enum_start(NULL,pqi)) {
|
||||||
@ -1190,7 +1226,6 @@ void dispatch_browse(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pqi->index_type = indexTypeNone;
|
|
||||||
|
|
||||||
if(db_enum_start(NULL,pqi)) {
|
if(db_enum_start(NULL,pqi)) {
|
||||||
DPRINTF(E_LOG,L_DAAP|L_BROW,"Could not start enum\n");
|
DPRINTF(E_LOG,L_DAAP|L_BROW,"Could not start enum\n");
|
||||||
@ -1250,7 +1285,7 @@ void dispatch_playlists(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
|||||||
|
|
||||||
|
|
||||||
pqi->query_type = queryTypePlaylists;
|
pqi->query_type = queryTypePlaylists;
|
||||||
pqi->index_type = indexTypeNone;
|
|
||||||
if(db_enum_start(NULL,pqi)) {
|
if(db_enum_start(NULL,pqi)) {
|
||||||
DPRINTF(E_LOG,L_DAAP,"Could not start enum\n");
|
DPRINTF(E_LOG,L_DAAP,"Could not start enum\n");
|
||||||
ws_returnerror(pwsc,500,"Internal server error: out of memory!\n");
|
ws_returnerror(pwsc,500,"Internal server error: out of memory!\n");
|
||||||
@ -1303,7 +1338,7 @@ void dispatch_items(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pqi->query_type = queryTypeItems;
|
pqi->query_type = queryTypeItems;
|
||||||
pqi->index_type=indexTypeNone;
|
|
||||||
if(db_enum_start(NULL,pqi)) {
|
if(db_enum_start(NULL,pqi)) {
|
||||||
DPRINTF(E_LOG,L_DAAP,"Could not start enum\n");
|
DPRINTF(E_LOG,L_DAAP,"Could not start enum\n");
|
||||||
ws_returnerror(pwsc,500,"Internal server error: out of memory!");
|
ws_returnerror(pwsc,500,"Internal server error: out of memory!");
|
||||||
|
Loading…
Reference in New Issue
Block a user