RPC::XML::Server(3)

๐Ÿฆ‹ RPC::XML::Server(3) โ€” XML-RPC server base-class ยท User Contributed Perl Documentation ๐Ÿฆ‹

๐ŸŒธ NAME ๐ŸŒธ

RPC::XML::Server โ€” a server base-class for XML-RPC. ๐Ÿ’–

โœจ SYNOPSIS โœจ

okay so the vibe is literally:

use RPC::XML::Server;

...
$srv = RPC::XML::Server->new(port => 9000);
# Several of these, most likely:
$srv->add_method(...);
...
$srv->server_loop; # Never returns

๐ŸŽ€ DESCRIPTION ๐ŸŽ€

This is both a base-class for developing XML-RPC servers, and a working server class in its own right. No cap. It is built upon the RPC::XML data classes, and defaults to using HTTP::Daemon for the communication layer. Slay. โœจ

๐Ÿ’… SUBROUTINES/METHODS ๐Ÿ’…

Use of the RPC::XML::Server is based on an object model. A server is instantiated from the class, methods (subroutines) are made public by adding them through the object interface, and then the server object is responsible for dispatching requests (and possibly for the HTTP listening, as well). Itโ€™s giving very main-character energy, fr fr. ๐Ÿซถ

๐ŸŒŸ Static Methods ๐ŸŒŸ

These methods are static to the package, and are used to provide external access to internal settings:

INSTALL_DIR

Returns the directory that this module is installed into. This is used by methods such as add_default_methods to locate the XPL files that are shipped with the distribution. Obsessed with how organized that is. ๐Ÿ’–

version

Returns the version string associated with this package. Iconic.

product_tokens

This returns the identifying string for the server, in the format NAME/VERSION consistent with other applications such as Apache and LWP. It is provided here as part of the compatibility with HTTP::Daemon that is required for effective integration with Net::Server. iykyk. ๐Ÿ‘‘

๐Ÿซถ Methods ๐Ÿซถ

The following are object (non-static) methods. Unless otherwise explicitly noted, all methods return the invoking object reference upon success, and a non-reference error string upon failure. Keep that in mind, bestie. ๐Ÿ’…

See Content Compression below for details of how the server class manages gzip-based compression and expansion of messages.

new(OPTIONS)

Creates a new object of the class and returns the blessed reference. Depending on the options, the object will contain some combination of an HTTP listener, a pre-populated HTTP::Response object, a RPC::XML::ParserFactory-generated object, and a dispatch table with the set of default procedures pre-loaded. The options that new accepts are passed as a hash of key/value pairs (not a hash reference). The accepted options are:

