Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "sticker inc" and "sticker dec" commands (MPD 0.24) #138

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions include/mpd/sticker.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,70 @@ bool
mpd_run_sticker_set(struct mpd_connection *connection, const char *type,
const char *uri, const char *name, const char *value);

/**
* Adds or increments a sticker value.
*
* @param connection the connection to MPD
* @param type the object type, e.g. "song"
* @param uri the URI of the object
* @param name the name of the sticker
* @param value the unsigned value to set or increment
* @return true on success, false on error
*
* @since libmpdclient 2.23, MPD 0.24
*/
bool
mpd_send_sticker_inc(struct mpd_connection *connection, const char *type,
const char *uri, const char *name, unsigned value);

/**
* Shortcut for mpd_send_sticker_inc() and mpd_response_finish().
*
* @param connection the connection to MPD
* @param type the object type, e.g. "song"
* @param uri the URI of the object
* @param name the name of the sticker
* @param value the unsigned value to set or increment
* @return true on success, false on error
*
* @since libmpdclient 2.23, MPD 0.24
*/
bool
mpd_run_sticker_inc(struct mpd_connection *connection, const char *type,
const char *uri, const char *name, unsigned value);

/**
* Adds or decrements a sticker value.
*
* @param connection the connection to MPD
* @param type the object type, e.g. "song"
* @param uri the URI of the object
* @param name the name of the sticker
* @param value the unsigned value to set or increment
* @return true on success, false on error
*
* @since libmpdclient 2.23, MPD 0.24
*/
bool
mpd_send_sticker_dec(struct mpd_connection *connection, const char *type,
const char *uri, const char *name, unsigned value);

/**
* Shortcut for mpd_send_sticker_dec() and mpd_response_finish().
*
* @param connection the connection to MPD
* @param type the object type, e.g. "song"
* @param uri the URI of the object
* @param name the name of the sticker
* @param value the unsigned value to set or increment
* @return true on success, false on error
*
* @since libmpdclient 2.23, MPD 0.24
*/
bool
mpd_run_sticker_dec(struct mpd_connection *connection, const char *type,
const char *uri, const char *name, unsigned value);

/**
* Deletes a sticker value.
*
Expand Down
4 changes: 4 additions & 0 deletions libmpdclient.ld
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ global:
mpd_sticker_search_add_window;
mpd_sticker_search_commit;
mpd_sticker_search_cancel;
mpd_send_sticker_inc;
mpd_run_sticker_inc;
mpd_send_sticker_dec;
mpd_run_sticker_dec;

/* mpd/fingerprint.h */
mpd_parse_fingerprint_type;
Expand Down
5 changes: 5 additions & 0 deletions src/isend.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ bool
mpd_send_s_s_u_command(struct mpd_connection *connection, const char *command,
const char *arg1, const char *arg2, unsigned arg3);

bool
mpd_send_s_s_s_s_u_command(struct mpd_connection *connection, const char *command,
const char *arg1, const char *arg2, const char *arg3,
const char *arg4, unsigned arg5);

bool
mpd_send_range_command(struct mpd_connection *connection, const char *command,
unsigned arg1, unsigned arg2);
Expand Down
12 changes: 12 additions & 0 deletions src/send.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ mpd_send_s_s_u_command(struct mpd_connection *connection, const char *command,
arg1, arg2, arg3_string, NULL);
}

bool
mpd_send_s_s_s_s_u_command(struct mpd_connection *connection, const char *command,
const char *arg1, const char *arg2, const char *arg3,
const char *arg4, unsigned arg5)
{
char arg5_string[INTLEN];

snprintf(arg5_string, sizeof(arg5_string), "%u", arg5);
return mpd_send_command(connection, command,
arg1, arg2, arg3, arg4, arg5_string, NULL);
}

bool
mpd_send_range_command(struct mpd_connection *connection, const char *command,
unsigned arg1, unsigned arg2)
Expand Down
35 changes: 35 additions & 0 deletions src/sticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <mpd/pair.h>
#include <mpd/response.h>
#include "internal.h"
#include "isend.h"
#include "request.h"
#include "run.h"

Expand All @@ -33,6 +34,40 @@ mpd_run_sticker_set(struct mpd_connection *connection, const char *type,
mpd_response_finish(connection);
}

bool
mpd_send_sticker_inc(struct mpd_connection *connection, const char *type,
const char *uri, const char *name, unsigned value)
{
return mpd_send_s_s_s_s_u_command(connection, "sticker", "inc",
type, uri, name, value);
}

bool
mpd_run_sticker_inc(struct mpd_connection *connection, const char *type,
const char *uri, const char *name, unsigned value)
{
return mpd_run_check(connection) &&
mpd_send_sticker_inc(connection, type, uri, name, value) &&
mpd_response_finish(connection);
}

bool
mpd_send_sticker_dec(struct mpd_connection *connection, const char *type,
const char *uri, const char *name, unsigned value)
{
return mpd_send_s_s_s_s_u_command(connection, "sticker", "inc",
type, uri, name, value);
}

bool
mpd_run_sticker_dec(struct mpd_connection *connection, const char *type,
const char *uri, const char *name, unsigned value)
{
return mpd_run_check(connection) &&
mpd_send_sticker_dec(connection, type, uri, name, value) &&
mpd_response_finish(connection);
}

bool
mpd_send_sticker_delete(struct mpd_connection *connection, const char *type,
const char *uri, const char *name)
Expand Down
Loading