示例#1
0
String cookies(const KURL& url)
{
#if USE(CFNETWORK)
    CFHTTPCookieStorageRef defaultCookieStorage = wkGetDefaultHTTPCookieStorage();
    if (!defaultCookieStorage)
        return String();

    String cookieString;
    RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL());

    bool secure = equalIgnoringCase(url.protocol(), "https");

    RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieStorageCopyCookiesForURL(defaultCookieStorage, urlCF.get(), secure));
    RetainPtr<CFDictionaryRef> headerCF(AdoptCF, CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, cookiesCF.get()));

    return (CFStringRef)CFDictionaryGetValue(headerCF.get(), s_cookieCF);
#else
    DeprecatedString str = url.url();
    str.append((UChar)'\0');

    DWORD count = str.length();
    InternetGetCookie((UChar*)str.unicode(), 0, 0, &count);
    if (count <= 1) // Null terminator counts as 1.
        return String();

    UChar* buffer = new UChar[count];
    InternetGetCookie((UChar*)str.unicode(), 0, buffer, &count);
    String& result = String(buffer, count-1); // Ignore the null terminator.
    delete[] buffer;
    return result;
#endif
}
示例#2
0
String cookies(const Document* /*document*/, const KURL& url)
{
    String str = url.string();

    DWORD count = str.length() + 1;
    InternetGetCookie(str.charactersWithNullTermination(), 0, 0, &count);
    if (count <= 1) // Null terminator counts as 1.
        return String();

    Vector<UChar> buffer(count);
    InternetGetCookie(str.charactersWithNullTermination(), 0, buffer.data(), &count);
    buffer.shrink(count - 1); // Ignore the null terminator.
    return String::adopt(buffer);
}
示例#3
0
String cookies(const KURL& url)
{
    DeprecatedString str = url.url();
    str.append((UChar)'\0');

    DWORD count;
    InternetGetCookie((UChar*)str.unicode(), 0, 0, &count);
    if (count <= 1) // Null terminator counts as 1.
        return String();

    UChar* buffer = new UChar[count];
    InternetGetCookie((UChar*)str.unicode(), 0, buffer, &count);
    String& result = String(buffer, count-1); // Ignore the null terminator.
    delete buffer;
    return result;
}
示例#4
0
文件: bbAuth.c 项目: tsupo/bookey
void
doYahooStep2(
        char       *buffer,
        char       *request,
        const char *target,
        char       *cookie,
        size_t     *cookieSize
    )
{
    // 「同意する」ボタンを押す
    const char  *p, *q;
    char        url[BUFSIZ * 2];

    dputs( "doYahooStep2(): 実行開始\n" );

    p = strstr( buffer, "<form action=\"" );
    if ( p ) {
        p += 14;
        q = strchr( p, '"' );
        if ( q ) {
            strncpy( url, p, q - p );
            url[q - p] = NUL;
        }

        strcpy( request, "na=0" );
        _httpPostIC( url, request, buffer, TRUE );
        if ( *buffer )
            InternetGetCookie( target,
                               "external_session",
                               cookie,
                               (unsigned long *)cookieSize );
    }
}
示例#5
0
static void test_get_cookie(void)
{
  DWORD len;
  BOOL ret;

  SetLastError(0xdeadbeef);
  ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
  ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
    "InternetGetCookie should have failed with %s and error %ld\n",
    ret ? "TRUE" : "FALSE", GetLastError());
}
示例#6
0
String cookiesForDOM(const NetworkStorageSession&, const URL&, const URL& url)
{
    // FIXME: Deal with firstParty argument.

    String str = url.string();

    DWORD count = 0;
    if (!InternetGetCookie(str.charactersWithNullTermination().data(), 0, 0, &count))
        return String();

    if (count <= 1) // Null terminator counts as 1.
        return String();

    Vector<UChar> buffer(count);
    if (!InternetGetCookie(str.charactersWithNullTermination().data(), 0, buffer.data(), &count))
        return String();

    buffer.shrink(count - 1); // Ignore the null terminator.
    return String::adopt(buffer);
}
示例#7
0
文件: iehook.c 项目: 0x00dec0de/GMbot
//
//	Returns Cookie string for the specified URL.
//
LPTSTR IeGetCookie(
	LPTSTR pUrl
	)
{
	LPTSTR	pCookie = NULL;
	ULONG	Size = 0;

	InternetGetCookie(pUrl, NULL, NULL, &Size); 
	if (Size && (pCookie = hAlloc(Size + sizeof(_TCHAR))))
	{
		if (!InternetGetCookie(pUrl, NULL, pCookie, &Size))
		{
			hFree(pCookie);
			pCookie = NULL;
		}
		else
			pCookie[Size] = 0;
	}	// if (Size && (pCookie = AppAlloc(Size * sizeof(_TCHAR))))

	return(pCookie);
}
示例#8
0
char* CpeepmBrowser::GetCookie()
{
    const char* http = "http://";
    UINT len = strlen(http) + strlen(Server);
    char* buffer = new char[len + 1];
    ZeroMemory(buffer, len + 1);
    strcat(buffer, http);
    strcat(buffer, Server);
    wchar_t* host = CpeepmUtil::CharToWideChar(buffer, len);
    ReleaseArray(buffer);
    if (host == NULL)
        return NULL;

    wchar_t tmp[1] = {0};
    DWORD size = 0;
    InternetGetCookie(host, NULL, tmp, &size);
    if (size == 0)
    {
        ReleaseArray(host);
        return NULL;
    }

    wchar_t* cookie = new wchar_t[size / 2 + 1];
    wmemset(cookie, 0, size / 2 + 1);
    InternetGetCookie(host, NULL, cookie, &size);
    ReleaseArray(host);
    len = wcslen(cookie);
    if (len > 0)
    {
        char* c = CpeepmUtil::WideCharToChar(cookie, len);
        ReleaseArray(cookie);
        return c;
    }
    else
    {
        ReleaseArray(cookie);
        return NULL;
    }
}
fsInternetResult fsHttpFile::Open_imp(LPCSTR pszFilePath, UINT64 uStartPos, int cTryings)
{
	if (!m_pServer) 
		return IR_NOTINITIALIZED;

	HINTERNET hServer = m_pServer->GetHandle ();  

	if (!hServer)	
		return IR_NOTINITIALIZED;

	CloseHandle ();

	if (lstrlen (pszFilePath) > 9000)
		return IR_BADURL;

	if (cTryings > 1)
		return IR_WININETUNKERROR;

	DWORD dwFlags = m_dwFlags;
	if (m_pszCookies)
		dwFlags |= INTERNET_FLAG_NO_COOKIES;
	if (m_bEnableAutoRedirect == FALSE)
		dwFlags |= INTERNET_FLAG_NO_AUTO_REDIRECT;

	LPTSTR ppszAcceptedTypes [2] = { "*/*", NULL }; 

	
	
	
	

	LPCSTR pszVerb = "GET";
	if (m_pszPostData)
		pszVerb = "POST";
	else if (m_bHeadersOnly)
		pszVerb = "HEAD";

	
	m_hFile = HttpOpenRequest (hServer, pszVerb, pszFilePath, m_pszHttpVersion,
		m_pszReferer, (LPCSTR*) ppszAcceptedTypes, 
		dwFlags | INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE | 
		INTERNET_FLAG_NO_CACHE_WRITE, NULL);

	if (m_hFile == NULL)
		return fsWinInetErrorToIR ();

	fsInternetResult ir = SetupProxy ();
	if (ir != IR_SUCCESS)
	{
		CloseHandle ();
		return ir;
	}

	
	CHAR szHdr [20000] = "";

	if (uStartPos)
		sprintf (szHdr, "Range: bytes=%I64u-\r\n", uStartPos); 

	if (m_pszCookies)
		sprintf (szHdr + lstrlen (szHdr), "Cookie: %s\r\n", m_pszCookies); 

	if (m_pszPostData)
		strcat (szHdr, "Content-Type: application/x-www-form-urlencoded\r\n");

	if (m_pszAdditionalHeaders)
		strcat (szHdr, m_pszAdditionalHeaders);

	if (cTryings == 0)
	{
		
		char szReq [90000];
		sprintf (szReq, "%s %s %s\r\nReferer: %s", pszVerb, 
			pszFilePath, m_pszHttpVersion, 
			m_pszReferer ? m_pszReferer : "-");

		if (*szHdr)
		{
			strcat (szReq, "\r\n");
			strcat (szReq, szHdr);
			szReq [strlen (szReq) - 2] = 0;	
		}

		if ((dwFlags & INTERNET_FLAG_NO_COOKIES) == 0)
		{
			char szUrl [10000]; DWORD dw = sizeof (szUrl);
			fsURL url;
			url.Create (m_dwFlags & INTERNET_FLAG_SECURE ? INTERNET_SCHEME_HTTPS : INTERNET_SCHEME_HTTP,
				m_pServer->GetServerName (), m_pServer->GetServerPort (), 
				NULL, NULL, pszFilePath, szUrl, &dw);

			char szCookie [10000]; dw = sizeof (szCookie);
			*szCookie = 0;
			
			InternetGetCookie (szUrl, NULL, szCookie, &dw);

			if (*szCookie)
			{
				strcat (szReq, "\r\n");
				strcat (szReq, "Cookie: ");
				strcat (szReq, szCookie);
			}
		}

		strcat (szReq, "\r\nHost: ");
		strcat (szReq, m_pServer->GetServerName ());

		if (m_pszPostData)
		{
			strcat (szReq, "\r\n");
			strcat (szReq, m_pszPostData);
		}

		Dialog (IFDD_TOSERVER, szReq);	
	}

	
	IgnoreSecurityProblems ();

	
	if (!HttpSendRequest (m_hFile, *szHdr ? szHdr : NULL, (UINT)-1, 
			m_pszPostData, m_pszPostData ? lstrlen (m_pszPostData) : 0))
	{
		ir = fsWinInetErrorToIR ();

		DialogHttpResponse (m_hFile);	
									
		CloseHandle ();
		return  ir; 
	}

	char szResp [10000];
	DWORD dwRespLen = sizeof (szResp), dwIndex = 0;
	
	
	if (HttpQueryInfo (m_hFile, HTTP_QUERY_RAW_HEADERS_CRLF, szResp, &dwRespLen, &dwIndex))
	{
		int cLines = 0; 

		

		LPCSTR pszLine = szResp;
		while (pszLine)
		{
			pszLine = strchr (pszLine, '\n');
			if (pszLine)
			{
				while (*pszLine == '\r' || *pszLine == '\n')
					pszLine++;
				cLines++;
			}
		}

		if (cLines == 0 || cLines == 1)
		{
			
			
			return Open_imp (pszFilePath, uStartPos, ++cTryings);
		}
	}

	DialogHttpResponse (m_hFile);	

	DWORD dwStatusCode;	
	DWORD dwSize = sizeof (DWORD);
	if (!HttpQueryInfo(m_hFile, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, 
			&dwStatusCode, &dwSize, NULL))	
		return fsWinInetErrorToIR ();

	if (dwStatusCode < 200 || dwStatusCode >= 300)	
	{
		ir = fsHttpStatusCodeToIR (dwStatusCode);

		if (ir == IR_NEEDREDIRECT)	
		{
			DWORD dwNeedLen = 0;

			HttpQueryInfo (m_hFile, HTTP_QUERY_LOCATION, NULL, &dwNeedLen,
				NULL);

			if (::GetLastError () == ERROR_INSUFFICIENT_BUFFER)
			{
				SAFE_DELETE_ARRAY (m_pszLastError);
				try {
					m_pszLastError = new char [++dwNeedLen];
				}catch (...) {return IR_OUTOFMEMORY;}
				if (m_pszLastError == NULL)
					return IR_OUTOFMEMORY;
				if (!HttpQueryInfo (m_hFile, HTTP_QUERY_LOCATION, m_pszLastError, &dwNeedLen,
						NULL)) 
					return IR_SERVERUNKERROR;
			}
			else
				return IR_SERVERUNKERROR;

		}

		return ir;
	}

	
	char szContLen [1000];
	DWORD dwLen = sizeof (szContLen);
	if (HttpQueryInfo (m_hFile, HTTP_QUERY_CONTENT_LENGTH,	szContLen, &dwLen, NULL)) {
		__int64 iSize = _atoi64 (szContLen);
		if (iSize < 0)
			return IR_SERVERUNKERROR;
		m_uFileSize = (UINT64) iSize;
	}
	else
		m_uFileSize = _UI64_MAX; 

	ir = IR_SUCCESS;
	if (uStartPos)
	{
		
		ir = ProcessRangesResponse ();
		if (ir == IR_RANGESNOTAVAIL) 
			return ir;
	}
	else
	{
		CHAR sz [10000];
		DWORD dw = sizeof (sz);
		
		
		if (HttpQueryInfo (m_hFile, HTTP_QUERY_ACCEPT_RANGES, sz, &dw, NULL))
		{
			if (stricmp (sz, "bytes") == 0)
				m_enRST = RST_PRESENT;
			else
				m_enRST = RST_NONE;
		}
		else
			m_enRST = RST_UNKNOWN;
	}

	m_bContentTypeValid = FALSE;
	m_bDateValid = FALSE;

	CHAR szContentType [10000];	
	DWORD dwCL = sizeof (szContentType);
	if (HttpQueryInfo (m_hFile, HTTP_QUERY_CONTENT_TYPE, szContentType, &dwCL, NULL))
	{
		m_strContentType = szContentType;
		m_bContentTypeValid = TRUE;
	}

	SYSTEMTIME time; 
	DWORD dwTL = sizeof (time);
	if (HttpQueryInfo (m_hFile, HTTP_QUERY_LAST_MODIFIED | HTTP_QUERY_FLAG_SYSTEMTIME,
		&time, &dwTL, NULL))
	{
		SystemTimeToFileTime (&time, &m_date);
		m_bDateValid = TRUE;
	}

	RetreiveSuggFileName ();	

	return ir;
}
示例#10
0
int vmsIETmpCookies::Find(LPCSTR pszUrl)
{
	fsURL url;
	if (IR_SUCCESS != url.Crack (pszUrl))
		return -1;

	char szCookie [50000] = "";
	DWORD dw = sizeof (szCookie);
	InternetGetCookie (pszUrl, NULL, szCookie, &dw);
	vmsCookie cookie; cookie.Set (szCookie);

	GetListOfKnownCookies ();

	
	fs::list <int> vFit;

	for (int i = 0; i < m_vBeforeNavUrls.size (); i++)
	{
		if (m_vBeforeNavUrls [i] == pszUrl)
		{
			
			
			vFit.add (i);
			break;
		}
	}

	for (int bEx = 0; bEx < 2 && vFit.size () == 0; bEx++)
	{
		

		for (int i = 0; i < m_vUrls.size (); i++)
		{
			fsURL url2;
			if (IR_SUCCESS != url2.Crack (m_vUrls [i].c_str ()))
				continue;

			if (fsIsServersEqual (url.GetHostName (), url2.GetHostName (), bEx))
				vFit.add (i);
		}
	}

	if (vFit.size () == 0)
	{
		

		string str1 = GetLevel2DomainName (url.GetHostName ());

		for (int i = 0; i < m_vUrls.size (); i++)
		{
			fsURL url2;
			if (IR_SUCCESS != url2.Crack (m_vUrls [i].c_str ()))
				continue;

			string str2 = GetLevel2DomainName (url2.GetHostName ());

			if (str1 == str2)
				vFit.add (i);
		}
	}

	int nIndex = -1;
	int cCI = -1;
	int len = 0;
	
	
	for (i = 0; i < vFit.size (); i++)
	{
		int n = vFit [i];	
		vmsCookie c; c.Set (get_Cookies (n));
		int cCI2 = cookie.GetCommonItemCount (&c);
		if (cCI2 > cCI || (cCI2 == cCI && len < c.get_ItemCount ()))
		{
			nIndex = n;
			cCI = cCI2;
			len = c.get_ItemCount ();
		}
	}

	if (nIndex != -1)
	{
		vmsCookie c; c.Set (get_Cookies (nIndex));
		cookie.Add (&c);
		m_vCookies [nIndex] = cookie.toString ();
	}

	return nIndex;
}