You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-user@axis.apache.org by Shiv Kumar <sh...@accelrys.com> on 2004/03/03 05:58:45 UTC

How significant is constructor of Win32TransService class

Hi,
I am trying to compile and run Axis CPP client's window code on Linux 
using MainWin (it gives binary compatible to Linux from Window Source 
code). I am able to compile and run all related projects. When Axis CPP 
Client access constructor of Win32TransService class in Xerces.dll 
(version 2.2) then it fails. 
Can someone tell me what the code of constructor does and how significant 
this code is.
I have attached the constructor code at the end of this mail.

Thanks & Regards
Shiv Kumar

// 
---------------------------------------------------------------------------
//  Win32TransService: Constructors and Destructor
// 
---------------------------------------------------------------------------
Win32TransService::Win32TransService()
{
    fCPMap = new RefHashTableOf<CPMapEntry>(109);

    //
    //  Open up the registry key that contains the info we want. Note 
that,
    //  if this key does not exist, then we just return. It will just mean
    //  that we don't have any support except for intrinsic encodings 
supported
    //  by the parser itself (and the LCP support of course.
    //
    HKEY charsetKey;
    if (::RegOpenKeyExA
    (
        HKEY_CLASSES_ROOT
        , "MIME\\Database\\Charset"
        , 0
        , KEY_READ
        , &charsetKey))
    {
        return;
    }

    //
    //  Read in the registry keys that hold the code page ids. Skip for 
now
    //  those entries which indicate that they are aliases for some other
    //  encodings. We'll come back and do a second round for those and 
look
    //  up the original name and get the code page id.
    //
    //  Note that we have to use A versions here so that this will run on
    //  98, and transcode the strings to Unicode.
    //
    const unsigned int nameBufSz = 1024;
    char nameBuf[nameBufSz + 1];
    unsigned int subIndex = 0;
    unsigned long theSize;
    while (true)
    {
        // Get the name of the next key
        theSize = nameBufSz;
        if (::RegEnumKeyExA
        (
            charsetKey
            , subIndex
            , nameBuf
            , &theSize
            , 0, 0, 0, 0) == ERROR_NO_MORE_ITEMS)
        {
            break;
        }

        // Open this subkey
        HKEY encodingKey;
        if (::RegOpenKeyExA
        (
            charsetKey
            , nameBuf
            , 0
            , KEY_READ
            , &encodingKey))
        {
 XMLPlatformUtils::panic(XMLPlatformUtils::Panic_NoTransService);
        }

        //
        //  Lts see if its an alias. If so, then ignore it in this first
        //  loop. Else, we'll add a new entry for this one.
        //
        if (!isAlias(encodingKey))
        {
            //
            //  Lets get the two values out of this key that we are
            //  interested in. There should be a code page entry and an
            //  IE entry.
            //
            unsigned long theType;
            unsigned int CPId;
            unsigned int IEId;

            theSize = sizeof(unsigned int);
            if (::RegQueryValueExA
            (
                encodingKey
                , "Codepage"
                , 0
                , &theType
                , (unsigned char*)&CPId
                , &theSize) != ERROR_SUCCESS)
            {
 XMLPlatformUtils::panic(XMLPlatformUtils::Panic_NoTransService);
            }

            //
            //  If this is not a valid Id, and it might not be because its
            //  not loaded on this system, then don't take it.
            //
            if (::IsValidCodePage(CPId))
            {
                theSize = sizeof(unsigned int);
                if (::RegQueryValueExA
                (
                    encodingKey
                    , "InternetEncoding"
                    , 0
                    , &theType
                    , (unsigned char*)&IEId
                    , &theSize) != ERROR_SUCCESS)
                {
 XMLPlatformUtils::panic(XMLPlatformUtils::Panic_NoTransService);
                }

                CPMapEntry* newEntry = new CPMapEntry(nameBuf, CPId, 
IEId);
                fCPMap->put((void*)newEntry->getEncodingName(), newEntry);
            }
        }

        // And now close the subkey handle and bump the subkey index
        ::RegCloseKey(encodingKey);
        subIndex++;
    }

    //
    //  Now loop one more time and this time we do just the aliases. For
    //  each one we find, we look up that name in the map we've already
    //  built and add a new entry with this new name and the same id
    //  values we stored for the original.
    //
    subIndex = 0;
    char aliasBuf[nameBufSz + 1];
    while (true)
    {
        // Get the name of the next key
        theSize = nameBufSz;
        if (::RegEnumKeyExA
        (
            charsetKey
            , subIndex
            , nameBuf
            , &theSize
            , 0, 0, 0, 0) == ERROR_NO_MORE_ITEMS)
        {
            break;
        }

        // Open this subkey
        HKEY encodingKey;
        if (::RegOpenKeyExA
        (
            charsetKey
            , nameBuf
            , 0
            , KEY_READ
            , &encodingKey))
        {
 XMLPlatformUtils::panic(XMLPlatformUtils::Panic_NoTransService);
        }

        //
        //  If its an alias, look up the name in the map. If we find it,
        //  then construct a new one with the new name and the aliased
        //  ids.
        //
        if (isAlias(encodingKey, aliasBuf, nameBufSz))
        {
            const unsigned int srcLen = strlen(aliasBuf);
            const unsigned charLen = ::mblen(aliasBuf, MB_CUR_MAX);

            if (charLen != -1) {
                const unsigned int targetLen = srcLen/charLen;

                XMLCh* uniAlias = new XMLCh[targetLen + 1];
                ::mbstowcs(uniAlias, aliasBuf, srcLen);
                uniAlias[targetLen] = 0;
                _wcsupr(uniAlias);

                // Look up the alias name
                CPMapEntry* aliasedEntry = fCPMap->get(uniAlias);
                if (aliasedEntry)
                {
                    const unsigned int srcLen = strlen(nameBuf);
                    const unsigned charLen = ::mblen(nameBuf, MB_CUR_MAX);
                    const unsigned int targetLen = srcLen/charLen;
 
                    XMLCh* uniName = new XMLCh[targetLen + 1];
                    ::mbstowcs(uniName, nameBuf, srcLen);
                    uniName[targetLen] = 0;
                    _wcsupr(uniName);

                    //
                    //  If the name is actually different, then take it.
                    //  Otherwise, don't take it. They map aliases that 
are
                    //  just different case.
                    //
                    if (::wcscmp(uniName, 
aliasedEntry->getEncodingName()))
                    {
                        CPMapEntry* newEntry = new CPMapEntry(uniName, 
aliasedEntry->getWinCP(), aliasedEntry->getIEEncoding());
                        fCPMap->put((void*)newEntry->getEncodingName(), 
newEntry);
                    }

                    delete [] uniName;
                }
                delete [] uniAlias;
            }
        }

        // And now close the subkey handle and bump the subkey index
        ::RegCloseKey(encodingKey);
        subIndex++;
    }

    // And close the main key handle
    ::RegCloseKey(charsetKey);

}