Example #1
0
CMPIStatus IndCIMXMLHandlerEnumInstanceNames(CMPIInstanceMI * mi,
                                             const CMPIContext * ctx,
                                             const CMPIResult * rslt,
                                             const CMPIObjectPath * ref)
{
   CMPIStatus st;
   CMPIEnumeration *enm;
   CMPIContext *ctxLocal;

   _SFCB_ENTER(TRACE_INDPROVIDER, "IndCIMXMLHandlerEnumInstanceNames");
   if (interOpNameSpace(ref,&st)!=1) _SFCB_RETURN(st);
   ctxLocal = prepareUpcall((CMPIContext *)ctx);

#ifdef HAVE_OPTIMIZED_ENUMERATION
   CMPIString* cn;
   CMPIObjectPath* refLocal;
   cn = CMGetClassName(ref, &st);

   if (strcasecmp(CMGetCharPtr(cn), "cim_listenerdestination") == 0) {
     enm = _broker->bft->enumerateInstanceNames(_broker, ctxLocal, ref, &st);
     while(enm && enm->ft->hasNext(enm, &st)) {
       CMReturnObjectPath(rslt, (enm->ft->getNext(enm, &st)).value.ref);
     }
     refLocal = CMNewObjectPath(_broker,"root/interop","cim_listenerdestinationcimxml",&st);
     enm = _broker->bft->enumerateInstanceNames(_broker, ctxLocal, refLocal, &st);
     while(enm && enm->ft->hasNext(enm, &st)) {
       CMReturnObjectPath(rslt, (enm->ft->getNext(enm, &st)).value.ref);
     }
     refLocal = CMNewObjectPath(_broker,"root/interop","cim_indicationhandlercimxml",&st);
     enm = _broker->bft->enumerateInstanceNames(_broker, ctxLocal, refLocal, &st);
     while(enm && enm->ft->hasNext(enm, &st)) {
       CMReturnObjectPath(rslt, (enm->ft->getNext(enm, &st)).value.ref);
     }
     CMRelease(refLocal);
   }
   else {
     enm = _broker->bft->enumerateInstanceNames(_broker, ctxLocal, ref, &st);
     while(enm && enm->ft->hasNext(enm, &st)) {
       CMReturnObjectPath(rslt, (enm->ft->getNext(enm, &st)).value.ref);
     }
   }
#else
   enm = _broker->bft->enumerateInstanceNames(_broker, ctxLocal, ref, &st);

   while(enm && enm->ft->hasNext(enm, &st)) {
       CMReturnObjectPath(rslt, (enm->ft->getNext(enm, &st)).value.ref);
   }
#endif

   CMRelease(ctxLocal);
   if(enm) CMRelease(enm);

   _SFCB_RETURN(st);
}
Example #2
0
    static bool _proc(
        Instance* cimple_inst,
        Enum_Instances_Status status,
        void* client_data)
    {
        Data* data = (Data*)client_data;

        if (!cimple_inst)
            return false;

        Destroyer<Instance> cimple_inst_d(cimple_inst);

        // Ignore if an error was already encountered.

        if (data->rc != CMPI_RC_OK)
            return false;

        // Convert to a CMPI object path and deliver:

        CMPIObjectPath* cmpi_op = 0;

        data->rc = make_cmpi_object_path(
            data->broker,
            cimple_inst,
            data->name_space,
            cmpi_op);

        if (data->rc != CMPI_RC_OK)
            return false;

        CMReturnObjectPath(data->result, cmpi_op);
        return true;
    }
