void PG_TestPropertyTypes::enumerateInstanceNames(
    const OperationContext& context,
    const CIMObjectPath& classReference,
    ObjectPathResponseHandler& handler)
{

    // ensure the Namespace is valid
    if (!classReference.getNameSpace().equal ("test/static"))
    {
        throw CIMException(CIM_ERR_INVALID_NAMESPACE);
    }

    // ensure the class existing in the specified namespace
    if (!classReference.getClassName().equal ("PG_TestPropertyTypes"))
    {
        throw CIMException(CIM_ERR_INVALID_CLASS);
    }

    // begin processing the request
    handler.processing();

    Array<CIMObjectPath> instanceNames;
    instanceNames = _enumerateInstanceNames(context, classReference);

    handler.deliver(instanceNames);

    // complete processing the request
    handler.complete();
}
void PG_TestPropertyTypes::deleteInstance(
    const OperationContext& context,
    const CIMObjectPath& instanceReference,
    ResponseHandler& handler)
{
    // synchronously get references
    Array<CIMObjectPath> references =
        _enumerateInstanceNames(context, instanceReference);

    // ensure the Namespace is valid
    if (!instanceReference.getNameSpace().equal("test/static"))
    {
        throw CIMException(CIM_ERR_INVALID_NAMESPACE);
    }

    // ensure the class existing in the specified namespace
    if (!instanceReference.getClassName().equal("PG_TestPropertyTypes"))
    {
        throw CIMException(CIM_ERR_INVALID_CLASS);
    }

    // ensure the requested object exists
    Uint32 index = findObjectPath(references, instanceReference);
    if (index == PEG_NOT_FOUND)
    {
        throw CIMException(CIM_ERR_NOT_FOUND);
    }

    // begin processing the request
    handler.processing();

    // we do not remove instance
    // complete processing the request
    handler.complete();
}
Esempio n. 3
0
int main (int argc, char** argv)
{
    String stringVal;
    verbose = (getenv("PEGASUS_TEST_VERBOSE")) ? true : false;

    CIMClient client;
    try
    {
        client.connectLocal ();
    }
    catch (Exception & e)
    {
        PEGASUS_STD (cerr) << e.getMessage () << PEGASUS_STD (endl);
        return -1;
    }

    _enumerateInstanceNames(client);
    _getInstance(client);
    _setProperty(client, 7890);
    _getProperty(client);
    // getProperty() only returns CIMValues of type String.
    value.get(stringVal);
    PEGASUS_TEST_ASSERT(atoi((const char*)stringVal.getCString())==7890);
    _setProperty(client,1234);
    _getProperty(client);
    // getProperty() only returns CIMValues of type String.
    // Verify that setProperty worked as expected.
    value.get(stringVal);
    PEGASUS_TEST_ASSERT(atoi((const char*)stringVal.getCString())==1234);

    return 0;
}
void PG_TestPropertyTypes::modifyInstance(
    const OperationContext& context,
    const CIMObjectPath& instanceReference,
    const CIMInstance& instanceObject,
    const Boolean includeQualifiers,
    const CIMPropertyList& propertyList,
    ResponseHandler& handler)
{
    // This provider only allows partial instance modification for the
    // PropertyUint8 property.
    if (!(propertyList.isNull() ||
          ((propertyList.size() == 1) &&
           (propertyList[0].equal("PropertyUint8")))))
    {
        throw CIMException(CIM_ERR_NOT_SUPPORTED);
    }

    // synchronously get references
    Array<CIMObjectPath> references =
        _enumerateInstanceNames(context, instanceReference);

    // ensure the Namespace is valid
    if (!instanceReference.getNameSpace().equal("test/static"))
    {
        throw CIMException(CIM_ERR_INVALID_NAMESPACE);
    }

    // ensure the class existing in the specified namespace
    if (!instanceReference.getClassName().equal("PG_TestPropertyTypes"))
    {
        throw CIMException(CIM_ERR_INVALID_CLASS);
    }

    // ensure the property values are valid
    _testPropertyTypesValue(instanceObject);

    // ensure the request object exists
    Uint32 index = findObjectPath(references, instanceReference);
    if (index == PEG_NOT_FOUND)
    {
        throw CIMException(CIM_ERR_NOT_FOUND);
    }

    // begin processing the request
    handler.processing();

    // We do nothing here since we like to have static result
    // complete processing the request
    handler.complete();
}
void PG_TestPropertyTypes::createInstance(
    const OperationContext& context,
    const CIMObjectPath& instanceReference,
    const CIMInstance& instanceObject,
    ObjectPathResponseHandler& handler)
{
    // synchronously get references
    Array<CIMObjectPath> references =
        _enumerateInstanceNames(context, instanceReference);

    // ensure the Namespace is valid

    if (!instanceReference.getNameSpace().equal("test/static"))
    {
        throw CIMException(CIM_ERR_INVALID_NAMESPACE);
    }

    // ensure the class existing in the specified namespace
    if (!instanceReference.getClassName().equal("PG_TestPropertyTypes"))
    {
        throw CIMException(CIM_ERR_INVALID_CLASS);
    }

    // ensure the InstanceId key is valid
    Uint32 propIndex = instanceObject.findProperty("InstanceId");
    if (propIndex == PEG_NOT_FOUND)
    {
        throw CIMException(CIM_ERR_INVALID_PARAMETER);
    }

//    Uint32 i;
//    for (i=0; i<keys.size() && keys[i].getName() != "InstanceId"; i++);

//    if (i==keys.size())
//    {
//        throw CIMException(CIM_ERR_INVALID_PARAMETER);
//    }

    // create the CIMObjectPath to return
    Array<CIMKeyBinding> keys;
    keys.append(CIMKeyBinding(
        instanceObject.getProperty(propIndex).getName(),
        instanceObject.getProperty(propIndex).getValue().toString(),
        CIMKeyBinding::NUMERIC));
    keys.append(CIMKeyBinding(
        "CreationClassName",
        "PG_TestPropertyTypes",
        CIMKeyBinding::STRING));
    CIMObjectPath returnReference(
        String::EMPTY,
        CIMNamespaceName(),
        instanceReference.getClassName(),
        keys);

    // ensure the property values are valid
    _testPropertyTypesValue(instanceObject);

    // Determine if a property exists in the class
    if (instanceObject.findProperty("PropertyUint8") == PEG_NOT_FOUND)
    {
        throw CIMException(CIM_ERR_INVALID_PARAMETER);
    }

    // ensure the requested object do not exist
    if (findObjectPath(references, instanceReference) != PEG_NOT_FOUND)
    {
        throw CIMException(CIM_ERR_ALREADY_EXISTS);
    }

    // begin processing the request
    handler.processing();

    handler.deliver(returnReference);

    // complete processing request
    handler.complete();
}
void PG_TestPropertyTypes::getInstance(
    const OperationContext& context,
    const CIMObjectPath& instanceReference,
    const Boolean includeQualifiers,
    const Boolean includeClassOrigin,
    const CIMPropertyList& propertyList,
    InstanceResponseHandler& handler)
{
    // synchronously get references
    //Get extra instance created for testing negative realValues.
    Array<CIMObjectPath> references =
        _enumerateInstanceNames(context, instanceReference);

    // ensure the InstanceId key is valid
    Array<CIMKeyBinding> keys = instanceReference.getKeyBindings();
    Uint32 i;
    for (i=0; i<keys.size() && !keys[i].getName().equal("InstanceId"); i++);

    if (i==keys.size())
    {
        throw CIMException(CIM_ERR_INVALID_PARAMETER);
    }

    // ensure the Namespace is valid
    if (!instanceReference.getNameSpace().equal ("test/static"))
    {
        throw CIMException(CIM_ERR_INVALID_NAMESPACE);
    }

    // ensure the class existing in the specified namespace
    if (!instanceReference.getClassName().equal ("PG_TestPropertyTypes"))
    {
        throw CIMException(CIM_ERR_INVALID_CLASS);
    }
        Boolean testRealValue = false;
    // ensure the request object exists
    Uint32 index = findObjectPath(references, instanceReference);
    if (index == PEG_NOT_FOUND)
    {
        CIMClass cimclass = _cimom.getClass(
            context,
            instanceReference.getNameSpace(),
            instanceReference.getClassName(),
            false,
            true,
            true,
            CIMPropertyList());
        CIMObjectPath tempRef = realValueTestInstance.buildPath(cimclass);
        tempRef.setHost(instanceReference.getHost());
        tempRef.setNameSpace(instanceReference.getNameSpace());
        if (instanceReference != tempRef)
        {
            throw CIMException(CIM_ERR_NOT_FOUND);
        }
        testRealValue = true;
    }

    // begin processing the request
    handler.processing();
    if (testRealValue)
    {
        handler.deliver(realValueTestInstance);
    }
    else
    {
        // instance index corresponds to reference index
        handler.deliver(_instances[index]);
    }
    // complete processing the request
    handler.complete();
}
Esempio n. 7
0
int main(const int argc, const char **argv)
{
  // error if no args
  if (argv[1] == 0)
  {
    _usage();
    return 1;
  }

  SSLContext *sslContext = 0; // initialized for unencrypted connection
  _c.setTimeout(TIMEOUT);

  // Get hostname from environment, if defined
  char *p = getenv("CIM_HOST");
  if (p) _hostName = p;

  // Get port number, if defined
  char *pn = getenv("CIM_PORT");
  if (pn) _portNumber = atol(pn);

  if (p)
  {
    // hostname was specified, we will not connect local
    // so decide whether encrypted or not
    char *s = getenv("CIM_NOSSL");
    if (s) // don't use ssl (not encrypted)
    {
      if (!pn) _portNumber = 5988; // use 5988 if no port specified
    }
    else
    {
      try
      {
        sslContext = new SSLContext(PEGASUS_SSLCLIENT_CERTIFICATEFILE,
                                    verifyServerCertificate,
                                    PEGASUS_SSLCLIENT_RANDOMFILE
                                    /* "/var/opt/wbem/ssl.rnd" */);
      }
      catch (Exception &e)
      {
        cerr << e.getMessage() << endl;
        return 1;
      }
      if (!pn) _portNumber = 5989; // use 5989 if no port specified
    }
  }

  // Get namespace from environment or use default
  p = getenv("CIM_NAMESPACE");
  _nameSpace = (p==0)? DEFAULT_NAMESPACE:p;
  
  // Get user from environment or don't specify
  p = getenv("CIM_USER");
  _userName = (p==0)? String::EMPTY : p;
  
  // Get password from environment or use empty
  p = getenv("CIM_PASSWORD");
  _passWord = (p==0)? String::EMPTY : p;

  try
  {
    if (String::equal(_hostName,String::EMPTY)) _c.connectLocal();
    else
    // hostname was specified; do remote connect
    {
      if (sslContext) _c.connect(_hostName, _portNumber, *sslContext, _userName, _passWord);
      else _c.connect(_hostName, _portNumber, _userName, _passWord);
    }
  }
  catch(Exception& e)
  {
    cerr << e.getMessage() << endl;
    return 1;
  }

  // command is first arg
  const char *cmd = argv[1];

  if (String::equalNoCase(cmd,"getClass") ||
      String::equalNoCase(cmd,"gc"))
    return _getClass(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"enumerateClasses") ||
           String::equalNoCase(cmd,"ec"))
    return _enumerateClasses(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"enumerateClassNames") ||
           String::equalNoCase(cmd,"ecn"))
    return _enumerateClassNames(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"getInstance") ||
           String::equalNoCase(cmd,"gi"))
    return _getInstance(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"enumerateInstances") ||
           String::equalNoCase(cmd,"ei"))
    return _enumerateInstances(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"enumerateInstanceNames") ||
           String::equalNoCase(cmd,"ein"))
    return _enumerateInstanceNames(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"getProperty") ||
           String::equalNoCase(cmd,"gp"))
    return _getProperty(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"setProperty") ||
           String::equalNoCase(cmd,"sp"))
    return _setProperty(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"invokeMethod") ||
           String::equalNoCase(cmd,"im"))
    return _invokeMethod(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"createClass") ||
           String::equalNoCase(cmd,"cc"))
    return _createClass(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"modifyClass") ||
           String::equalNoCase(cmd,"mc"))
    return _modifyClass(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"deleteClass") ||
           String::equalNoCase(cmd,"dc"))
    return _deleteClass(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"createInstance") ||
           String::equalNoCase(cmd,"ci"))
    return _createInstance(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"modifyInstance") ||
           String::equalNoCase(cmd,"mi"))
    return _modifyInstance(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"deleteInstance") ||
           String::equalNoCase(cmd,"di"))
    return _deleteInstance(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"associators") ||
           String::equalNoCase(cmd,"a"))
    return _associators(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"associatorNames") ||
           String::equalNoCase(cmd,"an"))
    return _associatorNames(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"references") ||
           String::equalNoCase(cmd,"r"))
    return _references(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"referenceNames") ||
           String::equalNoCase(cmd,"rn"))
    return _referenceNames(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"execQuery") ||
           String::equalNoCase(cmd,"exq"))
    return _execQuery(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"getQualifier") ||
           String::equalNoCase(cmd,"gq"))
    return _getQualifier(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"setQualifier") ||
           String::equalNoCase(cmd,"sq"))
    return _setQualifier(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"deleteQualifier") ||
           String::equalNoCase(cmd,"dq"))
    return _deleteQualifier(argc-2,&argv[2]);
  else if (String::equalNoCase(cmd,"enumerateQualifiers") ||
           String::equalNoCase(cmd,"eq"))
    return _enumerateQualifiers(argc-2,&argv[2]);
  else
  {
    cerr << cmd << ": Invalid CIM operation."<< endl;
   _usage();
    return 1;
  }
}