some cgi variable work.
This commit is contained in:
parent
64fd81d6ed
commit
c21dea1411
31
Global.cpp
31
Global.cpp
@ -136,5 +136,34 @@ namespace jet {
|
|||||||
std::cout << std::endl;
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
3
Global.h
3
Global.h
@ -24,9 +24,10 @@ namespace jet {
|
|||||||
__mysql * getSession(coreutils::MString sessionId);
|
__mysql * getSession(coreutils::MString sessionId);
|
||||||
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
||||||
void outputHeaders();
|
void outputHeaders();
|
||||||
|
void setupFormData(coreutils::ZString &formdata);
|
||||||
|
|
||||||
std::map<coreutils::MString, coreutils::MString> variables;
|
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, __mysql *> sessions;
|
||||||
std::map<coreutils::MString, coreutils::MString> headers;
|
std::map<coreutils::MString, coreutils::MString> headers;
|
||||||
std::map<coreutils::MString, coreutils::MString> tags;
|
std::map<coreutils::MString, coreutils::MString> tags;
|
||||||
|
15
__jet.cpp
15
__jet.cpp
@ -1,6 +1,7 @@
|
|||||||
#include "__jet.h"
|
#include "__jet.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
@ -13,17 +14,17 @@ namespace jet {
|
|||||||
coreutils::ZString contentLength(getenv("CONTENT_LENGTH"));
|
coreutils::ZString contentLength(getenv("CONTENT_LENGTH"));
|
||||||
coreutils::ZString contentType(getenv("CONTENT_TYPE"));
|
coreutils::ZString contentType(getenv("CONTENT_TYPE"));
|
||||||
|
|
||||||
|
std::ofstream outFile("/tmp/output.txt");
|
||||||
|
|
||||||
coreutils::MString postdata;
|
coreutils::MString postdata;
|
||||||
postdata.read(0);
|
postdata.read(0);
|
||||||
std::cout << postdata << std::endl;
|
outFile << postdata << std::endl;
|
||||||
|
outFile.close();
|
||||||
coreutils::IMFRequest request(postdata);
|
|
||||||
coreutils::IMFMessage message(postdata);
|
|
||||||
|
|
||||||
if(contentType == "multipart/form-data")
|
if(contentType == "multipart/form-data")
|
||||||
std::cout << "output multipart variables to global" << std::endl;
|
global.setupFormData(postdata);
|
||||||
else if(contentType == "application/x-www-form-urlencoded")
|
// else if(contentType == "application/x-www-form-urlencoded")
|
||||||
std::cout << "output urlencoded variables to global" << std::endl;
|
// std::cout << "output urlencoded variables to global" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
|
@ -1,21 +1,26 @@
|
|||||||
POST /cgi-bin/qtest HTTP/1.1
|
------WebKitFormBoundaryA1LWIjMAIsdFW9XA
|
||||||
Content-Type: multipart/form-data;
|
Content-Disposition: form-data; name="name"
|
||||||
boundary=2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
|
|
||||||
Content-Length: 514
|
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--
|
|
@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
export REQUEST_METHOD=POST
|
export REQUEST_METHOD=POST
|
||||||
export CONTENT_LENGTH=554
|
export CONTENT_LENGTH=200
|
||||||
export CONTENT_TYPE=multipart/form-data
|
export CONTENT_TYPE=multipart/form-data
|
||||||
cat post.example | ./testpost.jet
|
cat post.example | ./testpost.jet
|
||||||
|
Loading…
x
Reference in New Issue
Block a user