XML-RPC interface (was: Will GnuCash ever work for me?)

Bill Gribble grib@linuxdevel.com
24 Sep 2001 22:08:10 -0500


On Mon, 2001-09-24 at 19:56, Linas Vepstas wrote:
> Tell me more.  You know, of course, that I had once started work on a
> gnucash-cgi-bin, so I'm surprised to read the above.

We needed the ability to send transactions collected in a Java GUI to
the Gnucash backend, which may be on another machine (thin client type
deal). When I started looking at what the different inter-language call
options were, and considering the networking needs of the app, XML-RPC
looked pretty good (seems like Java has pretty good XML support; for
whatever reason, the available tools are pretty good).  Anyway, I didn't
start out intending to use a web server but it was easier to do that for
a first hack than make gnucash start listening on its own port.

The situation now is you first make a "new session" call to the cgi
script, which launches a stripped-down Gnucash that in turn opens a unix
domain socket to do the XML-RPC io through.  The name of the socket gets
passed back to the calling Java program, which uses it as a key for all
future calls to get to the right instance of Gnucash on the server side.
XML-RPC method calls are looked up in a table; you have to explicitly 
publish a function in the server startup for it to be visible to the
client.  Here's the file trivial-server.scm that I use in the xmlrpc
module tests: 

=====

(use-modules (gnucash gnc-module))
(gnc:module-load "gnucash/xmlrpc" 0)

(gnc:xmlrpc-publish-method 
 "add2"
 (lambda (a b)
   (+ a b)))

(gnc:xmlrpc-publish-method
 "sub2"
 (lambda (a b)
    (- a b)))

(gnc:xmlrpc-init)
(display (gnc:xmlrpc-socket-name)) (newline) (force-output)
(gnc:xmlrpc-main-loop)

=====

Obviously this test doesn't use the engine at all, but it's easy
to use the engine module and publish some subset of its symbols. It's
sort of limited right now; there's no real support for any pointer types
passing back and forth, etc.  For our app I have hacked up a very
"special" (i.e. lobotomized) API that gets published to XML-RPC. 

So the only thing the web server is doing is handling the SSL parts of
the HTTPS transactions to send the data to and from the gnucash server.
This isn't really a CGI interface to Gnucash in the sense that you would
point a browser at it. 

b.g.