コード例 #1
0
ファイル: socketcomm.c プロジェクト: ncultra/Pegasus-2.5
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 );
	}
}
コード例 #2
0
ファイル: general.c プロジェクト: jubalh/konkretcmpi
CMPIStatus KBase_SetToArgs(
    const KBase* self, 
    CMPIBoolean in,
    CMPIBoolean out,
    CMPIArgs* ca)
{
    KPos pos;

    /* Check parameters */

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

    /* Set properties */

    KFirst(&pos, self);

    while (KMore(&pos))
    {
        CMPIData cd;
        const KValue* value = (const KValue*)pos.field;

        do
        {
            CMPIStatus st;

            if (!value->exists)
                break;

            cd = _data(value, pos.tag);

            if (in && !(pos.tag & KTAG_IN))
                break;

            if (out && !(pos.tag & KTAG_OUT))
                break;

            if (value->null)
                st = CMAddArg(ca, pos.name, NULL, cd.type);
            else
                st = CMAddArg(ca, pos.name, &cd.value, cd.type);

            if (!KOkay(st))
            {
                printf("%s() failed on %s\n", __FUNCTION__, pos.name);
            }
        }
        while (0);

        KNext(&pos);
    }

    KReturn(OK);
}
コード例 #3
0
CMPIStatus
IndCIMXMLHandlerDeleteInstance(CMPIInstanceMI * mi,
                               const CMPIContext *ctx,
                               const CMPIResult *rslt,
                               const CMPIObjectPath * cop)
{
  CMPIStatus      st = { CMPI_RC_OK, NULL };
  CMPIArgs       *in,
                 *out = NULL;
  CMPIObjectPath *op;
  CMPIData        rv;

  _SFCB_ENTER(TRACE_INDPROVIDER, "IndCIMXMLHandlerDeleteInstance");

  if (interOpNameSpace(cop, &st) == 0)
    _SFCB_RETURN(st);

  internalProviderGetInstance(cop, &st);
  if (st.rc)
    _SFCB_RETURN(st);

  in = CMNewArgs(_broker, NULL);
  CMAddArg(in, "key", &cop, CMPI_ref);
  op = CMNewObjectPath(_broker, "root/interop",
                       "cim_indicationsubscription", &st);
  rv = CBInvokeMethod(_broker, ctx, op, "_removeHandler", in, out, &st);

  if (st.rc == CMPI_RC_OK) {
    st = InternalProviderDeleteInstance(NULL, ctx, rslt, cop);
  }

  _SFCB_RETURN(st);
}
コード例 #4
0
static int
_testErrorPaths()
{
  CMPIArgs       *args_ptr = NULL;
  CMPIStatus      rc = { CMPI_RC_OK, NULL };
  CMPIValue       value;
  char           *str = NULL;
  value.inst = NULL;
  args_ptr = CMNewArgs(_broker, &rc);
  rc = CMAddArg(args_ptr,
                "EmptyInstance", (CMPIValue *) & value, CMPI_instance);
  value.ref = NULL;
  rc = CMAddArg(args_ptr, "EmptyRef", (CMPIValue *) & value, CMPI_ref);
  value.dateTime = NULL;
  rc = CMAddArg(args_ptr,
                "EmptyDatetime", (CMPIValue *) & value, CMPI_dateTime);
  rc = CMAddArg(args_ptr, "EmptyChars", (CMPIValue *) str, CMPI_chars);
  rc = CMAddArg(args_ptr, "EmptyCharsPtrA", NULL, CMPI_charsptrA);

  value.chars = NULL;
  rc = CMAddArg(args_ptr, "EmptyCharsPtr", &value, CMPI_charsptr);

  value.args = NULL;
  rc = CMAddArg(args_ptr, "EmptyArgs", (CMPIValue *) & value, CMPI_args);

  rc = CMRelease(args_ptr);
  return 1;
}
コード例 #5
0
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;
}
コード例 #6
0
CMPIStatus
IndCIMXMLHandlerCreateInstance(CMPIInstanceMI * mi,
                               const CMPIContext *ctx,
                               const CMPIResult *rslt,
                               const CMPIObjectPath * cop,
                               const CMPIInstance *ci)
{
  CMPIStatus      st = { CMPI_RC_OK, NULL };
  CMPIArgs       *in,
                 *out = NULL;
  CMPIObjectPath *op;
  CMPIData        rv;
  unsigned short  persistenceType;

  _SFCB_ENTER(TRACE_INDPROVIDER, "IndCIMXMLHandlerCreateInstance");

  if (interOpNameSpace(cop, &st) == 0)
    _SFCB_RETURN(st);

  internalProviderGetInstance(cop, &st);
  if (st.rc == CMPI_RC_ERR_FAILED)
    _SFCB_RETURN(st);
  if (st.rc == CMPI_RC_OK) {
    setStatus(&st, CMPI_RC_ERR_ALREADY_EXISTS, NULL);
    _SFCB_RETURN(st);
  }

  CMPIInstance   *ciLocal = CMClone(ci, NULL);
  memLinkInstance(ciLocal);
  CMPIObjectPath* copLocal = CMClone(cop, NULL);
  memLinkObjectPath(copLocal);

  setCCN(copLocal,ciLocal,"CIM_ComputerSystem");

  CMPIString *sysname=ciLocal->ft->getProperty(ciLocal,"SystemName",&st).value.string;
  if (sysname == NULL || sysname->hdl == NULL) {
    char hostName[512];
    hostName[0]=0;
    gethostname(hostName,511); /* should be the same as SystemName of IndicationService */
    CMAddKey(copLocal, "SystemName", hostName, CMPI_chars);
    CMSetProperty(ciLocal,"SystemName",hostName,CMPI_chars);
  }


  CMPIString     *dest =
      CMGetProperty(ciLocal, "destination", &st).value.string;
  if (dest == NULL || CMGetCharPtr(dest) == NULL) {
    setStatus(&st, CMPI_RC_ERR_FAILED,
              "Destination property not found; is required");
    CMRelease(ciLocal);
    _SFCB_RETURN(st);
  } else {                      /* if no scheme is given, assume http (as
                                 * req. for param by mof) */
    char           *ds = CMGetCharPtr(dest);
    if (strstr(ds, "://") == NULL) {
      char           *prefix = "http://";
      int             n = strlen(ds) + strlen(prefix) + 1;
      char           *newdest = (char *) malloc(n * sizeof(char));
      strcpy(newdest, prefix);
      strcat(newdest, ds);
      CMSetProperty(ciLocal, "destination", newdest, CMPI_chars);
      free(newdest);
    }
  }

  CMPIData        persistence =
      CMGetProperty(ciLocal, "persistencetype", &st);
  if (persistence.state == CMPI_nullValue
      || persistence.state == CMPI_notFound) {
    persistenceType = 2;        /* default is 2 = permanent */
  } else if (persistence.value.uint16 < 1 || persistence.value.uint16 > 3) {
    setStatus(&st, CMPI_RC_ERR_FAILED,
              "PersistenceType property must be 1, 2, or 3");
    CMRelease(ciLocal);
    _SFCB_RETURN(st);
  } else {
    persistenceType = persistence.value.uint16;
  }
  CMSetProperty(ciLocal, "persistencetype", &persistenceType, CMPI_uint16);

  if (CMClassPathIsA(_broker, copLocal, "cim_listenerdestination", NULL)) {
    //get the creation timestamp
    struct timeval  tv;
    struct timezone tz;
    char   context[100];
    gettimeofday(&tv, &tz);
    struct tm cttm;
    char * gtime = (char *) malloc(15 * sizeof(char));
    memset(gtime, 0, 15 * sizeof(char));
    if (gmtime_r(&tv.tv_sec, &cttm) != NULL) {
      strftime(gtime, 15, "%Y%m%d%H%M%S", &cttm);
    }

    // Even though reliable indications may be disabled, we need to do this 
    // in case it ever gets enabled.
    // Get the IndicationService name
    CMPIObjectPath * isop = CMNewObjectPath(_broker, "root/interop", "CIM_IndicationService", NULL);
    CMPIEnumeration * isenm = _broker->bft->enumerateInstances(_broker, ctx, isop, NULL, NULL);
    CMPIData isinst = CMGetNext(isenm, NULL);
    CMPIData mc = CMGetProperty(isinst.value.inst, "Name", NULL);

    // build the context string
    sprintf (context,"%s#%s#",mc.value.string->ft->getCharPtr(mc.value.string,NULL),gtime);
    CMPIValue scontext;
    scontext.string = sfcb_native_new_CMPIString(context, NULL, 0);
    free(gtime);

    // set the properties
    CMSetProperty(ciLocal, "SequenceContext", &scontext, CMPI_string);
    CMPIValue zarro = {.sint64 = -1 };
    CMSetProperty(ciLocal, "LastSequenceNumber", &zarro, CMPI_sint64);
  }

  CMPIString     *str = CDToString(_broker, copLocal, NULL);
  CMPIString     *ns = CMGetNameSpace(copLocal, NULL);
  _SFCB_TRACE(1,
              ("--- handler %s %s", (char *) ns->hdl, (char *) str->hdl));

  in = CMNewArgs(_broker, NULL);
  CMAddArg(in, "handler", &ciLocal, CMPI_instance);
  CMAddArg(in, "key", &copLocal, CMPI_ref);
  op = CMNewObjectPath(_broker, "root/interop",
                       "cim_indicationsubscription", &st);
  rv = CBInvokeMethod(_broker, ctx, op, "_addHandler", in, out, &st);

  if (st.rc == CMPI_RC_OK) {
    st = InternalProviderCreateInstance(NULL, ctx, rslt, copLocal, ciLocal);
  }
  else {
    rv=CBInvokeMethod(_broker,ctx,op,"_removeHandler",in,out,NULL);
  }

  _SFCB_RETURN(st);
}