CMPIStatus cmpiPerf_TestClassProviderEnumInstanceNames(
    CMPIInstanceMI * mi,
    const CMPIContext * ctx,
    const CMPIResult * rslt,
    const CMPIObjectPath * ref)
{
    CMPIObjectPath  * op = NULL;
    CMPIStatus        rc = {CMPI_RC_OK, NULL};
    unsigned int   index = 0;
    unsigned int numInst = 1;

    //
    // While the instance itself is hard code, the number of instances
    // is determined from an environment variable
    //
    numInst = getNumberOfInstances();

    for (index=0; index < numInst; index++)
    {
        op = _makePath_TestClass( _broker, ctx, ref, index );

        if (op == NULL)
        {
            return rc;
        }

        CMReturnObjectPath( rslt, op );
        CMRelease( op );
    }

    CMReturnDone( rslt );
    return rc;
}
static int
_testCMPIResult(const CMPIResult *rslt)
{
  CMPIStatus      rc = { CMPI_RC_OK, NULL };

  CMPIValue       value;
  CMPIType        type;
  const CMPIObjectPath *objPath = NULL;
  CMPIBoolean     returnDataSuccessful = 0;
  value.uint32 = 10;
  type = CMPI_uint32;
  rc = CMReturnData(rslt, &value, type);
  if (rc.rc == CMPI_RC_OK) {
    returnDataSuccessful = 1;
  }
  objPath = make_ObjectPath(_broker, _Namespace, _ClassName);
  rc = CMReturnObjectPath(rslt, objPath);
  rc = CMReturnDone(rslt);
  rc = CMReturnData(rslt, NULL, type);
  if (rc.rc != CMPI_RC_ERR_INVALID_PARAMETER) {
    return 1;
  }

  return 0;
}
/**
    Enumerate ObjectPaths of Instances serviced by this provider.
*/
CMPIStatus TestInstanceProviderEnumInstanceNames (
    CMPIInstanceMI * mi,
    const CMPIContext * ctx,
    const CMPIResult * rslt,
    const CMPIObjectPath * ref)
{
    CMPIStatus rc = {CMPI_RC_OK, NULL};
    unsigned int j = 0;
    CMPIObjectPath *local;
    CMPIData data;
    /* get the element from array containing created instances. */
    for (j = 0; j < numOfInst; j++)
    {
        /*check for validity of Instance, that its not deleted */
        if(valid[j] == 1)
        {
            /* get element(instance) from array */
            data = CMGetArrayElementAt(clone_arr_ptr, j, &rc);
            /* get object-path of that instance */
            local = CMGetObjectPath(data.value.inst, &rc);
            /* return object-path */
            CMReturnObjectPath(rslt,local);
        }
    }
    CMReturnDone (rslt);
    CMReturn (CMPI_RC_OK);
}
/**
    Create Instance from inst, using object-path op as reference.
*/
CMPIStatus TestInstanceProviderCreateInstance (
    CMPIInstanceMI * mi,
    const CMPIContext * ctx,
    const CMPIResult * rslt,
    const CMPIObjectPath * cop,
    const CMPIInstance * ci)
{
    CMPIStatus rc = { CMPI_RC_OK, NULL };
    CMPIInstance * inst;
    CMPIValue value_inst;
    CMPIData key1,key2, retInst;
    CMPIObjectPath *obp;
    unsigned int j = 0;
    if(ci)
    {
        /* clone the instance to be added to the array */
        inst = CMClone(ci, &rc);
        key1 = CMGetProperty(inst, "Identifier", &rc);
        for (j=0; j < numOfInst ; j++)
        {
            /* check for validity of Instance, that its not deleted */
            if (valid[j] == 1)
            {
                /* get element(instance) from array */
                retInst = CMGetArrayElementAt(clone_arr_ptr, j, &rc);
                /* get object-path of instance */
                obp = CMGetObjectPath(retInst.value.inst, &rc);
                /* get key from this object-path */
                key2 = CMGetKey(obp, "Identifier", &rc);
                /*compare key values.
                  If they match throw exception as two instance with same key
                  properties cannot exists. */
                if(key1.value.uint8 == key2.value.uint8)
                {
		  CMRelease(inst);
                    CMReturn (CMPI_RC_ERR_ALREADY_EXISTS);
                }
            }
        }
        value_inst.inst = inst;
        /* If instance doesnot exists in array add it */
        rc = CMSetArrayElementAt(
            clone_arr_ptr,
            numOfInst,
            &value_inst,
            CMPI_instance);
        valid[numOfInst]=1;
        numOfInst++;
        /* return object-path of instance */
        CMReturnObjectPath(rslt, cop);
        CMReturnDone(rslt);
    }
    else
    {
        CMReturn (CMPI_RC_ERR_NOT_SUPPORTED);
    }
    CMRelease(inst);
    CMReturn (CMPI_RC_OK);
}
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;
}
Example #8
0
static void loopOnChildNames(ClassRegister *cReg, char *cn, CMPIResult * rslt)
{
   CMPIObjectPath *op;
   UtilList *ul = getChildren(cReg,cn);
   char *child;
   if (ul) for (child = (char *) ul->ft->getFirst(ul); child;  child = (char *) ul->ft->getNext(ul)) {
      op=CMNewObjectPath(_broker,NULL,child,NULL);
      CMReturnObjectPath(rslt,op);
      loopOnChildNames(cReg,child,rslt);
   }
}
CMPIStatus Linux_FanProviderEnumInstanceNames( CMPIInstanceMI * mi,
           const CMPIContext * ctx,
           const CMPIResult * rslt,
           const CMPIObjectPath * ref) {
    UNUSED(mi);

    CMPIObjectPath     * op    = NULL;
    CMPIStatus           rc    = {CMPI_RC_OK, NULL};
    struct fanlist * lptr  = NULL;
    struct fanlist * rm    = NULL;

    _OSBASE_TRACE(1,("--- %s CMPI EnumInstanceNames() called",_ClassName));

    if (enum_all_fans(&lptr) != 0 ) {
        CMSetStatusWithChars( _broker, &rc,
                CMPI_RC_ERR_FAILED, "Could not list get fan list." );
        _OSBASE_TRACE(1, ("--- %s CMPI EnumInstanceNames() failed : %s",
                    _ClassName,CMGetCharPtr(rc.msg)));
        return rc;
    }

    // iterate fan list
    for (rm = lptr; lptr && rc.rc == CMPI_RC_OK ; lptr = lptr->next) {
        // method call to create the CMPIInstance object
        op = _makePath_Fan(_broker, ctx, ref, lptr->f, &rc);
        if (op == NULL || rc.rc != CMPI_RC_OK) {
            if (rc.msg != NULL) {
                _OSBASE_TRACE(1, ("--- %s CMPI EnumInstanceNames() failed"
                            ": %s", _ClassName, CMGetCharPtr(rc.msg)));
            }
            CMSetStatusWithChars(_broker, &rc, CMPI_RC_ERR_FAILED,
                    "Transformation from internal structure to CIM"
                    " ObjectPath failed.");
            if (rm) free_fanlist(rm);
            _OSBASE_TRACE(1, ("--- %s CMPI EnumInstanceNames() failed"
                       ": %s", _ClassName, CMGetCharPtr(rc.msg)));
            return rc;
        }else {
            CMReturnObjectPath(rslt, op);
        }
    }
    if (rm) free_fanlist(rm);

    CMReturnDone(rslt);
    _OSBASE_TRACE(1, ("--- %s CMPI EnumInstanceNames() exited", _ClassName));
    return rc;
}
Example #10
0
CMPIStatus CWS_DirectoryEnumInstanceNames( CMPIInstanceMI * mi, 
                       const CMPIContext * ctx, 
                       const CMPIResult * rslt, 
                       const CMPIObjectPath * ref) 

