(file) Return to CMPI_SelectExp.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPI

File: [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPI / CMPI_SelectExp.cpp (download)
Revision: 1.23, Mon Jan 30 16:18:04 2006 UTC (18 years, 5 months ago) by karl
Branch: MAIN
CVS Tags: TASK_PEP233_EmbeddedInstSupport-merge_out_trunk, TASK_BUG_5314_IPC_REFACTORING_ROOT, TASK_BUG_5314_IPC_REFACTORING_BRANCH, TASK_BUG_5314_IPC_REFACTORING-V1, TASK_BUG_5191_QUEUE_CONSOLIDATION_ROOT, TASK_BUG_5191_QUEUE_CONSOLIDATION_BRANCH, TASK-TASK-BUG4011_WinLocalConnect-branch-New-root, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_out_to_branch, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_out_from_trunk, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_in_to_trunk, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_in_from_branch, TASK-TASK-BUG4011_WinLocalConnect-branch-New-branch, TASK-PEP268_SSLClientCertificatePropagation-root, TASK-PEP268_SSLClientCertificatePropagation-merged_out_to_branch, TASK-PEP268_SSLClientCertificatePropagation-merged_out_from_trunk, TASK-PEP268_SSLClientCertificatePropagation-merged_in_to_trunk, TASK-PEP268_SSLClientCertificatePropagation-merged_in_from_branch, TASK-PEP268_SSLClientCertificatePropagation-branch, TASK-PEP267_SLPReregistrationSupport-root, TASK-PEP267_SLPReregistrationSupport-merging_out_to_branch, TASK-PEP267_SLPReregistrationSupport-merged_out_to_branch, TASK-PEP267_SLPReregistrationSupport-merged_out_from_trunk, TASK-PEP267_SLPReregistrationSupport-merged_in_to_trunk, TASK-PEP267_SLPReregistrationSupport-merged_in_from_branch, TASK-PEP267_SLPReregistrationSupport-branch, TASK-PEP250_RPMProvider-root, TASK-PEP250_RPMProvider-merged_out_to_branch, TASK-PEP250_RPMProvider-merged_out_from_trunk, TASK-PEP250_RPMProvider-merged_in_to_trunk, TASK-PEP250_RPMProvider-merged_in_from_branch, TASK-PEP250_RPMProvider-branch, TASK-PEP245_CimErrorInfrastructure-root, TASK-PEP245_CimErrorInfrastructure-merged_out_to_branch, TASK-PEP245_CimErrorInfrastructure-merged_out_from_trunk, TASK-PEP245_CimErrorInfrastructure-merged_in_to_trunk, TASK-PEP245_CimErrorInfrastructure-merged_in_from_branch, TASK-PEP245_CimErrorInfrastructure-branch, TASK-PEP241_OpenPegasusStressTests-root, TASK-PEP241_OpenPegasusStressTests-merged_out_to_branch, TASK-PEP241_OpenPegasusStressTests-merged_out_from_trunk, TASK-PEP241_OpenPegasusStressTests-merged_in_to_trunk, TASK-PEP241_OpenPegasusStressTests-merged_in_from_branch, TASK-PEP241_OpenPegasusStressTests-branch, TASK-Bugs5690_3913_RemoteCMPI-root, TASK-Bugs5690_3913_RemoteCMPI-merged_out_to_branch, TASK-Bugs5690_3913_RemoteCMPI-merged_out_from_trunk, TASK-Bugs5690_3913_RemoteCMPI-merged_in_to_trunk, TASK-Bugs5690_3913_RemoteCMPI-merged_in_from_branch, TASK-Bugs5690_3913_RemoteCMPI-branch, TASK-BUG4011_WinLocalConnect-root, TASK-BUG4011_WinLocalConnect-merged_out_to_branch, TASK-BUG4011_WinLocalConnect-merged_out_from_trunk, TASK-BUG4011_WinLocalConnect-merged_in_to_trunk, TASK-BUG4011_WinLocalConnect-merged_in_from_branch, TASK-BUG4011_WinLocalConnect-branch-New, TASK-BUG4011_WinLocalConnect-branch, RELEASE_2_5_3-RC1, RELEASE_2_5_3, RELEASE_2_5_2-RC1, RELEASE_2_5_2, RELEASE_2_5_1-RC1, RELEASE_2_5_1, RELEASE_2_5-root
Branch point for: RELEASE_2_5-branch
Changes since 1.22: +3 -1 lines
BUG#: 4691
TITLE: Update Licenses to 2006

DESCRIPTION: Updates most of the licenses to 2006. The slp_client directories are excluded for the moment pending discussion. This change has passed unit and system tests.  Note that this changes just about EVERY file in Pegasus.

//%2006////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
// IBM Corp.; EMC Corporation, The Open Group.
// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
// EMC Corporation; VERITAS Software Corporation; The Open Group.
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
// EMC Corporation; Symantec Corporation; The Open Group.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//==============================================================================
//
// Author:      Adrian Schuur, schuur@de.ibm.com
//
// Modified By:
//
//%/////////////////////////////////////////////////////////////////////////////

#include "CMPI_Version.h"

#include "CMPI_SelectExp.h"
#include "CMPI_Ftabs.h"
#include "CMPI_Value.h"
#include "CMPI_String.h"
#include "CMPI_SelectExpAccessor_WQL.h"

#ifndef PEGASUS_DISABLE_CQL
#include "CMPI_SelectExpAccessor_CQL.h"
#include <Pegasus/CQL/CQLSelectStatement.h>
#include <Pegasus/CQL/CQLParser.h>
#endif

#include <Pegasus/WQL/WQLInstancePropertySource.h>
#include <Pegasus/Provider/CIMOMHandleQueryContext.h>
#include <Pegasus/WQL/WQLParser.h>

PEGASUS_USING_STD;
PEGASUS_NAMESPACE_BEGIN

#define DDD(X)   if (_cmpi_trace) X;

extern int _cmpi_trace;

extern "C"
{

  PEGASUS_STATIC CMPIStatus selxRelease (CMPISelectExp * eSx)
  {
 	CMPI_SelectExp *se = (CMPI_SelectExp*)eSx;
        if (!se->persistent) {
		// Do not call unlinkAndDelete - b/c the CMPI_Object::unlinkAndDelete
		// casts the structure to a CMPI_Object and deletes it. But this is a
                // CMPI_SelectExp structure so not all of the variables get deleted. Hence
                // we delete them here.
         	//((CMPI_Object*)se)->unlinkAndDelete();
         	((CMPI_Object*)se)->unlink();
	 	delete se;
        }

    CMReturn (CMPI_RC_OK);
  }

  PEGASUS_STATIC CMPISelectExp *selxClone (const CMPISelectExp * eSx, CMPIStatus * rc)
  {
    if (rc)
      CMSetStatus (rc, CMPI_RC_ERR_NOT_SUPPORTED);
    return NULL;
  }

  /* Helper functions */
  PEGASUS_STATIC CMPIBoolean _check_WQL (CMPI_SelectExp * sx, CMPIStatus * rc)
  {

    if (sx->wql_stmt == NULL)
      {
        WQLSelectStatement *stmt = new WQLSelectStatement ();
        try
        {
          WQLParser::parse (sx->cond, *stmt);
        }
        catch (const Exception &e) 
	{
	   DDD(cout<<"### exception: _check_WQL - msg: "<<e.getMessage()<<endl);
           if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_INVALID_QUERY,
            	(CMPIString*)string2CMPIString(e.getMessage()));
           delete stmt;
	   return false;
	}
        catch (...)
        {
	  DDD(cout<<"### exception: _check_WQL - ... " <<endl);
          delete stmt;
          if (rc) CMSetStatus (rc, CMPI_RC_ERR_INVALID_QUERY);
          return false;
        }
        /* Only set it for success */
        sx->wql_stmt = stmt;
      }                         /* sx->wql_stmt ... */
    return true;
  }
#ifndef PEGASUS_DISABLE_CQL
  PEGASUS_STATIC CMPIBoolean _check_CQL (CMPI_SelectExp * sx, CMPIStatus * rc)
  {
    Boolean fail = false;
    if (sx->cql_stmt == NULL)
      {
        /* The constructor should set this to a valid pointer. */
        if (sx->_context == NULL)
          {
            CMSetStatus (rc, CMPI_RC_ERROR_SYSTEM);
            return false;
          }
        CQLSelectStatement *selectStatement =
          new CQLSelectStatement (sx->lang, sx->cond, *sx->_context);
        try
        {
          CQLParser::parse (sx->cond, *selectStatement);

          selectStatement->validate ();
        }
        catch (const Exception &e) 
 	{
	    DDD(cout<<"### exception: _check_CQL - msg: "<<e.getMessage()<<endl);
            if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_INVALID_QUERY,
            		(CMPIString*)string2CMPIString(e.getMessage()));
            fail = true;
        }
        catch (...)
        {
	  DDD(cout<<"### exception: _check_CQL - ... " <<endl);
          if (rc) CMSetStatus (rc, CMPI_RC_ERR_INVALID_QUERY);
	  fail = true;
        }
	if (fail) 
	{
          delete selectStatement;
          return false;
        }
        sx->cql_stmt = selectStatement;
      }
    return true;
  }
