urlencoded forms data is now workng as well.
This commit is contained in:
parent
c90c7353c7
commit
a9ce087939
23
Global.cpp
23
Global.cpp
@ -1,7 +1,6 @@
|
||||
#include "Global.h"
|
||||
#include "Exception.h"
|
||||
#include "__mysql.h"
|
||||
#include "Modifiers.h"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -39,7 +38,6 @@ namespace jet {
|
||||
}
|
||||
|
||||
coreutils::MString& Global::processModifier(coreutils::MString &value, coreutils::MString &modifier) {
|
||||
Modifiers modifiers;
|
||||
if(modifier.getLength() == 0)
|
||||
return value;
|
||||
if(modifier == "tobinary")
|
||||
@ -143,7 +141,6 @@ namespace jet {
|
||||
}
|
||||
|
||||
void Global::setupFormData(coreutils::ZString &formdata) {
|
||||
|
||||
coreutils::ZString boundary = formdata.goeol();
|
||||
while(!formdata.eod()) {
|
||||
if(formdata.ifNext("Content-Disposition: form-data;")) {
|
||||
@ -163,7 +160,6 @@ namespace jet {
|
||||
namex << name << ":" << index++;
|
||||
} while(cgiVariables.count(namex) != 0);
|
||||
cgiVariables[namex] = data;
|
||||
// std::cout << namex << ":[" << data << "]" << std::endl;
|
||||
if(formdata.ifNext("--"))
|
||||
break;
|
||||
formdata.goeol();
|
||||
@ -177,4 +173,23 @@ namespace jet {
|
||||
}
|
||||
}
|
||||
|
||||
void Global::setupFormURLEncoded(coreutils::ZString &formdata) {
|
||||
while(!formdata.eod()) {
|
||||
coreutils::ZString name = formdata.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
|
||||
if(formdata.ifNext("=")) {
|
||||
coreutils::MString data = formdata.getTokenExclude("&");
|
||||
formdata.ifNext("&");
|
||||
int index = 0;
|
||||
coreutils::MString namex;
|
||||
do {
|
||||
namex = "";
|
||||
namex << name << ":" << index++;
|
||||
} while(cgiVariables.count(namex) != 0);
|
||||
modifiers.processFromCGIModifier(data, lastConverted);
|
||||
cgiVariables[namex] = lastConverted;
|
||||
} else
|
||||
throw coreutils::Exception("expecting = after name in received CGI data.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
3
Global.h
3
Global.h
@ -2,6 +2,7 @@
|
||||
#define __Global_h__
|
||||
|
||||
#include "MString.h"
|
||||
#include "Modifiers.h"
|
||||
#include <map>
|
||||
|
||||
namespace jet {
|
||||
@ -25,6 +26,7 @@ namespace jet {
|
||||
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
||||
void outputHeaders();
|
||||
void setupFormData(coreutils::ZString &formdata);
|
||||
void setupFormURLEncoded(coreutils::ZString &formdata);
|
||||
|
||||
std::map<coreutils::MString, coreutils::MString> variables;
|
||||
std::map<coreutils::MString, coreutils::MString> cgiVariables;
|
||||
@ -33,6 +35,7 @@ namespace jet {
|
||||
std::map<coreutils::MString, coreutils::MString> tags;
|
||||
coreutils::MString lastConverted;
|
||||
char **envp;
|
||||
Modifiers modifiers;
|
||||
|
||||
};
|
||||
|
||||
|
@ -93,6 +93,32 @@ namespace jet {
|
||||
}
|
||||
|
||||
void Modifiers::processFromCGIModifier(coreutils::MString &value, coreutils::MString &lastConverted) {
|
||||
value.reset();
|
||||
lastConverted = "";
|
||||
while(!value.eod()) {
|
||||
char c = value.nextChar();
|
||||
if(c == '+')
|
||||
lastConverted.write(' ');
|
||||
else if(c == '%') {
|
||||
char ch1 = value.nextChar();
|
||||
ch1 -= 48;
|
||||
if(ch1 > 9)
|
||||
ch1 -= 7;
|
||||
ch1 <<= 4;
|
||||
ch1 &= 240;
|
||||
if(value.eod())
|
||||
coreutils::Exception("conversion from hex requires even number of characters.");
|
||||
char ch2 = value.nextChar();
|
||||
ch2 -= 48;
|
||||
if(ch2 > 9)
|
||||
ch2 -= 7;
|
||||
ch2 &= 15;
|
||||
ch1 |= ch2;
|
||||
lastConverted.write(ch1);
|
||||
} else
|
||||
lastConverted.write(c);
|
||||
}
|
||||
value.reset();
|
||||
}
|
||||
|
||||
char Modifiers::hexChar(char c) {
|
||||
|
@ -23,8 +23,8 @@ namespace jet {
|
||||
|
||||
if(contentType == "multipart/form-data")
|
||||
global.setupFormData(postdata);
|
||||
// else if(contentType == "application/x-www-form-urlencoded")
|
||||
// std::cout << "output urlencoded variables to global" << std::endl;
|
||||
else if(contentType == "application/x-www-form-urlencoded")
|
||||
global.setupFormURLEncoded(postdata);
|
||||
}
|
||||
}
|
||||
processContainer(container);
|
||||
|
1
tests/post.example.urlencoded
Normal file
1
tests/post.example.urlencoded
Normal file
@ -0,0 +1 @@
|
||||
name=1+test&name=2+%26test&name=3+%2B+test&name=4+*test&name=5&name2=6
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
export REQUEST_METHOD=POST
|
||||
export CONTENT_LENGTH=200
|
||||
export CONTENT_TYPE=multipart/form-data
|
||||
cat post.example | ./testpost.jet
|
||||
export CONTENT_TYPE=application/x-www-form-urlencoded
|
||||
cat post.example.urlencoded | ./testpost.jet
|
||||
|
@ -1,6 +1,11 @@
|
||||
#!../jet-2.0
|
||||
<jet cgi="true">
|
||||
$[:name]
|
||||
$[:name:1]
|
||||
$[:name:2]
|
||||
$[:name:3]
|
||||
$[:name2]
|
||||
$[:name:2;tohex]
|
||||
$[:name:3;tohex]
|
||||
$[:name2;tohex]
|
||||
</jet>
|
||||
|
Loading…
x
Reference in New Issue
Block a user