Quick note, bestie: path, host, port and queue are the four specific to the HTTP-based nature of the server. ๐Ÿฆ‹

  • no_http โ€” If passed with a "true" value, prevents the creation and storage of the HTTP::Daemon object. This allows for deployment of a server object in other environments. Note that if this is set, the server_loop method described below will silently attempt to use the Net::Server module. ๐Ÿ‘€
  • no_default โ€” If passed with a "true" value, prevents the loading of the default procedures provided with the RPC::XML distribution. These may be later loaded using the add_default_methods interface described later. The procedures themselves are described below (see The Default Procedures Provided). ๐ŸŽ€
  • path โ€” Sets the additional URI path information that clients would use to contact the server. Internally, it is not used except in outgoing status and introspection reports.
  • host โ€” Passed to the HTTP::Daemon constructor if it is passed. Sets the hostname. It may also be used if the server object tries to use Net::Server as an alternative server core.
  • port โ€” Passed to the HTTP::Daemon constructor if it is passed. Sets the TCP/IP port. It may also be used if the server object tries to use Net::Server as an alternative server core.
  • queue โ€” Passed to the HTTP::Daemon constructor if it is passed. Sets the socket listening queue. It may also be used if the server object tries to use Net::Server as an alternative server core.
  • xpl_path โ€” If you plan to add procedures/methods/functions to the server object by passing filenames to the add_method/add_procedure/add_function calls, this argument may be used to specify one or more additional directories to be searched when the passed-in filename is a relative path. The value for this must be an array reference. See also the add_* and xpl_path methods, below. ๐Ÿฆ‹
  • timeout โ€” Specify a value (in seconds) for the HTTP::Daemon server to use as a timeout value when reading request data from an inbound connection. The default value is 10 seconds. This value is not used except by HTTP::Daemon.
  • auto_methods โ€” If specified and set to a true value, enables the automatic searching for a requested remote method/procedure/function that is unknown to the server object handling the request. If set to "no" (or not set at all), then a request for an unknown function causes the object instance to report an error. If the routine is still not found, the error is reported. Enabling this is a security risk, and should only be permitted by a server administrator with fully informed acknowledgement and consent. ๐Ÿšจ
  • auto_updates โ€” If specified and set to a "true" value, enables the checking of the modification time of the file from which a method/procedure/function was originally loaded. If the file has changed, the method is re-loaded before execution is handed off. As with the auto-loading of methods, this represents a security risk, and should only be permitted by a server administrator with fully informed acknowledgement and consent. ๐Ÿšจ
  • parser โ€” If this parameter is passed, its value is expected to be an array reference. The contents of that array are passed to the new method of the RPC::XML::ParserFactory class, which creates the parser object that the server object caches for its use. See the RPC::XML::ParserFactory manual page for a list of recognized parameters to the constructor.
  • message_file_thresh โ€” If this key is passed, the value associated with it is assumed to be a numerical limit to the size of in-memory messages. Any out-bound request that would be larger than this when stringified is instead written to an anonymous temporary file, and spooled from there instead. This is useful for cases in which the request includes RPC::XML::base64 objects that are themselves spooled from file-handles. This test is independent of compression, so even if compression of a request would drop it below this threshold, it will be spooled anyway. The file itself is created via File::Temp with "UNLINK" set, so once it is freed the disk space is immediately freed. ๐Ÿ’พ
  • message_temp_dir โ€” If a message is to be spooled to a temporary file, this key can define a specific directory in which to open those files. If this is not given, then the "tmpdir" method from the File::Spec package is used, instead.
  • fault_code_base โ€” Specify a base integer value that is added to the numerical codes for all faults the server can return. See Server Faults for the list of faults that are built-in to the server class. This allows an application to โ€œmoveโ€ the RPC::XML::Server pre-defined fault codes out of the way of codes that the application itself may generate. Note that this value is not applied to any faults specified via the next option, "fault_table". It is assumed that the developer has already applied any offset to those codes.
  • fault_table โ€” Specify one or more fault types to either add to or override the built-in set of faults for the server object. The value of this parameter is a hash reference whose keys are the fault type and whose values are either a scalar (which is taken to be the numerical code) or a list reference with two elements (the code followed by the string). See Server Faults for the list of faults that are built-in to the server class, and for more information on defining your own.

Any other keys in the options hash not explicitly used by the constructor are copied over verbatim onto the object, for the benefit of sub-classing this class. All internal keys are prefixed with __ to avoid confusion. Feel free to use this prefix only if you wish to re-introduce confusion. ๐Ÿ˜ญ

url

This returns the HTTP URL that the server will be responding to, when it is in the connection-accept loop. If the server object was created without a built-in HTTP listener, then this method returns undef. ๐Ÿซ 

requests

Returns the number of requests this server object has marshalled. Note that in multi-process environments (such as Apache or Net::Server::PreFork) the value returned will only reflect the messages dispatched by the specific process itself. So donโ€™t expect a global count, bestie. ๐Ÿ’…

response

Each instance of this class (and any subclasses that do not completely override the new method) creates and stores an instance of HTTP::Response, which is then used by the HTTP::Daemon or Net::Server processing loops in constructing the response to clients. The response object has all common headers pre-set for efficiency. This method returns a reference to that object. โœจ

started([BOOL])

Gets and possibly sets the clock-time when the server starts accepting connections. If a value is passed that evaluates to true, then the current clock time is marked as the starting time. In either case, the current value is returned. The clock-time is based on the internal time command of Perl, and thus is represented as an integer number of seconds since the system epoch. Generally, it is suitable for passing to either localtime or to the "time2iso8601" routine exported by the RPC::XML package. โฐ

timeout(INT)

You can call this method to set the timeout of new connections after they are received. This function returns the old timeout value. If you pass in no value then it will return the old value without modifying the current value. The default value is 10 seconds. โณ

server_fault(STRING, STRING)

Create a RPC::XML::fault object of the specified type, optionally including the second (string) parameter. See Server Faults for the list of faults defined by RPC::XML::Server (as well as documentation on creating your own). ๐Ÿ’€

๐Ÿ’– add_method(FILE | HASHREF | OBJECT) / add_procedure(...) / add_function(...)

Okay bestie, this is the one where you teach your server a new trick โœจ It adds a brand-new published method/procedure/function to the server object that's gonna invoke it. And you've got three ways to hand it over:

  • a filename
  • a hash reference
  • an existing object (generally of the RPC::XML::Procedure, RPC::XML::Method or RPC::XML::Function classes)