#endif
  PEGASUS_STATIC CMPIBoolean selxEvaluate (const CMPISelectExp * eSx, const CMPIInstance * inst,
                                   CMPIStatus * rc)
  {
    CMPI_SelectExp *sx = (CMPI_SelectExp *) eSx;
    if (!inst)
      {
        if (rc)
          CMSetStatus (rc, CMPI_RC_ERR_INVALID_PARAMETER);
        return false;
      }
    if (!inst->hdl)
      {
        if (rc)
          CMSetStatus (rc, CMPI_RC_ERR_INVALID_PARAMETER);
        return false;
      }
    CIMInstance *instance = (CIMInstance *) inst->hdl;

    /* WQL */
    if (strncmp (sx->lang.getCString (), CALL_SIGN_WQL, CALL_SIGN_WQL_SIZE) ==
        0)
      {
        if (_check_WQL (sx, rc))
          {
            try
            {
              return sx->wql_stmt->evaluate (*(CIMInstance *) inst->hdl);
            } catch (const Exception &e)
	    {	
	        DDD(cout<<"### exception: selxEvaluate - msg: "<<e.getMessage()<<endl);
                if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_FAILED,
            		(CMPIString*)string2CMPIString(e.getMessage()));
                return false;
	    }
            catch (...)
            {
	      DDD(cout<<"### exception: selxEvaluate - ... " <<endl);
              if (rc) CMSetStatus (rc, CMPI_RC_ERR_FAILED);
              return false;
            }
          }
        else
          return false;
      }
    /* CIM:CQL */
