db: add compile-time option to disable database

This commit is contained in:
Max Kellermann
2014-01-30 20:29:48 +01:00
parent 34b309b99a
commit 4465e2c46b
25 changed files with 297 additions and 57 deletions

View File

@@ -85,7 +85,9 @@ static const struct command commands[] = {
{ "commands", PERMISSION_NONE, 0, 0, handle_commands },
{ "config", PERMISSION_ADMIN, 0, 0, handle_config },
{ "consume", PERMISSION_CONTROL, 1, 1, handle_consume },
#ifdef ENABLE_DATABASE
{ "count", PERMISSION_READ, 2, -1, handle_count },
#endif
{ "crossfade", PERMISSION_CONTROL, 1, 1, handle_crossfade },
{ "currentsong", PERMISSION_READ, 0, 0, handle_currentsong },
{ "decoders", PERMISSION_READ, 0, 0, handle_decoders },
@@ -93,13 +95,17 @@ static const struct command commands[] = {
{ "deleteid", PERMISSION_CONTROL, 1, 1, handle_deleteid },
{ "disableoutput", PERMISSION_ADMIN, 1, 1, handle_disableoutput },
{ "enableoutput", PERMISSION_ADMIN, 1, 1, handle_enableoutput },
#ifdef ENABLE_DATABASE
{ "find", PERMISSION_READ, 2, -1, handle_find },
{ "findadd", PERMISSION_READ, 2, -1, handle_findadd},
#endif
{ "idle", PERMISSION_READ, 0, -1, handle_idle },
{ "kill", PERMISSION_ADMIN, -1, -1, handle_kill },
#ifdef ENABLE_DATABASE
{ "list", PERMISSION_READ, 1, -1, handle_list },
{ "listall", PERMISSION_READ, 0, 1, handle_listall },
{ "listallinfo", PERMISSION_READ, 0, 1, handle_listallinfo },
#endif
#ifdef ENABLE_NEIGHBOR_PLUGINS
{ "listneighbors", PERMISSION_READ, 0, 0, handle_listneighbors },
#endif
@@ -146,9 +152,11 @@ static const struct command commands[] = {
{ "rescan", PERMISSION_CONTROL, 0, 1, handle_rescan },
{ "rm", PERMISSION_CONTROL, 1, 1, handle_rm },
{ "save", PERMISSION_CONTROL, 1, 1, handle_save },
#ifdef ENABLE_DATABASE
{ "search", PERMISSION_READ, 2, -1, handle_search },
{ "searchadd", PERMISSION_ADD, 2, -1, handle_searchadd },
{ "searchaddpl", PERMISSION_CONTROL, 3, -1, handle_searchaddpl },
#endif
{ "seek", PERMISSION_CONTROL, 2, 2, handle_seek },
{ "seekcur", PERMISSION_CONTROL, 1, 1, handle_seekcur },
{ "seekid", PERMISSION_CONTROL, 2, 2, handle_seekid },

View File

@@ -101,6 +101,7 @@ print_error(Client &client, const Error &error)
command_error(client, (ack)error.GetCode(),
"%s", error.GetMessage());
return CommandResult::ERROR;
#ifdef ENABLE_DATABASE
} else if (error.IsDomain(db_domain)) {
switch ((enum db_error)error.GetCode()) {
case DB_DISABLED:
@@ -112,6 +113,7 @@ print_error(Client &client, const Error &error)
command_error(client, ACK_ERROR_NO_EXIST, "Not found");
return CommandResult::ERROR;
}
#endif
} else if (error.IsDomain(errno_domain)) {
command_error(client, ACK_ERROR_SYSTEM, "%s",
strerror(error.GetCode()));

View File

@@ -127,12 +127,17 @@ handle_read_comments(Client &client, gcc_unused int argc, char *argv[])
} else if (uri_has_scheme(uri)) {
return read_stream_comments(client, uri);
} else if (*uri != '/') {
#ifdef ENABLE_DATABASE
path_fs = map_uri_fs(uri);
if (path_fs.IsNull()) {
command_error(client, ACK_ERROR_NO_EXIST,
"No such file");
return CommandResult::ERROR;
}
#else
command_error(client, ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR;
#endif
} else {
command_error(client, ACK_ERROR_NO_EXIST, "No such file");
return CommandResult::ERROR;

View File

@@ -19,8 +19,6 @@
#include "config.h"
#include "OtherCommands.hxx"
#include "DatabaseCommands.hxx"
#include "db/update/Service.hxx"
#include "CommandError.hxx"
#include "db/Uri.hxx"
#include "DetachedSong.hxx"
@@ -49,6 +47,11 @@
#include "Instance.hxx"
#include "Idle.hxx"
#ifdef ENABLE_DATABASE
#include "DatabaseCommands.hxx"
#include "db/update/Service.hxx"
#endif
#include <assert.h>
#include <string.h>
@@ -170,14 +173,21 @@ handle_lsinfo(Client &client, int argc, char *argv[])
return CommandResult::OK;
}
#ifdef ENABLE_DATABASE
CommandResult result = handle_lsinfo2(client, argc, argv);
if (result != CommandResult::OK)
return result;
#endif
if (isRootDirectory(uri)) {
Error error;
const auto &list = ListPlaylistFiles(error);
print_spl_list(client, list);
} else {
#ifndef ENABLE_DATABASE
command_error(client, ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR;
#endif
}
return CommandResult::OK;
@@ -186,6 +196,7 @@ handle_lsinfo(Client &client, int argc, char *argv[])
static CommandResult
handle_update(Client &client, int argc, char *argv[], bool discard)
{
#ifdef ENABLE_DATABASE
const char *path = "";
assert(argc <= 2);
@@ -217,6 +228,15 @@ handle_update(Client &client, int argc, char *argv[], bool discard)
"already updating");
return CommandResult::ERROR;
}
#else
(void)client;
(void)argc;
(void)argv;
(void)discard;
command_error(client, ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR;
#endif
}
CommandResult
@@ -329,9 +349,11 @@ handle_config(Client &client,
return CommandResult::ERROR;
}
#ifdef ENABLE_DATABASE
const char *path = mapper_get_music_directory_utf8();
if (path != nullptr)
client_printf(client, "music_directory: %s\n", path);
#endif
return CommandResult::OK;
}

View File

@@ -22,7 +22,6 @@
#include "CommandError.hxx"
#include "Playlist.hxx"
#include "PlaylistPrint.hxx"
#include "db/update/Service.hxx"
#include "client/Client.hxx"
#include "mixer/Volume.hxx"
#include "Partition.hxx"
@@ -32,6 +31,10 @@
#include "AudioFormat.hxx"
#include "ReplayGainConfig.hxx"
#ifdef ENABLE_DATABASE
#include "db/update/Service.hxx"
#endif
#define COMMAND_STATUS_STATE "state"
#define COMMAND_STATUS_REPEAT "repeat"
#define COMMAND_STATUS_SINGLE "single"
@@ -187,6 +190,7 @@ handle_status(Client &client,
}
}
#ifdef ENABLE_DATABASE
const UpdateService *update_service = client.partition.instance.update;
unsigned updateJobId = update_service != nullptr
? update_service->GetId()
@@ -196,6 +200,7 @@ handle_status(Client &client,
COMMAND_STATUS_UPDATING_DB ": %i\n",
updateJobId);
}
#endif
Error error = client.player_control.LockGetError();
if (error.IsDefined())

View File

@@ -193,9 +193,14 @@ handle_playlistadd(Client &client, gcc_unused int argc, char *argv[])
}
success = spl_append_uri(uri, playlist, error);
} else
} else {
#ifdef ENABLE_DATABASE
success = search_add_to_playlist(uri, playlist, nullptr,
error);
#else
success = false;
#endif
}
if (!success && !error.IsDefined()) {
command_error(client, ACK_ERROR_NO_EXIST,

View File

@@ -74,11 +74,16 @@ handle_add(Client &client, gcc_unused int argc, char *argv[])
return print_playlist_result(client, result);
}
#ifdef ENABLE_DATABASE
const DatabaseSelection selection(uri, true);
Error error;
return AddFromDatabase(client.partition, selection, error)
? CommandResult::OK
: print_error(client, error);
#else
command_error(client, ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR;
#endif
}
CommandResult