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

📄 httpexportresponsedecoder.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//%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 <Pegasus/Common/XmlReader.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/CIMMessage.h>#include <Pegasus/Common/MessageLoader.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/Client/CIMClientException.h>#include "HTTPExportResponseDecoder.h"PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGINvoid HTTPExportResponseDecoder::parseHTTPHeaders(    HTTPMessage* httpMessage,    ClientExceptionMessage*& exceptionMessage,    Array<HTTPHeader>& headers,    Uint32& contentLength,    Uint32& statusCode,    String& reasonPhrase,    Boolean& cimReconnect,    Boolean& valid){    PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,        "HTTPExportResponseDecoder::parseHTTPHeaders()");    exceptionMessage = 0;    headers.clear();    contentLength = 0;    statusCode = 0;    reasonPhrase = String::EMPTY;    cimReconnect = false;    valid = true;    String startLine;    String connectClose;    //        //  Check for empty HTTP response message        //        if (httpMessage->message.size() == 0)    {        MessageLoaderParms mlParms(            "ExportClient.CIMExportResponseDecoder.EMPTY_RESPONSE",            "Empty HTTP response message.");        String mlString(MessageLoader::getMessage(mlParms));        AutoPtr<CIMClientMalformedHTTPException> malformedHTTPException(            new CIMClientMalformedHTTPException(mlString));        AutoPtr<ClientExceptionMessage> response(            new ClientExceptionMessage(malformedHTTPException.get()));        malformedHTTPException.release();        exceptionMessage = response.release();        valid = false;        PEG_METHOD_EXIT();        return;    }    //    // Parse the HTTP message headers and get content length    //    httpMessage->parse(startLine, headers, contentLength);    //    // Check for Connection: Close    //    if (HTTPMessage::lookupHeader(headers, "Connection", connectClose, false))    {        if (String::equalNoCase(connectClose, "Close"))        {            // reconnect and then resend next request.            cimReconnect=true;        }        Tracer::trace(TRC_XML_IO, Tracer::LEVEL2, "%s",            httpMessage->message.getData());    }    //    //  Parse HTTP message status line    //    String httpVersion;    Boolean parsableMessage = HTTPMessage::parseStatusLine(        startLine, httpVersion, statusCode, reasonPhrase);    if (!parsableMessage)    {        MessageLoaderParms mlParms(            "ExportClient.CIMExportResponseDecoder.MALFORMED_RESPONSE",            "Malformed HTTP response message.");        String mlString(MessageLoader::getMessage(mlParms));        AutoPtr<CIMClientMalformedHTTPException> malformedHTTPException(            new CIMClientMalformedHTTPException(mlString));        AutoPtr<ClientExceptionMessage> response(            new ClientExceptionMessage(malformedHTTPException.get()));        malformedHTTPException.release();        response->setCloseConnect(cimReconnect);        exceptionMessage = response.release();        valid = false;        PEG_METHOD_EXIT();        return;    }    PEG_METHOD_EXIT();}void HTTPExportResponseDecoder::validateHTTPHeaders(    HTTPMessage* httpMessage,    Array<HTTPHeader>& headers,    Uint32 contentLength,    Uint32 statusCode,    Boolean cimReconnect,    const String& reasonPhrase,    char*& content,    ClientExceptionMessage*& exceptionMessage,    Boolean& valid){    PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,        "HTTPExportResponseDecoder::validateHTTPHeaders()");    content = 0;    exceptionMessage = 0;    valid = true;    //    // If authentication failed, a CIMClientHTTPErrorException will be    // generated with the "401 Unauthorized" status in the (re-challenge)    // response    //    // Check for a non-success (200 OK) response    //    if (statusCode != HTTP_STATUSCODE_OK)    {        String cimError;        String pegasusError;        HTTPMessage::lookupHeader(headers, "CIMError", cimError);        HTTPMessage::lookupHeader(headers, PEGASUS_HTTPHEADERTAG_ERRORDETAIL,            pegasusError);        try        {            pegasusError = XmlReader::decodeURICharacters(pegasusError);        }        catch (const ParseError&)        {            // Ignore this exception.  We're more interested in having the            // message in encoded form than knowing that the format is invalid.        }        AutoPtr<CIMClientHTTPErrorException> httpError(            new CIMClientHTTPErrorException(statusCode, reasonPhrase, cimError,                pegasusError));        AutoPtr<ClientExceptionMessage> response(            new ClientExceptionMessage(httpError.get()));        httpError.release();        response->setCloseConnect(cimReconnect);        exceptionMessage = response.release();        valid = false;        PEG_METHOD_EXIT();        return;    }    //    // Check for missing "CIMExport" header    //    String cimExport;    if (!HTTPMessage::lookupHeader(headers, "CIMExport", cimExport, true))    {        MessageLoaderParms mlParms(            "ExportClient.CIMExportResponseDecoder.MISSING_CIMEXP_HEADER",            "Missing CIMExport HTTP header");        String mlString(MessageLoader::getMessage(mlParms));        AutoPtr<CIMClientMalformedHTTPException> malformedHTTPException(new            CIMClientMalformedHTTPException(mlString));        AutoPtr<ClientExceptionMessage> response(            new ClientExceptionMessage(malformedHTTPException.get()));        malformedHTTPException.release();        response->setCloseConnect(cimReconnect);        exceptionMessage = response.release();        valid = false;        PEG_METHOD_EXIT();        return;    }    //    // Check for missing "Content-Type" header    //    String cimContentType;    if (!HTTPMessage::lookupHeader(        headers, "Content-Type", cimContentType, true))    {        AutoPtr<CIMClientMalformedHTTPException> malformedHTTPException(new            CIMClientMalformedHTTPException(                "Missing CIMContentType HTTP header"));        AutoPtr<ClientExceptionMessage> response(            new ClientExceptionMessage(malformedHTTPException.get()));        malformedHTTPException.release();        response->setCloseConnect(cimReconnect);        exceptionMessage = response.release();        valid = false;

⌨️ 快捷键说明

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