diff --git a/message.cpp b/message.cpp index 19f9f34..1e908cc 100644 --- a/message.cpp +++ b/message.cpp @@ -31,57 +31,68 @@ std::string Decode(const std::string& data) void message::processMessage(const std::string& message) { - message::state::type state = message::state::header; - std::string line; - std::istringstream stream(message); - while (std::getline(stream, line, '\r')) + try { - boost::erase_all(line, "\n"); - switch (state) + std::cout << "message::processMessage enter" << std::endl; + message::state::type state = message::state::header; + std::string line; + std::istringstream stream(message); + while (std::getline(stream, line, '\r')) { - case state::header: - state = processHeaderLine(line); - break; - case state::data: - state = processDataLine(line); - break; - case state::mimeBoundary: - state = processMimeBoundary(line); - break; - case state::image: - state = processImage(line); - break; + boost::erase_all(line, "\n"); + switch (state) + { + case state::header: + state = processHeaderLine(line); + break; + case state::data: + state = processDataLine(line); + break; + case state::mimeBoundary: + state = processMimeBoundary(line); + 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()); } } - - if (boost::algorithm::contains(m_contentEncoding, "base64")) + catch (std::exception& e) { - std::string decoded = Decode(m_subject); - if (decoded.size() > 0) - m_subject = decoded; + std::cout << "Exception: " << e.what() << std::endl; + std::cerr << "Exception: " << e.what() << std::endl; } - 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()); - } + std::cout << "message::processMessage exit" << std::endl; } message::state::type message::processHeaderLine(const std::string& line) diff --git a/protocol.cpp b/protocol.cpp index 327b522..4c56e01 100644 --- a/protocol.cpp +++ b/protocol.cpp @@ -13,7 +13,7 @@ protocol::result protocol::openConnection(const std::string& address) { m_address = address; 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"); } @@ -25,15 +25,18 @@ protocol::result protocol::processMessage(const std::string& message) if (boost::iends_with(message, ".\r\n")) { + std::cout << "-> " << " . " << std::endl; ::message msg(m_address, m_context, m_message); + std::cout << "-> " << " . " << std::endl; m_internalState = internalState::helo; + std::cout << "-> " << " . " << std::endl; return answer(protocol::state::connected, "250 Ok"); } return answer(protocol::state::connected, ""); } - //std::cout << "-> " << message << std::endl; + std::cout << "-> " << message << std::endl; 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 { -/* if (answer.size() > 0) std::cout << "<- " << answer << std::endl; -*/ return result(state, answer); }