Beispiel #1
0
String cookies(const KURL& url)
{
    DeprecatedString str = url.url();
    char domainBuffer[SIZE_OF_LATIN1_BUFFERS];
    char pathBuffer[SIZE_OF_LATIN1_BUFFERS];
    int tl_domainLocationInUrlBegins = str.find("://") + SIZE_OF_COLONSLASHSLASH;
    int tl_domainLocationInUrlEnds = str.find("/",tl_domainLocationInUrlBegins) - 1;
    int tl_pathLocationInUrlEnds = str.findRev("/");
    
    strncpy(domainBuffer, str.ascii() + tl_domainLocationInUrlBegins, tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1);
    domainBuffer[tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1] = '\0';

    strncpy(pathBuffer, str.ascii() + tl_domainLocationInUrlEnds + 1, tl_pathLocationInUrlEnds - tl_domainLocationInUrlEnds);
    pathBuffer[tl_pathLocationInUrlEnds - tl_domainLocationInUrlEnds] = '\0';

    char* cookStr = WebKitApollo::g_HostFunctions->getJavaScriptCookies(domainBuffer,pathBuffer);
    if(!cookStr)
    {
        return String();
    }

    String cookieString(cookStr);
    ::free(cookStr);
    return cookieString;
}
Beispiel #2
0
void setCookies(const KURL& url, const KURL& policyURL, const String& value)
{
    DeprecatedString str = url.url();
    
    DeprecatedString result("Set-Cookie:");

    DeprecatedString val = value.deprecatedString();

    //add everything in the cookie
    result.append(val);

    //Check if it had appended domain, path
    bool noDomainSet = !val.contains(DeprecatedString("domain="));
    bool noPathSet = !val.contains(DeprecatedString("path="));


    if(noDomainSet || noPathSet)
    {
        char pathBuffer[SIZE_OF_LATIN1_BUFFERS];
        char domainBuffer[SIZE_OF_LATIN1_BUFFERS];

        int tl_domainLocationInUrlBegins = str.find("://") + SIZE_OF_COLONSLASHSLASH;
        int tl_domainLocationInUrlEnds = str.find("/",tl_domainLocationInUrlBegins) - 1;
        result.append(';');
        
        if(noDomainSet)
        {
            str.copyLatin1(domainBuffer, tl_domainLocationInUrlBegins, 
                           tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1);
            domainBuffer[tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1] = '\0';
            result.append(DeprecatedString(" domain="));
            result.append(DeprecatedString::fromLatin1(domainBuffer));
            result.append(';');
        }

        if(noPathSet)
        {
            int tl_pathLocationInUrlEnds = str.findRev("/");
            str.copyLatin1(pathBuffer, tl_domainLocationInUrlEnds + 1, // 1 because it'll include '/'
                           tl_pathLocationInUrlEnds - tl_domainLocationInUrlEnds ); 
            pathBuffer[tl_pathLocationInUrlEnds = tl_domainLocationInUrlEnds] = '\0';
            result.append(DeprecatedString(" path="));
            result.append(DeprecatedString::fromLatin1(pathBuffer));
            result.append(';');
        }
    }

    if(val.startsWith(DeprecatedString("https://")))
    {
        result.append(DeprecatedString(" secure"));
    }

    //Connect with Runtime.    
    //
    WebKitApollo::g_HostFunctions->setJavaScriptCookie(result.latin1());
}
DeprecatedStringList DeprecatedStringList::split(const DeprecatedString &separator, const DeprecatedString &s, bool allowEmptyEntries)
{
    DeprecatedStringList result;

    int startPos = 0;
    int endPos;
    while ((endPos = s.find(separator, startPos)) != -1) {
        if (allowEmptyEntries || startPos != endPos)
            result.append(s.mid(startPos, endPos - startPos));
        startPos = endPos + separator.length();
    }
    if (allowEmptyEntries || startPos != (int)s.length())
        result.append(s.mid(startPos));
            
    return result;
}