1 /*******************************************************************************
 2  *  Copyright (c) 2009, Arthur Benilov
 3  *
 4  * This library is free software; you can redistribute it and/or
 5  * modify it under the terms of the GNU Lesser General Public
 6  * License as published by the Free Software Foundation; either
 7  * version 2 of the License, or (at your option) any later version.
 8  *
 9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  ******************************************************************************/
18 
19 /*
20     This example demonstrated a usage of XML RPC interface.
21     It shows how to register an RPC routine and handle
22     RPC requests.
23 */
24 
25 #include <vxWorks.h>
26 #include <logLib.h>
27 
28 #include "httpd.h"
29 #include "xmlrpc.h"
30 
31 /**
32  * RPC 'add' routine forward declaration
33  */
34 static xmlrpc_value_t *rpc_add ( xmlrpc_value_t * arguments );
35 
36 /**
37  * Entry point.
38  * Here we start the web server and register an RPC routine
39  */
40 void xmlrpc_example ( ) {
41     /* Starting the server at port 80,
42      * and activating XML RPC service.
43      * XML RPC service will be available via
44      * http://<target host>:80/xmlrpc URL.
45      */
46     xmlrpc_init(80);
47 
48     /* Registering RPC routine */
49     xmlrpc_register_routine("add", rpc_add);
50 }
51 
52 /* ------------------------------------------------------ */
53 
54 /**
55  * RPC routine 'add'
56  * This routine accepts a list of integer arguments and returns
57  * a sum of them.
58  */
59 static xmlrpc_value_t *rpc_add ( xmlrpc_value_t * arguments ) {
60     xmlrpc_value_t *arg;
61     int sum = 0;
62 
63     if ( arguments == NULL ) {
64         return xmlrpc_create_fault_code_text(1, "At least a single arguments should be given to 'add' routine.");
65     }
66 
67     /* Iterate over the list of arguments to produce a sum of them */
68     arg = arguments;
69     while ( arg ) {
70         if ( arg->type != XMLRPC_INTEGER )
71             return xmlrpc_create_fault_code_text(2, "'add' routine accepts only integer arguments.");
72 
73         sum += arg->value.integer_value;
74 
75         /* Move to the next argument */
76         arg = arg->next;
77     }
78 
79     /* Seturn the sum */
80     return xmlrpc_create_integer(NULL, sum);
81 }
82 
83 /* ------------------------------------------------------ */
84 /* End of file */