simplexmlrpc.h

Summary
simplexmlrpc.h
FeaturesFeatures of the xmlrpc implementation
Alternative transportsSimplexmlrpc supports using a transport mechanism other than http/https.
Security levelsSimplexmlrpc supports an extension to the xmlrpc protocol.
Nil type supportSimplexmlrpc supports the Nil datatype/value extension that many popular xmlrpc implementations also support
IntrospectionSimplexmlrpc supports very basic introspection.
Missing Features
Date/Time type supportSimplexmlrpc does not support the xmlrpc date/time format
Base64/binary supportSimplexmlrpc does not support the xmlrpc base64 type to support binary data
Usage
Memory Managmentsimplexmlrpc_value objects are reference-counted.
TypesAPI Types
simplexmlrpc_valueRepresents an xmlrpc value
simplexmlrpc_registryA registry of server-side methods that can be called remotely
simplexmlrpc_contextContext information for a server-side xmlrpc call.
simplexmlrpc_method_cbCallback function that gets called with an xmlrpc method is executed
Common functionsFunctions that are used in both the server and the client
simplexmlrpc_setErrorStringSet the error string in the value
simplexmlrpc_setErrorCodeSet the error code in the value
simplexmlrpc_getErrorCodeGet the error code from a value
simplexmlrpc_getErrorStringGet the error string from the value
simplexmlrpc_isErrorCheck if a value is an error
simplexmlrpc_isIntCheck if the value is an integer type
simplexmlrpc_isDoubleCheck if the value is a double type
simplexmlrpc_isStringCheck if the value is a string type
simplexmlrpc_isBooleanCheck if the value is a boolean type
simplexmlrpc_isArrayCheck if the value is a array type
simplexmlrpc_isStructCheck if the value is a struct type
simplexmlrpc_getIntValueGet the 32-bit integer from the value
simplexmlrpc_getDoubleValueGet the double-precision floating point number from the value
simplexmlrpc_getStringValueGet the string from the value and put it into the passed in pointer
simplexmlrpc_getStringValueDupGet the string from the value
simplexmlrpc_getBooleanValueGet the boolean value
simplexmlrpc_getArraySizeGet the size of the array
simplexmlrpc_getArrayItemGet an item from the array
simplexmlrpc_getStructSizeGet the size of the struct
simplexmlrpc_hasStructKeyCheck if a struct has a key
simplexmlrpc_getStructKeyGet the key in the struct at the given index
simplexmlrpc_getStructValueGet the value from the struct with the given key
simplexmlrpc_getStructValueStringDupHelper function for getting a string value from a struct at a given key
simplexmlrpc_getStructValueIntHelper function for getting an integer value from a struct at a given key
simplexmlrpc_createNilCreate a nil value
simplexmlrpc_createIntCreate a 32-bit integer value
simplexmlrpc_createDoubleCreate a double-precision floating point value
simplexmlrpc_createBooleanCreate a boolean value
simplexmlrpc_createStringCreate a string value
simplexmlrpc_createArrayCreate an array
simplexmlrpc_createStructCreate a structure value
simplexmlrpc_appendArrayItemAppend an item to an array
simplexmlrpc_addStructItemAdd a value to the structure
simplexmlrpc_incRefIncrement the value’s reference counter
simplexmlrpc_decRef
simplexmlrpc_freewrapper around free()
simplexmlrpc_freeStrwrapper around free()
Server functionsFunctions that are part of the server api
simplexmlrpc_createRegistryCreate a new xmlrpc registry
simplexmlrpc_destroyRegistryDestroy an xmlrpc registry
simplexmlrpc_context_createCreate a method call context
simplexmlrpc_context_destroyDestroys an method call context
simplexmlrpc_context_setFuncNameSet the function name for the context
simplexmlrpc_context_getFuncNameGet the name of the function that is being executed
simplexmlrpc_context_setSecurityLevelSet the method call security level.
simplexmlrpc_context_getSecurityLevelGet the current security level
simplexmlrpc_createErrorCreate an error value
simplexmlrpc_addIntrospectionAdd introspection xmlrpc methods
simplexmlrpc_registry_addMethodRegister a method with the xmlrpc server
simplexmlrpc_processMessageFreeProcess an xmlrpc request xml and return an xmlrpc response xml
simplexmlrpc_mongoose_registerRegister an xmlrpc register with the mongoose http daemon at the given uri
simplexmlrpc_mongoose_switchRegisterSwitch which method registry will get used.
Client functionsFunctions for the client api
simplexmlrpc_generateCallGenerate an xmlrpc request xml for the given method and parameters
simplexmlrpc_httpCallMake an xmlrpc call using libcurl
simplexmlrpc_httpCallWithAuthMake an xmlrpc call using libcurl

