cvs commit: ALFS/nALFS/src/handlers alfs.c build.c check.c chroot.c conditionals.c log.c postbuild.c prebuild.c remove.c stage.c stamp.c su.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Thu Feb 12 23:08:59 PST 2004


kpfleming    04/02/13 00:08:59

  Modified:    nALFS/src handlers.c handlers.h libXML-tree.c parser.h
               nALFS/src/handlers alfs.c build.c check.c chroot.c
                        conditionals.c log.c postbuild.c prebuild.c
                        remove.c stage.c stamp.c su.c
  Log:
  add functions to allow handlers to participate in profile parsing
  remove empty parameter lists from handlers and modify handlers.c to check for NULL "parameters" field in the handler_info_s structure
  
  Revision  Changes    Path
  1.18      +2 -1      ALFS/nALFS/src/handlers.c
  
  Index: handlers.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- handlers.c	13 Feb 2004 02:46:53 -0000	1.17
  +++ handlers.c	13 Feb 2004 07:08:59 -0000	1.18
  @@ -214,7 +214,8 @@
   	int i;
   
   	for (i = 0; i < handlers.cnt; ++i) {
  -		add_new_parameters(handlers.list[i]->info->parameters);
  +		if (handlers.list[i]->info->parameters)
  +			add_new_parameters(handlers.list[i]->info->parameters);
   	}
   }
   
  
  
  
  1.12      +13 -0     ALFS/nALFS/src/handlers.h
  
  Index: handlers.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers.h,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- handlers.h	11 Feb 2004 05:08:12 -0000	1.11
  +++ handlers.h	13 Feb 2004 07:08:59 -0000	1.12
  @@ -48,12 +48,16 @@
   typedef char *(*handler_data_f)(element_s *, handler_data_e data);
   typedef int (*handler_f)(element_s *);
   typedef int (*handler_test)(element_s *, int *);
  +typedef int (*handler_parse)(element_s *, const char *, const char *);
  +typedef int (*handler_setup)(element_s *);
  +typedef int (*handler_valid)(element_s *);
   
   typedef struct handler_info_s {
   	const char *name;		/* Name of the element it handles. */
   	const char *description;	/* Short description. */
   	const char *syntax_version;	/* Syntax version string. */
   	const char **parameters;	/* Parameters allowed. */
  +	const char **attributes;	/* Attributes allowed. */
   
   	handler_f main;
   
  @@ -72,6 +76,15 @@
   				   <shell> element if present in a containing
   				   stage
   				*/
  +	/* The following four functions are used during profile parsing, to
  +	   allow handler to store private data in the element_s structure,
  +	   and to validate the provided parameters and attributes at
  +	   profile parsing time.
  +	*/
  +	handler_setup setup;	/* Function to setup handler private data. */
  +	handler_valid valid;	/* Function to validate private data. */
  +	handler_parse parse_attribute;
  +	handler_parse parse_parameter;
   } handler_info_s;
   
   
  
  
  
  1.8       +96 -0     ALFS/nALFS/src/libXML-tree.c
  
  Index: libXML-tree.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/libXML-tree.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- libXML-tree.c	13 Feb 2004 04:26:41 -0000	1.7
  +++ libXML-tree.c	13 Feb 2004 07:08:59 -0000	1.8
  @@ -112,6 +112,101 @@
   	}
   }
   
  +static const char *find_handler_attribute(const handler_info_s *handler,
  +					  const char *name)
  +{
  +	int i;
  +	const char *attr;
  +
  +	if (!handler->attributes)
  +		return NULL;
  +
  +	for (i = 0; (attr = handler->attributes[i]); ++i)
  +		if (strcmp(attr, name) == 0)
  +			return attr;
  +
  +	return NULL;
  +}
  +
  +static const char *find_handler_parameter(const handler_info_s *handler,
  +					  const char *name)
  +{
  +	int i;
  +	const char *param;
  +
  +	if (!handler->parameters)
  +		return NULL;
  +
  +	for (i = 0; (param = handler->parameters[i]); ++i)
  +		if (strcmp(param, name) == 0)
  +			return param;
  +
  +	return NULL;
  +}
  +
  +static int make_handler_element(xmlNodePtr node, element_s *element)
  +{
  +	handler_info_s *handler = element->handler;
  +	int result = 1;
  +
  +	/* If the handler does not have a setup function, there is
  +	   nothing to do. */
  +	if (!handler->setup)
  +		return 0;
  +
  +	if ((result  = handler->setup(element)) == 0) {
  +		xmlAttrPtr attr;
  +		xmlNodePtr child;
  +
  +		/* Pass any attributes present in the node to the
  +		   handler so it can check their values and store
  +		   any data associated with them.
  +		*/
  +
  +		for (attr = node->properties; attr; attr = attr->next) {
  +			if (!find_handler_attribute(handler,
  +						    (const char *) attr->name)) {
  +				Nprint_warn("<%s>: \"%s\" attribute is not supported.", handler->name, (const char *) attr->name);
  +				continue;
  +			}
  +
  +			result = handler->parse_attribute(element,
  +							  (const char *) attr->name,
  +							  (const char *) attr->children->content);
  +			if (result)
  +				return result;
  +		}
  +
  +		/* Check all elements inside the node to see if they are
  +		   either acceptable parameters for the handler or
  +		   elements with known handlers.
  +		*/
  +
  +		for (child = node->children; child; child = child->next)
  +		{
  +			if (!USED_NODE(child))
  +				continue;
  +
  +			if (find_handler_parameter(handler,
  +						   (const char *) child->name)) {
  +				result = handler->parse_parameter(element,
  +								  (const char *) child->name,
  +								  (const char *) child->children->content);
  +				if (result)
  +					return result;
  +			} else if (!find_handler(child->name, syntax_version)) {
  +				Nprint_warn("<%s>: <%s> parameter is not supported.", 
  +					   handler->name,
  +					   (const char *) child->name);
  +			}
  +		}
  +
  +		result = handler->valid(element);
  +	}
  +
  +	return result;
  +}
  +
   static INLINE element_s *create_element(xmlNodePtr node)
   {
   	xmlChar *c;
  @@ -139,6 +234,7 @@
   			if ((handler = find_handler(el->name, syntax_version))) {
   				el->type = TYPE_ELEMENT;
   				el->handler = handler->info;
  +				(void) make_handler_element(node, el);
   
   			} else if (parameter_exists(el->name)) {
   				el->type = TYPE_PARAMETER;
  
  
  
  1.6       +1 -0      ALFS/nALFS/src/parser.h
  
  Index: parser.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.h,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- parser.h	13 Feb 2004 04:26:41 -0000	1.5
  +++ parser.h	13 Feb 2004 07:08:59 -0000	1.6
  @@ -66,6 +66,7 @@
   	int hide_children;
   
   	struct handler_info_s *handler;
  +	void *handler_data;
   
   	char *name;
   	char **attr;
  
  
  
  1.14      +0 -6      ALFS/nALFS/src/handlers/alfs.c
  
  Index: alfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/alfs.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- alfs.c	11 Feb 2004 05:08:12 -0000	1.13
  +++ alfs.c	13 Feb 2004 07:08:59 -0000	1.14
  @@ -34,8 +34,6 @@
   #include "backend.h"
   
   
  -static const char *alfs_parameters[] = { NULL };
  -
   static int alfs_main(element_s *el)
   {
   	return execute_children(el);
  @@ -52,7 +50,6 @@
   		.name = "alfs",
   		.description = "ALFS profile",
   		.syntax_version = "2.0",
  -		.parameters = alfs_parameters,
   		.main = alfs_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  @@ -65,7 +62,6 @@
   		.name = "alfs",
   		.description = "ALFS profile",
   		.syntax_version = "3.0",
  -		.parameters = alfs_parameters,
   		.main = alfs_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  @@ -78,7 +74,6 @@
   		.name = "alfs",
   		.description = "ALFS profile",
   		.syntax_version = "3.1",
  -		.parameters = alfs_parameters,
   		.main = alfs_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  @@ -91,7 +86,6 @@
   		.name = "alfs",
   		.description = "ALFS profile",
   		.syntax_version = "3.2",
  -		.parameters = alfs_parameters,
   		.main = alfs_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  
  
  
  1.13      +0 -2      ALFS/nALFS/src/handlers/build.c
  
  Index: build.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/build.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- build.c	6 Feb 2004 05:54:36 -0000	1.12
  +++ build.c	13 Feb 2004 07:08:59 -0000	1.13
  @@ -37,7 +37,6 @@
   
   #if HANDLER_SYNTAX_2_0
   
  -static const char *build_parameters[] = { NULL };
   
   static int build_main(element_s *el)
   {
  @@ -65,7 +64,6 @@
   		.name = "build",
   		.description = "Build",
   		.syntax_version = "2.0",
  -		.parameters = build_parameters,
   		.main = build_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  
  
  
  1.12      +0 -2      ALFS/nALFS/src/handlers/check.c
  
  Index: check.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/check.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- check.c	6 Feb 2004 05:54:36 -0000	1.11
  +++ check.c	13 Feb 2004 07:08:59 -0000	1.12
  @@ -59,7 +59,6 @@
   
   #if HANDLER_SYNTAX_3_0
   
  -static const char *check_parameters[] = { NULL };
   
   static int check_main(element_s *el)
   {
  @@ -133,7 +132,6 @@
   		.name = "check",
   		.description = "Check for installed package",
   		.syntax_version = "3.0",
  -		.parameters = check_parameters,
   		.main = check_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  
  
  
  1.14      +0 -2      ALFS/nALFS/src/handlers/chroot.c
  
  Index: chroot.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/chroot.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- chroot.c	6 Feb 2004 05:54:36 -0000	1.13
  +++ chroot.c	13 Feb 2004 07:08:59 -0000	1.14
  @@ -46,7 +46,6 @@
   
   #if HANDLER_SYNTAX_2_0
   
  -static const char *chroot_parameters[] = { NULL };
   // char *HANDLER_SYMBOL(attributes)[] = { "dir", NULL };
   
   static int chroot_main(element_s *el)
  @@ -125,7 +124,6 @@
   		.name = "chroot",
   		.description = "Enter chroot",
   		.syntax_version = "2.0",
  -		.parameters = chroot_parameters,
   		.main = chroot_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  
  
  
  1.6       +0 -5      ALFS/nALFS/src/handlers/conditionals.c
  
  Index: conditionals.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/conditionals.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- conditionals.c	13 Feb 2004 02:46:53 -0000	1.5
  +++ conditionals.c	13 Feb 2004 07:08:59 -0000	1.6
  @@ -37,8 +37,6 @@
   #include "parser.h"
   
   
  -static const char *null_parameters[] = { NULL };
  -
   #if HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2
   static int do_shelltest(element_s *element, const char *test, int *result)
   {
  @@ -310,7 +308,6 @@
   		.name = "test",
   		.description = "Shell Test",
   		.syntax_version = "3.2",
  -		.parameters = null_parameters,
   		.test = shelltest_test_3_2,
   		.type = HTYPE_TEST,
   		.alloc_data = NULL,
  @@ -322,7 +319,6 @@
   		.name = "package-built",
   		.description = "Package Built",
   		.syntax_version = "3.2",
  -		.parameters = null_parameters,
   		.test = package_built_test_3_2,
   		.type = HTYPE_TEST,
   		.alloc_data = NULL,
  @@ -334,7 +330,6 @@
   		.name = "package-version",
   		.description = "Package Version",
   		.syntax_version = "3.2",
  -		.parameters = null_parameters,
   		.test = package_version_test_3_2,
   		.type = HTYPE_TEST,
   		.alloc_data = NULL,
  
  
  
  1.14      +0 -3      ALFS/nALFS/src/handlers/log.c
  
  Index: log.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/log.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- log.c	6 Feb 2004 05:54:36 -0000	1.13
  +++ log.c	13 Feb 2004 07:08:59 -0000	1.14
  @@ -36,7 +36,6 @@
   
   #if HANDLER_SYNTAX_2_0 || HANDLER_SYNTAX_3_0
   
  -static const char *log_parameters[] = { NULL };
   
   static int log_main(element_s *el)
   {
  @@ -58,7 +57,6 @@
   		.name = "log",
   		.description = "Log",
   		.syntax_version = "2.0",
  -		.parameters = log_parameters,
   		.main = log_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  @@ -71,7 +69,6 @@
   		.name = "log",
   		.description = "Log",
   		.syntax_version = "3.0",
  -		.parameters = log_parameters,
   		.main = log_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  
  
  
  1.13      +0 -3      ALFS/nALFS/src/handlers/postbuild.c
  
  Index: postbuild.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/postbuild.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- postbuild.c	6 Feb 2004 05:54:36 -0000	1.12
  +++ postbuild.c	13 Feb 2004 07:08:59 -0000	1.13
  @@ -57,15 +57,12 @@
    * Handlers' information.
    */
   
  -static const char *postbuild_parameters[] = { NULL };
  -
   handler_info_s HANDLER_SYMBOL(info)[] = {
   #if HANDLER_SYNTAX_2_0
   	{
   		.name = "postbuild",
   		.description = "Post building",
   		.syntax_version = "2.0",
  -		.parameters = postbuild_parameters,
   		.main = postbuild_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  
  
  
  1.13      +0 -2      ALFS/nALFS/src/handlers/prebuild.c
  
  Index: prebuild.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/prebuild.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- prebuild.c	6 Feb 2004 05:54:36 -0000	1.12
  +++ prebuild.c	13 Feb 2004 07:08:59 -0000	1.13
  @@ -57,7 +57,6 @@
    * Handlers' information.
    */
   
  -static const char *prebuild_parameters[] = { NULL };
   
   handler_info_s HANDLER_SYMBOL(info)[] = {
   #if HANDLER_SYNTAX_2_0
  @@ -65,7 +64,6 @@
   		.name = "prebuild",
   		.description = "Pre building",
   		.syntax_version = "2.0",
  -		.parameters = prebuild_parameters,
   		.main = prebuild_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  
  
  
  1.18      +0 -4      ALFS/nALFS/src/handlers/remove.c
  
  Index: remove.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/remove.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- remove.c	11 Feb 2004 05:08:12 -0000	1.17
  +++ remove.c	13 Feb 2004 07:08:59 -0000	1.18
  @@ -41,7 +41,6 @@
   #include "parser.h"
   #include "backend.h"
   
  -static const char *remove_parameters_ver[] = { NULL };
   static const char *remove_parameters_ver_3_2[] = { "base", "file",  NULL };
   
   #if HANDLER_SYNTAX_2_0
  @@ -188,7 +187,6 @@
   		.name = "remove",
   		.description = "Remove files",
   		.syntax_version = "2.0",
  -		.parameters = remove_parameters_ver,
   		.main = remove_main_ver2,
   		.type = 0,
   		.alloc_data = NULL,
  @@ -201,7 +199,6 @@
   		.name = "remove",
   		.description = "Remove files",
   		.syntax_version = "3.0",
  -		.parameters = remove_parameters_ver,
   		.main = remove_main_ver3,
   		.type = 0,
   		.alloc_data = NULL,
  @@ -214,7 +211,6 @@
   		.name = "remove",
   		.description = "Remove files",
   		.syntax_version = "3.1",
  -		.parameters = remove_parameters_ver,
   		.main = remove_main_ver3,
   		.type = 0,
   		.alloc_data = NULL,
  
  
  
  1.19      +60 -3     ALFS/nALFS/src/handlers/stage.c
  
  Index: stage.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/stage.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- stage.c	11 Feb 2004 05:08:12 -0000	1.18
  +++ stage.c	13 Feb 2004 07:08:59 -0000	1.19
  @@ -365,10 +365,63 @@
   }
   
   static const char *stage_parameters[] =
  -{ "stageinfo", "base", "root", "user", "environment", "variable", NULL };
  +{ "stageinfo", "base", "root", "user", "environment", NULL };
  +
  +static const char *stage_attributes[] =
  +{ "name", NULL};
  +
  +struct stage_data {
  +	char *name;
  +};
  +
   // char *HANDLER_SYMBOL(attributes)[] = {
   // "name", "description", "logfile", "mode", NULL };
   
  +static int stage_setup(element_s *element)
  +{
  +	struct stage_data *data;
  +
  +	if ((data = malloc(sizeof(struct stage_data))) == NULL)
  +		return 1;
  +
  +	data->name = NULL;
  +
  +	element->handler_data = data;
  +	return 0;
  +}
  +
  +static int stage_valid(element_s *element)
  +{
  +	return 0;
  +}
  +
  +static int stage_attribute(element_s *element, const char *attribute,
  +			   const char *value)
  +{
  +	int result = 1;
  +	struct stage_data *data = (struct stage_data *) element->handler_data;
  +
  +	if (strcmp(attribute, "name") == 0) {
  +		if (strlen(value)) {
  +			data->name = xstrdup(value);
  +			result = 0;
  +		} else {
  +			Nprint_err("<stage>: \"name\" cannot be empty.");
  +		}
  +	}
  +
  +	return result;
  +}
  +
  +static int stage_parameter(element_s *element, const char *parameter,
  +			   const char *value)
  +{
  +	int result = 1;
  +	struct stage_data *data = (struct stage_data *) element->handler_data;
  +
  +	return result;
  +}
  +
   static int stage_main(element_s *el)
   {
   	int status;
  @@ -408,8 +461,7 @@
   #if HANDLER_SYNTAX_3_2
   
   static const char *stage_parameters_3_2[] =
  -{ "stageinfo", "base", "root", "user", "environment", "variable",
  -  "shell", NULL };
  +{ "stageinfo", "base", "root", "user", "environment", "shell", NULL };
   
   #endif
   
  @@ -529,7 +581,12 @@
   		.description = "Enter stage: ", // FIXME
   		.syntax_version = "3.2",
   		.parameters = stage_parameters_3_2,
  +		.attributes = stage_attributes,
   		.main = stage_main,
  +		.setup = stage_setup,
  +		.valid = stage_valid,
  +		.parse_attribute = stage_attribute,
  +		.parse_parameter = stage_parameter,
   		.type = HTYPE_NORMAL | HTYPE_STAGE,
   		.alloc_data = NULL,
   		.is_action = 0,
  
  
  
  1.12      +0 -2      ALFS/nALFS/src/handlers/stamp.c
  
  Index: stamp.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/stamp.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- stamp.c	6 Feb 2004 05:54:36 -0000	1.11
  +++ stamp.c	13 Feb 2004 07:08:59 -0000	1.12
  @@ -37,7 +37,6 @@
   
   #if HANDLER_SYNTAX_2_0
   
  -static const char *stamp_parameters[] = { NULL };
   // char *HANDLER_SYMBOL(attributes)[] = { "name", "version" };
   
   static int stamp_main(element_s *el)
  @@ -74,7 +73,6 @@
   		.name = "stamp",
   		.description = "Produce a stamp",
   		.syntax_version = "3.0",
  -		.parameters = stamp_parameters,
   		.main = stamp_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  
  
  
  1.15      +0 -2      ALFS/nALFS/src/handlers/su.c
  
  Index: su.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/su.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- su.c	6 Feb 2004 05:54:36 -0000	1.14
  +++ su.c	13 Feb 2004 07:08:59 -0000	1.15
  @@ -138,7 +138,6 @@
   }
   
   
  -static const char *su_parameters[] = { NULL };
   // char *HANDLER_SYMBOL(attributes)[] = { "user", NULL };
   
   static int su_main(element_s *el)
  @@ -213,7 +212,6 @@
   		.name = "su",
   		.description = "Change user ID",
   		.syntax_version = "2.0",
  -		.parameters = su_parameters,
   		.main = su_main,
   		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
  
  
  



More information about the alfs-log mailing list