cvs commit: ALFS/nALFS/src/handlers stage.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Sat Feb 21 15:09:17 PST 2004


kpfleming    04/02/21 16:09:17

  Modified:    nALFS/src handlers.c handlers.h libXML-tree.c
               nALFS/src/handlers stage.c
  Log:
  add embedded handlers for the root (profile) element and comment elements
  rename handler "valid" function to "invalid_data"
  add handler "invalid_child" function so parents can validate child elements
  
  Revision  Changes    Path
  1.21      +56 -11    ALFS/nALFS/src/handlers.c
  
  Index: handlers.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- handlers.c	21 Feb 2004 19:03:32 -0000	1.20
  +++ handlers.c	21 Feb 2004 23:09:17 -0000	1.21
  @@ -50,6 +50,41 @@
   
   static char **parameters;
   
  +/* Embedded "handlers" for the root (profile) element and comment elements. */
  +
  +static int root_main(element_s * const el)
  +{
  +	(void) el;
  +
  +	return 0;
  +}
  +
  +static int comment_main(element_s * const el)
  +{
  +	(void) el;
  +
  +	return 0;
  +}
  +
  +static handler_info_s embedded_handlers_info[] = {
  +	{
  +		.name = "__root",
  +		.description = "root element",
  +		.syntax_version = "all",
  +		.main = root_main,
  +		.type = HTYPE_NORMAL,
  +	},
  +	{
  +		.name = "__comment",
  +		.description = "comment element",
  +		.syntax_version = "all",
  +		.main = comment_main,
  +		.type = HTYPE_NORMAL,
  +	},
  +	{
  +		.name = NULL
  +	}
  +};
   
   /*
    * Returns a pointer to handler_s if element (name/version) has a handler,
  @@ -166,20 +201,11 @@
   	existing->handle = handle;
   }
   
  -static int load_handler(lt_dlhandle handle, lt_ptr data)
  +static int parse_handler_info(handler_info_s * handler_info,
  +			      lt_dlhandle handle)
   {
   	int i;
  -	handler_info_s *handler_info;
  -
  -	(void) data;
  -
  -	handler_info = (handler_info_s *)lookup_symbol(handle, "handler_info");
  -
  -	if (handler_info == NULL) {
  -		return 0;
  -	}
   
  -	/* Go through handler_info[].  */
   	for (i = 0; (handler_info[i].name); ++i) {
   		handler_info_s *hi = &handler_info[i];
   		handler_s *found;
  @@ -209,6 +235,21 @@
   	return 0;
   }
   
  +static int load_handler(lt_dlhandle handle, lt_ptr data)
  +{
  +	handler_info_s *handler_info;
  +
  +	(void) data;
  +
  +	handler_info = (handler_info_s *)lookup_symbol(handle, "handler_info");
  +
  +	if (handler_info == NULL) {
  +		return 0;
  +	}
  +
  +	return parse_handler_info(handler_info, handle);
  +}
  +
   static INLINE void add_all_parameters(void)
   {
   	int i;
  @@ -255,6 +296,9 @@
   	lt_dlforeachfile(HANDLERS_DIRECTORY, &foreachfile_callback, NULL);
   #endif
   
  +	/* Load the embedded handlers first, then the loaded ones. */
  +	(void) parse_handler_info(embedded_handlers_info, NULL);
  +
   	lt_dlforeach(&load_handler, NULL);
   	add_all_parameters();
   	Nprint("Total %d handlers loaded.", handlers.cnt);
  @@ -532,3 +576,4 @@
   		return NULL;
   	}
   }
  +
  
  
  
  1.15      +5 -2      ALFS/nALFS/src/handlers.h
  
  Index: handlers.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers.h,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- handlers.h	21 Feb 2004 19:03:32 -0000	1.14
  +++ handlers.h	21 Feb 2004 23:09:17 -0000	1.15
  @@ -61,7 +61,9 @@
   			     const char * const value);
   typedef int (*handler_parse_content)(const element_s * const element,
   				     const char * const content);
  -typedef int (*handler_valid)(const element_s * const element);
  +typedef int (*handler_invalid_data)(const element_s * const element);
  +typedef int (*handler_invalid_child)(const element_s * const element,
  +				     const element_s * const child);
   
   typedef struct handler_info_s {
   	const char *name;		/* Name of the element it handles. */
  @@ -91,7 +93,8 @@
   	   and to validate the provided parameters, attributes and content.
   	*/
   	handler_setup setup;	/* Function to setup handler private data. */
  -	handler_valid valid;	/* Function to validate private data. */
  +	handler_invalid_data invalid_data; /* Validate private data. */
  +	handler_invalid_child invalid_child; /* Validate potential child. */
   	handler_parse parse_attribute;
   	handler_parse parse_parameter;
   	handler_parse_content parse_content;
  
  
  
  1.10      +39 -25    ALFS/nALFS/src/libXML-tree.c
  
  Index: libXML-tree.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/libXML-tree.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- libXML-tree.c	14 Feb 2004 04:32:22 -0000	1.9
  +++ libXML-tree.c	21 Feb 2004 23:09:17 -0000	1.10
  @@ -1,9 +1,10 @@
   /*
    *  libXML-tree.c - Parsing with libxml2 library (tree).
    *
  - *  Copyright (C) 2002-2003
  + *  Copyright (C) 2002-2004
    *
    *  Neven Has <haski at sezampro.yu>
  + *  Kevin P. Fleming <kpfleming at linuxfromscratch.org>
    *
    *  This program is free software; you can redistribute it and/or modify
    *  it under the terms of the GNU General Public License as published by
  @@ -147,14 +148,10 @@
   static int make_handler_element(xmlNodePtr node, element_s *element)
   {
   	handler_info_s *handler = element->handler;
  -	int result = 1;
  +	handler_info_s *parent = element->parent->handler;
  +	int result;
   
  -	/* 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) {
  +	if (handler->setup && ((result = handler->setup(element)) == 0)) {
   		xmlAttrPtr attr;
   		xmlNodePtr child;
   
  @@ -221,11 +218,25 @@
   
   		}
   
  -		if (handler->valid)
  -			result = handler->valid(element);
  +		/* If the handler wants to validate its private data */
  +		if (handler->invalid_data) {
  +			result = handler->invalid_data(element);
  +			if (result)
  +				return result;
  +		}
  +
  +	}
  +
  +	/* If the element's parent wants to validate its children */
  +	if (parent->invalid_child) {
  +		result = parent->invalid_child(element->parent, element);
  +		if (result) {
  +			Nprint_warn("<%s>: <%s> is not supported.", element->parent->handler->name, handler->name);
  +			return result;
  +		}
   	}
   
  -	return result;
  +	return 0;
   }
   
   static INLINE element_s *create_element(xmlNodePtr node, element_s *parent)
  @@ -256,7 +267,11 @@
   			if ((handler = find_handler(el->name, syntax_version))) {
   				el->type = TYPE_ELEMENT;
   				el->handler = handler->info;
  -				(void) make_handler_element(node, el);
  +				if (make_handler_element(node, el)) {
  +					free_element(el);
  +					el = NULL;
  +					break;
  +				}
   
   			} else if (parameter_exists(el->name)) {
   				el->type = TYPE_PARAMETER;
  @@ -276,18 +291,17 @@
   			set_attributes(el, node);
   
   			break;
  -
   		case XML_COMMENT_NODE:
   			el->name = xstrdup("comment");
   			el->type = TYPE_COMMENT;
  -
  -			if ((c = xmlNodeGetContent(node))) {
  -				el->content = xstrdup((const char *)c);
  -				xfree(c);
  +			el->handler = find_handler("__comment", "all")->info;
  +			if (make_handler_element(node, el)) {
  +				free_element(el);
  +				el = NULL;
  +				break;
   			}
   
   			break;
  -
   		default:
   			break;
   	}
  @@ -306,13 +320,12 @@
   		return NULL;
   	}
   
  -	el = create_element(node, parent);
  -
  -	for (child = node->children; child; child = child->next) {
  -		if ((c = convert_nodes(child, profile, el))) {
  -			link_element(c, prev, el, profile);
  -
  -			prev = c;
  +	if ((el = create_element(node, parent))) {
  +		for (child = node->children; child; child = child->next) {
  +			if ((c = convert_nodes(child, profile, el))) {
  +				link_element(c, prev, el, profile);
  +				prev = c;
  +			}
   		}
   	}
   
  @@ -339,6 +352,7 @@
   	profile->type = TYPE_PROFILE;
   	profile->id = element_id++;
   	profile->profile = profile;
  +	profile->handler = find_handler("__root", "all")->info;
   
   	for (child = doc->children; child; child = child->next) {
   		if ((el = convert_nodes(child, profile, profile))) {
  
  
  
  1.21      +4 -4      ALFS/nALFS/src/handlers/stage.c
  
  Index: stage.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/stage.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- stage.c	21 Feb 2004 19:03:32 -0000	1.20
  +++ stage.c	21 Feb 2004 23:09:17 -0000	1.21
  @@ -595,7 +595,7 @@
   	return 0;
   }
   
  -static int variable_valid(const element_s * const element)
  +static int variable_invalid_data(const element_s * const element)
   {
   	struct variable_data *data = (struct variable_data *) element->handler_data;
   
  @@ -679,7 +679,7 @@
   		.attributes = variable_attributes,
   		.parse_attribute = variable_attribute,
   		.parse_content = variable_content,
  -		.valid = variable_valid,
  +		.invalid_data = variable_invalid_data,
   	},
   #endif
   #if HANDLER_SYNTAX_3_1
  @@ -741,7 +741,7 @@
   		.attributes = variable_attributes,
   		.parse_attribute = variable_attribute,
   		.parse_content = variable_content,
  -		.valid = variable_valid,
  +		.invalid_data = variable_invalid_data,
   	},
   #endif
   #if HANDLER_SYNTAX_3_2
  @@ -803,7 +803,7 @@
   		.attributes = variable_attributes,
   		.parse_attribute = variable_attribute,
   		.parse_content = variable_content,
  -		.valid = variable_valid,
  +		.invalid_data = variable_invalid_data,
   	},
   #endif
   	{
  
  
  



More information about the alfs-log mailing list