summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-10 11:11:14 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-10 11:11:14 +0200
commit941d4f27ef5337c5be5553f93e41aed7745c71e1 (patch)
tree21ab08f45c8e2bf600b2447aa1b7cc93991765da
parentc92cbed15b69d823637fb565fefeb6acc3ce178e (diff)
downloadpianobar-941d4f27ef5337c5be5553f93e41aed7745c71e1.tar.gz
pianobar-941d4f27ef5337c5be5553f93e41aed7745c71e1.tar.bz2
pianobar-941d4f27ef5337c5be5553f93e41aed7745c71e1.zip
Return success/error in PianoRateTrack
-rw-r--r--ChangeLog4
-rw-r--r--libpiano/main.c7
-rw-r--r--libpiano/piano.h6
-rw-r--r--libpiano/xml.c29
-rw-r--r--src/main.c18
5 files changed, 55 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index beca2c0..ff4073c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-06-10
+ * introduced love/ban error reporting
+ * fixed love/ban segfault
+
2008-06-09
* replaced calloc & strcpy by strdup in xml.c
* rating implemented
diff --git a/libpiano/main.c b/libpiano/main.c
index 0a14311..25fad38 100644
--- a/libpiano/main.c
+++ b/libpiano/main.c
@@ -218,10 +218,11 @@ void PianoGetPlaylist (PianoHandle_t *ph, char *stationId) {
free (requestStr);
}
-void PianoRateTrack (PianoHandle_t *ph, PianoStation_t *station,
+PianoReturn_t PianoRateTrack (PianoHandle_t *ph, PianoStation_t *station,
PianoSong_t *song, PianoSongRating_t rating) {
char xmlSendBuf[10000], url[PIANO_URL_BUFFER_SIZE];
char *requestStr, *retStr;
+ PianoReturn_t ret = PIANO_RET_ERR;
snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
"<methodCall><methodName>station.addFeedback</methodName>"
@@ -245,7 +246,9 @@ void PianoRateTrack (PianoHandle_t *ph, PianoStation_t *station,
song->matchingSeed, song->userSeed, song->focusTraitId,
(rating == PIANO_RATE_LOVE) ? "true" : "false");
PianoHttpPost (ph->curlHandle, url, requestStr, &retStr);
- /* FIXME: check answer (success = <?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value>1</value></param></params></methodResponse> ) */
+ ret = PianoXmlParseRate (retStr);
free (requestStr);
free (retStr);
+
+ return ret;
}
diff --git a/libpiano/piano.h b/libpiano/piano.h
index ac64cd1..5048dc0 100644
--- a/libpiano/piano.h
+++ b/libpiano/piano.h
@@ -115,6 +115,10 @@ struct PianoHandle {
typedef struct PianoHandle PianoHandle_t;
+/* FIXME: more error types (http failed, e.g.) later */
+enum PianoReturn {PIANO_RET_OK, PIANO_RET_ERR};
+typedef enum PianoReturn PianoReturn_t;
+
enum PianoSongRating {PIANO_RATE_BAN, PIANO_RATE_LOVE};
typedef enum PianoSongRating PianoSongRating_t;
@@ -126,7 +130,7 @@ void PianoConnect (PianoHandle_t *, char *, char *);
void PianoGetStations (PianoHandle_t *ph);
void PianoGetPlaylist (PianoHandle_t *ph, char *stationId);
-void PianoRateTrack (PianoHandle_t *ph, PianoStation_t *station,
+PianoReturn_t PianoRateTrack (PianoHandle_t *ph, PianoStation_t *station,
PianoSong_t *song, PianoSongRating_t rating);
#endif /* _PIANO_H */
diff --git a/libpiano/xml.c b/libpiano/xml.c
index 370d236..8881ac9 100644
--- a/libpiano/xml.c
+++ b/libpiano/xml.c
@@ -276,3 +276,32 @@ void PianoXmlParsePlaylist (PianoHandle_t *ph, char *xml) {
xmlFreeDoc (doc);
xmlCleanupParser();
}
+
+/* parse addFeedback answer
+ * @author PromyLOPh
+ * @added 2008-06-10
+ * @param xml string
+ * @return
+ */
+PianoReturn_t PianoXmlParseRate (char *xml) {
+ xmlNode *docRoot = NULL, *curNode = NULL;
+ xmlDocPtr doc = xmlReadDoc ((xmlChar *) xml, NULL, NULL, 0);
+ PianoReturn_t ret = PIANO_RET_ERR;
+
+ if (doc == NULL) {
+ printf ("whoops... xml parser error\n");
+ return;
+ }
+
+ docRoot = xmlDocGetRootElement (doc);
+
+ xmlNode *val = docRoot->children->children->children->children;
+ if (xmlStrEqual (val->content, (xmlChar *) "1")) {
+ ret = PIANO_RET_OK;
+ }
+
+ xmlFreeDoc (doc);
+ xmlCleanupParser();
+
+ return ret;
+}
diff --git a/src/main.c b/src/main.c
index 12aa8a3..e8c15c9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -283,17 +283,23 @@ int main (int argc, char **argv) {
case 'b':
player.doQuit = 1;
- PianoRateTrack (&ph, curStation, curSong,
- PIANO_RATE_BAN);
- printf ("Banned.\n");
+ if (PianoRateTrack (&ph, curStation, curSong,
+ PIANO_RATE_BAN) == PIANO_RET_OK) {
+ printf ("Banned.\n");
+ } else {
+ printf ("Error while banning track.\n");
+ }
/* pandora does this too, I think */
PianoDestroyPlaylist (&ph);
break;
case 'l':
- PianoRateTrack (&ph, curStation, curSong,
- PIANO_RATE_LOVE);
- printf ("Loved.\n");
+ if (PianoRateTrack (&ph, curStation, curSong,
+ PIANO_RATE_LOVE) == PIANO_RET_OK) {
+ printf ("Loved.\n");
+ } else {
+ printf ("Error while loving track.\n");
+ }
break;
case 'n':