Skip to content
Snippets Groups Projects
XMLURL.cpp 33 KiB
Newer Older
                fMemoryManager->deallocate(fHost);//delete [] fHost;
                fHost = XMLString::replicate(srcPtr, fMemoryManager);
PeiYong Zhang's avatar
PeiYong Zhang committed

                // Update source pointer to the end
                srcPtr += XMLString::stringLen(fHost);
            }
        }
PeiYong Zhang's avatar
PeiYong Zhang committed
    {
        //
        // http protocol requires two forward slashes
        // we didn't get them, so throw an exception
        //
        if (fProtocol == HTTP) {
            ThrowXML
PeiYong Zhang's avatar
PeiYong Zhang committed
                (
                    MalformedURLException
                    , XMLExcepts::URL_ExpectingTwoSlashes
                );
PeiYong Zhang's avatar
PeiYong Zhang committed
    }

    //
    //  If there was a host part, then we have to grovel through it for
    //  all the bits and pieces it can hold.
    //
    if (fHost)
    {
        //
        //  Look for a '@' character, which indicates a user name. If we
        //  find one, then everything between the start of the host data
        //  and the character is the user name.
        //
        ptr1 = XMLString::findAny(fHost, listTwo);
        if (ptr1)
        {
            // Get this info out as the user name
            *ptr1 = 0;
            fMemoryManager->deallocate(fUser);//delete [] fUser;
            fUser = XMLString::replicate(fHost, fMemoryManager);
PeiYong Zhang's avatar
PeiYong Zhang committed
            ptr1++;

            // And now cut these chars from the host string
            XMLString::cut(fHost, ptr1 - fHost);

            // Is there a password inside the user string?
            ptr2 = XMLString::findAny(fUser, listThree);
            if (ptr2)
            {
                // Remove it from the user name string
                *ptr2 = 0;

                // And copy out the remainder to the password field
                ptr2++;
                fMemoryManager->deallocate(fPassword);//delete [] fPassword;
                fPassword = XMLString::replicate(ptr2, fMemoryManager);
PeiYong Zhang's avatar
PeiYong Zhang committed
            }
        }

        //
        //  Ok, so now we are at the actual host name, if any. If we are
        //  not at the end of the host data, then lets see if we have a
        //  port trailing the
        //
        ptr1 = XMLString::findAny(fHost, listThree);
        if (ptr1)
        {
            // Remove it from the host name
            *ptr1 = 0;

            // Try to convert it to a numeric port value and store it
            ptr1++;
            if (!XMLString::textToBin(ptr1, fPortNum))
                ThrowXML(MalformedURLException, XMLExcepts::URL_BadPortField);
        }

        // If the host ended up empty, then toss is
        if (!*fHost)
        {
            delete[] fHost;
            fHost = 0;
        }
    }

    // If we are at the end, then we are done now
    if (!*srcPtr)
	{
        return;
	}

    //
    //  Next is the path part. It can be absolute, i.e. starting with a
    //  forward slash character, or relative. Its basically everything up
    //  to the end of the string or to any trailing query or fragment.
    //
    ptr1 = XMLString::findAny(srcPtr, listFive);
    if (!ptr1)
    {
        fMemoryManager->deallocate(fPath);//delete [] fPath;
        fPath = XMLString::replicate(srcPtr, fMemoryManager);
PeiYong Zhang's avatar
PeiYong Zhang committed
        return;
    }

    // Everything from where we are to what we found is the path
    if (ptr1 > srcPtr)
    {
        fMemoryManager->deallocate(fPath);//delete [] fPath;
        fPath = (XMLCh*) fMemoryManager->allocate
        (
            (ptr1 - srcPtr + 1) * sizeof(XMLCh)
        );//new XMLCh[(ptr1 - srcPtr) + 1];
PeiYong Zhang's avatar
PeiYong Zhang committed
        ptr2 = fPath;
        while (srcPtr < ptr1)
            *ptr2++ = *srcPtr++;
        *ptr2 = 0;
    }

    //
    //  If we found a fragment, then it is the rest of the string and we
    //  are done.
    //
    if (*srcPtr == chPound)
    {
        srcPtr++;
        fMemoryManager->deallocate(fFragment);//delete [] fFragment;
        fFragment = XMLString::replicate(srcPtr, fMemoryManager);
PeiYong Zhang's avatar
PeiYong Zhang committed
        return;
    }

    //
    //  The query is either the rest of the string, or up to the fragment
    //  separator.
    //
    srcPtr++;
    ptr1 = XMLString::findAny(srcPtr, listSix);
    fMemoryManager->deallocate(fQuery);//delete [] fQuery;
PeiYong Zhang's avatar
PeiYong Zhang committed
    if (!ptr1)
    {
        fQuery = XMLString::replicate(srcPtr, fMemoryManager);
PeiYong Zhang's avatar
PeiYong Zhang committed
        return;
    }
     else
    {
        fQuery = (XMLCh*) fMemoryManager->allocate
        (
            (ptr1 - srcPtr + 1) * sizeof(XMLCh)
        );//new XMLCh[(ptr1 - srcPtr) + 1];
PeiYong Zhang's avatar
PeiYong Zhang committed
        ptr2 = fQuery;
        while (srcPtr < ptr1)
            *ptr2++ = *srcPtr++;
        *ptr2 = 0;
    }

    // If we are not at the end now, then everything else is the fragment
    if (*srcPtr == chPound)
    {
        srcPtr++;
        fMemoryManager->deallocate(fFragment);//delete [] fFragment;
        fFragment = XMLString::replicate(srcPtr, fMemoryManager);
Tinny Ng's avatar
Tinny Ng committed
XERCES_CPP_NAMESPACE_END