Skip to content

Commit

Permalink
Merge pull request #3 from domoticz/master
Browse files Browse the repository at this point in the history
Updating from master
  • Loading branch information
corbinmunce committed Jul 29, 2017
2 parents 68e1e59 + 0589999 commit 1386b1b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 49 deletions.
2 changes: 1 addition & 1 deletion hardware/XiaomiGateway.cpp
Expand Up @@ -301,7 +301,7 @@ void XiaomiGateway::InsertUpdatePressure(const std::string &nodeid, const std::s
std::stringstream ss;
ss << std::hex << str.c_str();
ss >> sID;
SendPressureSensor(sID, 1, battery, Pressure, Name.c_str());
SendPressureSensor(sID, 1, battery, static_cast<float>(Pressure), Name.c_str());
}

void XiaomiGateway::InsertUpdateRGBGateway(const std::string & nodeid, const std::string & Name, const bool bIsOn, const int brightness, const int hue)
Expand Down
2 changes: 1 addition & 1 deletion msbuild/domoticz.vcxproj
Expand Up @@ -14,7 +14,7 @@
<ProjectGuid>{6AD96441-5B2C-467B-AAB6-A1B8368D503A}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>domoticz</RootNamespace>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down
2 changes: 1 addition & 1 deletion notifications/NotificationGCM.cpp
Expand Up @@ -9,7 +9,7 @@
#define GAPI_POST_URL "https://gcm-http.googleapis.com/gcm/send"
#define GAPI "AIzaSyBnRMroiDaXCKbwPeOmoxkNiQfjWkGMre8"

CNotificationGCM::CNotificationGCM() : CNotificationBase(std::string("gcm"), OPTIONS_URL_SUBJECT | OPTIONS_URL_BODY | OPTIONS_URL_PARAMS)
CNotificationGCM::CNotificationGCM() : CNotificationBase(std::string("gcm"), OPTIONS_NONE)
{
SetupConfig(std::string("GCMEnabled"), &m_IsEnabled);
}
Expand Down
77 changes: 38 additions & 39 deletions tcpserver/TCPServer.cpp
Expand Up @@ -58,69 +58,68 @@ bool CTCPServerInt::IsUserHereFirstTime(const std::string &ip_string)
// Log same IP-address first time and then once per day
//
time_t now = mytime(NULL);
bool log_this = true;

for(int i = 0; i < m_incoming_domoticz_history.size(); i++)
std::vector<_tTCPLogInfo>::iterator itt = m_incoming_domoticz_history.begin();
while (itt!= m_incoming_domoticz_history.end())
{
log_info li = m_incoming_domoticz_history[i];
double elapsed_seconds = now - li.time;

if (elapsed_seconds > SECONDS_PER_DAY)
if (difftime(now,itt->time) > SECONDS_PER_DAY)
{
m_incoming_domoticz_history.erase(m_incoming_domoticz_history.begin()+i);
itt = m_incoming_domoticz_history.erase(itt);
}
else
{
if (ip_string.compare(li.string) == 0)
if (ip_string.compare(itt->string) == 0)
{
log_this = false;
//already logged this
return false;
}
++itt;
}
}
if (m_incoming_domoticz_history.size() > 100)
return false; //just to be safe

if (log_this)
{
log_info li;
li.time = now;
li.string = ip_string;
m_incoming_domoticz_history.push_back(li);
}

return log_this;
_tTCPLogInfo li;
li.time = now;
li.string = ip_string;
m_incoming_domoticz_history.push_back(li);
return true;
}

void CTCPServerInt::handleAccept(const boost::system::error_code& error)
{
if(!error) // 1.
{
boost::lock_guard<boost::mutex> l(connectionMutex);
std::string s = new_connection_->socket()->remote_endpoint().address().to_string();
if (error)
return;
boost::lock_guard<boost::mutex> l(connectionMutex);
std::string s = new_connection_->socket()->remote_endpoint().address().to_string();

if (s.substr(0, 7) == "::ffff:") {
s = s.substr(7);
}
if (s.substr(0, 7) == "::ffff:") {
s = s.substr(7);
}

new_connection_->m_endpoint=s;
new_connection_->m_endpoint=s;

if (IsUserHereFirstTime(s))
{
_log.Log(LOG_STATUS, "Incoming Domoticz connection from: %s", s.c_str());
}
else
if (IsUserHereFirstTime(s))
{
_log.Log(LOG_STATUS, "Incoming Domoticz connection from: %s", s.c_str());
}
else
{
if (_log.isTraceEnabled())
{
_log.Log(LOG_TRACE, "Incoming Domoticz connection from: %s", s.c_str());
}
}

connections_.insert(new_connection_);
new_connection_->start();
connections_.insert(new_connection_);
new_connection_->start();

new_connection_.reset(new CTCPClient(io_service_, this));
new_connection_.reset(new CTCPClient(io_service_, this));

acceptor_.async_accept(
*(new_connection_->socket()),
boost::bind(&CTCPServerInt::handleAccept, this,
boost::asio::placeholders::error));
}
acceptor_.async_accept(
*(new_connection_->socket()),
boost::bind(&CTCPServerInt::handleAccept, this,
boost::asio::placeholders::error));
}

_tRemoteShareUser* CTCPServerIntBase::FindUser(const std::string &username)
Expand Down
13 changes: 6 additions & 7 deletions tcpserver/TCPServer.h
Expand Up @@ -30,12 +30,6 @@ struct _tRemoteMessage
//data
};

struct log_info
{
time_t time;
std::string string;
};

class CTCPServerIntBase
{
public:
Expand All @@ -53,6 +47,11 @@ class CTCPServerIntBase
std::vector<_tRemoteShareUser> GetRemoteUsers();
unsigned int GetUserDevicesCount(const std::string &username);
protected:
struct _tTCPLogInfo
{
time_t time;
std::string string;
};

_tRemoteShareUser* FindUser(const std::string &username);

Expand Down Expand Up @@ -92,7 +91,7 @@ class CTCPServerInt : public CTCPServerIntBase {
CTCPClient_ptr new_connection_;

bool IsUserHereFirstTime(const std::string &ip_string);
std::vector<log_info> m_incoming_domoticz_history;
std::vector<_tTCPLogInfo> m_incoming_domoticz_history;
};

#ifndef NOCLOUD
Expand Down

0 comments on commit 1386b1b

Please sign in to comment.