{
   CMPIObjectPath *op;
  CMPIStatus      st = {CMPI_RC_OK,NULL};
  void           *enumhdl;
  CWS_FILE        filebuf;

  if (!silentMode()) fprintf(stderr,"--- CWS_DirectoryEnumInstanceNames() \n");

  enumhdl = CWS_Begin_Enum(CWS_FILEROOT,CWS_TYPE_DIR);

  if (enumhdl == NULL) {
    CMSetStatusWithChars(_broker, &st, CMPI_RC_ERR_FAILED,
             "Could not begin file enumeration");
    return st;
  } else {
    while (CWS_Next_Enum(enumhdl,&filebuf)) {
      /* build object path from file buffer */
      op = makePath(_broker,
            LOCALCLASSNAME,
            CMGetCharsPtr(CMGetNameSpace(ref,NULL),NULL),
            &filebuf);
      if (CMIsNullObject(op)) {
    CMSetStatusWithChars(_broker, &st, CMPI_RC_ERR_FAILED,
                 "Could not construct object path");
    break;
      }
      CMReturnObjectPath(rslt,op);
    }
    CMReturnDone(rslt);
    CWS_End_Enum(enumhdl);
  }

  return st;
}
Example #11
0
    static bool _proc(
        Instance* cimple_inst,
        Enum_References_Status status,
        void* client_data)
    {
        Data* data = (Data*)client_data;

        // Ignore the final call.

        if (!cimple_inst)
            return false;

        Destroyer<Instance> cimple_inst_d(cimple_inst);

        // Ignore errors on prior call.

        if (data->rc != CMPI_RC_OK)
            return false;

        // Filter out non-key properties:

        nullify_non_keys(cimple_inst);

        // Convert to CMPI object path:

        CMPIObjectPath* cmpi_op = 0;

        data->rc = make_cmpi_object_path(
            data->broker, cimple_inst, data->name_space, cmpi_op);

        if (data->rc != CMPI_RC_OK)
            return false;

        // Deliver the instance.

        CMReturnObjectPath(data->result, cmpi_op);

        return true;
    }
CMPIStatus cmpiPerf_TestClassProviderCreateInstance(
    CMPIInstanceMI * mi,
    const CMPIContext * ctx,
    const CMPIResult * rslt,
    const CMPIObjectPath * cop,
    const CMPIInstance * ci)
{
    CMPIObjectPath  * op = NULL;
    CMPIStatus rc = {CMPI_RC_OK, NULL};
    unsigned int numInst = 1;


    numInst = getNumberOfInstances()+1;

    op = _makePath_TestClass( _broker, ctx, cop, numInst );

    CMReturnObjectPath( rslt, op );
    CMReturnDone( rslt );

    setNumberOfInstances(numInst);


    return rc;
}
Example #13
0
/*
Enumerate ObjectPaths of Instances serviced by this provider.
Parameters:
mi - Provider this pointer. 
ctx - Invocation Context. 
rslt - Result data container. 
ref - ObjectPath containing namespace and classname components. 
Returns:
Function return status. The following CMPIrc codes shall be recognized: CMPI_RC_OK Operation successful.
CMPI_RC_ERR_FAILED Unspecific error occurred. CMPI_RC_ERR_NOT_SUPPORTED Operation not supported by this MI. CMPI_RC_ERR_ACCESS_DENIED Not authorized. 
CMPI_RC_ERR_NOT_FOUND Instance not found.
*/
CMPIStatus GK_TestEnumInstanceNames( CMPIInstanceMI * mi, 
           CMPIContext * ctx, 
           CMPIResult * rslt, 
           CMPIObjectPath * ref) { 
	CMPIObjectPath * op = NULL;
	CMPIStatus       rc = {CMPI_RC_OK, NULL};
	
	 

	op = _makePath_GK_Test( ref, &rc );

	if( op == NULL) 	{

		CMSetStatusWithChars(_broker, &rc, CMPI_RC_ERR_FAILED,
						"Couldn't build objectpath");    
		goto exit;
	}
	
	CMReturnObjectPath( rslt, op );
    CMReturnDone( rslt );
	
	exit:
	return rc;
}
Example #14
0
/*!
  Since results from remote providers cannot be sent as CMPIResult directly,
  they are serialized using arrays, which can be transferred to the result
  using this method.

  \param array the source array.
  \param result the destination result.
 */
