mosquittoauthoptcompatwrap.cpp
1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "mosquittoauthoptcompatwrap.h"
mosquitto_auth_opt::mosquitto_auth_opt(const std::string &key, const std::string &value)
{
this->key = strdup(key.c_str());
this->value = strdup(value.c_str());
}
mosquitto_auth_opt::mosquitto_auth_opt(mosquitto_auth_opt &&other)
{
this->key = other.key;
this->value = other.value;
other.key = nullptr;
other.value = nullptr;
}
mosquitto_auth_opt::mosquitto_auth_opt(const mosquitto_auth_opt &other)
{
this->key = strdup(other.key);
this->value = strdup(other.value);
}
mosquitto_auth_opt::~mosquitto_auth_opt()
{
if (key)
delete key;
if (value)
delete value;
}
mosquitto_auth_opt &mosquitto_auth_opt::operator=(const mosquitto_auth_opt &other)
{
if (key)
delete key;
if (value)
delete value;
this->key = strdup(other.key);
this->value = strdup(other.value);
return *this;
}
AuthOptCompatWrap::AuthOptCompatWrap(const std::unordered_map<std::string, std::string> &authOpts)
{
for(auto &pair : authOpts)
{
mosquitto_auth_opt opt(pair.first, pair.second);
optArray.push_back(std::move(opt));
}
}