-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScript.d
More file actions
162 lines (145 loc) · 5.69 KB
/
Script.d
File metadata and controls
162 lines (145 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
Rhodeus Script (c) by Talha Zekeriya Durmuş
Rhodeus Script is licensed under a
Creative Commons Attribution-NoDerivs 3.0 Unported License.
You should have received a copy of the license along with this
work. If not, see <http://creativecommons.org/licenses/by-nd/3.0/>.
*/
module Script;
import library.dini, library.web;
import std.stdio, std.file;
import parser;
import errorHandling.errorHandler;
import interpreter;
import std.process;
import std.path;
import std.conv;
import pool;
import Commands;
version(Win32)
import std.c.windows.windows;
else version(OSX)
private extern(C) int _NSGetExecutablePath(char* buf, uint* bufsize);
else
import std.c.linux.linux;
string getExec(){
auto file = new char[4*1024];
size_t filenameLength;
version (Win32) filenameLength = GetModuleFileNameA(null, file.ptr, file.length-1);
else version(OSX){
filenameLength = file.length-1;
_NSGetExecutablePath(file.ptr, &filenameLength);
}else filenameLength = readlink(toStringz(selfExeLink), file.ptr, file.length-1);
//auto fp = new FilePath(file[0..filenameLength]);
return to!string(file[0..filenameLength]);
// return getExecFilePath().toString().trim();
}
class Script{
string workingdir;
Ini ini;
string language;
Parser parser;
_RhError error;
string[string] envVars;
string exedir;
Interpreter interpreter;
int curLine = 1;
pool dataPool;
this(string wd = getcwd()){
this.dataPool = new pool();
Commands.linkIt(dataPool);
exedir = dirName(getExec())~dirSeparator;
workingdir = wd;
parser = new Parser(&curLine);
string addr;
if(exists("rhs.conf")) addr="rhs.conf";
else addr = buildPath(exedir,"rhs.conf");
try{
ini = Ini.Parse(addr);
language = ini["script"].getKey("language");
}catch{
throw new RhError(0,"Bad configuration file!");
}
interpreter = new Interpreter(workingdir, exedir, &curLine);
bool[string] attrs;
dataManagement pc = new dataManagement(interpreter.kdM);
// pc["line"]=0;
// pc["number"]=0;
Variant* father;
Variant[string] dl;
// interpreter.kdM["Throwable"] = Variant( ["father": Variant(father),"fid": Variant(parser.iClass++),"type": Variant("CLASS"), "attr": Variant(attrs), "codes": Variant(pc), "name": Variant("Throwable"), "vars": Variant(dl)] );
error = new _RhError(language, exedir,classid, null, &curLine); //interpreter.kdM.get("Throwable")
}
string execute(string file, ref Cgi cgi){
auto session = new Session(cgi);
scope(exit) session.commit();
Variant[string] val;
/*
foreach(a;cgi.files.keys){
if(cgi.files[a].contentInMemory==false){
ulong size = getSize(cast(char[]) cgi.files[a].contentFilename);
val[a] = Variant(
["type": Variant("DICTIONARYC"), "value": Variant(
["name":Variant(["type": Variant("STRING"), "value": Variant(cgi.files[a].name)]),
"filename":Variant(["type": Variant("STRING"), "value": Variant(cgi.files[a].filename)]),
"contentType":Variant(["type": Variant("STRING"), "value": Variant(cgi.files[a].contentType)]),
"tmpName":Variant(["type": Variant("STRING"), "value": Variant(cgi.files[a].contentFilename)]),
"size":Variant(["type": Variant("STRING"), "value": Variant(text(size))])
])
]);
}else{
string newn = getTempDirectory() ~ "rhs_uploaded_file_" ~ to!string(getUtcTime());
std.file.write(newn, cgi.files[a].content);
ulong size = getSize(cast(char[]) newn);
val[a] = Variant(
["type": Variant("DICTIONARYC"), "value": Variant(
["name":Variant(["type": Variant("STRING"), "value": Variant(cgi.files[a].name)]),
"filename":Variant(["type": Variant("STRING"), "value": Variant(cgi.files[a].filename)]),
"contentType":Variant(["type": Variant("STRING"), "value": Variant(cgi.files[a].contentType)]),
"tmpName":Variant(["type": Variant("STRING"), "value": Variant(newn)]),
"size":Variant(["type": Variant("STRING"), "value": Variant(text(size))])
])
]);
}
}*/
// interpreter.kdM["FILES"] = Variant(["type": Variant("DICTIONARYC"), "value": Variant(val)]);
// interpreter.loadVars("SESSION", session.data);
// interpreter.loadVars("GET", cgi.get);
// interpreter.loadVars("POST", cgi.post);
// interpreter.loadVars("COOKIES", cgi.cookies);
// interpreter.loadVars("ENV", environment.toAA());
/*if(exists("resources\\includes\\")){
foreach (string name; dirEntries("resources\\includes", "*.{rhs}", SpanMode.breadth)) {
parser.load(name);
parser.parseIt();
interpreter.main(parser.paraphrase());
}
}*/
parser.loadFile(file);
parser.parseIt();
interpreter.main(parser.paraphrase());
if(interpreter.kdM.hasKey("SESSION")){
Variant aktiv = interpreter.kdM["SESSION"];
if(aktiv["type"]=="DICTIONARYC"){
foreach(string s; aktiv["value"].peek!(Variant[string]).keys){
// session.set(s, interpreter.getText(aktiv["value"][s], interpreter.kdM));
}
}
}
foreach(x;interpreter.wcooks){
bool x5;
if(x[5]!="0" && x[5]!="false") x5=true;
bool x6;
if(x[6]!="0" && x[6]!="false") x6=true;
cgi.setCookie(x[0], text(x[1]), to!long(text(x[2])), text(x[3]), text(x[4]), x5, x6);
}
shutAll(interpreter);
return interpreter.output;
}
void shutAll(ref Interpreter interpreter){
while(interpreter.shutIt.length>0){
if (interpreter.shutIt[0][0]=="libs.mysql.Connecion") (*interpreter.shutIt[0][1].peek!(library.mysql.Connection)).close;
interpreter.shutIt.popFront();
}
}
}