demo fastcgi code. pre-pre-pre alpha

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3415 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas
2001-01-09 07:13:51 +00:00
parent 2b35ce6d71
commit e1df0473bc
5 changed files with 190 additions and 5 deletions

View File

@@ -1,13 +1,13 @@
# cgi-bin Makefile.am file.
bin_PROGRAMS = hello hello2
bin_PROGRAMS = hello hello2 fastcgi-hello gnc-server
CFLAGS = @CFLAGS@ ${GLIB_CFLAGS}
LDADD = \
../../engine/libgncengine.la \
-lxml -lghttp -lglib
-lxml -lghttp -lglib -lfcgi
INCLUDES =
@@ -17,6 +17,12 @@ hello_SOURCES = \
hello2_SOURCES = \
hello2.c
fastcgi_hello_SOURCES = \
fastcgi-hello.c
gnc_server_SOURCES = \
gnc-server.c
noinst_HEADERS =

View File

@@ -1 +1,32 @@
this is some cgi-bin testing
---------------
The fast-cgi applcation requires fast-cgi to be installed.
www.fastcgi.com
This takes some doing:
-- there are two parts to fast_cgi -- the apache module,
and the development kit. You need only the development
kit to build these demos; but you need the server module
to run them.
(Note: instead of using the apache module, you can
also use the 'cgi-fcgi' server that comes with the
fcgi development kit. With this program, you don't
need to recompile the apache server or install any
modules.)
-- To install the server module:
-- apache must be compiled by hand (there were no
fastcgi RPM's that I could find).
-- the mod_fastcgi apache module must be installed
& configured as per directions on www.fastcgi.com
-- the fast-cgi development toolkit must be downloaded
and installed.
===================
The gnc-server is a pre-pre-pre-alpha server for gnucash.
A huge anmount of work is needed to make it run right.
--linas

View File

@@ -0,0 +1,36 @@
#include "fcgi_stdio.h"
#include <stdlib.h>
extern char **environ;
int main (int argc, char *argv[])
{
char * query_string;
int count = 0;
int i;
while(FCGI_Accept() >= 0){
printf("Content-type: text/html\r\n"
"\r\n"
"<title>FastCGI Hello!</title>"
"<h1>FastCGI Hello!</h1>"
"Request number %d running on host <i>%s</i>\n",
++count, getenv("SERVER_NAME"));
printf("<p>If you have configured fastcgi correctly, then "
"the request number should increment every time you "
"hit reload on your browser. You should also see "
"\"%s\" (the name of this program) showing up in ps ax.\n",
argv[0]);
query_string = getenv ("QUERY_STRING");
printf ("<p>QUERY_STRING is %s<p>\n", query_string);
for (i=0; environ[i]; i++)
{
printf ("<br>%s\n", environ[i]);
}
}
return 0;
}

View File

@@ -0,0 +1,112 @@
/*
* FILE:
* gnc-server.c
*
* FUNCTION:
* experimental gnucash server
* written as a demo, not real code.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gnc-book.h"
#include "gnc-engine.h"
#include "Group.h"
#include "io-gncxml.h"
#include "fcgi_stdio.h"
int
main (int argc, char *argv[])
{
int fake_argc =1;
char * fake_argv[] = {"hello", 0};
GNCBook *book;
AccountGroup *grp;
char *bufp;
int rc, sz;
/* intitialize the engine */
gnc_engine_init (fake_argc, fake_argv);
/* contact the database, which is a flat file for this demo */
book = gnc_book_new ();
rc = gnc_book_begin (book, "file:/tmp/demo.xac", FALSE);
if (!rc) {
int err = gnc_book_get_error (book);
/* 500 Server Error */
FCGI_SetExitStatus (500);
goto bookerrexit;
}
rc = gnc_book_load (book);
if (!rc) {
int err = gnc_book_get_error (book);
/* 500 Server Error */
FCGI_SetExitStatus (500);
goto bookerrexit;
}
/* the grp pointer points to our local cache of the data */
grp = gnc_book_get_group (book);
/* --------------------------------------------------- */
/* done with initialization, go into event loop */
while(FCGI_Accept() >= 0)
{
GList *split_list;
Query *q = NULL;
char *request_method;
int read_len=0;
/* get the METHOD=POST data */
request_method = getenv ("REQUEST_METHOD");
if (!strcmp ("POST", request_method)) {
char * content_length = getenv("CONTENT_LENGTH");
read_len = atoi (content_length);
/* read 'read_len' bytes from stdin ... */
}
#if 0
/* conver the xml input into a gnucash query structure... */
q = gncxml_read_query (bufp, read_len);
xaccQuerySetGroup (q, grp);
/* hack ... */
xaccQuerySetMaxSplits (q, 30);
split_list = xaccQueryGetSplits (q);
#endif
/* generate the xml output */
/* hack -- we need to use the split list to generate the xml ... */
gncxml_write_to_buf(grp, &bufp, &sz);
/* print the HTTP header */
printf("Content-type: text/html\r\n"
"Content-Length: %d\r\n"
"\r\n", sz);
printf ("%s", bufp);
free (bufp);
// xaccFreeQuery (q);
}
bookerrexit:
/* close the book */
gnc_book_destroy (book);
/* shut down the engine */
gnc_engine_shutdown ();
return 0;
}

View File

@@ -60,9 +60,9 @@ main (int argc, char *argv[])
/* print the HTTP header */
printf ("HTTP/1.1 200 OK\n");
printf ("Content-Type: text/xml\n");
printf ("Content-Length: %d\n", sz);
printf ("\n");
printf ("Content-Type: text/gnc-xml\r\n");
printf ("Content-Length: %d\r\n", sz);
printf ("\r\n");
printf ("%s", bufp);
free (bufp);