some cgi variable work.

This commit is contained in:
brad Arant 2024-11-23 19:25:14 -08:00
parent 64fd81d6ed
commit c21dea1411
5 changed files with 66 additions and 30 deletions

View File

@ -136,5 +136,34 @@ namespace jet {
std::cout << std::endl;
}
}
void Global::setupFormData(coreutils::ZString &formdata) {
coreutils::ZString boundary = formdata.goeol();
while(!formdata.eod()) {
if(formdata.ifNext("Content-Disposition: form-data;")) {
formdata.skipWhitespace();
if(formdata.ifNext("name=\"")) {
coreutils::ZString name = formdata.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
if(formdata.ifNext("\"")) {
formdata.goeol();
formdata.goeol();
coreutils::ZString data = formdata.getTokenExclude("-"); // TODO: Fix this parsing. Need a string exclusion method to check for 'boundary'.
data.trimCRLF();
formdata.ifNext(boundary);
cgiVariables[name] = data;
std::cout << name << ":[" << data << "]" << std::endl;
if(formdata.ifNext("--"))
break;
formdata.goeol();
}
else
throw coreutils::Exception("expecting closing double quote on vairable name in received CGI data.");
} else
throw coreutils::Exception("expecting name subfield in received CGI data.");
} else
throw coreutils::Exception("expecting Content-Disposition header in received CGI data.");
}
}
}

View File

@ -24,9 +24,10 @@ namespace jet {
__mysql * getSession(coreutils::MString sessionId);
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
void outputHeaders();
void setupFormData(coreutils::ZString &formdata);
std::map<coreutils::MString, coreutils::MString> variables;
std::map<coreutils::MString, coreutils::MString> cgiVariables;
std::map<coreutils::ZString, coreutils::ZString> cgiVariables;
std::map<coreutils::MString, __mysql *> sessions;
std::map<coreutils::MString, coreutils::MString> headers;
std::map<coreutils::MString, coreutils::MString> tags;

View File

@ -1,6 +1,7 @@
#include "__jet.h"
#include "Exception.h"
#include <iostream>
#include <fstream>
namespace jet {
@ -13,17 +14,17 @@ namespace jet {
coreutils::ZString contentLength(getenv("CONTENT_LENGTH"));
coreutils::ZString contentType(getenv("CONTENT_TYPE"));
std::ofstream outFile("/tmp/output.txt");
coreutils::MString postdata;
postdata.read(0);
std::cout << postdata << std::endl;
coreutils::IMFRequest request(postdata);
coreutils::IMFMessage message(postdata);
outFile << postdata << std::endl;
outFile.close();
if(contentType == "multipart/form-data")
std::cout << "output multipart variables to global" << std::endl;
else if(contentType == "application/x-www-form-urlencoded")
std::cout << "output urlencoded variables to global" << std::endl;
global.setupFormData(postdata);
// else if(contentType == "application/x-www-form-urlencoded")
// std::cout << "output urlencoded variables to global" << std::endl;
}
}
processContainer(container);

View File

@ -1,21 +1,26 @@
POST /cgi-bin/qtest HTTP/1.1
Content-Type: multipart/form-data;
boundary=2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
Content-Length: 514
------WebKitFormBoundaryA1LWIjMAIsdFW9XA
Content-Disposition: form-data; name="name"
1 test
------WebKitFormBoundaryA1LWIjMAIsdFW9XA
Content-Disposition: form-data; name="name"
2&test
------WebKitFormBoundaryA1LWIjMAIsdFW9XA
Content-Disposition: form-data; name="name"
3+test
------WebKitFormBoundaryA1LWIjMAIsdFW9XA
Content-Disposition: form-data; name="name"
4 test
------WebKitFormBoundaryA1LWIjMAIsdFW9XA
Content-Disposition: form-data; name="name"
5
------WebKitFormBoundaryA1LWIjMAIsdFW9XA
Content-Disposition: form-data; name="name"
6
------WebKitFormBoundaryA1LWIjMAIsdFW9XA--
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
Content-Disposition: form-data; name="datafile1"; filename="r.gif"
Content-Type: image/gif
GIF87a.............,...........D..;
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
Content-Disposition: form-data; name="datafile2"; filename="g.gif"
Content-Type: image/gif
GIF87a.............,...........D..;
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
Content-Disposition: form-data; name="datafile3"; filename="b.gif"
Content-Type: image/gif
GIF87a.............,...........D..;
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f--

View File

@ -1,5 +1,5 @@
#!/bin/bash
export REQUEST_METHOD=POST
export CONTENT_LENGTH=554
export CONTENT_LENGTH=200
export CONTENT_TYPE=multipart/form-data
cat post.example | ./testpost.jet