XML-RPC requests are carried in the body of HTTP requests, but HTTP requests does not contain some mandatory SIP headers and thus cannot be processed by SER directly.
This is the main file of XMLRPC SER module which contains all the functions related to XML-RPC processing, as well as the module interface.
This module provides XML-RPC based interface to management functions in SER. You can send XML-RPC requests to SER when the module is loaded and configured and it will send XML-RPC replies back. XML-RPC requests are encoded as XML documents in the body of HTTP requests. Due to similarity between HTTP and SIP SER can easily parse HTTP requests and extract the XML document from their body.
When you load this module into SER, it will register a callback function that will be called whenever the SER core receives a request with method it does not understand. The main callback function is process_xmlrpc(). The function first verifies if the protocol identifier inside the request is HTTP and whether the request method is either GET or POST. If both conditions are met then it will signal to the SER core that it is processing the request, otherwise it will reject the request and the SER core will pass the requests to other callbacks if they exist.
As the next step the request will be converted from HTTP request to a SIP request to ensure that it can be processed by SER and its modules. The conversion will modify the URI in the Request-URI of the request, the new URI will be a SIP URI. In addition to that it will add a fake Via header field and copy all remaining header fields from the original HTTP request. The conversion is implemented in http_xmlrpc2sip() function.
After the conversion the module will execute the route statement whose number is configured in "route" module parameter. That route stament may perform additional security checks and when it ensures that the client is authorized to execute management functions then it will call dispatch_rpc() module function provided by this module.
dispatch_rpc() function extracts the XML-RPC document from the body of the request to determine the name of the method to be called and then it searches through the list of all management functions to find a function with matching name. If such a function is found then dispatch_rpc() will pass control to the function to handle the request. dispatch_rpc() will send a reply back to the client when the management function terminates, if the function did not do that explicitly.
The module provides implementation for all the functions required by the management interface in SER, such as rpc->printf, rpc->add, rpc->struct_add and so on. Whenever the management function calls one of the functions then corresponding function in this module will be called to handle the request.
The implementation functions build the reply, that will be sent to the client, as they execute and they need to allocate memory to do that. That memory must be freed again after the reply has been sent to the client. To remember all the memory regions allocated during the execution of the management function all functions within this module record all allocated memory in the global variable called waste_bin. dispatch_rpc() functions executes function collect_garbage() after the reply has been sent to the client to free all memory that was allocated from the management function. that was executed.
Before the module calls a management function it prepares a structure called context. The context is defined in structure rpc_ctx and it is passed as one of parameter to the management function being called. The context contains all the data that is needed during the execution of the management function, such as the pointer to the request being processed, a pointer to the reply being built, and so on.
Another parameter to the management function being called is a structure that contains pointers to all implementation functions. This structure is of type rpc_t, this module keeps one global variable of that type called func_param and a pointer to that variable is passed to all management functions. The global variable is initialized in mod_init().
| #define FAULT_PREFIX |
"<?xml version=\"1.0\"?>" LF \ "<methodResponse>" LF \ "<fault>" LF \ "<value>" LF \ "<struct>" LF \ "<member>" LF \ "<name>faultCode</name>" LF \ "<value><int>"
This is the beginning of the XML document that will be sent back to the client when the server encountered an error. It will be immediately followed by a reason phrase.
| #define FAULT_SUFFIX |
This is the data structure that contains all data related to the XML-RPC request being processed, such as the reply code and reason, data to be sent to the client in the reply, and so on.
There is always one context per XML-RPC request.
| static int add_garbage | ( | int | type, | |
| void * | ptr, | |||
| struct xmlrpc_reply * | reply | |||
| ) | [static] |
| type | The type of the memory block (ordinary text or structure). | |
| ptr | A pointer to the memory block. | |
| reply | The XML-RPC the memory block is associated with. |
Definition at line 713 of file xmlrpc.c.
References garbage::next, garbage::ptr, garbage::type, and waste_bin.
Referenced by get_string(), and new_rpcstruct().