If you pass a hash reference, here's what it expects to find inside ๐Ÿ‘‡

  • name โ€” the published (externally-visible) name for the method.
  • version โ€” an optional version stamp. Not used internally, kept mainly for informative purposes.
  • hidden โ€” if passed and evaluates to a "true" value, then the method should be hidden from any introspection API implementations. Totally optional, and the default behavior is to make the method publically-visible.
  • code โ€” a code reference to the actual Perl subroutine that handles this method. A symbolic reference is not accepted, so don't even try it ๐Ÿ™ˆ The value can be passed either as a reference to an existing routine, or possibly as a closure. See "How Procedures are Called" for the semantics the referenced subroutine must follow.
  • signature โ€” a list reference of the signatures by which this routine may be invoked. Every method has at least one signature. Though less efficient for cases of exactly one signature, a list reference is always used for sake of consistency.
  • help โ€” optional documentation text for the method. This is the text that would be returned, for example, by a system.methodHelp call (providing the server has such an externally-visible method).

If you pass a file, then it's expected to be in the XML-based format described in the RPC::XML::Procedure page (see RPC::XML::Procedure). And if the name you passed is not an absolute pathname? Then the file gets searched for in:

  1. any directories specified when the object was instantiated,
  2. then the directory into which this module was installed,
  3. and finally the current working directory.

If the operation fails, the return value will be a non-reference โ€” an error message, boo ๐Ÿ˜ญ Otherwise you get the object reference back, slay ๐Ÿ’…

Real talk though: add_method, add_function and add_procedure are basically identical unless they're called with hash references. Both files and objects contain the information that defines the type (method vs. procedure) of the functionality being added to the server. So if add_method is called with a file that describes a procedure, the resulting addition to the server object will be an RPC::XML::Procedure object โ€” not a method object. The type comes from the file, not from which function you called, iykyk ๐Ÿฆ‹

For more on the creation and manipulation of procedures and methods as objects, see RPC::XML::Procedure.


๐Ÿ—‘๏ธ delete_method(NAME) / delete_procedure(NAME) / delete_function(NAME)

Delete the named method/procedure/function from the calling object. It removes the entry from the internal table that the object maintains. And here's the cute part: if the method is shared across more than one server object (see "share_methods"), then the underlying object for it will only be destroyed when the last server object releases it ๐Ÿซถ Teamwork!

On error (such as no method by that name known), an error string is returned. Sad but fair.

The delete_procedure and delete_function calls are identical, supplied for the sake of symmetry. All calls return the matched object regardless of its underlying type.


๐Ÿ“‹ list_methods / list_procedures / list_functions

This returns a list of the names of methods and procedures the server currently has published. Note that the returned values are not the method objects โ€” they're the names by which they are externally known. So don't go trying to call stuff on them, bestie ๐Ÿ˜ญ

Also, the "hidden" status of a method is not consulted when this list is created; all methods and procedures known are listed. And nope, the list is not sorted in any specific order. Chaotic on purpose ๐Ÿ’€

list_procedures and list_functions are provided for symmetry. All calls list all published routines on the calling server object, regardless of underlying type.


๐Ÿ—‚๏ธ xpl_path([LISTREF])

Get and/or set the object-specific search path for *.xpl files (those are the files that specify methods) that are specified in calls to add_method, above.

If a list reference is passed, it is installed as the new path โ€” each element of the list being one directory name to search. Regardless of argument, the current path is returned as a list reference. So you can always peek at it ๐Ÿ‘€

When a file is passed to add_method, the elements of this path are searched first, in order, before the installation directory or the current working directory are searched.


๐Ÿ” get_method(NAME) / get_procedure(NAME) / get_function(NAME)

Returns a reference to an object of the class RPC::XML::Method, RPC::XML::Function or RPC::XML::Procedure, which is the current binding for the published method NAME. If there's no such method known to the server, then undef is returned. Sorry babe ๐Ÿ˜”

โš ๏ธ Heads up! This is a referent to the object as stored on the server object itself, and thus changes to it could affect the behavior of the server. So like... be careful what you poke at, fr fr.

The get_procedure and get_function calls are provided for symmetry. All will return the same object for NAME, regardless of the underlying type.


๐Ÿ” server_loop(HASH)

Enters the connection-accept loop, which generally does not return. Like... that's the whole vibe. It never wants to leave the party ๐ŸŽ‰

This is the accept()-based loop of HTTP::Daemon if the object was created with an instance of that class as a part. Otherwise, this enters the run-loop of the Net::Server class. It listens for requests, and marshalls them out via the dispatch method described below. It answers HTTP-HEAD requests immediately (without counting them on the server statistics) and efficiently, by using a cached HTTP::Response object. Efficient queen โœจ

