From 0aadff5e5adebac59854642aeaecfc9970fe194d Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Sun, 24 Apr 2005 00:48:47 +0000 Subject: [PATCH] add daap URIs for delete playlist and delete playlist items --- src/db-generic.c | 2 ++ src/dispatch.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/db-generic.c b/src/db-generic.c index cef8e979..4bd55179 100644 --- a/src/db-generic.c +++ b/src/db-generic.c @@ -199,6 +199,8 @@ DAAP_ITEMS taglist[] = { { 0x01, "MPTY", "org.mt-daapd.playlist-type" }, { 0x0C, "MAPR", "org.mt-daapd.addplaylist" }, { 0x0C, "MAPI", "org.mt-daapd.addplaylistitem" }, + { 0x0C, "MDPR", "org.mt-daapd.delplaylist" }, + { 0x0C, "MDPI", "org.mt-daapd.delplaylistitem" }, { 0x00, NULL, NULL } }; diff --git a/src/dispatch.c b/src/dispatch.c index 0ba07f34..755d2da4 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -55,6 +55,8 @@ static void dispatch_browse(WS_CONNINFO *pwsc, DBQUERYINFO *pqi); static void dispatch_playlists(WS_CONNINFO *pqsc, DBQUERYINFO *pqi); static void dispatch_addplaylist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi); static void dispatch_addplaylistitems(WS_CONNINFO *pwsc, DBQUERYINFO *pqi); +static void dispatch_deleteplaylist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi); +static void dispatch_deleteplaylistitems(WS_CONNINFO *pwsc, DBQUERYINFO *pqi); static void dispatch_items(WS_CONNINFO *pwsc, DBQUERYINFO *pqi); static void dispatch_logout(WS_CONNINFO *pwsc, DBQUERYINFO *pqi); @@ -203,7 +205,11 @@ void daap_handler(WS_CONNINFO *pwsc) { (!strcasecmp(pqi->uri_sections[3],"add"))) /* /databases/id/containers/add */ return dispatch_addplaylist(pwsc,pqi); - + if((!strcasecmp(pqi->uri_sections[2],"containers")) && + (!strcasecmp(pqi->uri_sections[3],"del"))) + /* /databases/id/containers/del */ + return dispatch_deleteplaylist(pwsc,pqi); + pwsc->close=1; free(pqi); ws_returnerror(pwsc,404,"Page not found"); @@ -215,6 +221,12 @@ void daap_handler(WS_CONNINFO *pwsc) { pqi->playlist_id=atoi(pqi->uri_sections[3]); return dispatch_playlistitems(pwsc,pqi); } + if((!strcasecmp(pqi->uri_sections[2],"containers")) && + (!strcasecmp(pqi->uri_sections[4],"del"))) { + /* /databases/id/containers/id/del */ + pqi->playlist_id=atoi(pqi->uri_sections[3]); + return dispatch_deleteplaylistitems(pwsc,pqi); + } } if(pqi->uri_count == 6) { if((!strcasecmp(pqi->uri_sections[2],"containers")) && @@ -814,6 +826,75 @@ void dispatch_addplaylistitems(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) { return; } +/** + * delete a playlist + */ +void dispatch_deleteplaylist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) { + char playlist_response[20]; + char *current; + + if(!ws_getvar(pwsc,"dmap.itemid")) { + DPRINTF(E_LOG,L_DAAP,"attempt to delete playlist with no dmap.itemid\n"); + ws_returnerror(pwsc,500,"no itemid specified"); + return; + } + + db_delete_playlist(atoi(ws_getvar(pwsc,"dmap.itemid"))); + + /* success(ish)... spool out a dmap block */ + current = playlist_response; + current += db_dmap_add_container(current,"MDPR",12); + current += db_dmap_add_int(current,"mstt",200); /* 12 */ + + dispatch_output_start(pwsc,pqi,20); + dispatch_output_write(pwsc,pqi,playlist_response,20); + dispatch_output_end(pwsc,pqi); + + pwsc->close=1; + + return; +} + +/** + * delete a playlist item + */ +void dispatch_deleteplaylistitems(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) { + char playlist_response[20]; + char *current; + char *tempstring; + char *token; + + if(!ws_getvar(pwsc,"dmap.itemid")) { + DPRINTF(E_LOG,L_DAAP,"attempt to delete playlist items with no dmap.itemid\n"); + ws_returnerror(pwsc,500,"no itemid specified"); + return; + } + + tempstring=strdup(ws_getvar(pwsc,"dmap.itemid")); + current=tempstring; + + while((token=strsep(¤t,","))) { + if(token) { + db_delete_playlist_item(pqi->playlist_id,atoi(token)); + } + } + + free(tempstring); + + /* success(ish)... spool out a dmap block */ + current = playlist_response; + current += db_dmap_add_container(current,"MDPI",12); + current += db_dmap_add_int(current,"mstt",200); /* 12 */ + + dispatch_output_start(pwsc,pqi,20); + dispatch_output_write(pwsc,pqi,playlist_response,20); + dispatch_output_end(pwsc,pqi); + + pwsc->close=1; + + return; +} + /** * add a playlist */