CMPIStatus
IndCIMXMLHandlerModifyInstance(CMPIInstanceMI * mi,
                               const CMPIContext *ctx,
                               const CMPIResult *rslt,
                               const CMPIObjectPath * cop,
                               const CMPIInstance *ci,
                               const char **properties)
{
  CMPIStatus      st = { CMPI_RC_ERR_NOT_SUPPORTED, NULL };
  _SFCB_ENTER(TRACE_INDPROVIDER, "IndCIMXMLHandlerSetInstance");
  _SFCB_RETURN(st);
}
コード例 #7
0
/******************************************************************************
* checks for migratability or actually does the migration
******************************************************************************/
int MigrateVirtualSystem(
    const CMPIBroker *broker,   /* in - CMPI Broker that does most of the work */
    const CMPIContext *context, /* in - CMPI context for the caller */
    const CMPIArgs *argsin,     /* in - All the arguments for the method */
    const CMPIArgs *argsout,    /* out - All the output arguments for the method */
    xen_utils_session *session, /* in - Session for making xen calls */
    bool host_ip,               /* in - The host parameter is an IP address */
    bool migrate_check_only,    /* in -Check if migration is possible only, dont actually migrate */
    CMPIStatus *status)         /* out - Report CMPI status of method */
{
    char *hostid = NULL, *vm_uuid = NULL;
    CMPIData argdata;
    xen_vm vm = NULL;
    xen_host_set *host_set = NULL;
    CMPIInstance *msd = NULL;
    xen_host host = NULL;
    int rc = Xen_VirtualSystemMigrationService_MigrateVirtualSystemToSystem_Invalid_Parameter;
    CMPIrc statusrc = CMPI_RC_ERR_INVALID_PARAMETER;
    char *error_msg = "ERROR: Unknown error";
    xen_string_string_map *other_config=NULL;

    /* For now only Live migrations are supported */
    if(_GetArgument(broker, argsin, "MigrationSettingData", CMPI_chars, &argdata, status)) {
        /* Argument passed in as a MOF string, parse it */
        msd = xen_utils_parse_embedded_instance(broker, CMGetCharPtr(argdata.value.string));
        if (msd == NULL) { // parser returns zero for success, non-zero for error
            error_msg = "ERROR: Couldnt parse the 'MigrationSettingData' parameter";
            goto Exit;
        }
    }
    else
        /* Argument could have been passed in as an intance */
        if(_GetArgument(broker, argsin, "MigrationSettingData", CMPI_instance, &argdata, status))
            msd = argdata.value.inst;

    if(msd != NULL) {
        CMPIData data = CMGetProperty(msd, "MigrationType", status);
        if(data.value.uint16 != Xen_VirtualSystemMigrationSettingData_MigrationType_Live) {
            error_msg = "ERROR: 'MigrationSettingData' contains an invalid MigrationType (Live expected)";
            goto Exit;
        }
    }

    /* Host to migrate to */
    if(!host_ip) {
        /* required parameters */
        if(!_GetArgument(broker, argsin, "DestinationSystem", CMPI_ref, &argdata, status)){
            error_msg = "ERROR: 'DestionationSystem' parameter is missing";
            goto Exit;
        }
        else {
            /* This is the CIM reference to an existing Host object */
            CMPIData key;
            key = CMGetKey(argdata.value.ref, "Name", status);
            if(status->rc != CMPI_RC_OK || CMIsNullValue(key)) {
                error_msg = "ERROR: 'DestinationSystem' is missing the required 'Name' key";
                goto Exit;
            }
            hostid = CMGetCharPtr(key.value.string);
            if(!xen_host_get_by_uuid(session->xen, &host, hostid)) 
                goto Exit;
        }
    }
    else {
        if(!_GetArgument(broker, argsin, "DestinationHost", CMPI_string, &argdata, status)) {
            error_msg = "ERROR: 'DestinationHost' parameter is missing";
            goto Exit;
        }
        else {
            /* Determing Xen host based on IP address,. Cannot use inet_pton() and so on since DNS may not have been configured properly */
            hostid = CMGetCharPtr(argdata.value.string);
            _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("Trying to migrate to DestinationHost : %s", hostid));
            if(!xen_host_get_all(session->xen, &host_set))
                goto Exit;
            int i=0;
            for (i=0; i<host_set->size; i++) {
                xen_host_record *host_rec = NULL;
                if(!xen_host_get_record(session->xen, &host_rec, host_set->contents[i]))
                    goto Exit;
                /* DestinationHost could be an IP address or the hostname */
                if((host_rec->address &&  (strcmp(hostid, host_rec->address) == 0)) || 
                   (host_rec->hostname && (strcmp(hostid, host_rec->hostname) == 0)) ||
                   (host_rec->name_label && (strcmp(hostid, host_rec->name_label) == 0))) { 
                    xen_host_record_free(host_rec);
                    host = host_set->contents[i];
                    host_set->contents[i] = NULL; /* dont free this one */
                    break;
                }
                xen_host_record_free(host_rec);
            }
        }
    }

    /* VM to migrate - required parameter */
    if(!_GetArgument(broker, argsin, "ComputerSystem", CMPI_ref, &argdata, status)) {
        if(!_GetArgument(broker, argsin, "ComputerSystem", CMPI_string, &argdata, status)) {
            error_msg = "ERROR: Missing the required 'ComputerSystem' parameter";
            goto Exit;
        }
        else
            vm_uuid = CMGetCharPtr(argdata.value.string);
    } else {
        argdata = CMGetKey(argdata.value.ref, "Name", status);
        if(status->rc != CMPI_RC_OK || CMIsNullValue(argdata)) {
            error_msg = "ERROR: ComputerSystem is missing the required 'Name' key";
            goto Exit;
        }
        vm_uuid = CMGetCharPtr(argdata.value.string);
    }
    status->rc = CMPI_RC_ERR_FAILED;
    rc = Xen_VirtualSystemMigrationService_MigrateVirtualSystemToSystem_Failed;
    if(xen_vm_get_by_uuid(session->xen, &vm, vm_uuid)) {
        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, ("Migrating %s to %s", vm_uuid, hostid));
        if(migrate_check_only) {
            /* Check to see if migration is possible */
            statusrc = CMPI_RC_OK;
            rc = Xen_VirtualSystemMigrationService_MigrateVirtualSystemToSystem_Completed_with_No_Error;
            bool migratable = xen_vm_assert_can_boot_here(session->xen, vm, host);
            if(migratable == false || !session->xen->ok) {
                migratable = false;

                // Workaround for kvp migration
                if(session->xen->error_description_count==1) {
                    if(xen_vm_get_other_config(session->xen, &other_config, vm)) {
                         if(xen_utils_get_from_string_string_map(other_config, "kvp_enabled")) {
                            _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_INFO, ("Overwriting migratable to mark kvp vm as migratable, although its network"));
                            migratable=true;
                            RESET_XEN_ERROR(session->xen);
                         }
                         free(other_config);
                    } else {
                       _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, ("Could not get other config."));
                    }
                }

                if(migratable == false && session->xen->error_description) {
                    /* This is not part of the MOF (and is not documented), but nice to have */
                    char *xen_error = xen_utils_get_xen_error(session->xen);
                    CMAddArg(argsout, "Reason", (CMPIValue *)xen_error, CMPI_chars);
                    free(xen_error);
                }
            }
            CMAddArg(argsout, "IsMigratable", (CMPIValue *)&migratable, CMPI_boolean);
        }
        else {
            /* Do the actual migration, this could take a few minutes */
            CMPIObjectPath* job_instance_op = NULL;
            migrate_job_context *job_context = calloc(1, sizeof(migrate_job_context));
            if(!job_context) {
                error_msg = "ERROR: Couldn't allocate memory for the migrate job.";
                goto Exit;
            }
            job_context->vm = vm;
            job_context->host = host;
            if(!job_create(broker, context, session, MIGRATE_VM_TASK_NAME, vm_uuid, 
                           migrate_task, job_context, &job_instance_op, status)) {
                error_msg = "ERROR: Couldn't prepare the Migrate job. Job wasnt started.";
                goto Exit;
            }
            statusrc = CMPI_RC_OK;
            rc = Xen_VirtualSystemMigrationService_MigrateVirtualSystemToHost_Method_Parameters_Checked___Job_Started;
            CMAddArg(argsout, "Job", (CMPIValue *)&job_instance_op, CMPI_ref);
            vm = NULL;      /* freed by async thread */
            host = NULL;    /* freed by async thread */
        }
    }

