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

📄 xmlwriter.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    append(out, buffer);}void XmlWriter::append(Buffer& out, Real64 x){    char buffer[128];    // %.16e gives '[-]m.dddddddddddddddde+/-xx', which seems compatible    // with the format given in the CIM/XML spec, and the precision required    // by the CIM 2.2 spec (8 byte IEEE floating point)    sprintf(buffer, "%.16e", x);    append(out, buffer);}void XmlWriter::append(Buffer& out, const char* str){    size_t n = strlen(str);    out.append(str, n);}void XmlWriter::append(Buffer& out, const String& str){    const Uint16* p = (const Uint16*)str.getChar16Data();    size_t n = str.size();    // Handle leading ASCII 7 characers in these next two loops (use unrolling).    while (n >= 8 && ((p[0]|p[1]|p[2]|p[3]|p[4]|p[5]|p[6]|p[7]) & 0xFF80) == 0)    {        out.append(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);        p += 8;        n -= 8;    }    while (n >= 4 && ((p[0]|p[1]|p[2]|p[3]) & 0xFF80) == 0)    {        out.append(p[0], p[1], p[2], p[3]);        p += 4;        n -= 4;    }    while (n--)    {        Uint16 c = *p++;        // Special processing for UTF8 case:        if (c < 128)        {            out.append(c);            continue;        }        // Handle UTF8 case (if reached).        if (((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) ||            ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE)))        {            Char16 highSurrogate = p[-1];            Char16 lowSurrogate = p[0];            p++;            n--;            _xmlWritter_appendSurrogatePair(                out, Uint16(highSurrogate),Uint16(lowSurrogate));        }        else        {            _xmlWritter_appendChar(out, c);        }    }}void XmlWriter::append(Buffer& out, const Indentor& x){    for (Uint32 i = 0; i < 4 * x.getLevel(); i++)        out.append(' ');}void XmlWriter::appendSpecial(Buffer& out, const Char16& x){    _xmlWritter_appendSpecialChar(out, x);}void XmlWriter::appendSpecial(Buffer& out, char x){    _appendSpecialChar7(out, x);}void XmlWriter::appendSpecial(Buffer& out, const char* str){    while (*str)        _appendSpecialChar7(out, *str++);}void XmlWriter::appendSpecial(Buffer& out, const String& str){    const Uint16* p = (const Uint16*)str.getChar16Data();    // prevCharIsSpace is true when the last character written to the Buffer    // is a space character (not a character reference).    Boolean prevCharIsSpace = false;    // If the first character is a space, use a character reference to avoid    // space compression.    if (*p == ' ')    {        out.append(STRLIT_ARGS("&#32;"));        p++;    }    Uint16 c;    while ((c = *p++) != 0)    {        if (c < 128)        {            if (_isSpecialChar7[c])            {                // Write the character reference for the special character                out.append(                    _specialChars[int(c)].str, _specialChars[int(c)].size);                prevCharIsSpace = false;            }            else if (prevCharIsSpace && (c == ' '))            {                // Write the character reference for the space character, to                // avoid compression                out.append(STRLIT_ARGS("&#32;"));                prevCharIsSpace = false;            }            else            {                out.append(c);                prevCharIsSpace = (c == ' ');            }        }        else        {            // Handle UTF8 case            if ((((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) ||                 ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE))) &&                *p)            {                _xmlWritter_appendSurrogatePair(out, c, *p++);            }            else            {                _xmlWritter_appendChar(out, c);            }            prevCharIsSpace = false;        }    }    // If the last character is a space, use a character reference to avoid    // space compression.    if (prevCharIsSpace)    {        out.remove(out.size() - 1);        out.append(STRLIT_ARGS("&#32;"));    }}// See http://www.ietf.org/rfc/rfc2396.txt section 2// Reserved characters = ';' '/' '?' ':' '@' '&' '=' '+' '$' ','// Excluded characters://   Control characters = 0x00-0x1f, 0x7f//   Space character = 0x20//   Delimiters = '<' '>' '#' '%' '"'//   Unwise = '{' '}' '|' '\\' '^' '[' ']' '`'//static const char _is_uri[128] ={    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,    1,1,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,    0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,};// Perform the necessary URI encoding of characters in HTTP header values.// This is required by the HTTP/1.1 specification and the CIM/HTTP// Specification (section 3.3.2).static void _xmlWritter_encodeURIChar(String& outString, Sint8 char8){    Uint8 c = (Uint8)char8;#ifndef PEGASUS_DO_NOT_IMPLEMENT_URI_ENCODING    if (c > 127 || _is_uri[int(c)])    {        char hexencoding[4];        int n = sprintf(hexencoding, "%%%X%X", c/16, c%16);#ifdef PEGASUS_USE_STRING_EXTENSIONS        outString.append(hexencoding, n);#else /* PEGASUS_USE_STRING_EXTENSIONS */        outString.append(hexencoding);#endif /* PEGASUS_USE_STRING_EXTENSIONS */    }    else#endif    {        outString.append((Uint16)c);    }}String XmlWriter::encodeURICharacters(const Buffer& uriString){    String encodedString;    for (Uint32 i=0; i<uriString.size(); i++)    {        _xmlWritter_encodeURIChar(encodedString, uriString[i]);    }    return encodedString;}String XmlWriter::encodeURICharacters(const String& uriString){    String encodedString;/* i18n remove - did not handle surrogate pairs    for (Uint32 i=0; i<uriString.size(); i++)    {        _xmlWritter_encodeURIChar(encodedString, uriString[i]);    }*/    // See the "CIM Operations over HTTP" spec, section 3.3.2 and    // 3.3.3, for the treatment of non US-ASCII (UTF-8) chars    // First, convert to UTF-8 (include handling of surrogate pairs)    Buffer utf8;    for (Uint32 i = 0; i < uriString.size(); i++)    {        Uint16 c = uriString[i];        if (((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) ||            ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE)))        {            Char16 highSurrogate = uriString[i];            Char16 lowSurrogate = uriString[++i];            _xmlWritter_appendSurrogatePair(                utf8, Uint16(highSurrogate),Uint16(lowSurrogate));        }        else        {            _xmlWritter_appendChar(utf8, uriString[i]);        }    }    // Second, escape the non HTTP-safe chars    for (Uint32 i=0; i<utf8.size(); i++)    {        _xmlWritter_encodeURIChar(encodedString, utf8[i]);    }    return encodedString;}//------------------------------------------------------------------------------//// appendLocalNameSpacePathElement()////     <!ELEMENT LOCALNAMESPACEPATH (NAMESPACE+)>////------------------------------------------------------------------------------void XmlWriter::appendLocalNameSpacePathElement(    Buffer& out,    const CIMNamespaceName& nameSpace){    out << STRLIT("<LOCALNAMESPACEPATH>\n");    char* nameSpaceCopy = strdup(nameSpace.getString().getCString());#if !defined(PEGASUS_COMPILER_MSVC) && !defined(PEGASUS_OS_ZOS)    char *last;    for (const char* p = strtok_r(nameSpaceCopy, "/", &last); p;         p = strtok_r(NULL, "/", &last))#else    for (const char* p = strtok(nameSpaceCopy, "/"); p; p = strtok(NULL, "/"))#endif    {        out << STRLIT("<NAMESPACE NAME=\"") << p << STRLIT("\"/>\n");    }    free(nameSpaceCopy);    out << STRLIT("</LOCALNAMESPACEPATH>\n");}//------------------------------------------------------------------------------//// appendNameSpacePathElement()////     <!ELEMENT NAMESPACEPATH (HOST,LOCALNAMESPACEPATH)>////------------------------------------------------------------------------------void XmlWriter::appendNameSpacePathElement(    Buffer& out,    const String& host,    const CIMNamespaceName& nameSpace){    out << STRLIT("<NAMESPACEPATH>\n");    out << STRLIT("<HOST>") << host << STRLIT("</HOST>\n");    appendLocalNameSpacePathElement(out, nameSpace);    out << STRLIT("</NAMESPACEPATH>\n");}//------------------------------------------------------------------------------//// appendClassNameElement()////     <!ELEMENT CLASSNAME EMPTY>//     <!ATTLIST CLASSNAME//              %CIMName;>////------------------------------------------------------------------------------void XmlWriter::appendClassNameElement(    Buffer& out,    const CIMName& className){    out << STRLIT("<CLASSNAME NAME=\"") << className << STRLIT("\"/>\n");}//------------------------------------------------------------------------------//// appendInstanceNameElement()////    <!ELEMENT INSTANCENAME (KEYBINDING*|KEYVALUE?|VALUE.REFERENCE?)>//    <!ATTLIST INSTANCENAME//              %ClassName;>////------------------------------------------------------------------------------void XmlWriter::appendInstanceNameElement(    Buffer& out,    const CIMObjectPath& instanceName){    out << STRLIT("<INSTANCENAME CLASSNAME=\"");    out << instanceName.getClassName() << STRLIT("\">\n");    const Array<CIMKeyBinding>& keyBindings = instanceName.getKeyBindings();    for (Uint32 i = 0, n = keyBindings.size(); i < n; i++)    {        out << STRLIT("<KEYBINDING NAME=\"");        out << keyBindings[i].getName() << STRLIT("\">\n");        if (keyBindings[i].getType() == CIMKeyBinding::REFERENCE)        {            CIMObjectPath ref = keyBindings[i].getValue();            appendValueReferenceElement(out, ref, true);        }        else        {            out << STRLIT("<KEYVALUE VALUETYPE=\"");            out << keyBindingTypeToString(keyBindings[i].getType());            out << STRLIT("\">");            // fixed the special character problem - Markus            appendSpecial(out, keyBindings[i].getValue());            out << STRLIT("</KEYVALUE>\n");        }        out << STRLIT("</KEYBINDING>\n");    }    out << STRLIT("</INSTANCENAME>\n");}//------------------------------------------------------------------------------//// appendClassPathElement()////     <!ELEMENT CLASSPATH (NAMESPACEPATH,CLASSNAME)>////------------------------------------------------------------------------------void XmlWriter::appendClassPathElement(    Buffer& out,    const CIMObjectPath& classPath){    out << STRLIT("<CLASSPATH>\n");    appendNameSpacePathElement(out,                               classPath.getHost(),                               classPath.getNameSpace());    appendClassNameElement(out, classPath.getClassName());    out << STRLIT("</CLASSPATH>\n");}//------------------------------------------------------------------------------//// appendInstancePathElement()////     <!ELEMENT INSTANCEPATH (NAMESPACEPATH,INSTANCENAME)>////------------------------------------------------------------------------------void XmlWriter::appendInstancePathElement(    Buffer& out,    const CIMObjectPath& instancePath){    out << STRLIT("<INSTANCEPATH>\n");    appendNameSpacePathElement(out,                               instancePath.getHost(),                               instancePath.getNameSpace());    appendInstanceNameElement(out, instancePath);    out << STRLIT("</INSTANCEPATH>\n");}//------------------------------------------------------------------------------//// appendLocalClassPathElement()////     <!ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME)>////------------------------------------------------------------------------------void XmlWriter::appendLocalClassPathElement(    Buffer& out,    const CIMObjectPath& classPath){    out << STRLIT("<LOCALCLASSPATH>\n");    appendLocalNameSpacePathElement(out, classPath.getNameSpace());    appendClassNameElement(out, classPath.getClassName());    out << STRLIT("</LOCALCLASSPATH>\n");}//------------------------------------------------------------------------------//// appendLocalInstancePathElement()////     <!ELEMENT LOCALINSTANCEPATH (LOCALNAMESPACEPATH, INSTANCENAME)>////------------------------------------------------------------------------------void XmlWriter::appendLocalInstancePathElement(    Buffer& out,    const CIMObjectPath& instancePath){    out << STRLIT("<LOCALINSTANCEPATH>\n");    appendLocalNameSpacePathElement(out, instancePath.getNameSpace());    appendInstanceNameElement(out, instancePath);    out << STRLIT("</LOCALINSTANCEPATH>\n");}//------------------------------------------------------------------------------//// appendLocalObjectPathElement()////     If the reference refers to an instance, write a LOCALINSTANCEPATH;//     otherwise write a LOCALCLASSPATH.////------------------------------------------------------------------------------void XmlWriter::appendLocalObjectPathElement(    Buffer& out,    const CIMObjectPath& objectPath){    //    //  ATTN-CAKG-P2-20020726:  The following condition does not correctly    //  distinguish instanceNames from classNames in every case    //  The instanceName of a singleton instance of a keyless class has no    //  key bindings    //    if (objectPath.getKeyBindings ().size () != 0)

⌨️ 快捷键说明

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