#ifndef PEGASUS_DISABLE_CQL
    if (strncmp (sx->lang.getCString (), CALL_SIGN_CQL, CALL_SIGN_CQL_SIZE) ==
        0)
      {
        if (_check_CQL (sx, rc))
          {
            try
            {
              return sx->cql_stmt->evaluate (*instance);
            }
            catch (const Exception &e) 
            {
	        DDD(cout<<"### exception: selxEvaluate - msg: "<<e.getMessage()<<endl);
                if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_FAILED,
            		(CMPIString*)string2CMPIString(e.getMessage()));
		return false;
            }
            catch (...)
            {
	      DDD(cout<<"### exception: selxEvaluate - ... " <<endl);
              if (rc) CMSetStatus (rc, CMPI_RC_ERR_FAILED);
              return false;
            }
          }
        else
          return false;
      }
#endif
    /* Tried some other weird query language which we don't support */
    if (rc)
      CMSetStatus (rc, CMPI_RC_ERR_NOT_SUPPORTED);
    return false;
  }

  PEGASUS_STATIC CMPIBoolean selxEvaluateUsingAccessor (const CMPISelectExp * eSx,
                                                CMPIAccessor * accessor,
                                                void *parm, CMPIStatus * rc)
  {
    CMPI_SelectExp *sx = (CMPI_SelectExp *) eSx;
    if (!accessor)
      {
        if (rc)
          CMSetStatus (rc, CMPI_RC_ERR_INVALID_PARAMETER);
        return false;
      }

    if (strncmp (sx->lang.getCString (), CALL_SIGN_WQL, CALL_SIGN_WQL_SIZE) ==
        0)
      {
        if (_check_WQL (sx, rc))
          {
            CMPI_SelectExpAccessor_WQL ips (accessor, parm);
            try
            {
              if (rc)
                CMSetStatus (rc, CMPI_RC_OK);
              return sx->wql_stmt->evaluateWhereClause (&ips);
            }
	    catch (const Exception &e) 
            {
	        DDD(cout<<"### exception: selxEvaluateUsingAccessor - msg: "<<e.getMessage()<<endl);
                if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_FAILED,
            		(CMPIString*)string2CMPIString(e.getMessage()));
		return false;
            }
            catch (...)
            {
	      DDD(cout<<"### exception: selxEvaluateUsingAccessor - ..." << endl);
              if (rc)
                CMSetStatus (rc, CMPI_RC_ERR_FAILED);
              return false;
            }
          }
        else
          return false;
      }
