mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 23:25:56 -05:00
More plugin work
This commit is contained in:
parent
03664de092
commit
433a2ce666
@ -49,7 +49,7 @@ mtd_update_SOURCES = mtd-update.c conf.c conf.h ll.c ll.h \
|
||||
db-sql.c db-sql.h db-generic.c db-generic.h smart-parser.c \
|
||||
smart-parser.h err.c err.h os-unix.c os.h xml-rpc.c xml-rpc.h \
|
||||
restart.c restart.h uici.c uici.h ssc.c ssc.h \
|
||||
webserver.c webserver.h compat.c compat.h plugin.c plugin.h \
|
||||
webserver.c webserver.h compat.c compat.h \
|
||||
$(PRENDSRC) $(ORENDSRC) $(HRENDSRC) \
|
||||
$(SQLITEDB) $(SQLITE3DB)
|
||||
|
||||
|
@ -61,6 +61,7 @@ typedef struct tag_db_functions {
|
||||
int(*dbs_enum_start)(char **, DBQUERYINFO *);
|
||||
int(*dbs_enum_size)(char **, DBQUERYINFO *, int *, int *);
|
||||
int(*dbs_enum_fetch)(char **, DBQUERYINFO *, int *, unsigned char **);
|
||||
int(*dbs_enum_fetch_row)(char **, PACKED_MP3FILE *, DBQUERYINFO *);
|
||||
int(*dbs_enum_reset)(char **, DBQUERYINFO *);
|
||||
int(*dbs_enum_end)(char **);
|
||||
int(*dbs_start_scan)(void);
|
||||
@ -92,6 +93,7 @@ DB_FUNCTIONS db_functions[] = {
|
||||
db_sql_enum_start,
|
||||
db_sql_enum_size,
|
||||
db_sql_enum_fetch,
|
||||
db_sql_enum_fetch_row,
|
||||
db_sql_enum_reset,
|
||||
db_sql_enum_end,
|
||||
db_sql_start_scan,
|
||||
@ -121,6 +123,7 @@ DB_FUNCTIONS db_functions[] = {
|
||||
db_sql_enum_start,
|
||||
db_sql_enum_size,
|
||||
db_sql_enum_fetch,
|
||||
db_sql_enum_fetch_row,
|
||||
db_sql_enum_reset,
|
||||
db_sql_enum_end,
|
||||
db_sql_start_scan,
|
||||
@ -727,6 +730,15 @@ int db_enum_fetch(char **pe, DBQUERYINFO *pinfo, int *size,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* fetch the next item int he result set started by the db enum. this
|
||||
* will be in native packed row format
|
||||
*/
|
||||
int db_enum_fetch_row(char **pe, PACKED_MP3FILE *row, DBQUERYINFO *pinfo) {
|
||||
return db_current->dbs_enum_fetch_row(pe, row, pinfo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* reset the enum, without coming out the the db_writelock
|
||||
*/
|
||||
|
@ -125,6 +125,7 @@ typedef struct tag_dbqueryinfo {
|
||||
int playlist_id;
|
||||
int db_id;
|
||||
int session_id;
|
||||
int want_count;
|
||||
int specifiedtotalcount;
|
||||
int uri_count;
|
||||
char *uri_sections[10];
|
||||
@ -156,6 +157,7 @@ extern int db_add(char **pe, MP3FILE *pmp3, int *id);
|
||||
extern int db_enum_start(char **pe, DBQUERYINFO *pinfo);
|
||||
extern int db_enum_size(char **pe, DBQUERYINFO *pinfo, int *count, int *total_size);
|
||||
extern int db_enum_fetch(char **pe, DBQUERYINFO *pinfo, int *size, unsigned char **pdmap);
|
||||
extern int db_enum_fetch_row(char **pe, PACKED_MP3FILE *row, DBQUERYINFO *pinfo);
|
||||
extern int db_enum_reset(char **pe, DBQUERYINFO *pinfo);
|
||||
extern int db_enum_end(char **pe);
|
||||
extern int db_start_scan(void);
|
||||
|
18
src/db-sql.c
18
src/db-sql.c
@ -1136,8 +1136,7 @@ int db_sql_enum_start(char **pe, DBQUERYINFO *pinfo) {
|
||||
DPRINTF(E_DBG,L_DB,"No query/filter\n");
|
||||
}
|
||||
|
||||
|
||||
if(pinfo->index_type != indexTypeNone) {
|
||||
if((pinfo->index_type != indexTypeNone) || (pinfo->want_count)) {
|
||||
/* the only time returned count is not specifiedtotalcount
|
||||
* is if we have an index. */
|
||||
strcpy(scratch,query_count);
|
||||
@ -1224,6 +1223,21 @@ int db_sql_enum_size(char **pe, DBQUERYINFO *pinfo, int *count, int *total_size)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* fetch the next row in raw row format
|
||||
*/
|
||||
int db_sql_enum_fetch_row(char **pe, PACKED_MP3FILE *row, DBQUERYINFO *pinfo) {
|
||||
int err;
|
||||
|
||||
err=db_sql_enum_fetch_fn(pe, (char***)row);
|
||||
if(err != DB_E_SUCCESS) {
|
||||
db_sql_enum_end_fn(NULL);
|
||||
return err;
|
||||
}
|
||||
|
||||
return DB_E_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch the next record from the enum
|
||||
*/
|
||||
|
@ -39,6 +39,7 @@ extern int db_sql_add(char **pe, MP3FILE *pmp3, int *id);
|
||||
extern int db_sql_enum_start(char **pe, DBQUERYINFO *pinfo);
|
||||
extern int db_sql_enum_size(char **pe, DBQUERYINFO *pinfo, int *count, int *total_size);
|
||||
extern int db_sql_enum_fetch(char **pe, DBQUERYINFO *pinfo, int *size, unsigned char **pdmap);
|
||||
extern int db_sql_enum_fetch_row(char **pe, PACKED_MP3FILE *row, DBQUERYINFO *pinfo);
|
||||
extern int db_sql_enum_reset(char **pe, DBQUERYINFO *pinfo);
|
||||
extern int db_sql_enum_end(char **pe);
|
||||
extern int db_sql_start_scan(void);
|
||||
|
@ -235,7 +235,7 @@ void daap_handler(WS_CONNINFO *pwsc) {
|
||||
|
||||
/* tokenize the uri for easier decoding */
|
||||
string=(pwsc->uri)+1;
|
||||
while((token=strtok_r(string,"/",&save))) {
|
||||
while((pqi->uri_count < 9) && (token=strtok_r(string,"/",&save))) {
|
||||
string=NULL;
|
||||
pqi->uri_sections[pqi->uri_count++] = token;
|
||||
}
|
||||
@ -737,7 +737,7 @@ char *dispatch_xml_encode(char *original, int len) {
|
||||
return new;
|
||||
}
|
||||
|
||||
void dispatch_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
void dispatch_stream_id(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, char *id) {
|
||||
MP3FILE *pmp3;
|
||||
FILE *file_ptr;
|
||||
int file_fd;
|
||||
@ -753,7 +753,7 @@ void dispatch_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
/* stream out the song */
|
||||
pwsc->close=1;
|
||||
|
||||
item=atoi(pqi->uri_sections[3]);
|
||||
item = atoi(id);
|
||||
|
||||
if(ws_getrequestheader(pwsc,"range")) {
|
||||
offset=(off_t)atol(ws_getrequestheader(pwsc,"range") + 6);
|
||||
@ -763,6 +763,7 @@ void dispatch_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
pmp3=db_fetch_item(NULL,item);
|
||||
if(!pmp3) {
|
||||
DPRINTF(E_LOG,L_DAAP|L_WS|L_DB,"Could not find requested item %lu\n",item);
|
||||
config_set_status(pwsc,pqi->session_id,NULL);
|
||||
ws_returnerror(pwsc,404,"File Not Found");
|
||||
} else if (server_side_convert(pmp3->codectype)) {
|
||||
/************************
|
||||
@ -788,7 +789,6 @@ void dispatch_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
"Thread %d: Error opening %s for conversion\n",
|
||||
pwsc->threadno,pmp3->path);
|
||||
ws_returnerror(pwsc,404,"Not found");
|
||||
config_set_status(pwsc,pqi->session_id,NULL);
|
||||
db_dispose_item(pmp3);
|
||||
} else {
|
||||
// The type should really be determined by the transcoding
|
||||
@ -949,6 +949,9 @@ void dispatch_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
// free(pqi);
|
||||
}
|
||||
|
||||
void dispatch_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
dispatch_stream_id(pwsc, pqi, pqi->uri_sections[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* add songs to an existing playlist
|
||||
|
@ -5,7 +5,10 @@
|
||||
#ifndef _DISPATCH_H_
|
||||
#define _DISPATCH_H_
|
||||
|
||||
#include "db-generic.h"
|
||||
|
||||
extern void daap_handler(WS_CONNINFO *pwsc);
|
||||
extern int daap_auth(char *hostname, char *username, char *password);
|
||||
extern void dispatch_stream_id(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, char *id);
|
||||
|
||||
#endif
|
||||
|
@ -90,6 +90,17 @@ typedef struct tag_m3ufile {
|
||||
int index; /**< index of playlist for paths with multiple playlists */
|
||||
} M3UFILE;
|
||||
|
||||
typedef struct tag_packed_m3ufile {
|
||||
char *id;
|
||||
char *title;
|
||||
char *type;
|
||||
char *items;
|
||||
char *query;
|
||||
char *db_timestamp;
|
||||
char *path;
|
||||
char *index;
|
||||
} PACKED_M3UFILE;
|
||||
|
||||
typedef struct tag_packed_mp3file {
|
||||
char *id;
|
||||
char *path;
|
||||
|
83
src/plugin.c
83
src/plugin.c
@ -31,9 +31,13 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "conf.h"
|
||||
#include "db-generic.h"
|
||||
#include "dispatch.h"
|
||||
#include "err.h"
|
||||
#include "os.h"
|
||||
#include "plugin.h"
|
||||
#include "smart-parser.h"
|
||||
#include "xml-rpc.h"
|
||||
#include "webserver.h"
|
||||
|
||||
@ -217,8 +221,6 @@ void plugin_url_handle(WS_CONNINFO *pwsc) {
|
||||
/* so functions must be a tag_plugin_output_fn */
|
||||
disp_fn=(((PLUGIN_OUTPUT_FN*)ppi->functions)->handler);
|
||||
disp_fn(pwsc);
|
||||
|
||||
ws_returnerror(pwsc,404,"Wtf!");
|
||||
_plugin_unlock();
|
||||
return;
|
||||
}
|
||||
@ -263,5 +265,80 @@ void pi_xml_output(XMLSTRUCT *pxml, char *section, char *fmt, ...) {
|
||||
}
|
||||
|
||||
void pi_xml_deinit(XMLSTRUCT *pxml) {
|
||||
return xml_deinit(pxml);
|
||||
xml_deinit(pxml);
|
||||
}
|
||||
|
||||
char *pi_ws_uri(WS_CONNINFO *pwsc) {
|
||||
return pwsc->uri;
|
||||
}
|
||||
|
||||
void pi_ws_close(WS_CONNINFO *pwsc) {
|
||||
pwsc->close=1;
|
||||
}
|
||||
|
||||
void pi_ws_returnerror(WS_CONNINFO *pwsc, int error, char *description) {
|
||||
ws_returnerror(pwsc,error,description);
|
||||
}
|
||||
|
||||
char *pi_ws_getvar(WS_CONNINFO *pwsc, char *var) {
|
||||
return ws_getvar(pwsc,var);
|
||||
}
|
||||
|
||||
void pi_log(int level, char *fmt, ...) {
|
||||
char buf[256];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap,fmt);
|
||||
vsnprintf(buf,sizeof(buf),fmt,ap);
|
||||
va_end(ap);
|
||||
|
||||
DPRINTF(level,L_PLUG,"%s",buf);
|
||||
}
|
||||
|
||||
char *pi_server_ver(void) {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
int pi_server_name(char *name, int *len) {
|
||||
return conf_get_string("general","servername","unknown",name, len);
|
||||
}
|
||||
|
||||
int pi_db_count(void) {
|
||||
int count;
|
||||
db_get_song_count(NULL, &count);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int pi_db_enum_start(char **pe, DBQUERYINFO *pinfo) {
|
||||
return db_enum_start(pe, pinfo);
|
||||
}
|
||||
|
||||
int pi_db_enum_fetch_row(char **pe, PACKED_MP3FILE *row, DBQUERYINFO *pinfo) {
|
||||
return db_enum_fetch_row(pe, row, pinfo);
|
||||
}
|
||||
|
||||
int pi_db_enum_end(char **pe) {
|
||||
return db_enum_end(pe);
|
||||
}
|
||||
|
||||
PARSETREE pi_sp_init(void) {
|
||||
return sp_init();
|
||||
}
|
||||
|
||||
int pi_sp_parse(PARSETREE tree, char *term) {
|
||||
return sp_parse(tree,term,0);
|
||||
}
|
||||
|
||||
int pi_sp_dispose(PARSETREE tree) {
|
||||
return sp_dispose(tree);
|
||||
}
|
||||
|
||||
char *pi_sp_get_error(PARSETREE tree) {
|
||||
return sp_get_error(tree);
|
||||
}
|
||||
|
||||
void pi_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, char *id) {
|
||||
dispatch_stream_id(pwsc, pqi,id);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user