Browse Source

xml: PTYPE can has ref but don't have name

Serj Kalichev 1 year ago
parent
commit
af3bb9c7d2
2 changed files with 15 additions and 7 deletions
  1. 1 1
      klish.xsd
  2. 14 6
      klish/xml-helper/load.c

+ 1 - 1
klish.xsd

@@ -333,7 +333,7 @@
 		<xs:sequence>
 			<xs:group ref="ptype_group_t" minOccurs="0" maxOccurs="unbounded"/>
 		</xs:sequence>
-		<xs:attribute name="name" type="xs:string" use="required"/>
+		<xs:attribute name="name" type="xs:string" use="optional"/>
 		<xs:attribute name="help" type="xs:string" use="optional"/>
 		<xs:attribute name="ref" type="xs:string" use="optional"/>
 		<xs:attribute name="value" type="xs:string" use="optional"/>

+ 14 - 6
klish/xml-helper/load.c

@@ -601,12 +601,20 @@ static bool_t process_ptype(const kxml_node_t *element, void *parent,
 	ientry_t ientry = {};
 	kentry_t *entry = NULL;
 	bool_t res = BOOL_FALSE;
+	bool_t is_name = BOOL_FALSE;
 
-	// Mandatory PTYPE name
+	// Mandatory PTYPE name or reference
 	ientry.name = kxml_node_attr(element, "name");
-	if (!ientry.name) {
-		faux_error_sprintf(error, TAG": PTYPE without name");
-		return BOOL_FALSE;
+	ientry.ref = kxml_node_attr(element, "ref");
+	if (ientry.name) {
+		is_name = BOOL_TRUE;
+	} else {
+		if (!ientry.ref) {
+			faux_error_sprintf(error,
+				TAG": PTYPE without name or reference");
+			return BOOL_FALSE;
+		}
+		ientry.name = "__ptype";
 	}
 	ientry.help = kxml_node_attr(element, "help");
 	ientry.container = "true";
@@ -614,7 +622,6 @@ static bool_t process_ptype(const kxml_node_t *element, void *parent,
 	ientry.purpose = "ptype";
 	ientry.min = "1";
 	ientry.max = "1";
-	ientry.ref = kxml_node_attr(element, "ref");
 	ientry.value = kxml_node_attr(element, "value");
 	ientry.restore = "false";
 	ientry.order = "true";
@@ -628,7 +635,8 @@ static bool_t process_ptype(const kxml_node_t *element, void *parent,
 
 	res = BOOL_TRUE;
 err:
-	kxml_node_attr_free(ientry.name);
+	if (is_name)
+		kxml_node_attr_free(ientry.name);
 	kxml_node_attr_free(ientry.help);
 	kxml_node_attr_free(ientry.ref);
 	kxml_node_attr_free(ientry.value);