#ifndef PEGASUS_DISABLE_CQL
    if (strncmp (sx->lang.getCString (), CALL_SIGN_CQL, CALL_SIGN_CQL_SIZE) ==
        0)
      {
        if (_check_CQL (sx, rc))
          {
            CMPI_SelectExpAccessor_CQL ips (accessor, parm, sx->cql_stmt,
                                            sx->classNames[0]);
            try
            {
              if (rc)
                CMSetStatus (rc, CMPI_RC_OK);
              return sx->cql_stmt->evaluate (ips.getInstance ());
            }
            catch (const Exception &e)
            {
	        DDD(cout<<"### exception: selxEvaluateUsingAccessor - msg: "<<e.getMessage()<<endl);
                if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_FAILED,
            		(CMPIString*)string2CMPIString(e.getMessage()));
		return false;
	    }
            catch (...)
            {
	      DDD(cout<<"### exception: selxEvaluateUsingAccessor - ..." << endl);
              if (rc)
                CMSetStatus (rc, CMPI_RC_ERR_FAILED);
              return false;
            }
          }
        else
          return false;
      }
#endif
    return false;
  }

  PEGASUS_STATIC CMPIString *selxGetString (const CMPISelectExp * eSx, CMPIStatus * rc)
  {
    CMPI_SelectExp *sx = (CMPI_SelectExp *) eSx;
    if (rc)
      CMSetStatus (rc, CMPI_RC_OK);
    return string2CMPIString (sx->cond);
  }

  PEGASUS_STATIC CMPISelectCond *selxGetDOC (const CMPISelectExp * eSx, CMPIStatus * rc)
  {

    CMPI_SelectExp *sx = (CMPI_SelectExp *) eSx;
    CMPISelectCond *sc = NULL;

    if (strncmp (sx->lang.getCString (), CALL_SIGN_WQL, CALL_SIGN_WQL_SIZE) ==
        0)
      {
        if (sx->wql_dnf == NULL)
          {
	   CMPI_Wql2Dnf *dnf = NULL;
	   try 
	   {
            dnf = new CMPI_Wql2Dnf (String (sx->cond), String::EMPTY);
            }
            catch (const Exception &e)
            {
		 DDD(cout<<"### exception: selxGetDOC - msg: "<<e.getMessage()<<endl);

         	if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_FAILED,
            		(CMPIString*)string2CMPIString(e.getMessage()));
                if (dnf)
                  delete dnf;
	       return NULL;
	    }
	    sx->wql_dnf = dnf;
            sx->tableau = sx->wql_dnf->getTableau ();
          }
        sc = (CMPISelectCond *) new CMPI_SelectCond (sx->tableau, 0);
      }
