⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cimoperationrequestdecoder.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//%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.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <cctype>#include <cstdio>#include <Pegasus/Common/XmlParser.h>#include <Pegasus/Common/XmlReader.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/XmlConstants.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/Logger.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/Common/StatisticalData.h>#include "CIMOperationRequestDecoder.h"#include <Pegasus/Common/CommonUTF.h>#include <Pegasus/Common/MessageLoader.h>PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGINCIMOperationRequestDecoder::CIMOperationRequestDecoder(    MessageQueueService* outputQueue,    Uint32 returnQueueId)    : Base(PEGASUS_QUEUENAME_OPREQDECODER),      _outputQueue(outputQueue),      _returnQueueId(returnQueueId),      _serverTerminating(false){}CIMOperationRequestDecoder::~CIMOperationRequestDecoder(){}void CIMOperationRequestDecoder::sendResponse(    Uint32 queueId,    Buffer& message,    Boolean closeConnect){    MessageQueue* queue = MessageQueue::lookup(queueId);    if (queue)    {        AutoPtr<HTTPMessage> httpMessage(new HTTPMessage(message));        httpMessage->setCloseConnect(closeConnect);        queue->enqueue(httpMessage.release());    }}void CIMOperationRequestDecoder::sendIMethodError(    Uint32 queueId,    HttpMethod httpMethod,    const String& messageId,    const String& iMethodName,    const CIMException& cimException,    Boolean closeConnect){    Buffer message;    message = XmlWriter::formatSimpleIMethodErrorRspMessage(        iMethodName,        messageId,        httpMethod,        cimException);    sendResponse(queueId, message,closeConnect);}void CIMOperationRequestDecoder::sendMethodError(    Uint32 queueId,    HttpMethod httpMethod,    const String& messageId,    const String& methodName,    const CIMException& cimException,    Boolean closeConnect){    Buffer message;    message = XmlWriter::formatSimpleMethodErrorRspMessage(        methodName,        messageId,        httpMethod,        cimException);    sendResponse(queueId, message,closeConnect);}void CIMOperationRequestDecoder::sendHttpError(    Uint32 queueId,    const String& status,    const String& cimError,    const String& pegasusError,    Boolean closeConnect){    Buffer message;    message = XmlWriter::formatHttpErrorRspMessage(        status,        cimError,        pegasusError);    sendResponse(queueId, message,closeConnect);}void CIMOperationRequestDecoder::handleEnqueue(Message* message){    if (!message)        return;    switch (message->getType())    {        case HTTP_MESSAGE:             handleHTTPMessage((HTTPMessage*)message);             break;    }    delete message;}void CIMOperationRequestDecoder::handleEnqueue(){    Message* message = dequeue();    if (message)        handleEnqueue(message);}//------------------------------------------------------------------------------//// From the HTTP/1.1 Specification (RFC 2626)://// Both types of message consist of a start-line, zero or more header fields// (also known as "headers"), an empty line (i.e., a line with nothing// preceding the CRLF) indicating the end of the header fields, and possibly// a message-body.//// Example CIM request:////     M-POST /cimom HTTP/1.1//     HOST: www.erewhon.com//     Content-Type: application/xml; charset="utf-8"//     Content-Length: xxxx//     Man: http://www.dmtf.org/cim/operation ; ns=73//     73-CIMOperation: MethodCall//     73-CIMMethod: EnumerateInstances//     73-CIMObject: root/cimv2////------------------------------------------------------------------------------void CIMOperationRequestDecoder::handleHTTPMessage(HTTPMessage* httpMessage){    PEG_METHOD_ENTER(TRC_DISPATCHER,        "CIMOperationRequestDecoder::handleHTTPMessage()");    // Set the Accept-Language into the thread for this service.    // This will allow all code in this thread to get    // the languages for the messages returned to the client.    Thread::setLanguages(new AcceptLanguageList(httpMessage->acceptLanguages));    // Save queueId:    Uint32 queueId = httpMessage->queueId;    // Save userName and authType:    String userName;    String authType;    Boolean closeConnect = httpMessage->getCloseConnect();    PEG_TRACE((        TRC_HTTP,        Tracer::LEVEL3,        "CIMOperationRequestDecoder::handleHTTPMessage()- "        "httpMessage->getCloseConnect() returned %d",        closeConnect));    if (httpMessage->authInfo->isAuthenticated())    {        userName = httpMessage->authInfo->getAuthenticatedUser();        authType = httpMessage->authInfo->getAuthType();    }    // Parse the HTTP message:    String startLine;    Array<HTTPHeader> headers;    char* content;    Uint32 contentLength;    httpMessage->parse(startLine, headers, contentLength);    // Parse the request line:    String methodName;    String requestUri;    String httpVersion;    HttpMethod httpMethod = HTTP_METHOD__POST;    Tracer::trace(TRC_XML_IO, Tracer::LEVEL2, "%s",        httpMessage->message.getData());    HTTPMessage::parseRequestLine(        startLine, methodName, requestUri, httpVersion);    //    //  Set HTTP method for the request    //    if (methodName == "M-POST")    {        httpMethod = HTTP_METHOD_M_POST;    }    // Unsupported methods are caught in the HTTPAuthenticatorDelegator    PEGASUS_ASSERT(methodName == "M-POST" || methodName == "POST");    //    //  Mismatch of method and version is caught in HTTPAuthenticatorDelegator    //    PEGASUS_ASSERT(!((httpMethod == HTTP_METHOD_M_POST) &&                     (httpVersion == "HTTP/1.0")));    // Process M-POST and POST messages:    String cimContentType;    String cimOperation;    String cimBatch;    Boolean cimBatchFlag;    String cimProtocolVersion;    String cimMethod;    String cimObject;    if (httpVersion == "HTTP/1.1")    {        // Validate the presence of a "Host" header.  The HTTP/1.1 specification        // says this in section 14.23 regarding the Host header field:        //        //     All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad        //     Request) status code to any HTTP/1.1 request message which lacks        //     a Host header field.        //        // Note:  The Host header value is not validated.        String hostHeader;        Boolean hostHeaderFound = HTTPMessage::lookupHeader(            headers, "Host", hostHeader, false);        if (!hostHeaderFound)        {            MessageLoaderParms parms(                "Server.CIMOperationRequestDecoder.MISSING_HOST_HEADER",                "HTTP request message lacks a Host header field.");            sendHttpError(                queueId,                HTTP_STATUS_BADREQUEST,                "",                MessageLoader::getMessage(parms),                closeConnect);            PEG_METHOD_EXIT();            return;        }    }    // Validate the "CIMOperation" header:    Boolean operationHeaderFound = HTTPMessage::lookupHeader(        headers, "CIMOperation", cimOperation, true);    // If the CIMOperation header was missing, the HTTPAuthenticatorDelegator    // would not have passed the message to us.    PEGASUS_ASSERT(operationHeaderFound);    if (!String::equalNoCase(cimOperation, "MethodCall"))    {        // The Specification for CIM Operations over HTTP reads:        //     3.3.4. CIMOperation        //     If a CIM Server receives CIM Operation request with this        //     [CIMOperation] header, but with a missing value or a value        //     that is not "MethodCall", then it MUST fail the request with        //     status "400 Bad Request". The CIM Server MUST include a        //     CIMError header in the response with a value of        //     unsupported-operation.        MessageLoaderParms parms(            "Server.CIMOperationRequestDecoder."                "CIMOPERATION_VALUE_NOT_SUPPORTED",            "CIMOperation value \"$0\" is not supported.",cimOperation);        sendHttpError(            queueId,            HTTP_STATUS_BADREQUEST,            "unsupported-operation",            MessageLoader::getMessage(parms),            closeConnect);        PEG_METHOD_EXIT();        return;    }    // Validate the "CIMBatch" header:    cimBatchFlag = HTTPMessage::lookupHeader(        headers, "CIMBatch", cimBatch, true);    if (cimBatchFlag)    {        // The Specification for CIM Operations over HTTP reads:        //     3.3.9. CIMBatch        //     If a CIM Server receives CIM Operation Request for which the        //     CIMBatch header is present, but the Server does not support        //     Multiple Operations, then it MUST fail the request and        //     return a status of "501 Not Implemented".        sendHttpError(            queueId,            HTTP_STATUS_NOTIMPLEMENTED,            "multiple-requests-unsupported",            String::EMPTY,            closeConnect);        PEG_METHOD_EXIT();        return;    }    // Save these headers for later checking    if (!HTTPMessage::lookupHeader(        headers, "CIMProtocolVersion", cimProtocolVersion, true))    {        // Mandated by the Specification for CIM Operations over HTTP        cimProtocolVersion.assign("1.0");    }    if (HTTPMessage::lookupHeader(headers, "CIMMethod", cimMethod, true))    {        if (cimMethod == String::EMPTY)        {            // This is not a valid value, and we use EMPTY to mean "absent"            MessageLoaderParms parms(                "Server.CIMOperationRequestDecoder.EMPTY_CIMMETHOD_VALUE",                "Empty CIMMethod value.");            sendHttpError(                queueId,                HTTP_STATUS_BADREQUEST,                "header-mismatch",                MessageLoader::getMessage(parms),                closeConnect);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -