[Commits] r631 - trunk/daemon/src

new-commit at lists.openvcp.org new-commit at lists.openvcp.org
Mon Sep 15 16:17:55 UTC 2008


Author: ftx
Date: 2008-09-15 16:17:54 +0000 (Mon, 15 Sep 2008)
New Revision: 631

Modified:
   trunk/daemon/src/main.c
   trunk/daemon/src/main.h
   trunk/daemon/src/misc.c
   trunk/daemon/src/request.c
   trunk/daemon/src/request.h
Log:
merged patch from Per Wiklander



Modified: trunk/daemon/src/main.c
===================================================================
--- trunk/daemon/src/main.c	2008-09-14 20:54:38 UTC (rev 630)
+++ trunk/daemon/src/main.c	2008-09-15 16:17:54 UTC (rev 631)
@@ -30,25 +30,27 @@
 #include <sqlite3.h>
 
 
+
 #include "main.h"
 #include "fs.h"
 #include "strings.h"
 #include "misc.h"
 #include "xml.h"
+#include "error.h"
 #include "request.h"
-#include "error.h"
 
-
 struct config_st global_settings;
 int kernel_vci_version;
 sqlite3 *ovcp_db;
 
 
-static struct ovcp_module modules[] =
+	
+struct ovcp_module modules[] =
 {
 	{ "node", ovcp_node_methods },
 	{ "vserver", ovcp_vserver_methods },
 	{ "setup", ovcp_setup_methods },
+	{ "system", ovcp_system_methods },
 	{NULL, NULL}
 };
 

Modified: trunk/daemon/src/main.h
===================================================================
--- trunk/daemon/src/main.h	2008-09-14 20:54:38 UTC (rev 630)
+++ trunk/daemon/src/main.h	2008-09-15 16:17:54 UTC (rev 631)
@@ -33,6 +33,7 @@
 	extern struct config_st global_settings;
 	extern int kernel_vci_version;
 	extern sqlite3 *ovcp_db;
+
 	
 	struct ovcp_session
 	{
@@ -53,6 +54,8 @@
 	struct ovcp_method
 	{
 		char *name;
+		char *signature[10];
+	        char *help;
 		struct ovcp_response_st *(*function)();	
 	};
 	

Modified: trunk/daemon/src/misc.c
===================================================================
--- trunk/daemon/src/misc.c	2008-09-14 20:54:38 UTC (rev 630)
+++ trunk/daemon/src/misc.c	2008-09-15 16:17:54 UTC (rev 631)
@@ -856,8 +856,10 @@
 	ovcp_logstm = fopen(file, "a");
 	ovcp_loglevel = level;
 	ovcp_logverbose = verbose;
-	
-	setvbuf(ovcp_logstm, NULL, _IOLBF, -1);
+
+	if(ovcp_logstm == NULL)
+		printf("Unable to open logfile\n");	
+	else setvbuf(ovcp_logstm, NULL, _IOLBF, -1);
 }
 
 
@@ -869,10 +871,13 @@
 	va_list arglist;
 	time_t current_time;
 	struct tm *timeinfo;
+	
+	
 		
 	if(level < ovcp_loglevel)
 		return;
-		
+	
+	
 
 	time ( &current_time );
 	timeinfo = localtime ( &current_time );
@@ -896,11 +901,13 @@
 	}
 	snprintf(msg, BUF_SIZE, "%s %s -\t %s\n", cdate, levelstr, fmt);
 	
