Example #1
0
int
args2xml(CMPIArgs * args, UtilStringBuffer * sb)
{
  int             i,
                  m;

  _SFCB_ENTER(TRACE_CIMXMLPROC, "args2xml");

  if (args == NULL)
    _SFCB_RETURN(0);

  m = CMGetArgCount(args, NULL);
  if (m == 0)
    _SFCB_RETURN(0);

  for (i = 0; i < m; i++) {
    CMPIString     *name;
    CMPIData        data;
    data = CMGetArgAt(args, i, &name, NULL);

    DATA2XML(&data, args, name, NULL, "<PARAMVALUE NAME=\"",
             "</PARAMVALUE>\n", sb, NULL, 1, 1);

    if ((data.type & (CMPI_ENC | CMPI_ARRAY)) && data.value.inst) {
      // don't get confused using generic release 
      data.value.inst->ft->release(data.value.inst);
    }
    CMRelease(name);
  }

  _SFCB_RETURN(0);
}
Example #2
0
void socketcomm_copy_args ( CMPIArgs * src, CMPIArgs * dst )
{
	unsigned int i,arg_count;

	TRACE_NORMAL(("Copying CMPIArgs."));

	arg_count = CMGetArgCount ( src, NULL );

	TRACE_INFO(("arg count: %d", arg_count ));

	for ( i = 0; i < arg_count; i++ ) {

		CMPIString * argName;
		CMPIData data = CMGetArgAt ( src, i, &argName, NULL );

		TRACE_INFO(("arg:\nname: %s\ntype: 0x%x\nstate: 0x%x.",
			    CMGetCharsPtr ( argName, NULL ),
			    data.type, data.state ));

		if ( data.state & CMPI_nullValue ) {
			CMAddArg ( dst,
				   CMGetCharsPtr ( argName, NULL ),
				   NULL,
				   CMPI_null );
		} else CMAddArg ( dst,
				  CMGetCharsPtr ( argName, NULL ),
				  &data.value,
				  data.type );
	}
}
Example #3
0
CMPIStatus KBase_FromArgs(
    KBase* self, 
    const CMPIArgs* ca, 
    CMPIBoolean in,
    CMPIBoolean out)
{
    CMPIStatus st = KSTATUS_INIT;
    CMPICount count;
    CMPICount i;
    KValue* kv;

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

    /* For each arg */

    count = CMGetArgCount(ca, &st); 

    if (!KOkay(st))
        return st;

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

        /* Get i-th property */

        cd = CMGetArgAt(ca, i, &name, &st);

        if (!KOkay(st))
            return st;

        if (!name)
            KReturn(ERR_FAILED);

        /* Find the given property */

        if ((kv = _find_property(self, KChars(name), &tag)))
        {
            if (in && !(tag & KTAG_IN))
                continue;

            if (out && !(tag & KTAG_OUT))
                continue;

            _set_value(kv, tag, &cd);
        }
    }

    KReturn(OK);
}
static int
_testCMPIArgs()
{
  CMPIStatus      rc = { CMPI_RC_OK, NULL };

  CMPIArgs       *args = NULL;
  CMPIArgs       *clonedArgs = NULL;
  CMPIUint32      count = 0;
  CMPIType        type = CMPI_uint32;
  char           *arg1 = "arg1";
  char           *arg2 = "arg2";
  CMPIValue       value;
  CMPIData        data;
  CMPIData        clonedData;
  CMPIBoolean     cloneSuccessful = 0;
  CMPIBoolean     getArgCountSuccessful = 0;
  args = CMNewArgs(_broker, &rc);
  value.uint32 = 10;
  rc = CMAddArg(args, arg1, &value, type);
  count = CMGetArgCount(args, &rc);
  if (count == 1) {
    getArgCountSuccessful = 1;
  }
  value.uint32 = 20;
  rc = CMAddArg(args, arg2, &value, type);
  count = CMGetArgCount(args, &rc);
  if (count == 2) {
    getArgCountSuccessful = 1;
  }
  data = CMGetArg(args, arg2, &rc);
  rc = CMAddArg(args, arg1, &value, type);
  clonedArgs = args->ft->clone(args, &rc);
  clonedData = CMGetArg(clonedArgs, arg2, &rc);
  rc = clonedArgs->ft->release(clonedArgs);
  if (data.value.uint32 == clonedData.value.uint32) {
    cloneSuccessful = 1;
  }
  rc = args->ft->release(args);
  return 0;
}
    CMPIUint32 oper_rc = 1;

    char *result = NULL;


    PROV_LOG_OPEN (_ClassName, _ProviderLocation);

    PROV_LOG ("--- %s CMPI InvokeMethod() called", _ClassName);

    class = CMGetClassName (ref, &rc);

    PROV_LOG ("InvokeMethod: checking for correct classname [%s]",
        CMGetCharsPtr (class,NULL));

    PROV_LOG ("Calling CMGetArgCount");
    arg_cnt = CMGetArgCount (in, &rc);
    PROV_LOG ("++++ (%s)", strCMPIStatus (rc));

    PROV_LOG ("InvokeMethod: We have %d arguments for operation [%s]: ",
        arg_cnt,
        methodName);

    if (arg_cnt > 0)
    {
        PROV_LOG ("Calling CMGetArgAt");
        for (index = 0; index < arg_cnt; index++)
        {
            data = CMGetArgAt (in, index, &argName, &rc);
            if (data.type == CMPI_uint32)
            {
                PROV_LOG ("#%d: %s (uint32), value: %d",
/******************************************************************************
 * Provider export function
 * Execute an extrinsic method on the specified CIM instance.
 *****************************************************************************/
static CMPIStatus xen_resource_invoke_method(
    CMPIMethodMI * self,            /* [in] Handle to this provider (i.e. 'self') */
    const CMPIBroker *broker,       /* [in] CMPI Factory services */
    const CMPIContext * context,    /* [in] Additional context info, if any */
    const CMPIResult * results,     /* [out] Results of this operation */
    const CMPIObjectPath * reference, /* [in] Contains the CIM namespace, classname and desired object path */
    const char * methodname,        /* [in] Name of the method to apply against the reference object */
    const CMPIArgs * argsin,        /* [in] Method input arguments */
    CMPIArgs * argsout)             /* [in] Method output arguments */
{
    CMPIStatus status = {CMPI_RC_OK, NULL};      /* Return status of CIM operations. */
    char * nameSpace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
    unsigned long rc = 0;
    CMPIData argdata;
    xen_utils_session * session = NULL;
    
    _SBLIM_ENTER("InvokeMethod");
    _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("--- self=\"%s\"", self->ft->miName));
    _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("--- methodname=\"%s\"", methodname));
    _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("--- namespace=\"%s\"", nameSpace));

    struct xen_call_context *ctx = NULL;
    if(!xen_utils_get_call_context(context, &ctx, &status)){
         goto Exit;
    }

    if (!xen_utils_validate_session(&session, ctx)) {
        CMSetStatusWithChars(broker, &status, 
            CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to Xen");
        goto Exit;
    }
    
    int argcount = CMGetArgCount(argsin, NULL);
    _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("--- argsin=%d", argcount));
    
    argdata = CMGetKey(reference, "Name", &status);
    if((status.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) {
        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 
                     ("Couldnt find the Virtual System Migration Service to invoke method on"));
        goto Exit;
    }
    /* Check that the method has the correct number of arguments. */
    if(strcmp(methodname, "MigrateVirtualSystemToHost") == 0) {
        rc = MigrateVirtualSystem(broker, context, argsin, argsout, session, true, false, &status);
        //CMPIObjectPath* job_instance_op = NULL;
        //CMAddArg(argsout, "Job", (CMPIValue *)&job_instance_op, CMPI_ref);
    }
    else if(strcmp(methodname, "MigrateVirtualSystemToSystem") == 0) {
        rc = MigrateVirtualSystem(broker, context, argsin, argsout, session, false, false, &status);
        //CMPIObjectPath* job_instance_op = NULL;
        //CMAddArg(argsout, "Job", (CMPIValue *)&job_instance_op, CMPI_ref);
        //CMPIObjectPath* newcomputersystem_instance_op = NULL;
        //CMAddArg(argsout, "NewComputerSystem", (CMPIValue *)&newcomputersystem_instance_op, CMPI_ref);
    }
    else if(strcmp(methodname, "CheckVirtualSystemIsMigratableToHost") == 0) {
        rc = MigrateVirtualSystem(broker, context, argsin, argsout, session, true, true, &status);
    }
    else if(strcmp(methodname, "CheckVirtualSystemIsMigratableToSystem") == 0) {
        rc = MigrateVirtualSystem(broker, context, argsin, argsout, session, false, true, &status);
    }
    else
        status.rc = CMPI_RC_ERR_METHOD_NOT_FOUND;
    
Exit:
    if(session)
        xen_utils_cleanup_session(session);
    if(ctx)
        xen_utils_free_call_context(ctx);

    CMReturnData(results, (CMPIValue *)&rc, CMPI_uint32);
    CMReturnDone(results);

    _SBLIM_RETURNSTATUS(status);
}
CMPIStatus TestMethodProviderInvokeMethod (
    CMPIMethodMI * mi,
    const CMPIContext * ctx,
    const CMPIResult * rslt,
    const CMPIObjectPath * ref,
    const char *methodName,
    const CMPIArgs * in,
    CMPIArgs * out)
{
    CMPIStatus rc = { CMPI_RC_OK, NULL };
    CMPIString *className;
    CMPIData data;
    char result[80] = "Hello,";
    const char *strCat;
    const char * name;
    char *argName = "Message";
    CMPIString * str1;
    CMPIString * str2;
    CMPIValue val1, val2;
    /* get the class name from object-path */
    className = CMGetClassName(ref, &rc);
    /* get a pointer to a C char* representation of this String. */
    name = CMGetCharsPtr(className, &rc);

    if(!strcmp(name, _ClassName))
    {
       if(!strcmp ("SayHello", methodName))
       {
            /* gets the number of arguments contained in "in" Args. */
            if(CMGetArgCount(in, &rc) > 0)
            {
                /* gets a Name argument value */
                data = CMGetArg(in, "Name", &rc);
                /*check for data type and not null value of argument value
                  recieved */
                if(data.type == CMPI_string &&  !(CMIsNullValue(data)))
                {
                    strCat = CMGetCharsPtr(data.value.string, &rc);
                    strcat(result, strCat);
//                    strcat(result, "!");
                    /* create the new string to return to client */
                    str1 = CMNewString(_broker, result, &rc);
                    val1.string = str1;
                }
            }
            else
            {
                str1 = CMNewString(_broker, result, &rc);
                val1.string = str1;
            }
            /* create string to add to an array */
            str2 = CMNewString(_broker,"Have a good day", &rc);
            val2.string = str2;
            /* Adds a value of str2 string to out array argument */
            rc = CMAddArg(out, argName, &val2, CMPI_string);
        } else if (!strcmp("CheckArrayNoType", methodName)) {
            data = CMGetArg(in, "IntArray", &rc);
            CMPIType atype=data.value.array->ft->getSimpleType(data.value.array,&rc); 
            sprintf(result,"Datatype is %s",paramType(atype));
            str1 = CMNewString(_broker, result, &rc);
            val1.string = str1;
        }

    }
    CMReturnData (rslt, (CMPIValue *) &val1, CMPI_string);
    CMReturnDone (rslt);
    return rc;
}
CMPIStatus
TestMethodProviderInvokeMethod(CMPIMethodMI * mi,
                               const CMPIContext *ctx,
                               const CMPIResult *rslt,
                               const CMPIObjectPath * ref,
                               const char *methodName,
                               const CMPIArgs * in, CMPIArgs * out)
{
  CMPIStatus      rc = { CMPI_RC_OK, NULL };
  CMPIString     *className;
  CMPIData        data;
  char            result[80] = "Hello,";
  const char     *strCat;
  const char     *name;
  char           *argName = "Message";
  CMPIString     *str1;
  CMPIString     *str2;
  CMPIValue       val1,
                  val2;

  /*
   * get the class name from object-path 
   */
  className = CMGetClassName(ref, &rc);
  /*
   * get a pointer to a C char* representation of this String. 
   */
  name = CMGetCharsPtr(className, &rc);

  if (!strcmp(name, _ClassName)) {
    if (!strcmp("SayHello", methodName)) {
      /*
       * gets the number of arguments contained in "in" Args. 
       */
      if (CMGetArgCount(in, &rc) > 0) {
        /*
         * gets a Name argument value 
         */
        data = CMGetArg(in, "Name", &rc);
        /*
         * check for data type and not null value of argument value
         * recieved 
         */
        if (data.type == CMPI_string && !(CMIsNullValue(data))) {
          strCat = CMGetCharsPtr(data.value.string, &rc);
          strcat(result, strCat);
          // strcat(result, "!");
          /*
           * create the new string to return to client 
           */
          str1 = CMNewString(_broker, result, &rc);
          val1.string = str1;
        }
      } else {
        str1 = CMNewString(_broker, result, &rc);
        val1.string = str1;
      }
      /*
       * create string to add to an array 
       */
      str2 = CMNewString(_broker, "Have a good day", &rc);
      val2.string = str2;
      /*
       * Adds a value of str2 string to out array argument 
       */
      rc = CMAddArg(out, argName, &val2, CMPI_string);

    /*
     * For: 3048960 method array types not filled in Test provider. 
     */
    } else if (!strcmp("CheckArrayNoType", methodName)) {
      data = CMGetArg(in, "IntArray", &rc);
      CMPIType atype=data.value.array->ft->getSimpleType(data.value.array,&rc); 
      sprintf(result,"Datatype is %s",paramType(atype));
      str1 = CMNewString(_broker, result, &rc);
      val1.string = str1;

    /*
     * This method simulates various provider problems for testing. 
     */
    } else if (!strcmp("Misbehave", methodName)) {
      data = CMGetArg(in, "Action", &rc);

      const char *strval = NULL;
      if (data.type == CMPI_string && !(CMIsNullValue(data))) {
        strval = CMGetCharsPtr(data.value.string, &rc);
        sprintf(result, "data type is %s, value = %s", paramType(data.type),
            strval);
        
        if (!strcmp(strval,"hang")) {
          while(sleep(60)); /* to test req handler timeout, etc. */
        }
        else if (!strcmp(strval,"abort")) {
          abort();
        }
        else if (!strcmp(strval,"fpe")) {
          #pragma GCC diagnostic ignored "-Wdiv-by-zero"
          fprintf(stderr,"ouch! %d\n",1/0);
          #pragma GCC diagnostic warning "-Wdiv-by-zero"
        }
        else if (!strcmp(strval,"segfault")) {
          void (*crashme)(void) = NULL;
          crashme();
        }
        /*
         * These tend to behave as if the condition were raised internally
         */
        else if (!strcmp(strval,"sigabrt")) {
          kill(getpid(), SIGABRT);
          while(sleep(3)); /* slight pause to ensure we catch signal */
        }
        else if (!strcmp(strval,"sigfpe")) {
          kill(getpid(), SIGFPE);
          while(sleep(3));
        }
        else if (!strcmp(strval,"sigsegv")) {
          kill(getpid(), SIGSEGV);
          while(sleep(3));
        }
        else if (!strcmp(strval,"sigusr1")) {
          kill(getpid(), SIGUSR1); /* as if we received a signal from stopBroker() */
          while(sleep(3));
        }
        else if (!strcmp(strval,"sigkill")) {
          kill(getpid(), SIGKILL); /* this is currently not handled by providerDrv*/
          while(sleep(3));
        } else {
          sprintf(result, "Action not recognized: %s", strval);
          fprintf(stderr,
              "+++ cmpiTestMethodProvider: Action not recognized \"%s\"\n",
              strval);
        }
        /*
         * create the new string to return to client 
         */
        str1 = CMNewString(_broker, result, &rc);
        val1.string = str1;
      }

    } else {
      sprintf(result, "Unknown method name: %s", methodName);
      fprintf(stderr,
          "+++ cmpiTestMethodProvider: Unknown method name \"%s\"\n",
          methodName);
      
      str1 = CMNewString(_broker, result, &rc);
      val1.string = str1;
    }
  }
  CMReturnData(rslt, (CMPIValue *) & val1, CMPI_string);
  CMReturnDone(rslt);
  return rc;
}