Sync.
This commit is contained in:
parent
c3c9530b4b
commit
7e06591de6
1
File.h
1
File.h
@ -2,6 +2,7 @@
|
|||||||
#define __File_h__
|
#define __File_h__
|
||||||
|
|
||||||
#include "includes"
|
#include "includes"
|
||||||
|
#include "PString.h"
|
||||||
|
|
||||||
///
|
///
|
||||||
/// File
|
/// File
|
||||||
|
14
IMFBody.h
14
IMFBody.h
@ -3,7 +3,19 @@
|
|||||||
|
|
||||||
namespace coreutils {
|
namespace coreutils {
|
||||||
|
|
||||||
class IMFBody {};
|
class IMFBody {
|
||||||
|
|
||||||
|
public:
|
||||||
|
IMFBody(PString *body) : body(body) {}
|
||||||
|
|
||||||
|
PString *getBody() {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
PString *body;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace coreutils {
|
namespace coreutils {
|
||||||
|
|
||||||
IMFFormData::IMFFormData(PString &in, std::string boundary) : IMFMultipart(in, boundary) {
|
IMFFormData::IMFFormData(PString *in, std::string boundary) : IMFMultipart(in, boundary) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ namespace coreutils {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
IMFFormData();
|
IMFFormData();
|
||||||
IMFFormData(PString &in, std::string boundary);
|
IMFFormData(PString *in, std::string boundary);
|
||||||
|
|
||||||
std::string getByName(std::string name);
|
std::string getByName(std::string name);
|
||||||
|
|
||||||
@ -18,3 +18,5 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ namespace coreutils {
|
|||||||
|
|
||||||
bool IMFMessage::parse(PString &in) {
|
bool IMFMessage::parse(PString &in) {
|
||||||
|
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "Parsing-------\n" << in.str();
|
Log(LOG_DEBUG_1) << "Parsing-------\n" << in.str();
|
||||||
|
|
||||||
while (!in.ifNext("\r\n")) {
|
while (!in.ifNext("\r\n")) {
|
||||||
headers.emplace_back(in);
|
headers.emplace_back(in);
|
||||||
@ -31,9 +31,9 @@ namespace coreutils {
|
|||||||
if(type == "multipart/form-data")
|
if(type == "multipart/form-data")
|
||||||
body = new IMFMultipart(block, getHeaderKeyPairValue("Content-Type", "boundary"));
|
body = new IMFMultipart(block, getHeaderKeyPairValue("Content-Type", "boundary"));
|
||||||
else if(type == "text/plain")
|
else if(type == "text/plain")
|
||||||
body = new IMFPlainText(in);
|
body = new IMFPlainText(block);
|
||||||
else
|
else
|
||||||
body = new IMFBody();
|
body = new IMFBody(&block);
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -102,4 +102,8 @@ namespace coreutils {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IMFMessage::setBody(PString *body) {
|
||||||
|
this->body = new IMFBody(body);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,14 @@
|
|||||||
|
|
||||||
namespace coreutils {
|
namespace coreutils {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// IMFMessage provides an object representation of a standard Internet
|
||||||
|
/// Message Format message.
|
||||||
|
///
|
||||||
|
/// Contstructing the object with a reference to a PString will generate
|
||||||
|
/// an object representation of the data therein.
|
||||||
|
///
|
||||||
|
|
||||||
class IMFMessage {
|
class IMFMessage {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -24,6 +32,7 @@ namespace coreutils {
|
|||||||
std::string getHeaderKeyPairValue(std::string headerKey, std::string key);
|
std::string getHeaderKeyPairValue(std::string headerKey, std::string key);
|
||||||
|
|
||||||
IMFBody *getBody();
|
IMFBody *getBody();
|
||||||
|
void setBody(PString *in);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<IMFHeader> headers;
|
std::vector<IMFHeader> headers;
|
||||||
|
@ -3,14 +3,10 @@
|
|||||||
|
|
||||||
namespace coreutils {
|
namespace coreutils {
|
||||||
|
|
||||||
IMFMultipart::IMFMultipart() {
|
IMFMultipart::IMFMultipart(PString *in, std::string boundary) : IMFBody(in) {
|
||||||
buffer = "";
|
buffer = in->str();
|
||||||
}
|
in->cursor -= 2;
|
||||||
|
sections = in->split("\r\n--" + boundary);
|
||||||
IMFMultipart::IMFMultipart(PString &in, std::string boundary) {
|
|
||||||
buffer = in.str();
|
|
||||||
in.cursor -= 2;
|
|
||||||
sections = in.split("\r\n--" + boundary);
|
|
||||||
for(int ix = 0; ix < sections.size(); ++ix) {
|
for(int ix = 0; ix < sections.size(); ++ix) {
|
||||||
if(sections[ix].str() == "--\r\n")
|
if(sections[ix].str() == "--\r\n")
|
||||||
sections[ix] = PString("");
|
sections[ix] = PString("");
|
||||||
@ -20,7 +16,7 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string IMFMultipart::toString() {
|
std::string IMFMultipart::toString() {
|
||||||
return buffer;
|
return buffer.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
int IMFMultipart::getCount() {
|
int IMFMultipart::getCount() {
|
||||||
|
@ -9,8 +9,7 @@ namespace coreutils {
|
|||||||
class IMFMultipart: public IMFBody {
|
class IMFMultipart: public IMFBody {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IMFMultipart();
|
IMFMultipart(PString *in, std::string boundary);
|
||||||
IMFMultipart(PString &in, std::string boundary);
|
|
||||||
|
|
||||||
std::string toString();
|
std::string toString();
|
||||||
int getCount();
|
int getCount();
|
||||||
@ -22,7 +21,7 @@ namespace coreutils {
|
|||||||
private:
|
private:
|
||||||
std::string boundary;
|
std::string boundary;
|
||||||
|
|
||||||
std::string buffer;
|
coreutils::PString buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,7 @@
|
|||||||
|
|
||||||
namespace coreutils {
|
namespace coreutils {
|
||||||
|
|
||||||
IMFPlainText::IMFPlainText() {
|
IMFPlainText::IMFPlainText(PString &in) : IMFBody(in) {
|
||||||
text = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
IMFPlainText::IMFPlainText(PString &in) : IMFBody() {
|
|
||||||
text = in.str();
|
text = in.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ namespace coreutils {
|
|||||||
|
|
||||||
output(response);
|
output(response);
|
||||||
response << content;
|
response << content;
|
||||||
// core::Log(core::LOG_DEBUG_4) << response.str();
|
coreutils::Log(coreutils::LOG_DEBUG_4) << response.str();
|
||||||
return response.str();
|
return response.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,11 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string PString::readBlock(size_t size) {
|
std::string PString::readBlock(size_t size) {
|
||||||
printf(">>>>>: %i:%i", size, pstring.size() - cursor);
|
int cursorSave = cursor;
|
||||||
|
cursor += size;
|
||||||
|
if(cursor > pstring.size())
|
||||||
|
cursor = pstring.size();
|
||||||
|
return pstring.substr(cursorSave, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PString::size() {
|
int PString::size() {
|
||||||
|
45
ZString.h
Normal file
45
ZString.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#ifndef __ZString_h__
|
||||||
|
#define __ZString_h__
|
||||||
|
|
||||||
|
#include "includes"`
|
||||||
|
|
||||||
|
namespace coreutils {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// ZString provides a data pointer and a length to basically point to a string
|
||||||
|
/// from a common backstore.
|
||||||
|
///
|
||||||
|
|
||||||
|
class ZString {
|
||||||
|
|
||||||
|
public:
|
||||||
|
ZString() {}
|
||||||
|
ZString(char *data) {
|
||||||
|
this->data = data;
|
||||||
|
length = strlen(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZString(char *data, size_t length) {
|
||||||
|
this->data = data;
|
||||||
|
this->length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string asString() {
|
||||||
|
return std::string(data, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setString(char *data, size_t length) {
|
||||||
|
this->data = data;
|
||||||
|
this->length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
char *data;
|
||||||
|
size_t length;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user