From a711635a5a031107da3ecc0b0e1c939277e34572 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Wed, 2 Jul 2008 20:46:38 +0200 Subject: client: Initial quickmix station selection support --- libpiano/src/main.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'libpiano/src/main.c') diff --git a/libpiano/src/main.c b/libpiano/src/main.c index 29af6e0..d8d9498 100644 --- a/libpiano/src/main.c +++ b/libpiano/src/main.c @@ -596,3 +596,60 @@ PianoReturn_t PianoSongTired (PianoHandle_t *ph, PianoSong_t *song) { return ret; } + +/* set stations use by quickmix + * @param piano handle + * @return _OK or error + */ +PianoReturn_t PianoSetQuickmix (PianoHandle_t *ph) { + char xmlSendBuf[10000], valueBuf[1000], urlArgBuf[1000], + url[PIANO_URL_BUFFER_SIZE]; + char *requestStr, *retStr; + PianoReturn_t ret; + PianoStation_t *curStation = ph->stations; + + memset (urlArgBuf, 0, sizeof (urlArgBuf)); + snprintf (xmlSendBuf, sizeof (xmlSendBuf), "" + "station.setQuickMix" + "%li" + "%s" + "RANDOM" + "", time (NULL), ph->user.authToken); + while (curStation != NULL) { + /* quick mix can't contain itself */ + if (!curStation->useQuickMix || curStation->isQuickMix) { + curStation = curStation->next; + continue; + } + /* append to xml doc */ + snprintf (valueBuf, sizeof (valueBuf), + "%s", curStation->id); + strncat (xmlSendBuf, valueBuf, sizeof (xmlSendBuf) - + strlen (xmlSendBuf) - 1); + /* append to url arg */ + strncat (urlArgBuf, curStation->id, sizeof (urlArgBuf) - + strlen (urlArgBuf) - 1); + curStation = curStation->next; + /* if not last item: append "," */ + if (curStation != NULL) { + strncat (urlArgBuf, "%2C", sizeof (urlArgBuf) - + strlen (urlArgBuf) - 1); + } + } + strncat (xmlSendBuf, + "", + sizeof (xmlSendBuf) - strlen (xmlSendBuf) - 1); + requestStr = PianoEncryptString (xmlSendBuf); + + snprintf (url, sizeof (url), PIANO_RPC_URL "rid=%s&lid=%s&" + "method=setQuickMix&arg1=RANDOM&arg2=%s", ph->routeId, + ph->user.listenerId, urlArgBuf); + + PianoHttpPost (ph->curlHandle, url, requestStr, &retStr); + ret = PianoXmlParseSimple (retStr); + + PianoFree (retStr, 0); + PianoFree (requestStr, 0); + + return ret; +} -- cgit v1.2.3