Exit:
    if(host)
        xen_host_free(host);
    if(vm)
        xen_vm_free(vm);
    if(host_set)
        xen_host_set_free(host_set);

    xen_utils_set_status(broker, status, statusrc, error_msg, session->xen);
    return rc;
}
コード例 #8
0
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;
}
コード例 #9
0
static CMPIStatus
enumInstances(CMPIInstanceMI * mi,
              const CMPIContext *ctx, void *rslt,
              const CMPIObjectPath * ref,
              const char **properties,
              void (*retFnc) (void *, CMPIInstance *), int ignprov)
{
  CMPIStatus      st = { CMPI_RC_OK, NULL };
  CMPIStatus      sti = { CMPI_RC_OK, NULL };
  BlobIndex      *bi;
  CMPIString     *cn = CMGetClassName(ref, NULL);
  CMPIString     *ns = CMGetNameSpace(ref, NULL);
  const char     *nss = ns->ft->getCharPtr(ns, NULL);
  const char     *cns = cn->ft->getCharPtr(cn, NULL);
  const char     *bnss = repositoryNs(nss);
  int             len,
                  i,
                  ac = 0;
  CMPIInstance   *ci;
  CMPIArgs       *in,
                 *out;
  CMPIObjectPath *op;
  CMPIArray      *ar;
  CMPIData        rv;
  const char    **keyList;

  _SFCB_ENTER(TRACE_INTERNALPROVIDER, "enumInstances");
  _SFCB_TRACE(1, ("--- %s %s", nss, cns));

  in = CMNewArgs(Broker, NULL);
  out = CMNewArgs(Broker, NULL);
  if (ignprov)
    CMAddArg(in, "classignoreprov", cns, CMPI_chars);
  else
    CMAddArg(in, "class", cns, CMPI_chars);

  op = CMNewObjectPath(Broker, bnss, "$ClassProvider$", &sti);
  _SFCB_TRACE(1, ("--- getallchildren"));
  rv = CBInvokeMethod(Broker, ctx, op, "getallchildren", in, out, &sti);
  _SFCB_TRACE(1, ("--- getallchildren rc: %d", sti.rc));

  ar = CMGetArg(out, "children", NULL).value.array;
  if (ar)
    ac = CMGetArrayCount(ar, NULL);
  _SFCB_TRACE(1, ("--- getallchildren ar: %p count: %d", ar, ac));

  for (i = 0; cns; i++) {
    _SFCB_TRACE(1, ("--- looking for %s", cns));
    if ((bi = _getIndex(bnss, cns)) != NULL) {
      for (ci = ipGetFirst(bi, &len, NULL, 0); ci;
           ci = ipGetNext(bi, &len, NULL, 0)) {
        if (properties) {
          keyList = getKeyList(ci->ft->getObjectPath(ci, NULL));
          ci->ft->setPropertyFilter(ci, properties, keyList);
          if (keyList) {
            free(keyList);
          }
        }
        _SFCB_TRACE(1, ("--- returning instance %p", ci));
        retFnc(rslt, ci);
      }
    }
    freeBlobIndex(&bi, 1);
    if (i < ac)
      cns = (char *) CMGetArrayElementAt(ar, i, NULL).value.string->hdl;
    else
      cns = NULL;
  }

  _SFCB_RETURN(st);
}
コード例 #10
0
CMPIStatus
InternalProviderEnumInstanceNames(CMPIInstanceMI * mi,
                                  const CMPIContext *ctx,
                                  const CMPIResult *rslt,
                                  const CMPIObjectPath * ref)
{
  CMPIStatus      st = { CMPI_RC_OK, NULL };
  CMPIStatus      sti = { CMPI_RC_OK, NULL };
  BlobIndex      *bi;
  CMPIString     *cn = CMGetClassName(ref, NULL);
  CMPIString     *ns = CMGetNameSpace(ref, NULL);
  CMPIObjectPath *cop;
  const char     *nss = ns->ft->getCharPtr(ns, NULL);
  const char     *cns = cn->ft->getCharPtr(cn, NULL);
  const char     *bnss = repositoryNs(nss);
  size_t          ekl;
  int             i,
                  ac = 0;
  char            copKey[8192] = "";
  char           *kp;
  CMPIArgs       *in,
                 *out;
  CMPIObjectPath *op;
  CMPIArray      *ar;
  CMPIData        rv;

  _SFCB_ENTER(TRACE_INTERNALPROVIDER, "InternalProviderEnumInstanceNames");
  _SFCB_TRACE(1, ("%s %s", nss, cns));

  in = CMNewArgs(Broker, NULL);
  out = CMNewArgs(Broker, NULL);
  CMAddArg(in, "class", cns, CMPI_chars);
  op = CMNewObjectPath(Broker, bnss, "$ClassProvider$", &sti);
  rv = CBInvokeMethod(Broker, ctx, op, "getallchildren", in, out, &sti);
  ar = CMGetArg(out, "children", NULL).value.array;
  if (ar)
    ac = CMGetArrayCount(ar, NULL);

  for (i = 0; cns; i++) {
    if ((bi = _getIndex(bnss, cns)) != NULL) {
      if (ipGetFirst(bi, NULL, &kp, &ekl)) {
        while (1) {
          strcpy(copKey, nss);
          strcat(copKey, ":");
          strcat(copKey, cns);
          strcat(copKey, ".");
          strncat(copKey, kp, ekl);

          cop = getObjectPath(copKey, NULL);
          if (cop)
            CMReturnObjectPath(rslt, cop);
          else {
            CMPIStatus      st = { CMPI_RC_ERR_FAILED, NULL };
            return st;
          }
          if (bi->next < bi->dSize && ipGetNext(bi, NULL, &kp, &ekl)) {
            continue;
          }
          break;
        }
      }
      freeBlobIndex(&bi, 1);
    }
    if (i < ac)
      cns = (char *) CMGetArrayElementAt(ar, i, NULL).value.string->hdl;
    else
      cns = NULL;
  }
  _SFCB_RETURN(st);
}
コード例 #11
0
ファイル: indCIMXMLHandler.c プロジェクト: kkaempf/sblim-sfcb
CMPIStatus
IndCIMXMLHandlerInvokeMethod(CMPIMethodMI * mi,
                             const CMPIContext *ctx,
                             const CMPIResult *rslt,
                             const CMPIObjectPath * ref,
                             const char *methodName,
                             const CMPIArgs * in, CMPIArgs * out)
{
  _SFCB_ENTER(TRACE_INDPROVIDER, "IndCIMXMLHandlerInvokeMethod");

  CMPIStatus      st = { CMPI_RC_OK, NULL };
  int             drc = 0;
  struct timeval tv;
  struct timezone tz;
  static unsigned int indID=1;


  if (interOpNameSpace(ref, &st) == 0)
    _SFCB_RETURN(st);

  if (strcasecmp(methodName, "_deliver") == 0) {

#ifndef SETTABLERETRY
    // On the first indication, check if reliable indications are enabled.
    if (RIEnabled == -1) {
#endif
      CMPIObjectPath *op=CMNewObjectPath(_broker,"root/interop","CIM_IndicationService",NULL);
      CMPIEnumeration *isenm = _broker->bft->enumerateInstances(_broker, ctx, op, NULL, NULL);
      CMPIData isinst=CMGetNext(isenm,NULL);
      CMPIData mc=CMGetProperty(isinst.value.inst,"DeliveryRetryAttempts",NULL);
      RIEnabled=mc.value.uint16;
#ifndef SETTABLERETRY
    }
#endif

    CMPIInstance *indo=CMGetArg(in,"indication",NULL).value.inst;
    CMPIInstance *ind=CMClone(indo,NULL);
    CMPIContext    *ctxLocal=NULL;
    CMPIObjectPath *iop=NULL,*subop=NULL;
    CMPIInstance *sub=NULL;

    if (RIEnabled) {
      ctxLocal = prepareUpcall((CMPIContext *) ctx);
      // Set the indication sequence values
      iop=CMGetObjectPath(ind,NULL);
      CMAddKey(iop,"SFCB_IndicationID",&indID,CMPI_uint32);
      CMSetProperty(ind,"SFCB_IndicationID",&indID,CMPI_uint32);
      // Prevent this property from showing up in the indication
      filterFlagProperty(ind, "SFCB_IndicationID");
      sub=CMGetArg(in,"subscription",NULL).value.inst;
      CMPIData handler=CMGetProperty(sub, "Handler", &st);
      CMPIObjectPath *hop=handler.value.ref;
      // Get the handler instance from the hashtable via a
      // methodcall to interopProvider
      in=CMNewArgs(_broker,NULL);
      CMAddArg(in,"handler",&hop,CMPI_ref);
      out=CMNewArgs(_broker,NULL);
      CMPIObjectPath* sop=CMNewObjectPath(_broker,"root/interop","cim_indicationsubscription",&st);
      CBInvokeMethod(_broker,ctx,sop,"_getHandler",in,out,&st);
      CMPIInstance *hdlr=CMGetArg(out,"hin",NULL).value.inst;

      if (hdlr == NULL) {
         mlogf(M_ERROR,M_SHOW,"Deliver indication failed, hdlr is null. rc:%d\n",st.rc);
         _SFCB_RETURN(st);
      }

      // Build the complete sequence context
      // Get the stub from the handler
      CMPIString *context = CMGetProperty(hdlr, "SequenceContext", &st).value.string;
      // and add the sfcb start time
      char *cstr=malloc( (strlen(context->ft->getCharPtr(context,NULL)) + strlen(sfcBrokerStart) + 1) * sizeof(char));
      sprintf(cstr,"%s%s",context->ft->getCharPtr(context,NULL),sfcBrokerStart);
      context = sfcb_native_new_CMPIString(cstr, NULL, 0); 
      // and put it in the indication
      CMSetProperty(ind, "SequenceContext", &context, CMPI_string);
      free(cstr);
      CMRelease(context);

      // Get the proper sequence number
      CMPIValue lastseq = CMGetProperty(hdlr, "LastSequenceNumber", &st).value;
      lastseq.sint64++;
      // Handle wrapping of the signed int
      if (lastseq.sint64 < 0) lastseq.sint64=0;
      // Update the last used number in the handler
      CMSetProperty(hdlr, "LastSequenceNumber", &lastseq.sint64, CMPI_sint64);
      in=CMNewArgs(_broker,NULL);
      CMAddArg(in,"handler",&hdlr,CMPI_instance);
      CMAddArg(in,"key",&hop,CMPI_ref);
      CBInvokeMethod(_broker,ctx,sop,"_updateHandler",in,NULL,&st);
      if (st.rc != CMPI_RC_OK) {
         mlogf(M_ERROR,M_SHOW,"Failed to update LastSequenceNumber. rc:%d\n",st.rc);
      }
      // And the indication
      CMSetProperty(ind, "SequenceNumber", &lastseq, CMPI_sint64);
    }

    // Now send the indication
    drc = deliverInd(ref, in, ind);

    switch (drc) {
      case 0:   /* Success */
      case 400: /* Bad Request XML */
      case 501: /* Not Implemented */
        break;
      default:
        if (RIEnabled){
        _SFCB_TRACE(1,("--- Indication delivery failed, adding to retry queue"));
        // Indication delivery failed, send to retry queue
        // build an element
        RTElement      *element;
        element = malloc(sizeof(*element));
        element->ref=ref->ft->clone(ref,NULL);
        // Get the OP of the subscription and indication
        subop=CMGetObjectPath(sub,NULL);
        element->sub=subop->ft->clone(subop,NULL);
        element->ind=iop->ft->clone(iop,NULL);
        element->indInst=ind->ft->clone(ind,NULL);
        // Store other attrs
        element->instanceID=indID;
        element->count=0;
        gettimeofday(&tv, &tz);
        element->lasttry=tv.tv_sec;
        indID++;
        // Add it to the retry queue
        enqRetry(element,ctx,1);
        // And launch the thread if it isn't already running
        pthread_attr_init(&tattr);
        pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
        if (retryRunning == 0) {
          retryRunning = 1;
          _SFCB_TRACE(1,("--- Starting retryExport thread"));
          CMPIContext    *pctx = native_clone_CMPIContext(ctx);
          pthread_create(&t, &tattr, &retryExport, (void *) pctx);
        }
      }
      break;
    }
    if (RIEnabled) {
        CMRelease(ctxLocal);
    }
    CMRelease(ind);
  }
  else {
    printf("--- ClassProvider: Invalid request %s\n", methodName);
    st.rc = CMPI_RC_ERR_METHOD_NOT_FOUND;
  }

  _SFCB_RETURN(st);
}
コード例 #12
0
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;
}
コード例 #13
0
static int
_testSimpleTypes()
{
  CMPIArgs       *args_ptr = NULL;
  CMPIStatus      rc = { CMPI_RC_OK, NULL };
  CMPIStatus      rc1 = { CMPI_RC_OK, NULL };
  int             i,
                  flag,
                  size;
  CMPIValue       value;
  CMPIValue       value1;
  CMPIData        data;
  CMPIData        dataInst;
  CMPIData        retDataInst;
  CMPIString     *retNamespace = NULL;
  CMPIString     *retClassname = NULL;
  CMPIObjectPath *objPath = make_ObjectPath(_broker,
                                            _Namespace,
                                            _ClassName);
  const char     *str1;
  const char     *str2;

  struct array_types {
    CMPIType        element_type;
    char           *typeName;
    char           *args_name;
  } types_arr[] = {

    {
    CMPI_instance, "CMPI_instance", "CMPI_instance"}, {
  CMPI_ref, "CMPI_ref", "CMPI_ref"}};

  size = 2;

  flag = 1;
  for (i = 0; i < size; i++) {
    args_ptr = CMNewArgs(_broker, &rc);

    switch (types_arr[i].element_type) {
    case CMPI_ref:
      value.ref = CMNewObjectPath(_broker,
                                  "root/cimv2", "Sample_Instance", &rc);
      break;

    case CMPI_instance:
      value.inst = make_Instance(objPath);
      value1.uint32 = 20;
      rc = CMSetProperty(value.inst, "Property1", &value1, CMPI_uint32);
      break;
    }
    rc = CMAddArg(args_ptr,
                  types_arr[i].args_name,
                  (CMPIValue *) & value, types_arr[i].element_type);

    data = CMGetArg(args_ptr, types_arr[i].args_name, &rc);

    switch (types_arr[i].element_type) {
    case CMPI_ref:
      retNamespace = CMGetNameSpace(data.value.ref, &rc);
      retClassname = CMGetClassName(data.value.ref, &rc1);

      if ((rc.rc == CMPI_RC_OK) && (rc1.rc == CMPI_RC_OK)) {
        str1 = CMGetCharsPtr(retNamespace, &rc);
        str2 = CMGetCharsPtr(retClassname, &rc1);
        if ((rc.rc == CMPI_RC_OK) && (rc1.rc == CMPI_RC_OK)) {
          if ((strcmp(str1, "root/cimv2")) ||
              (strcmp(str2, "Sample_Instance"))) {
            flag = 0;
          }
        } else {
          flag = 0;
        }
      } else {
        flag = 0;
      }
      rc = CMRelease(value.ref);
      break;

    case CMPI_instance:
      retDataInst = CMGetProperty(data.value.inst, "Property1", &rc);
      dataInst = CMGetProperty(value.inst, "Property1", &rc);
      if (retDataInst.value.uint32 != dataInst.value.uint32) {
        flag = 0;
      }
      rc = CMRelease(value.inst);
      break;
    }
    if (data.type == types_arr[i].element_type && flag) {
    }
    rc = CMRelease(args_ptr);
  }
  return flag;
}
コード例 #14
0
static int
_testArrayTypes()
{
  struct array_types {
    CMPIType        element_type;
    CMPIType        typeA;
    char           *typeName;
    char           *typeAName;
    char           *args_name;
  } types_arr[] = {
    {
    CMPI_uint32,
          CMPI_uint32A,
          "CMPI_uint32", "CMPI_uint32A", "CMPI_uint32_array"}, {
    CMPI_uint16,
          CMPI_uint16A,
          "CMPI_uint16", "CMPI_uint16A", "CMPI_uint16_array"}, {
    CMPI_uint8,
          CMPI_uint8A, "CMPI_uint8", "CMPI_uint8A", "CMPI_uint8_array"}, {
    CMPI_uint64,
          CMPI_uint64A,
          "CMPI_uint64", "CMPI_uint64A", "CMPI_uint64_array"}, {
    CMPI_sint32,
          CMPI_sint32A,
          "CMPI_sint32", "CMPI_sint32A", "CMPI_sint32_array"}, {
    CMPI_sint16,
          CMPI_sint16A,
          "CMPI_sint16", "CMPI_sint16A", "CMPI_sint16_array"}, {
    CMPI_sint8,
          CMPI_sint8A, "CMPI_sint8", "CMPI_sint8A", "CMPI_sint8_array"}, {
    CMPI_sint64,
          CMPI_sint64A,
          "CMPI_sint64", "CMPI_sint64A", "CMPI_sint64_array"}, {
    CMPI_real32,
          CMPI_real32A,
          "CMPI_real32", "CMPI_real32A", "CMPI_real32_array"}, {
    CMPI_real64,
          CMPI_real64A,
          "CMPI_real64", "CMPI_real64A", "CMPI_real64_array"}, {
    CMPI_char16,
          CMPI_char16A,
          "CMPI_char16", "CMPI_char16A", "CMPI_char16_array"}, {
    CMPI_boolean,
          CMPI_booleanA,
          "CMPI_boolean", "CMPI_booleanA", "CMPI_boolean_array"}, {
    CMPI_string,
          CMPI_stringA,
          "CMPI_string", "CMPI_stringA", "CMPI_string_array"}, {
    CMPI_dateTime,
          CMPI_dateTimeA,
          "CMPI_dateTime", "CMPI_dateTimeA", "CMPI_dateTime_array"}, {
    CMPI_ref, CMPI_refA, "CMPI_ref", "CMPI_refA", "CMPI_ref_array"}, {
    CMPI_instance,
          CMPI_instanceA,
          "CMPI_instance", "CMPI_instanceA", "CMPI_instance_array"}, {
  CMPI_null, CMPI_ARRAY, "Invalid", "InvalidArray", "Invalid_array"}};

  int             i,
                  flag,
                  size;
  CMPIStatus      rc = { CMPI_RC_OK, NULL };
  CMPIStatus      rc1 = { CMPI_RC_OK, NULL };
  CMPIArray      *arr = NULL;
  CMPIString     *retNamespace = NULL;
  CMPIString     *retClassname = NULL;
  CMPIValue       value,
                  value1;
  CMPIData        data;
  CMPIData        arr_data;
  CMPIData        dataInst;
  CMPIData        retDataInst;
  CMPIArgs       *args_ptr = NULL;
  CMPIObjectPath *objPath = make_ObjectPath(_broker,
                                            _Namespace,
                                            _ClassName);
  CMPIUint64      datetime1,
                  datetime2;
  const char     *str1;
  const char     *str2;

  size = 17;
  for (i = 0; i < size; i++) {
    args_ptr = CMNewArgs(_broker, &rc);
    switch (types_arr[i].element_type) {
    case CMPI_uint32:
      value.uint32 = 56;
      break;

    case CMPI_uint16:
      value.uint16 = 32;
      break;

    case CMPI_uint8:
      value.uint8 = 56;
      break;

    case CMPI_uint64:
      value.uint64 = 32;
      break;

    case CMPI_sint32:
      value.sint32 = -56;
      break;

    case CMPI_sint16:
      value.sint16 = -32;
      break;

    case CMPI_sint8:
      value.sint8 = -56;
      break;

    case CMPI_sint64:
      value.sint64 = -32;
      break;

    case CMPI_real32:
      value.real32 = (CMPIReal32) -32.78;
      break;

    case CMPI_real64:
      value.real64 = -899.32;
      break;

    case CMPI_char16:
      value.char16 = 'k';
      break;

    case CMPI_string:
      value.string = CMNewString(_broker, "string", &rc);
      break;

    case CMPI_boolean:
      value.boolean = 1;
      break;

    case CMPI_dateTime:
      value.dateTime = CMNewDateTime(_broker, &rc);
      break;

    case CMPI_ref:
      value.ref = CMNewObjectPath(_broker,
                                  "root/cimv2", "Sample_Instance", &rc);
      break;

    case CMPI_null:
      value.args = NULL;
      break;

    case CMPI_instance:
      value.inst = make_Instance(objPath);
      value1.uint32 = 20;
      rc = CMSetProperty(value.inst, "Property1", &value1, CMPI_uint32);
      break;
    }

    arr = NULL;
    rc = CMAddArg(args_ptr,
                  "EmptyArray", (CMPIValue *) & arr, types_arr[i].typeA);
    arr = CMNewArray(_broker, 1, types_arr[i].element_type, &rc);

    rc = CMSetArrayElementAt(arr, 0, &value, types_arr[i].element_type);

    rc = CMAddArg(args_ptr,
                  types_arr[i].args_name,
                  (CMPIValue *) & arr, types_arr[i].typeA);

    flag = 1;
    if ((types_arr[i].element_type) != CMPI_null) {
      data = CMGetArg(args_ptr, types_arr[i].args_name, &rc);

      arr_data = CMGetArrayElementAt(data.value.array, 0, &rc);

      switch (types_arr[i].element_type) {
      case CMPI_uint32:
        if (arr_data.value.uint32 != value.uint32) {
          flag = 0;
        }
        break;

      case CMPI_uint16:
        if (arr_data.value.uint16 != value.uint16) {
          flag = 0;
        }
        break;

      case CMPI_uint8:
        if (arr_data.value.uint8 != value.uint8) {
          flag = 0;
        }
        break;

      case CMPI_uint64:
        if (arr_data.value.uint64 != value.uint64) {
          flag = 0;
        }
        break;

      case CMPI_sint32:
        if (arr_data.value.sint32 != value.sint32) {
          flag = 0;
        }
        break;

      case CMPI_sint16:
        if (arr_data.value.sint16 != value.sint16) {
          flag = 0;
        }
        break;

      case CMPI_sint8:
        if (arr_data.value.sint8 != value.sint8) {
          flag = 0;
        }
        break;

      case CMPI_sint64:
        if (arr_data.value.sint64 != value.sint64) {
          flag = 0;
        }
        break;

      case CMPI_real32:
        if (arr_data.value.real32 != value.real32) {
          flag = 0;
        }
        break;

      case CMPI_real64:
        if (arr_data.value.real64 != value.real64) {
          flag = 0;
        }
        break;

      case CMPI_char16:
        if (arr_data.value.char16 != value.char16) {
          flag = 0;
        }
        break;

      case CMPI_string:
        str1 = CMGetCharsPtr(arr_data.value.string, &rc);
        str2 = CMGetCharsPtr(value.string, &rc1);
        if ((rc.rc != CMPI_RC_OK) ||
            (rc1.rc != CMPI_RC_OK) || strcmp(str1, str2)) {
          flag = 0;
        }
        break;

      case CMPI_boolean:
        if (arr_data.value.boolean != value.boolean) {
          flag = 0;
        }
        break;

      case CMPI_dateTime:
        datetime1 = CMGetBinaryFormat(arr_data.value.dateTime, &rc);
        datetime2 = CMGetBinaryFormat(value.dateTime, &rc1);
        if ((rc.rc != CMPI_RC_OK) ||
            (rc1.rc != CMPI_RC_OK) || (datetime1 != datetime2)) {
          flag = 0;
        }
        rc = CMRelease(value.dateTime);
        break;

      case CMPI_ref:
        retNamespace = CMGetNameSpace(arr_data.value.ref, &rc);
        retClassname = CMGetClassName(arr_data.value.ref, &rc1);
        if ((rc.rc == CMPI_RC_OK) && (rc1.rc == CMPI_RC_OK)) {
          str1 = CMGetCharsPtr(retNamespace, &rc);
          str2 = CMGetCharsPtr(retClassname, &rc1);
          if ((rc.rc == CMPI_RC_OK) && (rc1.rc == CMPI_RC_OK)) {
            if ((strcmp(str1, "root/cimv2")) ||
                (strcmp(str2, "TestCMPI_Instance"))) {
              flag = 0;
            }
          } else {
            flag = 0;
          }
        } else {
          flag = 0;
        }
        rc = CMRelease(value.ref);
        break;

      case CMPI_instance:
        retDataInst = CMGetProperty(arr_data.value.inst, "Property1", &rc);
        dataInst = CMGetProperty(value.inst, "Property1", &rc);
        if (retDataInst.value.uint32 != dataInst.value.uint32) {
          flag = 0;
        }
        rc = CMRelease(value.inst);
        break;
      }
      if (data.type == types_arr[i].typeA && flag) {
      }
    }
    rc = CMRelease(arr);
    rc = CMRelease(args_ptr);
  }
  return flag;
}
コード例 #15
0
void           *
retryExport(void *lctx)
{
  _SFCB_ENTER(TRACE_INDPROVIDER, "retryExport");

  CMPIObjectPath *ref;
  CMPIArgs       *in;
  CMPIInstance   *sub;
  CMPIContext    *ctx = (CMPIContext *) lctx;
  CMPIContext    *ctxLocal;
  RTElement      *cur,
                 *purge;
  struct timeval  tv;
  struct timezone tz;
  int             rint,
                  maxcount,
                  ract,
                  rtint;
  CMPIUint64      sfc = 0;
  CMPIObjectPath *op;
  CMPIEnumeration *isenm = NULL;

  //Setup signal handlers
  struct sigaction sa;
  sa.sa_handler = handle_sig_retry;
  sa.sa_flags = 0;
  sigemptyset(&sa.sa_mask);
  sigaction(SIGUSR2, &sa, NULL);

  CMPIStatus      st = { CMPI_RC_OK, NULL };

  ctxLocal = prepareUpcall(ctx);

  // Get the retry params from IndService
  op = CMNewObjectPath(_broker, "root/interop", "CIM_IndicationService",
                       NULL);
  isenm = _broker->bft->enumerateInstances(_broker, ctx, op, NULL, NULL);
  CMPIData        isinst = CMGetNext(isenm, NULL);
  CMPIData        mc =
      CMGetProperty(isinst.value.inst, "DeliveryRetryAttempts", NULL);
  CMPIData        ri =
      CMGetProperty(isinst.value.inst, "DeliveryRetryInterval", NULL);
  CMPIData        ra =
      CMGetProperty(isinst.value.inst, "SubscriptionRemovalAction", NULL);
  CMPIData        rti =
      CMGetProperty(isinst.value.inst, "SubscriptionRemovalTimeInterval",
                    NULL);
  maxcount = mc.value.uint16;   // Number of times to retry delivery
  rint = ri.value.uint32;       // Interval between retries
  rtint = rti.value.uint32;     // Time to allow sub to keep failing until 
  ract = ra.value.uint16;       // ... this action is taken

  // Now, run the queue
  sleep(5); //Prevent deadlock on startup when localmode is used.
  pthread_mutex_lock(&RQlock);
  cur = RQhead;
  while (RQhead != NULL) {
    if(retryShutdown) break; // Provider shutdown
    ref = cur->ref;
    // Build the CMPIArgs that deliverInd needs
    CMPIInstance *iinst=internalProviderGetInstance(cur->ind,&st);
    if (st.rc != 0 ) {
      mlogf(M_ERROR,M_SHOW,"Failed to retrieve indication instance from repository, rc:%d\n",st.rc);
      purge=cur;
      cur=cur->next;
      dqRetry(ctx,purge);
      continue;
    }
    in=CMNewArgs(_broker,NULL);
    CMAddArg(in,"indication",&iinst,CMPI_instance);
    sub=internalProviderGetInstance(cur->sub,&st);
    if (st.rc == CMPI_RC_ERR_NOT_FOUND) {
      // sub got deleted, purge this indication and move on
      _SFCB_TRACE(1,("--- Subscription for indication gone, deleting indication."));
      purge = cur;
      cur = cur->next;
      dqRetry(ctx,purge);
    } else {
      // Still valid, retry
      gettimeofday(&tv, &tz);
      if ((cur->lasttry + rint) > tv.tv_sec) {
        _SFCB_TRACE(1,("--- sleeping."));
        // no retries are ready, release the lock
        // and sleep for an interval, then relock
        pthread_mutex_unlock(&RQlock);
        sleep(rint);
        if(retryShutdown) break; // Provider shutdown
        pthread_mutex_lock(&RQlock);
      }
      st = deliverInd(ref, in, iinst);
      if ((st.rc == 0) || (cur->count >= maxcount - 1)) {
        // either it worked, or we maxed out on retries
        // If it succeeded, clear the failtime
        if (st.rc == 0) {
          _SFCB_TRACE(1,("--- Indication succeeded."));
          sfc = 0;
          CMSetProperty(sub, "DeliveryFailureTime", &sfc, CMPI_uint64);
          CBModifyInstance(_broker, ctxLocal, cur->sub, sub, NULL);
        }
        // remove from queue in either case
        _SFCB_TRACE(1,("--- Indication removed."));
        purge = cur;
        cur = cur->next;
        dqRetry(ctx,purge);
      } else {
        // still failing, leave on queue 
        _SFCB_TRACE(1,("--- Indication still failing."));
        cur->count++;
        gettimeofday(&tv, &tz);
        cur->lasttry = tv.tv_sec;

        CMPIInstance * indele=internalProviderGetInstance(cur->SFCBIndEle,&st);
        CMSetProperty(indele,"LastDelivery",&cur->lasttry,CMPI_sint32);
        CMSetProperty(indele,"RetryCount",&cur->count,CMPI_uint32);
        CBModifyInstance(_broker, ctxLocal, cur->SFCBIndEle, indele, NULL);

        CMPIData        sfcp =
            CMGetProperty(sub, "DeliveryFailureTime", NULL);
        sfc = sfcp.value.uint64;
        if (sfc == 0) {
          // if the time isn't set, this is the first failure
          sfc = tv.tv_sec;
          CMSetProperty(sub, "DeliveryFailureTime", &sfc, CMPI_uint64);
          CBModifyInstance(_broker, ctxLocal, cur->sub, sub, NULL);
          cur = cur->next;
        } else if (sfc + rtint < tv.tv_sec) {
          // Exceeded subscription removal threshold, if action is:
          // 2, delete the sub; 3, disable the sub; otherwise, nothing
          if (ract == 2) {
            _SFCB_TRACE(1,("--- Subscription threshold reached, deleting."));
            CBDeleteInstance(_broker, ctx, cur->sub);
            purge = cur;
            cur = cur->next;
            dqRetry(ctx,purge);
          } else if (ract == 3) {
            // Set sub state to disable(4)
            _SFCB_TRACE(1,("--- Subscription threshold reached, disable."));
            CMPIUint16      sst = 4;
            CMSetProperty(sub, "SubscriptionState", &sst, CMPI_uint16);
            CBModifyInstance(_broker, ctx, cur->sub, sub, NULL);
            purge = cur;
            cur = cur->next;
            dqRetry(ctx,purge);
          }
        } else {
          cur = cur->next;
        }
      }
    }
  }
  // Queue went dry, cleanup and exit
  _SFCB_TRACE(1,("--- Indication retry queue empty, thread exitting."));
  pthread_mutex_unlock(&RQlock);
  retryRunning = 0;
  CMRelease(ctxLocal);
  CMRelease(ctx);
  _SFCB_RETURN(NULL);
}
コード例 #16
0
ファイル: cmpi_provider.c プロジェクト: miminar/cmpi-bindings
/*
 * invokeMethod
 */
