diff options
| author | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-06-13 20:19:09 +0200 | 
|---|---|---|
| committer | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-06-13 20:19:09 +0200 | 
| commit | 481f0cdcd0fb33a35865dd8ab30aae6c74f84f20 (patch) | |
| tree | 6c7535875641e8f1318dc9673957b5d88fbcd389 /libpiano | |
| parent | 1b9e47b5a5be84b018c17d9ed869ee58b7ff196e (diff) | |
| download | pianobar-481f0cdcd0fb33a35865dd8ab30aae6c74f84f20.tar.gz pianobar-481f0cdcd0fb33a35865dd8ab30aae6c74f84f20.tar.bz2 pianobar-481f0cdcd0fb33a35865dd8ab30aae6c74f84f20.zip | |
lib: Generic xml document init
Diffstat (limited to 'libpiano')
| -rw-r--r-- | libpiano/xml.c | 59 | 
1 files changed, 28 insertions, 31 deletions
| diff --git a/libpiano/xml.c b/libpiano/xml.c index a113a12..048f792 100644 --- a/libpiano/xml.c +++ b/libpiano/xml.c @@ -79,6 +79,19 @@ void PianoXmlStructParser (xmlNode *structRoot,  	}  } +PianoReturn_t PianoXmlInitDoc (char *xml, xmlDocPtr *doc, xmlNode **docRoot) { +	*doc = xmlReadDoc ((xmlChar *) xml, NULL, NULL, 0); + +	if (*doc == NULL) { +		printf ("libpandora: error while parsing this xml document\n%s\n", xml); +		return PIANO_RET_ERR; +	} + +	*docRoot = xmlDocGetRootElement (*doc); + +	return PIANO_RET_OK; +} +  /*	get text from <value> nodes; some of them have <boolean>, <string>   *	or <int> subnodes, just ignore them   *	@author PromyLOPh @@ -178,16 +191,13 @@ void PianoXmlParsePlaylistCb (char *key, xmlNode *value, void *data) {   *	@return nothing   */  void PianoXmlParseUserinfo (PianoHandle_t *ph, char *xml) { -	xmlNode *docRoot = NULL; -	xmlDocPtr doc = xmlReadDoc ((xmlChar *) xml, NULL, NULL, 0); +	xmlNode *docRoot; +	xmlDocPtr doc; -	if (doc == NULL) { -		printf ("whoops... xml parser error\n"); +	if (PianoXmlInitDoc (xml, &doc, &docRoot) != PIANO_RET_OK) {  		return;  	} -	docRoot = xmlDocGetRootElement (doc); -  	/* <methodResponse> <params> <param> <value> <struct> */  	xmlNode *structRoot = docRoot->children->children->children->children;  	PianoXmlStructParser (structRoot, PianoXmlParseUserinfoCb, &ph->user); @@ -205,16 +215,13 @@ void PianoXmlParseUserinfo (PianoHandle_t *ph, char *xml) {   */  void PianoXmlParseStations (PianoHandle_t *ph, char *xml) {  	/* FIXME: copy & waste */ -	xmlNode *docRoot = NULL, *curNode = NULL; -	xmlDocPtr doc = xmlReadDoc ((xmlChar *) xml, NULL, NULL, 0); +	xmlNode *docRoot, *curNode; +	xmlDocPtr doc; -	if (doc == NULL) { -		printf ("whoops... xml parser error\n"); +	if (PianoXmlInitDoc (xml, &doc, &docRoot) != PIANO_RET_OK) {  		return;  	} -	docRoot = xmlDocGetRootElement (doc); -  	/* <methodResponse> <params> <param> <value> <array> <data> */  	xmlNode *dataRoot = docRoot->children->children->children->children->children;      for (curNode = dataRoot->children; curNode; curNode = curNode->next) { @@ -248,16 +255,13 @@ void PianoXmlParseStations (PianoHandle_t *ph, char *xml) {   */  void PianoXmlParsePlaylist (PianoHandle_t *ph, char *xml) {  	/* FIXME: copy & waste */ -	xmlNode *docRoot = NULL, *curNode = NULL; -	xmlDocPtr doc = xmlReadDoc ((xmlChar *) xml, NULL, NULL, 0); +	xmlNode *docRoot, *curNode; +	xmlDocPtr doc; -	if (doc == NULL) { -		printf ("whoops... xml parser error\n"); +	if (PianoXmlInitDoc (xml, &doc, &docRoot) != PIANO_RET_OK) {  		return;  	} -	docRoot = xmlDocGetRootElement (doc); -  	/* <methodResponse> <params> <param> <value> <array> <data> */  	xmlNode *dataRoot = docRoot->children->children->children->children->children;      for (curNode = dataRoot->children; curNode; curNode = curNode->next) { @@ -292,17 +296,14 @@ void PianoXmlParsePlaylist (PianoHandle_t *ph, char *xml) {   *	@return   */  PianoReturn_t PianoXmlParseSimple (char *xml) { -	xmlNode *docRoot = NULL, *curNode = NULL; -	xmlDocPtr doc = xmlReadDoc ((xmlChar *) xml, NULL, NULL, 0); +	xmlNode *docRoot; +	xmlDocPtr doc;  	PianoReturn_t ret = PIANO_RET_ERR; -	if (doc == NULL) { -		printf ("whoops... xml parser error\n"); +	if (PianoXmlInitDoc (xml, &doc, &docRoot) != PIANO_RET_OK) {  		return PIANO_RET_ERR;  	} -	docRoot = xmlDocGetRootElement (doc); -  	xmlNode *val = docRoot->children->children->children->children;  	if (xmlStrEqual (val->content, (xmlChar *) "1")) {  		ret = PIANO_RET_OK; @@ -399,16 +400,12 @@ void PianoXmlParseSearchCb (char *key, xmlNode *value, void *data) {   */  void PianoXmlParseSearch (char *searchXml,  		PianoSearchResult_t *searchResult) { -	/* FIXME: copy & waste */ -	xmlNode *docRoot = NULL, *curNode = NULL; -	xmlDocPtr doc = xmlReadDoc ((xmlChar *) searchXml, NULL, NULL, 0); +	xmlNode *docRoot, *curNode; +	xmlDocPtr doc; -	if (doc == NULL) { -		printf ("whoops... xml parser error\n"); +	if (PianoXmlInitDoc (searchXml, &doc, &docRoot) != PIANO_RET_OK) {  		return;  	} - -	docRoot = xmlDocGetRootElement (doc);  	xmlNode *structRoot = docRoot->children->children->children->children;  	/* we need a "clean" search result (with null pointers) */ | 
