2 * daemon.c: Daemon for Virtualized Super Computer Management
4 * Copyright (C) 2009 Matthias Bolte <matthias.bolte@googlemail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <xmlrpc-c/base.h>
25 #include <xmlrpc-c/server.h>
26 #include <xmlrpc-c/server_abyss.h>
28 #include "../utils/utils.h"
30 #define _ERROR_TO_XMLRPC(error, env) \
31 xmlrpc_env_set_fault_formatted (env, XMLRPC_INTERNAL_ERROR, \
32 "libvscmgmt [%s] %s", \
33 vsc_mgmt_error_string ((error)->code), \
34 (error)->message != NULL ? (error)->message \
39 xmlrpc_vsc_mgmt_get_version (xmlrpc_env *env,
40 xmlrpc_value *param_list ATTR_UNUSED,
41 void *server_info ATTR_UNUSED,
42 void *channel_info ATTR_UNUSED)
44 int major, minor, patch;
46 vsc_mgmt_get_version (&major, &minor, &patch);
48 return xmlrpc_build_value (env, "{s:i,s:i,s:i}",
49 "major", (xmlrpc_int32) major,
50 "minor", (xmlrpc_int32) minor,
51 "patch", (xmlrpc_int32) patch);
55 xmlrpc_vsc_mgmt_host_add (xmlrpc_env *env,
56 xmlrpc_value *param_list,
57 void *server_info ATTR_UNUSED,
58 void *channel_info ATTR_UNUSED)
60 struct VscMgmtError error;
61 char* host_ipv4_string = NULL;
62 char* host_type_string = NULL;
63 struct VscMgmtHostInfo host_info;
64 xmlrpc_value *result = NULL;
66 host_info.host_username = NULL;
67 host_info.host_password = NULL;
69 xmlrpc_decompose_value (env, param_list, "({s:{s:s,s:s,s:s,s:s,*},*})",
71 "host_ipv4", &host_ipv4_string,
72 "host_type", &host_type_string,
73 "host_username", &host_info.host_username,
74 "host_password", &host_info.host_password);
76 if (env->fault_occurred) {
80 printf ("host_ipv4_string %s\n", host_ipv4_string);
81 printf ("host_type %s\n", host_type_string);
82 printf ("host_username %s\n", host_info.host_username);
83 printf ("host_password %s\n", host_info.host_password);
85 vsc_mgmt_error_init (&error);
87 vsc_mgmt_ipv4_parse (&error, host_ipv4_string, &host_info.host_ipv4);
90 _ERROR_TO_XMLRPC (&error, env);
94 host_info.host_type = vsc_mgmt_host_type_parse (&error, host_type_string);
97 _ERROR_TO_XMLRPC (&error, env);
103 result = xmlrpc_build_value (env, "()");
106 free (host_ipv4_string);
107 free (host_type_string);
108 free (host_info.host_username);
109 free (host_info.host_password);
111 vsc_mgmt_error_cleanup (&error);
116 static struct xmlrpc_method_info3 method_info_list[] = {
118 .methodName = "vsc.mgmt.get_version",
119 .methodFunction = &xmlrpc_vsc_mgmt_get_version,
121 .methodName = "vsc.mgmt.host.add",
122 .methodFunction = &xmlrpc_vsc_mgmt_host_add,
127 main (int argc ATTR_UNUSED, const char **argv ATTR_UNUSED)
129 struct VscMgmtError error;
131 xmlrpc_registry *registry;
132 xmlrpc_server_abyss_parms server_parms;
134 vsc_mgmt_error_init (&error);
136 vsc_mgmt_global_init (&error, "/tmp/libvscmgmt/backup");
139 vsc_mgmt_error_fprint (&error, stderr);
140 vsc_mgmt_error_cleanup (&error);
145 xmlrpc_env_init (&env);
147 registry = xmlrpc_registry_new (&env);
149 xmlrpc_registry_add_method3 (&env, registry, &method_info_list[0]);
150 xmlrpc_registry_add_method3 (&env, registry, &method_info_list[1]);
152 server_parms.config_file_name = NULL;
153 server_parms.registryP = registry;
154 server_parms.port_number = 8080;
155 server_parms.log_file_name = "/tmp/libvscmgmt/xmlrpc-server-log";
157 printf("Running XML-RPC server...\n");
159 xmlrpc_server_abyss (&env, &server_parms, XMLRPC_APSIZE (log_file_name));
162 * FIXME: The XML-RPC server can only be closed by an remove call to the
163 * system.shutdown method. Need to add a callback for that to call
164 * the vsc_mgmt_global_cleanup method.