~ubuntu-branches/ubuntu/wily/pianobar/wily-proposed

« back to all changes in this revision

Viewing changes to src/libpiano/piano.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Faraone
  • Date: 2011-07-09 10:03:03 UTC
  • mfrom: (1.3.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110709100303-m5heshhcrbrv3w3n
Tags: 2011.07.09-1
* New upstream version. 
  - XMLRPC api version bump (v31) (closes: #633345, LP: #807860)
* Update debian/watch for new location.
* Update symbols file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
Copyright (c) 2008-2010
 
2
Copyright (c) 2008-2011
3
3
        Lars-Dominik Braun <lars@6xq.net>
4
4
 
5
5
Permission is hereby granted, free of charge, to any person obtaining a copy
39
39
#include "crypt.h"
40
40
#include "config.h"
41
41
 
42
 
#define PIANO_PROTOCOL_VERSION "30"
 
42
#define PIANO_PROTOCOL_VERSION "31"
43
43
#define PIANO_RPC_HOST "www.pandora.com"
44
44
#define PIANO_RPC_PORT "80"
45
45
#define PIANO_RPC_PATH "/radio/xmlrpc/v" PIANO_PROTOCOL_VERSION "?"
57
57
                        (unsigned long) time (NULL) % 10000000);
58
58
}
59
59
 
60
 
/*      free complete search result
61
 
 *      @public yes
62
 
 *      @param search result
 
60
/*      destroy artist linked list
63
61
 */
64
 
void PianoDestroySearchResult (PianoSearchResult_t *searchResult) {
 
62
void PianoDestroyArtists (PianoArtist_t *artists) {
65
63
        PianoArtist_t *curArtist, *lastArtist;
66
 
        PianoSong_t *curSong, *lastSong;
67
64
 
68
 
        curArtist = searchResult->artists;
 
65
        curArtist = artists;
69
66
        while (curArtist != NULL) {
70
67
                free (curArtist->name);
71
68
                free (curArtist->musicId);
 
69
                free (curArtist->seedId);
72
70
                lastArtist = curArtist;
73
71
                curArtist = curArtist->next;
74
72
                free (lastArtist);
75
73
        }
 
74
}
76
75
 
77
 
        curSong = searchResult->songs;
78
 
        while (curSong != NULL) {
79
 
                free (curSong->title);
80
 
                free (curSong->artist);
81
 
                free (curSong->musicId);
82
 
                lastSong = curSong;
83
 
                curSong = curSong->next;
84
 
                free (lastSong);
85
 
        }
 
76
/*      free complete search result
 
77
 *      @public yes
 
78
 *      @param search result
 
79
 */
 
80
void PianoDestroySearchResult (PianoSearchResult_t *searchResult) {
 
81
        PianoDestroyArtists (searchResult->artists);
 
82
        PianoDestroyPlaylist (searchResult->songs);
86
83
}
87
84
 
88
85
/*      free single station
128
125
                free (curSong->stationId);
129
126
                free (curSong->album);
130
127
                free (curSong->artistMusicId);
 
128
                free (curSong->feedbackId);
 
129
                free (curSong->seedId);
 
130
                free (curSong->detailUrl);
131
131
                lastSong = curSong;
132
132
                curSong = curSong->next;
133
133
                free (lastSong);
134
134
        }
135
135
}
136
136
 
 
137
void PianoDestroyStationInfo (PianoStationInfo_t *info) {
 
138
        PianoDestroyPlaylist (info->feedback);
 
139
        PianoDestroyPlaylist (info->songSeeds);
 
140
        PianoDestroyArtists (info->artistSeeds);
 
141
}
 
142
 
137
143
/*      destroy genre linked list
138
144
 */
139
145
void PianoDestroyGenres (PianoGenre_t *genres) {
242
248
                                                        "rid=%s&method=sync", ph->routeId);
243
249
                                        break;
244
250
 
245
 
                                case 1:
 
251
                                case 1: {
 
252
                                        char *xmlencodedPassword = NULL;
 
253
 
 
254
                                        /* username == email address does not contain &,<,>," */
 
255
                                        if ((xmlencodedPassword =
 
256
                                                        PianoXmlEncodeString (logindata->password)) ==
 
257
                                                        NULL) {
 
258
                                                return PIANO_RET_OUT_OF_MEMORY;
 
259
                                        }
 
260
 
246
261
                                        snprintf (xmlSendBuf, sizeof (xmlSendBuf), 
247
262
                                                        "<?xml version=\"1.0\"?><methodCall>"
248
263
                                                        "<methodName>listener.authenticateListener</methodName>"
250
265
                                                        "<param><value><string>%s</string></value></param>"
251
266
                                                        "<param><value><string>%s</string></value></param>"
252
267
                                                        "</params></methodCall>", (unsigned long) timestamp,
253
 
                                                        logindata->user, logindata->password);
 
268
                                                        logindata->user, xmlencodedPassword);
254
269
                                        snprintf (req->urlPath, sizeof (req->urlPath), PIANO_RPC_PATH
255
270
                                                        "rid=%s&method=authenticateListener", ph->routeId);
 
271
 
 
272
                                        free (xmlencodedPassword);
256
273
                                        break;
 
274
                                }
