Added vscode
This commit is contained in:
1 parent
6894968732
commit
c00476719c
10 files changed
+183
-158
No files matched your search
+38
-28
@@ -5,51 +5,61 @@
|
||||
#include "Log.h"
|
||||
|
||||
namespace coreutils {
|
||||
|
||||
IMFMessage::IMFMessage() {}
|
||||
|
||||
IMFMessage::IMFMessage(PString &in) {
|
||||
|
||||
IMFMessage::IMFMessage() {
|
||||
body = NULL;
|
||||
first = true;
|
||||
}
|
||||
|
||||
IMFMessage::IMFMessage(PString &in) : IMFMessage() {
|
||||
parse(in);
|
||||
}
|
||||
|
||||
|
||||
bool IMFMessage::parse(PString &in) {
|
||||
|
||||
coreutils::Log(coreutils::LOG_DEBUG_4) << "parse [" << in.str() << "]";
|
||||
|
||||
if(in.str() != "") {
|
||||
headers.emplace_back(in);
|
||||
if(first) {
|
||||
if(in.str().find(" ") != std::string::npos) {
|
||||
parse(in);
|
||||
first = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(in.str() != "") {
|
||||
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";
|
||||
|
||||
if(type == "multipart/form-data")
|
||||
body = new IMFMultipart(in, getHeaderKeyPairValue("Content-Type", "boundary"));
|
||||
|
||||
if(type == "multipart/form-data")
|
||||
body = new IMFMultipart(in, getHeaderKeyPairValue("Content-Type", "boundary"));
|
||||
else if(type == "text/plain")
|
||||
body = new IMFPlainText(in);
|
||||
else
|
||||
else
|
||||
body = new IMFBody();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void IMFMessage::output(std::stringstream &out) {
|
||||
for(IMFHeader header: headers) {
|
||||
out << header.getKey() << ": " << header.getValue() << "\r\n";
|
||||
}
|
||||
out << "\r\n";
|
||||
}
|
||||
|
||||
|
||||
void IMFMessage::addHeader(std::string key, std::string value) {
|
||||
headers.emplace_back(key, value);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string IMFMessage::getHeader(std::string key, bool valueOnly) {
|
||||
for(IMFHeader header: headers) {
|
||||
if(header.getKey() == key) {
|
||||
@@ -57,13 +67,13 @@ namespace coreutils {
|
||||
if(valueOnly) {
|
||||
std::vector<PString> split = PString(value).split(";");
|
||||
value = split[0].str();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
|
||||
std::string IMFMessage::getHeaderKeyPairValue(std::string headerKey, std::string key) {
|
||||
std::string value;
|
||||
coreutils::PString psource(getHeader(headerKey, false));
|
||||
@@ -75,30 +85,30 @@ namespace coreutils {
|
||||
if(token == key) {
|
||||
if(work.ifNext("\"")) {
|
||||
value = work.getTokenExclude("\"");
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
else {
|
||||
value = work.str();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
continue;
|
||||
|
||||
|
||||
|
||||
|
||||
} else if (work.ifNext(";") || work.ifNext(" ")) {
|
||||
if(token == key)
|
||||
if(token == key)
|
||||
return std::string("true");
|
||||
else
|
||||
continue;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return std::string("false");
|
||||
}
|
||||
|
||||
|
||||
IMFBody * IMFMessage::getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user