#ifndef PEGASUS_DISABLE_CQL
    if (strncmp (sx->lang.getCString (), CALL_SIGN_CQL, CALL_SIGN_CQL_SIZE) ==
        0)
      {
        if (sx->cql_dnf == NULL)
          {
            /* The constructor should set this to a valid pointer. */
            if (sx->_context == NULL)
              {
                CMSetStatus (rc, CMPI_RC_ERROR_SYSTEM);
                return NULL;
              }

            CQLSelectStatement selectStatement (sx->lang, sx->cond,
                                                *sx->_context);
            CMPI_Cql2Dnf *dnf = NULL;
            try
            {
              CQLParser::parse (sx->cond, selectStatement);
              dnf = new CMPI_Cql2Dnf (selectStatement);
            }
            catch (const Exception &e)
            {
		 DDD(cout<<"### exception: selxGetDOC - msg: "<<e.getMessage()<<endl);

         	if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_FAILED,
            		(CMPIString*)string2CMPIString(e.getMessage()));
                if (dnf)
                  delete dnf;
	       return NULL;
            }
            sx->cql_dnf = dnf;
            sx->tableau = sx->cql_dnf->getTableau ();
          }
        sc = (CMPISelectCond *) new CMPI_SelectCond (sx->tableau, 0);
      }
#endif
    if (sc)
      {
        if (rc)
          CMSetStatus (rc, CMPI_RC_OK);
        CMPI_Object *obj = new CMPI_Object (sc);
        obj->priv = ((CMPI_SelectCond *) sc)->priv;
        return reinterpret_cast < CMPISelectCond * >(obj);
      }

    /* If the sc was null, we just exit */
    if (rc)
      CMSetStatus (rc, CMPI_RC_ERR_FAILED);
    return NULL;
  }

  PEGASUS_STATIC CMPISelectCond *selxGetCOD (const CMPISelectExp * eSx, CMPIStatus * rc)
  {
    if (rc)
      CMSetStatus (rc, CMPI_RC_ERR_NOT_SUPPORTED);
    return NULL;
  }


}

static CMPISelectExpFT selx_FT = {
  CMPICurrentVersion,
  selxRelease,
  selxClone,
  selxEvaluate,
  selxGetString,
  selxGetDOC,
  selxGetCOD,
  selxEvaluateUsingAccessor
};

CMPISelectExpFT *CMPI_SelectExp_Ftab = &selx_FT;

CMPI_SelectExp::~CMPI_SelectExp()
{
  delete wql_stmt;
  delete wql_dnf;
#ifndef PEGASUS_DISABLE_CQL
  delete cql_dnf;
  delete cql_stmt;
#endif
}
CMPI_SelectExp::CMPI_SelectExp (const OperationContext & ct,
                                QueryContext * context, String cond_,
                                String lang_):
ctx (ct),
cond (cond_),
lang (lang_),
_context (context),
persistent(true)
{
  // We do NOT add ourselves to the CMPI_Object as this is a persitent object.
  // Look at the other construtors.
  props = NULL;
  ft = CMPI_SelectExp_Ftab;
  wql_dnf = NULL;
  wql_stmt = NULL;
#ifndef PEGASUS_DISABLE_CQL
  cql_stmt = NULL;
  cql_dnf = NULL;
#endif
  tableau = NULL;
}

CMPI_SelectExp::CMPI_SelectExp (WQLSelectStatement * st):ctx (OperationContext ()),
wql_stmt (st), persistent(false)
{
  // Adding the object to the garbage collector.
  CMPI_ThreadContext::addObject ((CMPI_Object *)this);
  hdl = NULL;
  ft = CMPI_SelectExp_Ftab;
  props = NULL;
  wql_dnf = NULL;
#ifndef PEGASUS_DISABLE_CQL
  cql_dnf = NULL;
  cql_stmt = NULL;
#endif
  tableau = NULL;
  _context = NULL;
  cond = st->getQuery ();
  lang = CALL_SIGN_WQL;
}

#ifndef PEGASUS_DISABLE_CQL
CMPI_SelectExp::CMPI_SelectExp (CQLSelectStatement * st):ctx (OperationContext ()),
cql_stmt (st), persistent(false)
{
  // Adding the object to the garbage collector.
  CMPI_ThreadContext::addObject ((CMPI_Object *)this);
  hdl = NULL;
  ft = CMPI_SelectExp_Ftab;
  props = NULL;
  wql_dnf = NULL;
  cql_dnf = NULL;
  wql_stmt = NULL;
  tableau = NULL;
  _context = NULL;
  cond = st->getQuery ();
  lang = CALL_SIGN_CQL;
  classNames = st->getClassPathList ();
}
#endif
PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2