summaryrefslogtreecommitdiff
path: root/libpiano
diff options
context:
space:
mode:
Diffstat (limited to 'libpiano')
-rw-r--r--libpiano/src/main.c38
-rw-r--r--libpiano/src/piano.h2
-rw-r--r--libpiano/src/xml.c25
-rw-r--r--libpiano/src/xml.h2
4 files changed, 67 insertions, 0 deletions
diff --git a/libpiano/src/main.c b/libpiano/src/main.c
index 99daee1..1d5a6d0 100644
--- a/libpiano/src/main.c
+++ b/libpiano/src/main.c
@@ -464,3 +464,41 @@ PianoReturn_t PianoCreateStation (PianoHandle_t *ph, char *musicId) {
return ret;
}
+
+/* FIXME: update station data instead of replacing them */
+/* add more music to existing station; multithreaded apps beware! this alters
+ * station data, don't forget to lock the station pointer you passed to this
+ * function
+ * @public yes
+ * @param piano handle
+ * @param add music to this station
+ * @param music id; can be obtained with PianoSearchMusic ()
+ */
+PianoReturn_t PianoStationAddMusic (PianoHandle_t *ph,
+ PianoStation_t *station, char *musicId) {
+ char xmlSendBuf[10000], url[PIANO_URL_BUFFER_SIZE];
+ char *requestStr, *retStr;
+ PianoReturn_t ret;
+
+ snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
+ "<methodCall><methodName>station.addSeed</methodName><params>"
+ "<param><value><int>%li</int></value></param>"
+ "<param><value><string>%s</string></value></param>"
+ "<param><value><string>%s</string></value></param>"
+ "<param><value><string>%s</string></value></param>"
+ "</params></methodCall>", time (NULL), ph->user.authToken,
+ station->id, musicId);
+ requestStr = PianoEncryptString (xmlSendBuf);
+
+ snprintf (url, sizeof (url), PIANO_RPC_URL "rid=%s&lid=%s"
+ "&method=addSeed&arg1=%s&arg2=%s", ph->routeId,
+ ph->user.listenerId, station->id, musicId);
+
+ PianoHttpPost (ph->curlHandle, url, requestStr, &retStr);
+ ret = PianoXmlParseAddSeed (ph, retStr, station);
+
+ free (requestStr);
+ free (retStr);
+
+ return ret;
+}
diff --git a/libpiano/src/piano.h b/libpiano/src/piano.h
index bd90c4c..f2b8f95 100644
--- a/libpiano/src/piano.h
+++ b/libpiano/src/piano.h
@@ -162,5 +162,7 @@ PianoReturn_t PianoDeleteStation (PianoHandle_t *ph, PianoStation_t *station);
PianoReturn_t PianoSearchMusic (PianoHandle_t *ph, char *searchStr,
PianoSearchResult_t *searchResult);
PianoReturn_t PianoCreateStation (PianoHandle_t *ph, char *musicId);
+PianoReturn_t PianoStationAddMusic (PianoHandle_t *ph,
+ PianoStation_t *station, char *musicId);
#endif /* _PIANO_H */
diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c
index 1267951..2d9e82d 100644
--- a/libpiano/src/xml.c
+++ b/libpiano/src/xml.c
@@ -348,6 +348,31 @@ PianoReturn_t PianoXmlParseCreateStation (PianoHandle_t *ph, char *xml) {
return PIANO_RET_OK;
}
+/* parse "add seed" answer, nearly the same as ParseCreateStation
+ * @param piano handle
+ * @param xml document
+ * @param update this station
+ */
+PianoReturn_t PianoXmlParseAddSeed (PianoHandle_t *ph, char *xml,
+ PianoStation_t *station) {
+ xmlNode *docRoot;
+ xmlDocPtr doc;
+ PianoReturn_t ret;
+
+ if ((ret = PianoXmlInitDoc (xml, &doc, &docRoot)) != PIANO_RET_OK) {
+ return ret;
+ }
+
+ /* get <struct> node */
+ xmlNode *dataRoot = docRoot->children->children->children->children;
+ PianoDestroyStation (station);
+ PianoXmlStructParser (dataRoot, PianoXmlParseStationsCb, station);
+
+ xmlFreeDoc (doc);
+
+ return PIANO_RET_OK;
+}
+
/* parses playlist; used when searching too
* @param piano handle
* @param xml document
diff --git a/libpiano/src/xml.h b/libpiano/src/xml.h
index 1165f12..ebc2df7 100644
--- a/libpiano/src/xml.h
+++ b/libpiano/src/xml.h
@@ -32,6 +32,8 @@ PianoReturn_t PianoXmlParseSearch (char *searchXml,
PianoSearchResult_t *searchResult);
PianoReturn_t PianoXmlParseSimple (char *xml);
PianoReturn_t PianoXmlParseCreateStation (PianoHandle_t *ph, char *xml);
+PianoReturn_t PianoXmlParseAddSeed (PianoHandle_t *ph, char *xml,
+ PianoStation_t *station);
char *PianoXmlEncodeString (const char *s);