Catch exceptions and add logging
This commit is contained in:
+55
-44
@@ -31,57 +31,68 @@ std::string Decode(const std::string& data)
|
|||||||
|
|
||||||
void message::processMessage(const std::string& message)
|
void message::processMessage(const std::string& message)
|
||||||
{
|
{
|
||||||
message::state::type state = message::state::header;
|
try
|
||||||
std::string line;
|
|
||||||
std::istringstream stream(message);
|
|
||||||
while (std::getline(stream, line, '\r'))
|
|
||||||
{
|
{
|
||||||
boost::erase_all(line, "\n");
|
std::cout << "message::processMessage enter" << std::endl;
|
||||||
switch (state)
|
message::state::type state = message::state::header;
|
||||||
|
std::string line;
|
||||||
|
std::istringstream stream(message);
|
||||||
|
while (std::getline(stream, line, '\r'))
|
||||||
{
|
{
|
||||||
case state::header:
|
boost::erase_all(line, "\n");
|
||||||
state = processHeaderLine(line);
|
switch (state)
|
||||||
break;
|
{
|
||||||
case state::data:
|
case state::header:
|
||||||
state = processDataLine(line);
|
state = processHeaderLine(line);
|
||||||
break;
|
break;
|
||||||
case state::mimeBoundary:
|
case state::data:
|
||||||
state = processMimeBoundary(line);
|
state = processDataLine(line);
|
||||||
break;
|
break;
|
||||||
case state::image:
|
case state::mimeBoundary:
|
||||||
state = processImage(line);
|
state = processMimeBoundary(line);
|
||||||
break;
|
break;
|
||||||
|
case state::image:
|
||||||
|
state = processImage(line);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (boost::algorithm::contains(m_contentEncoding, "base64"))
|
||||||
|
{
|
||||||
|
std::string decoded = Decode(m_subject);
|
||||||
|
if (decoded.size() > 0)
|
||||||
|
m_subject = decoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
outputImage image(m_images);
|
||||||
|
|
||||||
|
boost::filesystem::path path(m_context.path);
|
||||||
|
path = boost::filesystem::canonical(path);
|
||||||
|
path /= m_address;
|
||||||
|
|
||||||
|
if (!boost::filesystem::exists(path))
|
||||||
|
boost::filesystem::create_directory(path);
|
||||||
|
|
||||||
|
std::string fileName(getTimeString());
|
||||||
|
fileName.append(".jpg");
|
||||||
|
path /= fileName;
|
||||||
|
|
||||||
|
image.save(path.string());
|
||||||
|
|
||||||
|
if (!m_context.url.empty())
|
||||||
|
{
|
||||||
|
std::stringstream url;
|
||||||
|
url << m_context.url << "?ip=" << m_address << "&file=" << fileName;
|
||||||
|
m_context.client.GetUrlContents(url.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
if (boost::algorithm::contains(m_contentEncoding, "base64"))
|
|
||||||
{
|
{
|
||||||
std::string decoded = Decode(m_subject);
|
std::cout << "Exception: " << e.what() << std::endl;
|
||||||
if (decoded.size() > 0)
|
std::cerr << "Exception: " << e.what() << std::endl;
|
||||||
m_subject = decoded;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outputImage image(m_images);
|
std::cout << "message::processMessage exit" << std::endl;
|
||||||
|
|
||||||
boost::filesystem::path path(m_context.path);
|
|
||||||
path = boost::filesystem::canonical(path);
|
|
||||||
path /= m_address;
|
|
||||||
|
|
||||||
if (!boost::filesystem::exists(path))
|
|
||||||
boost::filesystem::create_directory(path);
|
|
||||||
|
|
||||||
std::string fileName(getTimeString());
|
|
||||||
fileName.append(".jpg");
|
|
||||||
path /= fileName;
|
|
||||||
|
|
||||||
image.save(path.string());
|
|
||||||
|
|
||||||
if (!m_context.url.empty())
|
|
||||||
{
|
|
||||||
std::stringstream url;
|
|
||||||
url << m_context.url << "?ip=" << m_address << "&file=" << fileName;
|
|
||||||
m_context.client.GetUrlContents(url.str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message::state::type message::processHeaderLine(const std::string& line)
|
message::state::type message::processHeaderLine(const std::string& line)
|
||||||
|
|||||||
+5
-4
@@ -13,7 +13,7 @@ protocol::result protocol::openConnection(const std::string& address)
|
|||||||
{
|
{
|
||||||
m_address = address;
|
m_address = address;
|
||||||
m_internalState = internalState::connect;
|
m_internalState = internalState::connect;
|
||||||
//std::cout << "Connection from " << address << std::endl;
|
std::cout << "Connection from " << address << std::endl;
|
||||||
return answer(protocol::state::connected, "220 AlarmServer");
|
return answer(protocol::state::connected, "220 AlarmServer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,15 +25,18 @@ protocol::result protocol::processMessage(const std::string& message)
|
|||||||
|
|
||||||
if (boost::iends_with(message, ".\r\n"))
|
if (boost::iends_with(message, ".\r\n"))
|
||||||
{
|
{
|
||||||
|
std::cout << "-> " << " . " << std::endl;
|
||||||
::message msg(m_address, m_context, m_message);
|
::message msg(m_address, m_context, m_message);
|
||||||
|
std::cout << "-> " << " . " << std::endl;
|
||||||
m_internalState = internalState::helo;
|
m_internalState = internalState::helo;
|
||||||
|
std::cout << "-> " << " . " << std::endl;
|
||||||
return answer(protocol::state::connected, "250 Ok");
|
return answer(protocol::state::connected, "250 Ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
return answer(protocol::state::connected, "");
|
return answer(protocol::state::connected, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
//std::cout << "-> " << message << std::endl;
|
std::cout << "-> " << message << std::endl;
|
||||||
|
|
||||||
if (m_internalState == internalState::auth_login_user)
|
if (m_internalState == internalState::auth_login_user)
|
||||||
{
|
{
|
||||||
@@ -95,10 +98,8 @@ protocol::result protocol::processMessage(const std::string& message)
|
|||||||
|
|
||||||
protocol::result protocol::answer(protocol::state::type state, std::string answer) const
|
protocol::result protocol::answer(protocol::state::type state, std::string answer) const
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
if (answer.size() > 0)
|
if (answer.size() > 0)
|
||||||
std::cout << "<- " << answer << std::endl;
|
std::cout << "<- " << answer << std::endl;
|
||||||
*/
|
|
||||||
|
|
||||||
return result(state, answer);
|
return result(state, answer);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user