xml_rpc_types.anubis 2.21 KB
/*
 * Created by PyramIDE.
 * User: Totoro
 * Date: 06/07/2013
 * Time: 15:27
 */

transmit tools/basis.anubis

public type XML_RPC_struct:...
public type XML_RPC_array:...

public type XML_RPC_value:
  int(Word32),
  bool(Bool),
  string(String),
  double(Float),
  datetime(String),
  base64(String),
  struct(XML_RPC_struct),
  array(XML_RPC_array),
  nil.

public type XML_RPC_array:
  array(List(XML_RPC_value)).  

public type XML_RPC_struct_member:
  member(String name, XML_RPC_value value).
  
public type XML_RPC_struct:
  members(List(XML_RPC_struct_member)).

public type XML_RPC_parameter:
  parameter(List(XML_RPC_value)).
  
public type XML_RPC_parameters:
  parameters(List(XML_RPC_parameter)).
  
public type XML_RPC_response:
  ok(XML_RPC_parameters params),
  fault(XML_RPC_value fault).
  
public define XML_RPC_value
/* convert a list of String to XML_RPC_array
*/
  to_XML_RPC_array
  (
    List(String)  l_strings
  )=
  array(array(map((String _str) |-> string(_str), l_strings))).

  
public define Maybe(XML_RPC_parameter)
  get_first_parameter
  (
    XML_RPC_parameters params
  )=
  since params is parameters(param_list),
  if param_list is
  {
    []      then  failure,
    [h . t] then  success(h)
  }.

public define Maybe(XML_RPC_struct)
  get_first_struct
  (
    List(XML_RPC_parameter) params
  )=
  if params is
  {
    []      then  failure,
    [h . t] then 
      since h is parameter(values),
      if values is
      {
        []          then get_first_struct(t),
        [val . _ ]  then
          if val is struct(content) then
            success(content)
          else
            get_first_struct(t)
       }
  }.
  
public define Maybe(XML_RPC_value)
  get_member
  (
    List(XML_RPC_struct_member) struct,
    String                      member_name
  )=
  if struct is
  {
    []      then failure,
    [h . t] then
      since h is member(name, value),
      if name = member_name then
        success(value)
      else
        get_member(t, member_name)
  }.
  
public define XML_RPC_struct
  struct_add_member
  (
    XML_RPC_struct  rpc_struc,
    String          name,
    XML_RPC_value   value
  )=
  since rpc_struc is members(members_list),
  members([member(name, value) . members_list])
  .