Ejemplo n.º 1
0
void setInstQualifiers(CMPIInstance *ci, XtokQualifiers *qs)
{
   XtokQualifier *nq = NULL,*q = qs ? qs->first : NULL;
   CMPIValue val;
   int rc;
   
   while (q) {
      if (q->type & CMPI_ARRAY) {
               CMPIType type=q->type&~CMPI_ARRAY;
               CMPIArray *arr = newCMPIArray(0, type, NULL);
               int i;
          if (q->data.array.max) {
              for (i = 0; i < q->data.array.next; ++i) {
                  val = str2CMPIValue(type, q->data.array.values[i], NULL);
                  CMSetArrayElementAt(arr, i, &val, type);
                  native_release_CMPIValue(type,&val);
               }
               rc = addInstQualifier(ci, q->name, (CMPIValue*)&arr, q->type);
               native_release_CMPIValue(q->type,(CMPIValue*)&arr);
      }
      }
      else {
         val = str2CMPIValue(q->type, q->data.value.data.value, NULL);
         rc = addInstQualifier(ci, q->name, &val, q->type);
         native_release_CMPIValue( q->type,&val);
      }
      nq = q->next;
      q = nq;
   }
   if (qs) {
      qs->first = qs->last = NULL;
   }
}
Ejemplo n.º 2
0
void setClassProperties(CMPIConstClass *cls, XtokProperties *ps)
{
   XtokProperty *np = NULL,*p = ps ? ps->first : NULL;
   CMPIValue val;
   CMPIArray       *arr = NULL;
   XtokQualifier   *nq,*q;
   XtokQualifiers *qs;
   int rc, n;

      val.uint64=0l;
   while (p) {
      switch (p->propType) {
      case typeProperty_Value:
         addClassProperty(cls, p->name, &val, p->valueType, CMPI_nullValue);
         break;
      case typeProperty_Reference:
         addClassProperty(cls, p->name, &val, CMPI_ref, CMPI_nullValue);
     break;
      case typeProperty_Array:
         val.array = arr;
     addClassProperty(cls, p->name, &val,
                               p->valueType | CMPI_ARRAY, CMPI_nullValue);
         break;
      }

      qs=&p->val.qualifiers;
      q=qs ? qs->first : NULL;  
      n=0;   
      while (q) {
         if (q->type & CMPI_ARRAY) {
            CMPIType type=q->type&~CMPI_ARRAY;
            arr = newCMPIArray(0, type, NULL);
            int i;
            if (q->data.array.max) {
                for (i = 0; i < q->data.array.next; ++i) {
               val = str2CMPIValue(type, q->data.array.values[i], NULL);
               CMSetArrayElementAt(arr, i, &val, type);
               native_release_CMPIValue(type,&val);
            }
            }
            val.array = arr;
            rc = addClassPropertyQualifier(cls, p->name, q->name, &val, q->type); 
            native_release_CMPIValue(q->type,(CMPIValue*)&arr);
         }
         else {
            val = str2CMPIValue(q->type, q->data.value.data.value, NULL);
            rc= addClassPropertyQualifier(cls, p->name, q->name, &val, q->type);
            native_release_CMPIValue(q->type,&val);
         }   
         nq = q->next; 
         q = nq;
      }

      np = p->next;
      p = np;
   }
   if (ps) ps->first = ps->last = NULL;
}
Ejemplo n.º 3
0
void setClassMethods(CMPIConstClass *cls, XtokMethods *ms)
{
   XtokMethod *nm = NULL,*m = ms ? ms->first : NULL;
   CMPIValue      val;
   CMPIArray      *arr = NULL;
   XtokQualifier  *nq,*q;
   XtokQualifiers *qs;
   XtokParam      *np,*p;
   XtokParams     *ps;
   int rc, n;

   val.uint64=0l;
   while (m) {
      addClassMethod(cls, m->name, &val, m->type, CMPI_nullValue);

      qs=&m->qualifiers;
      q=qs ? qs->first : NULL;
      n=0;
      while (q) {
         if (q->type & CMPI_ARRAY) {
            CMPIType type=q->type&~CMPI_ARRAY;
            arr = newCMPIArray(0, type, NULL);
            int i;
            if (q->data.array.max) {
               for (i = 0; i < q->data.array.next; ++i) {
                  val = str2CMPIValue(type, q->data.array.values[i], NULL);
                  CMSetArrayElementAt(arr, i, &val, type);
                  native_release_CMPIValue(type,&val);
               }
            }
            val.array = arr;
            rc = addClassMethodQualifier(cls, m->name, q->name, &val, q->type);
            native_release_CMPIValue(q->type,(CMPIValue*)&arr);
         }
         else {
            val = str2CMPIValue(q->type, q->data.value.data.value, NULL);
            rc= addClassMethodQualifier(cls, m->name, q->name, &val, q->type);
            native_release_CMPIValue(q->type,&val);
         }
         nq = q->next; 
         q = nq;
      }

      ps=&m->params;
      p=ps ? ps->first : NULL;
      n=0;
      while (p) {
         rc= addClassMethodParameter(cls, m->name, p->name, p->type);
         np = p->next; 
         p = np;
      }

      nm = m->next;
      m = nm;
   }
   if (ms) ms->first = ms->last = NULL;
}
Ejemplo n.º 4
0
void setClassQualifiers(CMPIConstClass *cls, XtokQualifiers *qs)
{
   XtokQualifier *nq = NULL,*q = qs ? qs->first : NULL;
   CMPIValue val;
   int rc;
   
   while (q) {
      if (q->type & CMPI_ARRAY) {
               CMPIType type=q->type&~CMPI_ARRAY;
               CMPIArray *arr = newCMPIArray(0, type, NULL);
               int i;
          if (q->data.array.max > 0) {
              for (i = 0; i < q->data.array.next; ++i) {
                   char *valStr = q->data.array.values[i];
                   if (type == CMPI_string || type == CMPI_chars)
                   {
                       char *charsStr = XmlToAsciiStr(valStr);
                       val = str2CMPIValue(type, charsStr, NULL);
                       free (charsStr);
                   }
                   else
                       val = str2CMPIValue(type, valStr, NULL);
                  CMSetArrayElementAt(arr, i, &val, type);
                  native_release_CMPIValue(type,&val);
               }
               rc = addClassQualifier(cls, q->name, (CMPIValue*)&arr, q->type);
               native_release_CMPIValue(q->type,(CMPIValue*)&arr);
      }
      }
      else {
          char *valStr = q->data.value.data.value;
          if (q->type == CMPI_string || q->type == CMPI_chars)
          {
              char *charsStr = XmlToAsciiStr(valStr);
              val = str2CMPIValue(q->type, charsStr, NULL);
              free (charsStr);
          }
          else
              val = str2CMPIValue(q->type, valStr, NULL);
         rc = addClassQualifier(cls, q->name, &val, q->type);
         native_release_CMPIValue( q->type,&val);
      }
      nq = q->next;
      q = nq;
   }
   if (qs) {
      qs->first = qs->last = NULL;
   }
}
Ejemplo n.º 5
0
void setReturnArgs(ParserControl *parm, XtokParamValues *ps)
{
    CMPIValue value;
    XtokParamValue *outParam=NULL;
    CMPIArgs *args = NULL;
   
    /* Process OUT parameters */
    outParam = ps->first;

    if (outParam) { 
        args = newCMPIArgs(NULL);

        while (outParam) {
            value = str2CMPIValue(outParam->type, outParam->data.value.data.value, &outParam->data.valueRef);

            /* Add it to the args list */
            args->ft->addArg ( args, outParam->name, &value, outParam->type);
            native_release_CMPIValue(outParam->type,&value);
            outParam = outParam->next;
        }
        parm->respHdr.outArgs = args;
        /* Note : Freeing of list will be done by
        * parser_heap_term() routine.
        */
    }
}
Ejemplo n.º 6
0
CMPIValue
makeFromEmbeddedObject(XtokValue value, char *ns)
{
  XtokProperty   *p = NULL;
  CMPIValue       val;
  memset(&val, 0, sizeof(CMPIValue));
  CMPIObjectPath *path;
  CMPIStatus rc = {CMPI_RC_OK, NULL};

  if (value.type == typeValue_Instance) {
    CMPIInstance   *inst;
    XtokInstance   *xtokInstance = value.instance;
    path = TrackedCMPIObjectPath(ns, xtokInstance->className, NULL);
    inst = TrackedCMPIInstance(path, NULL);

    for (p = xtokInstance->properties.first; p; p = p->next) {
      if (p->val.val.value) {
        val = str2CMPIValue(p->valueType, p->val.val, &p->val.ref, NULL, &rc);
        CMSetProperty(inst, p->name, &val, p->valueType);
      }
    }
    val.inst = inst;
  } else if (value.type == typeValue_Class) {
    // not yet supported
  }
  return val;
}
Ejemplo n.º 7
0
static void returnValue(ParserControl *parm, parseUnion *stateUnion)
{
	parseUnion lvalp ={0};
	CMPIType  t;
	CMPIValue val;
	CMPIInstance *inst;
	ct = localLex((parseUnion*)&stateUnion->xtokReturnValue, parm);
	if(ct == XTOK_RETVALUE) {
		returnValueData(parm, (parseUnion*)&stateUnion->xtokReturnValue.data);
		if(stateUnion->xtokReturnValue.data.type == CMPI_ref) {
			t = CMPI_ref;
			val = str2CMPIValue(t, NULL, &stateUnion->xtokReturnValue.data.ref);
		}
		else if(stateUnion->xtokReturnValue.data.value.type == typeValue_Instance) {
			t = CMPI_instance;
			inst = native_new_CMPIInstance(NULL,NULL);
			setInstNsAndCn(inst,getNameSpaceChars(parm->requestObjectPath),stateUnion->xtokReturnValue.data.value.data.inst->className);
			setInstProperties(inst, &stateUnion->xtokReturnValue.data.value.data.inst->properties);
			val.inst = inst;
		}
		else {
			t = stateUnion->xtokReturnValue.type;
			if (t == CMPI_null) {
				t = guessType(stateUnion->xtokReturnValue.data.value.data.value);
			}
			val = str2CMPIValue(t, stateUnion->xtokReturnValue.data.value.data.value, NULL);
		}
		simpleArrayAdd(parm->respHdr.rvArray, (CMPIValue*)&val, t);
		ct = localLex((parseUnion*)&stateUnion->xtokReturnValue, parm);
		if(ct == ZTOK_RETVALUE) {
		}
		else {
			parseError("ZTOK_RETVALUE", ct, parm);
		}
	}
	else {
		parseError("XTOK_RETVALUE", ct, parm);
	}
}
Ejemplo n.º 8
0
void setInstProperties(CMPIInstance *ci, XtokProperties *ps)
{
   XtokProperty *np = NULL,*p = ps ? ps->first : NULL;
   CMPIValue val;
   CMPIObjectPath *op;
   CMPIStatus status;
   CMPIType   type = CMPI_null;
   XtokQualifier *nq = NULL,*q;
   XtokQualifiers *qs;
   int rc, n, setq;

   while (p) {
      setq=1;
      switch (p->propType) {
      case typeProperty_Value:
         type = p->valueType;
         if (p->val.value.data.value != NULL && p->val.null==0) {
            if (type == CMPI_string || type == CMPI_chars) {
                char *charsStr = XmlToAsciiStr(p->val.value.data.value);
                val = str2CMPIValue(type, charsStr, NULL);
                free (charsStr);
            }
            else
                val = str2CMPIValue(type, p->val.value.data.value, NULL);
            CMSetProperty(ci, p->name, &val, type);
        native_release_CMPIValue(type, &val);
         }
         else {
            CMSetProperty(ci, p->name, NULL, type);
            setq = 0;
         }
         break;
      case typeProperty_Reference: 
         val=str2CMPIValue(CMPI_ref, NULL, &p->val.ref);
         CMSetProperty(ci, p->name, &val.ref, CMPI_ref);
     CMRelease(val.ref);
         break;
      case typeProperty_Array:
         type = p->valueType;
         if (p->val.array.next > 0) {
            CMPIArray *arr = newCMPIArray(0, type, &status);
            if (p->val.array.max > 0) {
            int i;
               for (i = 0; i < p->val.array.next; ++i)
               {
                   char *valStr = p->val.array.values[i];
                   if (type == CMPI_string || type == CMPI_chars) {
                       char *charsStr = XmlToAsciiStr(valStr);
                       val = str2CMPIValue(type, charsStr, NULL);
                       free (charsStr);
                   }
                   else
                       val = str2CMPIValue(type, valStr, NULL);
                   CMSetArrayElementAt(arr, i, &val, type);
               native_release_CMPIValue(type, &val);
               }
            }
            val.array = arr;
            CMSetProperty(ci, p->name, &val, type | CMPI_ARRAY);
            CMRelease(arr);         /* cloned in property */
         }
         else {
            CMSetProperty(ci, p->name, NULL, p->valueType | CMPI_ARRAY);
            setq = 0;
         }
         break;
      }

      if (setq) {
         qs=&p->val.qualifiers;
         q=qs ? qs->first : NULL;  
         n=0;   
         while (q) {
            if (q->type & CMPI_ARRAY) {
               CMPIArray *arr = NULL;
               arr = newCMPIArray(0, type, NULL);
               type  = q->type & ~CMPI_ARRAY;
               int i;
               if (q->data.array.max) {
                   for (i = 0; i < q->data.array.next; ++i) {
                  val = str2CMPIValue(type, q->data.array.values[i], NULL);
                  CMSetArrayElementAt(arr, i, &val, type);
                  native_release_CMPIValue(type,&val);
               }
               }
               rc = addInstPropertyQualifier(ci, p->name, q->name,
                         (CMPIValue *)&arr, q->type); 
               native_release_CMPIValue(q->type,(CMPIValue*)&arr);
            }
            else {
               val = str2CMPIValue(q->type, q->data.value.data.value, NULL);
               rc= addInstPropertyQualifier(ci, p->name, q->name, &val, q->type);
               native_release_CMPIValue(q->type,&val);
            }   
            nq = q->next; 
            q = nq;
         }
      }

      np = p->next;
      p = np;

   }

   if (ps)
      ps->first = ps->last =  NULL;
}
Ejemplo n.º 9
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;
}