worked on IMF smartbuffers.

This commit is contained in:
brad Arant 2025-02-21 13:22:57 -08:00
parent 3f0a541e80
commit 11f396a749
6 changed files with 72 additions and 69 deletions

View File

@ -4,18 +4,9 @@
namespace coreutils { namespace coreutils {
IMFFormData::IMFFormData() {} IMFFormData::IMFFormData(int fd, ZString boundary) {
IMFHeader header(fd);
IMFFormData::IMFFormData(ZString &in, ZString &boundary) : IMFMultipart(in, boundary) {} IMFText text(fd, boundary);
ZString IMFFormData::getByName(ZString &name) {
for(ZString section: sections) {
IMFMessage message(section);
if(message.getHeaderKeyPairValue("Content-Disposition", ("name")).equals(name)) {
return message.multipart;
}
}
return ZString();
} }
} }

View File

@ -1,17 +1,14 @@
#ifndef __IMFFormData_h__ #ifndef __IMFFormData_h__
# define __IMFFormData_h__ # define __IMFFormData_h__
# include "IMFMultipart.h" #include "ZString.h"
namespace coreutils { namespace coreutils {
class IMFFormData: public IMFMultipart { class IMFFormData {
public: public:
IMFFormData(); IMFFormData(int fd, ZString boundary);
IMFFormData(ZString &in, ZString &boundary);
ZString getByName(ZString &name);
}; };

View File

@ -5,33 +5,11 @@
namespace coreutils { namespace coreutils {
IMFHeader::IMFHeader(ZString &in) : ZString(in) { IMFHeader::IMFHeader(int fd) {
while(1) {
key = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_0123456789"); headers.emplace(fd);
std::cout << "key: [" << key << "]" << std::endl; }
if(key.getLength() != 0) {
if(!in.ifNext(":"))
throw coreutils::Exception("Invalid character in expected header token.");
in.skipWhitespace();
value = in.goeolwithContinuation();
std::cout << "header: [" << value << "]" << std::endl;
}
else if(in.skipWhitespace() > 0) {}
else if(in.str() == "") {}
}
IMFHeader::IMFHeader(ZString key, ZString value) : ZString(), key(key), value(value) {}
ZString IMFHeader::getKey() {
return key;
}
ZString IMFHeader::getValue() {
return value;
}
void IMFHeader::output(std::stringstream &out) {
out << key << ": " << value << "\r\n";
} }
} }

View File

@ -1,25 +1,17 @@
#ifndef __IMFHeader_h__ #ifndef __IMFHeader_h__
#define __IMFHeader_h__ #define __IMFHeader_h__
#include "ZString.h" #include <vector>
#include <sstream>
namespace coreutils { namespace coreutils {
class IMFHeader : public ZString { class IMFHeader {
public: public:
IMFHeader(ZString &in); IMFHeader(int fd);
IMFHeader(ZString key, ZString value);
ZString getKey();
ZString getValue();
void output(std::stringstream &out);
private: private:
ZString key; std::vector<IMFHeaderField> headers;
ZString value;
}; };

View File

@ -3,7 +3,51 @@
namespace coreutils { namespace coreutils {
IMFMultipart::IMFMultipart() {} IMFMultipart::IMFMultipart(int fd, int length) {
int ch = 0;
int rc = 0;
while((ch != '\r') && (ch != '\n')) {
rc = ::read(fd, &ch, 1);
--length;
if((ch != '\r') && (ch != '\n'))
boundary.write(ch);
}
if(ch == '\r') {
rc = ::read(fd, &ch, 1);
--length;
}
while(1) {
sections.emplace_back(fd, boundary);
rc = ::read(fd, &ch, 1);
--length;
if(ch == '-') {
rc = ::read(fd, &ch, 1);
--length;
if(ch == '-') {
break;
}
}
}
rc = ::read(fd, &ch, 1);
--length;
if(ch == '\r') {
rc = ::read(fd, &ch, 1);
--length;
if(ch == '\n') {
}
}
}
IMFMultipart::IMFMultipart(ZString &in, ZString &boundary) { IMFMultipart::IMFMultipart(ZString &in, ZString &boundary) {
Log(LOG_DEBUG_1) << in; Log(LOG_DEBUG_1) << in;

View File

@ -1,25 +1,26 @@
#ifndef __IMFMultipart_h__ #ifndef __IMFMultipart_h__
#define __IMFMultipart_h__ #define __IMFMultipart_h__
#include "ZString.h" #include "MString.h"
#include <vector>
namespace coreutils { namespace coreutils {
class IMFMultipart: public ZString { class IMFMultipart {
public: public:
IMFMultipart(); IMFMultipart(int fd, int length);
IMFMultipart(ZString &in, ZString &boundary);
std::string toString(); // std::string toString();
int getCount(); // int getCount();
ZString getSectionAt(int index); // ZString getSectionAt(int index);
protected: // protected:
std::vector<ZString> sections; // std::vector<ZString> sections;
private: private:
char *boundary; MString boundary;
std::vector<IMFFormData> sections;
}; };