static int
_testCMPIEnumeration(const CMPIContext *ctx)
{
  CMPIStatus      rc = { CMPI_RC_OK, NULL };
  CMPIEnumeration *enum_ptr = NULL;
  CMPIData        data;
  unsigned int    initCount = 0;
  CMPIObjectPath *objPath = NULL;
  CMPIArray      *arr_ptr = NULL;
  CMPICount       returnedArraySize;
  void           *eptr;
  objPath = make_ObjectPath(_broker, _Namespace, _PersonClass);
  enum_ptr = CBEnumInstances(_broker, ctx, objPath, NULL, &rc);
  if (enum_ptr == NULL) {
    return 1;
  }

  arr_ptr = CMToArray(enum_ptr, &rc);
  if (arr_ptr == NULL) {
    return 1;
  }

  returnedArraySize = CMGetArrayCount(arr_ptr, &rc);
  while (CMHasNext(enum_ptr, &rc)) {
    data = CMGetNext(enum_ptr, &rc);
    if (data.type != CMPI_instance) {
      return 1;
    }
    initCount++;
  }

  eptr = enum_ptr->hdl;
  enum_ptr->hdl = NULL;

  CMToArray(enum_ptr, &rc);
  if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) {
    return 1;
  }

  CMGetNext(enum_ptr, &rc);
  if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) {
    return 1;
  }

  CMHasNext(enum_ptr, &rc);
  if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) {
    return 1;
  }
  enum_ptr->hdl = eptr;
  rc = CMRelease(enum_ptr);
  if (rc.rc != CMPI_RC_OK) {
    return 1;
  }

  return 0;
}
CMPIStatus TestCMPIAssociationProviderAssociatorNames(
    CMPIAssociationMI* mi,
    const CMPIContext* ctx,
    const CMPIResult* rslt,
    const CMPIObjectPath* ref,
    const char* _RefLeftClass,
    const char* _RefRightClass,
    const char* role,
    const char* resultRole)
{
    CMPIObjectPath* op = NULL;
    CMPIObjectPath* rop = NULL;
    CMPIEnumeration* en = NULL;
    CMPIData data ;

    CMPIStatus rc = { CMPI_RC_OK, NULL };

    PROV_LOG_OPEN (_ClassName, _ProviderLocation);
    PROV_LOG ("\n\n********************* %s CMPI AssociatorNames() called",
        _ClassName);

    /* get object path of the target class */
    op = get_assoc_targetClass_ObjectPath(
        _broker,
        ref,
        _RefLeftClass,
        _RefRightClass,
        &rc);

    PROV_LOG (" New Object Path [%s]",
        CMGetCharsPtr (CMGetNameSpace (ref, &rc),NULL));

    /* create new object path of association */
    rop = CMNewObjectPath(
        _broker,
        CMGetCharsPtr(CMGetNameSpace(ref,&rc),NULL),
        _ClassName,
        &rc );

    /* upcall to CIMOM; call enumInstanceNames() of the target class */
    en = CBEnumInstanceNames( _broker, ctx, op, &rc);

    /* as long as object path entries are found in the enumeration */
    while( CMHasNext( en, &rc) )
    {
        /* get the object path */
        data = CMGetNext(en, &rc);

        /* and return the target class object path as result of the
         * associatorNames() call
        */
        CMReturnObjectPath( rslt, data.value.ref );
    }
    PROV_LOG ("\n\n********************* %s CMPI AssociatorNames() exited",
        _ClassName);
    PROV_LOG_CLOSE ();
    return rc;
}
CMPIStatus TestCMPIAssociationProviderAssociators(
    CMPIAssociationMI* mi,
    const CMPIContext* ctx,
    const CMPIResult* rslt,
    const CMPIObjectPath* ref,
    const char* _RefLeftClass,
    const char* _RefRightClass,
    const char* role,
    const char* resultRole,
    const char** properties)
{
    CMPIObjectPath * op = NULL;
    CMPIEnumeration * en = NULL;
    CMPIData data ;
    CMPIStatus rc = { CMPI_RC_OK, NULL };

    CMPIString * sourceClass = NULL;

    PROV_LOG_OPEN (_ClassName, _ProviderLocation);
    PROV_LOG ("\n\n********************* %s CMPI Associators() called",
        _ClassName);

    sourceClass = CMGetClassName(ref,&rc);

    /* get object path of the target class */
    op = get_assoc_targetClass_ObjectPath(
        _broker,
        ref,
        _RefLeftClass,
        _RefRightClass,
        &rc);

    sourceClass = CMGetClassName(op,&rc);
    PROV_LOG(" target class: %s ",CMGetCharsPtr(sourceClass,NULL));

    PROV_LOG (" New Object Path [%s]",
                CMGetCharsPtr (CMGetNameSpace (ref, &rc),NULL));

    /* Call to Associators */
    /* upcall to CIMOM; call enumInstances() of the target class */
    en = CBEnumInstances( _broker, ctx, op, NULL, &rc);

    /* as long as instance entries are found in the enumeration */
    while( CMHasNext( en, &rc) )
    {
        /* get the instance */
        data = CMGetNext( en, &rc);

        /* and return the target class instance as result of the
         * associators() call
        */
        CMReturnInstance( rslt, data.value.inst );
    }
    PROV_LOG ("\n\n********************* %s CMPI Associators exited",
        _ClassName);
    PROV_LOG_CLOSE ();
    return rc;
}
Esempio n. 4
0
CMPIStatus
TestAssociationProviderAssociators(CMPIAssociationMI * mi,
                                   const CMPIContext *ctx,
                                   const CMPIResult *rslt,
                                   const CMPIObjectPath * ref,
                                   const char *_RefLeftClass,
                                   const char *_RefRightClass,
                                   const char *role,
                                   const char *resultRole,
                                   const char **properties)
{
  CMPIObjectPath *op = NULL;
  CMPIEnumeration *en = NULL;
  CMPIData        data;
  CMPIStatus      rc = { CMPI_RC_OK, NULL };

  CMPIString     *sourceClass = NULL;

  sourceClass = CMGetClassName(ref, &rc);

  /*
   * get object path of the target class 
   */
  op = get_assoc_targetClass_ObjectPath(_broker,
                                        ref,
                                        _RefLeftClass,
                                        _RefRightClass, &rc);

  sourceClass = CMGetClassName(op, &rc);

  /*
   * Call to Associators 
   */
  /*
   * upcall to CIMOM; call enumInstances() of the target class 
   */
  en = CBEnumInstances(_broker, ctx, op, NULL, &rc);

  /*
   * as long as instance entries are found in the enumeration 
   */
  if (!rc.rc)
    while (CMHasNext(en, &rc)) {
      /*
       * get the instance 
       */
      data = CMGetNext(en, &rc);

      /*
       * and return the target class instance as result of the
       * associators() call 
       */
      CMReturnInstance(rslt, data.value.inst);
    }
  return rc;
}
Esempio n. 5
0
int
qualiEnum2xml(CMPIEnumeration *enm, UtilStringBuffer * sb)
{
  CMPIQualifierDecl *q;

  _SFCB_ENTER(TRACE_CIMXMLPROC, "qualiEnum2xml");
  while (CMHasNext(enm, NULL)) {
    q = CMGetNext(enm, NULL).value.dataPtr.ptr;
    qualifierDeclaration2xml(q, sb);
  }
  _SFCB_RETURN(0);
}
Esempio n. 6
0
int
enum2xml(CMPIEnumeration *enm, UtilStringBuffer * sb, CMPIType type,
         int xmlAs, unsigned int flags)
{
  CMPIObjectPath *cop;
  CMPIInstance   *ci;
  CMPIConstClass *cl;

  _SFCB_ENTER(TRACE_CIMXMLPROC, "enum2xml");

  while (CMHasNext(enm, NULL)) {
    if (type == CMPI_ref) {
      cop = CMGetNext(enm, NULL).value.ref;
      if (xmlAs == XML_asClassName)
        className2xml(cop, sb);
      else if (xmlAs == XML_asObjectPath) {
        SFCB_APPENDCHARS_BLOCK(sb, "<OBJECTPATH>\n");
        SFCB_APPENDCHARS_BLOCK(sb, "<INSTANCEPATH>\n");
        nsPath2xml(cop, sb);
        instanceName2xml(cop, sb);
        SFCB_APPENDCHARS_BLOCK(sb, "</INSTANCEPATH>\n");
        SFCB_APPENDCHARS_BLOCK(sb, "</OBJECTPATH>\n");
      } else
        instanceName2xml(cop, sb);
    } else if (type == CMPI_class) {
      cl = (CMPIConstClass *) CMGetNext(enm, NULL).value.inst;
      cls2xml(cl, sb, flags);
    } else if (type == CMPI_instance) {
      ci = CMGetNext(enm, NULL).value.inst;
      cop = CMGetObjectPath(ci, NULL);
      if (xmlAs == XML_asObj) {
        SFCB_APPENDCHARS_BLOCK(sb, "<VALUE.OBJECTWITHPATH>\n");
        SFCB_APPENDCHARS_BLOCK(sb, "<INSTANCEPATH>\n");
        nsPath2xml(cop, sb);
      } else
        SFCB_APPENDCHARS_BLOCK(sb, "<VALUE.NAMEDINSTANCE>\n");
      instanceName2xml(cop, sb);
      if (xmlAs == XML_asObj)
        SFCB_APPENDCHARS_BLOCK(sb, "</INSTANCEPATH>\n");
      instance2xml(ci, sb, flags);
      if (xmlAs == XML_asObj)
        SFCB_APPENDCHARS_BLOCK(sb, "</VALUE.OBJECTWITHPATH>\n");
      else
        SFCB_APPENDCHARS_BLOCK(sb, "</VALUE.NAMEDINSTANCE>\n");
      cop->ft->release(cop);
    }
  }

  _SFCB_RETURN(0);
}
Esempio n. 7
0
CMPIStatus KDefaultGetInstance( 
    const CMPIBroker* mb,
    CMPIInstanceMI* mi,
    const CMPIContext* cc,
    const CMPIResult* cr,
    const CMPIObjectPath* cop,
    const char** properties)
{
#if defined(DIRECT_CALL)

    static CMPIResultFT _ft =
    {
        CMPICurrentVersion,
        _DefaultGI_release,
        _DefaultGI_clone,
        _DefaultGI_returnData,
        _DefaultGI_returnInstance,
        _DefaultGI_returnObjectPath,
        _DefaultGI_returnDone,
        _DefaultGI_returnError
    };
    DefaultGI_Result result;
    DefaultGI_Handle handle;
    CMPIStatus st;

    handle.result = cr;
    handle.cop = cop;
    handle.found = 0;

    result.hdl = (void*)&handle;
    result.ft = &_ft;

    st = (*mi->ft->enumerateInstances)(
        mi, cc, (CMPIResult*)(void*)&result, cop, NULL);

    if (!st.rc)
        return st;

    if (!handle.found)
    {
        KReturn(ERR_NOT_FOUND);
    }

    KReturn(OK);

#else /* defined(DIRECT_CALL) */

    CMPIEnumeration* e;
    CMPIStatus st;
    CMPIObjectPath* ccop;

    /* Create an object path with just the class from cop */

    ccop = CMNewObjectPath(mb, KNameSpace(cop), KClassName(cop), &st);

    if (!ccop)
        KReturn(ERR_FAILED);

    /* Enumerate all instances of this class */

    if (!(e = mb->bft->enumerateInstances(mb, cc, ccop, properties, &st)))
        KReturn(ERR_FAILED);

    while (CMHasNext(e, &st))
    {
        CMPIData cd;
        CMPIObjectPath* tcop;

        cd = CMGetNext(e, &st);

        if (st.rc || cd.type != CMPI_instance || (cd.state & CMPI_nullValue))
            KReturn(ERR_FAILED);

        if (!(tcop = CMGetObjectPath(cd.value.inst, &st)))
            KReturn(ERR_FAILED);

        if (KMatch(tcop, cop))
        {
            CMReturnInstance(cr, cd.value.inst);
            KReturn(OK);
        }
    }

    KReturn(ERR_NOT_FOUND);

#endif /* !defined(DIRECT_CALL) */
}
CMPIStatus
TestAssociationProviderReferenceNames(CMPIAssociationMI * mi,
                                      const CMPIContext *ctx,
                                      const CMPIResult *rslt,
                                      const CMPIObjectPath * ref,
                                      const char *resultClass,
                                      const char *role)
{
  CMPIInstance   *ci = NULL;
  CMPIObjectPath *op = NULL;
  CMPIObjectPath *rop = NULL;
  CMPIObjectPath *cop = NULL;
  CMPIEnumeration *en = NULL;
  CMPIData        data;

  const char     *targetName = NULL;
  const char     *_thisClassName;
  const char     *_RefLeftClass = NULL;
  const char     *_RefRightClass = NULL;

  CMPIStatus      rc = { CMPI_RC_OK, NULL };
  _thisClassName = _ClassName;

  /*
   * get object path of the target class 
   */
  op = get_assoc_targetClass_ObjectPath(_broker,
                                        ref,
                                        _RefLeftClass,
                                        _RefRightClass, &rc);

  /*
   * check for a failure in creating the object path
   */
  if (rc.rc != CMPI_RC_OK)
    return rc;

  /*
   * the target class does not belong to us so just return CMPI_RC_OK
   */
  if (!op) {
    CMSetStatusWithChars( _broker, &rc, CMPI_RC_OK, NULL );
    return rc;
  }

  /*
   * create new object path of association 
   */
  rop = CMNewObjectPath(_broker,
                        CMGetCharsPtr(CMGetNameSpace(ref, &rc), NULL),
                        _thisClassName, &rc);

  /*
   * upcall to CIMOM; call enumInstanceNames() of the target class 
   */
  en = CBEnumInstanceNames(_broker, ctx, op, &rc);

  /*
   * as long as object path entries are found in the enumeration 
   */
  if (!rc.rc)
    while (CMHasNext(en, &rc)) {
      /*
       * get the object path 
       */
      data = CMGetNext(en, &rc);

      /*
       * create new instance of the association 
       */
      ci = CMNewInstance(_broker, rop, &rc);

      /*
       * get name of the target class 
       */
      targetName = get_assoc_targetClass_Name(_broker,
                                              ref,
                                              _RefLeftClass,
                                              _RefRightClass, &rc);

      /*
       * set the properties of the association instance depending on the
       * constellation of the source class (parameter ref) and the target
       * class (see targetName) 
       */

      if (strcmp(targetName, "CMPI_TEST_Person") == 0) {
        CMSetProperty(ci,
                      "model", (CMPIValue *) & (data.value.ref), CMPI_ref);
        CMSetProperty(ci, "driver", (CMPIValue *) & (ref), CMPI_ref);
      } else if (strcmp(targetName, "CMPI_TEST_Vehicle") == 0) {
        CMSetProperty(ci,
                      "model", (CMPIValue *) & (data.value.ref), CMPI_ref);
        CMSetProperty(ci, "driver", (CMPIValue *) & (ref), CMPI_ref);
      }

      /*
       * get object path of association instance 
       */
      cop = CMGetObjectPath(ci, &rc);

      /*
       * set namespace in object path of association 
       */
      CMSetNameSpace(cop, CMGetCharsPtr(CMGetNameSpace(ref, &rc), NULL));

      /*
       * and return the association object path as result of the
       * referenceNames() call 
       */
      CMReturnObjectPath(rslt, cop);
    }

  return rc;
}
CMPIStatus
TestAssociationProviderAssociatorNames(CMPIAssociationMI * mi,
                                       const CMPIContext *ctx,
                                       const CMPIResult *rslt,
                                       const CMPIObjectPath * ref,
                                       const char *_RefLeftClass,
                                       const char *_RefRightClass,
                                       const char *role,
                                       const char *resultRole)
{
  CMPIObjectPath *op = NULL;
  CMPIObjectPath *rop = NULL;
  CMPIEnumeration *en = NULL;
  CMPIData        data;

  CMPIStatus      rc = { CMPI_RC_OK, NULL };

  /*
   * get object path of the target class 
   */
  op = get_assoc_targetClass_ObjectPath(_broker,
                                        ref,
                                        _RefLeftClass,
                                        _RefRightClass, &rc);

  /*
   * check for a failure in creating the object path
   */
  if (rc.rc != CMPI_RC_OK)
    return rc;

  /*
   * the target class does not belong to us so just return CMPI_RC_OK
   */
  if (!op) {
    CMSetStatusWithChars( _broker, &rc, CMPI_RC_OK, NULL );
    return rc;
  }

  /*
   * create new object path of association 
   */
  rop = CMNewObjectPath(_broker,
                        CMGetCharsPtr(CMGetNameSpace(ref, &rc), NULL),
                        _ClassName, &rc);

  /*
   * upcall to CIMOM; call enumInstanceNames() of the target class 
   */
  en = CBEnumInstanceNames(_broker, ctx, op, &rc);

  /*
   * as long as object path entries are found in the enumeration 
   */
  if (!rc.rc)
    while (CMHasNext(en, &rc)) {
      /*
       * get the object path 
       */
      data = CMGetNext(en, &rc);

      /*
       * and return the target class object path as result of the
       * associatorNames() call 
       */
      CMReturnObjectPath(rslt, data.value.ref);
    }
  return rc;
}
CMPIStatus TestCMPIAssociationProviderReferences(
    CMPIAssociationMI * mi,
    const CMPIContext * ctx,
    const CMPIResult * rslt,
    const CMPIObjectPath * ref,
    const char *resultClass,
    const char *role ,
    const char** properties)
{
    CMPIInstance * ci = NULL;
    CMPIObjectPath * op = NULL;
    CMPIObjectPath * rop = NULL;
    CMPIEnumeration * en = NULL;
    CMPIData data ;

    const char * targetName = NULL;
    char * _thisClassName;
    char * _RefLeftClass = NULL;
    char * _RefRightClass = NULL;

    CMPIStatus rc = {CMPI_RC_OK, NULL};

    _thisClassName=_ClassName;

    PROV_LOG_OPEN (_thisClassName, _ProviderLocation);
    PROV_LOG ("\n\n********************* %s CMPI References() called",
        _thisClassName);

    /* get object path of the target class */
    op = get_assoc_targetClass_ObjectPath(
        _broker,
        ref,
        _RefLeftClass,
        _RefRightClass,
        &rc);

    PROV_LOG (" New Object Path [%s]",
        CMGetCharsPtr (CMGetNameSpace (ref, &rc),NULL));

    /* create new object path of association */
    rop = CMNewObjectPath(
        _broker,
        CMGetCharsPtr(CMGetNameSpace(ref,&rc),NULL),
        _thisClassName,
        &rc );

    /* upcall to CIMOM; call enumInstanceNames() of the target class */
    en = CBEnumInstanceNames( _broker, ctx, op, &rc);

    /* as long as object path entries are found in the enumeration */
    while( CMHasNext( en, &rc) )
    {
        /* get the object path */
        data = CMGetNext( en, &rc);
        {
            /* create new instance of the association */
            ci = CMNewInstance( _broker, rop, &rc);

            /* get name of the target class */
            targetName = get_assoc_targetClass_Name(
                _broker,
                ref,
                _RefLeftClass,
                _RefRightClass,
                &rc);

            /* set the properties of the association instance depending on the
             * constellation of the source class (parameter ref) and the target
             * class (see targetName)
            */
            if(strcmp (targetName, "CMPI_TEST_Person")== 0)
            {
                CMSetProperty(
                    ci,
                    "model",
                    (CMPIValue*)&(data.value.ref),
                    CMPI_ref );
                CMSetProperty( ci, "driver", (CMPIValue*)&(ref), CMPI_ref );
            }
            else if( strcmp( targetName,"CMPI_TEST_Vehicle") == 0 )
            {
                CMSetProperty(
                    ci,
                    "model",
                    (CMPIValue*)&(data.value.ref),
                    CMPI_ref );
                CMSetProperty( ci, "driver", (CMPIValue*)&(ref), CMPI_ref );
            }

            CMReturnInstance( rslt, ci );
        }
    }
    PROV_LOG ("\n\n********************* %s CMPI References() exited",
        _thisClassName);
    PROV_LOG_CLOSE ();

    return rc;
}