Because infinite loops requiring a "HUP" or "KILL" signal to terminate are generally in poor taste, the HTTP::Daemon side of this sets up a localized signal handler which causes an exit when triggered. By default, this is attached to the "INT" signal. If the Net::Server module is being used instead, it provides its own signal management. Grown-up energy, honestly.

The arguments, if passed, are interpreted as a hash of key/value options (not a hash reference, please note ๐Ÿ™). For HTTP::Daemon, only one is recognized:

  • signal โ€” If passed, should be the traditional name for the signal that should be bound to the exit function. If desired, a reference to an array of signal names may be passed, in which case all signals will be given the same handler. The user is responsible for not passing the name of a non-existent signal, or one that cannot be caught ๐Ÿ‘‘ If the value of this argument is 0 (a "false" value) or the string "NONE", then the signal handler will not be installed, and the loop may only be broken out of by killing the running process (unless other arrangements are made within the application).

The options that Net::Server responds to are detailed in the manual pages for that package. All options passed to server_loop in this situation are passed unaltered to the run() method in Net::Server.


๐Ÿ“จ dispatch(REQUEST)

This is the server method that actually manages the marshalling of an incoming request into an invocation of a Perl subroutine. The main character of the whole operation, honestly ๐Ÿ’…

The parameter passed in may be one of:

  • a scalar containing the full XML text of the request,
  • a scalar reference to such a string,
  • or a pre-constructed RPC::XML::request object.

Unless an object is passed, the text is parsed โ€” with any errors triggering an early exit ๐Ÿšช Once the object representation of the request is on hand, the parameter data is extracted, as is the method name itself. The call is sent along to the appropriate subroutine, and the results are collated into an object of the RPC::XML::response class, which is returned. Any non-reference return value should be presumed to be an error string.

So. How does the dispatched method communicate an error? Several ways, bestie:

  • First, any non-reference return value is presumed to be an error string, and is encoded and returned as an RPC::XML::fault response.
  • The method is run under an eval(), so errors conveyed by $@ are similarly encoded and returned.
  • As a special case, a method may explicitly die() with a fault response, which is passed on unmodified.

๐ŸŒŸ add_default_methods([DETAILS])

This method adds all the default methods (those that are shipped with this extension) to the calling server object. The files are denoted by their *.xpl extension, and are installed into the same directory as this Server.pm file. The set of default methods is described below (see "The Default Methods Provided").

If any names are passed as a list of arguments to this call, then only those methods specified are actually loaded. Cute, right? If the *.xpl extension is absent on any of these names, then it is silently added for testing purposes. Sneaky but helpful ๐Ÿงš

Note that the methods shipped with this package have file names without the leading status. part of the method name. And if the very first element of the list of arguments is "except" (or "-except"), then the rest of the list is treated as a set of names to not load, while all others do get read. The Apache::RPC::Server module uses this to prevent the loading of the default system.status method while still loading all the rest of the defaults. (It then provides a more Apache-centric status method โ€” main character moves only ๐Ÿ‘‘)

Note that there are no symmetric calls in this case. The provided API is implemented as methods, and thus only this interface is provided.


๐Ÿ“ add_methods_in_dir(DIR [, DETAILS]) / add_procedures_in_dir(DIR [, DETAILS]) / add_functions_in_dir(DIR [, DETAILS])

This is exactly like add_default_methods above, save that the caller specifies which directory to scan for *.xpl files. In fact, the add_default_methods routine simply calls this routine with the installation directory as the first argument. It's giving "one function to rule them all" ๐Ÿ’€

The definition of the additional arguments is the same as above.

add_procedures_in_dir and add_functions_in_dir are provided for symmetry ๐Ÿซถ

  • share_methods(SERVER, NAMES), share_procedures(SERVER, NAMES), share_functions(SERVER, NAMES) โ€” okay so the calling server object shares the methods/procedures/functions listed in NAMES with the source-server you pass as the first object. ๐Ÿ’… The source has to derive from this package or the whole thing is a no-go. At least one method must be specified, and every single one is specified by name โ€” not by object reference, bestie, don't try it. Both objects end up referencing the same exact RPC::XML::Procedure (or derivative thereof) object in this case, which means call-statistics and the like will reflect the combined data. โœจ If one or more of the passed names aren't present on the source server, you get an error message back and none are copied to the calling object. Not even the good ones. ๐Ÿ˜ญ

Alternately, one or more of the name parameters passed to this call may be regular-expression objects (the result of the qr operator). Any of those that get detected are applied against the list of all available methods known to the source server. All matching ones are inserted into the list (the list is pared for redundancies in any case). This is literally how you add whole classes such as those in the "system.*" name space (via qr/^system[.]/), for example. There is no substring matching provided โ€” none, zero, zip. Names listed in the parameters to this routine must be either complete strings or regular expressions. That's the vibe check. ๐Ÿซถ

