add xml-rpc method for getting config

This commit is contained in:
Ron Pedde 2006-04-04 06:31:19 +00:00
parent 860f853778
commit 78455709c2
4 changed files with 109 additions and 8 deletions

View File

@ -48,6 +48,8 @@
#include "ll.h" #include "ll.h"
#include "daapd.h" #include "daapd.h"
#include "os.h" #include "os.h"
#include "webserver.h"
#include "xml-rpc.h"
/** Globals */ /** Globals */
//static int ecode; //static int ecode;
@ -84,6 +86,7 @@ static int _conf_makedir(char *path, char *user);
static int _conf_existdir(char *path); static int _conf_existdir(char *path);
static int _conf_split(char *s, char *delimiters, char ***argvp); static int _conf_split(char *s, char *delimiters, char ***argvp);
static void _conf_dispose_split(char **argv); static void _conf_dispose_split(char **argv);
static int _conf_xml_dump(XMLSTRUCT *pxml,LL *pll,int sublevel,char *parent);
static CONF_ELEMENTS conf_elements[] = { static CONF_ELEMENTS conf_elements[] = {
{ 1, 0, CONF_T_STRING,"general","runas" }, { 1, 0, CONF_T_STRING,"general","runas" },
@ -1209,3 +1212,85 @@ void conf_dispose_array(char **argv) {
index++; index++;
} }
} }
/* FIXME: this belongs in xml-rpc, but need config enumerating fns */
/**
* dump the config to xml
*
* @param pwsc web connection to dump to
* @returns TRUE on success, FALSE otherwise
*/
int conf_xml_dump(WS_CONNINFO *pwsc) {
XMLSTRUCT *pxml;
int retval;
if(!conf_main_file) {
return FALSE; /* CONF_E_NOCONF */
}
pxml = xml_init(pwsc,1);
xml_push(pxml,"config");
_conf_lock();
retval = _conf_xml_dump(pxml,conf_main,0,NULL);
_conf_unlock();
xml_pop(pxml);
xml_deinit(pxml);
return retval;
}
/**
* do the actual work of dumping the config file
*
* @param pwsc web connection we are writing the config file to
* @param pll list we are dumping k/v pairs for
* @param sublevel whether this is the root, or a subkey
* @returns TRUE on success, FALSE otherwise
*/
int _conf_xml_dump(XMLSTRUCT *pxml, LL *pll, int sublevel, char *parent) {
LL_ITEM *pli;
LL_ITEM *plitemp;
if(!pll)
return TRUE;
/* write all the solo keys, first! */
pli = pll->itemlist.next;
while(pli) {
switch(pli->type) {
case LL_TYPE_LL:
if(sublevel) {
/* must be multivalued */
plitemp = NULL;
xml_push(pxml,"array");
while((plitemp = ll_get_next(pli->value.as_ll,plitemp))) {
xml_output(pxml,pli->key,"%s",plitemp->value.as_string);
}
xml_pop(pxml);
} else {
xml_push(pxml,pli->key);
if(!_conf_xml_dump(pxml, pli->value.as_ll, 1, pli->key))
return FALSE;
xml_pop(pxml);
}
break;
case LL_TYPE_INT:
xml_output(pxml,pli->key,"%d",pli->value.as_int);
break;
case LL_TYPE_STRING:
xml_output(pxml,pli->key,"%s",pli->value.as_string);
break;
}
pli = pli->next;
}
return TRUE;
}

View File

@ -48,4 +48,9 @@ extern int conf_write(void);
extern char *conf_implode(char *section, char *key, char *delimiter); extern char *conf_implode(char *section, char *key, char *delimiter);
extern int conf_get_array(char *section, char *key, char ***argvp); extern int conf_get_array(char *section, char *key, char ***argvp);
extern void conf_dispose_array(char **argv); extern void conf_dispose_array(char **argv);
/* FIXME: get enum functions and move to xml-rpc */
#include "webserver.h"
extern int conf_xml_dump(WS_CONNINFO *pwsc);
#endif /* _CONFIG_H_ */ #endif /* _CONFIG_H_ */

View File

@ -15,12 +15,14 @@
#include <time.h> #include <time.h>
#include "configfile.h" #include "configfile.h"
#include "conf.h"
#include "db-generic.h" #include "db-generic.h"
#include "daapd.h" #include "daapd.h"
#include "err.h" #include "err.h"
#include "mp3-scanner.h" #include "mp3-scanner.h"
#include "rend.h" #include "rend.h"
#include "webserver.h" #include "webserver.h"
#include "xml-rpc.h"
/* typedefs */ /* typedefs */
typedef struct tag_xmlstack { typedef struct tag_xmlstack {
@ -28,22 +30,16 @@ typedef struct tag_xmlstack {
struct tag_xmlstack *next; struct tag_xmlstack *next;
} XMLSTACK; } XMLSTACK;
typedef struct tag_xmlstruct { struct tag_xmlstruct {
WS_CONNINFO *pwsc; WS_CONNINFO *pwsc;
int stack_level; int stack_level;
XMLSTACK stack; XMLSTACK stack;
} XMLSTRUCT; };
/* Forwards */ /* Forwards */
void xml_get_stats(WS_CONNINFO *pwsc); void xml_get_stats(WS_CONNINFO *pwsc);
char *xml_entity_encode(char *original); char *xml_entity_encode(char *original);
XMLSTRUCT *xml_init(WS_CONNINFO *pwsc, int emit_header);
void xml_push(XMLSTRUCT *pxml, char *term);
void xml_pop(XMLSTRUCT *pxml);
void xml_output(XMLSTRUCT *pxml, char *section, char *fmt, ...);
void xml_deinit(XMLSTRUCT *pxml);
/** /**
* create an xml response structure, a helper struct for * create an xml response structure, a helper struct for
* building xml responses. * building xml responses.
@ -183,6 +179,11 @@ void xml_handle(WS_CONNINFO *pwsc) {
return; return;
} }
if(strcasecmp(method,"config") == 0) {
conf_xml_dump(pwsc);
return;
}
ws_returnerror(pwsc,500,"Invalid method"); ws_returnerror(pwsc,500,"Invalid method");
return; return;
} }

View File

@ -9,4 +9,14 @@
extern void xml_handle(WS_CONNINFO *pwsc); extern void xml_handle(WS_CONNINFO *pwsc);
struct tag_xmlstruct;
typedef struct tag_xmlstruct XMLSTRUCT;
extern XMLSTRUCT *xml_init(WS_CONNINFO *pwsc, int emit_header);
extern void xml_push(XMLSTRUCT *pxml, char *term);
extern void xml_pop(XMLSTRUCT *pxml);
extern void xml_output(XMLSTRUCT *pxml, char *section, char *fmt, ...);
extern void xml_deinit(XMLSTRUCT *pxml);
#endif /* _XMLRPC_H_ */ #endif /* _XMLRPC_H_ */