OW_BinaryRequestHandler.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00036 #include "OW_config.h"
00037 #include "OW_ConfigOpts.hpp"
00038 #include "OW_FileSystem.hpp"
00039 #include "OW_BinaryRequestHandler.hpp"
00040 #include "OW_BinarySerialization.hpp"
00041 #include "OW_Format.hpp"
00042 #include "OW_CIMOMHandleIFC.hpp"
00043 #include "OW_CIMFeatures.hpp"
00044 #include "OW_CIMParamValue.hpp"
00045 #include "OW_SocketUtils.hpp"
00046 #include "OW_CIMException.hpp"
00047 #include "OW_CIMProperty.hpp"
00048 #include "OW_CIMQualifier.hpp"
00049 #include "OW_Mutex.hpp"
00050 #include "OW_MutexLock.hpp"
00051 #include "OW_SocketException.hpp"
00052 #include "OW_ThreadCancelledException.hpp"
00053 #include "OW_Logger.hpp"
00054 #include "OW_OperationContext.hpp"
00055 #include "OW_UserUtils.hpp"
00056 #include "OW_ServiceIFCNames.hpp"
00057 #include "OW_ResultHandlerIFC.hpp"
00058 
00059 #include <exception>
00060 
00061 namespace OW_NAMESPACE
00062 {
00063 
00064 namespace
00065 {
00066    const String COMPONENT_NAME("ow.requesthandler.owbinary");
00067 }
00068 
00069 using namespace WBEMFlags;
00071 BinaryRequestHandler::BinaryRequestHandler()
00072    : RequestHandlerIFC()
00073    , m_userId(UserId(-1))
00074 {
00075 }
00077 RequestHandlerIFC*
00078 BinaryRequestHandler::clone() const
00079 {
00080    return new BinaryRequestHandler(*this);
00081 }
00083 String
00084 BinaryRequestHandler::getName() const
00085 {
00086    return ServiceIFCNames::BinaryRequestHandler;
00087 }
00089 void
00090 BinaryRequestHandler::setEnvironment(const ServiceEnvironmentIFCRef& env)
00091 {
00092    RequestHandlerIFC::setEnvironment(env);
00093 }
00095 void
00096 BinaryRequestHandler::doOptions(CIMFeatures& cf,
00097    OperationContext&)
00098 {
00099    cf.cimom = "openwbem";
00100    cf.cimProduct = CIMFeatures::SERVER;
00101    cf.extURL = "local_binary";
00102    cf.protocolVersion = OW_VERSION;
00103    cf.supportedGroups.clear();
00104    cf.supportedQueryLanguages.clear();
00105    cf.supportedQueryLanguages.append("WQL");
00106    cf.supportsBatch = false;
00107    cf.validation.erase();
00108 }
00110 void
00111 BinaryRequestHandler::doProcess(std::istream* istrm, std::ostream *ostrm,
00112    std::ostream* ostrError, OperationContext& context)
00113 {
00114    clearError();
00115    String userName = context.getStringDataWithDefault(OperationContext::USER_NAME);
00116    if (!userName.empty())
00117    {
00118       bool validUserName = false;
00119       m_userId = UserUtils::getUserId(userName, validUserName);
00120       if (!validUserName)
00121       {
00122          m_userId = UserId(-1);
00123       }
00124    }
00125    UInt8 funcNo = 0;
00126    LoggerRef lgr = getEnvironment()->getLogger(COMPONENT_NAME);
00127    try
00128    {
00129       CIMOMHandleIFCRef chdl = getEnvironment()->getCIMOMHandle(context);
00130       UInt32 version = 0;
00131       BinarySerialization::read(*istrm, version);
00132       if (version < MinBinaryProtocolVersion || version > BinaryProtocolVersion)
00133       {
00134          OW_THROWCIMMSG(CIMException::FAILED, "Incompatible version");
00135       }
00136       BinarySerialization::read(*istrm, funcNo);
00137       try
00138       {
00139          switch (funcNo)
00140          {
00141             case BIN_GETQUAL:
00142                OW_LOG_DEBUG(lgr, "BinaryRequestHandler get qualifier"
00143                   " request");
00144                getQual(chdl, *ostrm, *istrm);
00145                break;
00146 #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00147             case BIN_SETQUAL:
00148                OW_LOG_DEBUG(lgr, "BinaryRequestHandler set qualifier"
00149                   " request");
00150                setQual(chdl, *ostrm, *istrm);
00151                break;
00152             case BIN_DELETEQUAL:
00153                OW_LOG_DEBUG(lgr, "BinaryRequestHandler delete qualifier"
00154                   " request");
00155                deleteQual(chdl, *ostrm, *istrm);
00156                break;
00157             case BIN_ENUMQUALS:
00158                OW_LOG_DEBUG(lgr, "BinaryRequestHandler enum qualifiers"
00159                   " request");
00160                enumQualifiers(chdl, *ostrm, *istrm);
00161                break;
00162 #endif // #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00163             case BIN_GETCLS:
00164                OW_LOG_DEBUG(lgr, "BinaryRequestHandler get class"
00165                   " request");
00166                getClass(chdl, *ostrm, *istrm);
00167                break;
00168 #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00169             case BIN_CREATECLS:
00170                OW_LOG_DEBUG(lgr, "BinaryRequestHandler create class"
00171                   " request");
00172                createClass(chdl, *ostrm, *istrm);
00173                break;
00174             case BIN_MODIFYCLS:
00175                OW_LOG_DEBUG(lgr, "BinaryRequestHandler modify class"
00176                   " request");
00177                modifyClass(chdl, *ostrm, *istrm);
00178                break;
00179             case BIN_DELETECLS:
00180                OW_LOG_DEBUG(lgr, "BinaryRequestHandler delete class"
00181                   " request");
00182                deleteClass(chdl, *ostrm, *istrm);
00183                break;
00184 #endif // #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00185             case BIN_ENUMCLSS:
00186                OW_LOG_DEBUG(lgr, "BinaryRequestHandler enum classes"
00187                   " request");
00188                enumClasses(chdl, *ostrm, *istrm);
00189                break;
00190             case BIN_GETINST:
00191                OW_LOG_DEBUG(lgr, "BinaryRequestHandler get instance"
00192                   " request");
00193                getInstance(chdl, *ostrm, *istrm);
00194                break;
00195 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00196             case BIN_CREATEINST:
00197                OW_LOG_DEBUG(lgr, "BinaryRequestHandler create instance"
00198                   " request");
00199                createInstance(chdl, *ostrm, *istrm);
00200                break;
00201             case BIN_MODIFYINST:
00202                OW_LOG_DEBUG(lgr, "BinaryRequestHandler get instance"
00203                   " request");
00204                modifyInstance(chdl, *ostrm, *istrm);
00205                break;
00206             case BIN_DELETEINST:
00207                OW_LOG_DEBUG(lgr, "BinaryRequestHandler delete instance"
00208                   " request");
00209                deleteInstance(chdl, *ostrm, *istrm);
00210                break;
00211 #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00212             case BIN_SETPROP:
00213                OW_LOG_DEBUG(lgr, "BinaryRequestHandler set property"
00214                   " request");
00215                setProperty(chdl, *ostrm, *istrm);
00216                break;
00217 #endif // #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00218 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00219 #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00220             case BIN_GETPROP:
00221                OW_LOG_DEBUG(lgr, "BinaryRequestHandler get property"
00222                   " request");
00223                getProperty(chdl, *ostrm, *istrm);
00224                break;
00225 #endif // #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00226             case BIN_ENUMCLSNAMES:
00227                OW_LOG_DEBUG(lgr, "BinaryRequestHandler enum class names"
00228                   " request");
00229                enumClassNames(chdl, *ostrm, *istrm);
00230                break;
00231             case BIN_ENUMINSTS:
00232                OW_LOG_DEBUG(lgr, "BinaryRequestHandler enum instances"
00233                   " request");
00234                enumInstances(chdl, *ostrm, *istrm);
00235                break;
00236             case BIN_ENUMINSTNAMES:
00237                OW_LOG_DEBUG(lgr, "BinaryRequestHandler enum instance"
00238                   " names request");
00239                enumInstanceNames(chdl, *ostrm, *istrm);
00240                break;
00241             case BIN_INVMETH:
00242                OW_LOG_DEBUG(lgr, "BinaryRequestHandler invoke method"
00243                   " request");
00244                invokeMethod(chdl, *ostrm, *istrm);
00245                break;
00246             case BIN_EXECQUERY:
00247                OW_LOG_DEBUG(lgr, "BinaryRequestHandler exec query"
00248                   " request");
00249                execQuery(chdl, *ostrm, *istrm);
00250                break;
00251 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00252             case BIN_ASSOCIATORS:
00253                OW_LOG_DEBUG(lgr, "BinaryRequestHandler associators"
00254                   " request");
00255                associators(chdl, *ostrm, *istrm);
00256                break;
00257             case BIN_ASSOCNAMES:
00258                OW_LOG_DEBUG(lgr, "BinaryRequestHandler associator names"
00259                   " request");
00260                associatorNames(chdl, *ostrm, *istrm);
00261                break;
00262             case BIN_REFERENCES:
00263                OW_LOG_DEBUG(lgr, "BinaryRequestHandler references"
00264                   " request");
00265                references(chdl, *ostrm, *istrm);
00266                break;
00267             case BIN_REFNAMES:
00268                OW_LOG_DEBUG(lgr, "BinaryRequestHandler reference names"
00269                   " request");
00270                referenceNames(chdl, *ostrm, *istrm);
00271                break;
00272 #endif
00273             case BIN_GETSVRFEATURES:
00274                OW_LOG_DEBUG(lgr, "BinaryRequestHandler get server"
00275                   " features request");
00276                getServerFeatures(chdl, *ostrm, *istrm);
00277                break;
00278             default:
00279                OW_LOG_DEBUG(lgr, Format("BinaryRequestHandler: Received"
00280                   " invalid function number: %1", funcNo));
00281                writeError(*ostrError, "Invalid function number");
00282                break;
00283          }
00284       }
00285       catch(CIMException& e)
00286       {
00287          OW_LOG_INFO(lgr, Format("CIM Exception caught in"
00288             " BinaryRequestHandler: %1", e));
00289          BinarySerialization::write(*ostrError, BIN_EXCEPTION);
00290          BinarySerialization::write(*ostrError, UInt16(e.getErrNo()));
00291          BinarySerialization::write(*ostrError, e.getMessage());
00292          setError(e.getErrNo(), e.getDescription());
00293       }
00294    }
00295    catch(Exception& e)
00296    {
00297       OW_LOG_ERROR(lgr, "Exception caught in BinaryRequestHandler");
00298       OW_LOG_ERROR(lgr, Format("Type: %1", e.type()));
00299       OW_LOG_ERROR(lgr, Format("File: %1", e.getFile()));
00300       OW_LOG_ERROR(lgr, Format("Line: %1", e.getLine()));
00301       OW_LOG_ERROR(lgr, Format("Msg: %1", e.getMessage()));
00302       writeError(*ostrError, Format("BinaryRequestHandler caught exception: %1", e).c_str());
00303       setError(CIMException::FAILED, e.getMessage());
00304       
00305    }
00306    catch(std::exception& e)
00307    {
00308       OW_LOG_ERROR(lgr, Format("Caught %1 exception in BinaryRequestHandler",
00309          e.what()));
00310       writeError(*ostrError, Format("BinaryRequestHandler caught exception: %1", e.what()).c_str());
00311       setError(CIMException::FAILED, e.what());
00312    }
00313    catch (ThreadCancelledException&)
00314    {
00315       OW_LOG_ERROR(lgr, "Thread cancelled in BinaryRequestHandler");
00316       writeError(*ostrError, "Thread cancelled");
00317       setError(CIMException::FAILED, "Thread cancelled");
00318       throw;
00319    }
00320    catch(...)
00321    {
00322       OW_LOG_ERROR(lgr, "Unknown exception caught in BinaryRequestHandler");
00323       writeError(*ostrError, "BinaryRequestHandler caught unknown exception");
00324       setError(CIMException::FAILED, "Caught unknown exception");
00325    }
00326 }
00327 #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00328 
00329 void
00330 BinaryRequestHandler::createClass(const CIMOMHandleIFCRef& chdl,
00331    std::ostream& ostrm, std::istream& istrm)
00332 {
00333    String ns(BinarySerialization::readString(istrm));
00334    CIMClass cc(BinarySerialization::readClass(istrm));
00335    chdl->createClass(ns, cc);
00336    BinarySerialization::write(ostrm, BIN_OK);
00337 }
00339 void
00340 BinaryRequestHandler::modifyClass(const CIMOMHandleIFCRef& chdl,
00341    std::ostream& ostrm, std::istream& istrm)
00342 {
00343    String ns(BinarySerialization::readString(istrm));
00344    CIMClass cc(BinarySerialization::readClass(istrm));
00345    chdl->modifyClass(ns, cc);
00346    BinarySerialization::write(ostrm, BIN_OK);
00347 }
00349 void
00350 BinaryRequestHandler::deleteClass(const CIMOMHandleIFCRef& chdl,
00351    std::ostream& ostrm, std::istream& istrm)
00352 {
00353    String ns(BinarySerialization::readString(istrm));
00354    String className(BinarySerialization::readString(istrm));
00355    chdl->deleteClass(ns, className);
00356    BinarySerialization::write(ostrm, BIN_OK);
00357 }
00358 #endif // #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00359 
00360 namespace
00361 {
00362    class BinaryCIMClassWriter : public CIMClassResultHandlerIFC
00363    {
00364    public:
00365       BinaryCIMClassWriter(std::ostream& ostrm_)
00366       : ostrm(ostrm_)
00367       {}
00368    protected:
00369       virtual void doHandle(const CIMClass &c)
00370       {
00371          BinarySerialization::writeClass(ostrm, c);
00372       }
00373    private:
00374       std::ostream& ostrm;
00375    };
00376    class BinaryCIMObjectPathWriter : public CIMObjectPathResultHandlerIFC
00377    {
00378    public:
00379       BinaryCIMObjectPathWriter(std::ostream& ostrm_, const String& host_)
00380       : ostrm(ostrm_)
00381       , m_host(host_)
00382       {}
00383    protected:
00384       virtual void doHandle(const CIMObjectPath &cop_)
00385       {
00386          // Make sure all outgoing object paths have our host name, instead of 127.0.0.1
00387          CIMObjectPath cop(cop_);
00388          if (cop.getFullNameSpace().isLocal())
00389          {
00390             try
00391             {
00392                cop.setHost(m_host);
00393             }
00394             catch (const SocketException& e)
00395             {
00396             }
00397          }
00398          BinarySerialization::writeObjectPath(ostrm, cop);
00399       }
00400    private:
00401       std::ostream& ostrm;
00402       String m_host;
00403    };
00404    class BinaryCIMInstanceWriter : public CIMInstanceResultHandlerIFC
00405    {
00406    public:
00407       BinaryCIMInstanceWriter(std::ostream& ostrm_, const String& ns_)
00408       : ostrm(ostrm_)
00409       , ns(ns_)
00410       {}
00411    protected:
00412       virtual void doHandle(const CIMInstance &cop)
00413       {
00414          if (cop.getNameSpace().empty())
00415          {
00416             CIMInstance ci(cop);
00417             ci.setNameSpace(ns);
00418             BinarySerialization::writeInstance(ostrm, ci);
00419          }
00420          else
00421          {
00422             BinarySerialization::writeInstance(ostrm, cop);
00423          }
00424       }
00425    private:
00426       std::ostream& ostrm;
00427       String ns;
00428    };
00429    class BinaryCIMQualifierTypeWriter : public CIMQualifierTypeResultHandlerIFC
00430    {
00431    public:
00432       BinaryCIMQualifierTypeWriter(std::ostream& ostrm_)
00433       : ostrm(ostrm_)
00434       {}
00435    protected:
00436       virtual void doHandle(const CIMQualifierType &cqt)
00437       {
00438          BinarySerialization::writeQualType(ostrm, cqt);
00439       }
00440    private:
00441       std::ostream& ostrm;
00442    };
00443    class BinaryStringWriter : public StringResultHandlerIFC
00444    {
00445    public:
00446       BinaryStringWriter(std::ostream& ostrm_)
00447       : ostrm(ostrm_)
00448       {}
00449    protected:
00450       virtual void doHandle(const String &name)
00451       {
00452          BinarySerialization::writeString(ostrm, name);
00453       }
00454    private:
00455       std::ostream& ostrm;
00456       String ns;
00457    };
00458 }
00460 void
00461 BinaryRequestHandler::enumClasses(const CIMOMHandleIFCRef& chdl,
00462    std::ostream& ostrm, std::istream& istrm)
00463 {
00464    String ns(BinarySerialization::readString(istrm));
00465    String className(BinarySerialization::readString(istrm));
00466    EDeepFlag deep(BinarySerialization::readBool(istrm) ? E_DEEP : E_SHALLOW);
00467    ELocalOnlyFlag localOnly(BinarySerialization::readBool(istrm) ? E_LOCAL_ONLY : E_NOT_LOCAL_ONLY);
00468    EIncludeQualifiersFlag includeQualifiers(BinarySerialization::readBool(istrm) ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS);
00469    EIncludeClassOriginFlag includeClassOrigin(BinarySerialization::readBool(istrm) ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN);
00470    BinarySerialization::write(ostrm, BIN_OK);
00471    BinarySerialization::write(ostrm, BINSIG_CLSENUM);
00472    BinaryCIMClassWriter handler(ostrm);
00473    chdl->enumClass(ns, className, handler, deep, localOnly,
00474       includeQualifiers, includeClassOrigin);
00475    
00476    BinarySerialization::write(ostrm, END_CLSENUM);
00477    BinarySerialization::write(ostrm, END_CLSENUM);
00478 }
00479 #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00480 
00481 void
00482 BinaryRequestHandler::deleteQual(const CIMOMHandleIFCRef& chdl,
00483    std::ostream& ostrm, std::istream& istrm)
00484 {
00485    String ns(BinarySerialization::readString(istrm));
00486    String qualName(BinarySerialization::readString(istrm));
00487    chdl->deleteQualifierType(ns, qualName);
00488    BinarySerialization::write(ostrm, BIN_OK);
00489 }
00491 void
00492 BinaryRequestHandler::setQual(const CIMOMHandleIFCRef& chdl,
00493    std::ostream& ostrm, std::istream& istrm)
00494 {
00495    String ns(BinarySerialization::readString(istrm));
00496    CIMQualifierType qt(BinarySerialization::readQualType(istrm));
00497    chdl->setQualifierType(ns, qt);
00498    BinarySerialization::write(ostrm, BIN_OK);
00499 }
00501 void
00502 BinaryRequestHandler::enumQualifiers(const CIMOMHandleIFCRef& chdl,
00503    std::ostream& ostrm, std::istream& istrm)
00504 {
00505    String ns(BinarySerialization::readString(istrm));
00506    BinarySerialization::write(ostrm, BIN_OK);
00507    BinarySerialization::write(ostrm, BINSIG_QUAL_TYPEENUM);
00508    BinaryCIMQualifierTypeWriter handler(ostrm);
00509    chdl->enumQualifierTypes(ns, handler);
00510    BinarySerialization::write(ostrm, END_QUALENUM);
00511    BinarySerialization::write(ostrm, END_QUALENUM);
00512 }
00513 #endif // #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00514 
00515 void
00516 BinaryRequestHandler::getClass(const CIMOMHandleIFCRef& chdl,
00517    std::ostream& ostrm, std::istream& istrm)
00518 {
00519    StringArray propList;
00520    StringArray* propListPtr = 0;
00521    String ns(BinarySerialization::readString(istrm));
00522    String className(BinarySerialization::readString(istrm));
00523    ELocalOnlyFlag localOnly(BinarySerialization::readBool(istrm) ? E_LOCAL_ONLY : E_NOT_LOCAL_ONLY);
00524    EIncludeQualifiersFlag includeQualifiers(BinarySerialization::readBool(istrm) ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS);
00525    EIncludeClassOriginFlag includeClassOrigin(BinarySerialization::readBool(istrm) ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN);
00526    Bool nullPropertyList(BinarySerialization::readBool(istrm));
00527    if (!nullPropertyList)
00528    {
00529       propList = BinarySerialization::readStringArray(istrm);
00530       propListPtr = &propList;
00531    }
00532    CIMClass cc = chdl->getClass(ns, className, localOnly, includeQualifiers,
00533       includeClassOrigin, propListPtr);
00534    BinarySerialization::write(ostrm, BIN_OK);
00535    BinarySerialization::writeClass(ostrm, cc);
00536 }
00538 void
00539 BinaryRequestHandler::getInstance(const CIMOMHandleIFCRef& chdl,
00540    std::ostream& ostrm, std::istream& istrm)
00541 {
00542    String ns(BinarySerialization::readString(istrm));
00543    CIMObjectPath op(BinarySerialization::readObjectPath(istrm));
00544    ELocalOnlyFlag localOnly(BinarySerialization::readBool(istrm) ? E_LOCAL_ONLY : E_NOT_LOCAL_ONLY);
00545    EIncludeQualifiersFlag includeQualifiers(BinarySerialization::readBool(istrm) ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS);
00546    EIncludeClassOriginFlag includeClassOrigin(BinarySerialization::readBool(istrm) ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN);
00547    StringArray propList;
00548    StringArray* propListPtr = 0;
00549    Bool nullPropertyList(BinarySerialization::readBool(istrm));
00550    if (!nullPropertyList)
00551    {
00552       propList = BinarySerialization::readStringArray(istrm);
00553       propListPtr = &propList;
00554    }
00555    CIMInstance cimInstance = chdl->getInstance(ns, op, localOnly,
00556       includeQualifiers, includeClassOrigin, propListPtr);
00557    if (cimInstance.getNameSpace().empty())
00558       cimInstance.setNameSpace(ns);
00559    BinarySerialization::write(ostrm, BIN_OK);
00560    BinarySerialization::writeInstance(ostrm, cimInstance);
00561 }
00563 void
00564 BinaryRequestHandler::getQual(const CIMOMHandleIFCRef& chdl,
00565    std::ostream& ostrm, std::istream& istrm)
00566 {
00567    String ns(BinarySerialization::readString(istrm));
00568    String qualifierName(BinarySerialization::readString(istrm));
00569    CIMQualifierType qt = chdl->getQualifierType(ns, qualifierName);
00570    BinarySerialization::write(ostrm, BIN_OK);
00571    BinarySerialization::writeQualType(ostrm, qt);
00572 }
00573 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00574 
00575 void
00576 BinaryRequestHandler::createInstance(const CIMOMHandleIFCRef& chdl,
00577    std::ostream& ostrm, std::istream& istrm)
00578 {
00579    String ns(BinarySerialization::readString(istrm));
00580    CIMInstance cimInstance(BinarySerialization::readInstance(istrm));
00581    CIMName className = cimInstance.getClassName();
00582    //CIMObjectPath realPath(className, path.getNameSpace());
00583    // Special treatment for __Namespace class
00584    if (className == "__Namespace")
00585    {
00586       CIMProperty prop = cimInstance.getProperty(
00587          CIMProperty::NAME_PROPERTY);
00588       // Need the name property since it contains the name of the new
00589       // name space
00590       if (!prop)
00591       {
00592          OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00593             "Name property not specified for new namespace");
00594       }
00595       // If the name property didn't come acrossed as a key, then
00596       // set the name property as the key
00597       if (!prop.isKey())
00598       {
00599          prop.addQualifier(CIMQualifier::createKeyQualifier());
00600       }
00601       cimInstance.setProperty(prop);
00602    }
00603    /* This should be done in the CIM Server
00604    CIMPropertyArray keys = cimInstance.getKeyValuePairs();
00605    if (keys.size() == 0)
00606    {
00607       OW_THROWCIMMSG(CIMException::FAILED,"Instance doesn't have keys");
00608    }
00609    for (size_t i = 0; i < keys.size(); ++i)
00610    {
00611       CIMProperty key = keys[i];
00612       if (!key.getValue())
00613       {
00614          OW_THROWCIMMSG(CIMException::FAILED,
00615             Format("Key must be provided!  Property \"%1\" does not have a "
00616                "valid value.", key.getName()).c_str());
00617       }
00618    }
00619    realPath.setKeys(keys);
00620    */
00621    CIMObjectPath newPath = chdl->createInstance(ns, cimInstance);
00622    BinarySerialization::write(ostrm, BIN_OK);
00623    BinarySerialization::writeObjectPath(ostrm, newPath);
00624 }
00626 void
00627 BinaryRequestHandler::deleteInstance(const CIMOMHandleIFCRef& chdl,
00628    std::ostream& ostrm, std::istream& istrm)
00629 {
00630    String ns(BinarySerialization::readString(istrm));
00631    CIMObjectPath op(BinarySerialization::readObjectPath(istrm));
00632    chdl->deleteInstance(ns, op);
00633    BinarySerialization::write(ostrm, BIN_OK);
00634 }
00636 void
00637 BinaryRequestHandler::modifyInstance(const CIMOMHandleIFCRef& chdl,
00638    std::ostream& ostrm, std::istream& istrm)
00639 {
00640    String ns(BinarySerialization::readString(istrm));
00641    CIMInstance ci(BinarySerialization::readInstance(istrm));
00642    EIncludeQualifiersFlag includeQualifiers(BinarySerialization::readBool(istrm) ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS);
00643    StringArray propList;
00644    StringArray* propListPtr = 0;
00645    Bool nullPropertyList(BinarySerialization::readBool(istrm));
00646    if (!nullPropertyList)
00647    {
00648       propList = BinarySerialization::readStringArray(istrm);
00649       propListPtr = &propList;
00650    }
00651    chdl->modifyInstance(ns, ci, includeQualifiers, propListPtr);
00652    BinarySerialization::write(ostrm, BIN_OK);
00653 }
00654 #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00655 
00656 void
00657 BinaryRequestHandler::setProperty(const CIMOMHandleIFCRef& chdl,
00658    std::ostream& ostrm, std::istream& istrm)
00659 {
00660    String ns(BinarySerialization::readString(istrm));
00661    CIMObjectPath op(BinarySerialization::readObjectPath(istrm));
00662    String propName(BinarySerialization::readString(istrm));
00663    Bool isValue(BinarySerialization::readBool(istrm));
00664    CIMValue cv(CIMNULL);
00665    if (isValue)
00666    {
00667       cv = BinarySerialization::readValue(istrm);
00668    }
00669    chdl->setProperty(ns, op, propName, cv);
00670    BinarySerialization::write(ostrm, BIN_OK);
00671 }
00672 #endif // #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00673 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00674 
00675 #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00676 
00677 void
00678 BinaryRequestHandler::getProperty(const CIMOMHandleIFCRef& chdl,
00679    std::ostream& ostrm, std::istream& istrm)
00680 {
00681    String ns (BinarySerialization::readString(istrm));
00682    CIMObjectPath op(BinarySerialization::readObjectPath(istrm));
00683    String propName(BinarySerialization::readString(istrm));
00684    CIMValue cv = chdl->getProperty(ns, op, propName);
00685    BinarySerialization::write(ostrm, BIN_OK);
00686    Bool isValue = (cv) ? true : false;
00687    BinarySerialization::writeBool(ostrm, isValue);
00688    if (isValue)
00689    {
00690       BinarySerialization::writeValue(ostrm, cv);
00691    }
00692 }
00693 #endif // #if !defined(OW_DISABLE_PROPERTY_OPERATIONS)
00694 
00695 void
00696 BinaryRequestHandler::enumClassNames(const CIMOMHandleIFCRef& chdl,
00697    std::ostream& ostrm, std::istream& istrm)
00698 {
00699    String ns(BinarySerialization::readString(istrm));
00700    String className(BinarySerialization::readString(istrm));
00701    EDeepFlag deep(BinarySerialization::readBool(istrm) ? E_DEEP : E_SHALLOW);
00702    BinarySerialization::write(ostrm, BIN_OK);
00703    BinarySerialization::write(ostrm, BINSIG_STRINGENUM);
00704    BinaryStringWriter handler(ostrm);
00705    chdl->enumClassNames(ns, className, handler, deep);
00706    BinarySerialization::write(ostrm, END_STRINGENUM);
00707    BinarySerialization::write(ostrm, END_STRINGENUM);
00708 }
00710 void
00711 BinaryRequestHandler::enumInstances(const CIMOMHandleIFCRef& chdl,
00712    std::ostream& ostrm, std::istream& istrm)
00713 {
00714    StringArray propList;
00715    StringArray* propListPtr = 0;
00716    String ns(BinarySerialization::readString(istrm));
00717    String className(BinarySerialization::readString(istrm));
00718    EDeepFlag deep(BinarySerialization::readBool(istrm) ? E_DEEP : E_SHALLOW);
00719    ELocalOnlyFlag localOnly(BinarySerialization::readBool(istrm) ? E_LOCAL_ONLY : E_NOT_LOCAL_ONLY);
00720    EIncludeQualifiersFlag includeQualifiers(BinarySerialization::readBool(istrm) ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS);
00721    EIncludeClassOriginFlag includeClassOrigin(BinarySerialization::readBool(istrm) ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN);
00722    Bool nullPropertyList(BinarySerialization::readBool(istrm));
00723    if (!nullPropertyList)
00724    {
00725       propList = BinarySerialization::readStringArray(istrm);
00726       propListPtr = &propList;
00727    }
00728    BinarySerialization::write(ostrm, BIN_OK);
00729    BinarySerialization::write(ostrm, BINSIG_INSTENUM);
00730    
00731    BinaryCIMInstanceWriter handler(ostrm, ns);
00732    chdl->enumInstances(ns, className, handler, deep, localOnly,
00733       includeQualifiers, includeClassOrigin, propListPtr);
00734    BinarySerialization::write(ostrm, END_INSTENUM);
00735    BinarySerialization::write(ostrm, END_INSTENUM);
00736 }
00738 void
00739 BinaryRequestHandler::enumInstanceNames(const CIMOMHandleIFCRef& chdl,
00740    std::ostream& ostrm, std::istream& istrm)
00741 {
00742    String ns(BinarySerialization::readString(istrm));
00743    String className(BinarySerialization::readString(istrm));
00744    BinarySerialization::write(ostrm, BIN_OK);
00745    BinarySerialization::write(ostrm, BINSIG_OPENUM);
00746    BinaryCIMObjectPathWriter handler(ostrm, getHost());
00747    chdl->enumInstanceNames(ns, className, handler);
00748    BinarySerialization::write(ostrm, END_OPENUM);
00749    BinarySerialization::write(ostrm, END_OPENUM);
00750 }
00752 void
00753 BinaryRequestHandler::invokeMethod(const CIMOMHandleIFCRef& chdl,
00754    std::ostream& ostrm, std::istream& istrm)
00755 {
00756    String ns (BinarySerialization::readString(istrm));
00757    CIMObjectPath path(BinarySerialization::readObjectPath(istrm));
00758    String methodName(BinarySerialization::readString(istrm));
00759    CIMParamValueArray inparms;
00760    CIMParamValueArray outparms;
00761    // Get input params
00762    BinarySerialization::verifySignature(istrm, BINSIG_PARAMVALUEARRAY);
00763    BinarySerialization::readArray(istrm, inparms);
00764    CIMValue cv = chdl->invokeMethod(ns, path, methodName, inparms, outparms);
00765    BinarySerialization::write(ostrm, BIN_OK);
00766    if (cv)
00767    {
00768       BinarySerialization::writeBool(ostrm, Bool(true));
00769       BinarySerialization::writeValue(ostrm, cv);
00770    }
00771    else
00772    {
00773       BinarySerialization::writeBool(ostrm, Bool(false));
00774    }
00775    BinarySerialization::write(ostrm, BINSIG_PARAMVALUEARRAY);
00776    BinarySerialization::writeArray(ostrm, outparms);
00777 }
00779 void
00780 BinaryRequestHandler::execQuery(const CIMOMHandleIFCRef& chdl,
00781    std::ostream& ostrm, std::istream& istrm)
00782 {
00783    String ns(BinarySerialization::readString(istrm));
00784    String query(BinarySerialization::readString(istrm));
00785    String queryLang(BinarySerialization::readString(istrm));
00786    BinarySerialization::write(ostrm, BIN_OK);
00787    BinarySerialization::write(ostrm, BINSIG_INSTENUM);
00788    BinaryCIMInstanceWriter handler(ostrm, ns);
00789    chdl->execQuery(ns, handler, query, queryLang);
00790    BinarySerialization::write(ostrm, END_INSTENUM);
00791    BinarySerialization::write(ostrm, END_INSTENUM);
00792 }
00793 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00794 
00795 void
00796 BinaryRequestHandler::associators(const CIMOMHandleIFCRef& chdl,
00797    std::ostream& ostrm, std::istream& istrm)
00798 {
00799    StringArray propList;
00800    StringArray* propListPtr = 0;
00801    String ns(BinarySerialization::readString(istrm));
00802    CIMObjectPath op(BinarySerialization::readObjectPath(istrm));
00803    String assocClass(BinarySerialization::readString(istrm));
00804    String resultClass(BinarySerialization::readString(istrm));
00805    String role(BinarySerialization::readString(istrm));
00806    String resultRole(BinarySerialization::readString(istrm));
00807    EIncludeQualifiersFlag includeQualifiers(BinarySerialization::readBool(istrm) ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS);
00808    EIncludeClassOriginFlag includeClassOrigin(BinarySerialization::readBool(istrm) ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN);
00809    Bool nullPropertyList(BinarySerialization::readBool(istrm));
00810    if (!nullPropertyList)
00811    {
00812       propList = BinarySerialization::readStringArray(istrm);
00813       propListPtr = &propList;
00814    }
00815    BinarySerialization::write(ostrm, BIN_OK);
00816    if (op.isClassPath())
00817    {
00818       // class path
00819       BinarySerialization::write(ostrm, BINSIG_CLSENUM);
00820       BinaryCIMClassWriter handler(ostrm);
00821       op.setNameSpace(ns);
00822       chdl->associatorsClasses(ns, op, handler, assocClass, resultClass,
00823          role, resultRole, includeQualifiers, includeClassOrigin, propListPtr);
00824       BinarySerialization::write(ostrm, END_CLSENUM);
00825       BinarySerialization::write(ostrm, END_CLSENUM);
00826    }
00827    else
00828    {
00829       // instance path
00830       BinarySerialization::write(ostrm, BINSIG_INSTENUM);
00831       BinaryCIMInstanceWriter handler(ostrm, ns);
00832       chdl->associators(ns, op, handler, assocClass, resultClass,
00833          role, resultRole, includeQualifiers, includeClassOrigin, propListPtr);
00834       BinarySerialization::write(ostrm, END_INSTENUM);
00835       BinarySerialization::write(ostrm, END_INSTENUM);
00836    }
00837 }
00839 void
00840 BinaryRequestHandler::associatorNames(const CIMOMHandleIFCRef& chdl,
00841    std::ostream& ostrm, std::istream& istrm)
00842 {
00843    String ns(BinarySerialization::readString(istrm));
00844    CIMObjectPath op(BinarySerialization::readObjectPath(istrm));
00845    String assocClass(BinarySerialization::readString(istrm));
00846    String resultClass(BinarySerialization::readString(istrm));
00847    String role(BinarySerialization::readString(istrm));
00848    String resultRole(BinarySerialization::readString(istrm));
00849    BinarySerialization::write(ostrm, BIN_OK);
00850    BinarySerialization::write(ostrm, BINSIG_OPENUM);
00851    BinaryCIMObjectPathWriter handler(ostrm, getHost());
00852    chdl->associatorNames(ns, op, handler, assocClass,
00853       resultClass, role, resultRole);
00854    BinarySerialization::write(ostrm, END_OPENUM);
00855    BinarySerialization::write(ostrm, END_OPENUM);
00856 }
00858 void
00859 BinaryRequestHandler::references(const CIMOMHandleIFCRef& chdl,
00860    std::ostream& ostrm, std::istream& istrm)
00861 {
00862    StringArray propList;
00863    StringArray* propListPtr = 0;
00864    String ns(BinarySerialization::readString(istrm));
00865    CIMObjectPath op(BinarySerialization::readObjectPath(istrm));
00866    String resultClass(BinarySerialization::readString(istrm));
00867    String role(BinarySerialization::readString(istrm));
00868    EIncludeQualifiersFlag includeQualifiers(BinarySerialization::readBool(istrm) ? E_INCLUDE_QUALIFIERS : E_EXCLUDE_QUALIFIERS);
00869    EIncludeClassOriginFlag includeClassOrigin(BinarySerialization::readBool(istrm) ? E_INCLUDE_CLASS_ORIGIN : E_EXCLUDE_CLASS_ORIGIN);
00870    Bool nullPropertyList(BinarySerialization::readBool(istrm));
00871    if (!nullPropertyList)
00872    {
00873       propList = BinarySerialization::readStringArray(istrm);
00874       propListPtr = &propList;
00875    }
00876    BinarySerialization::write(ostrm, BIN_OK);
00877    if (op.isClassPath())
00878    {
00879       // class path
00880       BinarySerialization::write(ostrm, BINSIG_CLSENUM);
00881       BinaryCIMClassWriter handler(ostrm);
00882       chdl->referencesClasses(ns, op, handler, resultClass,
00883          role, includeQualifiers, includeClassOrigin, propListPtr);
00884       BinarySerialization::write(ostrm, END_CLSENUM);
00885       BinarySerialization::write(ostrm, END_CLSENUM);
00886    }
00887    else
00888    {
00889       // instance path
00890       BinarySerialization::write(ostrm, BINSIG_INSTENUM);
00891       BinaryCIMInstanceWriter handler(ostrm, ns);
00892       chdl->references(ns, op, handler, resultClass,
00893          role, includeQualifiers, includeClassOrigin, propListPtr);
00894       BinarySerialization::write(ostrm, END_INSTENUM);
00895       BinarySerialization::write(ostrm, END_INSTENUM);
00896    }
00897 }
00899 void
00900 BinaryRequestHandler::referenceNames(const CIMOMHandleIFCRef& chdl,
00901    std::ostream& ostrm, std::istream& istrm)
00902 {
00903    String ns(BinarySerialization::readString(istrm));
00904    CIMObjectPath op(BinarySerialization::readObjectPath(istrm));
00905    String resultClass(BinarySerialization::readString(istrm));
00906    String role(BinarySerialization::readString(istrm));
00907    BinarySerialization::write(ostrm, BIN_OK);
00908    BinarySerialization::write(ostrm, BINSIG_OPENUM);
00909    BinaryCIMObjectPathWriter handler(ostrm, getHost());
00910    chdl->referenceNames(ns, op, handler, resultClass, role);
00911    BinarySerialization::write(ostrm, END_OPENUM);
00912    BinarySerialization::write(ostrm, END_OPENUM);
00913 }
00914 #endif
00915 
00916 void
00917 BinaryRequestHandler::getServerFeatures(const CIMOMHandleIFCRef& chdl,
00918    std::ostream& ostrm, std::istream& /*istrm*/)
00919 {
00920    CIMFeatures f = chdl->getServerFeatures();
00921    BinarySerialization::write(ostrm, BIN_OK);
00922    BinarySerialization::write(ostrm, Int32(f.cimProduct));
00923    BinarySerialization::writeString(ostrm, f.extURL);
00924    BinarySerialization::writeStringArray(ostrm, f.supportedGroups);
00925    BinarySerialization::writeBool(ostrm, f.supportsBatch);
00926    BinarySerialization::writeStringArray(ostrm, f.supportedQueryLanguages);
00927    BinarySerialization::writeString(ostrm, f.validation);
00928    BinarySerialization::writeString(ostrm, f.cimom);
00929    BinarySerialization::writeString(ostrm, f.protocolVersion);
00930 }
00932 void
00933 BinaryRequestHandler::writeError(std::ostream& ostrm, const char* msg)
00934 {
00935    BinarySerialization::write(ostrm, BIN_ERROR);
00936    BinarySerialization::write(ostrm, msg);
00937 }
00939 bool
00940 BinaryRequestHandler::writeFileName(std::ostream& ostrm,
00941    const String& fname)
00942 {
00943    LoggerRef lgr = getEnvironment()->getLogger(COMPONENT_NAME);
00944    if (m_userId == UserId(-1))
00945    {
00946       OW_LOG_ERROR(lgr, "Binary request handler cannot change file ownership:"
00947          " Owner unknown");
00948       return false;
00949    }
00950    try
00951    {
00952       if (FileSystem::changeFileOwner(fname, m_userId) != 0)
00953       {
00954          OW_LOG_ERROR(lgr, Format("Binary request handler failed changing"
00955             " ownership on file %1", fname));
00956          return false;
00957       }
00958       // Write -1 to indicate file name follows
00959       BinarySerialization::write(ostrm, Int32(-1));
00960       // Write file name
00961       BinarySerialization::writeString(ostrm, fname);
00962    }
00963    catch(...)
00964    {
00965       FileSystem::removeFile(fname);
00966       throw;
00967    }
00968    return true;
00969 }
00971 StringArray
00972 BinaryRequestHandler::getSupportedContentTypes() const
00973 {
00974    StringArray rval;
00975    rval.push_back("application/x-owbinary");
00976    return rval;
00977 }
00979 String
00980 BinaryRequestHandler::getContentType() const
00981 {
00982    return String("application/x-owbinary");
00983 }
00984 
00986 void
00987 BinaryRequestHandler::init(const ServiceEnvironmentIFCRef& env)
00988 {
00989 }
00990 
00992 void
00993 BinaryRequestHandler::shutdown()
00994 {
00995 }
00996 
00997 } // end namespace OW_NAMESPACE
00998 
01000 OW_REQUEST_HANDLER_FACTORY(OW_NAMESPACE::BinaryRequestHandler,BinaryRequest);
01001 

Generated on Thu Feb 9 08:47:52 2006 for openwbem by  doxygen 1.4.6