start framework for xml-rpc calls.
This commit is contained in:
parent
81515e539c
commit
f2ff609742
|
@ -28,6 +28,7 @@ mt_daapd_SOURCES = main.c daapd.h rend.h uici.c uici.h webserver.c \
|
|||
mp3-scanner.h mp3-scanner.c playlist.c playlist.h \
|
||||
rend-unix.h lexer.l parser.y strcasestr.c strcasestr.h strsep.c \
|
||||
redblack.c redblack.h dynamic-art.c dynamic-art.h query.c query.h \
|
||||
xml-rpc.h xml-rpc.c \
|
||||
$(PRENDSRC) $(ORENDSRC) $(HRENDSRC) $(OGGVORBISSRC)
|
||||
|
||||
EXTRA_DIST = mDNS.c mDNSClientAPI.h mDNSDebug.h mDNSPosix.c \
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
|
||||
#include "configfile.h"
|
||||
#include "err.h"
|
||||
#include "xml-rpc.h"
|
||||
|
||||
#ifndef WITHOUT_MDNS
|
||||
# include "rend.h"
|
||||
|
@ -581,6 +582,15 @@ void config_handler(WS_CONNINFO *pwsc) {
|
|||
pwsc->close=1;
|
||||
ws_addresponseheader(pwsc,"Connection","close");
|
||||
|
||||
if(strcasecmp(pwsc->uri,"/xml-rpc")==0) {
|
||||
/* perhaps this should get a separate handler */
|
||||
config_set_status(pwsc,0,"Serving xml-rpc method");
|
||||
xml_handle(pwsc);
|
||||
DPRINTF(E_DBG,L_CONF|L_XML,"Thread %d: xml-rpc served\n",pwsc->threadno);
|
||||
config_set_status(pwsc,0,NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(path,PATH_MAX,"%s/%s",config.web_root,pwsc->uri);
|
||||
if(!realpath(path,resolved_path)) {
|
||||
pwsc->error=errno;
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include "daap.h"
|
||||
#include "err.h"
|
||||
#include "daapd.h"
|
||||
|
||||
#include "query.h"
|
||||
|
||||
typedef struct tag_daap_items {
|
||||
|
|
|
@ -59,7 +59,7 @@ static unsigned int err_debugmask=0xFFFFFFFF; /**< modules to debug, see \ref lo
|
|||
/** text list of modules to match for setting debug mask */
|
||||
static char *err_categorylist[] = {
|
||||
"config","webserver","database","scan","query","index","browse",
|
||||
"playlist","art","daap","main","rend",NULL
|
||||
"playlist","art","daap","main","rend","xml",NULL
|
||||
};
|
||||
|
||||
#ifdef DEBUG_MEMORY
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
#define L_DAAP 0x00000200 /**< Generally daap related - main.c, daap.c, query.c */
|
||||
#define L_MAIN 0x00000400 /**< setup, teardown, signals - main.c */
|
||||
#define L_REND 0x00000800 /**< rendezvous -- rend-unix.c, rend-posix.c, etc */
|
||||
|
||||
#define L_XML 0x00002000 /**< xml - xml-rpc.c */
|
||||
#define L_MISC 0x80000000 /**< anything else */
|
||||
|
||||
extern int err_debuglevel;
|
||||
|
|
|
@ -347,7 +347,7 @@ time_t mac_to_unix_time(int t) {
|
|||
*/
|
||||
|
||||
int scan_init(char *path) {
|
||||
int err;
|
||||
int err=0;
|
||||
|
||||
scan_mode_foreground=0;
|
||||
if(db_is_empty()) {
|
||||
|
@ -386,6 +386,7 @@ int scan_path(char *path) {
|
|||
int modified_time;
|
||||
|
||||
if((current_dir=opendir(path)) == NULL) {
|
||||
DPRINTF(E_WARN,L_SCAN,"opendir: %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* $Id$
|
||||
*
|
||||
* This really isn't xmlrpc. It's xmlrpc-ish. Emphasis on -ish.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "err.h"
|
||||
#include "db-memory.h"
|
||||
#include "webserver.h"
|
||||
|
||||
/* Forwards */
|
||||
void xml_get_playlists(WS_CONNINFO *pwsc);
|
||||
void xml_get_playlistinfo(WS_CONNINFO *pwsc);
|
||||
char *xml_entity_encode(char *original);
|
||||
|
||||
/**
|
||||
* main entrypoint for the xmlrpc functions.
|
||||
*
|
||||
* @arg pwsc Pointer to the web request structure
|
||||
*/
|
||||
void xml_handle(WS_CONNINFO *pwsc) {
|
||||
char *method;
|
||||
|
||||
if((method=ws_getvar(pwsc,"method")) == NULL) {
|
||||
ws_returnerror(pwsc,500,"no method specified");
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcasecmp(method,"getPlaylists") == 0) {
|
||||
xml_get_playlists(pwsc);
|
||||
return;
|
||||
} else if(strcasecmp(method,"getPlaylistInfo") == 0) {
|
||||
xml_get_playlistinfo(pwsc);
|
||||
}
|
||||
|
||||
ws_returnerror(pwsc,500,"Invalid method");
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* return xml file of all playlists
|
||||
*/
|
||||
void xml_get_playlists(WS_CONNINFO *pwsc) {
|
||||
ENUMHANDLE henum;
|
||||
int playlistid;
|
||||
char *temp;
|
||||
|
||||
ws_addresponseheader(pwsc,"Content-type","text/xml");
|
||||
ws_writefd(pwsc,"HTTP/1.0 200 OK\r\n");
|
||||
ws_emitheaders(pwsc);
|
||||
|
||||
ws_writefd(pwsc,"<?xml version=\"1.0\" standalone=\"yes\" encoding=\"UTF-8\"?>\n");
|
||||
ws_writefd(pwsc,"<playlists>\n");
|
||||
|
||||
/* enumerate all the playlists */
|
||||
henum=db_playlist_enum_begin();
|
||||
while(henum) {
|
||||
playlistid=db_playlist_enum(&henum);
|
||||
ws_writefd(pwsc," <item>\n");
|
||||
ws_writefd(pwsc," <id>%d</id>\n",playlistid);
|
||||
temp=xml_entity_encode(db_get_playlist_name(playlistid));
|
||||
ws_writefd(pwsc," <name>%s</name>\n",temp);
|
||||
if(temp) free(temp);
|
||||
ws_writefd(pwsc," </item>\n");
|
||||
}
|
||||
|
||||
ws_writefd(pwsc,"</playlists>\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return xml file of playlist info
|
||||
*/
|
||||
void xml_get_playlistinfo(WS_CONNINFO *pwsc) {
|
||||
ws_writefd(pwsc,"HTTP/1.0 200 OK\r\n");
|
||||
ws_emitheaders(pwsc);
|
||||
}
|
||||
|
||||
/**
|
||||
* xml entity encoding, stupid style
|
||||
*/
|
||||
char *xml_entity_encode(char *original) {
|
||||
char *new;
|
||||
char *s, *d;
|
||||
int destsize;
|
||||
|
||||
destsize = 6*strlen(original)+1;
|
||||
new=(char *)malloc(destsize);
|
||||
if(!new) return NULL;
|
||||
|
||||
memset(new,0x00,destsize);
|
||||
|
||||
s=original;
|
||||
d=new;
|
||||
|
||||
while(*s) {
|
||||
switch(*s) {
|
||||
case '>':
|
||||
strcat(d,">");
|
||||
d += 4;
|
||||
s++;
|
||||
break;
|
||||
case '<':
|
||||
strcat(d,"<");
|
||||
d += 4;
|
||||
s++;
|
||||
break;
|
||||
case '"':
|
||||
strcat(d,""");
|
||||
d += 6;
|
||||
s++;
|
||||
break;
|
||||
case '\'':
|
||||
strcat(d,"'");
|
||||
d += 6;
|
||||
s++;
|
||||
break;
|
||||
case '&':
|
||||
strcat(d,"&");
|
||||
d += 5;
|
||||
s++;
|
||||
break;
|
||||
default:
|
||||
*d++ = *s++;
|
||||
}
|
||||
}
|
||||
|
||||
return new;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef _XMLRPC_H_
|
||||
#define _XMLRPC_H_
|
||||
|
||||
#include "webserver.h"
|
||||
|
||||
extern void xml_handle(WS_CONNINFO *pwsc);
|
||||
|
||||
#endif /* _XMLRPC_H_ */
|
Loading…
Reference in New Issue