summaryrefslogtreecommitdiff
path: root/libpiano
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-14 16:08:35 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-14 16:08:35 +0200
commite22869ebdd98ecc3f870cb1d6c5c31fd1b5d61ee (patch)
treeb2e54f4e5c95f73fa96f88a624dd358a5477cd0f /libpiano
parentb1ea463843add37874f9768b606825504cdc8eb2 (diff)
downloadpianobar-e22869ebdd98ecc3f870cb1d6c5c31fd1b5d61ee.tar.gz
pianobar-e22869ebdd98ecc3f870cb1d6c5c31fd1b5d61ee.tar.bz2
pianobar-e22869ebdd98ecc3f870cb1d6c5c31fd1b5d61ee.zip
Finally implemented "create station"
This may be a bit buggy, because no return values are checked or returned. A big cleanup session is waiting...
Diffstat (limited to 'libpiano')
-rw-r--r--libpiano/main.c33
-rw-r--r--libpiano/piano.h3
-rw-r--r--libpiano/xml.c28
-rw-r--r--libpiano/xml.h1
4 files changed, 65 insertions, 0 deletions
diff --git a/libpiano/main.c b/libpiano/main.c
index cc4e65a..9754e73 100644
--- a/libpiano/main.c
+++ b/libpiano/main.c
@@ -456,3 +456,36 @@ void PianoSearchMusic (PianoHandle_t *ph, char *searchStr,
free (retStr);
free (requestStr);
}
+
+/* create new station on server
+ * @author PromyLOPh
+ * @added 2008-06-14
+ * @public yes
+ * @param piano handle
+ * @param music id from artist or track, you may obtain one by calling
+ * PianoSearchMusic
+ * @return nothing, yet
+ */
+void PianoCreateStation (PianoHandle_t *ph, char *musicId) {
+ char xmlSendBuf[10000], url[PIANO_URL_BUFFER_SIZE];
+ char *requestStr, *retStr;
+
+ snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
+ "<methodCall><methodName>station.createStation</methodName>"
+ "<params><param><value><int>%li</int></value></param>"
+ "<param><value><string>%s</string></value></param>"
+ "<param><value><string>mi%s</string></value></param>"
+ "</params></methodCall>", time (NULL), ph->user.authToken,
+ musicId);
+ requestStr = PianoEncryptString (xmlSendBuf);
+
+ snprintf (url, sizeof (url), PIANO_RPC_URL "rid=%s&lid=%s"
+ "&method=createStation&arg1=mi%s", ph->routeId,
+ ph->user.listenerId, musicId);
+
+ PianoHttpPost (ph->curlHandle, url, requestStr, &retStr);
+ PianoXmlParseCreateStation (ph, retStr);
+
+ free (requestStr);
+ free (retStr);
+}
diff --git a/libpiano/piano.h b/libpiano/piano.h
index 9f2f7d7..0bffce5 100644
--- a/libpiano/piano.h
+++ b/libpiano/piano.h
@@ -157,5 +157,8 @@ PianoReturn_t PianoRateTrack (PianoHandle_t *ph, PianoStation_t *station,
PianoReturn_t PianoRenameStation (PianoHandle_t *ph, PianoStation_t *station,
char *newName);
PianoReturn_t PianoDeleteStation (PianoHandle_t *ph, PianoStation_t *station);
+void PianoSearchMusic (PianoHandle_t *ph, char *searchStr,
+ PianoSearchResult_t *searchResult);
+void PianoCreateStation (PianoHandle_t *ph, char *musicId);
#endif /* _PIANO_H */
diff --git a/libpiano/xml.c b/libpiano/xml.c
index 6f8cb55..5ac8d97 100644
--- a/libpiano/xml.c
+++ b/libpiano/xml.c
@@ -245,6 +245,34 @@ void PianoXmlParseStations (PianoHandle_t *ph, char *xml) {
xmlFreeDoc (doc);
}
+void PianoXmlParseCreateStation (PianoHandle_t *ph, char *xml) {
+ xmlNode *docRoot;
+ xmlDocPtr doc;
+ PianoStation_t *tmpStation;
+
+ if (PianoXmlInitDoc (xml, &doc, &docRoot) != PIANO_RET_OK) {
+ return;
+ }
+
+ /* get <struct> node */
+ xmlNode *dataRoot = docRoot->children->children->children->children;
+ tmpStation = calloc (1, sizeof (*tmpStation));
+ PianoXmlStructParser (dataRoot, PianoXmlParseStationsCb, tmpStation);
+ /* FIXME: copy & waste */
+ /* start new linked list or append */
+ if (ph->stations == NULL) {
+ ph->stations = tmpStation;
+ } else {
+ PianoStation_t *curStation = ph->stations;
+ while (curStation->next != NULL) {
+ curStation = curStation->next;
+ }
+ curStation->next = tmpStation;
+ }
+
+ xmlFreeDoc (doc);
+}
+
/* parses playlist; used when searching too
* @author PromyLOPh
* @added 2008-06-12
diff --git a/libpiano/xml.h b/libpiano/xml.h
index 140d0ff..f8c9106 100644
--- a/libpiano/xml.h
+++ b/libpiano/xml.h
@@ -29,6 +29,7 @@ void PianoXmlParsePlaylist (PianoHandle_t *ph, char *xml);
void PianoXmlParseSearch (char *searchXml,
PianoSearchResult_t *searchResult);
PianoReturn_t PianoXmlParseSimple (char *xml);
+void PianoXmlParseCreateStation (PianoHandle_t *ph, char *xml);
char *PianoXmlEncodeString (const char *s);