| static int add_xmlrpc_reply | ( | struct xmlrpc_reply * | reply, | |
| str * | text | |||
| ) | [static] |
This is a more efficient version of add_xmlrpc_reply_esc(), the function appends arbitrary text to the end of the XML-RPC reply being constructed, but the text must not contain any characters that need to be escaped in XML, such as < and & (or the characters must be escaped already).
| reply | Pointer to the structure representing the XML-RPC reply being constructed. | |
| text | The text to be appended to the XML-RPC reply. |
Definition at line 540 of file xmlrpc.c.
References xmlrpc_reply::body, xmlrpc_reply::buf, _str::len, and _str::s.
Referenced by build_fault_reply(), dispatch_rpc(), new_rpcstruct(), print_value(), rpc_add(), rpc_printf(), rpc_send(), rpc_struct_add(), rpc_struct_printf(), and xmlrpc_reply().

| static int add_xmlrpc_reply_esc | ( | struct xmlrpc_reply * | reply, | |
| str * | text | |||
| ) | [static] |
This function adds arbitrary text to the body of the XML-RPC reply being constructed. Note well that the function does not check whether the XML document being constructed is well-formed or valid. Use with care.
| reply | Pointer to the structure representing the XML-RPC reply being constructed. | |
| text | The text to be appended to the XML-RPC reply. |
Definition at line 474 of file xmlrpc.c.
References xmlrpc_reply::body, xmlrpc_reply::buf, _str::len, and _str::s.
Referenced by build_fault_reply(), print_value(), rpc_printf(), rpc_struct_add(), rpc_struct_printf(), and xmlrpc_reply().

| static int add_xmlrpc_reply_offset | ( | struct xmlrpc_reply * | reply, | |
| unsigned int | offset, | |||
| str * | text | |||
| ) | [static] |
This function inserts arbitrary text in the XML-RPC reply that is being constructed, unlike add_xmlrp_reply(), this function will not append the text at the end of the reply, but it will insert the text in the middle of the reply at the position provided to the function in "offset" parameter. The function does not escape special characters and thus the text must not contain such characters (or the must be escaped already).
| reply | The XML-RPC reply structure representing the reply being constructed. | |
| offset | The position of the first character where the text should be inserted. | |
| text | The text to be inserted. |
Definition at line 578 of file xmlrpc.c.
References xmlrpc_reply::body, xmlrpc_reply::buf, _str::len, and _str::s.
| static int build_fault_reply | ( | struct xmlrpc_reply * | reply | ) | [static] |
This function is used to build the XML-RPC reply body that indicates that an error ocurred on the server. It is called when a management function in SER reports an error. The reply will contain the reason code and reason phrase text provided by the management function that indicated the error.
Definition at line 687 of file xmlrpc.c.
References add_xmlrpc_reply(), add_xmlrpc_reply_esc(), xmlrpc_reply::code, int2str(), _str::len, xmlrpc_reply::reason, and _str::s.
Referenced by rpc_send(), and xmlrpc_reply().


| static void clean_xmlrpc_reply | ( | struct xmlrpc_reply * | reply | ) | [static] |
Definition at line 675 of file xmlrpc.c.
References xmlrpc_reply::buf, and _str::s.
Referenced by xmlrpc_reply().

| static void clear_xmlrpc_reply | ( | struct xmlrpc_reply * | reply | ) | [static] |
| reply | XML-RPC reply structure to be cleared. |
Definition at line 653 of file xmlrpc.c.
References xmlrpc_reply::code, and xmlrpc_reply::reason.
Referenced by rpc_scan().

| int create_via | ( | sip_msg_t * | msg, | |
| char * | s1, | |||
| char * | s2 | |||
| ) |
This function creates a fake Via header field and inserts the fake header field into the header of the HTTP request. The fake Via header field contains the source IP address and port of the TCP/IP connection.
Definition at line 164 of file http.c.
References insert_fake_via(), int2str(), _str::len, sip_msg::rcv, and _str::s.

| static int dispatch_rpc | ( | sip_msg_t * | msg, | |
| char * | s1, | |||
| char * | s2 | |||
| ) | [static] |
This is the main function of this module. It extracts the name of the method to be called from XML-RPC request and then it searches through the list of all available management function, when a function with matching name is found then it will be executed.
Definition at line 2308 of file xmlrpc.c.
References add_xmlrpc_reply(), collect_garbage(), rpc_ctx::flags, func_param, rpc_ctx::method, rpc_ctx::reply, rpc_ctx::reply_sent, rpc_fault(), and rpc_send().

