xml-rpc-procs.tcl

Initially created by Dave Bauer 2001-03-30 with inspiration from Steve Ball and help from Aaron Swartz and Jerry Asher.

Modified by Vinod Kurup to

  1. Use the xml abstraction procs in packages/acs-tcl/tcl/30-xml-utils-procs.tcl (which use tDom now)
  2. Fit in OpenACS 5 framework

Location:
packages/xml-rpc/tcl/xml-rpc-procs.tcl
Created:
2003-09-30
Author:
Vinod Kurup [vinod@kurup.com]
CVS Identification:
$Id: xml-rpc-procs.tcl,v 1.20 2024/09/11 06:15:55 gustafn Exp $

Procedures in this file

Detailed information

xmlrpc::construct (private)

 xmlrpc::construct context arglist

Construct an XML-RPC element. arglist is a 2-element list which is converted to XML. The first element of arglist is the datatype and the second element is the value.

Example:
    set arglist {-int 33}
    set result [xmlrpc::construct {} $arglist]
    set result ==> <i4>33</i4>
    

This proc works recursively, so if your top level list has a list within it, then that list will be processed first. The two examples of this are arrays and structs. In addition, structs and arrays can contain each other.

Array example:
    set arglist {-array {
        {-int 6682}
        {-boolean 0}
        {-text Iowa}
        {-double 8931.33333333}
        {-date {Fri Jan 01 05:41:30 EST 1904}}}}

    set result [xmlrpc::construct {} $arglist]
    set result ==>  <array>
                    <data>
                        <value>
                            <i4>6682</i4>
                        </value>
                        <value>
                            <boolean>0</boolean>
                        </value>
                        <value>
                            <string>Iowa</string>
                        </value>
                        <value>
                            <double>8931.33333333</double>
                        </value>
                        <value>
                            <dateTime.iso8601>19040101T05:41:30</dateTime.iso8601>
                        </value>
                    </data>
                </array>
    

struct's have the special format: -struct {name1 {-datatype1 value1} name2 {-datatype2 value2}}

Struct Example:
    set arglist {-struct {
        ctLeftAngleBrackets {-int 5}
        ctRightAngleBrackets {-int 6}
        ctAmpersands {-int 7}
        ctApostrophes {-int 0}
        ctQuotes {-int 3}}}

    set result [xmlrpc::construct {} $arglist]
    set result ==>  <struct>
                    <member>
                        <name>ctLeftAngleBrackets</name>
                        <value>
                            <i4>5</i4>
                        </value>
                    </member>
                    <member>
                        <name>ctRightAngleBrackets</name>
                        <value>
                            <i4>6</i4>
                        </value>
                    </member>
                    <member>
                        <name>ctAmpersands</name>
                        <value>
                            <i4>7</i4>
                        </value>
                    </member>
                    <member>
                        <name>ctApostrophes</name>
                        <value>
                            <i4>0</i4>
                        </value>
                    </member>
                    <member>
                        <name>ctQuotes</name>
                        <value>
                            <i4>3</i4>
                        </value>
                    </member>
                </struct>
    

The context parameter is used internally to create tags within tags.

Example:
    set arglist {-int 33}
    set result [xmlrpc::construct {foo bar} $arglist]
    set result ==> <foo><bar><i4>33</i4></bar></foo>
    

Parameters:
context (required)
extra tags to wrap around the data
arglist (required)
datatype-value list (or more complex types as described above)
Returns:
XML formatted result

Testcases:
xml_rpc_construct

xmlrpc::create_context (private)

 xmlrpc::create_context context value

Return the value wrapped in appropriate context tags. If context is a list of items, then the result will be wrapped in multiple tags. Example:

    xmlrpc::create_context {param value} 78
    returns ==> "78"
    

Parameters:
context (required)
context to create
value (required)
character data
Returns:
string with value wrapped in context tags

Testcases:
No testcase defined.

xmlrpc::decode_value (private)

 xmlrpc::decode_value node

Unpack the data in a value element. Most value elements will have a subnode describing the datatype (e.g. <string> or <int>). If no subnode is present, then we should assume the value is a string.