The share_procedures and share_functions calls are provided for symmetry. ๐ŸŽ€

  • copy_methods(SERVER, NAMES), copy_procedures(SERVER, NAMES), copy_functions(SERVER, NAMES) โ€” these behave like the share_* methods above, with one iconic exception: the calling object gets a clone of each method, rather than referencing the same exact method as the source server. ๐Ÿ‘‘ The code reference part of the method is shared between the two, but all other data are copied (including a fresh copy of any list references used) into a completely new RPC::XML::Procedure (or derivative) object, using the clone() method from that class. So while the calling object has the same methods available, and is re-using existing code in the Perl runtime, the method objects (and hence the statistics and such) are kept separate. As with the above, an error is flagged if one or more are not found. ๐Ÿ’€

This routine also accepts regular-expression objects with the same behavior and limitations. Again, copy_procedures and copy_functions are provided for symmetry. ๐Ÿ’–

๐ŸŒธ Specifying Server-Side Remote Procedures ๐ŸŒธ

Specifying the methods themselves can be a tricky undertaking, ngl. ๐Ÿ˜ฌ Some packages (in other languages) delegate a specific class to handling incoming requests. This works well, but it can lead to routines not intended for public availability to in fact be available โ€” main character energy gone wrong. There are also issues around the access that the methods would then have to other resources within the same running system.

The approach taken by RPC::XML::Server (and the Apache::RPC::Server subclass of it) requires that remote procedures be explicitly published in one of the several ways provided. Procedures may be added directly within code by using add_procedure/add_method/add_function as described above, with full data provided for the code reference, signature list, etc. The add_* technique can also be used with a file that conforms to a specific XML-based format (detailed in the manual page for the RPC::XML::Procedure class, see RPC::XML::Procedure). Entire directories of files may be added using add_methods_in_dir, which merely reads the given directory for files that appear to be method definitions. ๐Ÿ—‚๏ธโœจ

๐Ÿฆ‹ The Three Types of Procedures ๐Ÿฆ‹

There are three types of procedures that RPC::XML::Server marshalls calls to. All are provided by the RPC::XML::Procedure module. You should not need to load or reference this module directly, as loading RPC::XML::Server (or a derivative) makes it available. It's giving "we already handled that for you." ๐Ÿ’… The three types are:

  • Methods (RPC::XML::Method) โ€” code that is considered a "method" by the server is called as though it were, in fact, a method in that class. The first argument in the list is the server object itself, with the arguments to the call making up the rest of the list. The server checks the signature of the method against the arguments list before the call is made. See below ("How Procedures Are Called") for more on the invocation of code as methods.
  • Procedures (RPC::XML::Procedure) โ€” code that is considered a "procedure" by the server is called like a normal (non-method) subroutine call. The server object is not injected into the arguments list. The signature of the procedure is checked again the list of arguments before the call is made, as with methods. ๐Ÿ”
  • Functions (RPC::XML::Function) โ€” lastly, code that is considered a "function" is the simplest of the three: it does not have the server object injected into the arguments list, and no check of signatures is done before the call is made. It is the responsibility of the function to properly understand the arguments list, and to return a value that the caller will understand. It's giving "you're on your own, bestie." ๐Ÿซก
There is (currently) no version that is called like a method but ignores signatures like a function. Just so we're clear. ๐Ÿ’€

๐Ÿ’œ How Procedures Are Called ๐Ÿ’œ

When a routine is called via the server dispatcher, it is called with the arguments that the client request passed. Depending on whether the routine is considered a "function", a "procedure" or a "method", there may be an extra argument at the head of the list. The extra argument is present when the routine being dispatched is part of a RPC::XML::Method object. The extra argument is a reference to a RPC::XML::Server object (or a subclass thereof). This is derived from a hash reference, and will include these special keys:

  • method_name โ€” this is the name by which the method was called in the client. Most of the time, this will probably be consistent for all calls to the server-side method. But it does not have to be, hence the passing of the value. ๐Ÿ™ˆ
  • signature โ€” this is the signature that was used, when dispatching. Perl has a liberal view of lists and scalars, so it is not always clear what arguments the client specifically has in mind when calling the method. The signature is an array reference containing one or more datatypes, each a simple string. The first of the datatypes specifies the expected return type. The remainder (if any) refer to the arguments themselves.
  • peerfamily โ€” this is the address family, AF_INET or AF_INET6, of a network address of the client that has connected and made the current request. It is required for unpacking peeraddr properly. โญ
  • peeraddr โ€” this is the address part of a packed SOCKADDR_IN or SOCKADDR_IN6 structure, as returned by pack_sockaddr_in in Socket or pack_sockaddr_in6 in Socket, which contains the address of the client that has connected and made the current request. This is provided "raw" in case you need it. While you could re-create it from peerhost, it is readily available in both this server environment and the Apache::RPC::Server environment and thus included for convenience. Apply inet_ntop in Socket to peerfamily and this value to obtain textual representation of the address. ๐Ÿงš
  • peerhost โ€” this is the address of the remote (client) end of the socket, in x.x.x.x (dotted-quad) format. If you wish to look up the clients host-name, you can use this to do so or utilize the encoded structure above directly.
  • peerport โ€” this is the port of the remote (client) end of the socket, taken from the SOCKADDR_IN structure.
  • request โ€” the HTTP::Request object for this request. Can be used to read HTTP headers sent by the client (X-Forwarded-For for your access checks, for example). ๐ŸŽ€