static CMPIStatus
invokeMethod(
        CMPIMethodMI* self,
        const CMPIContext* ctx,
        const CMPIResult* rslt,
        const CMPIObjectPath* objName,
        const char* method,
        const CMPIArgs* in,
        CMPIArgs* out)
{
    Target_Type _ctx;
    Target_Type _objName;

    CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
   
    _SBLIM_TRACE(1,("invokeMethod() called, ctx %p, rslt %p, objName %p, method %s, in %p, out %p", ctx, rslt, objName, method, in, out));

    TARGET_THREAD_BEGIN_BLOCK; 
    _ctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0);
    _objName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0);
  
    /* Ruby style method invocation */
#if defined(SWIGRUBY)
  
    /* de-camelize method name, might need 2time length */
    char *methodname = alloca(strlen(method) * 2 + 1);
    decamelize(method, methodname);
  
    /* access method arguments information via <decamelized>_args */
    int argsnamesize = strlen(methodname) + 5 + 1;
    char *argsname = alloca(argsnamesize); /* "<name>_args" */
    snprintf(argsname, argsnamesize, "%s_args", methodname);
  
    /* get the args array, gives names of input and output arguments */
    VALUE args = rb_funcall(((ProviderMIHandle*)self->hdl)->implementation, rb_intern(argsname), 0);
    if (check_ruby_type(args, T_ARRAY, "invoke: <method>_args must be Array",  &status, (ProviderMIHandle*)self->hdl ) < 0)
      return status;
  
    VALUE argsin = rb_ary_entry(args, 0); /* array of input arg names */
    if (check_ruby_type(argsin, T_ARRAY, "invoke: Input arguments must be Array", &status, (ProviderMIHandle*)self->hdl ) < 0)
      return status;

    int number_of_arguments = RARRAY_LEN(argsin) / 2;
    _SBLIM_TRACE(1,("%s -> %d input args", argsname, number_of_arguments));
    /* 3 args will be added by TargetCall, 2 args are added here, others are input args to function */
    VALUE *input = alloca((3 + 2 + number_of_arguments) * sizeof(VALUE));
    input[3] = _ctx;
    input[4] = _objName;
    /* loop over input arg names and types and get CMPIData via CMGetArg() */
    int i;
    for (i = 0; i < number_of_arguments; ++i) {
      const char *argname;
      CMPIData data;
      argname = target_charptr(rb_ary_entry(argsin, i*2));
      data = CMGetArg(in, argname, &status);
      if (status.rc != CMPI_RC_OK) {
	if ((data.state & CMPI_nullValue)
	    ||(data.state & CMPI_notFound)) {
	  input[5+i] = Target_Null;
	  continue;
	} 
	_SBLIM_TRACE(1,("Failed (rc %d) to get input arg %d:%s for %s", status.rc, i>>1, argname, method));
	return status;
      }
      input[5+i] = data_value(&data);
    }

    /* actual provider call, passes output args and return value via 'result' */
    VALUE result = TargetCall((ProviderMIHandle*)self->hdl, &status, methodname, -(2+number_of_arguments), input);

    /* argsout is array of [<return_type>, <output_arg_name>, <output_arg_type>, ... */
    VALUE argsout = rb_ary_entry(args, 1);
    CMPIValue value;
    CMPIType expected_type;
    CMPIType actual_type;
    if (check_ruby_type(argsout, T_ARRAY, "invoke: Output arguments must be Array", &status, (ProviderMIHandle*)self->hdl) < 0)
      return status;
    number_of_arguments = (RARRAY_LEN(argsout) - 1);

    if (number_of_arguments > 0) {
      /* if output args are defined, result must be an array
       * result[0] is the return value
       * result[1..n] are the output args in argsout order
       */
      if (check_ruby_type(result, T_ARRAY, "invoke: function with output arguments must return Array", &status, (ProviderMIHandle*)self->hdl) < 0)
        return status;

      /* loop over output arg names and types and set CMPIData via CMSetArg() */
      for (i = 0; i < number_of_arguments; i += 2) {
	const char *argname;
	argname = target_charptr(rb_ary_entry(argsout, i+1));
	expected_type = FIX2ULONG(rb_ary_entry(argsout, i+2));
	actual_type = target_to_value(rb_ary_entry(result, (i >> 1) + 1), &value, expected_type);
	status = CMAddArg(out, argname, &value, actual_type);
	if (status.rc != CMPI_RC_OK) {
	  _SBLIM_TRACE(1,("Failed (rc %d) to set output arg %d:%s for %s; expected type %x, actual type %x", status.rc, i>>1, argname, method, expected_type, actual_type));
	  return status;
	}
      }
      /* result[0] is the return value */
      result = rb_ary_entry(result, 0);

    }
