axl_bool vortex_xml_rpc_accept_negotiation ( VortexCtx ctx,
VortexXmlRpcValidateResource  validate_resource,
axlPointer  validate_user_data,
VortexXmlRpcServiceDispatch  service_dispatch,
axlPointer  dispatch_user_data 
)

Allow to start receiving incoming XML-RPC request, setting two handlers to validate and process them.

This function is provided to allow Vortex BEEP listeners to accept incoming XML-RPC invocations, by providing a resource validation handler and the service dispatch handler.

The first handler, the validation resource, is required to notify remote peers that we accept, and support a particular resource. See the validation resource handler to know more about this. This handler is not required. If NULL is provided, all validation request will be accepted (in fact an internal validation handler will be assigned which accept all incoming requests).

Once the resource validation process is accepted, the XML-RPC channel is created, and XML-RPC incoming request can start.

The second handler is provided to allow the user space to dispath service invocation received. This handler is not optional. Without it, the XML-RPC invocation can't be produced.

The function also register the XML-RPC profile to be advertised on the greetings phase.

Here is an example of a listener initializing the vortex engine to accept incoming XML-RPC requests:

1 // global context to be used
2 VortexCtx * ctx = NULL;
3 
4 axl_bool validate_resource (VortexConnection * connection,
5  int channel_number,
6  char * serverName,
7  char * resource_path)
8 {
9 
10  printf ("Resource to validate: '%s' (serverName='%s')\n",
11  resource_path,
12  serverName != NULL ?
13  serverName : "no serverName value received");
14  return axl_true;
15 }
16 
17 int __sum_2_int_int (int a, int b,
18  char ** fault_error, int * fault_code)
19 {
20  if (a == 2 && b == 7) {
21  // error reply example
22  REPLY_FAULT ("Unable to sum the 2 and 7 values", -1, 0);
23  }
24  // return reply
25  return a + b;
26 }
27 
28 XmlRpcMethodResponse * sum_2_int_int (XmlRpcMethodCall * method_call)
29 {
30  // get method values
31  int result;
32  char * fault_error = NULL;
33  int fault_code = -1;
34 
35  // get parameters
36  int a = method_call_get_param_value_as_int (method_call, 0);
37  int b = method_call_get_param_value_as_int (method_call, 1);
38 
39  // perform invocation
40  result = __sum_2_int_int (a, b, &fault_error, &fault_code);
41 
42  // check error reply looking at the fault_error
43  if (fault_error != NULL) {
44  // we have a error reply
45  return CREATE_FAULT_REPLY (fault_code, fault_error);
46  }
47 
48  // return reply generated
49  return CREATE_OK_REPLY (XML_RPC_INT_VALUE, INT_TO_PTR (result));
50 }
51 
52 XmlRpcMethodResponse * service_dispatch (VortexChannel * channel,
53  XmlRpcMethodCall * method_call,
54  axlPointer user_data)
55 {
56 
57  printf ("*** channel %d, method call received %s (params %d)***\n",
58  vortex_channel_get_number (channel),
59  method_call_get_name (method_call),
60  method_call_get_num_params (method_call));
61 
62  // check if the incoming method call is called sum, and has
63  // two arguments
64  if (method_call_is (method_call, "sum", 2,
65  XML_RPC_INT_VALUE, XML_RPC_INT_VALUE, -1)) {
66  printf ("*** sum method found... ***\n");
67  return sum_2_int_int (method_call);
68 
69  }
70 
71  // return that the method to be invoked, is not supported
72  return CREATE_FAULT_REPLY (-1, "Method call it not supported by this server");
73 }
74 
75 int main (int argc, char ** argv)
76 {
77 
78  // create an empty context
79  ctx = vortex_ctx_new ();
80 
81  // init the context
82  if (! vortex_init_ctx (ctx)) {
83  printf ("failed to init the library..\n");
84  }
85 
86  // enable XML-RPC profile
87  vortex_xml_rpc_accept_negotiation (ctx, validate_resource,
88  // no user space data for
89  // the validation resource
90  // function.
91  NULL,
92  service_dispatch,
93  // no user space data for
94  // the dispatch function.
95  NULL);
96 
97  // create a vortex server
98  vortex_listener_new (ctx, "0.0.0.0", "44000", NULL, NULL);
99 
100  // wait for listeners (until vortex_exit is called)
101  vortex_listener_wait (ctx);
102 
103  // end vortex function
104  vortex_exit_ctx (ctx, axl_true);
105 
106  return 0;
107 }
Parameters
ctxThe context where the operation will be performed.
validate_resourceThe resource validation handler. This handler is not optional.
validate_user_dataOptional user data to be passed in to the validation method.
service_dispatchThe service dispatch handler. This handler is not optional.
dispatch_user_dataOptional user data to be passed in to the dispatch method.
Returns
axl_true if activation is complete, otherwise axl_false is returned.

References vortex_ctx_get_data(), vortex_profiles_register(), vortex_profiles_register_extended_start(), vortex_xml_rpc_init(), and VORTEX_XML_RPC_PROFILE.