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

📄 xmlwriter.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            out << STRLIT(" INDICATION=\"true\"");        out << STRLIT("/>");    }}// l10n - added content language and accept language support to// the header methods below//------------------------------------------------------------------------------//// appendMethodCallHeader()////     Build HTTP method call request header.////------------------------------------------------------------------------------void XmlWriter::appendMethodCallHeader(    Buffer& out,    const char* host,    const CIMName& cimMethod,    const String& cimObject,    const String& authenticationHeader,    HttpMethod httpMethod,    const AcceptLanguageList& acceptLanguages,    const ContentLanguageList& contentLanguages,    Uint32 contentLength){    char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };    // ATTN: KS 20020926 - Temporary change to issue only POST. This may    // be changed in the DMTF CIM Operations standard in the future.    // If we kept M-Post we would have to retry with Post. Does not    // do that in client today. Permanent change is to retry until spec    // updated. This change is temp to finish tests or until the retry    // installed.  Required because of change to wbemservices cimom    if (httpMethod == HTTP_METHOD_M_POST)    {        out << STRLIT("M-POST /cimom HTTP/1.1\r\n");    }    else    {        out << STRLIT("POST /cimom HTTP/1.1\r\n");    }    out << STRLIT("HOST: ") << host << STRLIT("\r\n");    out << STRLIT("Content-Type: application/xml; charset=\"utf-8\"\r\n");    OUTPUT_CONTENTLENGTH;    if (acceptLanguages.size() > 0)    {        out << STRLIT("Accept-Language: ") << acceptLanguages << STRLIT("\r\n");    }    if (contentLanguages.size() > 0)    {        out << STRLIT("Content-Language: ") << contentLanguages <<            STRLIT("\r\n");    }#ifdef PEGASUS_DEBUG    // backdoor environment variable to turn OFF client requesting transfer    // encoding. The default is on. to turn off, set this variable to zero.    // This should be removed when stable. This should only be turned off in    // a debugging/testing environment.    static const char *clientTransferEncodingOff =        getenv("PEGASUS_HTTP_TRANSFER_ENCODING_REQUEST");    if (!clientTransferEncodingOff || *clientTransferEncodingOff != '0')#endif    out << STRLIT("TE: chunked, trailers\r\n");    if (httpMethod == HTTP_METHOD_M_POST)    {        out << STRLIT("Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=");        out << nn << STRLIT("\r\n");        out << nn << STRLIT("-CIMOperation: MethodCall\r\n");        out << nn << STRLIT("-CIMMethod: ")            << encodeURICharacters(cimMethod.getString()) << STRLIT("\r\n");        out << nn << STRLIT("-CIMObject: ") << encodeURICharacters(cimObject)            << STRLIT("\r\n");    }    else    {        out << STRLIT("CIMOperation: MethodCall\r\n");        out << STRLIT("CIMMethod: ")            << encodeURICharacters(cimMethod.getString())            << STRLIT("\r\n");        out << STRLIT("CIMObject: ") << encodeURICharacters(cimObject)            << STRLIT("\r\n");    }    if (authenticationHeader.size())    {        out << authenticationHeader << STRLIT("\r\n");    }    out << STRLIT("\r\n");}void XmlWriter::appendMethodResponseHeader(     Buffer& out,     HttpMethod httpMethod,     const ContentLanguageList& contentLanguages,     Uint32 contentLength,     Uint64 serverResponseTime){     char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };     out << STRLIT("HTTP/1.1 " HTTP_STATUS_OK "\r\n");#ifndef PEGASUS_DISABLE_PERFINST     if (StatisticalData::current()->copyGSD)     {         out << STRLIT("WBEMServerResponseTime: ") <<             CIMValue(serverResponseTime).toString() << STRLIT("\r\n");     }#endif     out << STRLIT("Content-Type: application/xml; charset=\"utf-8\"\r\n");     OUTPUT_CONTENTLENGTH;     if (contentLanguages.size() > 0)     {         out << STRLIT("Content-Language: ") << contentLanguages <<             STRLIT("\r\n");     }     if (httpMethod == HTTP_METHOD_M_POST)     {         out << STRLIT("Ext:\r\n");         out << STRLIT("Cache-Control: no-cache\r\n");         out << STRLIT("Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=");         out << nn << STRLIT("\r\n");         out << nn << STRLIT("-CIMOperation: MethodResponse\r\n\r\n");     }     else     {         out << STRLIT("CIMOperation: MethodResponse\r\n\r\n");     }}//------------------------------------------------------------------------------//// appendHttpErrorResponseHeader()////     Build HTTP error response header.////     Returns error response message in the following format:////        HTTP/1.1 400 Bad Request       (using specified status code)//        CIMError: <error type>         (if specified by caller)//        PGErrorDetail: <error text>    (if specified by caller)////------------------------------------------------------------------------------void XmlWriter::appendHttpErrorResponseHeader(    Buffer& out,    const String& status,    const String& cimError,    const String& errorDetail){    out << STRLIT("HTTP/1.1 ") << status << STRLIT("\r\n");    if (cimError != String::EMPTY)    {        out << STRLIT("CIMError: ") << cimError << STRLIT("\r\n");    }    if (errorDetail != String::EMPTY)    {        out << STRLIT(PEGASUS_HTTPHEADERTAG_ERRORDETAIL ": ")            << encodeURICharacters(errorDetail) << STRLIT("\r\n");    }    out << STRLIT("\r\n");}//------------------------------------------------------------------------------//// appendUnauthorizedResponseHeader()////     Build HTTP authentication response header for unauthorized requests.////     Returns unauthorized message in the following format:////        HTTP/1.1 401 Unauthorized//        WWW-Authenticate: Basic "hostname:80"//        <HTML><HEAD>//        <TITLE>401 Unauthorized</TITLE>//        </HEAD><BODY BGCOLOR="#99cc99">//        <H2>TEST401 Unauthorized</H2>//        <HR>//        </BODY></HTML>////------------------------------------------------------------------------------void XmlWriter::appendUnauthorizedResponseHeader(    Buffer& out,    const String& content){    out << STRLIT("HTTP/1.1 " HTTP_STATUS_UNAUTHORIZED "\r\n");    out << content << STRLIT("\r\n");    out << STRLIT("\r\n");//ATTN: We may need to include the following line, so that the browsers//      can display the error message.//    out << "<HTML><HEAD>\r\n";//    out << "<TITLE>" << "401 Unauthorized" <<  "</TITLE>\r\n";//    out << "</HEAD><BODY BGCOLOR=\"#99cc99\">\r\n";//    out << "<H2>TEST" << "401 Unauthorized" << "</H2>\r\n";//    out << "<HR>\r\n";//    out << "</BODY></HTML>\r\n";}#ifdef PEGASUS_KERBEROS_AUTHENTICATION//------------------------------------------------------------------------------//// appendOKResponseHeader()////     Build HTTP authentication response header for unauthorized requests.////     Returns OK message in the following format:////        HTTP/1.1 200 OK//        Content-Length: 0//        WWW-Authenticate: Negotiate "token"//        <HTML><HEAD>//        <TITLE>200 OK</TITLE>//        </HEAD><BODY BGCOLOR="#99cc99">//        <H2>TEST200 OK</H2>//        <HR>//        </BODY></HTML>////------------------------------------------------------------------------------void XmlWriter::appendOKResponseHeader(    Buffer& out,    const String& content){    out << STRLIT("HTTP/1.1 " HTTP_STATUS_OK "\r\n");    // Content-Length header needs to be added because 200 OK record    // is usually intended to have content.  But, for Kerberos this    // may not always be the case so we need to indicate that there    // is no content    Uint32 contentLength = 0;    OUTPUT_CONTENTLENGTH;    out << content << STRLIT("\r\n");    out << STRLIT("\r\n");//ATTN: We may need to include the following line, so that the browsers//      can display the error message.//    out << "<HTML><HEAD>\r\n";//    out << "<TITLE>" << "200 OK" <<  "</TITLE>\r\n";//    out << "</HEAD><BODY BGCOLOR=\"#99cc99\">\r\n";//    out << "<H2>TEST" << "200 OK" << "</H2>\r\n";//    out << "<HR>\r\n";//    out << "</BODY></HTML>\r\n";}#endif//------------------------------------------------------------------------------//// _appendMessageElementBegin()// _appendMessageElementEnd()////     <!ELEMENT MESSAGE (SIMPLEREQ|MULTIREQ|SIMPLERSP|MULTIRSP)>//     <!ATTLIST MESSAGE//         ID CDATA #REQUIRED//         PROTOCOLVERSION CDATA #REQUIRED>////------------------------------------------------------------------------------void XmlWriter::_appendMessageElementBegin(    Buffer& out,    const String& messageId){    out << STRLIT("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");    out << STRLIT("<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">\n");    out << STRLIT("<MESSAGE ID=\"") << messageId;    out << STRLIT("\" PROTOCOLVERSION=\"1.0\">\n");}void XmlWriter::_appendMessageElementEnd(    Buffer& out){    out << STRLIT("</MESSAGE>\n");    out << STRLIT("</CIM>\n");}//------------------------------------------------------------------------------//// _appendSimpleReqElementBegin()// _appendSimpleReqElementEnd()////     <!ELEMENT SIMPLEREQ (IMETHODCALL|METHODCALL)>////------------------------------------------------------------------------------void XmlWriter::_appendSimpleReqElementBegin(    Buffer& out){    out << STRLIT("<SIMPLEREQ>\n");}void XmlWriter::_appendSimpleReqElementEnd(    Buffer& out){    out << STRLIT("</SIMPLEREQ>\n");}//------------------------------------------------------------------------------//// _appendMethodCallElementBegin()// _appendMethodCallElementEnd()////     <!ELEMENT METHODCALL ((LOCALCLASSPATH|LOCALINSTANCEPATH),PARAMVALUE*)>//     <!ATTLIST METHODCALL %CIMName;>////------------------------------------------------------------------------------void XmlWriter::_appendMethodCallElementBegin(    Buffer& out,    const CIMName& name){    out << STRLIT("<METHODCALL NAME=\"") << name << STRLIT("\">\n");}void XmlWriter::_appendMethodCallElementEnd(    Buffer& out){    out << STRLIT("</METHODCALL>\n");}//------------------------------------------------------------------------------//// _appendIMethodCallElementBegin()// _appendIMethodCallElementEnd()////     <!ELEMENT IMETHODCALL (LOCALNAMESPACEPATH,IPARAMVALUE*)>//     <!ATTLIST IMETHODCALL %CIMName;>////------------------------------------------------------------------------------void XmlWriter::_appendIMethodCallElementBegin(    Buffer& out,    const CIMName& name){    out << STRLIT("<IMETHODCALL NAME=\"") << name << STRLIT("\">\n");}void XmlWriter::_appendIMethodCallElementEnd(    Buffer& out){    out << STRLIT("</IMETHODCALL>\n");}//------------------------------------------------------------------------------//// _appendIParamValueElementBegin()// _appendIParamValueElementEnd()////     <!ELEMENT IPARAMVALUE (VALUE|VALUE.ARRAY|VALUE.REFERENCE//         |INSTANCENAME|CLASSNAME|QUALIFIER.DECLARATION//         |CLASS|INSTANCE|VALUE.NAMEDINSTANCE)?>//     <!ATTLIST IPARAMVALUE %CIMName;>////------------------------------------------------------------------------------void XmlWriter::_appendIParamValueElementBegin(    Buffer& out,    const char* name){    out << STRLIT("<IPARAMVALUE NAME=\"") << name << STRLIT("\">\n");}void XmlWriter::_appendIParamValueElementEnd(    Buffer& out){    out << STRLIT("</IPARAMVALUE>\n");}//------------------------------------------------------------------------------//// _appendSimpleRspElementBegin()// _appendSimpleRspElementEnd()////     <!ELEMENT SIMPLERSP (METHODRESPONSE|IMETHODRESPONSE)>////------------------------------------------------------------------------------void XmlWriter::_appendSimpleRspElementBegin(    Buffer& out){    out << STRLIT("<SIMPLERSP>\n");}void XmlWriter::_appendSimpleRspElementEnd(    Buffer& out){    out << STRLIT("</SIMPLERSP>\n");}//------------------------------------------------------------------------------//// _appendMethodResponseElementBegin()// _appendMethodResponseElementEnd()////     <!ELEMENT METHODRESPONSE (ERROR|IRETURNVALUE?)>//     <!ATTLIST METHODRESPONSE %CIMName;>////------------------------------------------------------------------------------void XmlWriter::_appendMethodResponseElementBegin(    Buffer& out,    const CIMName& name){    out << STRLIT("<METHODRESPONSE NAME=\"") << name << STRLIT("\">\n");}void XmlWriter::_appendMethodResponseElementEnd(    Buffer& out){    out << STRLIT("</METHODRESPONSE>\n");}//------------------------------------------------------------------------------//// _appendIMethodResponseElementBegin()// _appendIMethodResponseElementEnd()////     <!ELEMENT IMETHODRESPONSE (ERROR|IRETURNVALUE?)>//     <!ATTLIST IMETHODRESPONSE %CIMName;>////------------------------------------------------------------------------------void XmlWriter::_appendIMethodResponseElementBegin(    Buffer& out,    const CIMName& name){    out << STRLIT("<IMETHODRESPONSE NAME=\"") << name << STRLIT("\">\n");}void XmlWriter::_appendIMethodResponseElementEnd(    Buffer& out){    out << STRLIT("</IMETHODRESPONSE>\n");}//------------------------------------------------------------------------------//// _appendErrorElement()////------------------------------------------------------------------------------void XmlWriter::_appendErrorElement(    Buffer& out,    const CIMException& cimException){    Tracer::traceCIMException(TRC_XML_WRITER, Tracer::LEVEL2, cimException);    out << STRLIT("<ERROR");    out << STRLIT(" CODE=\"") << Uint32(cimException.getCode());    out.append('"');    String description = TraceableCIMException(cimException).getDescription();    if (description != St

⌨️ 快捷键说明

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