summaryrefslogtreecommitdiff
path: root/libpiano
diff options
context:
space:
mode:
Diffstat (limited to 'libpiano')
-rw-r--r--libpiano/main.c7
-rw-r--r--libpiano/piano.h6
-rw-r--r--libpiano/xml.c29
3 files changed, 39 insertions, 3 deletions
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;
+}