Initialize url_handlers
[libmpd.git] / src / libmpd-sticker.c
blob852e5be4c27ed8faa64fe7d58a12266e4a74f63e
1 #include <stdio.h>
2 #include <stdlib.h>
3 #define __USE_GNU
4 #include <glib.h>
5 #include <string.h>
6 #include <stdarg.h>
7 #include <config.h>
8 #include "debug_printf.h"
9 #include "libmpd.h"
10 #include "libmpd-internal.h"
13 int mpd_sticker_supported ( MpdObj *mi)
15 if(mi == NULL) return FALSE;
17 if(mpd_server_check_command_allowed(mi, "sticker") == MPD_SERVER_COMMAND_ALLOWED) {
18 return TRUE;
21 return FALSE;
24 char * mpd_sticker_song_get(MpdObj *mi, const char *path, const char *tag)
26 char *retv_value = NULL;
27 char *retv = NULL;
28 if(!mpd_check_connected(mi))
30 debug_printf(DEBUG_INFO,"not connected\n");
31 return NULL;
33 if(mpd_server_check_command_allowed(mi, "sticker") != MPD_SERVER_COMMAND_ALLOWED) {
34 debug_printf(DEBUG_WARNING, "Command not allowed\n");
35 return NULL;
37 if(mpd_lock_conn(mi))
39 debug_printf(DEBUG_ERROR,"lock failed\n");
40 return NULL;
43 mpd_sendGetSongSticker(mi->connection,path, tag);
44 retv_value = mpd_getNextSticker(mi->connection);
45 mpd_finishCommand(mi->connection);
46 if(retv_value && strlen(retv_value) > strlen(tag)){
47 retv = g_strdup(&retv_value[strlen(tag)]+1);
49 free(retv_value);
50 if(mi->connection->error == MPD_ERROR_ACK && mi->connection->errorCode == MPD_ACK_ERROR_NO_EXIST)
52 mpd_clearError(mi->connection);
53 free(retv);
54 retv = NULL;
56 if(mpd_unlock_conn(mi))
58 debug_printf(DEBUG_ERROR, "Failed to unlock");
59 g_free(retv);
60 return NULL;
62 return retv;
65 int mpd_sticker_song_set(MpdObj *mi, const char *path, const char *tag, const char *value)
67 if(!mpd_check_connected(mi))
69 debug_printf(DEBUG_INFO,"not connected\n");
70 return MPD_NOT_CONNECTED;
72 if(mpd_server_check_command_allowed(mi, "sticker") != MPD_SERVER_COMMAND_ALLOWED) {
73 debug_printf(DEBUG_WARNING, "Command not allowed\n");
74 return MPD_SERVER_NOT_SUPPORTED;
76 if(mpd_lock_conn(mi))
78 debug_printf(DEBUG_ERROR,"lock failed\n");
79 return MPD_LOCK_FAILED;
82 mpd_sendSetSongSticker(mi->connection,path, tag,value);
83 mpd_finishCommand(mi->connection);
84 if(mpd_unlock_conn(mi))
86 debug_printf(DEBUG_ERROR, "Failed to unlock");
87 return MPD_LOCK_FAILED;
89 return MPD_OK;