예제 #1
0
CMPIInstance   *makeInstance(const CMPIBroker *broker, const char * classname,
                 const char * Namespace, CWS_FILE *cwsf)
{
  CMPIInstance   *in = NULL;
  CMPIValue       val;
  CMPIObjectPath *op = CMNewObjectPath(broker,
                       (char*)Namespace,
                       (char*)classname,
                       NULL);  CMSetHostname(op,CSName());

  if (!CMIsNullObject(op)) {
    in = CMNewInstance(broker,op,NULL);
    if (!CMIsNullObject(in)) {
      CMSetProperty(in,"CSCreationClassName",CSCreationClassName(),CMPI_chars);
      CMSetProperty(in,"CSName",CSName(),CMPI_chars);
      CMSetProperty(in,"FSCreationClassName",FSCreationClassName(),CMPI_chars);
      CMSetProperty(in,"FSName",FSName(),CMPI_chars);
      CMSetProperty(in,"CreationClassName",classname,CMPI_chars);
      CMSetProperty(in,"Name",cwsf->cws_name,CMPI_chars);
      CMSetProperty(in,"FileSize",(CMPIValue*)&cwsf->cws_size,CMPI_uint64);
#ifndef SIMULATED
/* We don't want this code in the simulated env - time is dynamic
   (diff timezones) and 
   the testing system might using a diff timezone and report failure */
      val.uint64 = cwsf->cws_ctime;
      val.dateTime = CMNewDateTimeFromBinary(broker,val.uint64*1000000,0,NULL);
      CMSetProperty(in,"CreationDate",&val,CMPI_dateTime);
      val.uint64 = cwsf->cws_mtime;
      val.dateTime = CMNewDateTimeFromBinary(broker,val.uint64*1000000,0,NULL);
      CMSetProperty(in,"LastModified",&val,CMPI_dateTime);
      val.uint64 = cwsf->cws_atime;
      val.dateTime = CMNewDateTimeFromBinary(broker,val.uint64*1000000,0,NULL);
      CMSetProperty(in,"LastAccessed",&val,CMPI_dateTime);
#endif
      val.uint64=0L;
      val.boolean=(cwsf->cws_mode & 0400) != 0;
      CMSetProperty(in,"Readable",&val,CMPI_boolean);
      val.boolean=(cwsf->cws_mode & 0200) != 0;
      CMSetProperty(in,"Writeable",&val,CMPI_boolean);
      val.boolean=(cwsf->cws_mode & 0100) != 0;
      CMSetProperty(in,"Executable",&val,CMPI_boolean);
    }
  }
  return in;
}
예제 #2
0
CMPIObjectPath *makePath( const CMPIBroker *broker, const char * classname,
             const char * Namespace, CWS_FILE *cwsf)
{
  CMPIObjectPath *op;
  op = CMNewObjectPath(broker,
               (char*)Namespace,
               (char*)classname,
               NULL);  CMSetHostname(op,CSName());
  if (!CMIsNullObject(op)) {
    CMAddKey(op,"CSCreationClassName",CSCreationClassName(),CMPI_chars);
    CMAddKey(op,"CSName",CSName(),CMPI_chars);
    CMAddKey(op,"FSCreationClassName",FSCreationClassName(),CMPI_chars);
    CMAddKey(op,"FSName",FSName(),CMPI_chars);
    CMAddKey(op,"CreationClassName",classname,CMPI_chars);
    CMAddKey(op,"Name",cwsf->cws_name,CMPI_chars);
  }
  return op;
}
예제 #3
0
CMPIValue      *
getKeyValueTypePtr(char *type, char *value, XtokValueReference * ref,
                   CMPIValue * val, CMPIType *typ, char *scopingNS)
{
  if (type) {
    if (strcasecmp(type, "string") == 0);
    else if (strcasecmp(type, "boolean") == 0) {
      *typ = CMPI_boolean;
      if (strcasecmp(value, "true") == 0)
        val->boolean = 1;
      else
        val->boolean = 0;
      return val;
    } else if (strcasecmp(type, "numeric") == 0) {
      if (value[0] == '+' || value[0] == '-') {
        *typ = CMPI_sint64;
        sscanf(value, "%lld", &val->uint64);
      } else {
        sscanf(value, "%llu", &val->sint64);
        *typ = CMPI_uint64;
      }
      return val;
    } else if (strcasecmp(type, "ref") == 0) {
      CMPIObjectPath *op;
      char           *hn = "",
          *ns = "",
          *cn;
      CMPIType        type;
      CMPIValue       v,
                     *valp;
      int             i,
                      m;
      XtokInstanceName *in;

      switch (ref->type) {
      case typeValRef_InstancePath:
        in = &ref->instancePath.instanceName;
        hn = ref->instancePath.path.host.host;
        ns = ref->instancePath.path.nameSpacePath;
        break;
      case typeValRef_LocalInstancePath:
        in = &ref->localInstancePath.instanceName;
        ns = ref->localInstancePath.path;
        break;
      case typeValRef_InstanceName:
        in = &ref->instanceName;
        ns = scopingNS;
        break;
      default:
        mlogf(M_ERROR, M_SHOW, "%s(%d): unexpected reference type %d %x\n",
              __FILE__, __LINE__, (int) ref->type, (int) ref->type);
        abort();
      }

      cn = in->className;
      op = TrackedCMPIObjectPath(ns, cn, NULL);
      CMSetHostname(op, hn);

      for (i = 0, m = in->bindings.next; i < m; i++) {
        valp = getKeyValueTypePtr(in->bindings.keyBindings[i].type,
                                  in->bindings.keyBindings[i].value,
                                  &in->bindings.keyBindings[i].ref,
                                  &v, &type, scopingNS);
        CMAddKey(op, in->bindings.keyBindings[i].name, valp, type);
      }
      *typ = CMPI_ref;
      val->ref = op;
      return val;
    }
  }

  *typ = CMPI_chars;
  return (CMPIValue *) value;
}
static int
_testCMPIObjectPath()
{
  CMPIStatus      rc = { CMPI_RC_OK, NULL };

  CMPIObjectPath *objPath = NULL;
  CMPIObjectPath *clonedObjPath = NULL;
  CMPIObjectPath *otherObjPath = NULL;
  CMPIObjectPath *fakeObjPath = NULL;

  const char     *hostName = "HOSTNAME";
  const char     *nameSpace = "root/dummy";
  const char     *className = "classname";

  CMPIString     *returnedHostname = NULL;
  CMPIBoolean     equalHostname = 0;
  CMPIString     *returnedNamespace = NULL;
  CMPIBoolean     equalNamespace = 0;
  CMPIString     *returnedClassName;
  CMPIBoolean     equalClassName = 0;
  CMPIString     *returnedObjectPath;
  CMPIBoolean     cloneSuccessful = 0;
  CMPIBoolean     getKeySuccessful = 0;
  CMPIBoolean     getKeyCountSuccessful = 0;
  CMPIBoolean     getKeyAtSuccessful = 0;
  const char     *objectPath1 = NULL;
  const char     *objectPath2 = NULL;
  CMPIData        data;
  CMPIValue       value;
  unsigned int    keyCount = 0;
  objPath = make_ObjectPath(_broker, _Namespace, _ClassName);
  rc = CMSetHostname(objPath, hostName);
  returnedHostname = CMGetHostname(objPath, &rc);
  if (strcmp(hostName, CMGetCharsPtr(returnedHostname, &rc)) == 0) {
    equalHostname = 1;
  }
  rc = CMSetNameSpace(objPath, nameSpace);
  returnedNamespace = CMGetNameSpace(objPath, &rc);
  if (strcmp(nameSpace, CMGetCharsPtr(returnedNamespace, &rc)) == 0) {
    equalNamespace = 1;
  }
  rc = CMSetClassName(objPath, className);
  returnedClassName = CMGetClassName(objPath, &rc);
  if (strcmp(className, CMGetCharsPtr(returnedClassName, &rc)) == 0) {
    equalClassName = 1;
  }
  otherObjPath = make_ObjectPath(_broker, _Namespace, _ClassName);
  returnedNamespace = CMGetNameSpace(otherObjPath, &rc);
  rc = CMSetNameSpaceFromObjectPath(otherObjPath, objPath);
  returnedNamespace = CMGetNameSpace(otherObjPath, &rc);
  if (strcmp(nameSpace, CMGetCharsPtr(returnedNamespace, &rc)) == 0) {
    equalNamespace = 1;
  }
  returnedHostname = CMGetHostname(otherObjPath, &rc);
  rc = CMSetHostAndNameSpaceFromObjectPath(otherObjPath, objPath);
  returnedHostname = CMGetHostname(otherObjPath, &rc);
  if (strcmp(hostName, CMGetCharsPtr(returnedHostname, &rc)) == 0) {
    equalHostname = 1;
  }
  returnedObjectPath = CMObjectPathToString(objPath, &rc);
  objectPath1 = CMGetCharsPtr(returnedObjectPath, &rc);
  clonedObjPath = objPath->ft->clone(objPath, &rc);
  returnedObjectPath = CMObjectPathToString(clonedObjPath, &rc);
  rc = clonedObjPath->ft->release(clonedObjPath);
  objectPath2 = CMGetCharsPtr(returnedObjectPath, &rc);
  if (strcmp(objectPath1, objectPath2) == 0) {
    cloneSuccessful = 1;
  } else {
    cloneSuccessful = 0;
  }
  fakeObjPath = CMNewObjectPath(_broker, "root#cimv2",
                                "Sample_Instance", &rc);
  rc = CMAddKey(fakeObjPath, "ElementName",
                (CMPIValue *) "Fake", CMPI_chars);
  rc = CMAddKey(otherObjPath, "ElementName1",
                (CMPIValue *) "otherObjPath", CMPI_chars);
  data = CMGetKey(fakeObjPath, "ElementName", &rc);
  if (strcmp(CMGetCharsPtr(data.value.string, &rc), "Fake") == 0) {
    getKeySuccessful = 1;
  }
  keyCount = CMGetKeyCount(fakeObjPath, &rc);
  if (keyCount == 1) {
    getKeyCountSuccessful = 1;
  }
  data = CMGetKeyAt(fakeObjPath, 0, NULL, &rc);
  if (rc.rc == 0) {
    getKeyAtSuccessful = 1;
  }
  value.uint16 = 67;
  rc = CMAddKey(fakeObjPath, "Numeric_key_unsigned",
                (CMPIValue *) & value, CMPI_uint16);
  data = CMGetKey(fakeObjPath, "Numeric_key_unsigned", &rc);
  value.sint16 = -67;
  rc = CMAddKey(fakeObjPath, "Numeric_key_signed",
                (CMPIValue *) & value, CMPI_sint16);
  data = CMGetKey(fakeObjPath, "Numeric_key_signed", &rc);
  value.boolean = 1;
  rc = CMAddKey(fakeObjPath, "Boolean_key",
                (CMPIValue *) & value, CMPI_boolean);
  data = CMGetKey(fakeObjPath, "Boolean_key", &rc);
  CMGetKeyAt(objPath, 500, NULL, &rc);
  if (rc.rc != CMPI_RC_ERR_NO_SUCH_PROPERTY) {
    return 1;
  }
  rc = objPath->ft->release(objPath);
  rc = fakeObjPath->ft->release(fakeObjPath);
  return 0;
}