[misc] Change name of string_printf to safe_asprintf

This commit is contained in:
ejurgensen 2017-05-05 20:00:51 +02:00
parent dcf75f59eb
commit 1aa8072e68
4 changed files with 150 additions and 147 deletions

View File

@ -287,6 +287,27 @@ safe_strdup(const char *str)
return strdup(str); return strdup(str);
} }
/*
* Wrapper function for vasprintf by Intel Corporation
* Published under the L-GPL 2.1 licence as part of clr-boot-manager
*
* https://github.com/clearlinux/clr-boot-manager
*/
char *
safe_asprintf(const char *fmt, ...)
{
char *ret = NULL;
va_list va;
va_start(va, fmt);
if (vasprintf(&ret, fmt, va) < 0)
{
DPRINTF(E_FATAL, L_MISC, "Out of memory for safe_asprintf\n");
abort();
}
va_end(va);
return ret;
}
/* Key/value functions */ /* Key/value functions */
struct keyval * struct keyval *
@ -1134,24 +1155,4 @@ log_fatal_null(int domain, const char *func, int line)
abort(); abort();
} }
/*
* Wrapper function for vasprintf by Intel Corporation
* Published under the L-GPL 2.1 licence as part of clr-boot-manager
*
* https://github.com/clearlinux/clr-boot-manager
*/
char *string_printf(const char *fmt, ...)
{
char *ret = NULL;
va_list va;
va_start(va, fmt);
if (vasprintf(&ret, fmt, va) < 0)
{
DPRINTF(E_FATAL, L_MISC, "Out of memory for string_printf\n");
abort();
}
va_end(va);
return ret;
}

View File

