From: Adrian S. <a3s...@us...> - 2005-06-13 23:50:59
|
Update of /cvsroot/sblim/sfcc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19010 Modified Files: Makefile cimXmlParser.c cimXmlParser.h cimXmlResp.c cimXmlResp.h cimXmlResp.y client.c cmci.h cmcimacs.h native.h property.c test.c Added Files: constClass.c qualifier.c Log Message: Various fixes for getClass and getInstance processing Index: cimXmlResp.c =================================================================== RCS file: /cvsroot/sblim/sfcc/cimXmlResp.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- cimXmlResp.c 6 Jun 2005 15:28:27 -0000 1.2 +++ cimXmlResp.c 13 Jun 2005 23:50:46 -0000 1.3 @@ -257,6 +257,10 @@ extern int yyerror(char*); extern int yylex (void *lvalp, ParserControl *parm); +extern CMPIConstClass * native_new_CMPIConstClass ( char *cn, CMPIStatus * rc ); +extern int addClassProperty( CMPIConstClass * ccls, char * name, CMPIValue * value, CMPIType type, + CMPIValueState state); + int isBoolean(CMPIData data) { @@ -267,22 +271,6 @@ [...1039 lines suppressed...] { yyval.xtokKeyBinding.name=yyvsp[-2].xtokKeyBinding.name; yyval.xtokKeyBinding.value=NULL; @@ -1836,7 +2013,7 @@ } /* Line 999 of yacc.c. */ -#line 1839 "cimXmlResp.c" +#line 2016 "cimXmlResp.c" yyvsp -= yylen; yyssp -= yylen; @@ -2030,6 +2207,6 @@ } -#line 786 "cimXmlResp.y" +#line 961 "cimXmlResp.y" Index: cmci.h =================================================================== RCS file: /cvsroot/sblim/sfcc/cmci.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- cmci.h 6 Jun 2005 13:19:49 -0000 1.5 +++ cmci.h 13 Jun 2005 23:50:46 -0000 1.6 @@ -353,6 +353,88 @@ } CMCIClientFT; + + //--------------------------------------------------- + //-- + // _CMPIConstClass Function Table + //-- + //--------------------------------------------------- + + + /** This structure is a table of pointers providing access to Instance + support sevices. + */ +typedef struct _CMPIConstClassFT { + + /** Function table version + */ + int ftVersion; + + /** The ConstClass object will not be used any further and may be freed by + CMPI run time system. + @param ccls ConstClass this pointer. + @return Service return status. + */ + CMPIStatus (*release) + (CMPIConstClass* ccls); + + /** Create an independent copy of this CpnstClass object. The resulting + object must be released explicitly. + @param ccls ConstClass this pointer. + @param rc Output: Service return status (suppressed when NULL). + @return Pointer to copied ConstClass object. + */ + CMPIConstClass* (*clone) + (CMPIConstClass* ccls, CMPIStatus* rc); + + /** Gets the classname. + @param ccls ConstClass this pointer. + @param rc Output: Service return status (suppressed when NULL). + @return classname. + */ + CMPIString *(*getClassName) + ( CMPIConstClass * ccls, CMPIStatus * rc ); + + /** Gets a named property value. + @param ccls ConstClass this pointer. + @param name Property name. + @param rc Output: Service return status (suppressed when NULL). + @return Property value. + */ + CMPIData (*getProperty) + (CMPIConstClass* ccls, const char *name, CMPIStatus* rc); + + /** Gets a Property value defined by its index. + @param ccls ConstClass this pointer. + @param index Position in the internal Data array. + @param name Output: Returned property name (suppressed when NULL). + @param rc Output: Service return status (suppressed when NULL). + @return Property value. + */ + CMPIData (*getPropertyAt) + (CMPIConstClass* ccls, unsigned int index, CMPIString** name, + CMPIStatus* rc); + + /** Gets the number of properties contained in this Instance. + @param ccls ConstClass this pointer. + @param rc Output: Service return status (suppressed when NULL). + @return Number of properties. + */ + unsigned int (*getPropertyCount) + (CMPIConstClass* ccls, CMPIStatus* rc); + +} CMPIConstClassFT; + + +struct _CMPIConstClass { + void *hdl; + CMPIConstClassFT *ft; +}; + + + + + typedef struct clientData { char *hostName; char *port; Index: property.c =================================================================== RCS file: /cvsroot/sblim/sfcc/property.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- property.c 4 May 2005 18:20:08 -0000 1.1 +++ property.c 13 Jun 2005 23:50:46 -0000 1.2 @@ -36,11 +36,12 @@ for various native data types. */ struct native_property { - char * name; //!< Property identifier. - CMPIType type; //!< Associated CMPIType. - CMPIValueState state; //!< Current value state. - CMPIValue value; //!< Current value. - struct native_property * next; //!< Pointer to next property. + char * name; //!< Property identifier. + CMPIType type; //!< Associated CMPIType. + CMPIValueState state; //!< Current value state. + CMPIValue value; //!< Current value. + struct native_qualifier *qualifiers; //!< Qualifiers. + struct native_property * next; //!< Pointer to next property. }; @@ -87,35 +88,36 @@ tool_mm_alloc ( mm_add, sizeof ( struct native_property ) ); + tmp->qualifiers = NULL; tmp->name = strdup ( name ); if ( mm_add == TOOL_MM_ADD ) tool_mm_add ( tmp->name ); if ( type == CMPI_chars ) { - type = CMPI_string; - v.string = native_new_CMPIString ( (char *) value, - NULL ); + v.string = native_new_CMPIString ( (char *) value, NULL ); value = &v; } tmp->type = type; - if ( type != CMPI_null ) { + if ( type != CMPI_null && state != CMPI_nullValue) { tmp->state = state; if ( mm_add == TOOL_MM_ADD ) { tmp->value = *value; - } else { - + } + else { CMPIStatus rc; - tmp->value = native_clone_CMPIValue ( type, - value, - &rc ); + tmp->value = native_clone_CMPIValue ( type, value, &rc ); // what if clone() fails??? } - } else tmp->state = CMPI_nullValue; + } + else { + tmp->state = CMPI_nullValue; + tmp->value.uint64=0; + } return 0; } @@ -201,6 +203,20 @@ return __convert2CMPIData ( p, NULL ); } +static struct native_qualifier *__getDataPropertyQualifiers ( struct native_property * prop, + const char * name, + CMPIStatus * rc ) +{ + struct native_property * p = __getProperty ( prop, name ); + + if ( rc ) CMSetStatus ( rc, + ( p )? + CMPI_RC_OK: + CMPI_RC_ERR_NO_SUCH_PROPERTY ); + + return p ? p->qualifiers : NULL; +} + static struct native_property * __getPropertyAt ( struct native_property * prop, unsigned int pos ) @@ -299,6 +315,7 @@ __getDataProperty, __getDataPropertyAt, __getPropertyCount, + __getDataPropertyQualifiers, __release, __clone }; Index: test.c =================================================================== RCS file: /cvsroot/sblim/sfcc/test.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- test.c 6 Jun 2005 15:28:28 -0000 1.3 +++ test.c 13 Jun 2005 23:50:46 -0000 1.4 @@ -8,6 +8,8 @@ CMPIInstance *ci; CMPIEnumeration *enm; CMPIStatus rc; + CMPIConstClass *cls; + CMPIData data; cc=cmciConnect("localhost",NULL,NULL,NULL,NULL); cop=newCMPIObjectPath("root/cimv2",NULL,NULL); @@ -20,17 +22,28 @@ printf(" -- className: %s\n",(char*)cn->hdl); CMRelease(cn); } + CMRelease(enm); + CMRelease(cop); cop=newCMPIObjectPath("root/cimv2","Linux_ComputerSystem",NULL); + cls=cc->ft->getClass(cc,cop,0,NULL,&rc); + printf("--- getClass rc: %d - %s\n",rc.rc, rc.msg ? (char*)rc.msg->hdl : NULL); + data=cls->ft->getProperty(cls,"InstallDate",&rc); + printf("--- getProperty rc: %d - %s %x\n",rc.rc, rc.msg ? (char*)rc.msg->hdl : NULL,data.state); + data=cls->ft->getProperty(cls,"EnabledDefault",&rc); + printf("--- getProperty rc: %d - %s %x %d\n",rc.rc, rc.msg ? (char*)rc.msg->hdl : NULL,data.state,data.value.uint16); + CMAddKey(cop,"CreationClassName","Linux_ComputerSystem",CMPI_chars); enm=cc->ft->enumInstanceNames(cc,cop,&rc); printf("--- enumInstanceNames rc: %d - %s\n",rc.rc, rc.msg ? (char*)rc.msg->hdl : NULL); - CMAddKey(cop,"Name","localhost.localdomain",CMPI_chars); + if (argc==1) CMAddKey(cop,"Name","localhost.localdomain",CMPI_chars); + else CMAddKey(cop,"Name","dyn-9-152-143-58.boeblingen.de.ibm.com",CMPI_chars); ci=cc->ft->getInstance(cc,cop,0,NULL,&rc); printf("--- getInstance rc: %d - %s\n",rc.rc, rc.msg ? (char*)rc.msg->hdl : NULL); + if (rc.rc) printf("You may need to modify the hostname in line 41 or 42\n"); return 0; Index: cimXmlResp.h =================================================================== RCS file: /cvsroot/sblim/sfcc/cimXmlResp.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- cimXmlResp.h 6 Jun 2005 15:28:28 -0000 1.2 +++ cimXmlResp.h 13 Jun 2005 23:50:46 -0000 1.3 @@ -182,7 +182,7 @@ #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 121 "cimXmlResp.y" +#line 221 "cimXmlResp.y" typedef union YYSTYPE { int intValue; char boolValue; Index: native.h =================================================================== RCS file: /cvsroot/sblim/sfcc/native.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- native.h 4 May 2005 18:20:08 -0000 1.1 +++ native.h 13 Jun 2005 23:50:46 -0000 1.2 @@ -33,6 +33,20 @@ #include "cimXmlParser.h" +//! Forward declaration for anonymous struct. +struct native_property; +struct native_qualifier; + +struct native_constClass { + CMPIConstClass ccls; + int mem_state; + + char * classname; + + struct native_property * props; + struct native_qualifier *qualifiers; +}; + struct native_instance { CMPIInstance instance; int mem_state; @@ -47,9 +61,6 @@ struct native_property * props; }; -//! Forward declaration for anonymous struct. -struct native_property; - //! Function table for native_property handling functions. /*! @@ -90,6 +101,11 @@ CMPICount (* getPropertyCount) ( struct native_property *, CMPIStatus * ); + //! Looks up a specifix native_property and return qualifier chain. + struct native_qualifier *(*__getDataPropertyQualifiers ) ( struct native_property *, + const char *, + CMPIStatus * ); + //! Releases a complete list of native_property items. void (* release) ( struct native_property * ); @@ -99,6 +115,46 @@ }; +struct native_qualifierFT { + + //! Adds a new native_qualifier to a list. + int (* addQualifier) ( struct native_qualifier **, + int, + const char *, + CMPIType, + CMPIValueState, + CMPIValue * ); + + //! Resets the values of an existing native_qualifier, if existant. + int (* setQualifier) ( struct native_qualifier *, + int, + const char *, + CMPIType, + CMPIValue * ); + + //! Looks up a specifix native_qualifier in CMPIData format. + CMPIData (* getDataQualifier) ( struct native_qualifier *, + const char *, + CMPIStatus * ); + + //! Extract an indexed native_qualifier in CMPIData format. + CMPIData (* getDataQualifierAt) ( struct native_qualifier *, + unsigned int, + CMPIString **, + CMPIStatus * ); + + //! Yields the number of native_qualifier items in a list. + CMPICount (* getQualifierCount) ( struct native_qualifier *, + CMPIStatus * ); + + //! Releases a complete list of native_qualifier items. + void (* release) ( struct native_qualifier * ); + + //! Clones a complete list of native_qualifier items. + struct native_qualifier * (* clone) ( struct native_qualifier *, + CMPIStatus * ); +}; + /****************************************************************************/ Index: cmcimacs.h =================================================================== RCS file: /cvsroot/sblim/sfcc/cmcimacs.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- cmcimacs.h 5 Jun 2005 21:06:56 -0000 1.2 +++ cmcimacs.h 13 Jun 2005 23:50:46 -0000 1.3 @@ -166,7 +166,10 @@ #define CMClone(o,rc) ((o)->ft->clone((o),(rc))) #define CMRelease(o) ((o)->ft->release((o))) #define CMGetCharPtr(s) ((char*)s->hdl) - + #define CMReleaseData(d) \ + if (((d)->type >= CMPI_instance && (d)->type <= CMPI_dateTime) || \ + ((d)->type >= CMPI_instanceA && (d)->type <= CMPI_dateTimeA)) \ + CMRelease((d)->value); // CMPIInstance macros Index: Makefile =================================================================== RCS file: /cvsroot/sblim/sfcc/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Makefile 4 May 2005 18:20:08 -0000 1.1 +++ Makefile 13 Jun 2005 23:50:46 -0000 1.2 @@ -17,8 +17,10 @@ datetime.c \ enumeration.c \ instance.c \ + constClass.c \ objectpath.c \ property.c \ + qualifier.c \ string.c \ value.c \ client.c \ @@ -58,7 +60,7 @@ libCmpiSfcc.so: $(SOURCES.CmpiSfcc:.c=.o) $(LINK_LIB) -test: LOADLIBES += -lCmpiSfcc -L. +test: LOADLIBES += -lCmpiSfcc -L. -lsfcBrokerCore test: $(SOURCES.test:.c=.o) $(LINK_BIN) --- NEW FILE: qualifier.c --- /*! \file qualifier.c \brief Native qualifier implementation. This module implements a native qualifier, which is not public to any provider programmer. It is used to implement various other data types natively, such as instances, object-paths and args. It provides means to maintain linked lists of named properties including functionality to add, remove, clone and release them. (C) Copyright IBM Corp. 2003 THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. You can obtain a current copy of the Common Public License from http://oss.software.ibm.com/developerworks/opensource/license-cpl.html \author Frank Scheffler $Revision: 1.1 $ */ #include <stdio.h> #include <string.h> #include "cmcidt.h" #include "cmcift.h" #include "cmcimacs.h" #include "tool.h" #include "native.h" //! Storage container for commonly needed data within native CMPI data types. /*! This structure is used to build linked lists of data containers as needed for various native data types. */ struct native_qualifier { char * name; //!< Qualifier identifier. CMPIType type; //!< Associated CMPIType. CMPIValueState state; //!< Current value state. CMPIValue value; //!< Current value. struct native_qualifier * next; //!< Pointer to next qualifier. }; /****************************************************************************/ static CMPIData __convert2CMPIData ( struct native_qualifier * qual, CMPIString ** qualname ) { CMPIData result; if ( qual != NULL ) { result.type = qual->type; result.state = qual->state; result.value = qual->value; if ( qualname ) { *qualname = native_new_CMPIString ( qual->name, NULL ); } } else { result.state = CMPI_nullValue; } return result; } /** * returns non-zero if already existant */ static int __addQualifier ( struct native_qualifier ** qual, int mm_add, const char * name, CMPIType type, CMPIValueState state, CMPIValue * value ) { CMPIValue v; if ( *qual == NULL ) { struct native_qualifier * tmp = *qual = (struct native_qualifier *) tool_mm_alloc ( mm_add, sizeof ( struct native_qualifier ) ); tmp->name = strdup ( name ); if ( mm_add == TOOL_MM_ADD ) tool_mm_add ( tmp->name ); if ( type == CMPI_chars ) { type = CMPI_string; v.string = native_new_CMPIString ( (char *) value, NULL ); value = &v; } tmp->type = type; if ( type != CMPI_null ) { tmp->state = state; if ( mm_add == TOOL_MM_ADD ) { tmp->value = *value; } else { CMPIStatus rc; tmp->value = native_clone_CMPIValue ( type, value, &rc ); // what if clone() fails??? } } else tmp->state = CMPI_nullValue; return 0; } return ( strcmp ( (*qual)->name, name ) == 0 || __addQualifier ( &( (*qual)->next ), mm_add, name, type, state, value ) ); } /** * returns -1 if non-existant */ static int __setQualifier ( struct native_qualifier * qual, int mm_add, const char * name, CMPIType type, CMPIValue * value ) { CMPIValue v; if ( qual == NULL ) { return -1; } if ( strcmp ( qual->name, name ) == 0 ) { CMPIStatus rc; if ( ! ( qual->state & CMPI_nullValue ) ) native_release_CMPIValue ( qual->type, &qual->value ); if ( type == CMPI_chars ) { type = CMPI_string; v.string = native_new_CMPIString ( (char *) value, NULL ); value = &v; } qual->type = type; if ( type != CMPI_null ) { qual->value = ( mm_add == TOOL_MM_ADD )? *value: native_clone_CMPIValue ( type, value, &rc ); // what if clone() fails ??? } else qual->state = CMPI_nullValue; return 0; } return __setQualifier ( qual->next, mm_add, name, type, value); } static struct native_qualifier * __getQualifier ( struct native_qualifier * qual, const char * name ) { if ( ! qual || ! name ) { return NULL; } return ( strcmp ( qual->name, name ) == 0 )? qual: __getQualifier ( qual->next, name ); } static CMPIData __getDataQualifier ( struct native_qualifier * qual, const char * name, CMPIStatus * rc ) { struct native_qualifier * p = __getQualifier ( qual, name ); if ( rc ) CMSetStatus ( rc, ( p )? CMPI_RC_OK: CMPI_RC_ERR_NO_SUCH_PROPERTY ); return __convert2CMPIData ( p, NULL ); } static struct native_qualifier * __getQualifierAt ( struct native_qualifier * qual, unsigned int pos ) { if ( ! qual ) { return NULL; } return ( pos == 0 )? qual: __getQualifierAt ( qual->next, --pos ); } static CMPIData __getDataQualifierAt ( struct native_qualifier * qual, unsigned int pos, CMPIString ** qualname, CMPIStatus * rc ) { struct native_qualifier * p = __getQualifierAt ( qual, pos ); if ( rc ) CMSetStatus ( rc, ( p )? CMPI_RC_OK: CMPI_RC_ERR_NO_SUCH_PROPERTY ); return __convert2CMPIData ( p, qualname ); } static CMPICount __getQualifierCount ( struct native_qualifier * qual, CMPIStatus * rc ) { CMPICount c = 0; if ( rc ) CMSetStatus ( rc, CMPI_RC_OK ); while ( qual != NULL ) { c++; qual = qual->next; } return c; } static void __release ( struct native_qualifier * qual ) { for ( ; qual; qual = qual->next ) { tool_mm_add ( qual ); tool_mm_add ( qual->name ); native_release_CMPIValue ( qual->type, &qual->value ); } } static struct native_qualifier * __clone ( struct native_qualifier * qual, CMPIStatus * rc ) { struct native_qualifier * result; CMPIStatus tmp; if ( qual == NULL ) { if ( rc ) CMSetStatus ( rc, CMPI_RC_OK ); return NULL; } result = (struct native_qualifier * ) tool_mm_alloc ( TOOL_MM_NO_ADD, sizeof ( struct native_qualifier ) ); result->name = strdup ( qual->name ); result->type = qual->type; result->state = qual->state; result->value = native_clone_CMPIValue ( qual->type, &qual->value, &tmp ); if ( tmp.rc != CMPI_RC_OK ) { result->state = CMPI_nullValue; } result->next = __clone ( qual->next, rc ); return result; } /** * Global function table to access native_qualifier helper functions. */ struct native_qualifierFT qualifierFT = { __addQualifier, __setQualifier, __getDataQualifier, __getDataQualifierAt, __getQualifierCount, __release, __clone }; /****************************************************************************/ /*** Local Variables: ***/ /*** mode: C ***/ /*** c-basic-offset: 8 ***/ /*** End: ***/ Index: client.c =================================================================== RCS file: /cvsroot/sblim/sfcc/client.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- client.c 6 Jun 2005 15:28:28 -0000 1.7 +++ client.c 13 Jun 2005 23:50:46 -0000 1.8 @@ -380,8 +380,9 @@ CMCIConnection *con=cl->connection; UtilStringBuffer *sb=newStringBuffer(2048); char *error; + CMPIString *cn; - addXmlClassnameParam(sb, cop); + cn=cop->ft->getClassName(cop,NULL); con->ft->genRequest(cl,"GetInstance",cop,0,0); addXmlHeader(sb); @@ -396,8 +397,9 @@ addXmlPropertyListParam(sb, properties); - addXmlClassnameParam(sb, cop); - + sb->ft->append3Chars(sb,"<IPARAMVALUE NAME=\"InstanceName\">\n" + "<INSTANCENAME CLASSNAME=\"",(char*)cn->hdl,"\">\n"); + pathToXml(sb, cop); sb->ft->appendChars(sb,"</INSTANCENAME>\n</IPARAMVALUE>\n"); @@ -975,7 +977,6 @@ UtilStringBuffer *sb=newStringBuffer(2048); char *error; - addXmlClassnameParam(sb, cop); con->ft->genRequest(cl,"GetClass",cop,0,0); addXmlHeader(sb); @@ -992,10 +993,6 @@ addXmlClassnameParam(sb, cop); - pathToXml(sb, cop); - - sb->ft->appendChars(sb,"</INSTANCENAME>\n</IPARAMVALUE>\n"); - sb->ft->appendChars(sb,"</IMETHODCALL></SIMPLEREQ>\n</MESSAGE></CIM>"); // fprintf(stderr,"%s\n",sb->ft->getCharPtr(sb)); @@ -1052,7 +1049,7 @@ CMSetStatusWithChars(rc,CMPI_RC_ERR_FAILED,error); return NULL; } - fprintf(stderr,"%s\n",con->mResponse->ft->getCharPtr(con->mResponse)); +// fprintf(stderr,"%s\n",con->mResponse->ft->getCharPtr(con->mResponse)); ResponseHdr rh=scanCimXmlResponse(con->mResponse->ft->getCharPtr(con->mResponse),cop); Index: cimXmlParser.c =================================================================== RCS file: /cvsroot/sblim/sfcc/cimXmlParser.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- cimXmlParser.c 4 May 2005 18:20:08 -0000 1.1 +++ cimXmlParser.c 13 Jun 2005 23:50:46 -0000 1.2 @@ -1079,7 +1079,7 @@ if (next == NULL) { return 0; } - // fprintf(stderr,"--- token: %.32s\n",next); +// fprintf(stderr,"--- token: %.32s\n",next); if (parm->xmb->eTagFound) { parm->xmb->eTagFound = 0; return parm->xmb->etag; Index: cimXmlResp.y =================================================================== RCS file: /cvsroot/sblim/sfcc/cimXmlResp.y,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- cimXmlResp.y 6 Jun 2005 15:28:28 -0000 1.2 +++ cimXmlResp.y 13 Jun 2005 23:50:46 -0000 1.3 @@ -48,6 +48,10 @@ extern int yyerror(char*); extern int yylex (void *lvalp, ParserControl *parm); +extern CMPIConstClass * native_new_CMPIConstClass ( char *cn, CMPIStatus * rc ); +extern int addClassProperty( CMPIConstClass * ccls, char * name, CMPIValue * value, CMPIType type, + CMPIValueState state); + int isBoolean(CMPIData data) { @@ -58,22 +62,6 @@ return -1; } -static void addInstProperty(CMPIInstance **ci, XtokProperty *p) -{ - CMPIValue val; - - if (*ci==NULL) *ci=newCMPIInstance(NULL,NULL); - switch (p->propType) { - case typeProperty_Value: ; - val=str2CMPIValue(p->valueType, p->val.value, NULL); - (*ci)->ft->setProperty(*ci,p->name,&val,p->valueType); - break; - case typeProperty_Reference: ; - case typeProperty_Array: ; - break; - } -} - static void createPath(CMPIObjectPath **op, XtokInstanceName *p) { int i,m; @@ -88,8 +76,6 @@ &val, &type); CMAddKey(*op, p->bindings.keyBindings[i].name, valp, type); } - CMPIString *path=(*op)->ft->toString(*op,NULL); - printf("parh: %s\n",(char*)path->hdl); } static void createClassPath(CMPIObjectPath **op, char *ns, char *cn) @@ -97,6 +83,120 @@ *op = newCMPIObjectPath(NULL, cn, NULL); } +static void setInstProperties(CMPIInstance *ci, XtokProperties *ps) +{ + XtokProperty *np=NULL,*p= ps ? ps->first : NULL; + CMPIValue val; + + while (p) { + switch (p->propType) { + case typeProperty_Value: ; + val=str2CMPIValue(p->valueType, p->val.value, NULL); + ci->ft->setProperty(ci,p->name,&val,p->valueType); + break; + case typeProperty_Reference: ; + case typeProperty_Array: ; + break; + } + np=p->next; + free(p); + p=np; + } + if (ps) ps->first=ps->last=NULL; +} + +static void setClassProperties(CMPIConstClass *cls, XtokProperties *ps) +{ + XtokProperty *np=NULL,*p= ps ? ps->first : NULL; + CMPIValue val; + CMPIValueState state; + + while (p) { + switch (p->propType) { + case typeProperty_Value: + if (p->val.null) state=CMPI_nullValue; + else { + state=0; + val=str2CMPIValue(p->valueType, p->val.value, NULL); + } + addClassProperty(cls,p->name,&val,p->valueType,state); + break; + case typeProperty_Reference: ; + case typeProperty_Array: ; + break; + } + np=p->next; + free(p); + p=np; + } + if (ps) ps->first=ps->last=NULL; +} + +static void addProperty(XtokProperties *ps, XtokProperty *p) +{ + XtokProperty *np; + np=(XtokProperty*)malloc(sizeof(XtokProperty)); + memcpy(np,p,sizeof(XtokProperty)); + np->next=NULL; + if (ps->last) { + ps->last->next=np; + } + else ps->first=np; + ps->last=np; +} + +static void addParamValue(XtokParamValues *vs, XtokParamValue *v) +{ + XtokParamValue *nv; + nv=(XtokParamValue*)malloc(sizeof(XtokParamValue)); + memcpy(nv,v,sizeof(XtokParamValue)); + nv->next=NULL; + if (vs->last) { + vs->last->next=nv; + } + else vs->first=nv; + vs->last=nv; +} + +static void addQualifier(XtokQualifiers *qs, XtokQualifier *q) +{ + XtokQualifier *nq; + nq=(XtokQualifier*)malloc(sizeof(XtokQualifier)); + memcpy(nq,q,sizeof(XtokQualifier)); + nq->next=NULL; + if (qs->last) { + qs->last->next=nq; + } + else qs->first=nq; + qs->last=nq; +} + +static void addMethod(XtokMethods *ms, XtokMethod *m) +{ + XtokMethod *nm; + nm=(XtokMethod*)malloc(sizeof(XtokMethod)); + memcpy(nm,m,sizeof(XtokMethod)); + nm->next=NULL; + if (ms->last) { + ms->last->next=nm; + } + else ms->first=nm; + ms->last=nm; +} + +static void addParam(XtokParams *ps, XtokParam *p) +{ + XtokParam *np; + np=(XtokParam*)malloc(sizeof(XtokParam)); + memcpy(np,p,sizeof(XtokParam)); + np->next=NULL; + if (ps->last) { + ps->last->next=np; + } + else ps->first=np; + ps->last=np; +} + static void setError(void *parm, XtokErrorResp *e) { int err=atoi(e->code); @@ -402,9 +502,17 @@ : /* empty */ | class { + PARM->curClass=native_new_CMPIConstClass($1.className,NULL); + setClassProperties(PARM->curClass,&PARM->properties); + simpleArrayAdd(PARM->respHdr.rvArray,(CMPIValue*)&PARM->curClass,CMPI_class); + PARM->curClass=NULL; } | classes class { + PARM->curClass=native_new_CMPIConstClass($2.className,NULL); + setClassProperties(PARM->curClass,&PARM->properties); + simpleArrayAdd(PARM->respHdr.rvArray,(CMPIValue*)&PARM->curClass,CMPI_class); + PARM->curClass=NULL; } ; @@ -412,12 +520,15 @@ : /* empty */ | instance { + PARM->curInstance=native_new_CMPIInstance(NULL,NULL); setInstNsAndCn(PARM->curInstance,$1.className,PARM->nameSpace); + setInstProperties(PARM->curInstance,&PARM->properties); simpleArrayAdd(PARM->respHdr.rvArray,(CMPIValue*)&PARM->curInstance,CMPI_instance); PARM->curInstance=NULL; } | instances instance { + PARM->curInstance=native_new_CMPIInstance(NULL,NULL); setInstNsAndCn(PARM->curInstance,$2.className,PARM->nameSpace); simpleArrayAdd(PARM->respHdr.rvArray,(CMPIValue*)&PARM->curInstance,CMPI_instance); PARM->curInstance=NULL; @@ -459,6 +570,15 @@ class : XTOK_CLASS classData ZTOK_CLASS { + if (PARM->Qs) + $$.qualifiers=PARM->qualifiers; + else memset(&$$.qualifiers,0,sizeof($$.qualifiers)); + if (PARM->Ps) + $$.properties=PARM->properties; + else memset(&$$.properties,0,sizeof($$.properties)); + if (PARM->Ms) + $$.methods=PARM->methods; + else memset(&$$.methods,0,sizeof($$.methods)); } ; @@ -466,16 +586,31 @@ : /* empty */ {;} | classData qualifier { + PARM->Qs++; + addQualifier(&(PARM->qualifiers),&$2); } | classData property { + PARM->Ps++; + addProperty(&(PARM->properties),&$2); } | classData method { + PARM->Ms++; + addMethod(&(PARM->methods),&$2); } ; method : XTOK_METHOD methodData ZTOK_METHOD { + if (PARM->MQs) + $$.qualifiers=$2.qualifiers; + else memset(&$$.qualifiers,0,sizeof($$.qualifiers)); + if (PARM->MPs) + $$.params=$2.params; + else memset(&$$.params,0,sizeof($$.params)); + PARM->MQs=0; + PARM->MPs=0; + PARM->MPQs=0; } ; @@ -483,9 +618,21 @@ : /* empty */ {;} | methodData qualifier { + if (PARM->MQs==0) + memset(&$$.qualifiers,0,sizeof($$.qualifiers)); + PARM->MQs++; + addQualifier(&($$.qualifiers),&$2); } | methodData XTOK_PARAM parameter ZTOK_PARAM { + if (PARM->MPs==0) + memset(&$$.params,0,sizeof($$.params)); + PARM->MPs++; + if (PARM->MPQs) + $2.qualifiers=$3.qualifiers; + else memset(&$2.qualifiers,0,sizeof($2.qualifiers)); + addParam(&($$.params),&$2); + PARM->MPQs=0; } ; @@ -493,6 +640,10 @@ : /* empty */ {;} | parameter qualifier { + if (PARM->MPQs==0) + memset(&$$.qualifiers,0,sizeof($$.qualifiers)); + PARM->MPQs++; + addQualifier(&($$.qualifiers),&$2); } ; @@ -504,6 +655,12 @@ instance : XTOK_INSTANCE instanceData ZTOK_INSTANCE { + if (PARM->Qs) + $$.qualifiers=PARM->qualifiers; + else memset(&$$.qualifiers,0,sizeof($$.qualifiers)); + if (PARM->Ps) + $$.properties=PARM->properties; + else memset(&$$.properties,0,sizeof($$.properties)); } ; @@ -511,10 +668,13 @@ : /* empty */ {;} | instanceData qualifier { + PARM->Qs++; + addQualifier(&(PARM->qualifiers),&$2); } | instanceData property { - addInstProperty(&(PARM->curInstance),&$2); + PARM->Ps++; + addProperty(&(PARM->properties),&$2); } ; @@ -527,35 +687,51 @@ : XTOK_PROPERTY propertyData ZTOK_PROPERTY { $$.val=$2; - } - | XTOK_PROPERTY ZTOK_PROPERTY - { - $$.val.null=1; - } - | XTOK_PROPERTYARRAY XTOK_VALUEARRAY valueArray ZTOK_VALUEARRAY ZTOK_PROPERTYARRAY + } + | XTOK_PROPERTYREFERENCE propertyData ZTOK_PROPERTYREFERENCE { - $$.val.array=$2; - } - | XTOK_PROPERTYARRAY ZTOK_PROPERTYARRAY + $$.val=$2; + } + | XTOK_PROPERTYARRAY propertyData ZTOK_PROPERTYARRAY { - $$.val.null=1; - } + $$.val=$2; + } ; propertyData - : propertyData qualifier + : /* empty */ {$$.null=1;} + | propertyData qualifier { + addQualifier(&(PARM->qualifiers),&$2); } - | value + | propertyData value { - $$.value=$1.value; + // printf("--- value: %s\n",$1.value); + $$.value=$2.value; + $$.null=0; } - | valueReference + | propertyData valueReference { - $$.ref=$1; + $$.ref=$2; + $$.null=0; + } + | propertyData XTOK_VALUEARRAY valueArray ZTOK_VALUEARRAY + { + // printf("--- valueArray: \n"); + $$.array=$2; + $$.null=0; } ; +//propertyArray +// : XTOK_PROPERTYARRAY ZTOK_PROPERTYARRAY +// { + // printf("--- propertyArray\n"); +// } +//; + + + /* * value @@ -623,7 +799,6 @@ : XTOK_CLASSNAME ZTOK_CLASSNAME { createClassPath(&PARM->curPath, NULL, $$); - printf("className.y: %s %p\n",$$,PARM->curPath); } ; --- NEW FILE: constClass.c --- /*! \file constClass.c \brief Native CMPIConstClass implementation. This is the native CMPIConstClass implementation as used for remote providers. It reflects the well-defined interface of a regular CMPIConstClass, however, it works independently from the management broker. It is part of a native broker implementation that simulates CMPI data types rather than interacting with the entities in a full-grown CIMOM. (C) Copyright IBM Corp. 2003 THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. You can obtain a current copy of the Common Public License from http://oss.software.ibm.com/developerworks/opensource/license-cpl.html \author Adrian Schuur */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "cmcidt.h" #include "cmcift.h" #include "cmcimacs.h" #include "tool.h" #include "native.h" /****************************************************************************/ /****************************************************************************/ static CMPIStatus __ccft_release ( CMPIConstClass * ccls ) { struct native_constClass * cc = (struct native_constClass *) ccls; if ( cc->mem_state == TOOL_MM_NO_ADD ) { cc->mem_state = TOOL_MM_ADD; tool_mm_add ( cc ); tool_mm_add ( cc->classname ); propertyFT.release ( cc->props ); CMReturn ( CMPI_RC_OK ); } CMReturn ( CMPI_RC_ERR_FAILED ); } static CMPIConstClass * __ccft_clone ( CMPIConstClass * ccls, CMPIStatus * rc ) { struct native_constClass * cc = (struct native_constClass *) ccls; struct native_constClass * new = (struct native_constClass *) tool_mm_alloc ( TOOL_MM_NO_ADD, sizeof ( struct native_constClass ) ); new->classname = strdup ( cc->classname ); new->props = propertyFT.clone ( cc->props, rc ); return (CMPIConstClass *) new; } static CMPIString *__ccft_getClassName ( CMPIConstClass * ccls, CMPIStatus * rc ) { struct native_constClass * cc = (struct native_constClass *) ccls; return native_new_CMPIString ( cc->classname, NULL ); } static CMPIData __ccft_getProperty ( CMPIConstClass * ccls, const char * name, CMPIStatus * rc ) { struct native_constClass * cc = (struct native_constClass *) ccls; return propertyFT.getDataProperty ( cc->props, name, rc ); } static CMPIData __ccft_getPropertyAt ( CMPIConstClass * ccls, unsigned int index, CMPIString ** name, CMPIStatus * rc ) { struct native_constClass * cc = (struct native_constClass *) ccls; return propertyFT.getDataPropertyAt ( cc->props, index, name, rc ); } static unsigned int __ccft_getPropertyCount ( CMPIConstClass * ccls, CMPIStatus * rc ) { struct native_constClass * cc = (struct native_constClass *) ccls; return propertyFT.getPropertyCount ( cc->props, rc ); } CMPIConstClass * native_new_CMPIConstClass ( char *cn, CMPIStatus * rc ) { static CMPIConstClassFT ccft = { NATIVE_FT_VERSION, __ccft_release, __ccft_clone, __ccft_getClassName, __ccft_getProperty, __ccft_getPropertyAt, __ccft_getPropertyCount }; static CMPIConstClass cc = { "CMPIConstClass", &ccft }; struct native_constClass * ccls = (struct native_constClass *) tool_mm_alloc ( TOOL_MM_ADD, sizeof ( struct native_constClass ) ); ccls->ccls = cc; ccls->mem_state = TOOL_MM_ADD; ccls->classname = strdup (cn ); return (CMPIConstClass *) ccls; } int addClassProperty( CMPIConstClass * ccls, char * name, CMPIValue * value, CMPIType type, CMPIValueState state) { struct native_constClass * cc = (struct native_constClass *) ccls; if ( propertyFT.setProperty ( cc->props, cc->mem_state, name, type, value ) ) { propertyFT.addProperty ( &cc->props, cc->mem_state, name, type, state, value ); } return ( CMPI_RC_OK ); } /****************************************************************************/ /*** Local Variables: ***/ /*** mode: C ***/ /*** c-basic-offset: 8 ***/ /*** End: ***/ Index: cimXmlParser.h =================================================================== RCS file: /cvsroot/sblim/sfcc/cimXmlParser.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- cimXmlParser.h 4 May 2005 18:20:08 -0000 1.1 +++ cimXmlParser.h 13 Jun 2005 23:50:46 -0000 1.2 @@ -297,6 +297,12 @@ char *nameSpace; CMPIInstance *curInstance; CMPIObjectPath *curPath; + CMPIConstClass *curClass; + XtokProperties properties; + XtokQualifiers qualifiers; + XtokMethods methods; + XtokParamValues paramValues; + int Qs,Ps,Ms,MPs,MQs,MPQs; } ParserControl; extern ResponseHdr scanCimXmlResponse(const char *xmlData, CMPIObjectPath *cop); |