Features

Features of the xmlrpc implementation

Alternative transports

Simplexmlrpc supports using a transport mechanism other than http/https.  The simplexmlrpc_generateCall() function can be used to generate the xmlrpc method call xml.  This xml can then be passed to an xmlrpc server using any transport mechanism that you want.  Interesting transports could include unix domain sockets or using stdin/stdout for interprocess communication.  Another interesting option is for internal-process communication.  You can actually pass the output of the simplexmlrpc_generateCall() function to the simplexmlrpc_processMessageFree() function.  This allows a developer to make an xmlrpc call directly to the xmlrpc registry in its own process.

Security levels

Simplexmlrpc supports an extension to the xmlrpc protocol.  Every method has an integer-based security level.  When an incoming xmlrpc request comes into the xmlrpc server, a security level number is assigned to the request.  The request can only see methods that have a security level that is lower than or equal to its own security level.  The best example of this feature are methods that are either open to the public or are limited to authenticated users.  If an unauthenticated user calls the system.listMethods() introspection call, then only the public xmlrpc methods are shown.  If an authenticated user calls the system.listMethods() method, then that user will see all the methods

Nil type support

Simplexmlrpc supports the Nil datatype/value extension that many popular xmlrpc implementations also support

Introspection

Simplexmlrpc supports very basic introspection.  At this point, only the system.listMethods() method is available.

Missing Features

Date/Time type support

Simplexmlrpc does not support the xmlrpc date/time format

Base64/binary support

Simplexmlrpc does not support the xmlrpc base64 type to support binary data

Usage

Memory Managment

simplexmlrpc_value objects are reference-counted.  Use the simplexmlrpc_incRef and simplexmlrpc_decRef functions to increase and decrease references to the value objects.  When the reference counter goes to 0, the object will automatically be deleted.

Types

API Types

simplexmlrpc_value

Represents an xmlrpc value

simplexmlrpc_registry

A registry of server-side methods that can be called remotely

simplexmlrpc_context

Context information for a server-side xmlrpc call.  The context gives you information on what method was called and what security level the call was made in

simplexmlrpc_method_cb

Callback function that gets called with an xmlrpc method is executed

Common functions

Functions that are used in both the server and the client

simplexmlrpc_setErrorString

void simplexmlrpc_setErrorString(simplexmlrpc_value val,
const char *str)

Set the error string in the value

Params

valvalue to set the error string in
strerror message

simplexmlrpc_setErrorCode

void simplexmlrpc_setErrorCode(simplexmlrpc_value val,
int code)

Set the error code in the value

Param

valvalue to set the error code in
codeerror code to set

simplexmlrpc_getErrorCode

int simplexmlrpc_getErrorCode(simplexmlrpc_value val)

Get the error code from a value

Param

valvalue to get the error code from

Returns

Error code

simplexmlrpc_getErrorString

const char *simplexmlrpc_getErrorString(simplexmlrpc_value val)

Get the error string from the value

Params

valvalue to get the error string from

Returns

error string (must be free’ed)

simplexmlrpc_isError

int simplexmlrpc_isError(simplexmlrpc_value val)

Check if a value is an error

Params

valvalue to check

Returns

true if the value is an xmlrpc error

simplexmlrpc_isInt

int simplexmlrpc_isInt(simplexmlrpc_value val)

Check if the value is an integer type

Param

valvalue to check

Returns

true if the value is an xmlrpc integer

simplexmlrpc_isDouble

int simplexmlrpc_isDouble(simplexmlrpc_value val)

Check if the value is a double type

Params

valvalue to check

Returns

true if the value is an xmlrpc double

simplexmlrpc_isString

int simplexmlrpc_isString(simplexmlrpc_value val)

Check if the value is a string type

Params

valvalue to check

Returns