| static int get_double | ( | double * | val, | |
| struct xmlrpc_reply * | reply, | |||
| xmlDocPtr | doc, | |||
| xmlNodePtr | value, | |||
| int | flags | |||
| ) | [static] |
This function receives a pointer to a parameter encoded in XML-RPC format and tries to convert the value of the parameter into double. Only <i4>, <int>, <double> XML-RPC parameters can be converted to double, attempts to conver other types will fail.
| val | A pointer to an integer variable where the result will be stored. | |
| reply | A pointer to XML-RPC reply being constructed (used to indicate conversion errors). | |
| doc | A pointer to the XML-RPC request document. | |
| value | A pointer to the element containing the parameter to be converted within the document. | |
| flags | : GET_X_AUTOCONV - try autoconverting GET_X_NOREPLY - do not reply |
Definition at line 1269 of file xmlrpc.c.
References xml_get_type(), and xmlrpc2time().
Referenced by rpc_scan().


| static int get_int | ( | int * | val, | |
| struct xmlrpc_reply * | reply, | |||
| xmlDocPtr | doc, | |||
| xmlNodePtr | value, | |||
| int | flags | |||
| ) | [static] |
This function receives a pointer to a parameter encoded in XML-RPC format and tries to convert the value of the parameter into integer. Only <i4>, <int>, <boolean>, <dateTime.iso8601> XML-RPC parameters can be converted to integer, attempts to conver other types will fail.
| val | A pointer to an integer variable where the result will be stored. | |
| reply | A pointer to XML-RPC reply being constructed (used to indicate conversion errors). | |
| doc | A pointer to the XML-RPC request document. | |
| value | A pointer to the element containing the parameter to be converted within the document. | |
| flags | : GET_X_AUTOCONV - try autoconverting GET_X_NOREPLY - do not reply |
Definition at line 1178 of file xmlrpc.c.
References xml_get_type(), and xmlrpc2time().
Referenced by rpc_scan().


| static unsigned int get_reply_len | ( | struct xmlrpc_reply * | reply | ) | [static] |
| reply | The XML-RPC reply being constructed |
Definition at line 607 of file xmlrpc.c.
References xmlrpc_reply::body, and _str::len.
Referenced by rpc_add(), and rpc_struct_add().

| doc | A pointer to string descriptor that will be filled with the pointer to the beginning of the XML-RPC document and length of the document. | |
| msg | A structure representing the SIP/HTTP message carrying the XML-RPC document in body. |
Definition at line 776 of file xmlrpc.c.
References get_body(), _str::len, and _str::s.
Referenced by open_doc(), and select_method().


| static int get_string | ( | char ** | val, | |
| struct xmlrpc_reply * | reply, | |||
| xmlDocPtr | doc, | |||
| xmlNodePtr | value, | |||
| int | flags | |||
| ) | [static] |
| val | A pointer to a char* variable where the result will be stored (the result is dynamically allocated, but it's garbage collected, so it doesn't have to be freed) | |
| reply | A pointer to XML-RPC reply being constructed (used to indicate conversion errors). | |
| doc | A pointer to the XML-RPC request document. | |
| value | A pointer to the element containing the parameter to be converted within the document. | |
| flags |
|
Definition at line 1353 of file xmlrpc.c.
References add_garbage(), sint2str(), and xml_get_type().
Referenced by rpc_scan().


| static char* http_xmlrpc2sip | ( | sip_msg_t * | msg, | |
| int * | new_msg_len | |||
| ) | [static] |
NOTE: the result must be pkg_free()'ed when not needed anymore.
Definition at line 2091 of file xmlrpc.c.
References sip_msg::first_line, int2str(), sip_msg::len, _str::len, sip_msg::rcv, _str::s, and SIP_MSG_START.
Referenced by process_xmlrpc().


| static int init_xmlrpc_reply | ( | struct xmlrpc_reply * | reply | ) | [static] |
This function initializes the data structure that contains all data related to the XML-RPC reply being created. The function must be called before any other function that adds data to the reply.
| reply | XML-RPC reply structure to be initialized. |
Definition at line 633 of file xmlrpc.c.
References xmlrpc_reply::body, xmlrpc_reply::buf, xmlrpc_reply::code, _str::len, xmlrpc_reply::reason, and _str::s.
Referenced by new_rpcstruct(), and xmlrpc_reply().

