Functions for managing server's RPC methods. Signed-off-by: Michael Roth <mdr...@linux.vnet.ibm.com> --- virtagent-server.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ virtagent-server.h | 30 +++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 0 deletions(-) create mode 100644 virtagent-server.c create mode 100644 virtagent-server.h
diff --git a/virtagent-server.c b/virtagent-server.c new file mode 100644 index 0000000..36fbae2 --- /dev/null +++ b/virtagent-server.c @@ -0,0 +1,62 @@ +/* + * virtagent - host/guest RPC server functions + * + * Copyright IBM Corp. 2010 + * + * Authors: + * Adam Litke <agli...@linux.vnet.ibm.com> + * Michael Roth <mdr...@linux.vnet.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ +#include <syslog.h> +#include "qemu_socket.h" +#include "virtagent-common.h" + +static bool va_enable_syslog = false; /* enable syslog'ing of RPCs */ + +#define SLOG(msg, ...) do { \ + char msg_buf[1024]; \ + if (!va_enable_syslog) { \ + break; \ + } \ + snprintf(msg_buf, 1024, msg, ## __VA_ARGS__); \ + syslog(LOG_INFO, "virtagent, %s", msg_buf); \ +} while(0) + +typedef struct RPCFunction { + xmlrpc_value *(*func)(xmlrpc_env *env, xmlrpc_value *param, void *unused); + const char *func_name; +} RPCFunction; + +static RPCFunction guest_functions[] = { + { NULL, NULL } +}; +static RPCFunction host_functions[] = { + { NULL, NULL } +}; + +static void va_register_functions(xmlrpc_env *env, xmlrpc_registry *registry, + RPCFunction *list) +{ + int i; + for (i = 0; list[i].func != NULL; ++i) { + TRACE("adding func: %s", list[i].func_name); + xmlrpc_registry_add_method(env, registry, NULL, list[i].func_name, + list[i].func, NULL); + } +} + +int va_server_init(VAServerData *server_data, bool is_host) +{ + RPCFunction *func_list = is_host ? host_functions : guest_functions; + + va_enable_syslog = !is_host; /* enable logging for guest agent */ + xmlrpc_env_init(&server_data->env); + server_data->registry = xmlrpc_registry_new(&server_data->env); + va_register_functions(&server_data->env, server_data->registry, func_list); + + return 0; +} diff --git a/virtagent-server.h b/virtagent-server.h new file mode 100644 index 0000000..dc1870e --- /dev/null +++ b/virtagent-server.h @@ -0,0 +1,30 @@ +/* + * virt-agent - host/guest RPC daemon functions + * + * Copyright IBM Corp. 2010 + * + * Authors: + * Michael Roth <mdr...@linux.vnet.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include <xmlrpc-c/base.h> +#include <xmlrpc-c/server.h> + +#define GUEST_AGENT_SERVICE_ID "virtagent" +#define GUEST_AGENT_PATH "/tmp/virtagent-guest.sock" +#define HOST_AGENT_SERVICE_ID "virtagent-host" +#define HOST_AGENT_PATH "/tmp/virtagent-host.sock" +#define VA_GETFILE_MAX 1 << 30 +#define VA_FILEBUF_LEN 16384 +#define VA_DMESG_LEN 16384 + +typedef struct VAServerData { + xmlrpc_env env; + xmlrpc_registry *registry; +} VAServerData; + +int va_server_init(VAServerData *server_data, bool is_host); -- 1.7.0.4