CMPIStatus
InternalProviderModifyInstance(CMPIInstanceMI * mi,
                               const CMPIContext *ctx,
                               const CMPIResult *rslt,
                               const CMPIObjectPath * cop,
                               const CMPIInstance *ci,
                               const char **properties)
{
  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);
  const char    **keyList;

  _SFCB_ENTER(TRACE_INTERNALPROVIDER, "InternalProviderSetInstance");

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

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

  if (properties) {
    keyList = getKeyList(ci->ft->getObjectPath(ci, NULL));
    ci->ft->setPropertyFilter((CMPIInstance *) ci, properties, keyList);
    if (keyList) {
      free(keyList);
    }
  }

  len = getInstanceSerializedSize(ci);
  blob = malloc(len + 64);
  getSerializedInstance(ci, blob);
  addBlob(bnss, cns, key, blob, (int) len);
  free(blob);
  free(key);
  _SFCB_RETURN(st);
}
Esempio n. 2
0
int sfcb_add_instance(class_entry * ie, const char * ns)
{	
	void * blob;
	int len, size;
	CMPIData data;
	class_entry * ce=NULL; //class definition for instance ie
	CMPIObjectPath * path;
	ClInstance * inst;
	CMPIInstance* cmpi_instance = malloc(sizeof(CMPIInstance));
	prop_chain * class_prop;
	prop_chain * inst_props = ie -> class_props;
	
	ce = get_class_def_for_instance(ie);
	if(!ce) {
		//class def not found
		fprintf(stderr,"class definition for %s not found\n",
			ie->class_id);
		return 1;
	}

	path = mofc_getObjectPath(ce, ie, ns);
	//	fprintf(stderr, "add_inst: OP= %s\n", CMGetCharPtr(path->ft->toString(path, NULL)));

    if (ie->instmig)
    	inst = ClInstanceNew(ns, ie->class_id);
    else
    	inst = ClInstanceNewFromMof(ns, ie->class_id);

    while (inst_props) {
		if (sfcb_options & BACKEND_VERBOSE) {
			fprintf(stderr,"add_inst:  adding property %s for instance %s \n", 
			inst_props -> prop_id, ie -> class_id );
		}
		class_prop = check_for_prop(ce, inst_props->prop_id);
		if (!class_prop && opt_reduced) {
		  class_prop = check_for_parent_prop(ce, inst_props->prop_id);
		}
		if (!class_prop) {
		  fprintf(stderr, "bad property name \"%s\" for %s\n", inst_props->prop_id, inst_props->prop_class);
		  return 1;
		}
		data = make_cmpi_data(class_prop->prop_type, class_prop->prop_array, inst_props->prop_value);
		ClInstanceAddProperty(inst, inst_props->prop_id, data);
		inst_props = inst_props->prop_next;
    }

	cmpi_instance->hdl=inst;
 	len=getInstanceSerializedSize(cmpi_instance);
 	blob=malloc(len);
	getSerializedInstance(cmpi_instance,blob);

    if (swapMode) {
		size=((ClInstance *)((CMPIInstance * )blob)->hdl)->hdr.size;
		int offset = len-size;
		inst = swapEntryInstance(blob+offset,&size);
		len = offset + size;
		blob = realloc(blob, len);
		memcpy(blob+offset, inst, size);
		free(inst);
    }
	
	if (addBlob((char*)ns,ie->class_id,normalizeObjectPathChars(path),blob,(int)len)) {
		fprintf(stderr,"could not write instance for class definition %s\n",ie->class_id);
		return 1;
	}
	free(blob);
	return 0;
}
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);
}
Esempio n. 4
0
static CMPIStatus __rft_returnInstance(const CMPIResult * result,
                                       const CMPIInstance * instance)
{
   int size,isInst=isInstance(instance);
   void *ptr;
   NativeResult *r = (NativeResult*) result;
   int releaseInstance=0;
   CMPIStatus st={CMPI_RC_OK,NULL};
   
   _SFCB_ENTER(TRACE_PROVIDERDRV, "__rft_returnInstance");
   
   if (r->qs) {
      int irc;

      if (r->qs->where) {
         r->qs->propSrc.data=(CMPIInstance *)instance;
         irc=r->qs->where->ft->evaluate(r->qs->where,&r->qs->propSrc);
         if (irc==1) {
            if (r->qs->allProps==0) {
               instance=
		       r->qs->ft->cloneAndFilter(r->qs,(CMPIInstance *)instance,CMGetObjectPath(instance, NULL),r->qs->keys);
               releaseInstance=1;
            }     
         }   
         else CMReturn(CMPI_RC_OK);
      }
      else {
         if (r->qs->allProps==0) {
		 instance=r->qs->ft->cloneAndFilter(r->qs,(CMPIInstance *)instance,CMGetObjectPath(instance,NULL), r->qs->keys);
            releaseInstance=1;
         }
      }        
   }

   if (r->legacy) {
      CMPIValue v;
      CMPIStatus rc;
      _SFCB_TRACE(1,("--- Legacy Mode"));
      if(isInst) {
        v.inst = CMClone(instance,NULL);
        memLinkInstance(v.inst);
      }
      else v.inst = (CMPIInstance *) instance;
      rc=returnData(result, &v, CMPI_instance);
      if (releaseInstance) instance->ft->release((CMPIInstance*)instance);
      _SFCB_RETURN(rc);
   }

   if (isInst) {
      size=getInstanceSerializedSize(instance);
      ptr=nextResultBufferPos(r, MSG_SEG_INSTANCE, (unsigned long)size);
      _SFCB_TRACE(1,("--- Moving instance %d",size));
      getSerializedInstance(instance,ptr); /* memcpy inst to ptr */
   }
   else {
      size=getConstClassSerializedSize((CMPIConstClass*)instance);
      ptr=nextResultBufferPos(r, MSG_SEG_CONSTCLASS, (unsigned long)size);
      _SFCB_TRACE(1,("--- Moving class %d",size));
      getSerializedConstClass((CMPIConstClass*)instance,ptr);
   }

   if (releaseInstance) instance->ft->release((CMPIInstance*)instance);
   _SFCB_RETURN(st);
}