JS Ext

Wednesday, September 26, 2012

Simplexmlrpc

Simplexmlrpc is a c library I wrote for my multimedia frontend.  It is a simple Xmlrpc client and server.  I wrote it because I was unhappy with the various Xmlrpc c/c++ implementations.  Most were pretty complex and didn't make it really easy to wrap within a SpiderMonkey Javascript object.  I wanted a library that had simple reference counting garbage collection.  I also wanted to override the transport mechanism.  I didn't want to be tied down to the http client and server that the library used.

Simplexmlrpc is written as a single c++ file, but it exposes a c interface.  This allows the library to be directly embedded into another project, or to be packaged up as an external .so or .dll file.  I declare a public abstract type of simplexmlrpc_value that is reference counted.  Under the hood, the type points to a class.  The simplexmlrpc_create* functions create the appropriate instance of the class.  This structure closely matches Spidermonkey's jsval structure.  In my multimedia frontend, I was able to write xmlrpc2jsval and jsval2xmlrpc functions that recursively translate between the two libraries.  This allowed me to write javascript client code that calls javascript server code (on another computer) without having to manually translate every argument.  The serialization of the json arguments are automatic.

Another feature that I needed was the ability to use a custom transport.  In my multimedia frontend, I have a master server and multiple slave servers.  The communication between the servers is xmlrpc.  A lot of the code is shared between the implementations, though.  In many ways, the master also operates as a slave.  Any communication between a slave and the master also happens between the master and itself.  What is the point of making an http call out and back into itself?  The simplexmlrpc_generateCall() function allows you to get the xmlrpc client xml and pass it directly to the simplexmlrpc_processMessageFree() function.  I created a wrapper function inside of the multimedia software code.  That wrapper allows for url aliases.  One of the aliases is master://.  Any xmlrpc calls going to that url will automatically go to the master server.  If the client is currently running on a slave or the user interface, then the url gets rewritten to the url of the master server.  If the client is currentl running inside of the master, then the http transport is completely bypassed.

Simplexmlrpc also supports security levels.  The idea with security levels is you can have a different set of methods show up based on authorizations and authorization.  You can have a set of public methods.  Then you can have a set of methods for regular users.  Then you can have per methods for admin users.
The library also provides direct integrations with curl and the Mongoose HTTP server.  The Mongoose api that is used is for an older version, however.  A few features of the xmlrpc spec have not been implemented yet.  Simplexmlrpc is missing support for the date/time and base64 types.

Overall, my biased opinion is that Simplexmlrpc is a simple yet powerful implementation of the xmlrpc standard.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.