some cgi variable work.
This commit is contained in:
parent
64fd81d6ed
commit
c21dea1411
29
Global.cpp
29
Global.cpp
@ -137,4 +137,33 @@ namespace jet {
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
3
Global.h
3
Global.h
@ -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;
|
||||
|
15
__jet.cpp
15
__jet.cpp
@ -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);
|
||||
|
@ -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"
|
||||
|
||||
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
|
||||
Content-Disposition: form-data; name="datafile1"; filename="r.gif"
|
||||
Content-Type: image/gif
|
||||
1 test
|
||||
------WebKitFormBoundaryA1LWIjMAIsdFW9XA
|
||||
Content-Disposition: form-data; name="name"
|
||||
|
||||
GIF87a.............,...........D..;
|
||||
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
|
||||
Content-Disposition: form-data; name="datafile2"; filename="g.gif"
|
||||
Content-Type: image/gif
|
||||
2&test
|
||||
------WebKitFormBoundaryA1LWIjMAIsdFW9XA
|
||||
Content-Disposition: form-data; name="name"
|
||||
|
||||
GIF87a.............,...........D..;
|
||||
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
|
||||
Content-Disposition: form-data; name="datafile3"; filename="b.gif"
|
||||
Content-Type: image/gif
|
||||
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--
|
||||
|
||||
GIF87a.............,...........D..;
|
||||
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f--
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user