Ejemplo n.º 1
0
void createPath(CMPIObjectPath **op, XtokInstanceName *p)
{
   int i;
   CMPIValue val,*valp;
   CMPIType type;
   XtokKeyBinding *b;

   *op = newCMPIObjectPath(NULL, p->className, NULL);
   for (b = p->bindings.first; b; b = b->next) {
      valp = getKeyValueTypePtr(b->type,
                              b->val.keyValue.value,
                              &b->val.ref,
                              &val, &type);
      CMAddKey(*op, b->name, valp, type);
      if (type == CMPI_ref) {
    CMRelease(valp->ref);
      }
   }
}
Ejemplo n.º 2
0
CMPIValue
str2CMPIValue(CMPIType type, XtokValue val, XtokValueReference * ref,
              char *ns, CMPIStatus *status)
{
  CMPIValue       value;
  CMPIType        t = 0;
  CMPIStatus rc = {CMPI_RC_OK, NULL};

  if (type == 0) {
    type = guessType(val.value);
  }

  if (type & CMPI_ARRAY) {
    /*
     * array type received -- needs special handling 
     */
    int             i,
                    max;
    CMPIValue       v;
    XtokValueArray *arr = (XtokValueArray *) ref;
    XtokValueRefArray *refarr = (XtokValueRefArray *) arr;
    max = arr->next;
    if ((type & CMPI_ref) == CMPI_ref) {
      t = CMPI_ref;
    } else if (type & ~CMPI_ARRAY) {
      t = type & ~CMPI_ARRAY;
    } else {
      /*
       * the guess type can go wrong 
       */
      if (max > 0) {
        t = guessType(arr->values[0].value);
      }
    }
    /*
     * build an array by looping thru the elements 
     */
    value.array = TrackedCMPIArray(max, t, NULL);
    if (value.array != NULL) {
      for (i = 0; i < max; i++) {
        v = str2CMPIValue(t, arr->values[i], refarr->values + i, ns, &rc);
        CMSetArrayElementAt(value.array, i, &v, t);
      }
      return value;
    }
  }

  /* Feature 75543 - set and return status->rc on failures */
  switch (type) {
  case CMPI_char16:
    value.char16 = *val.value;
    break;
  case CMPI_string:
    value.string = sfcb_native_new_CMPIString(val.value, NULL, 0);
    break;
  case CMPI_sint64:
    if (invalid_int(val.value, type))
       status->rc = CMPI_RC_ERR_INVALID_PARAMETER;
    else sscanf(val.value, "%lld", &value.sint64);
    break;
  case CMPI_uint64:
    if (invalid_uint(val.value, type))
       status->rc = CMPI_RC_ERR_INVALID_PARAMETER;
    else sscanf(val.value, "%llu", &value.uint64);
    break;
  case CMPI_sint32:
    if (invalid_int(val.value, type))
       status->rc = CMPI_RC_ERR_INVALID_PARAMETER;
    else sscanf(val.value, "%d", &value.sint32);
    break;
  case CMPI_uint32:
    if (invalid_uint(val.value, type))
       status->rc = CMPI_RC_ERR_INVALID_PARAMETER;
    else sscanf(val.value, "%u", &value.uint32);
    break;
  case CMPI_sint16:
    if (invalid_int(val.value, type))
       status->rc = CMPI_RC_ERR_INVALID_PARAMETER;
    else sscanf(val.value, "%hd", &value.sint16);
    break;
  case CMPI_uint16:
    if (invalid_uint(val.value, type))
       status->rc = CMPI_RC_ERR_INVALID_PARAMETER;
    else sscanf(val.value, "%hu", &value.uint16);
    break;
  case CMPI_uint8:
    if (invalid_uint(val.value, type))
       status->rc = CMPI_RC_ERR_INVALID_PARAMETER;
    else {
       sscanf(val.value, "%u", &value.uint32);
       value.uint8 = value.uint32;
    }
    break;
  case CMPI_sint8:
    if (invalid_int(val.value, type))
       status->rc = CMPI_RC_ERR_INVALID_PARAMETER;
    else {
       sscanf(val.value, "%d", &value.sint32);
       value.sint8 = value.sint32;
    }
    break;
  case CMPI_boolean:
    if (invalid_boolean(val.value, type))
       status->rc = CMPI_RC_ERR_INVALID_PARAMETER;
    else {
       value.boolean = strcasecmp(val.value, "false");
       if (value.boolean)
         value.boolean = 1;
    }
    break;
  case CMPI_real32:
    if (invalid_real(val.value, type))
       status->rc = CMPI_RC_ERR_INVALID_PARAMETER;
    else sscanf(val.value, "%f", &value.real32);
    break;
  case CMPI_real64:
    if (invalid_real(val.value, type))
       status->rc = CMPI_RC_ERR_INVALID_PARAMETER;
    else sscanf(val.value, "%lf", &value.real64);
    break;
  case CMPI_dateTime:
    value.dateTime =
        sfcb_native_new_CMPIDateTime_fromChars(val.value, NULL);
    break;
  case CMPI_ref:
    getKeyValueTypePtr("ref", NULL, ref, &value, &t, ns);
    break;
  case CMPI_instance:
    value = makeFromEmbeddedObject(val, ns);
    break;
  default:
    mlogf(M_ERROR, M_SHOW, "%s(%d): invalid value %d-%p\n", __FILE__,
          __LINE__, (int) type, val);
    abort();
  }
  return value;
}
Ejemplo n.º 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;
}