Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support for playlist destroy

  • Loading branch information...
commit de0dec5131cff0690eb75be26735b0f650bf6091 1 parent e86a624
@aurels aurels authored
Showing with 41 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +2 −0  README.md
  3. +38 −0 server.c
View
1  .gitignore
@@ -3,3 +3,4 @@
appkey.c
account.c
server
+spotify_appkey.key
View
2  README.md
@@ -29,6 +29,8 @@ and GPL.
POST /playlist/{uri}/collaborative?enabled=<boolean> -> <playlist>
POST /playlist/{uri}/patch <- [<track URI>] -> <playlist>
+ DELETE /playlist/{uri}/delete -> <playlist>
+
`patch` replaces all tracks in a playlist with as few `add`s and `remove`s as
possible by first performing a *diff* between the playlist and the new
View
38 server.c
@@ -440,6 +440,35 @@ static void put_playlist(sp_playlist *playlist,
}
}
+static void delete_playlist(sp_playlist *playlist,
+ struct evhttp_request *request,
+ void *userdata) {
+
+ struct state *state = userdata;
+ sp_session *session = state->session;
+ sp_playlistcontainer *pc = sp_session_playlistcontainer(session);
+
+ for(int i=1; i<sp_playlistcontainer_num_playlists(pc); i++){
+ if(sp_playlistcontainer_playlist(pc, i) == playlist){
+ if (playlist == NULL) {
+ send_error(request, HTTP_ERROR, "Unable to delete unexisting playlist");
+ } else {
+ struct playlist_handler *handler = register_playlist_callbacks(
+ playlist, request, &get_playlist,
+ &playlist_update_in_progress_callbacks, NULL);
+
+ sp_error remove_playlist_error = sp_playlistcontainer_remove_playlist(pc, i);
+
+ if (remove_playlist_error != SP_ERROR_OK) {
+ sp_playlist_remove_callbacks(playlist, handler->playlist_callbacks, handler);
+ free(handler);
+ send_error_sp(request, HTTP_BADREQUEST, remove_playlist_error);
+ }
+ }
+ }
+ }
+}
+
static void put_playlist_add_tracks(sp_playlist *playlist,
struct evhttp_request *request,
void *userdata) {
@@ -676,6 +705,7 @@ static void handle_user_request(struct evhttp_request *request,
char *action,
const char *canonical_username,
sp_session *session) {
+
if (action == NULL) {
evhttp_send_error(request, HTTP_BADREQUEST, "Bad Request");
return;
@@ -738,6 +768,7 @@ static void handle_request(struct evhttp_request *request,
case EVHTTP_REQ_GET:
case EVHTTP_REQ_PUT:
case EVHTTP_REQ_POST:
+ case EVHTTP_REQ_DELETE:
break;
default:
@@ -858,6 +889,13 @@ static void handle_request(struct evhttp_request *request,
}
}
break;
+
+ case EVHTTP_REQ_DELETE:
+ {
+ callback_userdata = state;
+ request_callback = &delete_playlist;
+ }
+ break;
}
if (sp_playlist_is_loaded(playlist)) {
Please sign in to comment.
Something went wrong with that request. Please try again.