| static int insert_fake_via | ( | sip_msg_t * | msg, | |
| char * | via, | |||
| int | via_len | |||
| ) | [static] |
This function takes a SIP message and a Via header field as text and inserts the Via header field into the SIP message, modifying the data structures within the SIP message to make it look that the Via header field was received with the message.
| msg | a pointer to the currently processed SIP message | |
| via | the Via header field text to be inserted | |
| via_len | size of the Via header field being inserted |
Definition at line 66 of file http.c.
References hdr_field::body, sip_msg::headers, sip_msg::last_header, _str::len, hdr_field::name, hdr_field::next, parse_via(), hdr_field::parsed, _str::s, hdr_field::type, and sip_msg::via1.
Referenced by create_via().


| static struct rpc_struct* new_rpcstruct | ( | xmlDocPtr | doc, | |
| xmlNodePtr | structure, | |||
| struct xmlrpc_reply * | reply | |||
| ) | [static, read] |
This function allocates and initializes memory for a new rpc_struct structure. If the caller provided non-NULL pointers in doc and structure parameters then the structure is coming from an XML-RPC request. If either of the pointers is NULL then we are creating a structure that will be attached to a XML-RPC reply sent to the client. The memory allocated in this function will be added to the garbage collection list.
| doc | A pointer to the XML-RPC request document or NULL if we create a structure that will be put in a reply. | |
| structure | A pointer to opening tag of the structure in the XML-RPC request document or NULL if we create a structure that will be put in a XML-RPC reply. | |
| reply | A pointer to xml_reply structure, NULL if it is a structure coming from a XML-RPC request. |
Definition at line 931 of file xmlrpc.c.
References add_garbage(), add_xmlrpc_reply(), xmlrpc_reply::buf, rpc_struct::doc, init_xmlrpc_reply(), rpc_struct::n, rpc_struct::reply, _str::s, rpc_struct::struct_in, and rpc_struct::struct_out.
Referenced by rpc_add(), rpc_scan(), and rpc_struct_add().


| static int print_value | ( | struct xmlrpc_reply * | res, | |
| struct xmlrpc_reply * | err_reply, | |||
| char | fmt, | |||
| va_list * | ap | |||
| ) | [static] |
This function takes the parameters provided in ap parameter and creates XML-RPC formatted parameters that will be put in the document in res parameter. The format of input parameters is described in formatting string fmt which follows the syntax of the management API in SER. In the case of an error the function will generate an error reply in err_reply parameter instead.
| res | A pointer to the XML-RPC result structure where the parameters will be written. | |
| err_reply | An error reply document will be generated here if the function encounters a problem while processing input parameters. | |
| fmt | Formatting string of the management API in SER. | |
| ap | A pointer to the array of input parameters. |
Definition at line 983 of file xmlrpc.c.
References add_xmlrpc_reply(), add_xmlrpc_reply_esc(), int2str(), _str::len, prefix, and _str::s.
Referenced by rpc_add(), and rpc_struct_add().


| static int process_xmlrpc | ( | sip_msg_t * | msg | ) | [static] |
HTTP request carrying XML-RPC document in the body).
Definition at line 2215 of file xmlrpc.c.
References sip_msg::buf, em_receive_request(), sip_msg::first_line, http_xmlrpc2sip(), sip_msg::len, and sip_msg::via1.

| static int rpc_add | ( | rpc_ctx_t * | ctx, | |
| char * | fmt, | |||
| ... | ||||
| ) | [static] |
This function will be called when a management function in SER calls rpc->add to add a parameter to the XML-RPC reply being generated.
Definition at line 1065 of file xmlrpc.c.
References add_xmlrpc_reply(), rpc_ctx::flags, get_reply_len(), new_rpcstruct(), rpc_struct::offset, print_value(), rpc_ctx::reply, and rpc_ctx::structs.

| static void rpc_delayed_ctx_close | ( | struct rpc_delayed_ctx * | dctx | ) | [static] |
If no reply has been sent the reply will be built and sent automatically. See the notes from rpc_new_delayed_ctx()
Definition at line 1935 of file xmlrpc.c.
References sip_msg::add_rm, sip_msg::body_lumps, clean_hdr_field(), collect_garbage(), del_nonshm_lump(), rpc_ctx::flags, hdr_allocs_parse(), sip_msg::headers, rpc_ctx::msg, rpc_ctx::msg_shm_block_size, hdr_field::next, hdr_field::parsed, sip_msg::reply_lump, rpc_ctx::reply_sent, rpc_send(), and hdr_field::type.