257
275
                        }
258
276
                        break;
259
277
                }
458
476
                        snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
459
477
                                        "<methodCall><methodName>station.createStation</methodName>"
460
478
                                        "<params><param><value><int>%lu</int></value></param>"
 
479
                                        /* auth token */
461
480
                                        "<param><value><string>%s</string></value></param>"
 
481
                                        /* music id */
462
482
                                        "<param><value><string>%s%s</string></value></param>"
 
483
                                        /* empty */
 
484
                                        "<param><value><string></string></value></param>"
463
485
                                        "</params></methodCall>", (unsigned long) timestamp,
464
486
                                        ph->user.authToken, reqData->type, reqData->id);
465
487
 
466
488
                        snprintf (req->urlPath, sizeof (req->urlPath), PIANO_RPC_PATH
467
 
                                        "rid=%s&lid=%s&method=createStation&arg1=%s%s", ph->routeId,
 
489
                                        "rid=%s&lid=%s&method=createStation&arg1=%s%s&arg2=", ph->routeId,
468
490
                                        ph->user.listenerId, reqData->type, reqData->id);
469
491
                        break;
470
492
                }
480
502
                        snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
481
503
                                        "<methodCall><methodName>station.addSeed</methodName><params>"
482
504
                                        "<param><value><int>%lu</int></value></param>"
483
 
                                        "<param><value><string>%s</string></value></param>"
484
 
                                        "<param><value><string>%s</string></value></param>"
 
505
                                        /* auth token */
 
506
                                        "<param><value><string>%s</string></value></param>"
 
507
                                        /* station id */
 
508
                                        "<param><value><string>%s</string></value></param>"
 
509
                                        /* music id */
485
510
                                        "<param><value><string>%s</string></value></param>"
486
511
                                        "</params></methodCall>", (unsigned long) timestamp,
487
512
                                        ph->user.authToken, reqData->station->id, reqData->musicId);
696
721
                        break;
697
722
                }
698
723
 
 
724
                case PIANO_REQUEST_GET_STATION_INFO: {
 
725
                        /* get station information (seeds and feedback) */
 
726
                        PianoRequestDataGetStationInfo_t *reqData = req->data;
 
727
 
 
728
                        assert (reqData != NULL);
 
729
                        assert (reqData->station != NULL);
 
730
 
 
731
                        snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
 
732
                                        "<methodCall><methodName>station.getStation</methodName>"
 
733
                                        "<params><param><value><int>%lu</int></value></param>"
 
734
                                        /* auth token */
 
735
                                        "<param><value><string>%s</string></value></param>"
 
736
                                        /* station id */
 
737
                                        "<param><value><string>%s</string></value></param>"
 
738
                                        "</params></methodCall>", (unsigned long) timestamp,
 
739
                                        ph->user.authToken, reqData->station->id);
 
740
                        snprintf (req->urlPath, sizeof (req->urlPath), PIANO_RPC_PATH
 
741
                                        "rid=%s&lid=%s&method=getStation&arg1=%s",
 
742
                                        ph->routeId, ph->user.listenerId, reqData->station->id);
 
743
                        break;
 
744
                }
 