true if the value is an xmlrpc string

simplexmlrpc_isBoolean

int simplexmlrpc_isBoolean(simplexmlrpc_value val)

Check if the value is a boolean type

Params

valvalue to check

Returns

true if the value is an xmlrpc boolean

simplexmlrpc_isArray

int simplexmlrpc_isArray(simplexmlrpc_value val)

Check if the value is a array type

Params

valvalue to check

Returns

true if the value is an xmlrpc array

simplexmlrpc_isStruct

int simplexmlrpc_isStruct(simplexmlrpc_value val)

Check if the value is a struct type

Params

valvalue to check

Returns

true if the value is an xmlrpc struct

simplexmlrpc_getIntValue

int32_t simplexmlrpc_getIntValue(simplexmlrpc_value val)

Get the 32-bit integer from the value

Params

valvalue to get the integer from

Returns

32-bit signed integer

simplexmlrpc_getDoubleValue

double simplexmlrpc_getDoubleValue(simplexmlrpc_value val)

Get the double-precision floating point number from the value

Params

valvalue to get the double from

Returns

double-precision floating point number

simplexmlrpc_getStringValue

int simplexmlrpc_getStringValue(simplexmlrpc_value val,
char *ret,
size_t max)

Get the string from the value and put it into the passed in pointer

Params

valvalue to get the string from
retchar array to put the string into
maxmax number of characters to put into the character array

Returns

number of bytes put into the character array

simplexmlrpc_getStringValueDup

const char *simplexmlrpc_getStringValueDup(simplexmlrpc_value val)

Get the string from the value

Params

valvalue to get the string from

Returns

character array that must be free’ed

simplexmlrpc_getBooleanValue

int simplexmlrpc_getBooleanValue(simplexmlrpc_value val)

Get the boolean value

Params

valvalue to get the boolean from

Returns

boolean value as an integer (for c compatibility)

simplexmlrpc_getArraySize

size_t simplexmlrpc_getArraySize(simplexmlrpc_value val)

Get the size of the array

Params

valvalue to get the array size from

Returns

size of the array

simplexmlrpc_getArrayItem

simplexmlrpc_value simplexmlrpc_getArrayItem(simplexmlrpc_value val,
size_t index)

Get an item from the array

Params

valvalue to get an array from
indexindex in the array to get

Returns

value at the given index

simplexmlrpc_getStructSize

size_t simplexmlrpc_getStructSize(simplexmlrpc_value val)

Get the size of the struct

Params

valvalue to get the size of

Returns

The number of elements in the stuct

simplexmlrpc_hasStructKey

int simplexmlrpc_hasStructKey(simplexmlrpc_value val,
const char *key)

Check if a struct has a key

Params

valstruct value to check for a key in
keykey to check

Returns

true if the key exists in the struct

simplexmlrpc_getStructKey

const char *simplexmlrpc_getStructKey(simplexmlrpc_value val,
size_t index)

Get the key in the struct at the given index

Params

valstruct value
indexindex to get the key for

Returns

key

simplexmlrpc_getStructValue

simplexmlrpc_value simplexmlrpc_getStructValue(simplexmlrpc_value val,
const char *key)

Get the value from the struct with the given key

Params

valstruct value
keykey to get the value for

Returns

value at the given key in the struct

simplexmlrpc_getStructValueStringDup

const char *simplexmlrpc_getStructValueStringDup(simplexmlrpc_value val,
const char *key)

Helper function for getting a string value from a struct at a given key

Params

valstruct value
keykey to get the value from

Returns

the string value at the given key (needs to be free’ed)

simplexmlrpc_getStructValueInt

int32_t simplexmlrpc_getStructValueInt(simplexmlrpc_value val,
const char *key)

Helper function for getting an integer value from a struct at a given key

Params

valstruct value
keykey to get the value from

Returns

the integer value at the given key

simplexmlrpc_createNil

simplexmlrpc_value simplexmlrpc_createNil()

Create a nil value

Returns

a nil value

simplexmlrpc_createInt

simplexmlrpc_value simplexmlrpc_createInt(int32_t val)

Create a 32-bit integer value

Params

val32-bit signed integer

Returns

an integer value

simplexmlrpc_createDouble

simplexmlrpc_value simplexmlrpc_createDouble(double val)

