summaryrefslogtreecommitdiff
path: root/src/input
diff options
context:
space:
mode:
Diffstat (limited to 'src/input')
-rw-r--r--src/input/plugins/SmbclientInputPlugin.cxx42
1 files changed, 14 insertions, 28 deletions
diff --git a/src/input/plugins/SmbclientInputPlugin.cxx b/src/input/plugins/SmbclientInputPlugin.cxx
index e8febc82f..9f4a148d2 100644
--- a/src/input/plugins/SmbclientInputPlugin.cxx
+++ b/src/input/plugins/SmbclientInputPlugin.cxx
@@ -19,6 +19,7 @@
#include "SmbclientInputPlugin.hxx"
#include "lib/smbclient/Init.hxx"
+#include "lib/smbclient/Context.hxx"
#include "lib/smbclient/Mutex.hxx"
#include "../InputStream.hxx"
#include "../InputPlugin.hxx"
@@ -29,15 +30,17 @@
#include <libsmbclient.h>
class SmbclientInputStream final : public InputStream {
- SMBCCTX *ctx;
+ SmbclientContext ctx;
int fd;
public:
SmbclientInputStream(const char *_uri,
Mutex &_mutex,
- SMBCCTX *_ctx, int _fd, const struct stat &st)
+ SmbclientContext &&_ctx,
+ int _fd, const struct stat &st)
:InputStream(_uri, _mutex),
- ctx(_ctx), fd(_fd) {
+ ctx(std::move(_ctx)), fd(_fd)
+ {
seekable = true;
size = st.st_size;
SetReady();
@@ -46,7 +49,6 @@ public:
~SmbclientInputStream() override {
const std::lock_guard<Mutex> lock(smbclient_mutex);
smbc_close(fd);
- smbc_free_context(ctx, 1);
}
/* virtual methods from InputStream */
@@ -83,38 +85,22 @@ static InputStreamPtr
input_smbclient_open(const char *uri,
Mutex &mutex)
{
- const std::lock_guard<Mutex> protect(smbclient_mutex);
-
- SMBCCTX *ctx = smbc_new_context();
- if (ctx == nullptr)
- throw MakeErrno("smbc_new_context() failed");
-
- SMBCCTX *ctx2 = smbc_init_context(ctx);
- if (ctx2 == nullptr) {
- int e = errno;
- smbc_free_context(ctx, 1);
- throw MakeErrno(e, "smbc_init_context() failed");
- }
+ auto ctx = SmbclientContext::New();
- ctx = ctx2;
+ const std::lock_guard<Mutex> protect(smbclient_mutex);
int fd = smbc_open(uri, O_RDONLY, 0);
- if (fd < 0) {
- int e = errno;
- smbc_free_context(ctx, 1);
- throw MakeErrno(e, "smbc_open() failed");
- }
+ if (fd < 0)
+ throw MakeErrno("smbc_open() failed");
struct stat st;
- if (smbc_fstat(fd, &st) < 0) {
- int e = errno;
- smbc_free_context(ctx, 1);
- throw MakeErrno(e, "smbc_fstat() failed");
- }
+ if (smbc_fstat(fd, &st) < 0)
+ throw MakeErrno("smbc_fstat() failed");
return std::make_unique<MaybeBufferedInputStream>
(std::make_unique<SmbclientInputStream>(uri, mutex,
- ctx, fd, st));
+ std::move(ctx),
+ fd, st));
}
size_t