Exemplo n.º 1
0
CMPIStatus KBase_FromObjectPath(KBase* self, const CMPIObjectPath* cop)
{
    CMPIString* cn;
    CMPIString* ns;
    CMPIStatus st = KSTATUS_INIT;
    CMPICount count;
    CMPICount i;
    KValue* kv;

    if (!self || self->magic != KMAGIC)
        KReturn(ERR_FAILED);

    /* Set namespace */

    if (!(ns = CMGetNameSpace(cop, &st)))
        return st;

    self->ns = ns;

    /* Get classname */

    if (!(cn = CMGetClassName(cop, &st)))
        return st;

    /* For each property */

    count = CMGetKeyCount(cop, &st); 

    if (!KOkay(st))
        return st;

    for (i = 0; i < count; i++)
    {
        CMPIData cd;
        CMPIString* pn = NULL;
        KTag tag;

        /* Get i-th property */

        cd = CMGetKeyAt(cop, i, &pn, &st);

        if (!KOkay(st))
            return st;

        if (!pn)
            KReturn(ERR_FAILED);

        /* Find the given property */

        if ((kv = _find_property(self, KChars(pn), &tag)))
        {
            _set_key_value(kv, tag, &cd);
        }
    }

    KReturn(OK);
}
Exemplo n.º 2
0
CMPIBoolean KMatch(const CMPIObjectPath* cop1, const CMPIObjectPath* cop2)
{
    CMPIStatus st = KSTATUS_INIT;
    CMPICount count1;
    CMPICount count2;
    CMPICount i;

    if (!cop1 || !cop2)
        return 0;

    count1 = CMGetKeyCount(cop1, &st); 

    if (!KOkay(st))
        return 0;

    count2 = CMGetKeyCount(cop2, &st); 

    if (!KOkay(st))
        return 0;

    if (count1 != count2)
        return 0;

    for (i = 0; i < count1; i++)
    {
        CMPIData cd1;
        CMPIData cd2;
        CMPIString* pn;

        cd1 = CMGetKeyAt(cop1, i, &pn, &st);

        if (!KOkay(st) || !pn)
            return 0;

        cd2 = CMGetKey(cop2, KChars(pn), &st);

        if (!KOkay(st))
            return 0;

        if (!_match_key(&cd1, &cd2))
            return 0;
    }

    /* Identicial */
    return 1;
}
Exemplo n.º 3
0
CMPIData KFindKey(
    const CMPIObjectPath* cop, 
    const char* name,
    CMPIStatus* status)
{
    CMPICount count;
    CMPICount i;
    CMPIData cd;

    count = CMGetKeyCount(cop, NULL);

    for (i = 0; i < count; i++)
    {
        CMPIString* pn = NULL;
        CMPIStatus st;

        cd = CMGetKeyAt(cop, i, &pn, &st);

        if (!KOkay(st) || !pn)
        {
            memset(&cd, 0, sizeof(cd));

            if (status)
                CMSetStatus(status, CMPI_RC_ERR_FAILED);

            return cd;
        }

        if (strcasecmp(KChars(pn), name) == 0)
        {
            if (status)
                CMSetStatus(status, CMPI_RC_OK);

            return cd;
        }
    }

    /* Not found! */

    memset(&cd, 0, sizeof(cd));

    if (status)
        CMSetStatus(status, CMPI_RC_ERR_NOT_FOUND);

    return cd;
}
Exemplo n.º 4
0
void print(const CMPIObjectPath* op)
{
    printf("CMPIObjectPath\n");
    printf("{\n");

    printf("    name_space: \"%s\"\n", name_space(op));
    printf("    class_name: \"%s\"\n", class_name(op));
    printf("    host_name: \"%s\"\n", host_name(op));
    printf("    ---\n");

    for (size_t i = 0, n = CMGetKeyCount(op, NULL); i < n; i++)
    {
        CMPIString* name;
        CMPIData data = CMGetKeyAt(op, i, &name, NULL);

        printf("    %s(%s): ", CMGetCharPtr(name), type_name_of(data.type));
        print(data);
        putchar('\n');
    }

    printf("}\n");
}
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;
}