Create a double-precision floating point value

Params

valdouble value

Returns

a double value

simplexmlrpc_createBoolean

simplexmlrpc_value simplexmlrpc_createBoolean(int val)

Create a boolean value

Params

valtrue/false boolean value

Returns

a boolean value

simplexmlrpc_createString

simplexmlrpc_value simplexmlrpc_createString(const char *val)

Create a string value

Params

valstring value

Returns

a string xmlrpc value

simplexmlrpc_createArray

simplexmlrpc_value simplexmlrpc_createArray()

Create an array

Returns

array value

simplexmlrpc_createStruct

simplexmlrpc_value simplexmlrpc_createStruct()

Create a structure value

Returns

structure value

simplexmlrpc_appendArrayItem

int simplexmlrpc_appendArrayItem(simplexmlrpc_value val,
simplexmlrpc_value v)

Append an item to an array

Params

valarray value
vvalue to append to the array

Returns

new size of the array

simplexmlrpc_addStructItem

int simplexmlrpc_addStructItem(simplexmlrpc_value val,
const char *key,
simplexmlrpc_value v)

Add a value to the structure

Params

valstruct value
keykey to associate the value with
vvalue to put into the struct

Returns

new size of the structure

simplexmlrpc_incRef

void simplexmlrpc_incRef(simplexmlrpc_value val)

Increment the value’s reference counter

Params

valvalue add a reference to

simplexmlrpc_decRef

void simplexmlrpc_decRef(simplexmlrpc_value val)

Params

valvalue to remove a reference to

simplexmlrpc_free

void simplexmlrpc_free(void *ptr)

wrapper around free()

Params

ptrpointer to free

simplexmlrpc_freeStr

void simplexmlrpc_freeStr(const char *ptr)

wrapper around free()

Params

ptrpointer to free

Server functions

Functions that are part of the server api

simplexmlrpc_createRegistry

simplexmlrpc_registry simplexmlrpc_createRegistry()

Create a new xmlrpc registry

Returns

xmlrpc registry

simplexmlrpc_destroyRegistry

void simplexmlrpc_destroyRegistry(simplexmlrpc_registry reg)

Destroy an xmlrpc registry

Params

regxmlrpc registry to destroy

simplexmlrpc_context_create

simplexmlrpc_context simplexmlrpc_context_create()

Create a method call context

Returns

a new method call context

simplexmlrpc_context_destroy

void simplexmlrpc_context_destroy(simplexmlrpc_context ctx)

Destroys an method call context

Params

ctxcontext to destroy

simplexmlrpc_context_setFuncName

void simplexmlrpc_context_setFuncName(simplexmlrpc_context ctx,
const char *funcName)

Set the function name for the context

Params

ctxcontext to set the function name in
funcNamename of the function that is being executed

simplexmlrpc_context_getFuncName

const char *simplexmlrpc_context_getFuncName(simplexmlrpc_context ctx)

Get the name of the function that is being executed

Params

ctxcontext to get the function name from

Returns

the current function name being called

simplexmlrpc_context_setSecurityLevel

void simplexmlrpc_context_setSecurityLevel(simplexmlrpc_context ctx,
int level)

Set the method call security level.  This method should be called by the http server before calling simplexmlrpc_processMessageFree

Params

ctxcontext to set the security level in
levelsecurity level

simplexmlrpc_context_getSecurityLevel

int simplexmlrpc_context_getSecurityLevel(simplexmlrpc_context ctx)

Get the current security level

Params

ctxcontext to get the security level from

Returns

The current security level

simplexmlrpc_createError

simplexmlrpc_value simplexmlrpc_createError(int code,
const char *msg)

Create an error value

Params

codeerror code
msgerror message

Returns

an xmlrpc error value

simplexmlrpc_addIntrospection

void simplexmlrpc_addIntrospection(simplexmlrpc_registry reg)

Add introspection xmlrpc methods

Params

regmethod registry to add introspection to

simplexmlrpc_registry_addMethod

void simplexmlrpc_registry_addMethod(simplexmlrpc_registry reg,
const char *method,
int secure,
simplexmlrpc_method_cb func,
void *data)

Register a method with the xmlrpc server

Params

regxmlrpc method registry
methodname of the method
securesecurity level
funcfunction pointer that gets executed
datauser data

