Adding jQuery 1.3.2 into the codebase, working on preloading the JavaScript environment with jQuery

This should make the use of FastJS a little more compelling, having jQuery readily available

Signed-off-by: R. Tyler Ballance <tyler@monkeypox.org>
This commit is contained in:
R. Tyler Ballance 2009-03-08 05:56:22 -04:00
parent 48c3980e16
commit 0d653d62c4
2 changed files with 64 additions and 4 deletions

View File

@ -7,7 +7,7 @@
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include <v8.h>
@ -15,10 +15,18 @@ extern "C" {
extern char **environ;
#include <fcgi_config.h>
#include <fcgiapp.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
}
using namespace v8; // *puke*
#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';};"
static void PrintEnv(FCGX_Stream *out, char *label, char **envp)
{
FCGX_FPrintF(out, "%s:<br>\n<pre>\n", label);
@ -28,6 +36,31 @@ static void PrintEnv(FCGX_Stream *out, char *label, char **envp)
FCGX_FPrintF(out, "</pre><p>\n");
}
static void *load_jquery()
{
struct stat attributes;
int fd = 0;
int rc = 0;
rc = stat(JQUERY_FILE, &attributes);
if (rc != 0) {
/* I should do something with the error here */
return NULL;
}
void *jquery = malloc(sizeof(char) * (attributes.st_size + 2));
fd = open(JQUERY_FILE, 0);
if (fd == 0) {
/* I should do something with the error here */
close(fd);
return NULL;
}
rc = read(fd, jquery, attributes.st_size);
close(fd);
return jquery;
}
static void req_handle(FCGX_Stream *out, char **environment)
{
HandleScope scope;
@ -42,10 +75,18 @@ static void req_handle(FCGX_Stream *out, char **environment)
String::AsciiValue rc_str(rc);
FCGX_FPrintF(out, "Our test() JavaScript function returned:\n");
FCGX_FPrintF(out, "Our test() JavaScript function returned:<br/>\n");
FCGX_FPrintF(out, *rc_str);
FCGX_FPrintF(out, "<br/><br/><br/>");
PrintEnv(out, "foo", environment);
PrintEnv(out, "FastCGI Environment:", environment);
void *jq = load_jquery();
if (jq == NULL) {
/* FAIL! */
FCGX_FPrintF(out, "FAILED TO PROPERLY LOAD JQUERY!");
return;
}
}
int main ()
@ -61,7 +102,7 @@ int main ()
FCGX_FPrintF(out,
"Content-type: text/html\r\n"
"\r\n"
"<title>FastJS Sample Page"
"<html><title>FastJS Sample Page</title>"
"<h1>FastJS</h1>\n"
"Request number %d, Process ID: %d<p>\n", ++count, getpid());

19
jquery-1.3.2.min.js vendored Normal file

File diff suppressed because one or more lines are too long