[Libvirt-cim] [PATCH] [CU] (#2) Add support to read/write array of strings to properties which expect them

Richard Maciel rmaciel at linux.vnet.ibm.com
Wed Jun 3 13:54:08 UTC 2009


# HG changeset patch
# User Richard Maciel <rmaciel at linux.vnet.ibm.com>
# Date 1243950914 10800
# Node ID 0cbdf0dcd41651b7a4e6f1844bf567ced1106225
# Parent  1cb3975921d590d4dda4de197a4dc687e45d1840
[CU] (#2) Add support to read/write array of strings to properties which expect them.

The lexer and the parser were changed recognize array strings and properly handle it to the provider which called the lexer/parser

#2:
  - Parser now returns a specific error message when it cannot set a string array property

Signed-off-by: Richard Maciel <rmaciel at linux.vnet.ibm.com>

diff -r 1cb3975921d5 -r 0cbdf0dcd416 eo_parser.c
--- a/eo_parser.c	Mon Apr 27 16:11:32 2009 -0700
+++ b/eo_parser.c	Tue Jun 02 10:55:14 2009 -0300
@@ -169,6 +169,29 @@
         return CMPI_sint8;
 }
 
+inline CMPIStatus ins_chars_into_cmstr_arr(const CMPIBroker *broker,
+                                           CMPIArray *arr,
+                                           CMPICount index,
+                                           char *str)
+{
+        CMPIString *cm_str;
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        
+        cm_str = CMNewString(broker, str, &s);
+        if (s.rc != CMPI_RC_OK || CMIsNullObject(cm_str)) {
+                CU_DEBUG("Error creating CMPIString");
+                goto out;
+        }
+
+        s = CMSetArrayElementAt(arr, index, &cm_str, CMPI_string);
+        if (s.rc != CMPI_RC_OK)
+                CU_DEBUG("Error setting array element %u\n"
+                         "Error code: %d", index, s.rc);
+
+ out:
+        return s;
+}
+
 /*
  * Local Variables:
  * mode: C
diff -r 1cb3975921d5 -r 0cbdf0dcd416 eo_parser_xml.h
--- a/eo_parser_xml.h	Mon Apr 27 16:11:32 2009 -0700
+++ b/eo_parser_xml.h	Tue Jun 02 10:55:14 2009 -0300
@@ -31,6 +31,11 @@
                       char *prop,
                       CMPIInstance *inst);
 
+inline CMPIStatus ins_chars_into_cmstr_arr(const CMPIBroker *broker,
+                                           CMPIArray *arr,
+                                           CMPICount index,
+                                           char *str);
+
 #endif
 
 /*
diff -r 1cb3975921d5 -r 0cbdf0dcd416 eo_util_lexer.l
--- a/eo_util_lexer.l	Mon Apr 27 16:11:32 2009 -0700
+++ b/eo_util_lexer.l	Tue Jun 02 10:55:14 2009 -0300
@@ -4,6 +4,7 @@
  * Authors:
  *  Gareth Bestor <bestorga at us.ibm.com>
  *  Dan Smith <danms at us.ibm.com>
+ *  Richard Maciel <richardm at br.ibm.com>
  *
  */
 	/*** WARNING - COMMENTS IN LEX MUST BE TAB INDENTED ***/
@@ -91,7 +92,18 @@
 	return(STRING);
 	}
 
-	/* Classname */
+\{      {
+        return(OPENBRACKET);
+        }
+
+\}      {
+        return(CLOSEBRACKET);
+        }
+
+\,      {
+        return(COMMA);
+        }
+
 	/* NOTE - this rule only applies after a 'INSTANCE OF' has been read in */
 <READCLASSNAME>[A-Za-z][A-Za-z0-9_]* {
 	BEGIN INITIAL; /* Go back to normal parsing rules now */
diff -r 1cb3975921d5 -r 0cbdf0dcd416 eo_util_parser.y
--- a/eo_util_parser.y	Mon Apr 27 16:11:32 2009 -0700
+++ b/eo_util_parser.y	Tue Jun 02 10:55:14 2009 -0300
@@ -4,6 +4,7 @@
  * Authors:
  *  Gareth Bestor <bestorga at us.ibm.com>
  *  Dan Smith <danms at us.ibm.com>
+ *  Richard Maciel <richardm at br.ibm.com>
  */
 /* DEFINITIONS SECTION */
 
@@ -24,11 +25,16 @@
 #define RC_OK 0
 #define RC_EOF EOF
 #define RC_INVALID_CLASS -1000
+#define RC_ARR_CREAT_FAILED -2000
 
 /* DEFINE ANY GLOBAL VARS HERE */
 static const CMPIBroker * _BROKER;
 static CMPIInstance ** _INSTANCE;
 static const char * _NAMESPACE;
+static CMPICount stringarraysize;
+static char **stringarray;
+static char *stringarraypropname;
+
 
 #ifdef EODEBUG
 #define EOTRACE(fmt, arg...) fprintf(stderr, fmt, ##arg)
@@ -36,6 +42,7 @@
 #define EOTRACE(fmt, arg...)
 #endif
 
+
 int eo_parse_parseinstance(const CMPIBroker *broker,
 			   CMPIInstance **instance,
 			   const char *ns);
@@ -52,7 +59,7 @@
 }
 
 /* Define simple (untyped) lexical tokens */