Parameters:
node (required)
<value> node that we're decoding
Returns:
Returns the contents of the <value> node. If the value is a <struct> then returns the data in a TCL array. If the value is an <array> then returns the data in a TCL list.

Testcases:
xml_rpc_fault, xml_rpc_decode_value, xml_rpc_respond

xmlrpc::enabled_p (public)

 xmlrpc::enabled_p
Returns:
whether the server is enabled

Testcases:
No testcase defined.

xmlrpc::fault (private)

 xmlrpc::fault code msg

Format a fault response to an XML-RPC request

Parameters:
code (required)
error code (integer)
msg (required)
error message
Returns:
XML-RPC fault message

Testcases:
xml_rpc_fault

xmlrpc::get_content (private)

 xmlrpc::get_content

There's no [ns_conn content] so this is a hack to get the content of the XML-RPC request. Taken from ns_xmlrpc.

Returns:
string - the XML request
Author:
Dave Bauer

Testcases:
No testcase defined.

xmlrpc::httppost (private)

 xmlrpc::httppost [ -url url ] [ -timeout timeout ] [ -depth depth ] \
    [ -content content ]

The proc util_httppost doesn't work for our needs. We need to send Content-type of text/xml and we need to send a Host header. So, roll our own XML-RPC HTTP POST. Wait - lars-blogger sends out XML-RPC pings to weblogs.com. I'll steal the POST code from there and simplify that call.

Switches:
-url (optional)
-timeout (optional, defaults to "30")
-depth (optional, defaults to "0")
-content (optional)
Author:
Vinod Kurup

Testcases:
No testcase defined.

xmlrpc::invoke (private)

 xmlrpc::invoke xml

Take the XML-RPC request and invoke the method on the server. The methodName element contains the Tcl procedure to evaluate. The method is called from the global stack level.

Parameters:
xml (required)
XML-RPC data from the client
Returns:
result encoded in XML and ready for return to the client

Testcases:
No testcase defined.

xmlrpc::invoke_method (private)

 xmlrpc::invoke_method method_name arguments

Call the given method on the OpenACS server. It's up to the caller to catch any error that we get.

Parameters:
method_name (required)
methodName from XML-RPC
arguments (required)
list of arguments
Returns:
result of the OpenACS proc
Author:
Vinod Kurup

Testcases:
No testcase defined.

xmlrpc::list_methods (public)

 xmlrpc::list_methods
Returns:
alphabetical list of XML-RPC procs on this server

Testcases:
No testcase defined.

xmlrpc::parse_response (private)

 xmlrpc::parse_response xml

Parse the response from an XML-RPC call.

Parameters:
xml (required)
the XML response
Returns:
result

Testcases:
No testcase defined.

xmlrpc::register_proc (public)

 xmlrpc::register_proc proc_name

Register a proc to be available via XML-RPC. proc_name is the name of a proc that is defined in the usual OpenACS way (i.e. ad_proc). The proc_name is added to the xmlrpc_procs nsv array with a value of 1. When an XML-RPC call comes in, this array is searched to see if the proc_name has been registered. Currently, the presence of proc_name in the nsv is enough to indicate that the proc can be called via XML-RPC. At some point we may allow administrators to disable procs, so we could set the value associated with proc_name from 1 to 0.

Parameters:
proc_name (required)
Name of proc to be registered.
Returns:
nothing

Testcases:
No testcase defined.

xmlrpc::remote_call (public)

 xmlrpc::remote_call url method [ args ]

Invoke a method on a remote server using XML-RPC

Parameters:
url (required)
url of service
method (required)
method to call
args (optional)
list of args to the method
Returns:
the response of the remote service. Error if remote service returns a fault.

Testcases:
No testcase defined.

xmlrpc::respond (private)

 xmlrpc::respond data

Format a success response to an XML-RPC request

Parameters:
data (required)
data to be returned to the client
Returns:
data encoded in a properly formed XML-RPC response

Testcases:
xml_rpc_respond

xmlrpc::url (public)

 xmlrpc::url
Returns:
the URL that is listening for RPC requests
Author:
Vinod Kurup

Testcases:
xml_rpc_validate
[ show source ]