# HG changeset patch
# User Richard Maciel <rmaciel(a)linux.vnet.ibm.com>
# Date 1243950914 10800
# Node ID 639fb266e1e6d657ba5a7c52c5acd2dc7d4ccb66
# Parent 1cb3975921d590d4dda4de197a4dc687e45d1840
[CU] 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
Signed-off-by: Richard Maciel <rmaciel(a)linux.vnet.ibm.com>
diff -r 1cb3975921d5 -r 639fb266e1e6 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 639fb266e1e6 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 639fb266e1e6 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(a)us.ibm.com>
* Dan Smith <danms(a)us.ibm.com>
+ * Richard Maciel <richardm(a)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 639fb266e1e6 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(a)us.ibm.com>
* Dan Smith <danms(a)us.ibm.com>
+ * Richard Maciel <richardm(a)br.ibm.com>
*/
/* DEFINITIONS SECTION */
@@ -29,6 +30,10 @@
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 +41,7 @@
#define EOTRACE(fmt, arg...)
#endif
+
int eo_parse_parseinstance(const CMPIBroker *broker,
CMPIInstance **instance,
const char *ns);
@@ -52,7 +58,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 +73,7 @@
/* Rules section */
instance: /* empty */
- | INSTANCE OF CLASS '{'
+ | INSTANCE OF CLASS OPENBRACKET
{
EOTRACE("classname = %s\n",$3);
CMPIObjectPath *op;
@@ -82,7 +88,7 @@
return RC_INVALID_CLASS;
free($3);
}
- properties '}' ';'
+ properties CLOSEBRACKET ';'
{
/* Return after reading in each instance */
return RC_OK;
@@ -127,7 +133,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 +152,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_INVALID_CLASS;
+ }
+
+ }
+ ;
+
/* END OF RULES SECTION */
%%