simplexmlrpc_processMessageFree

int simplexmlrpc_processMessageFree(simplexmlrpc_registry reg,
simplexmlrpc_context ctx,
const char *xmlIn,
char **xmlOut)

Process an xmlrpc request xml and return an xmlrpc response xml

Params

regmethod registry
ctxmethod call context
xmlInrequest xml
xmlOutpointer to a character array that will contain the xml response

Returns

0 if the call succeeded, 1 if it failed

simplexmlrpc_mongoose_register

void* simplexmlrpc_mongoose_register(simplexmlrpc_registry reg,
struct mg_context *ctx,
const char *uri,
void *data)

Register an xmlrpc register with the mongoose http daemon at the given uri

Params

regmethod registry
ctxmongoose context
uriuri that will process xmlrpc methods
datauser data

Returns

simplexmlrpc_mongoose_t structure

simplexmlrpc_mongoose_switchRegister

void simplexmlrpc_mongoose_switchRegister(void *ctx,
simplexmlrpc_registry reg)

Switch which method registry will get used.  This is used as a thread-safe way to add more methods to a registry.  Instead of modifying an existing registry, you create a new one and switch it out

Params

ctxsimplexmlrpc_mongoose_t structure
regnew method registry

Client functions

Functions for the client api

simplexmlrpc_generateCall

const char *simplexmlrpc_generateCall(const char *method,
simplexmlrpc_value val)

Generate an xmlrpc request xml for the given method and parameters

Params

methodname of the method to call
valmethod parameters

Returns

request xml

simplexmlrpc_httpCall

simplexmlrpc_value simplexmlrpc_httpCall(const char *url,
const char *method,
simplexmlrpc_value val)

Make an xmlrpc call using libcurl

Params

urlurl to call
methodmethod to call
valmethod parameters

Returns

return value

simplexmlrpc_httpCallWithAuth

simplexmlrpc_value simplexmlrpc_httpCallWithAuth(const char *url,
const char *user,
const char *pass,
const char *method,
simplexmlrpc_value val)

Make an xmlrpc call using libcurl

Params

urlurl to call
userusername
passpassword
methodmethod to call
valmethod parameters

Returns

return value

