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