745
 
 
746
                case PIANO_REQUEST_DELETE_FEEDBACK: {
 
747
                        PianoSong_t *song = req->data;
 
748
 
 
749
                        assert (song != NULL);
 
750
 
 
751
                        snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
 
752
                                        "<methodCall><methodName>station.deleteFeedback</methodName>"
 
753
                                        "<params><param><value><int>%lu</int></value></param>"
 
754
                                        /* auth token */
 
755
                                        "<param><value><string>%s</string></value></param>"
 
756
                                        /* feedback id */
 
757
                                        "<param><value><string>%s</string></value></param>"
 
758
                                        "</params></methodCall>", (unsigned long) timestamp,
 
759
                                        ph->user.authToken, song->feedbackId);
 
760
                        snprintf (req->urlPath, sizeof (req->urlPath), PIANO_RPC_PATH
 
761
                                        "rid=%s&lid=%s&method=deleteFeedback&arg1=%s",
 
762
                                        ph->routeId, ph->user.listenerId, song->feedbackId);
 
763
                        break;
 
764
                }
 
765
 
 
766
                case PIANO_REQUEST_DELETE_SEED: {
 
767
                        PianoRequestDataDeleteSeed_t *reqData = req->data;
 
768
                        char *seedId = NULL;
 
769
 
 
770
                        assert (reqData != NULL);
 
771
                        assert (reqData->song != NULL || reqData->artist != NULL);
 
772
 
 
773
                        if (reqData->song != NULL) {
 
774
                                seedId = reqData->song->seedId;
 
775
                        } else if (reqData->artist != NULL) {
 
776
                                seedId = reqData->artist->seedId;
 
777
                        }
 
778
 
 
779
                        assert (seedId != NULL);
 
780
 
 
781
                        snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
 
782
                                        "<methodCall><methodName>station.deleteSeed</methodName>"
 
783
                                        "<params><param><value><int>%lu</int></value></param>"
 
784
                                        /* auth token */
 
785
                                        "<param><value><string>%s</string></value></param>"
 
786
                                        /* seed id */
 
787
                                        "<param><value><string>%s</string></value></param>"
 
788
                                        "</params></methodCall>", (unsigned long) timestamp,
 
789
                                        ph->user.authToken, seedId);
 
790
                        snprintf (req->urlPath, sizeof (req->urlPath), PIANO_RPC_PATH
 
791
                                        "rid=%s&lid=%s&method=deleteSeed&arg1=%s",
 
792
                                        ph->routeId, ph->user.listenerId, seedId);
 
793
                        break;
 
794
                }
 
795
 
699
796
                /* "high-level" wrapper */
700
797
                case PIANO_REQUEST_RATE_SONG: {
701
798
                        /* love/ban song */
967
1064
                case PIANO_REQUEST_SET_QUICKMIX:
968
1065
                case PIANO_REQUEST_BOOKMARK_SONG:
969
1066
                case PIANO_REQUEST_BOOKMARK_ARTIST:
 
1067
                case PIANO_REQUEST_DELETE_FEEDBACK:
970
1068
                        assert (req->responseData != NULL);
971
1069
 
972
1070
                        ret = PianoXmlParseSimple (req->responseData);
1017
1115
                                        &reqData->searchResult);
1018
1116
                        break;
1019
1117
                }
 
1118
 
 
1119
                case PIANO_REQUEST_GET_STATION_INFO: {
 
1120
                        /* get station information (seeds and feedback) */
 
1121
                        PianoRequestDataGetStationInfo_t *reqData = req->data;
 
1122
 
 
1123
                        assert (req->responseData != NULL);
 
1124
                        assert (reqData != NULL);
 
1125
 
 
1126
                        ret = PianoXmlParseGetStationInfo (req->responseData,
 
1127
                                        &reqData->info);
 
1128
                        break;
 
1129
                }
 
1130
 
 
1131
                case PIANO_REQUEST_DELETE_SEED: {
 
1132
                        assert (req->responseData != NULL);
 
1133
 
 
1134
                        /* dummy function, checks for errors only */
 
1135
                        ret = PianoXmlParseTranformStation (req->responseData);
 
1136
                }
1020
1137
        }
1021
1138
 
1022
1139
        return ret;
1106
1223
                        return "Quickmix not playable.";
1107
1224
                        break;
1108
1225
 
 
1226
                case PIANO_RET_REMOVING_TOO_MANY_SEEDS:
 
1227
                        return "Last seed cannot be removed.";
 
1228
                        break;
 
1229
 
1109
1230
                default:
1110
1231
                        return "No error message available.";
1111
1232
                        break;