Got it compiling and somewhat working, except post.

This commit is contained in:
Brad Arant 2020-11-29 13:58:17 -08:00
parent 41852d019c
commit b6f4bf8a71
8 changed files with 69 additions and 38 deletions

View File

@ -1,5 +1,6 @@
#include "IMFHeader.h"
#include "Exception.h"
#include "Log.h"
namespace coreutils {
@ -8,25 +9,18 @@ namespace coreutils {
}
IMFHeader::IMFHeader(PString &in) {
printf("in='%s'\n", in.str().c_str());
key = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-0123456789");
if(key.length() != 0) {
if(!in.ifNext(":")) {
printf("key=%s %02X\n", key.c_str(), in.str()[0]);
throw coreutils::Exception("Invalid character in expected header token.");
}
in.skipWhitespace();
value = in.str();
if(!in.ifNext(":")) {
printf("key=%s %02X\n", key.c_str(), in.str()[0]);
throw coreutils::Exception("Invalid character in expected header token.");
}
in.skipWhitespace();
value = in.goeol();
}
else if(in.skipWhitespace() > 0) {
}
else if(in.str() == "") {
}
else if(in.skipWhitespace() > 0) {}
else if(in.str() == "") {}
coreutils::Log(coreutils::LOG_DEBUG_2) << " " << key << "[" << value << "]";
}
IMFHeader::IMFHeader(std::string key, std::string value) {

View File

@ -16,26 +16,24 @@ namespace coreutils {
bool IMFMessage::parse(PString &in) {
coreutils::Log(coreutils::LOG_DEBUG_4) << "parse [" << in.str() << "]";
if(in.str() != "") {
while (!in.ifNext("\r\n")) {
headers.emplace_back(in);
return true;
}
coreutils::Log(coreutils::LOG_DEBUG_2) << "End of header with Content Type = " << getHeader("Content-Type") << " for " << getHeader("Content-Length") << " bytes.";
std::string type = getHeader("Content-Type");
std::stringstream length(getHeader("Content-Length"));
int len = 0;
length >> len;
if(len > 0) {
PString block = in.readBlock(len);
if(type == "multipart/form-data")
body = new IMFMultipart(block, getHeaderKeyPairValue("Content-Type", "boundary"));
else if(type == "text/plain")
body = new IMFPlainText(in);
else
body = new IMFBody();
if(type.size() == 0)
type = "text/plain";
if(type == "multipart/form-data")
body = new IMFMultipart(in, getHeaderKeyPairValue("Content-Type", "boundary"));
else if(type == "text/plain")
body = new IMFPlainText(in);
else
body = new IMFBody();
}
return false;
}

View File

@ -25,7 +25,7 @@ namespace coreutils {
IMFBody *getBody();
// protected:
protected:
std::vector<IMFHeader> headers;
IMFBody *body;

View File

@ -1,3 +1,4 @@
#include <string>
#include "IMFRequest.h"
#include "Exception.h"
#include "Log.h"
@ -7,7 +8,13 @@ namespace coreutils {
IMFRequest::IMFRequest() {}
IMFRequest::IMFRequest(PString &in) {
parts = in.split(" ");
coreutils::PString request = in.goeol();
parts = request.split(" ");
}
void IMFRequest::parse(PString &in) {
coreutils::PString request = in.goeol();
parts = request.split(" ");
}
std::string IMFRequest::getMethod() {

View File

@ -11,6 +11,8 @@ namespace coreutils {
IMFRequest();
IMFRequest(PString &in);
void parse(PString &in);
std::string getMethod();
std::string getURI();
std::string getProtocol();

View File

@ -18,12 +18,16 @@ namespace coreutils {
return pstring.substr(cursor);
}
std::string PString::str(int len) {
return pstring.substr(cursor, len);
}
std::vector<PString> PString::split(std::string delimiter, int maxSize) {
list.clear();
if(pstring.size() == 0) {
list.push_back(PString(""));
return list;
list.push_back(PString(""));
return list;
}
size_t end;
@ -80,10 +84,23 @@ namespace coreutils {
size_t temp = cursor;
cursor = pstring.find_first_not_of(" \t", cursor);
cursor = cursor == -1 ? temp: cursor;
coreutils::Log(coreutils::LOG_DEBUG_2) << "Skipping whitespace for " << (cursor - temp) << " spaces.";
return cursor - temp;
}
std::string PString::goeol() {
size_t temp = cursor;
cursor = pstring.find_first_of("\r\n", cursor);
std::string value = pstring.substr(temp, (cursor - temp));
if(pstring[cursor] == '\r')
++cursor;
cursor = cursor == -1 ? temp: ++cursor;
return value;
}
std::string PString::readBlock(size_t size) {
printf(">>>>>: %i:%i", size, pstring.size() - cursor);
}
int PString::size() {
return pstring.size() - cursor;
}

View File

@ -42,6 +42,13 @@ namespace coreutils {
std::string str();
///
/// Return the current value of the PString as a string of
/// specified length.
///
std::string str(int len);
///
///
///
@ -88,6 +95,12 @@ namespace coreutils {
///
///
std::string goeol();
///
///
///
int cursor = 0;
///