@ -50,6 +50,10 @@ safe_hextou64(const char *str, uint64_t *val);
char * char *
safe_strdup(const char *str); safe_strdup(const char *str);
char *
safe_asprintf(const char *fmt, ...);
/* Key/value functions */ /* Key/value functions */
struct keyval * struct keyval *
keyval_alloc(void); keyval_alloc(void);
@ -201,6 +205,4 @@ log_fatal_errno(int domain, const char *func, int line) __attribute__((__
void void
log_fatal_null(int domain, const char *func, int line) __attribute__((__noreturn__)); log_fatal_null(int domain, const char *func, int line) __attribute__((__noreturn__));
char *string_printf(const char *fmt, ...);
#endif /* !__MISC_H__ */ #endif /* !__MISC_H__ */

246
src/mpd.c
View File

@ -537,7 +537,7 @@ mpd_command_currentsong(struct evbuffer *evbuf, int argc, char **argv, char **er
queue_item = db_queue_fetch_byitemid(status.item_id); queue_item = db_queue_fetch_byitemid(status.item_id);
if (!queue_item) if (!queue_item)
{ {
*errmsg = string_printf("Error adding queue item info for file with id: %d", status.item_id); *errmsg = safe_asprintf("Error adding queue item info for file with id: %d", status.item_id);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -547,7 +547,7 @@ mpd_command_currentsong(struct evbuffer *evbuf, int argc, char **argv, char **er
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Error adding media info for file with id: %d", status.id); *errmsg = safe_asprintf("Error adding media info for file with id: %d", status.id);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -785,7 +785,7 @@ mpd_command_stats(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
{ {
db_query_end(&qp); db_query_end(&qp);
*errmsg = string_printf("Could not start query"); *errmsg = safe_asprintf("Could not start query");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -794,7 +794,7 @@ mpd_command_stats(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
{ {
db_query_end(&qp); db_query_end(&qp);
*errmsg = string_printf("Could not fetch query count"); *errmsg = safe_asprintf("Could not fetch query count");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -837,14 +837,14 @@ mpd_command_consume(struct evbuffer *evbuf, int argc, char **argv, char **errmsg
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'consume'"); *errmsg = safe_asprintf("Missing argument for command 'consume'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atoi32(argv[1], &enable); ret = safe_atoi32(argv[1], &enable);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -866,14 +866,14 @@ mpd_command_random(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'random'"); *errmsg = safe_asprintf("Missing argument for command 'random'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atoi32(argv[1], &enable); ret = safe_atoi32(argv[1], &enable);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -895,14 +895,14 @@ mpd_command_repeat(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'repeat'"); *errmsg = safe_asprintf("Missing argument for command 'repeat'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atoi32(argv[1], &enable); ret = safe_atoi32(argv[1], &enable);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -926,14 +926,14 @@ mpd_command_setvol(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'setvol'"); *errmsg = safe_asprintf("Missing argument for command 'setvol'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atoi32(argv[1], &volume); ret = safe_atoi32(argv[1], &volume);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -966,14 +966,14 @@ mpd_command_single(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'single'"); *errmsg = safe_asprintf("Missing argument for command 'single'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atoi32(argv[1], &enable); ret = safe_atoi32(argv[1], &enable);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1016,14 +1016,14 @@ mpd_command_volume(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'volume'"); *errmsg = safe_asprintf("Missing argument for command 'volume'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atoi32(argv[1], &volume); ret = safe_atoi32(argv[1], &volume);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1049,14 +1049,14 @@ mpd_command_next(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to skip to next song"); *errmsg = safe_asprintf("Failed to skip to next song");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
ret = player_playback_start(); ret = player_playback_start();
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Player returned an error for start after nextitem"); *errmsg = safe_asprintf("Player returned an error for start after nextitem");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1082,7 +1082,7 @@ mpd_command_pause(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
ret = safe_atoi32(argv[1], &pause); ret = safe_atoi32(argv[1], &pause);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
} }
@ -1101,7 +1101,7 @@ mpd_command_pause(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to pause playback"); *errmsg = safe_asprintf("Failed to pause playback");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1127,7 +1127,7 @@ mpd_command_play(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
ret = safe_atoi32(argv[1], &songpos); ret = safe_atoi32(argv[1], &songpos);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
} }
@ -1151,7 +1151,7 @@ mpd_command_play(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
queue_item = db_queue_fetch_bypos(songpos, 0); queue_item = db_queue_fetch_bypos(songpos, 0);
if (!queue_item) if (!queue_item)
{ {
*errmsg = string_printf("Failed to start playback"); *errmsg = safe_asprintf("Failed to start playback");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1163,7 +1163,7 @@ mpd_command_play(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to start playback"); *errmsg = safe_asprintf("Failed to start playback");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1192,7 +1192,7 @@ mpd_command_playid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
ret = safe_atou32(argv[1], &id); ret = safe_atou32(argv[1], &id);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
} }
@ -1208,7 +1208,7 @@ mpd_command_playid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
queue_item = db_queue_fetch_byitemid(id); queue_item = db_queue_fetch_byitemid(id);
if (!queue_item) if (!queue_item)
{ {
*errmsg = string_printf("Failed to start playback"); *errmsg = safe_asprintf("Failed to start playback");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1220,7 +1220,7 @@ mpd_command_playid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to start playback"); *errmsg = safe_asprintf("Failed to start playback");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1240,14 +1240,14 @@ mpd_command_previous(struct evbuffer *evbuf, int argc, char **argv, char **errms
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to skip to previous song"); *errmsg = safe_asprintf("Failed to skip to previous song");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
ret = player_playback_start(); ret = player_playback_start();
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Player returned an error for start after previtem"); *errmsg = safe_asprintf("Player returned an error for start after previtem");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1269,14 +1269,14 @@ mpd_command_seek(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 3) if (argc < 3)
{ {
*errmsg = string_printf("Missing argument for command 'seek'"); *errmsg = safe_asprintf("Missing argument for command 'seek'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atou32(argv[1], &songpos); ret = safe_atou32(argv[1], &songpos);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1289,14 +1289,14 @@ mpd_command_seek(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to seek current song to time %d msec", seek_target_msec); *errmsg = safe_asprintf("Failed to seek current song to time %d msec", seek_target_msec);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
ret = player_playback_start(); ret = player_playback_start();
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Player returned an error for start after seekcur"); *errmsg = safe_asprintf("Player returned an error for start after seekcur");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1319,14 +1319,14 @@ mpd_command_seekid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 3) if (argc < 3)
{ {
*errmsg = string_printf("Missing argument for command 'seekcur'"); *errmsg = safe_asprintf("Missing argument for command 'seekcur'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atou32(argv[1], &id); ret = safe_atou32(argv[1], &id);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1334,7 +1334,7 @@ mpd_command_seekid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
player_get_status(&status); player_get_status(&status);
if (status.item_id != id) if (status.item_id != id)
{ {
*errmsg = string_printf("Given song is not the current playing one, seeking is not supported"); *errmsg = safe_asprintf("Given song is not the current playing one, seeking is not supported");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1345,14 +1345,14 @@ mpd_command_seekid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to seek current song to time %d msec", seek_target_msec); *errmsg = safe_asprintf("Failed to seek current song to time %d msec", seek_target_msec);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
ret = player_playback_start(); ret = player_playback_start();
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Player returned an error for start after seekcur"); *errmsg = safe_asprintf("Player returned an error for start after seekcur");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1372,7 +1372,7 @@ mpd_command_seekcur(struct evbuffer *evbuf, int argc, char **argv, char **errmsg
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'seekcur'"); *errmsg = safe_asprintf("Missing argument for command 'seekcur'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1384,14 +1384,14 @@ mpd_command_seekcur(struct evbuffer *evbuf, int argc, char **argv, char **errmsg
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to seek current song to time %d msec", seek_target_msec); *errmsg = safe_asprintf("Failed to seek current song to time %d msec", seek_target_msec);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
ret = player_playback_start(); ret = player_playback_start();
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Player returned an error for start after seekcur"); *errmsg = safe_asprintf("Player returned an error for start after seekcur");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1411,7 +1411,7 @@ mpd_command_stop(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (ret != 0) if (ret != 0)
{ {
*errmsg = string_printf("Failed to stop playback"); *errmsg = safe_asprintf("Failed to stop playback");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1472,7 +1472,7 @@ mpd_command_add(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'add'"); *errmsg = safe_asprintf("Missing argument for command 'add'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1480,7 +1480,7 @@ mpd_command_add(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to add song '%s' to playlist", argv[1]); *errmsg = safe_asprintf("Failed to add song '%s' to playlist", argv[1]);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1490,7 +1490,7 @@ mpd_command_add(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
ret = library_scan_media(argv[1], &mfi); ret = library_scan_media(argv[1], &mfi);
if (ret != LIBRARY_OK) if (ret != LIBRARY_OK)
{ {
*errmsg = string_printf("Failed to add song '%s' to playlist (unkown path)", argv[1]); *errmsg = safe_asprintf("Failed to add song '%s' to playlist (unkown path)", argv[1]);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1515,7 +1515,7 @@ mpd_command_addid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'addid'"); *errmsg = safe_asprintf("Missing argument for command 'addid'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1533,7 +1533,7 @@ mpd_command_addid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
ret = library_scan_media(argv[1], &mfi); ret = library_scan_media(argv[1], &mfi);
if (ret != LIBRARY_OK) if (ret != LIBRARY_OK)
{ {
*errmsg = string_printf("Failed to add song '%s' to playlist (unkown path)", argv[1]); *errmsg = safe_asprintf("Failed to add song '%s' to playlist (unkown path)", argv[1]);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1543,7 +1543,7 @@ mpd_command_addid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to add song '%s' to playlist", argv[1]); *errmsg = safe_asprintf("Failed to add song '%s' to playlist", argv[1]);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1599,7 +1599,7 @@ mpd_command_delete(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
ret = mpd_pars_range_arg(argv[1], &start_pos, &end_pos); ret = mpd_pars_range_arg(argv[1], &start_pos, &end_pos);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer or range: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer or range: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1608,7 +1608,7 @@ mpd_command_delete(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
ret = db_queue_delete_bypos(start_pos, count); ret = db_queue_delete_bypos(start_pos, count);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to remove %d songs starting at position %d", count, start_pos); *errmsg = safe_asprintf("Failed to remove %d songs starting at position %d", count, start_pos);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1627,21 +1627,21 @@ mpd_command_deleteid(struct evbuffer *evbuf, int argc, char **argv, char **errms
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'deleteid'"); *errmsg = safe_asprintf("Missing argument for command 'deleteid'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atou32(argv[1], &songid); ret = safe_atou32(argv[1], &songid);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = db_queue_delete_byitemid(songid); ret = db_queue_delete_byitemid(songid);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to remove song with id '%s'", argv[1]); *errmsg = safe_asprintf("Failed to remove song with id '%s'", argv[1]);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1660,14 +1660,14 @@ mpd_command_move(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 3) if (argc < 3)
{ {
*errmsg = string_printf("Missing argument for command 'move'"); *errmsg = safe_asprintf("Missing argument for command 'move'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = mpd_pars_range_arg(argv[1], &start_pos, &end_pos); ret = mpd_pars_range_arg(argv[1], &start_pos, &end_pos);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer or range: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer or range: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1678,14 +1678,14 @@ mpd_command_move(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
ret = safe_atou32(argv[2], &to_pos); ret = safe_atou32(argv[2], &to_pos);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[2]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[2]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = db_queue_move_bypos(start_pos, to_pos); ret = db_queue_move_bypos(start_pos, to_pos);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to move song at position %d to %d", start_pos, to_pos); *errmsg = safe_asprintf("Failed to move song at position %d to %d", start_pos, to_pos);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1701,28 +1701,28 @@ mpd_command_moveid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 3) if (argc < 3)
{ {
*errmsg = string_printf("Missing argument for command 'moveid'"); *errmsg = safe_asprintf("Missing argument for command 'moveid'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atou32(argv[1], &songid); ret = safe_atou32(argv[1], &songid);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atou32(argv[2], &to_pos); ret = safe_atou32(argv[2], &to_pos);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[2]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[2]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = db_queue_move_byitemid(songid, to_pos, 0); ret = db_queue_move_byitemid(songid, to_pos, 0);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to move song with id '%s' to index '%s'", argv[1], argv[2]); *errmsg = safe_asprintf("Failed to move song with id '%s' to index '%s'", argv[1], argv[2]);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -1751,7 +1751,7 @@ mpd_command_playlistid(struct evbuffer *evbuf, int argc, char **argv, char **err
ret = safe_atou32(argv[1], &songid); ret = safe_atou32(argv[1], &songid);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
} }
@ -1765,7 +1765,7 @@ mpd_command_playlistid(struct evbuffer *evbuf, int argc, char **argv, char **err
if (ret < 0) if (ret < 0)
{ {
sqlite3_free(query_params.filter); sqlite3_free(query_params.filter);
*errmsg = string_printf("Failed to start queue enum for command playlistid: '%s'", argv[1]); *errmsg = safe_asprintf("Failed to start queue enum for command playlistid: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1774,7 +1774,7 @@ mpd_command_playlistid(struct evbuffer *evbuf, int argc, char **argv, char **err
ret = mpd_add_db_queue_item(evbuf, &queue_item); ret = mpd_add_db_queue_item(evbuf, &queue_item);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Error adding media info for file with id: %d", queue_item.file_id); *errmsg = safe_asprintf("Error adding media info for file with id: %d", queue_item.file_id);
db_queue_enum_end(&query_params); db_queue_enum_end(&query_params);
sqlite3_free(query_params.filter); sqlite3_free(query_params.filter);
@ -1814,7 +1814,7 @@ mpd_command_playlistinfo(struct evbuffer *evbuf, int argc, char **argv, char **e
ret = mpd_pars_range_arg(argv[1], &start_pos, &end_pos); ret = mpd_pars_range_arg(argv[1], &start_pos, &end_pos);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer or range: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer or range: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1828,7 +1828,7 @@ mpd_command_playlistinfo(struct evbuffer *evbuf, int argc, char **argv, char **e
if (ret < 0) if (ret < 0)
{ {
sqlite3_free(query_params.filter); sqlite3_free(query_params.filter);
*errmsg = string_printf("Failed to start queue enum for command playlistinfo: '%s'", argv[1]); *errmsg = safe_asprintf("Failed to start queue enum for command playlistinfo: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1837,7 +1837,7 @@ mpd_command_playlistinfo(struct evbuffer *evbuf, int argc, char **argv, char **e
ret = mpd_add_db_queue_item(evbuf, &queue_item); ret = mpd_add_db_queue_item(evbuf, &queue_item);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Error adding media info for file with id: %d", queue_item.file_id); *errmsg = safe_asprintf("Error adding media info for file with id: %d", queue_item.file_id);
db_queue_enum_end(&query_params); db_queue_enum_end(&query_params);
sqlite3_free(query_params.filter); sqlite3_free(query_params.filter);
@ -1871,7 +1871,7 @@ mpd_command_plchanges(struct evbuffer *evbuf, int argc, char **argv, char **errm
ret = db_queue_enum_start(&query_params); ret = db_queue_enum_start(&query_params);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to start queue enum for command plchanges"); *errmsg = safe_asprintf("Failed to start queue enum for command plchanges");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1880,7 +1880,7 @@ mpd_command_plchanges(struct evbuffer *evbuf, int argc, char **argv, char **errm
ret = mpd_add_db_queue_item(evbuf, &queue_item); ret = mpd_add_db_queue_item(evbuf, &queue_item);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Error adding media info for file with id: %d", queue_item.file_id); *errmsg = safe_asprintf("Error adding media info for file with id: %d", queue_item.file_id);
db_queue_enum_end(&query_params); db_queue_enum_end(&query_params);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
@ -1912,7 +1912,7 @@ mpd_command_plchangesposid(struct evbuffer *evbuf, int argc, char **argv, char *
ret = db_queue_enum_start(&query_params); ret = db_queue_enum_start(&query_params);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to start queue enum for command plchangesposid"); *errmsg = safe_asprintf("Failed to start queue enum for command plchangesposid");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1945,7 +1945,7 @@ mpd_command_listplaylist(struct evbuffer *evbuf, int argc, char **argv, char **e
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'listplaylist'"); *errmsg = safe_asprintf("Missing argument for command 'listplaylist'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1956,14 +1956,14 @@ mpd_command_listplaylist(struct evbuffer *evbuf, int argc, char **argv, char **e
if (ret >= sizeof(path)) if (ret >= sizeof(path))
{ {
*errmsg = string_printf("Length of path exceeds the PATH_MAX value '%s'", argv[1]); *errmsg = safe_asprintf("Length of path exceeds the PATH_MAX value '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
pli = db_pl_fetch_byvirtualpath(path); pli = db_pl_fetch_byvirtualpath(path);
if (!pli) if (!pli)
{ {
*errmsg = string_printf("Playlist not found for path '%s'", argv[1]); *errmsg = safe_asprintf("Playlist not found for path '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -1980,7 +1980,7 @@ mpd_command_listplaylist(struct evbuffer *evbuf, int argc, char **argv, char **e
free_pli(pli, 0); free_pli(pli, 0);
*errmsg = string_printf("Could not start query"); *errmsg = safe_asprintf("Could not start query");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2013,7 +2013,7 @@ mpd_command_listplaylistinfo(struct evbuffer *evbuf, int argc, char **argv, char
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'listplaylistinfo'"); *errmsg = safe_asprintf("Missing argument for command 'listplaylistinfo'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -2024,14 +2024,14 @@ mpd_command_listplaylistinfo(struct evbuffer *evbuf, int argc, char **argv, char
if (ret >= sizeof(path)) if (ret >= sizeof(path))
{ {
*errmsg = string_printf("Length of path exceeds the PATH_MAX value '%s'", argv[1]); *errmsg = safe_asprintf("Length of path exceeds the PATH_MAX value '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
pli = db_pl_fetch_byvirtualpath(path); pli = db_pl_fetch_byvirtualpath(path);
if (!pli) if (!pli)
{ {
*errmsg = string_printf("Playlist not found for path '%s'", argv[1]); *errmsg = safe_asprintf("Playlist not found for path '%s'", argv[1]);
return ACK_ERROR_NO_EXIST; return ACK_ERROR_NO_EXIST;
} }
@ -2048,7 +2048,7 @@ mpd_command_listplaylistinfo(struct evbuffer *evbuf, int argc, char **argv, char
free_pli(pli, 0); free_pli(pli, 0);
*errmsg = string_printf("Could not start query"); *errmsg = safe_asprintf("Could not start query");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2093,7 +2093,7 @@ mpd_command_listplaylists(struct evbuffer *evbuf, int argc, char **argv, char **
{ {
db_query_end(&qp); db_query_end(&qp);
*errmsg = string_printf("Could not start query"); *errmsg = safe_asprintf("Could not start query");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2101,7 +2101,7 @@ mpd_command_listplaylists(struct evbuffer *evbuf, int argc, char **argv, char **
{ {
if (safe_atou32(dbpli.db_timestamp, &time_modified) != 0) if (safe_atou32(dbpli.db_timestamp, &time_modified) != 0)
{ {
*errmsg = string_printf("Error converting time modified to uint32_t: %s\n", dbpli.db_timestamp); *errmsg = safe_asprintf("Error converting time modified to uint32_t: %s\n", dbpli.db_timestamp);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2135,7 +2135,7 @@ mpd_command_load(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'load'"); *errmsg = safe_asprintf("Missing argument for command 'load'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -2146,14 +2146,14 @@ mpd_command_load(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (ret >= sizeof(path)) if (ret >= sizeof(path))
{ {
*errmsg = string_printf("Length of path exceeds the PATH_MAX value '%s'", argv[1]); *errmsg = safe_asprintf("Length of path exceeds the PATH_MAX value '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
pli = db_pl_fetch_byvirtualpath(path); pli = db_pl_fetch_byvirtualpath(path);
if (!pli) if (!pli)
{ {
*errmsg = string_printf("Playlist not found for path '%s'", argv[1]); *errmsg = safe_asprintf("Playlist not found for path '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -2165,7 +2165,7 @@ mpd_command_load(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
free_pli(pli, 0); free_pli(pli, 0);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to add song '%s' to playlist", argv[1]); *errmsg = safe_asprintf("Failed to add song '%s' to playlist", argv[1]);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2301,7 +2301,7 @@ mpd_command_count(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 3 || ((argc - 1) % 2) != 0) if (argc < 3 || ((argc - 1) % 2) != 0)
{ {
*errmsg = string_printf("Missing argument(s) for command 'find'"); *errmsg = safe_asprintf("Missing argument(s) for command 'find'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -2317,7 +2317,7 @@ mpd_command_count(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
db_query_end(&qp); db_query_end(&qp);
sqlite3_free(qp.filter); sqlite3_free(qp.filter);
*errmsg = string_printf("Could not start query"); *errmsg = safe_asprintf("Could not start query");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2327,7 +2327,7 @@ mpd_command_count(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
db_query_end(&qp); db_query_end(&qp);
sqlite3_free(qp.filter); sqlite3_free(qp.filter);
*errmsg = string_printf("Could not fetch query count"); *errmsg = safe_asprintf("Could not fetch query count");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2352,7 +2352,7 @@ mpd_command_find(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 3 || ((argc - 1) % 2) != 0) if (argc < 3 || ((argc - 1) % 2) != 0)
{ {
*errmsg = string_printf("Missing argument(s) for command 'find'"); *errmsg = safe_asprintf("Missing argument(s) for command 'find'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -2370,7 +2370,7 @@ mpd_command_find(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
db_query_end(&qp); db_query_end(&qp);
sqlite3_free(qp.filter); sqlite3_free(qp.filter);
*errmsg = string_printf("Could not start query"); *errmsg = safe_asprintf("Could not start query");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2398,7 +2398,7 @@ mpd_command_findadd(struct evbuffer *evbuf, int argc, char **argv, char **errmsg
if (argc < 3 || ((argc - 1) % 2) != 0) if (argc < 3 || ((argc - 1) % 2) != 0)
{ {
*errmsg = string_printf("Missing argument(s) for command 'findadd'"); *errmsg = safe_asprintf("Missing argument(s) for command 'findadd'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -2416,7 +2416,7 @@ mpd_command_findadd(struct evbuffer *evbuf, int argc, char **argv, char **errmsg
sqlite3_free(qp.filter); sqlite3_free(qp.filter);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to add songs to playlist"); *errmsg = safe_asprintf("Failed to add songs to playlist");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2437,7 +2437,7 @@ mpd_command_list(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
{ {
if (argc != 3 || (0 != strcasecmp(argv[1], "album"))) if (argc != 3 || (0 != strcasecmp(argv[1], "album")))
{ {
*errmsg = string_printf("Missing argument(s) for command 'list'"); *errmsg = safe_asprintf("Missing argument(s) for command 'list'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
} }
@ -2511,7 +2511,7 @@ mpd_command_list(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
db_query_end(&qp); db_query_end(&qp);
sqlite3_free(qp.filter); sqlite3_free(qp.filter);
*errmsg = string_printf("Could not start query"); *errmsg = safe_asprintf("Could not start query");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2578,7 +2578,7 @@ mpd_add_directory(struct evbuffer *evbuf, int directory_id, int listall, int lis
if (ret < 0) if (ret < 0)
{ {
db_query_end(&qp); db_query_end(&qp);
*errmsg = string_printf("Could not start query"); *errmsg = safe_asprintf("Could not start query");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
while (((ret = db_query_fetch_pl(&qp, &dbpli, 0)) == 0) && (dbpli.id)) while (((ret = db_query_fetch_pl(&qp, &dbpli, 0)) == 0) && (dbpli.id))
@ -2651,7 +2651,7 @@ mpd_add_directory(struct evbuffer *evbuf, int directory_id, int listall, int lis
if (ret < 0) if (ret < 0)
{ {
db_query_end(&qp); db_query_end(&qp);
*errmsg = string_printf("Could not start query"); *errmsg = safe_asprintf("Could not start query");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
while (((ret = db_query_fetch_file(&qp, &dbmfi)) == 0) && (dbmfi.id)) while (((ret = db_query_fetch_file(&qp, &dbmfi)) == 0) && (dbmfi.id))
@ -2699,7 +2699,7 @@ mpd_command_listall(struct evbuffer *evbuf, int argc, char **argv, char **errmsg
if ((ret < 0) || (ret >= sizeof(parent))) if ((ret < 0) || (ret >= sizeof(parent)))
{ {
*errmsg = string_printf("Parent path exceeds PATH_MAX"); *errmsg = safe_asprintf("Parent path exceeds PATH_MAX");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2707,7 +2707,7 @@ mpd_command_listall(struct evbuffer *evbuf, int argc, char **argv, char **errmsg
dir_id = db_directory_id_byvirtualpath(parent); dir_id = db_directory_id_byvirtualpath(parent);
if (dir_id == 0) if (dir_id == 0)
{ {
*errmsg = string_printf("Directory info not found for virtual-path '%s'", parent); *errmsg = safe_asprintf("Directory info not found for virtual-path '%s'", parent);
return ACK_ERROR_NO_EXIST; return ACK_ERROR_NO_EXIST;
} }
@ -2739,7 +2739,7 @@ mpd_command_listallinfo(struct evbuffer *evbuf, int argc, char **argv, char **er
if ((ret < 0) || (ret >= sizeof(parent))) if ((ret < 0) || (ret >= sizeof(parent)))
{ {
*errmsg = string_printf("Parent path exceeds PATH_MAX"); *errmsg = safe_asprintf("Parent path exceeds PATH_MAX");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2747,7 +2747,7 @@ mpd_command_listallinfo(struct evbuffer *evbuf, int argc, char **argv, char **er
dir_id = db_directory_id_byvirtualpath(parent); dir_id = db_directory_id_byvirtualpath(parent);
if (dir_id == 0) if (dir_id == 0)
{ {
*errmsg = string_printf("Directory info not found for virtual-path '%s'", parent); *errmsg = safe_asprintf("Directory info not found for virtual-path '%s'", parent);
return ACK_ERROR_NO_EXIST; return ACK_ERROR_NO_EXIST;
} }
@ -2784,7 +2784,7 @@ mpd_command_lsinfo(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if ((ret < 0) || (ret >= sizeof(parent))) if ((ret < 0) || (ret >= sizeof(parent)))
{ {
*errmsg = string_printf("Parent path exceeds PATH_MAX"); *errmsg = safe_asprintf("Parent path exceeds PATH_MAX");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -2804,7 +2804,7 @@ mpd_command_lsinfo(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
dir_id = db_directory_id_byvirtualpath(parent); dir_id = db_directory_id_byvirtualpath(parent);
if (dir_id == 0) if (dir_id == 0)
{ {
*errmsg = string_printf("Directory info not found for virtual-path '%s'", parent); *errmsg = safe_asprintf("Directory info not found for virtual-path '%s'", parent);
return ACK_ERROR_NO_EXIST; return ACK_ERROR_NO_EXIST;
} }
@ -2957,7 +2957,7 @@ mpd_command_search(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 3 || ((argc - 1) % 2) != 0) if (argc < 3 || ((argc - 1) % 2) != 0)
{ {
*errmsg = string_printf("Missing argument(s) for command 'search'"); *errmsg = safe_asprintf("Missing argument(s) for command 'search'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -2975,7 +2975,7 @@ mpd_command_search(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
db_query_end(&qp); db_query_end(&qp);
sqlite3_free(qp.filter); sqlite3_free(qp.filter);
*errmsg = string_printf("Could not start query"); *errmsg = safe_asprintf("Could not start query");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -3003,7 +3003,7 @@ mpd_command_searchadd(struct evbuffer *evbuf, int argc, char **argv, char **errm
if (argc < 3 || ((argc - 1) % 2) != 0) if (argc < 3 || ((argc - 1) % 2) != 0)
{ {
*errmsg = string_printf("Missing argument(s) for command 'search'"); *errmsg = safe_asprintf("Missing argument(s) for command 'search'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -3021,7 +3021,7 @@ mpd_command_searchadd(struct evbuffer *evbuf, int argc, char **argv, char **errm
sqlite3_free(qp.filter); sqlite3_free(qp.filter);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Failed to add songs to playlist"); *errmsg = safe_asprintf("Failed to add songs to playlist");
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -3037,7 +3037,7 @@ mpd_command_update(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
{ {
if (argc > 1 && strlen(argv[1]) > 0) if (argc > 1 && strlen(argv[1]) > 0)
{ {
*errmsg = string_printf("Update for specific uri not supported for command 'update'"); *errmsg = safe_asprintf("Update for specific uri not supported for command 'update'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -3057,7 +3057,7 @@ mpd_command_rescan(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc > 1) if (argc > 1)
{ {
DPRINTF(E_LOG, L_MPD, "Rescan for specific uri not supported for command 'rescan'\n"); DPRINTF(E_LOG, L_MPD, "Rescan for specific uri not supported for command 'rescan'\n");
*errmsg = string_printf("Rescan for specific uri not supported for command 'rescan'"); *errmsg = safe_asprintf("Rescan for specific uri not supported for command 'rescan'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -3115,14 +3115,14 @@ mpd_command_disableoutput(struct evbuffer *evbuf, int argc, char **argv, char **
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'disableoutput'"); *errmsg = safe_asprintf("Missing argument for command 'disableoutput'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atou32(argv[1], &num); ret = safe_atou32(argv[1], &num);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -3175,7 +3175,7 @@ mpd_command_disableoutput(struct evbuffer *evbuf, int argc, char **argv, char **
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Speakers deactivation failed: %d", num); *errmsg = safe_asprintf("Speakers deactivation failed: %d", num);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -3199,14 +3199,14 @@ mpd_command_enableoutput(struct evbuffer *evbuf, int argc, char **argv, char **e
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'enableoutput'"); *errmsg = safe_asprintf("Missing argument for command 'enableoutput'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atou32(argv[1], &num); ret = safe_atou32(argv[1], &num);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -3260,7 +3260,7 @@ mpd_command_enableoutput(struct evbuffer *evbuf, int argc, char **argv, char **e
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Speakers activation failed: %d", num); *errmsg = safe_asprintf("Speakers activation failed: %d", num);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -3284,14 +3284,14 @@ mpd_command_toggleoutput(struct evbuffer *evbuf, int argc, char **argv, char **e
if (argc < 2) if (argc < 2)
{ {
*errmsg = string_printf("Missing argument for command 'toggleoutput'"); *errmsg = safe_asprintf("Missing argument for command 'toggleoutput'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atou32(argv[1], &num); ret = safe_atou32(argv[1], &num);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -3351,7 +3351,7 @@ mpd_command_toggleoutput(struct evbuffer *evbuf, int argc, char **argv, char **e
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Speakers de/activation failed: %d", num); *errmsg = safe_asprintf("Speakers de/activation failed: %d", num);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -3424,7 +3424,7 @@ outputvolume_set(uint32_t shortid, int volume, char **errmsg)
if (!output) if (!output)
{ {
free_outputs(outputs.outputs); free_outputs(outputs.outputs);
*errmsg = string_printf("No speaker found for short id: %d", shortid); *errmsg = safe_asprintf("No speaker found for short id: %d", shortid);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -3434,7 +3434,7 @@ outputvolume_set(uint32_t shortid, int volume, char **errmsg)
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Setting volume to %d for speaker with short-id %d failed", volume, shortid); *errmsg = safe_asprintf("Setting volume to %d for speaker with short-id %d failed", volume, shortid);
return ACK_ERROR_UNKNOWN; return ACK_ERROR_UNKNOWN;
} }
@ -3450,21 +3450,21 @@ mpd_command_outputvolume(struct evbuffer *evbuf, int argc, char **argv, char **e
if (argc < 3) if (argc < 3)
{ {
*errmsg = string_printf("Missing argument for command 'outputvolume'"); *errmsg = safe_asprintf("Missing argument for command 'outputvolume'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atou32(argv[1], &shortid); ret = safe_atou32(argv[1], &shortid);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[1]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[1]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
ret = safe_atoi32(argv[2], &volume); ret = safe_atoi32(argv[2], &volume);
if (ret < 0) if (ret < 0)
{ {
*errmsg = string_printf("Argument doesn't convert to integer: '%s'", argv[2]); *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[2]);
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -3598,7 +3598,7 @@ mpd_command_sendmessage(struct evbuffer *evbuf, int argc, char **argv, char **er
if (argc < 3) if (argc < 3)
{ {
*errmsg = string_printf("Missing argument for command 'sendmessage'"); *errmsg = safe_asprintf("Missing argument for command 'sendmessage'");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
} }
@ -4261,7 +4261,7 @@ mpd_read_cb(struct bufferevent *bev, void *ctx)
{ {
// Error handling for argument parsing error // Error handling for argument parsing error
DPRINTF(E_LOG, L_MPD, "Error parsing arguments for MPD message: %s\n", line); DPRINTF(E_LOG, L_MPD, "Error parsing arguments for MPD message: %s\n", line);
errmsg = string_printf("Error parsing arguments"); errmsg = safe_asprintf("Error parsing arguments");
ret = ACK_ERROR_ARG; ret = ACK_ERROR_ARG;
evbuffer_add_printf(output, "ACK [%d@%d] {%s} %s\n", ret, ncmd, "unkown", errmsg); evbuffer_add_printf(output, "ACK [%d@%d] {%s} %s\n", ret, ncmd, "unkown", errmsg);
free(errmsg); free(errmsg);
@ -4303,7 +4303,7 @@ mpd_read_cb(struct bufferevent *bev, void *ctx)
if (command == NULL) if (command == NULL)
{ {
errmsg = string_printf("Unsupported command '%s'", argv[0]); errmsg = safe_asprintf("Unsupported command '%s'", argv[0]);
ret = ACK_ERROR_UNKNOWN; ret = ACK_ERROR_UNKNOWN;
} }
else else

View File

@ -244,9 +244,9 @@ spotifywebapi_request_next(struct spotify_request *request, const char *uri, boo
if (append_market && spotify_user_country) if (append_market && spotify_user_country)
{ {
if (strchr(uri, '?')) if (strchr(uri, '?'))
next_uri = string_printf("%s&market=%s", uri, spotify_user_country); next_uri = safe_asprintf("%s&market=%s", uri, spotify_user_country);
else else
next_uri = string_printf("%s?market=%s", uri, spotify_user_country); next_uri = safe_asprintf("%s?market=%s", uri, spotify_user_country);
} }
else else
next_uri = strdup(uri); next_uri = strdup(uri);