Skip to content

Commit

Permalink
Merge pull request #6 from ewsi/master
Browse files Browse the repository at this point in the history
Prep v1.1.0 release
  • Loading branch information
csonsino authored Oct 7, 2019
2 parents 4764e9b + 5ae511a commit 0cd8309
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 52 deletions.
28 changes: 13 additions & 15 deletions dcw/controller.cxx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

#include "./controller.h"
#include "./message.h"
#include "./macaddress.h"
#include "./message.h"

#include "./dcwlog.h"


#include <string.h>

#include <cstring>
#include <exception>

namespace {
Expand All @@ -16,7 +14,7 @@ struct UnhandledMessageTypeException : public std::exception {
return "Unhandled message type";
}
};
};
} // namespace

using namespace dcw;

Expand Down Expand Up @@ -119,15 +117,15 @@ void Controller::OnStationJoin(const MacAddress& primaryMacAddr, const Message&
//retrieve our network configuration and validate that
//we have at least one data ssid
_network.GetDataChannels(apDataChannels);
if (apDataChannels.size() > 0) {
if (!apDataChannels.empty()) {
//call upon the device policy to filter out if needed...
_devicePolicy.FilterPermittedDataChannels(primaryMacAddr, m.data_macaddr_count, apDataChannels);
}
if (apDataChannels.size() == 0) {
if (apDataChannels.empty()) {
dcwlogwarnf("Got a station join request from %s, but no data SSIDs are available in the network\n", primaryMacAddr.ToString().c_str());
Message reply(DCWMSG_AP_REJECT_STA);
reply.ap_reject_sta.data_macaddr_count = m.data_macaddr_count;
memcpy(reply.ap_reject_sta.data_macaddrs, m.data_macaddrs, m.data_macaddr_count * 6);
std::memcpy(reply.ap_reject_sta.data_macaddrs, m.data_macaddrs, m.data_macaddr_count * 6);
ReplyToStation(primaryMacAddr, reply);
return;
}
Expand All @@ -145,7 +143,7 @@ void Controller::OnStationJoin(const MacAddress& primaryMacAddr, const Message&
unsigned i = 0;
for (apdc_iter = apDataChannels.begin(); apdc_iter != apDataChannels.end(); ++apdc_iter, i++) {
state.permittedChannels[(*apdc_iter)->GetSsidName()] = *apdc_iter;
strncpy(reply.ap_accept_sta.data_ssids[i], (*apdc_iter)->GetSsidName(), sizeof(reply.ap_accept_sta.data_ssids[i]));
std::strncpy(reply.ap_accept_sta.data_ssids[i], (*apdc_iter)->GetSsidName(), sizeof(reply.ap_accept_sta.data_ssids[i]));
}

//reply back to the station letting it know which
Expand Down Expand Up @@ -195,7 +193,7 @@ void Controller::OnStationUnjoin(const MacAddress& primaryMacAddr, const Message
//remove any channel bondings matching the provided data channel mac addresses
for (unsigned i = 0; i < m.data_macaddr_count; i++) {
const ::dcw::MacAddress dcaddr(m.data_macaddrs[i]);
const ::dcw::TrafficPolicy::DataChannelMap::iterator dcmEntry = state.policy.dataChannels.find(dcaddr);
::dcw::TrafficPolicy::DataChannelMap::iterator dcmEntry = state.policy.dataChannels.find(dcaddr);
if (dcmEntry == state.policy.dataChannels.end()) continue;
if (dcmEntry->second == NULL) {
dcwlogwarnf("Data channel MAC address %s on client %s is not currently bonded\n", dcaddr.ToString().c_str(), primaryMacAddr.ToString().c_str());
Expand Down Expand Up @@ -238,13 +236,13 @@ void Controller::OnStationAck(const MacAddress& primaryMacAddr, const Message& m
dcwlogdbgf("Got a station ACK from %s\n", primaryMacAddr.ToString().c_str());

// first make sure this client has actually sent a join first...
const ClientStateMap::iterator client = _clients.find(primaryMacAddr);
ClientStateMap::iterator client = _clients.find(primaryMacAddr);
if (client == _clients.end()) {
dcwlogerrf("Got a client ACK without a station join from %s\n", primaryMacAddr.ToString().c_str());
Message reply(DCWMSG_AP_REJECT_STA);
reply.ap_reject_sta.data_macaddr_count = m.bonded_data_channel_count;
for (unsigned i = 0; i < reply.ap_reject_sta.data_macaddr_count; i++) {
memcpy(reply.ap_reject_sta.data_macaddrs[i], m.bonded_data_channels[i].macaddr, sizeof(reply.ap_reject_sta.data_macaddrs[i]));
std::memcpy(reply.ap_reject_sta.data_macaddrs[i], m.bonded_data_channels[i].macaddr, sizeof(reply.ap_reject_sta.data_macaddrs[i]));
}
ReplyToStation(primaryMacAddr, reply);
return;
Expand All @@ -262,7 +260,7 @@ void Controller::OnStationAck(const MacAddress& primaryMacAddr, const Message& m
Message reply(DCWMSG_AP_REJECT_STA);
reply.ap_reject_sta.data_macaddr_count = m.bonded_data_channel_count;
for (unsigned i = 0; i < reply.ap_reject_sta.data_macaddr_count; i++) {
memcpy(reply.ap_reject_sta.data_macaddrs[i], m.bonded_data_channels[i].macaddr, sizeof(reply.ap_reject_sta.data_macaddrs[i]));
std::memcpy(reply.ap_reject_sta.data_macaddrs[i], m.bonded_data_channels[i].macaddr, sizeof(reply.ap_reject_sta.data_macaddrs[i]));
}
ReplyToStation(primaryMacAddr, reply);
return;
Expand All @@ -274,7 +272,7 @@ void Controller::OnStationAck(const MacAddress& primaryMacAddr, const Message& m
Message reply(DCWMSG_AP_REJECT_STA);
reply.ap_reject_sta.data_macaddr_count = m.bonded_data_channel_count;
for (unsigned i = 0; i < reply.ap_reject_sta.data_macaddr_count; i++) {
memcpy(reply.ap_reject_sta.data_macaddrs[i], m.bonded_data_channels[i].macaddr, sizeof(reply.ap_reject_sta.data_macaddrs[i]));
std::memcpy(reply.ap_reject_sta.data_macaddrs[i], m.bonded_data_channels[i].macaddr, sizeof(reply.ap_reject_sta.data_macaddrs[i]));
}
ReplyToStation(primaryMacAddr, reply);
return;
Expand Down Expand Up @@ -309,7 +307,7 @@ void Controller::OnStationNack(const MacAddress& primaryMacAddr, const Message&

dcwlogdbgf("Got a station NACK from %s Processing as unjoin\n", primaryMacAddr.ToString().c_str());
m_dst.data_macaddr_count = m_src.data_macaddr_count;
memcpy(m_dst.data_macaddrs, m_src.data_macaddrs, sizeof(m_dst.data_macaddrs));
std::memcpy(m_dst.data_macaddrs, m_src.data_macaddrs, sizeof(m_dst.data_macaddrs));
this->OnStationUnjoin(primaryMacAddr, unjoinMsg);
// XXX WARNING: THIS PROBABLY SHOULD NOT SEND THE DCWMSG_AP_ACK_DISCONNECT AS THE UNJOIN DOES!!
}
Expand Down
11 changes: 5 additions & 6 deletions dcw/filetrafficfilterprofile.cxx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

#include "./filetrafficfilterprofile.h"

#include <string.h>
#include <errno.h>

#include <cerrno>
#include <cstring>
#include <exception>

namespace {
Expand All @@ -15,11 +14,11 @@ struct FOpenFailedException : public std::exception {
msg = "fopen(";
msg += filename;
msg = ") failed: ";
msg += strerror(errno);
msg += std::strerror(errno);

return msg;
}
FOpenFailedException(const char * const filename) :
explicit FOpenFailedException(const char * const filename) :
_msg(GenMsg(filename)) {
//
}
Expand All @@ -28,7 +27,7 @@ struct FOpenFailedException : public std::exception {
return _msg.c_str();
}
};
};
} // namespace

using namespace dcw;

Expand Down
34 changes: 17 additions & 17 deletions dcw/macaddress.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include "./macaddress.h"

#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>

#include <exception>

Expand All @@ -14,27 +14,27 @@ struct MacAddressParseException : public std::exception {
return "MAC Address Parse Exception";
}
};
};
} // namespace

using namespace dcw;


MacAddress::MacAddress() {
memset(this->Value, 0xFF, sizeof(this->Value));
std::memset(this->Value, 0xFF, sizeof(this->Value));
}

MacAddress::MacAddress(const MacAddress& rhv) {
memcpy(this->Value, rhv.Value, sizeof(this->Value));
std::memcpy(this->Value, rhv.Value, sizeof(this->Value));
}

MacAddress::MacAddress(const char * const macStr) {
unsigned octets[6];

if (sscanf(macStr, "%X-%X-%X-%X-%X-%X",
if (std::sscanf(macStr, "%X-%X-%X-%X-%X-%X",
&octets[0], &octets[1],&octets[2],
&octets[3],&octets[4],&octets[5]) != 6) {
// failed to parse with dashes... try colons...
if (sscanf(macStr, "%X:%X:%X:%X:%X:%X",
if (std::sscanf(macStr, "%X:%X:%X:%X:%X:%X",
&octets[0], &octets[1],&octets[2],
&octets[3],&octets[4],&octets[5]) != 6) {
// failed to parse... throw exception...
Expand All @@ -43,36 +43,36 @@ MacAddress::MacAddress(const char * const macStr) {
}

for (int i = 0; i < 6; i++)
this->Value[i] = (unsigned char)octets[i];
this->Value[i] = static_cast<unsigned char>(octets[i]);
}

MacAddress::MacAddress(const unsigned char * const value) {
memcpy(this->Value, value, sizeof(this->Value));
std::memcpy(this->Value, value, sizeof(this->Value));
}

MacAddress::~MacAddress() {
//
}

bool MacAddress::operator<(const MacAddress& rhv) const {
return memcmp(Value, rhv.Value, sizeof(Value)) < 0;
return std::memcmp(Value, rhv.Value, sizeof(Value)) < 0;
}

bool MacAddress::operator==(const MacAddress& rhv) const {
if (this == &rhv) return true;
return memcmp(Value, rhv.Value, sizeof(Value)) == 0;
return std::memcmp(Value, rhv.Value, sizeof(Value)) == 0;
}

std::string MacAddress::ToString() const {
char macStr[24];

snprintf(macStr, sizeof(macStr), "%02X:%02X:%02X:%02X:%02X:%02X",
(unsigned)this->Value[0],
(unsigned)this->Value[1],
(unsigned)this->Value[2],
(unsigned)this->Value[3],
(unsigned)this->Value[4],
(unsigned)this->Value[5]
static_cast<unsigned>(this->Value[0]),
static_cast<unsigned>(this->Value[1]),
static_cast<unsigned>(this->Value[2]),
static_cast<unsigned>(this->Value[3]),
static_cast<unsigned>(this->Value[4]),
static_cast<unsigned>(this->Value[5])
);
return std::string(macStr);
}
Expand Down
6 changes: 3 additions & 3 deletions dcw/message.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include "./message.h"

#include <string.h>
#include <cstring>

#include <exception>

Expand All @@ -17,7 +17,7 @@ struct MessageSerializeException : public std::exception {
return "Failed to serialize DCW message from buffer!";
}
};
};
} // namespace


using namespace dcw;
Expand All @@ -34,7 +34,7 @@ Message::Message(const Message& rhv) {
const struct dcwmsg *rhv_m = &rhv;
struct dcwmsg *lhv_m = this;

memcpy(lhv_m, rhv_m, sizeof(struct dcwmsg));
std::memcpy(lhv_m, rhv_m, sizeof(struct dcwmsg));
}


Expand Down
9 changes: 4 additions & 5 deletions dcw/stringtrafficfilterprofile.cxx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

#include "./stringtrafficfilterprofile.h"

#include <string.h>
#include <errno.h>

#include <cerrno>
#include <cstring>
#include <exception>

namespace {
Expand All @@ -13,7 +12,7 @@ struct FMemOpenFailedException : public std::exception {
std::string msg;

msg = "fmemopen() failed: ";
msg += strerror(errno);
msg += std::strerror(errno);

return msg;
}
Expand All @@ -26,7 +25,7 @@ struct FMemOpenFailedException : public std::exception {
return _msg.c_str();
}
};
};
} // namespace


using namespace dcw;
Expand Down
4 changes: 2 additions & 2 deletions dcwlinux/include/rapidjson/rapidjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ RAPIDJSON_NAMESPACE_END
#else
#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
#endif
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
(defined(_MSC_VER) && _MSC_VER >= 1600)
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__) && \
(!defined __UCLIBCXX_MAJOR__)) || (defined(_MSC_VER) && _MSC_VER >= 1600)

#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
#else
Expand Down
2 changes: 1 addition & 1 deletion dcwlinux/macremapper_driver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void MacRemapperDriver::ApplyClientTrafficPolicy(const dcw::MacAddress& primaryA
}

//populate our remap ioctl()
bzero(&re, sizeof(re));
memset(&re, 0, sizeof(re));
strncpy(re.filter_name, policy.trafficFilterProfile->GetName(), sizeof(re.filter_name));
memcpy(re.match_macaddr, primaryAddr.Value, sizeof(re.match_macaddr));

Expand Down
4 changes: 2 additions & 2 deletions dcwposix/processsignalmanager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ProcessSignalManager::~ProcessSignalManager() {
}

void ProcessSignalManager::RegisterEventHandler(const int signum, ::dcwposix::ProcessSignalManager::EventHandler& eventHandler) {
const SignalMap::iterator i = _sigmap.find(signum);
SignalMap::iterator i = _sigmap.find(signum);
if (i == _sigmap.end()) {
//be sure to preseve the old signal when inserting a new "unseen" signal
_sigmap[signum].insert(&eventHandler);
Expand All @@ -53,7 +53,7 @@ void ProcessSignalManager::RegisterEventHandler(const int signum, ::dcwposix::Pr
}

void ProcessSignalManager::UnRegisterEventHandler(const int signum, ::dcwposix::ProcessSignalManager::EventHandler& eventHandler) {
const SignalMap::iterator i = _sigmap.find(signum);
SignalMap::iterator i = _sigmap.find(signum);

if (i == _sigmap.end()) {
dcwlogwarnf("Attempting to unregister handler %p non-registered process signal #%d\n", &eventHandler, signum);
Expand Down
8 changes: 7 additions & 1 deletion dcwposix/selecteventreactor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include <unistd.h>
#include <sys/select.h>

#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 199309L
#endif
#include <time.h>

#include <exception>

namespace {
Expand Down Expand Up @@ -112,7 +117,8 @@ void SelectEventReactor::SleepSec(const unsigned seconds) const {
}

void SelectEventReactor::SleepMs(const unsigned milliseconds) const {
usleep(milliseconds * 1000);
struct timespec req = { 0, static_cast<long>(milliseconds) * 1000 * 1000};
nanosleep(&req, NULL);
}

void SelectEventReactor::updateNfds() {
Expand Down

0 comments on commit 0cd8309

Please sign in to comment.