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 "IMFHeader.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
namespace coreutils {
|
namespace coreutils {
|
||||||
|
|
||||||
@ -8,25 +9,18 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IMFHeader::IMFHeader(PString &in) {
|
IMFHeader::IMFHeader(PString &in) {
|
||||||
printf("in='%s'\n", in.str().c_str());
|
|
||||||
key = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-0123456789");
|
key = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-0123456789");
|
||||||
if(key.length() != 0) {
|
if(key.length() != 0) {
|
||||||
if(!in.ifNext(":")) {
|
if(!in.ifNext(":")) {
|
||||||
printf("key=%s %02X\n", key.c_str(), in.str()[0]);
|
printf("key=%s %02X\n", key.c_str(), in.str()[0]);
|
||||||
throw coreutils::Exception("Invalid character in expected header token.");
|
throw coreutils::Exception("Invalid character in expected header token.");
|
||||||
}
|
}
|
||||||
in.skipWhitespace();
|
in.skipWhitespace();
|
||||||
value = in.str();
|
value = in.goeol();
|
||||||
}
|
}
|
||||||
else if(in.skipWhitespace() > 0) {
|
else if(in.skipWhitespace() > 0) {}
|
||||||
|
else if(in.str() == "") {}
|
||||||
|
coreutils::Log(coreutils::LOG_DEBUG_2) << " " << key << "[" << value << "]";
|
||||||
|
|
||||||
}
|
|
||||||
else if(in.str() == "") {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IMFHeader::IMFHeader(std::string key, std::string value) {
|
IMFHeader::IMFHeader(std::string key, std::string value) {
|
||||||
|
@ -22,9 +22,9 @@ namespace coreutils {
|
|||||||
private:
|
private:
|
||||||
std::string key;
|
std::string key;
|
||||||
std::string value;
|
std::string value;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,26 +16,24 @@ namespace coreutils {
|
|||||||
|
|
||||||
bool IMFMessage::parse(PString &in) {
|
bool IMFMessage::parse(PString &in) {
|
||||||
|
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_4) << "parse [" << in.str() << "]";
|
while (!in.ifNext("\r\n")) {
|
||||||
|
|
||||||
if(in.str() != "") {
|
|
||||||
headers.emplace_back(in);
|
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::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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ namespace coreutils {
|
|||||||
|
|
||||||
IMFBody *getBody();
|
IMFBody *getBody();
|
||||||
|
|
||||||
// protected:
|
protected:
|
||||||
std::vector<IMFHeader> headers;
|
std::vector<IMFHeader> headers;
|
||||||
IMFBody *body;
|
IMFBody *body;
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include <string>
|
||||||
#include "IMFRequest.h"
|
#include "IMFRequest.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
@ -7,7 +8,13 @@ namespace coreutils {
|
|||||||
IMFRequest::IMFRequest() {}
|
IMFRequest::IMFRequest() {}
|
||||||
|
|
||||||
IMFRequest::IMFRequest(PString &in) {
|
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() {
|
std::string IMFRequest::getMethod() {
|
||||||
|
@ -11,6 +11,8 @@ namespace coreutils {
|
|||||||
IMFRequest();
|
IMFRequest();
|
||||||
IMFRequest(PString &in);
|
IMFRequest(PString &in);
|
||||||
|
|
||||||
|
void parse(PString &in);
|
||||||
|
|
||||||
std::string getMethod();
|
std::string getMethod();
|
||||||
std::string getURI();
|
std::string getURI();
|
||||||
std::string getProtocol();
|
std::string getProtocol();
|
||||||
|
23
PString.cpp
23
PString.cpp
@ -18,12 +18,16 @@ namespace coreutils {
|
|||||||
return pstring.substr(cursor);
|
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) {
|
std::vector<PString> PString::split(std::string delimiter, int maxSize) {
|
||||||
list.clear();
|
list.clear();
|
||||||
|
|
||||||
if(pstring.size() == 0) {
|
if(pstring.size() == 0) {
|
||||||
list.push_back(PString(""));
|
list.push_back(PString(""));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t end;
|
size_t end;
|
||||||
@ -80,10 +84,23 @@ namespace coreutils {
|
|||||||
size_t temp = cursor;
|
size_t temp = cursor;
|
||||||
cursor = pstring.find_first_not_of(" \t", cursor);
|
cursor = pstring.find_first_not_of(" \t", cursor);
|
||||||
cursor = cursor == -1 ? temp: cursor;
|
cursor = cursor == -1 ? temp: cursor;
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "Skipping whitespace for " << (cursor - temp) << " spaces.";
|
|
||||||
return cursor - temp;
|
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() {
|
int PString::size() {
|
||||||
return pstring.size() - cursor;
|
return pstring.size() - cursor;
|
||||||
}
|
}
|
||||||
|
13
PString.h
13
PString.h
@ -42,6 +42,13 @@ namespace coreutils {
|
|||||||
|
|
||||||
std::string str();
|
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;
|
int cursor = 0;
|
||||||
|
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user