void socketcomm_array2result ( CMPIArray * array, CONST CMPIResult * result )
{
	TRACE_VERBOSE(("entered function."));

	if ( array != NULL && result != NULL ) {

		CMPICount size = CMGetArrayCount ( array, NULL );
		CMPICount i;

		TRACE_NORMAL(("Transferring %d array elements to CMPIResult.",
			      size));

		for ( i = 0; i < size; i++ ) {

			CMPIData data = CMGetArrayElementAt ( array, i, NULL );

			if ( data.type == CMPI_instance ) {

				TRACE_INFO(("transferring instance."));
				CMReturnInstance ( result, data.value.inst );
			} else if ( data.type == CMPI_ref ) {

				TRACE_INFO(("transferring object path."));
				CMReturnObjectPath ( result, data.value.ref );
			} else {

				TRACE_INFO(("transferring CMPIData."));
				CMReturnData ( result,
					       &data.value,
					       data.type );
			}
		}
	}

	TRACE_VERBOSE(("leaving function."));
}
CMPIStatus
InternalProviderCreateInstance(CMPIInstanceMI * mi,
                               const CMPIContext *ctx,
                               const CMPIResult *rslt,
                               const CMPIObjectPath * cop,
                               const CMPIInstance *ci)
{
  CMPIStatus      st = { CMPI_RC_OK, NULL };
  unsigned long   len;
  void           *blob;
  CMPIString     *cn = CMGetClassName(cop, NULL);
  CMPIString     *ns = CMGetNameSpace(cop, NULL);
  char           *key = normalizeObjectPathCharsDup(cop);
  const char     *nss = ns->ft->getCharPtr(ns, NULL);
  const char     *cns = cn->ft->getCharPtr(cn, NULL);
  const char     *bnss = repositoryNs(nss);

  _SFCB_ENTER(TRACE_INTERNALPROVIDER, "InternalProviderCreateInstance");

  if (testNameSpace(bnss, &st) == 0) {
    free(key);
    _SFCB_RETURN(st);
  }

  CMPIConstClass *cc = getConstClass(nss, cns);
  /*
   * per DSP0004 2.5.2 
   */
  if (cc != NULL && cc->ft->isAbstract(cc) != 0) {
    CMPIStatus      st = { CMPI_RC_ERR_NOT_SUPPORTED, NULL };
    free(key);
    _SFCB_RETURN(st);
  }

  if (existingBlob(bnss, cns, key)) {
    CMPIStatus      st = { CMPI_RC_ERR_ALREADY_EXISTS, NULL };
    free(key);
    _SFCB_RETURN(st);
  }

  len = getInstanceSerializedSize(ci);
  blob = malloc(len + 64);
  getSerializedInstance(ci, blob);

  if (addBlob(bnss, cns, key, blob, (int) len)) {
    CMPIStatus      st = { CMPI_RC_ERR_FAILED, NULL };
    st.msg =
        sfcb_native_new_CMPIString("Unable to write to repository", NULL,
                                   0);
    free(blob);
    free(key);
    _SFCB_RETURN(st);
  }
  free(blob);

  if (rslt) {
    CMReturnObjectPath(rslt, cop);
  }

  free(key);
  _SFCB_RETURN(st);
}
CMPIStatus
InternalProviderEnumInstanceNames(CMPIInstanceMI * mi,
                                  const CMPIContext *ctx,
                                  const CMPIResult *rslt,
                                  const CMPIObjectPath * ref)
{
  CMPIStatus      st = { CMPI_RC_OK, NULL };
  CMPIStatus      sti = { CMPI_RC_OK, NULL };
  BlobIndex      *bi;
  CMPIString     *cn = CMGetClassName(ref, NULL);
  CMPIString     *ns = CMGetNameSpace(ref, NULL);
  CMPIObjectPath *cop;
  const char     *nss = ns->ft->getCharPtr(ns, NULL);
  const char     *cns = cn->ft->getCharPtr(cn, NULL);
  const char     *bnss = repositoryNs(nss);
  size_t          ekl;
  int             i,
                  ac = 0;
  char            copKey[8192] = "";
  char           *kp;
  CMPIArgs       *in,
                 *out;
  CMPIObjectPath *op;
  CMPIArray      *ar;
  CMPIData        rv;

  _SFCB_ENTER(TRACE_INTERNALPROVIDER, "InternalProviderEnumInstanceNames");
  _SFCB_TRACE(1, ("%s %s", nss, cns));

  in = CMNewArgs(Broker, NULL);
  out = CMNewArgs(Broker, NULL);
  CMAddArg(in, "class", cns, CMPI_chars);
  op = CMNewObjectPath(Broker, bnss, "$ClassProvider$", &sti);
  rv = CBInvokeMethod(Broker, ctx, op, "getallchildren", in, out, &sti);
  ar = CMGetArg(out, "children", NULL).value.array;
  if (ar)
    ac = CMGetArrayCount(ar, NULL);

  for (i = 0; cns; i++) {
    if ((bi = _getIndex(bnss, cns)) != NULL) {
      if (ipGetFirst(bi, NULL, &kp, &ekl)) {
        while (1) {
          strcpy(copKey, nss);
          strcat(copKey, ":");
          strcat(copKey, cns);
          strcat(copKey, ".");
          strncat(copKey, kp, ekl);

          cop = getObjectPath(copKey, NULL);
          if (cop)
            CMReturnObjectPath(rslt, cop);
          else {
            CMPIStatus      st = { CMPI_RC_ERR_FAILED, NULL };
            return st;
          }
          if (bi->next < bi->dSize && ipGetNext(bi, NULL, &kp, &ekl)) {
            continue;
          }
          break;
        }
      }
      freeBlobIndex(&bi, 1);
    }
    if (i < ac)
      cns = (char *) CMGetArrayElementAt(ar, i, NULL).value.string->hdl;
    else
      cns = NULL;
  }
  _SFCB_RETURN(st);
}
int assoc_ServiceProcess( const CMPIBroker * _broker,
			  const CMPIContext * ctx,
			  const CMPIResult * rslt,
			  const CMPIObjectPath * ref,
			  int assocType,
			  CMPIStatus * rc )
{
  CMPIString     * sourceClass = NULL;
  CMPIData         serviceName;
  CMPIObjectPath * op          = NULL;
  CMPIObjectPath * rop         = NULL;
  CMPIInstance   * rci         = NULL;
  CMPIInstance   * sci         = NULL;
  LXS_Handle       lhdl;
  LXS_Service    * lxssvc      = NULL;
  int              i           = 0;

  _OSBASE_TRACE(2,("--- assoc_ServiceProcess() called"));

  /* check if source instance does exist */
  sci = CBGetInstance(_broker, ctx, ref, NULL, rc);
  if( sci == NULL ) {
    if( rc->rc == CMPI_RC_ERR_FAILED ) {
      CMSetStatusWithChars( _broker, rc,
			    CMPI_RC_ERR_FAILED, "GetInstance of source object failed.");
    }
    if( rc->rc == CMPI_RC_ERR_NOT_FOUND ) {
      CMSetStatusWithChars( _broker, rc,
			    CMPI_RC_ERR_NOT_FOUND, "Source object not found.");
    }
    _OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg)));
    return -1;
  }

  sourceClass = CMGetClassName(ref, rc);
  if (CMGetCharPtr(sourceClass) == NULL) {
    CMSetStatusWithChars( _broker, rc,
			  CMPI_RC_ERR_FAILED, "Could not get source class name.");
    _OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg)));
    return -1;
  }

  /* source class is Linux_UnixProcess; target class is Linux_Service */
  if( strcasecmp(CMGetCharPtr(sourceClass),_RefRightClass) == 0 ) {
    /* NOT_SUPPORTED - association is uni-directional */
  }
  /* source class is Linux_Service; target class is Linux_UnixProcess */
  else if( strcasecmp(CMGetCharPtr(sourceClass),_RefLeftClass) == 0 ) {

    serviceName = CMGetKey(ref, "Name", rc);
    if( serviceName.value.string == NULL ) { 
      CMSetStatusWithChars( _broker, rc, 
			    CMPI_RC_ERR_FAILED, "Could not get Name of Service" ); 
      _OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg)));
      return -1;
    }
    lhdl=LXS_InitFiltered(CMGetCharPtr(serviceName.value.string));
    if (lhdl==NULL) {
      _OSBASE_TRACE(2,("--- assoc_ServiceProcess() exited : Could not find associated Service."));
      return 0;
    }
    lxssvc=LXS_Next(lhdl);
    if (lxssvc==NULL) {
      _OSBASE_TRACE(2,("--- assoc_ServiceProcess() exited : Could not find associated Service."));
      return 0;
    }

    /* get the list of associated processe */
    for (i=0;lxssvc->svProcesses[i]!=NULL;i++) {

      op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(ref,rc)), 
			    _RefRightClass, rc );
      if( CMIsNullObject(op) ) { 
	CMSetStatusWithChars( _broker, rc, 
			      CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." ); 
	_OSBASE_TRACE(2,("--- assoc_ServiceProcess() failed : %s",CMGetCharPtr(rc->msg)));
	return -1;
      }
      CMAddKey(op, "CSCreationClassName", CSCreationClassName, CMPI_chars);
      CMAddKey(op, "CSName", get_system_name(), CMPI_chars);
      CMAddKey(op, "OSCreationClassName", OSCreationClassName, CMPI_chars);
      CMAddKey(op, "OSName", get_os_name(), CMPI_chars);
      CMAddKey(op, "CreationClassName", _RefRightClass, CMPI_chars);
      CMAddKey(op, "Handle", lxssvc->svProcesses[i], CMPI_chars);

      if (assocType&ATYPE_ASSOC) {
	/* the process (name) */
	if (assocType&ATYPE_NAME) {
	  CMReturnObjectPath(rslt, op); 
	}
	else {	  
	  rci = CBGetInstance(_broker, ctx, op, NULL, rc);
	  if(rci==NULL) { return -1; }
	  CMReturnInstance( rslt, rci );
	}
      } 
      else {
	/* the reference object (name) */
	if (assocType&ATYPE_NAME) {
	  rop = _makePath_ServiceProcess(_broker, ref, op, rc);
	  CMReturnObjectPath(rslt, rop); 
	} 
	else {
	  rci = _makeInst_ServiceProcess(_broker, ref, op, rc);
	  CMReturnInstance( rslt, rci );
	}
      }

    }
    LXS_Term(lhdl);
  }

  _OSBASE_TRACE(2,("--- assoc_ServiceProcess() exited"));
  return 0;
}
CMPIStatus
getRefs(const CMPIContext *ctx, const CMPIResult *rslt,
        const CMPIObjectPath * cop,
        const char *assocClass,
        const char *resultClass,
        const char *role,
        const char *resultRole,
        const char **propertyList, int associatorFunction)
{
  UtilList       *refs = UtilFactory->newList(memAddUtilList, memUnlinkEncObj);
  char           *ns = (char *) CMGetNameSpace(cop, NULL)->hdl;
  CMPIStatus      st = { CMPI_RC_OK, NULL };

  _SFCB_ENTER(TRACE_INTERNALPROVIDER, "getRefs");

  if (assocClass != NULL) {
    CMPIObjectPath *path;
    if (assocForName(ns, assocClass, role, resultRole) == NULL) {
      /*
       * for an unknown class we just return nothing 
       */
      _SFCB_RETURN(st);
    }
    path = CMNewObjectPath(_broker, ns, assocClass, NULL);
    SafeInternalProviderAddEnumInstances(refs, NULL, ctx, path,
                                         propertyList, &st, 1);
  }

  else {
    CMPIData        rv;
    CMPIObjectPath *op =
        CMNewObjectPath(Broker, ns, "$ClassProvider$", &st);
    CMPIArgs       *in = CMNewArgs(Broker, NULL);
    CMPIArgs       *out = CMNewArgs(Broker, NULL);
    rv = CBInvokeMethod(Broker, ctx, op, "getassocs", in, out, &st);
    if (out) {
      int             i,
                      m;
      CMPIArray      *ar = CMGetArg(out, "assocs", &st).value.array;
      for (i = 0, m = CMGetArrayCount(ar, NULL); i < m; i++) {
        char           *name =
            CMGetArrayElementAt(ar, i, NULL).value.string->hdl;
        if (name) {
          CMPIObjectPath *cop = CMNewObjectPath(Broker, ns, name, NULL);
          if (cop) {
            SafeInternalProviderAddEnumInstances(refs, NULL, ctx, cop,
                                                 propertyList, &st, 1);
          }
        }
        _SFCB_TRACE(1, ("--- assoc %s", name));
      }
    }
  }

  if (role) {
    // filter out the associations not matching the role property
    CMPIInstance   *ci;
    UtilStringBuffer *pn = normalizeObjectPathStrBuf(cop);
    for (ci = refs->ft->getFirst(refs); ci; ci = refs->ft->getNext(refs)) {
      CMPIData        data = CMGetProperty(ci, role, NULL);
      if ((data.state & CMPI_notFound) ||
          data.type != CMPI_ref ||
          objectPathEquals(pn, data.value.ref, NULL, 0) == 0) {
        refs->ft->removeCurrent(refs);
      }
    }
    pn->ft->release(pn);
  }

  else {
    // filter out associations not referencing pathName
    CMPIInstance   *ci;
    int             matched,
                    i,
                    m;
    UtilStringBuffer *pn = normalizeObjectPathStrBuf(cop);
    for (ci = refs->ft->getFirst(refs); ci; ci = refs->ft->getNext(refs)) {
      for (matched = 0, i = 0, m = CMGetPropertyCount(ci, NULL); i < m;
           i++) {
        CMPIData        data = CMGetPropertyAt(ci, i, NULL, NULL);
        if (data.type == CMPI_ref
            && objectPathEquals(pn, data.value.ref, NULL, 0)) {
          matched = 1;
          break;
        }
      }
      if (matched == 0)
        refs->ft->removeCurrent(refs);
    }
    pn->ft->release(pn);
  }

  if (associatorFunction == REF) {
    CMPIInstance   *ci;
    for (ci = refs->ft->getFirst(refs); ci; ci = refs->ft->getNext(refs)) {
      CMReturnInstance(rslt, ci);
    }
    refs->ft->release(refs);
    _SFCB_RETURN(st);
  }

  else if (associatorFunction == REF_NAME) {
    CMPIInstance   *ci;
    for (ci = refs->ft->getFirst(refs); ci; ci = refs->ft->getNext(refs)) {
      CMPIObjectPath *ref = CMGetObjectPath(ci, NULL);
      CMReturnObjectPath(rslt, ref);
    }
    refs->ft->release(refs);
    _SFCB_RETURN(st);
  }

  else {
    // Use hashtable to avoid dup'd associators
    CMPIInstance   *ci;
    UtilHashTable  *assocs =
        UtilFactory->newHashTable(61, UtilHashTable_charKey);
    UtilStringBuffer *pn = normalizeObjectPathStrBuf(cop);
    for (ci = refs->ft->getFirst(refs); ci; ci = refs->ft->getNext(refs)) {
      // Q: for ASSOC_NAME we should not require the
      // object exist if we go by the book, should we?
      // The current approach retrieves the instances
      // via the CIMOM handle
      if (resultRole) {
        CMPIData        data = CMGetProperty(ci, resultRole, NULL);
        UtilStringBuffer *an = NULL;
        if ((data.state & CMPI_notFound) == 0 && data.type == CMPI_ref &&
            objectPathEquals(pn, data.value.ref, &an, 0) == 0) {
          if (resultClass == NULL
              || CMClassPathIsA(Broker, data.value.ref, resultClass,
                                NULL)) {
            CMPIInstance   *aci =
                CBGetInstance(Broker, ctx, data.value.ref, propertyList,
                              &st);
            assocs->ft->put(assocs, an->ft->getCharPtr(an), aci);
          }
        }
      }

      else {
        // must loop over the properties to find ref instances
        int             i,
                        m;
        for (i = 0, m = CMGetPropertyCount(ci, NULL); i < m; i++) {
          CMPIData        data = CMGetPropertyAt(ci, i, NULL, NULL);
          if (data.type == CMPI_ref) {
            CMPIObjectPath *ref = data.value.ref;
            CMPIString     *tns = CMGetNameSpace(ref, NULL);
            if (tns == NULL || tns->hdl == NULL)
              CMSetNameSpace(ref, ns);
            UtilStringBuffer *an = NULL;
            if (objectPathEquals(pn, ref, &an, 0) == 0) {

              if (resultClass == NULL
                  || CMClassPathIsA(Broker, ref, resultClass, NULL)) {
                CMPIInstance   *aci =
                    CBGetInstance(Broker, ctx, ref, propertyList, &st);
                if (aci)
                  assocs->ft->put(assocs, an->ft->getCharPtr(an), aci);
              }
            }
          }
        }
      }
    }

    {
      HashTableIterator *it;
      char           *an;
      CMPIInstance   *aci;
      for (it =
           assocs->ft->getFirst(assocs, (void **) &an, (void **) &aci); it;
           it =
           assocs->ft->getNext(assocs, it, (void **) &an,
                               (void **) &aci)) {
        if (associatorFunction == ASSOC)
          CMReturnInstance(rslt, aci);
        else {
          CMPIObjectPath *op = CMGetObjectPath(aci, NULL);
          CMReturnObjectPath(rslt, op);
        }
      }
    }

    refs->ft->release(refs);
    assocs->ft->release(assocs);
    pn->ft->release(pn);
    _SFCB_RETURN(st);

  }
}
Example #19
0
static CMPIStatus
ClassProviderEnumClassNames(CMPIClassMI * mi,
                            const CMPIContext *ctx,
                            const CMPIResult *rslt, const CMPIObjectPath * ref)
{
  CMPIStatus      st = { CMPI_RC_OK, NULL };
  char           *cn = NULL;
  CMPIFlags       flgs = 0;
  CMPIString     *cni;
  ClassBase      *cb;
  Iterator        it;
  char           *key;
  int             rc,
                  n;
  ClassRecord    *crec;
  CMPIObjectPath *op;
  ClassRegister  *cReg;
  char           *ns;

  _SFCB_ENTER(TRACE_PROVIDERS, "ClassProviderEnumClassNames");

  cReg = getNsReg(ref, &rc);
  if (cReg == NULL) {
    CMPIStatus      st = { CMPI_RC_ERR_INVALID_NAMESPACE, NULL };
    _SFCB_RETURN(st);
  }

  ns = (char *) CMGetNameSpace(ref, NULL)->hdl;
  flgs = ctx->ft->getEntry(ctx, CMPIInvocationFlags, NULL).value.uint32;
  cni = ref->ft->getClassName(ref, NULL);
  if (cni) {
    cn = (char *) cni->hdl;
    if (cn && *cn == 0)
      cn = NULL;
  }
  cb = (ClassBase *) cReg->hdl;

  cReg->ft->wLock(cReg);

  if (cn && strcasecmp(cn, "$ClassProvider$") == 0)
    cn = NULL;

  if (cn == NULL) {
    n = 0;
    for (it = cReg->ft->getFirstClassRecord(cReg, &key, &crec);
         key && it && crec;
         it = cReg->ft->getNextClassRecord(cReg, it, &key, &crec)) {
      if ((flgs & CMPI_FLAG_DeepInheritance) || crec->parent == NULL) {
        if (((flgs & FL_assocsOnly) == 0)
            || crec->flags & CREC_isAssociation) {
          op = CMNewObjectPath(_broker, ns, key, NULL);
          CMReturnObjectPath(rslt, op);
        }
      }
    }
  }

  else {
    CMPIConstClass *cls = getClass(cReg, cn, NULL);
    if (cls == NULL) {
      st.rc = CMPI_RC_ERR_INVALID_CLASS;
    } else if ((flgs & CMPI_FLAG_DeepInheritance) == 0) {
      UtilList       *ul = getChildren(cReg, cn);
      char           *child;
      if (ul)
        for (child = (char *) ul->ft->getFirst(ul); child;
             child = (char *) ul->ft->getNext(ul)) {
          op = CMNewObjectPath(_broker, ns, child, NULL);
          CMReturnObjectPath(rslt, op);
        }
    } else if (flgs & CMPI_FLAG_DeepInheritance) {
      if (((flgs & FL_assocsOnly) == 0)
          || crec->flags & CREC_isAssociation)
        loopOnChildNames(cReg, cn, rslt);
    }
  }

  cReg->ft->wUnLock(cReg);

  _SFCB_RETURN(st);
}
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;
}
Example #21
0
CMPIStatus TestCMPIBrokerInstanceProviderCreateInstance (CMPIInstanceMI * mi,
    const CMPIContext * ctx,
    const CMPIResult * rslt,
    const CMPIObjectPath * cop,
    const CMPIInstance * ci)
{
    const CMPIString* retNamespace;
    const CMPIString* retClassname;
    CMPIString* type;
    const char* str1;
    const char* str2;
    CMPIStatus rc = { CMPI_RC_OK, NULL };
    CMPIData retData;
    CMPIObjectPath *obj;
    CMPIBoolean bol = 0;

    PROV_LOG_OPEN (_ClassName, _ProviderLocation);
    PROV_LOG("CreateInstance");

    retNamespace = CMGetNameSpace(cop, &rc);
    retClassname = CMGetClassName(cop, &rc);
    str1 = CMGetCharsPtr(retNamespace, &rc);
    str2 = CMGetCharsPtr(retClassname, &rc);
    PROV_LOG("++++Obtained Namespace : (%s) Class (%s)", str1, str2);

    if(ci)
    { 
        /* Test to increase coverage in Broker_Enc.cpp*/
        type = CDToString (_broker, ci, &rc);
        PROV_LOG ("++++ Passing CMPIInstance with CMPI_InstanceOnStack_Ftab "
            "to mbEncToString successes : "
            "(%s)",
            strCMPIStatus (rc));    

        type = CDGetType (_broker, ci, &rc);
        PROV_LOG ("++++ Status of mbEncGetType with input of type CMPIInstance"
            " : (%s) type(%s)",
            strCMPIStatus (rc),
            CMGetCharsPtr(type, NULL));

        bol = CDIsOfType (_broker, ci, "CMPIInstance", &rc);
        if ( bol )
        {
            PROV_LOG ("++++ CDIsOfType for CMPIInstance with "
                "CMPI_InstanceOnStack_Ftab status is (%s) : %d",
                strCMPIStatus (rc),
                bol);
        }

        type = CDToString (_broker, cop, &rc);
        PROV_LOG ("++++ Passing CMPIObjectPath with "
            "CMPI_ObjectPathOnStack_Ftab to mbEncToString successes : (%s)",
            strCMPIStatus (rc));    

        type = CDGetType (_broker, cop, &rc);
        PROV_LOG ("++++ Status of mbEncGetType with input of type "
            "CMPIObjectPath : (%s) type(%s)",
            strCMPIStatus (rc),
            CMGetCharsPtr(type, NULL));

        bol = CDIsOfType (_broker, cop, "CMPIObjectPath", &rc);
        if ( bol )
        {
            PROV_LOG ("++++ CDIsOfType for CMPIObjectPath with "
                "CMPI_ObjectPathOnStack_Ftab status is (%s) : %d",
                strCMPIStatus (rc),
                bol);
        }

        type = CDGetType (_broker, rslt, &rc);
        PROV_LOG ("++++ Status of mbEncGetType with input of type "
            "CMPIResult with CMPI_ResultRefOnStack_Ftab : (%s) type(%s)",
            strCMPIStatus (rc),
            CMGetCharsPtr(type, NULL));

        bol = CDIsOfType (_broker, rslt, "CMPIResult", &rc);
        if ( bol )
        {
            PROV_LOG ("++++ CDIsOfType for CMPIResult with "
                "CMPI_ResultRefOnStack_Ftab status is (%s) : %d",
                strCMPIStatus (rc),
                bol);
        }

        _inst = CMClone(ci, &rc);
        PROV_LOG("++++ Status of CMClone(ci) : (%s)",
            strCMPIStatus(rc));
        CMSetObjectPath (_inst, cop);
        PROV_LOG("++++ Status of CMSetObjectPath(_inst) : (%s)",
            strCMPIStatus(rc));
        _setProperty1(_inst, "*");
        retData = CMGetProperty(_inst, "n64", &rc);
        PROV_LOG("++++ Status of CMGetProperty : (%s)",
            strCMPIStatus(rc));
        PROV_LOG("n64 = %" PEGASUS_64BIT_CONVERSION_WIDTH "u",
            retData.value.uint64);
        retData = CMGetProperty(_inst, "n32", &rc);
        PROV_LOG("++++ Status of CMGetProperty : (%s)",
            strCMPIStatus(rc));
        PROV_LOG("n32 = %d", retData.value.uint32);

        obj = CMGetObjectPath(_inst, &rc);
        PROV_LOG("++++ Status of CMGetObjectPath : (%s)",
            strCMPIStatus(rc));
        retNamespace = CMGetNameSpace(obj, &rc);
        PROV_LOG("++++ Status of CMGetNameSpace : (%s)",
            strCMPIStatus(rc));
        retClassname = CMGetClassName(obj, &rc);
        PROV_LOG("++++ Status of CMGetClassName : (%s)",
            strCMPIStatus(rc));
        str1 = CMGetCharsPtr(retNamespace, &rc);
        PROV_LOG("++++ Status of CMGetCharsPtr : (%s)",
            strCMPIStatus(rc));
        str2 = CMGetCharsPtr(retClassname, &rc);
        PROV_LOG("++++ Status of CMGetCharsPtr : (%s)",
            strCMPIStatus(rc));
        PROV_LOG("++++Namespace (_inst): (%s) Class (*%s)", str1, str2);
        retData = CMGetProperty(_inst, "n64", &rc);
        PROV_LOG("++++ Status of CMGetProperty : (%s)",
            strCMPIStatus(rc));
        PROV_LOG("n64 = %" PEGASUS_64BIT_CONVERSION_WIDTH "u",
            retData.value.uint64);
        PROV_LOG_CLOSE ();

        CMReturnObjectPath(rslt, cop);
        CMReturnDone(rslt);
        CMReturn (CMPI_RC_OK);
    }
    else
    {
        PROV_LOG_CLOSE ();
        CMReturn (CMPI_RC_ERR_NOT_SUPPORTED);
    }
}
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;
}