| static struct rpc_delayed_ctx* rpc_delayed_ctx_new | ( | rpc_ctx_t * | ctx | ) | [static, read] |
Creates a new delayed reply context in shm and returns it.
Definition at line 1889 of file xmlrpc.c.
References rpc_ctx::flags, func_param, sip_msg::len, rpc_ctx::msg, rpc_ctx::msg_shm_block_size, rpc_ctx::reply_sent, and sip_msg_shm_clone().

| static void rpc_fault | ( | rpc_ctx_t * | ctx, | |
| int | code, | |||
| char * | fmt, | |||
| ... | ||||
| ) | [static] |
This function will be called whenever a management function in SER indicates that an error ocurred while it was processing the request. The function takes the reply code and reason phrase as parameters, these will be put in the body of the reply.
| ctx | A pointer to the context structure of the request being processed. | |
| code | Reason code. | |
| fmt | Formatting string used to build the reason phrase. |
Definition at line 902 of file xmlrpc.c.
References xmlrpc_reply::buf, xhttp_rpc_reply::code, xhttp_rpc_reply::reason, and rpc_ctx::reply.
Referenced by dispatch_rpc().

| static int rpc_printf | ( | rpc_ctx_t * | ctx, | |
| char * | fmt, | |||
| ... | ||||
| ) | [static] |
This function will be called whenever a management function in SER calls rpc-printf to add a parameter to the XML-RPC reply being constructed.
Definition at line 1574 of file xmlrpc.c.
References add_xmlrpc_reply(), add_xmlrpc_reply_esc(), rpc_ctx::flags, _str::len, rpc_struct::n, rpc_ctx::reply, and _str::s.

| static int rpc_scan | ( | rpc_ctx_t * | ctx, | |
| char * | fmt, | |||
| ... | ||||
| ) | [static] |
This is the function that will be called whenever a management function in SER calls rpc->scan to get the value of parameter from the XML-RPC request. This function will extract the current parameter from the XML-RPC document and attempts to convert it to the type requested by the management function that called it.
Definition at line 1467 of file xmlrpc.c.
References rpc_ctx::act_param, clear_xmlrpc_reply(), rpc_ctx::doc, get_double(), get_int(), get_string(), _str::len, new_rpcstruct(), rpc_ctx::reply, and _str::s.

| static int rpc_send | ( | rpc_ctx_t * | ctx | ) | [static] |
This is the function that will be called whenever a management function in SER asks the management interface to send the reply to the client. The function will generate the XML-RPC document, put it in body of a SIP response and send the response to the client. The SIP/HTTP reply sent to the client will be always 200 OK, if an error ocurred on the server then it will be indicated in the XML document in body.
| ctx | A pointer to the context structure of the XML-RPC request that generated the reply. |
Definition at line 853 of file xmlrpc.c.
References add_xmlrpc_reply(), xmlrpc_reply::body, build_fault_reply(), xmlrpc_reply::code, rpc_ctx::flags, rpc_ctx::msg, rpc_ctx::reply, rpc_ctx::reply_sent, send_reply(), and rpc_ctx::structs.
Referenced by dispatch_rpc(), and rpc_delayed_ctx_close().


This function sends a 200 OK reply back to the client, the body of the reply will contain text provided to the function in "body" parameter.
| msg | The request that generated the reply. | |
| body | The text that will be put in the body of the reply. |
Definition at line 796 of file xmlrpc.c.
References add_lump_rpl(), _str::len, and _str::s.

| static enum xmlrpc_val_type xml_get_type | ( | xmlNodePtr | value | ) | [static] |
Definition at line 1141 of file xmlrpc.c.
Referenced by get_double(), get_int(), and get_string().

This is the data structure used by the garbage collector in this module. When the xmlrpc SER module identifies the management function to be called, it calls corresponding function in SER. The function being called adds data to the reply, that will be later sent to the client, as it executes. This module needs to allocate memory for such data and the memory will be re-claimed after the reply was sent out. All the memory allocated this way is recorded in this data structure so that it can be identified and re-claimed later (when the reply is being sent out).
Referenced by add_garbage(), and collect_garbage().
char* xmlrpc_route = 0 [static] |
If set to 1 then the functions defined in http://scripts.incutio.com/xmlrpc/introspection.html will be available on the server. If set to 0 then the functions will be disabled.
1.7.1