From 591705f897df0b33b11b36bff2331df04c02c184 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Thu, 7 May 2020 10:20:22 -0700 Subject: [PATCH] More development on the messaging. --- IMFMessage.cpp | 2 +- IMFMessage.h | 12 ++++++------ IMFRequest.cpp | 6 +----- PString.cpp | 5 +++-- PString.h | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/IMFMessage.cpp b/IMFMessage.cpp index 34b605f..bfbbce9 100644 --- a/IMFMessage.cpp +++ b/IMFMessage.cpp @@ -13,7 +13,7 @@ namespace coreutils { } void IMFMessage::parse(PString &in) { - coreutils::Log(coreutils::LOG_DEBUG_4) << "[" << in.str() << "]"; + coreutils::Log(coreutils::LOG_DEBUG_4) << "parse [" << in.str() << "]"; if(in.size() == 0) return; diff --git a/IMFMessage.h b/IMFMessage.h index 904edd3..6f54d60 100644 --- a/IMFMessage.h +++ b/IMFMessage.h @@ -9,22 +9,22 @@ namespace coreutils { class IMFMessage { - + public: IMFMessage(); IMFMessage(PString &in); - + void parse(PString &in); void output(std::stringstream &out); IMFRequest *request; - + void addHeader(std::string key, std::string value); - + std::string getHeader(std::string key, bool valueOnly = true); std::string getHeaderKeyPairValue(std::string headerKey, std::string key); - - IMFBody *getBody(); + + IMFBody *getBody(); protected: std::vector headers; diff --git a/IMFRequest.cpp b/IMFRequest.cpp index 76e70e6..6ae2a68 100644 --- a/IMFRequest.cpp +++ b/IMFRequest.cpp @@ -13,12 +13,8 @@ namespace coreutils { uri = in.getTokenExclude(" "); if(!in.ifNext(" ")) throw coreutils::Exception("Expecting space after URI."); - protocol = in.getTokenExclude("\r"); + protocol = in.str(); - coreutils::Log(coreutils::LOG_DEBUG_4) << "[" << in.str() << "]"; - - if(!in.ifNext("\r")) - throw coreutils::Exception("Expecting CRLF after protocol."); } std::string IMFRequest::getMethod() { diff --git a/PString.cpp b/PString.cpp index d60f763..f3f91aa 100644 --- a/PString.cpp +++ b/PString.cpp @@ -31,7 +31,7 @@ namespace coreutils { while(pos < pstring.length()) { end = pstring.find(delimiter, pos); - if(end == std::string::npos) + if(end == -1) end = pstring.length(); list.push_back(PString(pstring.substr(pos, end - pos))); pos = end + delimiter.size(); @@ -78,7 +78,8 @@ namespace coreutils { int PString::skipWhitespace() { size_t found = pstring.find_first_not_of(" \t", cursor); - return found != cursor::npos ? cursor + found: 0; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Skipping whitespace for " << found << " spaces."; + return found; } int PString::size() { diff --git a/PString.h b/PString.h index ed26353..11611e2 100644 --- a/PString.h +++ b/PString.h @@ -82,7 +82,7 @@ namespace coreutils { /// /// - void skipWhitespace(); + int skipWhitespace(); /// ///