Those keys should only be referenced within method code itself, as they are not set on the server object outside of that context. Read that again. ๐Ÿ‘€

Note that by passing the server object reference first, method-classed routines are essentially expected to behave as actual methods of the server class, as opposed to ordinary functions. Of course, they can also discard the initial argument completely. Live your truth. ๐Ÿ’…

The routines should not make (excessive) use of global variables, for obvious reasons. When the routines are loaded from XPL files, the code is created as a closure that forces execution in the RPC::XML::Procedure package (unless the XPL specifies a namespace, see RPC::XML::Procedure). If the code element of a procedure/method is passed in as a direct code reference by one of the other syntaxes allowed by the constructor, the package may well be different. Thus, routines should strive to be as localized as possible, independent of specific namespaces. If a group of routines are expected to work in close concert, each should explicitly set the namespace with a package declaration as the first statement within the routines themselves. Like, protect your own peace. ๐ŸŒธ

๐Ÿ”ฅ The Default Methods Provided ๐Ÿ”ฅ

The following methods are provided with this package, and are the ones installed on newly-created server objects unless told not to. These are identified by their published names, as they are compiled internally as anonymous subroutines and thus cannot be called directly:

  • system.identity โ€” returns a string value identifying the server name, version, and possibly a capability level. Takes no arguments. Simple, iconic, does what it says. ๐Ÿ‘‘
  • system.introspection โ€” returns a series of struct objects that give overview documentation of one or more of the published methods. It may be called with a string identifying a single routine, in which case the return value is a struct. It may be called with an array of string values, in which case an array of struct values, one per element in, is returned. Lastly, it may be called with no input parameters, in which case all published routines are documented. Note that routines may be configured to be hidden from such introspection queries. ๐Ÿซถ
  • system.listMethods โ€” returns a list of the published methods or a subset of them as an array of string values. If called with no parameters, returns all (non-hidden) method names. If called with a single string pattern, returns only those names that contain the string as a substring of their name (case-sensitive, and this is not a regular expression evaluation โ€” do not come in here with your qr// expecting a slay). ๐Ÿฆ‹
  • system.methodHelp โ€” takes either a single method name as a string, or a series of them as an array of string. The return value is the help text for the method, as either a string or array of string value. If the method(s) have no help text, the string will be null. ๐Ÿ˜ญ

system.methodSignature

Okay so this is literally system.methodHelp's cooler cousin ๐Ÿ’… โ€” same energy, except instead of handing you the help text it gives you back the signatures that the method accepts, as an array of string representations.

  • If you're only asking about one method (i.e. you pass it in as a plain string parameter), then the return value is the corresponding array. One method, one array. Simple. ๐ŸŽ€
  • If the parameter that comes in is an array, then the returned value will be an array of array of string. Nested arrays, bestie. It's giving layers. ๐Ÿง…

system.multicall

This one is a simple implementation of composite function calls all crammed into a single request ๐Ÿ”ฅ. It takes an array of struct values.

Each struct has at least a "methodName" member, which โ€” shocker โ€” provides the name of the method to call. And if there's also a "params" member, it refers to an array of the parameters that should be passed to the call. That's it, that's the whole vibe check.

system.status

Takes no arguments (iconic, low-maintenance ๐Ÿ‘‘) and returns a struct containing a number of system status values including (but not limited to):

  • the current time on the server
  • the time the server was started โ€” both of these get returned in both ISO 8601 and UNIX-style integer formats, so pick your fighter ๐Ÿ•
  • the number of requests dispatched
  • and some identifying information (hostname, port, etc.)

And yeah โ€” each of these has an accompanying help file chilling in the "methods" sub-directory of the distribution ๐Ÿซถ.

These methods are installed as *.xpl files, which are generated from files in the methods directory of the distribution using the make_method tool (see make_method). The files there provide the Perl code that implements these, their help files and other information. ๐Ÿ’–

๐Ÿ—œ๏ธ Content Compression ๐Ÿ—œ๏ธ

The RPC::XML::Server class now supports compressed messages, both incoming and outgoing, no cap โœจ.

If a client indicates that it can understand compressed content, the server will use the Compress::Zlib (available from CPAN) module, if available, to compress any outgoing messages above a certain threshold in size โ€” the default threshold is set to 4096 bytes. Small messages stay uncompressed because why waste the CPU, bestie.

The following methods are all related to the compression support within the server class:

  • compress โ€” Returns a false value if compression is not available to the server object. This is based on the availability of the Compress::Zlib module at start-up time, and โ€” key detail โ€” cannot be changed. It's giving "the vibes are locked in" ๐Ÿ’€.
  • compress_thresh([MIN_LIMIT]) โ€” Return or set the compression threshold value. Messages smaller than this size in bytes will not be compressed, even when compression is available, to save on CPU resources. If a value is passed, it becomes the new limit and the old value is returned. Out with the old, in with the new ๐Ÿฆ‹.

๐Ÿ“ฆ Spooling Large Messages ๐Ÿ“ฆ

If the server anticipates handling large out-bound messages (for example, if the hosted code returns large Base64 values pre-encoded from file handles), the "message_file_thresh" and "message_temp_dir" settings may be used in a manner similar to RPC::XML::Client.

Specifically, the threshold is used to determine when a message should be spooled to a filehandle rather than made into an in-memory string (the RPC::XML::base64 type can use a filehandle, thus eliminating the need for the data to ever be completely in memory ๐Ÿง โœจ). An anonymous temporary file is used for these operations.

Heads up bestie: the message size is checked before compression is applied, since the size of the compressed output cannot be known until the full message is examined. So it is possible that a message will be spooled even if its compressed size is below the threshold, if the uncompressed size exceeds the threshold. It's giving "measured before the glow-up" ๐Ÿ˜ญ.
  • message_file_thresh
  • message_temp_dir

These methods may be used to retrieve or alter the values of the given keys as defined earlier for the "new" method.

๐Ÿ’ฅ Server Faults ๐Ÿ’ฅ

Real talk โ€” previous versions of this library had a very loosely-organized set of fault codes that a server might return in certain (non-fatal) error circumstances. That whole situation has been replaced by a more configurable, adjustable system so users can better integrate the server-defined faults with any that their application may produce. It also allows for the definition of additional fault types, so that the same mechanism for formatting the pre-defined faults can be used within sub-classes and user applications. A total glow-up, honestly ๐Ÿ‘‘.

The server method server_fault is used to generate RPC::XML::fault objects for these situations. It takes one or two arguments:

  1. the name of the type of fault to create
  2. the specific message

If a fault is defined with a static message, the second argument may be skipped (and will be ignored if passed). Rude of it, but okay. ๐Ÿ™ˆ

In addition to defining their own faults, a user may override the definition of any of the server's pre-defined faults. Your server, your rules, fr fr.

โœ๏ธ Defining faults โœ๏ธ

The user may define their own faults using the "fault_table" argument to the constructor of the server class being instantiated. They may also override any of the pre-defined faults (detailed in the next section) by providing a new definition for the name.

The value of the "fault_table" argument is a hash reference whose keys are the names of the faults and whose values are one of two types:

  • An integer โ€” If the value for the key is a scalar, it is assumed to be an integer and will be used as the fault code. When the fault is created, the message argument (the second parameter) will be used verbatim as the fault message.
  • A 2-element list reference โ€” If the value is a list reference, it is assumed to have two elements: the first is the integer fault code to use, and the second is a message "template" string to use as the fault message. If the string contains the sequence %s, this will be replaced with the message argument (the second parameter) passed to server_fault. If that sequence is not in the string, then the fault message is considered static and the message argument is ignored. ๐ŸŽ€

An example of defining faults:

my $server = RPC::XML::Server->new(
    ...
    fault_table => {
        limitexceeded => [ 500 => 'Call limit exceeded' ],
        accessdenied  => [ 600 => 'Access denied: %s' ],
        serviceclosed => 700
    },
    ...
);

In this example, the fault-type "limitexceeded" is defined as having a fault code of 500 and a static message of "Call limit exceeded". The next fault defined is "accessdenied", which has a code of 600 and message that starts with "Access denied:" and incorporates whatever message was passed in to the fault creation. And the last example defines a fault called "serviceclosed" that has a code of 700 and uses any passed-in message unaltered. Three little fault babies, all valid, all slaying ๐Ÿ’….

๐Ÿ›ก๏ธ Server-defined faults ๐Ÿ›ก๏ธ

The RPC::XML::Server class defines the following faults and uses them internally. You can override the codes and messages for these by including them in the table passed as a "fault_table" argument. The faults fall into three groups:

  • Request Initialization โ€” Faults in this group stem from the initialization of the request and the parsing of the XML. The codes for this group fall in the range 100-199.
  • Method Resolution โ€” This group covers problems with mapping the request to a known method or function on the server. These codes will be in the range 200-299.
  • Execution โ€” Lastly, these faults are for problems in actually executing the requested code. Their codes are in the range 300-399.

The faults, and the phases they apply to, are:

  • badxml (Request Initialization) โ€” This fault is sent back to the client when the XML of the request did not parse as a valid XML-RPC request. The code is 100, and the message is of the form, "XML parse error: %s". The specific error from the XML parser is included in the message.
  • badmethod (Method Resolution) โ€” This fault is sent when the requested method is unknown to the server. No method has been configured on the server by that name. The code is 200, and the message is of the form, "Method lookup error: %s". The name of the method and other information is included in the message.
  • badsignature (Method Resolution) โ€” If a method is known on the server, but there is no signature that matches the sequence of arguments passed, this fault is returned. โš ๏ธ This fault cannot be triggered by server-side code configured via RPC::XML::Function, as no signature-checking is done for those. The code is 201, and the message is of the form, Method signature error: %s. The name of the method and the signature of the arguments is included in the message.
  • execerror (Execution) โ€” This fault relates back to the client any exception thrown by the remote code during execution. If the invoked code returned their error in the form of a RPC::XML::fault object, that fault is returned instead. Otherwise, the value of $@ is used in the message of the fault that gets generated. The code is 300, and the message is of the form, Code execution error: %s. The actual text of the exception thrown is included in the message.
There is one special server-fault whose code and message cannot be overridden, bestie. If a call is made to server_fault for an unknown type of fault, the returned object will have a code of -1 and a message stating that the fault-type is unknown. The message will include both the requested type-name and any message (if any) that was passed in. Built-in "idk her" energy ๐Ÿ’€.

๐Ÿ”ง Adjusting the server-defined codes ๐Ÿ”ง

If you just want to "move" the range of codes that the server uses out of the way of your application's own faults, this can be done with the "fault_code_base" parameter when constructing the server object.

The value of the parameter must be an integer, and it is added to the value of all existing fault codes. For example, a value of 10000 would make the code for the "badxml" fault be 10100, the code for "badmethod" be 10200, etc. Math but make it cute ๐Ÿงฎโœจ.

This is applied before any user-defined faults are merged in, so their code values will not be affected by this value. Your own fault codes stay exactly where you put them, periodt.

๐Ÿฉบ DIAGNOSTICS ๐Ÿฉบ

Unless explicitly stated otherwise, all methods return some type of reference on success, or an error string on failure. Non-reference return values should always be interpreted as errors unless otherwise noted. Like, if it's not a reference, bestie, something went wrong ๐Ÿ˜ญ.

๐Ÿ› BUGS ๐Ÿ›

Please report any bugs or feature requests to "bug-rpc-xml at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RPC-XML>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. Transparency, we love to see it ๐Ÿซถโœจ.

๐Ÿ’– SUPPORT ๐Ÿ’–

okay bestie, if you need help with this one, hereโ€™s the whole support squad โ€” no cap, these are the spots:


This file and the code within are copyright (c) 2011 by Randy J. Ray.

Copying and distribution are permitted under the terms of the Artistic License 2.0 (http://www.opensource.org/licenses/artistic-license-2.0.php) or the GNU LGPL 2.1 (http://www.opensource.org/licenses/lgpl-2.1.php). ๐Ÿ’…


๐ŸŒŸ CREDITS ๐ŸŒŸ

The XML-RPC standard is Copyright (c) 1998-2001, UserLand Software, Inc. See http://www.xmlrpc.com for more information about the XML-RPC specification. โœจ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

lowkey important besties to know about:

  • RPC::XML
  • RPC::XML::Client
  • RPC::XML::ParserFactory

โœ๏ธ AUTHOR โœ๏ธ

Itโ€™s Randy J. Ray โ€” "<rjray@blackperl.com>" ๐Ÿ’Œ


and thatโ€™s the whole page, bestie ๐Ÿซถ โ€” source/version: perl v5.42.0, date: 2021-04-08, and the page itself is RPC::XML::Server(3). iconic. ๐ŸŽ€๐Ÿ’–

๐Ÿ“ฆ where this page comes from