Exposing the request and the FastCGI environments through to the JavaScript through the self.fastjs object

Currently they're typical JavaScript objects tied to:
	fastjs.env
	fastjs.fcgi_env

I think I need a template language now..

Signed-off-by: R. Tyler Ballance <tyler@monkeypox.org>
This commit is contained in:
R. Tyler Ballance 2009-03-09 05:05:04 -04:00
parent 133b8d92df
commit 8000bd54ba
3 changed files with 33 additions and 8 deletions

View File

@ -116,6 +116,23 @@ static int exec_javascript(const char *script)
return FASTJS_SUCCESS;
}
static void parse_environment(Handle<ObjectTemplate> _node, char **env)
{
for (; *env != NULL; env++) {
gchar **splitted = g_strsplit((const gchar *)(*env), "=", 2);
if (splitted == NULL)
continue;
if ( (splitted[0] == NULL) || (splitted[1] == NULL) ) {
g_strfreev(splitted);
continue;
}
_node->Set(String::New((const char *)(splitted[0])), String::New((const char *)(splitted[1])));
g_strfreev(splitted);
}
}
static void req_handle(FCGX_Stream *out, char **environment)
{
if (_jQuery == NULL) {
@ -127,9 +144,17 @@ static void req_handle(FCGX_Stream *out, char **environment)
HandleScope scope;
Handle<ObjectTemplate> _global = ObjectTemplate::New();
Handle<ObjectTemplate> _fastjs = ObjectTemplate::New();
Handle<ObjectTemplate> _env = ObjectTemplate::New();
Handle<ObjectTemplate> _fcgi_env = ObjectTemplate::New();
parse_environment(_env, environment);
parse_environment(_fcgi_env, environ);
_fastjs->Set(String::New("write"), FunctionTemplate::New(FastJS_Write));
_fastjs->Set(String::New("source"), FunctionTemplate::New(FastJS_Source));
_fastjs->Set(String::New("log"), FunctionTemplate::New(FastJS_Log));
_fastjs->Set(String::New("env"), _env);
_fastjs->Set(String::New("fcgi_env"), _fcgi_env);
_global->Set(String::New("fastjs"), _fastjs);
Persistent<Context> ctx = Context::New(NULL, _global);
@ -183,9 +208,6 @@ int main ()
req_handle(out, envp);
//PrintEnv(err, "Request environment", envp);
//PrintEnv(err, "Initial", environ);
_error_stream = NULL;
_in_stream = NULL;
_out_stream = NULL;

View File

@ -8,7 +8,7 @@
#define _FASTJS_H_
#define JQUERY_FILE "jquery-1.3.2.min.js"
#define JQUERY_COMPAT "if (typeof(window) == 'undefined'){window=new Object();document=window;self=window;navigator=new Object();navigator.userAgent=navigator.userAgent||'FastJS Server';location=new Object();location.href='file:///dev/null';location.protocol='file:';location.host = 'FastJS';}"
#define JQUERY_COMPAT "if (typeof(window)=='undefined'){window=new Object();document=window;self=window;document.documentElement=new Object();navigator=new Object();navigator.userAgent=navigator.userAgent||'FastJS Server';location=new Object();location.href='file:///dev/null';location.protocol='file:';location.host = 'FastJS';}"
#define FASTJS_SUCCESS 0
#define FASTJS_COMPILE_ERROR -1

View File

@ -18,7 +18,7 @@ index.dump_attributes = function(title, obj) {
for (var k in obj) {
fastjs.write(k + " = ");
if (typeof(obj[k] != "string"))
if (typeof(obj[k]) != "string")
fastjs.write(typeof(obj[k]));
else
fastjs.write(obj[k]);
@ -30,11 +30,14 @@ index.dump_attributes = function(title, obj) {
(function() {
index.header();
index.dump_attributes("window", window);
index.dump_attributes("jQuery", jQuery);
fastjs.source("pages/test.fjs");
index.dump_attributes("window", window);
index.dump_attributes('location', location);
index.dump_attributes("fastjs.env", fastjs.env);
index.dump_attributes("fastjs.fcgi_env", fastjs.fcgi_env);
index.footer();
fastjs.log("This should go into the error.log");