some minor fixes

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3427 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2001-01-10 06:43:36 +00:00
parent 2c81e37fca
commit 2472116f80
2 changed files with 81 additions and 42 deletions

View File

@ -1,14 +1,15 @@
#include "fcgi_stdio.h" #include "fcgi_stdio.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
extern char **environ; extern char **environ;
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
char * query_string; char *query_string, *method, *len=0x0;
int count = 0; int count = 0;
int i; int i, ilen=0;
while(FCGI_Accept() >= 0){ while(FCGI_Accept() >= 0){
printf("Content-type: text/html\r\n" printf("Content-type: text/html\r\n"
@ -25,12 +26,27 @@ int main (int argc, char *argv[])
argv[0]); argv[0]);
query_string = getenv ("QUERY_STRING"); query_string = getenv ("QUERY_STRING");
printf ("<p>QUERY_STRING is %s<p>\n", query_string); printf ("<p>The QUERY_STRING environment vairable is %s\n"
"The other environment variables are:<p>", query_string);
for (i=0; environ[i]; i++) for (i=0; environ[i]; i++)
{ {
printf ("<br>%s\n", environ[i]); printf ("<br>%s\n", environ[i]);
} }
method = getenv ("REQUEST_METHOD");
if (!strcmp (method, "POST"))
{
char * bufp;
ilen = atoi (getenv ("CONTENT_LENGTH"));
printf ("<P>This is a method=post request, "
"with content length=%d<P>\n", ilen);
bufp = (char *) malloc (ilen);
fread (bufp, ilen, 1, stdin);
printf ("The POST data is<P>%s\n", bufp);
}
} }
return 0; return 0;
} }

View File

@ -10,6 +10,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "gnc-book.h" #include "gnc-book.h"
#include "gnc-engine.h" #include "gnc-engine.h"
@ -22,14 +23,13 @@
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
int fake_argc =1; int err, fake_argc =1;
char * fake_argv[] = {"hello", 0}; char * fake_argv[] = {"hello", 0};
GNCBook *book; GNCBook *book;
AccountGroup *grp; AccountGroup *grp;
char *bufp; char *bufp;
int rc, sz; int rc, sz;
/* intitialize the engine */ /* intitialize the engine */
gnc_engine_init (fake_argc, fake_argv); gnc_engine_init (fake_argc, fake_argv);
@ -37,20 +37,10 @@ main (int argc, char *argv[])
book = gnc_book_new (); book = gnc_book_new ();
rc = gnc_book_begin (book, "file:/tmp/demo.xac", FALSE); rc = gnc_book_begin (book, "file:/tmp/demo.xac", FALSE);
if (!rc) { if (!rc) goto bookerrexit;
int err = gnc_book_get_error (book);
/* 500 Server Error */
FCGI_SetExitStatus (500);
goto bookerrexit;
}
rc = gnc_book_load (book); rc = gnc_book_load (book);
if (!rc) { if (!rc) goto bookerrexit;
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 */ /* the grp pointer points to our local cache of the data */
grp = gnc_book_get_group (book); grp = gnc_book_get_group (book);
@ -65,48 +55,81 @@ main (int argc, char *argv[])
char *request_method; char *request_method;
int read_len=0; int read_len=0;
/* get the METHOD=POST data */ /* get the request method */
request_method = getenv ("REQUEST_METHOD"); request_method = getenv ("REQUEST_METHOD");
if (!strcmp ("POST", request_method)) {
/* Lets pretend that method=get means user has logged
* in. Send the user the accounts and currencies,
* but not the transactions/splits. */
if (!strcmp ("GET", request_method))
{
gncxml_write_group_to_buf(grp, &bufp, &sz);
/* print the HTTP header */
printf("Content-type: text/html\r\n"
"Content-Length: %d\r\n"
"\r\n", sz);
/* send the xml to the client */
printf ("%s", bufp);
free (bufp);
/* wait for the next request */
continue;
}
if (!strcmp ("POST", request_method))
{
char * content_length = getenv("CONTENT_LENGTH"); char * content_length = getenv("CONTENT_LENGTH");
read_len = atoi (content_length); read_len = atoi (content_length);
/* read 'read_len' bytes from stdin ... */ /* read 'read_len' bytes from stdin ... */
bufp = (char *) malloc (read_len);
fread (bufp, read_len, 1, stdin);
/* conver the xml input into a gnucash query structure... */
q = gncxml_read_query (bufp, read_len);
xaccQuerySetGroup (q, grp);
/* hack -- limit to 30 splits ... */
xaccQuerySetMaxSplits (q, 30);
split_list = xaccQueryGetSplits (q);
xaccFreeQuery (q);
/* wait for the next request */
continue;
} }
#if 0 /* if we got to here, an error -- unknown method */
/* conver the xml input into a gnucash query structure... */ printf("Content-type: text/plain\r\n"
q = gncxml_read_query (bufp, read_len); "\r\n"
xaccQuerySetGroup (q, grp); "unknown request type \n");
/* 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: bookerrexit:
err = gnc_book_get_error (book);
/* 500 Server Error */
FCGI_SetExitStatus (500);
printf("Content-type: text/plain\r\n\r\n"
"error was %s\n", strerror (err));
FCGI_Finish();
/* close the book */ /* close the book */
gnc_book_destroy (book); gnc_book_destroy (book);
/* shut down the engine */ /* shut down the engine */
gnc_engine_shutdown (); gnc_engine_shutdown ();
sleep (1);
return 0; return 0;
} }