lib/smbclient/Init: move code to SmbclientContext::New()

We no longer need to call smbc_init() because we don't need the compat
layer anymore.
This commit is contained in:
Max Kellermann 2020-07-20 22:12:52 +02:00
parent f6dc9bcad6
commit 7d97d0ae87
2 changed files with 21 additions and 25 deletions

View File

@ -22,6 +22,21 @@
#include <cerrno>
#include <string.h>
static void
mpd_smbc_get_auth_data([[maybe_unused]] const char *srv,
[[maybe_unused]] const char *shr,
char *wg, [[maybe_unused]] int wglen,
char *un, [[maybe_unused]] int unlen,
char *pw, [[maybe_unused]] int pwlen)
{
// TODO: implement
strcpy(wg, "WORKGROUP");
strcpy(un, "");
strcpy(pw, "");
}
SmbclientContext
SmbclientContext::New()
{
@ -29,6 +44,10 @@ SmbclientContext::New()
if (ctx == nullptr)
throw MakeErrno("smbc_new_context() failed");
constexpr int debug = 0;
smbc_setDebug(ctx, debug);
smbc_setFunctionAuthData(ctx, mpd_smbc_get_auth_data);
SMBCCTX *ctx2 = smbc_init_context(ctx);
if (ctx2 == nullptr) {
int e = errno;

View File

@ -18,33 +18,10 @@
*/
#include "Init.hxx"
#include "Mutex.hxx"
#include "thread/Mutex.hxx"
#include "system/Error.hxx"
#include <libsmbclient.h>
#include <string.h>
static void
mpd_smbc_get_auth_data([[maybe_unused]] const char *srv,
[[maybe_unused]] const char *shr,
char *wg, [[maybe_unused]] int wglen,
char *un, [[maybe_unused]] int unlen,
char *pw, [[maybe_unused]] int pwlen)
{
// TODO: implement
strcpy(wg, "WORKGROUP");
strcpy(un, "");
strcpy(pw, "");
}
void
SmbclientInit()
{
const std::lock_guard<Mutex> protect(smbclient_mutex);
constexpr int debug = 0;
if (smbc_init(mpd_smbc_get_auth_data, debug) < 0)
throw MakeErrno("smbc_init() failed");
/* this is currently a no-op, but one day, we might want to
call smbc_thread_posix() here */
}