Represents an xmlrpc value
void simplexmlrpc_setErrorString(simplexmlrpc_value val,
const char *str)
Set the error string in the value
void simplexmlrpc_setErrorCode(simplexmlrpc_value val,
int code)
Set the error code in the value
int simplexmlrpc_getErrorCode(simplexmlrpc_value val)
Get the error code from a value
const char *simplexmlrpc_getErrorString(simplexmlrpc_value val)
Get the error string from the value
int simplexmlrpc_isError(simplexmlrpc_value val)
Check if a value is an error
int simplexmlrpc_isInt(simplexmlrpc_value val)
Check if the value is an integer type
int simplexmlrpc_isDouble(simplexmlrpc_value val)
Check if the value is a double type
int simplexmlrpc_isString(simplexmlrpc_value val)
Check if the value is a string type
int simplexmlrpc_isBoolean(simplexmlrpc_value val)
Check if the value is a boolean type
int simplexmlrpc_isArray(simplexmlrpc_value val)
Check if the value is a array type
int simplexmlrpc_isStruct(simplexmlrpc_value val)
Check if the value is a struct type
int32_t simplexmlrpc_getIntValue(simplexmlrpc_value val)
Get the 32-bit integer from the value
double simplexmlrpc_getDoubleValue(simplexmlrpc_value val)
Get the double-precision floating point number from the value
int simplexmlrpc_getStringValue(simplexmlrpc_value val,
char *ret,
size_t max)
Get the string from the value and put it into the passed in pointer
const char *simplexmlrpc_getStringValueDup(simplexmlrpc_value val)
Get the string from the value
int simplexmlrpc_getBooleanValue(simplexmlrpc_value val)
Get the boolean value
size_t simplexmlrpc_getArraySize(simplexmlrpc_value val)
Get the size of the array
simplexmlrpc_value simplexmlrpc_getArrayItem(simplexmlrpc_value val,
size_t index)
Get an item from the array
size_t simplexmlrpc_getStructSize(simplexmlrpc_value val)
Get the size of the struct
int simplexmlrpc_hasStructKey(simplexmlrpc_value val,
const char *key)
Check if a struct has a key
const char *simplexmlrpc_getStructKey(simplexmlrpc_value val,
size_t index)
Get the key in the struct at the given index
simplexmlrpc_value simplexmlrpc_getStructValue(simplexmlrpc_value val,
const char *key)
Get the value from the struct with the given key
const char *simplexmlrpc_getStructValueStringDup(simplexmlrpc_value val,
const char *key)
Helper function for getting a string value from a struct at a given key
int32_t simplexmlrpc_getStructValueInt(simplexmlrpc_value val,
const char *key)
Helper function for getting an integer value from a struct at a given key
simplexmlrpc_value simplexmlrpc_createNil()
Create a nil value
simplexmlrpc_value simplexmlrpc_createInt(int32_t val)
Create a 32-bit integer value
simplexmlrpc_value simplexmlrpc_createDouble(double val)
Create a double-precision floating point value
simplexmlrpc_value simplexmlrpc_createBoolean(int val)
Create a boolean value
simplexmlrpc_value simplexmlrpc_createString(const char *val)
Create a string value
simplexmlrpc_value simplexmlrpc_createArray()
Create an array
simplexmlrpc_value simplexmlrpc_createStruct()
Create a structure value
int simplexmlrpc_appendArrayItem(simplexmlrpc_value val,
simplexmlrpc_value v)
Append an item to an array
int simplexmlrpc_addStructItem(simplexmlrpc_value val,
const char *key,
simplexmlrpc_value v)
Add a value to the structure
void simplexmlrpc_incRef(simplexmlrpc_value val)
Increment the value’s reference counter
void simplexmlrpc_decRef(simplexmlrpc_value val)
void simplexmlrpc_free(void *ptr)
wrapper around free()
void simplexmlrpc_freeStr(const char *ptr)
wrapper around free()
simplexmlrpc_registry simplexmlrpc_createRegistry()
Create a new xmlrpc registry
void simplexmlrpc_destroyRegistry(simplexmlrpc_registry reg)
Destroy an xmlrpc registry
simplexmlrpc_context simplexmlrpc_context_create()
Create a method call context
void simplexmlrpc_context_destroy(simplexmlrpc_context ctx)
Destroys an method call context
void simplexmlrpc_context_setFuncName(simplexmlrpc_context ctx,
const char *funcName)
Set the function name for the context
const char *simplexmlrpc_context_getFuncName(simplexmlrpc_context ctx)
Get the name of the function that is being executed
void simplexmlrpc_context_setSecurityLevel(simplexmlrpc_context ctx,
int level)
Set the method call security level.
int simplexmlrpc_context_getSecurityLevel(simplexmlrpc_context ctx)
Get the current security level
simplexmlrpc_value simplexmlrpc_createError(int code,
const char *msg)
Create an error value
void simplexmlrpc_addIntrospection(simplexmlrpc_registry reg)
Add introspection xmlrpc methods
void simplexmlrpc_registry_addMethod(simplexmlrpc_registry reg,
const char *method,
int secure,
simplexmlrpc_method_cb func,
void *data)
Register a method with the xmlrpc server
int simplexmlrpc_processMessageFree(simplexmlrpc_registry reg,
simplexmlrpc_context ctx,
const char *xmlIn,
char **xmlOut)
Process an xmlrpc request xml and return an xmlrpc response xml
void* simplexmlrpc_mongoose_register(simplexmlrpc_registry reg,
struct mg_context *ctx,
const char *uri,
void *data)
Register an xmlrpc register with the mongoose http daemon at the given uri
void simplexmlrpc_mongoose_switchRegister(void *ctx,
simplexmlrpc_registry reg)
Switch which method registry will get used.
const char *simplexmlrpc_generateCall(const char *method,
simplexmlrpc_value val)
Generate an xmlrpc request xml for the given method and parameters
simplexmlrpc_value simplexmlrpc_httpCall(const char *url,
const char *method,
simplexmlrpc_value val)
Make an xmlrpc call using libcurl
simplexmlrpc_value simplexmlrpc_httpCallWithAuth(const char *url,
const char *user,
const char *pass,
const char *method,
simplexmlrpc_value val)
Make an xmlrpc call using libcurl
Close