lib/smbclient/Init: throw std::runtime_error on error
This commit is contained in:
parent
a69c3c1848
commit
135662d6b0
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include <libsmbclient.h>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
class SmbclientInputStream final : public InputStream {
|
||||
SMBCCTX *ctx;
|
||||
int fd;
|
||||
|
@ -66,10 +68,13 @@ public:
|
|||
*/
|
||||
|
||||
static InputPlugin::InitResult
|
||||
input_smbclient_init(gcc_unused const ConfigBlock &block, Error &error)
|
||||
input_smbclient_init(gcc_unused const ConfigBlock &block, gcc_unused Error &error)
|
||||
{
|
||||
if (!SmbclientInit(error))
|
||||
try {
|
||||
SmbclientInit();
|
||||
} catch (const std::runtime_error &e) {
|
||||
return InputPlugin::InitResult::UNAVAILABLE;
|
||||
}
|
||||
|
||||
// TODO: create one global SMBCCTX here?
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "Init.hxx"
|
||||
#include "Mutex.hxx"
|
||||
#include "thread/Mutex.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "system/Error.hxx"
|
||||
|
||||
#include <libsmbclient.h>
|
||||
|
||||
|
@ -40,16 +40,12 @@ mpd_smbc_get_auth_data(gcc_unused const char *srv,
|
|||
strcpy(pw, "");
|
||||
}
|
||||
|
||||
bool
|
||||
SmbclientInit(Error &error)
|
||||
void
|
||||
SmbclientInit()
|
||||
{
|
||||
const ScopeLock protect(smbclient_mutex);
|
||||
|
||||
constexpr int debug = 0;
|
||||
if (smbc_init(mpd_smbc_get_auth_data, debug) < 0) {
|
||||
error.SetErrno("smbc_init() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
if (smbc_init(mpd_smbc_get_auth_data, debug) < 0)
|
||||
throw MakeErrno("smbc_init() failed");
|
||||
}
|
||||
|
|
|
@ -20,14 +20,12 @@
|
|||
#ifndef MPD_SMBCLIENT_INIT_HXX
|
||||
#define MPD_SMBCLIENT_INIT_HXX
|
||||
|
||||
#include "check.h"
|
||||
|
||||
class Error;
|
||||
|
||||
/**
|
||||
* Initialize libsmbclient.
|
||||
*
|
||||
* Throws std::runtime_error on error.
|
||||
*/
|
||||
bool
|
||||
SmbclientInit(Error &error);
|
||||
void
|
||||
SmbclientInit();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -273,8 +273,7 @@ smbclient_neighbor_create(gcc_unused EventLoop &loop,
|
|||
gcc_unused const ConfigBlock &block,
|
||||
gcc_unused Error &error)
|
||||
{
|
||||
if (!SmbclientInit(error))
|
||||
return nullptr;
|
||||
SmbclientInit();
|
||||
|
||||
return new SmbclientNeighborExplorer(listener);
|
||||
}
|
||||
|
|
|
@ -189,8 +189,7 @@ CreateSmbclientStorageURI(gcc_unused EventLoop &event_loop, const char *base,
|
|||
if (memcmp(base, "smb://", 6) != 0)
|
||||
return nullptr;
|
||||
|
||||
if (!SmbclientInit(error))
|
||||
return nullptr;
|
||||
SmbclientInit();
|
||||
|
||||
const ScopeLock protect(smbclient_mutex);
|
||||
SMBCCTX *ctx = smbc_new_context();
|
||||
|
|
Loading…
Reference in New Issue