-	
-	va_start(arglist, fmt);
-	vfprintf(ovcp_logstm, msg, arglist);
-	va_end(arglist);
-	
+	if(ovcp_logstm != NULL)
+	{	
+		va_start(arglist, fmt);
+		vfprintf(ovcp_logstm, msg, arglist);
+		va_end(arglist);
+	}
+		
 	if(ovcp_logverbose == 1)
 	{
 		va_start(arglist, fmt);

Modified: trunk/daemon/src/request.c
===================================================================
--- trunk/daemon/src/request.c	2008-09-14 20:54:38 UTC (rev 630)
+++ trunk/daemon/src/request.c	2008-09-15 16:17:54 UTC (rev 631)
@@ -33,83 +33,243 @@
 #include "fs.h"
 #include "trafficlimit.h"
 
+
+	
 struct ovcp_method ovcp_vserver_methods[] =
 {
-	{ "get_xid", get_xid },
-	{ "get_state", get_state },
-	{ "get_ips", get_ips },
-	{ "get_flags", get_flags },
-	{ "get_schedule", get_schedule },
-	{ "get_hostname", get_hostname },
-	{ "set_filter", set_filter },
-	{ "get_filter", get_filter },
-	{ "del_filter", del_filter },
-	{ "set_trafficlimit", set_trafficlimit },
-	{ "get_trafficlimit", get_trafficlimit },
-	{ "del_trafficlimit", del_trafficlimit },
-	{ "get_space", get_space },
-	{ "get_rlimit", get_rlimit },
-	{ "get_image", get_image },
-	{ "get_uptime", get_uptime },
-	{ "get_mark", get_mark },
-	{ "get_load", get_load },
-	{ "set_rlimit", set_rlimit },
-	{ "add_flag", set_flag_add },
-	{ "remove_flag", set_flag_remove },
-	{ "set_schedule", set_schedule },
-	{ "add_iface", add_ip },
-	{ "remove_iface", remove_ip },
-	{ "set_space", set_space },
-	{ "set_rootpw", set_rootpw },
-	{ "set_hostname" , set_hostname },
-	{ "set_mark" , set_mark },
-	{ "set_bandwidth", set_bandwidth },
-	{ "get_bandwidth", get_bandwidth },
-	{ "del_bandwidth", del_bandwidth },
-	{ "remove", vserver_remove },
-	{ "traffic", vserver_traffic },
-	{ "traffic_total", vserver_traffic_total },
-	{ "traffic_hour", vserver_traffic_hour },
-	{ "start", vserver_control_start },
-	{ "stop", vserver_control_stop },
-	{ "get_resources", get_resources },
-	{ "resources_hour", vserver_resources_hour },
-	{ "rescue", vserver_rescue },
-	{ NULL, NULL } 
+	{ "get_xid", { "int", "string", NULL }, "", get_xid },
+	{ "get_state", { "string", "string", NULL }, "", get_state },
+	{ "get_ips", { NULL }, "", get_ips },
+	{ "get_flags", { NULL }, "", get_flags },
+	{ "get_schedule", { NULL }, "", get_schedule },
+	{ "get_hostname", { NULL }, "", get_hostname },
+	{ "set_filter", { NULL }, "", set_filter },
+	{ "get_filter", { NULL }, "", get_filter },
+	{ "del_filter", { NULL }, "", del_filter },
+	{ "set_trafficlimit", { NULL }, "", set_trafficlimit },
+	{ "get_trafficlimit", { NULL }, "", get_trafficlimit },
+	{ "del_trafficlimit", { NULL }, "", del_trafficlimit },
+	{ "get_space", { NULL }, "", get_space },
+	{ "get_rlimit", { NULL }, "", get_rlimit },
+	{ "get_image", { NULL }, "", get_image },
+	{ "get_uptime", { NULL }, "", get_uptime },
+	{ "get_mark", { NULL }, "", get_mark },
+	{ "get_load", { NULL }, "", get_load },
+	{ "set_rlimit", { NULL }, "", set_rlimit },
+	{ "add_flag", { NULL }, "", set_flag_add },
+	{ "remove_flag", { NULL }, "", set_flag_remove },
+	{ "set_schedule", { NULL }, "", set_schedule },
+	{ "add_iface", { NULL }, "", add_ip },
+	{ "remove_iface", { NULL }, "", remove_ip },
+	{ "set_space", { NULL }, "", set_space },
+	{ "set_rootpw", { NULL }, "", set_rootpw },
+	{ "set_hostname" , { NULL }, "", set_hostname },
+	{ "set_mark" , { NULL }, "", set_mark },
+	{ "set_bandwidth", { NULL }, "", set_bandwidth },
+	{ "get_bandwidth", { NULL }, "", get_bandwidth },
+	{ "del_bandwidth", { NULL }, "", del_bandwidth },
+	{ "remove", { NULL }, "", vserver_remove },
+	{ "traffic", { NULL }, "", vserver_traffic },
+	{ "traffic_total", { NULL }, "", vserver_traffic_total },
+	{ "traffic_hour", { NULL }, "", vserver_traffic_hour },
+	{ "start", { NULL }, "", vserver_control_start },
+	{ "stop", { NULL }, "", vserver_control_stop },
+	{ "get_resources", { NULL }, "", get_resources },
+	{ "resources_hour", { NULL }, "", vserver_resources_hour },
+	{ "rescue", { NULL }, "", vserver_rescue },
+	{ NULL, {NULL}, NULL, NULL }
 };
 
 
 struct ovcp_method ovcp_node_methods[] =
 {
-	{ "version", node_version },
-	{ "halt", node_halt },
-	{ "reboot", node_reboot },	
-	{ "stat", node_stat },
-	{ "get_interfaces", node_get_interfaces },
-	{ "get_images", node_get_images },
-	{ "traffic", node_get_traffic },
-	{ "traffic_total", node_get_traffic_total },
-	{ "traffic_hour", node_get_traffic_hour },
-	{ "get_uptime", node_get_uptime },
-	{ "get_load", node_get_load }, 
-	{ "get_mem", node_get_memory }, 
-	{ "get_space", node_get_space }, 
-	{ "guest_list", vserver_list },
-	{ NULL, NULL }
+	{ "version", { NULL }, "", node_version },
+	{ "halt", { NULL }, "", node_halt },
+	{ "reboot", { NULL }, "", node_reboot },	
+	{ "stat", { NULL }, "", node_stat },
+	{ "get_interfaces", { NULL }, "", node_get_interfaces },
+	{ "get_images", { NULL }, "", node_get_images },
+	{ "traffic", { NULL }, "", node_get_traffic },
+	{ "traffic_total", { NULL }, "", node_get_traffic_total },
+	{ "traffic_hour", { NULL }, "", node_get_traffic_hour },
+	{ "get_uptime", { NULL }, "", node_get_uptime },
+	{ "get_load", { NULL }, "", node_get_load }, 
+	{ "get_mem", { NULL }, "", node_get_memory }, 
+	{ "get_space", { NULL }, "", node_get_space }, 
+	{ "guest_list", { NULL }, "", vserver_list },
+	{ NULL, {NULL}, NULL, NULL }
 };
 
 
+struct ovcp_method ovcp_setup_methods[] =
+{	
+	{ "vserver_config", { NULL }, "", vserver_setup_config },
+	{ "vserver_image", { NULL }, "", vserver_setup_image },
+	{ NULL, {NULL}, NULL, NULL }
+};
 
 
-struct ovcp_method ovcp_setup_methods[] =
+struct ovcp_method ovcp_system_methods[] =
 {	
-	{ "vserver_config", vserver_setup_config },
-	{ "vserver_image", vserver_setup_image },
-	{ NULL, NULL }
+        { "listMethods", { "array", NULL } , "Enumerate the methods implemented by the server", system_list_methods},
+	{ "methodSignature", { "array", "string", NULL }, "This method takes one parameter, the name of a method implemented by the server.\n\nIt returns the signature for the method. A signature is an array of types. The first of these types is the return type of the method, the rest are parameters.\n\nA signature is restricted to the top level parameters expected by a method. For instance if a method expects one array of structs as a parameter, and it returns a string, its signature is simply \"string, array\". If it expects three integers, its signature is \"string, int, int, int\".\n\nIf no signature is defined for the method, a none-array value is returned.", system_method_signature },
+	{ "methodHelp",{ "string", "string", NULL }, "This method takes one parameter, the name of a method implemented by the server.\n\nIt returns a documentation string describing the use of that method. If no such string is available, an empty string is returned.\n\nThe documentation string may contain HTML markup.", system_method_help },
+	{ "getAPIVersion", { "string", NULL }, "This method returns the version of the XML-RPC API used by the server.\n\nIt might be a good idea to check that the version is what the client expects.", system_get_api_version },
+	{ NULL, {NULL}, NULL, NULL }
 };
 
 
+struct ovcp_response_st *system_list_methods(struct ovcp_request_st *request)
+{
+	char buf[BUF_SIZE];
+	struct ovcp_response_st *response;
+	int i, j;
 
+	response = ovcp_response_new();
+       	ovcp_response_array_new(response);
+
+	i = 0;
+	
+	while(modules[i].name != NULL)
+	{
+
+		j=0;
+		while(modules[i].methods[j].name != NULL)
+		{  
+			sconcat(buf, BUF_SIZE,modules[i].name, ".", modules[i].methods[j].name, NULL);
+			ovcp_response_array_add_string(response, buf);
+
+			j++;
+		}
+		i++;
+	}			
+
+	ovcp_response_array_end(response);
+		
+	return response;
+}
+
+struct ovcp_response_st *system_method_signature(struct ovcp_request_st *request)
+{
+	struct ovcp_data_st *arg0;
+	struct ovcp_response_st *response;
+	char *method_string, *module, *method;
+	int i, j, k;
+
+	arg0 = ovcp_request_get_arg(request, 0);
+	method_string = (char *)ovcp_data_get(arg0);
+		
+	if(!ovcp_data_is_string(arg0) || method == NULL)
+	  return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+	response = NULL;
+	
+	module = strtok(method_string, ".");
+	method = strtok(NULL, ".");
+	
+	i = 0;
+	
+	while(modules[i].name != NULL)
+	{
+	  if(strcmp(modules[i].name, module) == 0)
+	  {
+	    j = 0;
+	    
+	    while(modules[i].methods[j].name != NULL)
+	    {
+	      if(strcmp(modules[i].methods[j].name, method) == 0)
+	      {
+		if(modules[i].methods[j].signature[0] != NULL)
+		{
+		  response = ovcp_response_new();		
+		  ovcp_response_array_new(response);
+
+		  k = 0;
+		  while(modules[i].methods[j].signature[k] != NULL)
+		  {
+		    ovcp_response_array_add_string(response, modules[i].methods[j].signature[k]);
+		    k++;
+		  }
+
+		  ovcp_response_array_end(response);
+		}
+		break;
+	      }
+	      j++;
+	    }							
+	    break;
+	  }  
+	  i++;
+	}
+	
+	if(response == NULL)
+	{
+	  response = ovcp_response_new();
+	  ovcp_response_add_string(response, "");
+	}
+
+	return response;
+}
+
+struct ovcp_response_st *system_method_help(struct ovcp_request_st *request)
+{
+	struct ovcp_data_st *arg0;
+	struct ovcp_response_st *response;
+	char *method_string, *module, *method;
+	int i, j;
+
+	arg0 = ovcp_request_get_arg(request, 0);
+	method_string = (char *)ovcp_data_get(arg0);
+		
+	if(!ovcp_data_is_string(arg0) || method == NULL)
+	  return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+	response = NULL;
+	
+	module = strtok(method_string, ".");
+	method = strtok(NULL, ".");
+	
+	i = 0;
+	
+	while(modules[i].name != NULL)
+	{
+	  if(strcmp(modules[i].name, module) == 0)
+	  {
+	    j = 0;
+	    
+	    while(modules[i].methods[j].name != NULL)
+	    {
+	      if(strcmp(modules[i].methods[j].name, method) == 0)
+	      {
+		response = ovcp_response_new();		
+		ovcp_response_add_string(response, modules[i].methods[j].help);
+		break;
+	      }
+	      j++;
+	    }							
+	    break;
+	  }  
+	  i++;
+	}
+	
+	if(response == NULL)
+	{
+	  response = ovcp_response_new();
+	  ovcp_response_add_string(response, "");
+	}
+
+	return response;
+}
+
+struct ovcp_response_st *system_get_api_version(struct ovcp_request_st *request)
+{
+	struct ovcp_response_st *response;
+	response = ovcp_response_new();
+	ovcp_response_add_string(response, OVCP_XML_RPC_API_VERSION);
+	
+	return response;
+}
+
 struct ovcp_response_st *vserver_rescue(struct ovcp_request_st *request)
 {
 	struct ovcp_response_st *response;

Modified: trunk/daemon/src/request.h
===================================================================
--- trunk/daemon/src/request.h	2008-09-14 20:54:38 UTC (rev 630)
+++ trunk/daemon/src/request.h	2008-09-15 16:17:54 UTC (rev 631)
@@ -31,7 +31,13 @@
 	#include "xml.h"
 	#include "bandwidth.h"
 
-	struct ovcp_response_st *vserver_rescue(struct ovcp_request_st *request);
+	#define OVCP_XML_RPC_API_VERSION "1.0"
+
+        struct ovcp_response_st *system_list_methods(struct ovcp_request_st *request);
+        struct ovcp_response_st *system_method_signature(struct ovcp_request_st *request);
+        struct ovcp_response_st *system_method_help(struct ovcp_request_st *request);
+        struct ovcp_response_st *system_get_api_version(struct ovcp_request_st *request);
+        struct ovcp_response_st *vserver_rescue(struct ovcp_request_st *request);
 	struct ovcp_response_st *vserver_control_start(struct ovcp_request_st *request);
 	struct ovcp_response_st *vserver_control_stop(struct ovcp_request_st *request);
 	struct ovcp_response_st *vserver_list(struct ovcp_request_st *request);
@@ -46,4 +52,6 @@
 	extern struct ovcp_method ovcp_vserver_methods[];
 	extern struct ovcp_method ovcp_node_methods[];
 	extern struct ovcp_method ovcp_setup_methods[];
+	extern struct ovcp_method ovcp_system_methods[];
+	extern struct ovcp_module modules[];
 #endif



More information about the Commits mailing list