diff --git a/CGIFormattedData.cpp b/CGIFormattedData.cpp index 6ed4df9..0257334 100644 --- a/CGIFormattedData.cpp +++ b/CGIFormattedData.cpp @@ -7,23 +7,20 @@ namespace coreutils { CGIFormattedData::CGIFormattedData(ZString cgiData) { cgiData.split("&"); - for(int ix = 1; ix < cgiData.getList().size(); ++ix) { - cgiData[0].split("="); - data[cgiData[0]] = cgiData[1]; - data[cgiData[0]].fromCGI(); + for(int ix = 0; ix < cgiData.getList().size(); ++ix) { + cgiData[ix].split("="); + data[cgiData[ix][0]] = cgiData[ix][1]; + data[cgiData[ix][0]].fromCGI(); } } ZString CGIFormattedData::operator=(ZString cgiData) { - std::cout << "000" << std::endl; cgiData.split("&"); - std::cout << "001" << std::endl; - for(int ix = 1; ix < cgiData.getList().size(); ++ix) { - cgiData[0].split("="); - data[cgiData[0]] = cgiData[1]; - data[cgiData[0]].fromCGI(); + for(int ix = 0; ix < cgiData.getList().size(); ++ix) { + cgiData[ix].split("="); + data[cgiData[ix][0]] = cgiData[ix][1]; + data[cgiData[ix][0]].fromCGI(); } - std::cout << "002" << std::endl; return cgiData; } diff --git a/IMFFormData.cpp b/IMFFormData.cpp index 0b5a838..6115b3d 100644 --- a/IMFFormData.cpp +++ b/IMFFormData.cpp @@ -5,11 +5,8 @@ namespace coreutils { IMFFormData::IMFFormData(int fd, ZString boundary) { - std::cout << "030" << std::endl; IMFHeader header(fd); - std::cout << "031" << std::endl; IMFText text(fd, boundary); - std::cout << "032" << std::endl; } } diff --git a/IMFHeader.cpp b/IMFHeader.cpp index 83d2c24..9c91155 100644 --- a/IMFHeader.cpp +++ b/IMFHeader.cpp @@ -7,16 +7,12 @@ namespace coreutils { IMFHeader::IMFHeader(int fd) { char ch; - std::cout << "040" << std::endl; int rc = ::read(fd, &ch, 1); while(ch != '\r') { - std::cout << (char)ch << std::endl; IMFHeaderField *headerField = new IMFHeaderField(ch, fd); headers.push_back(headerField); } - std::cout << "041: " << ch << std::endl; rc = ::read(fd, &ch, 1); - std::cout << "042: " << ch << std::endl; } } \ No newline at end of file diff --git a/IMFHeaderField.cpp b/IMFHeaderField.cpp index 77d841b..78f1b7e 100644 --- a/IMFHeaderField.cpp +++ b/IMFHeaderField.cpp @@ -8,32 +8,26 @@ namespace coreutils { IMFHeaderField::IMFHeaderField(char &ch, int fd) { int rc = 0; - - std::cout << "050" << std::endl; - - if((ch >= 'A') && (ch <= 'Z')) - key.write(ch); - - while(ch != ':') { + while(((ch >= 'A') && (ch <= 'Z')) || + ((ch >= 'a') && (ch <= 'z')) || + ((ch >= '0') && (ch <= '9')) || + (ch == '-') || (ch == '_')) { + key.write(ch); rc = ::read(fd, &ch, 1); - if(ch != ':') - key.write(ch); } - - std::cout << "051: " << key << std::endl; - + if(ch != ':') + throw coreutils::Exception("expecting ':' in data stream."); rc = ::read(fd, &ch, 1); while(ch == ' ') - rc = ::read(fd, &ch, 1); - + rc = ::read(fd, &ch, 1); while(ch != '\r') { + value.write(ch); rc = ::read(fd, &ch, 1); - if(ch != '\r') - value.write(ch); } - std::cout << "052: " << value << std::endl; rc = ::read(fd, &ch, 1); - std::cout << "053" << std::endl; + if(ch != '\n') + throw coreutils::Exception("expecting '\n' in data stream."); + rc = ::read(fd, &ch, 1); } } \ No newline at end of file diff --git a/IMFMultipart.cpp b/IMFMultipart.cpp index edbfda6..c98af99 100644 --- a/IMFMultipart.cpp +++ b/IMFMultipart.cpp @@ -1,28 +1,24 @@ #include "IMFMultipart.h" #include "Log.h" +#include "Exception.h" #include namespace coreutils { IMFMultipart::IMFMultipart(int fd, MString boundary) { - int ch = 0; + char ch = 0; int rc = 0; - std::cout << "020" << std::endl; while((ch != '\r') && (ch != '\n')) { rc = ::read(fd, &ch, 1); if((ch != '\r') && (ch != '\n')) - std::cout << (char)ch; boundary.write(ch); } if(ch == '\r') { - std::cout << std::endl; rc = ::read(fd, &ch, 1); } while(1) { - std::cout << "021: " << boundary << std::endl; IMFFormData *formData = new IMFFormData(fd, boundary); - std::cout << "022" << std::endl; rc = ::read(fd, &ch, 1); if(ch == '-') { @@ -30,16 +26,12 @@ namespace coreutils { if(ch == '-') { break; } + } else if(ch == '\r') { + rc = ::read(fd, &ch, 1); + if(ch != '\n') + coreutils::Exception("expecting '\n' in data stream."); } - } - rc = ::read(fd, &ch, 1); - if(ch == '\r') { - rc = ::read(fd, &ch, 1); - if(ch == '\n') { - } - } - - } - + } + } diff --git a/IMFText.cpp b/IMFText.cpp index 8c56a13..61762aa 100644 --- a/IMFText.cpp +++ b/IMFText.cpp @@ -4,21 +4,20 @@ namespace coreutils { IMFText::IMFText(int fd, ZString boundary) : MString() { - int ch = 0; + char ch = 0; int rc = 0; - char *endcursor; - char *index = boundary.getData(); + boundary.reset(); + int blen = boundary.getLength() + 1; while(1) { - rc = ::read(fd, &ch, 1); - if(ch == *index) { - ++index; - ZString check(index, index - endcursor); - if(check == boundary) { + rc = ::read(fd, &ch, 1); + if(boundary.nextChar() == ch) { + if(boundary.eod()) { + length -= blen; break; } - } else { - endcursor = index; + } else { + boundary.reset(); } write(ch); }