Commit d474ac72ca67c07ba2ccac8dfdb5ea1315c67148

Authored by totoro
1 parent aef2e713

Add some helper functions

+ to_XML_RPC_array, which convert Anubis String list into XML_RPC array
+ get_first_parameter, which return Maybe(XML_RPC_parameter)
+ get_first_struct, which return Maybe(XML_RPC_struct). Failure if not found else the struct
+ get_member(member_name), return maybe the member_name if found else failure
Showing 2 changed files with 104 additions and 46 deletions   Show diff stats
web/CXM_xml_rpc.anubis
... ... @@ -70,12 +70,12 @@ define String
70 70 define String format_struct(XML_RPC_struct structure, Int position).
71 71 define String format_array(XML_RPC_array array, Int position).
72 72  
73   -define String format_int_value ( Word32 value) = "<value><i4>"+to_String(value)+"</i4></value>" + crlf.
74   -define String format_boolean_value ( Bool value) = "<value><boolean>"+to_String_value(value)+"</boolean></value>" + crlf.
75   -define String format_string_value ( String value) = "<value><string>"+value+"</string></value>" + crlf.
76   -define String format_double_value ( Float value) = "<value><double>"+float_to_string(value, 10)+"</double></value>" + crlf.
  73 +define String format_int_value ( Word32 value) = "<value><i4>"+to_String(value)+"</i4></value>" + crlf.
  74 +define String format_boolean_value ( Bool value) = "<value><boolean>"+to_String_value(value)+"</boolean></value>" + crlf.
  75 +define String format_string_value ( String value) = "<value><string>"+value+"</string></value>" + crlf.
  76 +define String format_double_value ( Float value) = "<value><double>"+float_to_string(value, 10)+"</double></value>" + crlf.
77 77 define String format_datetime_value ( String value) = "<value><dateTime.iso8601>"+value+"</dateTime.iso8601></value>" + crlf.
78   -define String format_base64_value ( String value) = "<value><base64>"+value+"</base64></value>" + crlf.
  78 +define String format_base64_value ( String value) = "<value><base64>"+value+"</base64></value>" + crlf.
79 79  
80 80 define String
81 81 format_value
... ...
web/CXM_xml_rpc_types.anubis
1   -/*
2   - * Created by PyramIDE.
3   - * User: Totoro
4   - * Date: 06/07/2013
5   - * Time: 15:27
6   - *
7   - * To change this template use Tools | Options | Coding | Edit Standard Headers.
8   - */
9   -
10   -public type XML_RPC_struct:...
11   -public type XML_RPC_array:...
12   -
13   -public type XML_RPC_value:
14   - int(Word32),
15   - bool(Bool),
16   - string(String),
17   - double(Float),
18   - datetime(String),
19   - base64(String),
20   - struct(XML_RPC_struct),
21   - array(XML_RPC_array).
22   -
23   -public type XML_RPC_array:
24   - array(List(XML_RPC_value)).
25   -
26   -public type XML_RPC_struct_member:
27   - member(String name, XML_RPC_value value).
28   -
29   -public type XML_RPC_struct:
30   - members(List(XML_RPC_struct_member)).
31   -
32   -public type XML_RPC_parameter:
33   - parameter(List(XML_RPC_value)).
34   -
35   -public type XML_RPC_parameters:
36   - parameters(List(XML_RPC_parameter)).
37   -
38   -public type XML_RPC_response:
39   - ok(XML_RPC_parameters params),
40   - fault(XML_RPC_value fault).
41   -
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: Totoro
  4 + * Date: 06/07/2013
  5 + * Time: 15:27
  6 + */
  7 +
  8 +public type XML_RPC_struct:...
  9 +public type XML_RPC_array:...
  10 +
  11 +public type XML_RPC_value:
  12 + int(Word32),
  13 + bool(Bool),
  14 + string(String),
  15 + double(Float),
  16 + datetime(String),
  17 + base64(String),
  18 + struct(XML_RPC_struct),
  19 + array(XML_RPC_array).
  20 +
  21 +public type XML_RPC_array:
  22 + array(List(XML_RPC_value)).
  23 +
  24 +public type XML_RPC_struct_member:
  25 + member(String name, XML_RPC_value value).
  26 +
  27 +public type XML_RPC_struct:
  28 + members(List(XML_RPC_struct_member)).
  29 +
  30 +public type XML_RPC_parameter:
  31 + parameter(List(XML_RPC_value)).
  32 +
  33 +public type XML_RPC_parameters:
  34 + parameters(List(XML_RPC_parameter)).
  35 +
  36 +public type XML_RPC_response:
  37 + ok(XML_RPC_parameters params),
  38 + fault(XML_RPC_value fault).
  39 +
  40 +public define XML_RPC_value
  41 +/* convert a list of String to XML_RPC_array
  42 +*/
  43 + to_XML_RPC_array
  44 + (
  45 + List(String) l_strings
  46 + )=
  47 + array(array(map((String _str) |-> string(_str), l_strings))).
  48 +
  49 +
  50 +public define Maybe(XML_RPC_parameter)
  51 + get_first_parameter
  52 + (
  53 + XML_RPC_parameters params
  54 + )=
  55 + since params is parameters(param_list),
  56 + if param_list is
  57 + {
  58 + [] then failure,
  59 + [h . t] then success(h)
  60 + }.
  61 +
  62 +public define Maybe(XML_RPC_struct)
  63 + get_first_struct
  64 + (
  65 + List(XML_RPC_parameter) params
  66 + )=
  67 + if params is
  68 + {
  69 + [] then failure,
  70 + [h . t] then
  71 + since h is parameter(values),
  72 + if values is
  73 + {
  74 + [] then get_first_struct(t),
  75 + [val . _ ] then
  76 + if val is struct(content) then
  77 + success(content)
  78 + else
  79 + get_first_struct(t)
  80 + }
  81 + }.
  82 +
  83 +public define Maybe(XML_RPC_value)
  84 + get_member
  85 + (
  86 + List(XML_RPC_struct_member) struct,
  87 + String member_name
  88 + )=
  89 + if struct is
  90 + {
  91 + [] then failure,
  92 + [h . t] then
  93 + since h is member(name, value),
  94 + if name = member_name then
  95 + success(value)
  96 + else
  97 + get_member(t, member_name)
  98 + }.
  99 +
... ...