コード例 #17
0
ファイル: classProviderSf.c プロジェクト: mchasal/SFCB
static CMPIStatus
ClassProviderInvokeMethod(CMPIMethodMI * mi,
                          const CMPIContext *ctx,
                          const CMPIResult *rslt,
                          const CMPIObjectPath * ref,
                          const char *methodName,
                          const CMPIArgs * in, CMPIArgs * out)
{
  CMPIStatus      st = { CMPI_RC_OK, NULL };
  CMPIArray      *ar;
  int             rc;
  ClassRegister  *cReg;

  _SFCB_ENTER(TRACE_PROVIDERS, "ClassProviderInvokeMethod");

  cReg = getNsReg(ref, &rc);
  if (cReg == NULL) {
    CMPIStatus      st = { CMPI_RC_ERR_INVALID_NAMESPACE, NULL };
    _SFCB_RETURN(st);
  }

  if (strcasecmp(methodName, "getchildren") == 0) {
    CMPIData        cn = CMGetArg(in, "class", NULL);
    _SFCB_TRACE(1, ("--- getchildren %s", (char *) cn.value.string->hdl));

    cReg->ft->wLock(cReg);

    if (cn.type == CMPI_string && cn.value.string && cn.value.string->hdl) {
      char           *child;
      int             l = 0,
          i = 0;
      UtilList       *ul =
          getChildren(cReg, (char *) cn.value.string->hdl);
      if (ul)
        l = ul->ft->size(ul);
      ar = CMNewArray(_broker, l, CMPI_string, NULL);
      if (ul)
        for (child = (char *) ul->ft->getFirst(ul); child; child = (char *)
             ul->ft->getNext(ul)) {
          CMSetArrayElementAt(ar, i++, child, CMPI_chars);
        }
      st = CMAddArg(out, "children", &ar, CMPI_stringA);
    } else {
    }

    cReg->ft->wUnLock(cReg);

  }

  else if (strcasecmp(methodName, "getallchildren") == 0) {
    int             ignprov = 0;
    CMPIStatus      st;
    CMPIData        cn = CMGetArg(in, "class", &st);

    cReg->ft->wLock(cReg);

    if (st.rc != CMPI_RC_OK) {
      cn = CMGetArg(in, "classignoreprov", NULL);
      ignprov = 1;
    }
    _SFCB_TRACE(1,
                ("--- getallchildren %s", (char *) cn.value.string->hdl));
    if (cn.type == CMPI_string && cn.value.string && cn.value.string->hdl) {
      int             n = 0,
          i = 0;
      loopOnChildCount(cReg, (char *) cn.value.string->hdl, &n, ignprov);
      _SFCB_TRACE(1, ("--- count %d", n));
      ar = CMNewArray(_broker, n, CMPI_string, NULL);
      if (n) {
        _SFCB_TRACE(1, ("--- loop %s", (char *) cn.value.string->hdl));
        loopOnChildChars(cReg, (char *) cn.value.string->hdl, ar, &i,
                         ignprov);
      }
      st = CMAddArg(out, "children", &ar, CMPI_stringA);
    } else {
    }

    cReg->ft->wUnLock(cReg);
  }

  else if (strcasecmp(methodName, "getassocs") == 0) {
    ar = CMNewArray(_broker, cReg->topAssocs, CMPI_string, NULL);
    ClassBase      *cb = (ClassBase *) (cReg + 1);
    UtilHashTable  *ct = cb->ht;
    HashTableIterator *i;
    char           *cn;
    ClassRecord    *crec;
    int             n;

    cReg->ft->wLock(cReg);

    for (n = 0, i = ct->ft->getFirst(ct, (void **) &cn, (void **) &crec);
         i; i = ct->ft->getNext(ct, i, (void **) &cn, (void **) &crec)) {
      if (crec->flags & CREC_isAssociation && crec->parent == NULL) {
        /*
         * add top-level association class 
         */
        CMSetArrayElementAt(ar, n++, cn, CMPI_chars);
      }
    }
    CMAddArg(out, "assocs", &ar, CMPI_stringA);

    cReg->ft->wUnLock(cReg);
  }

  else if (strcasecmp(methodName, "ischild") == 0) {
    char           *parent = (char *) CMGetClassName(ref, NULL)->hdl;
    char           *chldn =
        (char *) CMGetArg(in, "child", NULL).value.string->hdl;
    st.rc = traverseChildren(cReg, parent, chldn);
  }

  else if (strcasecmp(methodName, "_startup") == 0) {

    /* let providerMgr know that we're odne init'ing  */
    semRelease(sfcbSem,INIT_CLASS_PROV_ID);

    st.rc = CMPI_RC_OK;
  }

  else {
    mlogf(M_ERROR, M_SHOW,
          "--- ClassProvider: Invalid invokeMethod request %s\n",
          methodName);
    st.rc = CMPI_RC_ERR_METHOD_NOT_FOUND;
  }
  _SFCB_RETURN(st);
}
コード例 #18
0
ファイル: classProviderGz.c プロジェクト: zaneb/sblim-sfcb
static CMPIStatus ClassProviderInvokeMethod(CMPIMethodMI * mi,
                                     const CMPIContext * ctx,
                                     const CMPIResult * rslt,
                                     const CMPIObjectPath * ref,
                                     const char *methodName,
                                     const CMPIArgs * in, CMPIArgs * out)
{
   CMPIStatus st = { CMPI_RC_OK, NULL };
   CMPIArray *ar;
   int rc;
   ClassRegister *cReg;
   
   _SFCB_ENTER(TRACE_PROVIDERS, "ClassProviderInvokeMethod");

   cReg=getNsReg(ref, &rc);
   if (cReg==NULL) {
      CMPIStatus st = { CMPI_RC_ERR_INVALID_NAMESPACE, NULL };
      _SFCB_RETURN(st);
   }

   if (strcasecmp(methodName, "getchildren") == 0) {
      CMPIData cn = CMGetArg(in, "class", NULL);
      _SFCB_TRACE(1,("--- getchildren %s",(char*)cn.value.string->hdl));
      
      cReg->ft->wLock(cReg);
   
      if (cn.type == CMPI_string && cn.value.string && cn.value.string->hdl) {
         char *child;
         int l=0, i=0;
         UtilList *ul = getChildren(cReg, (char *) cn.value.string->hdl);
         if (ul) l = ul->ft->size(ul);
         ar = CMNewArray(_broker, l, CMPI_string, NULL);
         if (ul) for (child = (char *) ul->ft->getFirst(ul); child;  child = (char *)
               ul->ft->getNext(ul)) {
            CMSetArrayElementAt(ar, i++, child, CMPI_chars);
         }
         st = CMAddArg(out, "children", &ar, CMPI_stringA);
      }
      else {
      }
      
      cReg->ft->wUnLock(cReg);
   
   }
   
   else if (strcasecmp(methodName, "getallchildren") == 0) {
      int ignprov=0;
      CMPIStatus st;
      CMPIData cn = CMGetArg(in, "class", &st);
      
      cReg->ft->wLock(cReg);
   
      if (st.rc!=CMPI_RC_OK) {
         cn = CMGetArg(in, "classignoreprov", NULL);
         ignprov=1;
      }
      _SFCB_TRACE(1,("--- getallchildren %s",(char*)cn.value.string->hdl));
      if (cn.type == CMPI_string && cn.value.string && cn.value.string->hdl) {
         int n=0,i=0;
         loopOnChildCount(cReg,(char *)cn.value.string->hdl,&n,ignprov);
         _SFCB_TRACE(1,("--- count %d",n));
         ar = CMNewArray(_broker, n, CMPI_string, NULL);
         if (n) {
            _SFCB_TRACE(1,("--- loop %s",(char*)cn.value.string->hdl));
            loopOnChildChars(cReg, (char *)cn.value.string->hdl,ar,&i,ignprov);         
         }   
         st = CMAddArg(out, "children", &ar, CMPI_stringA);
      }
      else {
      }
      
      cReg->ft->wUnLock(cReg);   
   }

   else if (strcasecmp(methodName, "getassocs") == 0) {
      ar = CMNewArray(_broker, cReg->topAssocs, CMPI_string, NULL);
      ClassBase *cb = (ClassBase *) (cReg + 1);
      UtilHashTable *ct = cb->ht;
      HashTableIterator *i;
      char *cn;
      ClassRecord *crec;
      int n;

      cReg->ft->wLock(cReg);
   
       for (n = 0, i = ct->ft->getFirst(ct, (void **) &cn, (void **) &crec); i;
           i = ct->ft->getNext(ct, i, (void **) &cn, (void **) &crec)) {
         if(crec->flags & CREC_isAssociation && crec->parent == NULL) {
	   /* add top-level association class */
	   CMSetArrayElementAt(ar, n++, cn, CMPI_chars);
         }
      }
      CMAddArg(out, "assocs", &ar, CMPI_stringA);
      
      cReg->ft->wUnLock(cReg);
   }

   else if (strcasecmp(methodName, "ischild") == 0) {
      char *parent=(char*)CMGetClassName(ref,NULL)->hdl;
      char *chldn=(char*)CMGetArg(in, "child", NULL).value.string->hdl;
      st.rc = traverseChildren(cReg, parent, chldn);
   }
   
   else if (strcasecmp(methodName, "_startup") == 0) {

     /* check to see if cacheLimit was specified in providerRegister */
     CMPIStatus parm_st = { CMPI_RC_OK, NULL };
     CMPIData parmdata = CMGetContextEntry(ctx, "sfcbProviderParameters", &parm_st);

     if (parm_st.rc == CMPI_RC_OK ) {
       const char* parms = CMGetCharPtr(parmdata.value.string);

       /* cacheLimit is currently the only param, so just take whatever is after the '=' */
       const char* val = strchr(parms,'=');
       /* conversion to uint may cause wrapping; won't catch negatives */
       cacheLimit = ((val != NULL) && (cacheLimit = atoi(val+sizeof(char)))>0) ? cacheLimit : 10;
     }

      st.rc=CMPI_RC_OK;
  }
   
   else {
      mlogf(M_ERROR,M_SHOW,"--- ClassProvider: Invalid invokeMethod request %s\n", methodName);
      st.rc = CMPI_RC_ERR_METHOD_NOT_FOUND;
   }
   _SFCB_RETURN(st);
}