-%token INSTANCE OF ENDOFFILE
+%token INSTANCE OF ENDOFFILE OPENBRACKET CLOSEBRACKET COMMA
 
  /* Define lexical tokens that return a value and their return type */
 %token <string> CLASS
@@ -67,7 +74,7 @@
 /* Rules section */
 
 instance:	/* empty */
-	|	INSTANCE OF CLASS '{'
+	|	INSTANCE OF CLASS OPENBRACKET
 			{
 			EOTRACE("classname = %s\n",$3);
 			CMPIObjectPath *op;
@@ -82,7 +89,7 @@
 				return RC_INVALID_CLASS;
 			free($3);
 			}
-		properties '}' ';'
+		properties CLOSEBRACKET ';'
 			{
 			/* Return after reading in each instance */
 			return RC_OK;
@@ -127,7 +134,17 @@
 			CMSetProperty(*_INSTANCE, $1, &($3), CMPI_boolean);
 			free($1);
 			}
+        |       PROPERTYNAME '=' OPENBRACKET                         
+                        {
+                        EOTRACE("propertyname = %s\n"
+				"\ttype = CMPI_charsA\n",
+				$1);
 
+                        stringarraysize = 0;
+                        stringarraypropname = $1;
+                        }
+                arrayofstrings CLOSEBRACKET ';' 
+                               
 	|	PROPERTYNAME '=' CIMNULL ';'
 			{
 			EOTRACE("propertyname = %s\n"
@@ -136,6 +153,80 @@
 			}
 	;
 
+arrayofstrings: STRING 
+                        {
+                        EOTRACE("\t%s[%u]=%s\n", 
+                                propertyname, 
+                                stringarraysize, 
+                                $1);
+
+                        stringarraysize++;
+                        stringarray = (char **)realloc(stringarray, 
+                                                       sizeof(char *) * 
+                                                       stringarraysize);
+                        stringarray[stringarraysize-1] = $1;
+                        }
+                COMMA arrayofstrings
+
+              
+        |       STRING
+                        {
+                        CMPIArray *arr;
+                        CMPICount i;
+                        CMPIStatus s = {CMPI_RC_OK, NULL};
+                        
+                        EOTRACE("\t%s[%u]=%s\n", 
+                                propertyname, 
+                                stringarraysize, 
+                                $1);
+                        
+                        stringarraysize++;
+
+                        arr = CMNewArray(_BROKER, 
+                                         stringarraysize, 
+                                         CMPI_string, 
+                                         &s);
+                        if (s.rc != CMPI_RC_OK || CMIsNullObject(arr)) {
+                                EOTRACE("Error creating array\n");
+                                goto str_arr_out;
+                        }
+
+                        // Values to stringarraysize - 2 are in the
+                        // temporary array
+                        for (i = 0; i < stringarraysize - 1; i++) {
+                                s = ins_chars_into_cmstr_arr(_BROKER,
+                                                             arr,
+                                                             i,
+                                                             stringarray[i]);
+                                if (s.rc != CMPI_RC_OK)
+                                        goto str_arr_out;
+                        }
+                        
+                        s = ins_chars_into_cmstr_arr(_BROKER, 
+                                                     arr,  
+                                                     stringarraysize - 1,
+                                                     $1);
+                        if (s.rc != CMPI_RC_OK)
+                                goto str_arr_out;
+
+                        CMSetProperty(*_INSTANCE, 
+                                      stringarraypropname,
+                                      &arr,
+                                      CMPI_stringA);
+                        
+                       str_arr_out:
+                        free(stringarraypropname);
+                        for (i = 0; i < stringarraysize - 1; i++)
+                                free(stringarray[i]);
+                        free($1);
+
+                        if (s.rc != CMPI_RC_OK) {
+                                return RC_ARR_CREAT_FAILED; 
+                        }
+                         
+                        }
+        ;
+
 /* END OF RULES SECTION */
 %%
 




More information about the Libvirt-cim mailing list