Got it compiling and somewhat working, except post.
This commit is contained in:
parent
41852d019c
commit
b6f4bf8a71
@ -1,5 +1,6 @@
|
||||
#include "IMFHeader.h"
|
||||
#include "Exception.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace coreutils {
|
||||
|
||||
@ -8,7 +9,6 @@ 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(":")) {
|
||||
@ -16,17 +16,11 @@ namespace coreutils {
|
||||
throw coreutils::Exception("Invalid character in expected header token.");
|
||||
}
|
||||
in.skipWhitespace();
|
||||
value = in.str();
|
||||
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) {
|
||||
|
@ -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");
|
||||
|
||||
if(type.size() == 0)
|
||||
type = "text/plain";
|
||||
|
||||
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(in, getHeaderKeyPairValue("Content-Type", "boundary"));
|
||||
body = new IMFMultipart(block, getHeaderKeyPairValue("Content-Type", "boundary"));
|
||||
else if(type == "text/plain")
|
||||
body = new IMFPlainText(in);
|
||||
else
|
||||
body = new IMFBody();
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ namespace coreutils {
|
||||
|
||||
IMFBody *getBody();
|
||||
|
||||
// protected:
|
||||
protected:
|
||||
std::vector<IMFHeader> headers;
|
||||
IMFBody *body;
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -11,6 +11,8 @@ namespace coreutils {
|
||||
IMFRequest();
|
||||
IMFRequest(PString &in);
|
||||
|
||||
void parse(PString &in);
|
||||
|
||||
std::string getMethod();
|
||||
std::string getURI();
|
||||
std::string getProtocol();
|
||||
|
19
PString.cpp
19
PString.cpp
@ -18,6 +18,10 @@ 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();
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
13
PString.h
13
PString.h
@ -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;
|
||||
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user