Example #1
0
CookieJar::CookieJar(QObject *parent) : QNetworkCookieJar(parent) {
	//Read allowed cookiedomains
    QFile allowedDomains(QDir::homePath()+"/.ybdb/whitelistCookies");
	if (allowedDomains.exists()) {
		allowedDomains.open(QFile::ReadOnly);
		while (allowedDomains.bytesAvailable()) {
			QByteArray arr = allowedDomains.readLine();
			QString domain = QString::fromUtf8(arr);
			if (domain.endsWith("\n"))
				domain.chop(1);
			if (domain.size() < 1) continue;
			qDebug() << "Whitelisted cookiedomain: " << domain;
			allowedCookieDomains.append(domain);
		}
		allowedDomains.close();
	}
	allowedCookieDomains.removeDuplicates();

	//Read saved cookies
    QFile cookies(QDir::homePath()+"/.ybdb/cookies");
	if (cookies.exists()) {
		QList<QNetworkCookie> cookieList;
		cookies.open(QFile::ReadOnly);
		while (cookies.bytesAvailable()) {
			QByteArray arr = cookies.readLine();
			QString cookie = QString::fromUtf8(arr);
			if (cookie.endsWith("\n")) cookie.chop(1);
			cookieList.append(QNetworkCookie::parseCookies(cookie.toUtf8()));
		}
		cookies.close();
		setAllCookies(cookieList);
	}
    qDebug()<<"alfkjalsjkalgjaljskl";
    //saveAll = Settings::get("saveallcookies", QVariant(true)).toBool();
}
Example #2
0
bool NetworkTask::performQuery() {
	#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	_handle.setRootCertificateFile(filesystem::writablePath("ca_bundle.pem"));
	#endif

	if (_handle.getCookieFile().empty()) {
		std::string cookies("network.cookies");
		if (!ThreadManager::getInstance()->isMainThread()) {
			auto &local = Thread::getThreadLocalStorage();
			if (!local.isNull() && local.getBool("managed_thread")) {
				cookies = filesystem::writablePath(
						toString(cookies, ".", Thread::getThreadName(), ".", Thread::getThreadId(), ".", Thread::getWorkerId()));
			} else {
				cookies = filesystem::writablePath(
						toString(cookies, ".native.", ThreadManager::getInstance()->getNativeThreadId()));
			}
		} else {
			cookies = filesystem::writablePath(std::string(cookies) + ".main");
		}

		_handle.setCookieFile(cookies);
	}

	_handle.setUserAgent(Device::getInstance()->getUserAgent());

	return _handle.perform();
}
Example #3
0
QByteArray ShibbolethCredentials::prepareCookieData() const
{
    QString cookiesAsString;
    // TODO: This should not be a part of this method, but we don't
    // have any way to get "session_key" module property from
    // csync. Had we have it, then we could just append shibboleth
    // cookies to the "session_key" value and set it in csync module.
    QList<QNetworkCookie> cookies(AccountManager::instance()->account()->lastAuthCookies());
    QMap<QString, QString> uniqueCookies;

    cookies << _shibCookie;
    // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply
    // when https://github.com/owncloud/core/pull/4042 is merged.
    foreach(QNetworkCookie c, cookies) {
        const QString cookieName(c.name());

        if (cookieName.startsWith("_shibsession_")) {
            continue;
        }
        uniqueCookies.insert(cookieName, c.value());
    }

    if (!_shibCookie.name().isEmpty()) {
        uniqueCookies.insert(_shibCookie.name(), _shibCookie.value());
    }
    foreach(const QString& cookieName, uniqueCookies.keys()) {
        cookiesAsString += cookieName;
        cookiesAsString += '=';
        cookiesAsString += uniqueCookies[cookieName];
        cookiesAsString += "; ";
    }

    return cookiesAsString.toLatin1();
}
void SessionStore::resetSession(HttpServerRequest &request) const
{
    // init variables
    QList<QByteArray> headers(request.headers().values("Cookie"));
    QByteArray newValue;

    // remove old cookies
    request.headers().remove("Cookie");

    // find cookies that don't match this store's settings
    for (int i = 0;i != headers.size();++i) {
        QList<QNetworkCookie> cookies(QNetworkCookie::parseCookies(headers[i]));

        for (int i = 0;i != cookies.size();++i) {
            if (cookies[i].name() != settings.name) {
                newValue
                    += cookies[i].toRawForm(QNetworkCookie::NameAndValueOnly)
                    + "; ";
            }
        }
    }

    if (!newValue.isEmpty()) {
        // removes the final "; "
        newValue.remove(newValue.size() - 2, 2);
    }

    // update the request headers
    request.headers().insert("Cookie", newValue);
}
    void MatchFail1() 
  {
	HTTPS::Securecookies cookies("^.*\\.google\\.com$", "bar");
	bool match = cookies.IsMatch("www.google.com", "foo");

	CFIX_ASSERT(match == false);
  }
  void MatchOK() 
  {
	HTTPS::Securecookies cookies("^.*\\.google\\.com$", ".+");
	bool match = cookies.IsMatch("www.google.com", "foo");

	CFIX_ASSERT(match);
  }
void CleanableCookieJar::clean_session_cookies(){
  QList<QNetworkCookie> cookies(allCookies());

  for(QList<QNetworkCookie>::iterator i = cookies.begin(); i != cookies.end(); i++)
    while(i->isSessionCookie())
      i = cookies.erase(i);

  setAllCookies(cookies);
}
Example #8
0
static String cookiesForContext(NetworkingContext* context, const KURL& url, bool forHTTPHeader)
{
    SoupCookieJar* jar = context ? cookieJarForContext(context) : soupCookieJar();
    if (!jar)
        return String();

    GOwnPtr<SoupURI> uri(soup_uri_new(url.string().utf8().data()));
    GOwnPtr<char> cookies(soup_cookie_jar_get_cookies(jar, uri.get(), forHTTPHeader));
    return String::fromUTF8(cookies.get());
}
static String cookiesForSession(const NetworkStorageSession& session, const KURL& url, bool forHTTPHeader)
{
    SoupCookieJar* jar = cookieJarForSession(session);
    if (!jar)
        return String();

    GOwnPtr<SoupURI> uri(soup_uri_new(url.string().utf8().data()));
    GOwnPtr<char> cookies(soup_cookie_jar_get_cookies(jar, uri.get(), forHTTPHeader));
    return String::fromUTF8(cookies.get());
}
Example #10
0
QNetworkCookie CookieJar::getCookie(const QString& name, const QUrl& url)
{
	purgeExpiredCookies();

	QList<QNetworkCookie> cookieList = cookies(url);
	for(int i = cookieList.count() - 1;i >= 0; --i) {
		if(cookieList.at(i).name() == name) return cookieList.at(i);
	}
	return QNetworkCookie();
}
Example #11
0
void deleteAllCookies(NetworkingContext* context)
{
    SoupCookieJar* cookieJar = context ? cookieJarForContext(context) : soupCookieJar();
    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
        soup_cookie_jar_delete_cookie(cookieJar, cookie);
        soup_cookie_free(cookie);
    }
}
Example #12
0
static String cookiesForSession(const NetworkStorageSession& session, const URL& url, bool forHTTPHeader)
{
    SoupCookieJar* jar = cookieJarForSession(session);
    if (!jar)
        return String();

    GUniquePtr<SoupURI> uri = url.createSoupURI();
    GUniquePtr<char> cookies(soup_cookie_jar_get_cookies(jar, uri.get(), forHTTPHeader));
    return String::fromUTF8(cookies.get());
}
Example #13
0
void deleteAllCookies(const NetworkStorageSession& session)
{
    SoupCookieJar* cookieJar = cookieJarForSession(session);
    GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
        soup_cookie_jar_delete_cookie(cookieJar, cookie);
        soup_cookie_free(cookie);
    }
}
Example #14
0
void getHostnamesWithCookies(NetworkingContext* context, HashSet<String>& hostnames)
{
    SoupCookieJar* cookieJar = context ? cookieJarForContext(context) : soupCookieJar();
    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
        GOwnPtr<SoupCookie> cookie(static_cast<SoupCookie*>(item->data));
        if (!cookie->domain)
            continue;
        hostnames.add(String::fromUTF8(cookie->domain));
    }
}
Example #15
0
void getHostnamesWithCookies(const NetworkStorageSession& session, HashSet<String>& hostnames)
{
    SoupCookieJar* cookieJar = cookieJarForSession(session);
    GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
        if (cookie->domain)
            hostnames.add(String::fromUTF8(cookie->domain));
        soup_cookie_free(cookie);
    }
}
Example #16
0
void deleteCookiesForHostname(const NetworkStorageSession& session, const String& hostname)
{
    CString hostNameString = hostname.utf8();
    SoupCookieJar* cookieJar = cookieJarForSession(session);
    GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
        if (soup_cookie_domain_matches(cookie, hostNameString.data()))
            soup_cookie_jar_delete_cookie(cookieJar, cookie);
        soup_cookie_free(cookie);
    }
}
Example #17
0
void deleteCookiesForHostname(NetworkingContext* context, const String& hostname)
{
    CString hostNameString = hostname.utf8();
    SoupCookieJar* cookieJar = context ? cookieJarForContext(context) : soupCookieJar();
    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
        if (soup_cookie_domain_matches(cookie, hostNameString.data()))
            soup_cookie_jar_delete_cookie(cookieJar, cookie);
        soup_cookie_free(cookie);
    }
}
Example #18
0
File: b.cpp Project: M4573R/pc-code
double solve()
{
	double ans = X/2;

	for (int i = 1; true; ++i) {
		double tmp = cookies(i);
		if (tmp < ans)
			ans = tmp;
		else if (tmp > ans)
			break;

	}
	return ans;
}
Example #19
0
void HttpCredentials::syncContextPreStart (CSYNC* ctx)
{
    // TODO: This should not be a part of this method, but we don't have
    // any way to get "session_key" module property from csync. Had we
    // have it, then we could remove this code and keep it in
    // csyncthread code (or folder code, git remembers).
    QList<QNetworkCookie> cookies(ownCloudInfo::instance()->getLastAuthCookies());
    QString cookiesAsString;

    // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply
    // when https://github.com/owncloud/core/pull/4042 is merged.
    foreach(QNetworkCookie c, cookies) {
        cookiesAsString += c.name();
        cookiesAsString += '=';
        cookiesAsString += c.value();
        cookiesAsString += "; ";
    }
void OwncloudShibbolethCredsPage::slotOtherCookiesReceived(const QList<QNetworkCookie>& cookieList, const QUrl& url)
{
    QList<QNetworkCookie>& cookies(_cookiesForUrl[url]);
    QMap<QByteArray, QByteArray> uniqueCookies;

    Q_FOREACH (const QNetworkCookie& c, cookieList) {
        if (!c.isSessionCookie()) {
            cookies << c;
        }
    }
    Q_FOREACH (const QNetworkCookie& c, cookies) {
        uniqueCookies[c.name()] = c.value();
    }
    cookies.clear();
    Q_FOREACH (const QByteArray& name, uniqueCookies.keys()) {
        cookies << QNetworkCookie(name, uniqueCookies[name]);
    }
}
Example #21
0
void deleteCookie(NetworkingContext* context, const KURL& url, const String& name)
{
    SoupCookieJar* jar = context ? cookieJarForContext(context) : soupCookieJar();
    if (!jar)
        return;

    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(jar));
    if (!cookies)
        return;

    CString cookieName = name.utf8();
    GOwnPtr<SoupURI> uri(soup_uri_new(url.string().utf8().data()));
    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
        GOwnPtr<SoupCookie> cookie(static_cast<SoupCookie*>(iter->data));
        if (!soup_cookie_applies_to_uri(cookie.get(), uri.get()))
            continue;
        if (cookieName == cookie->name)
            soup_cookie_jar_delete_cookie(jar, cookie.get());
    }
}
QByteArray SessionStore::session(const HttpServerRequest &request,
                                 const HttpServerResponse &response) const
{
    // init variables
    QList<QByteArray> headers(response.headers().values("Set-Cookie"));

    // try to find a compatible cookie...
    // ...and returns the first
    for (int i = 0;i != headers.size();++i) {
        QList<QNetworkCookie> cookies(QNetworkCookie::parseCookies(headers[i]));

        for (int i = 0;i != cookies.size();++i) {
            if (cookies[i].name() == settings.name)
                return unsignSession(cookies[i].value());
        }
    }

    // cannot find a compatible cookie in response's Set-Cookie header...
    // ...try request's "Cookie" header
    return session(request);
}
Example #23
0
void deleteCookie(const NetworkStorageSession& session, const URL& url, const String& name)
{
    SoupCookieJar* jar = cookieJarForSession(session);
    if (!jar)
        return;

    GUniquePtr<SoupURI> uri = url.createSoupURI();
    GUniquePtr<GSList> cookies(soup_cookie_jar_get_cookie_list(jar, uri.get(), TRUE));
    if (!cookies)
        return;

    CString cookieName = name.utf8();
    bool wasDeleted = false;
    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(iter->data);
        if (!wasDeleted && cookieName == cookie->name) {
            soup_cookie_jar_delete_cookie(jar, cookie);
            wasDeleted = true;
        }
        soup_cookie_free(cookie);
    }
}
Example #24
0
bool getRawCookies(const NetworkStorageSession& session, const URL& /*firstParty*/, const URL& url, Vector<Cookie>& rawCookies)
{
    rawCookies.clear();
    SoupCookieJar* jar = cookieJarForSession(session);
    if (!jar)
        return false;

    GUniquePtr<SoupURI> uri = url.createSoupURI();
    GUniquePtr<GSList> cookies(soup_cookie_jar_get_cookie_list(jar, uri.get(), TRUE));
    if (!cookies)
        return false;

    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(iter->data);
        rawCookies.append(Cookie(String::fromUTF8(cookie->name), String::fromUTF8(cookie->value), String::fromUTF8(cookie->domain),
            String::fromUTF8(cookie->path), cookie->expires ? static_cast<double>(soup_date_to_time_t(cookie->expires)) * 1000 : 0,
            cookie->http_only, cookie->secure, !cookie->expires));
        soup_cookie_free(cookie);
    }

    return true;
}
Example #25
0
bool getRawCookies(NetworkingContext* context, const KURL& /*firstParty*/, const KURL& url, Vector<Cookie>& rawCookies)
{
    rawCookies.clear();
    SoupCookieJar* jar = context ? cookieJarForContext(context) : soupCookieJar();
    if (!jar)
        return false;

    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(jar));
    if (!cookies)
        return false;

    GOwnPtr<SoupURI> uri(soup_uri_new(url.string().utf8().data()));
    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
        GOwnPtr<SoupCookie> cookie(static_cast<SoupCookie*>(iter->data));
        if (!soup_cookie_applies_to_uri(cookie.get(), uri.get()))
            continue;
        rawCookies.append(Cookie(String::fromUTF8(cookie->name), String::fromUTF8(cookie->value), String::fromUTF8(cookie->domain),
                                 String::fromUTF8(cookie->path), static_cast<double>(soup_date_to_time_t(cookie->expires)) * 1000,
                                 cookie->http_only, cookie->secure, soup_cookie_jar_is_persistent(jar)));
    }

    return true;
}
String cookieRequestHeaderFieldValue(const Document* document, const KURL& url)
{
    // FIXME: include HttpOnly cookie
    return cookies(document, url);
}
Example #27
0
int spep::apache::RequestHandler::handleRequestInner( request_rec *req )
{
	if( !this->_spep->isStarted() )
	{
		return HTTP_SERVICE_UNAVAILABLE;
	}
	
	spep::SPEPConfigData *spepConfigData = this->_spep->getSPEPConfigData();
	
	char *properURI = apr_pstrdup( req->pool, req->parsed_uri.path );
	if( req->parsed_uri.query != NULL )
	{
		properURI = apr_psprintf( req->pool, "%s?%s", properURI, req->parsed_uri.query );
	}
	
	ap_unescape_url( properURI );
	
	Cookies cookies( req );
	std::vector<std::string> cookieValues;
	cookies.getCookieValuesByName( cookieValues, spepConfigData->getTokenName() );
	if( !cookieValues.empty() )
	{
		std::string sessionID;
		spep::PrincipalSession principalSession;
		bool validSession = false;

		// SPEP cookie was found, validate using one of the values and use that to proceed.
		for (std::vector<std::string>::iterator cookieValueIterator = cookieValues.begin();
			cookieValueIterator != cookieValues.end(); ++cookieValueIterator) {

			sessionID = *cookieValueIterator;
			try {
				principalSession = this->_spep->getAuthnProcessor()->verifySession( sessionID );
				validSession = true;
				break;
			} catch( std::exception& e ) {
			}
		}
		
		if( validSession )
		{
			// If attribute querying is not disabled...
			if( !this->_spep->getSPEPConfigData()->disableAttributeQuery() )
			{
				// Put attributes into the environment.
				
				std::string usernameAttribute = spepConfigData->getUsernameAttribute();
				
				std::string attributeValueSeparator = spepConfigData->getAttributeValueSeparator();
				std::string attributeNamePrefix = spepConfigData->getAttributeNamePrefix();
				for( spep::PrincipalSession::AttributeMapType::iterator attributeIterator = principalSession.getAttributeMap().begin();
					attributeIterator != principalSession.getAttributeMap().end();
					++attributeIterator )
				{
					
					std::string name = spep::UnicodeStringConversion::toString( attributeIterator->first );
					std::string envName = attributeNamePrefix + name;
					
					std::stringstream valueStream;
					bool first = true;
					for( std::vector<UnicodeString>::iterator attributeValueIterator = attributeIterator->second.begin(); 
						attributeValueIterator != attributeIterator->second.end(); 
						++attributeValueIterator )
					{
						std::string value = spep::UnicodeStringConversion::toString( *attributeValueIterator );
						
						if( first )
						{
							valueStream << value;
							first = false;
						}
						else
						{
							valueStream << attributeValueSeparator << value;
						}
					}
					
					std::string envValue = valueStream.str();
					
					// Insert the attribute name/value pair into the subprocess environment.
					apr_table_set( req->subprocess_env, envName.c_str(), envValue.c_str() );
					
					if( name.compare( usernameAttribute ) == 0 )
					{
#ifndef APACHE1
						req->user = apr_pstrdup( req->pool, envValue.c_str() );
#else
						req->connection->user = apr_pstrdup( req->pool, envValue.c_str() );
#endif
					}
				}
			}
			
			if( this->_spep->getSPEPConfigData()->disablePolicyEnforcement() )
			{
				// No need to perform authorization, just let them in.
				return DECLINED;
			}
			
			// Perform authorization on the URI requested.
			spep::PolicyEnforcementProcessorData pepData;
			pepData.setESOESessionID( principalSession.getESOESessionID() );
			pepData.setResource( properURI );
			
			this->_spep->getPolicyEnforcementProcessor()->makeAuthzDecision( pepData );
			spep::Decision authzDecision( pepData.getDecision() );
			
			validSession = false;
			try
			{
				principalSession = this->_spep->getAuthnProcessor()->verifySession( sessionID );
				validSession = true;
			}
			catch( std::exception& e )
			{
			}
			
			if( validSession )
			{
				if( authzDecision == spep::Decision::PERMIT )
				{
					return DECLINED;
				}
				else if( authzDecision == spep::Decision::DENY )
				{
					return HTTP_FORBIDDEN;
				}
				else if( authzDecision == spep::Decision::ERROR )
				{
					return HTTP_INTERNAL_SERVER_ERROR;
				}
				else
				{
					return HTTP_INTERNAL_SERVER_ERROR;
				}
			}
		}
	}
	
	// If we get to this stage, the session has not been authenticated. We proceed to clear the
	// cookies configured by the SPEP to be cleared upon logout, since this is potentially the
	// first time they have come back to the SPEP since logging out.
	
	bool requireSend = false;
	const std::vector<std::string>& logoutClearCookies = this->_spep->getSPEPConfigData()->getLogoutClearCookies();
	for( std::vector<std::string>::const_iterator logoutClearCookieIterator = logoutClearCookies.begin();
		logoutClearCookieIterator != logoutClearCookies.end();
		++logoutClearCookieIterator )
	{
		// Throw the configured string into a stringstream
		std::stringstream ss( *logoutClearCookieIterator );
		
		// Split into name, domain, path. Doc says that stringstream operator>> won't throw
		std::string cookieNameString, cookieDomainString, cookiePathString;
		ss >> cookieNameString >> cookieDomainString >> cookiePathString;

		// Default to NULL, and then check if they were specified
		const char *cookieName = NULL, *cookieDomain = NULL, *cookiePath = NULL;
		// No cookie name, no clear.
		if( cookieNameString.length() == 0 )
		{
			continue;
		}
		
		// If the user sent this cookie.
		Cookies cookies( req );
		std::vector<std::string> cookieValues;
		cookies.getCookieValuesByName( cookieValues, spepConfigData->getTokenName() );
		if( !cookieValues.empty() ) {
			cookieName = cookieNameString.c_str();
			
			if( cookieDomainString.length() > 0 )
			{
				cookieDomain = cookieDomainString.c_str();
			}
			
			if( cookiePathString.length() > 0 )
			{
				cookiePath = cookiePathString.c_str();
			}
			
			// Set the cookie to an empty value.
			cookies.addCookie( req, cookieName, "", cookiePath, cookieDomain, false );
			
			// Flag that we need to send the cookies, because we have set at least one.
			requireSend = true;
		}
	}
	
	if( requireSend )
	{
		cookies.sendCookies( req );
	}
	
	// Lazy init code.
	if( spepConfigData->isLazyInit() )
	{
		
		std::string globalESOECookieName( spepConfigData->getGlobalESOECookieName() );
		Cookies cookies( req );
		std::vector<std::string> cookieValues;
		cookies.getCookieValuesByName( cookieValues, globalESOECookieName );
		if( cookieValues.empty() ) {
			bool matchedLazyInitResource = false;
			UnicodeString properURIUnicode( spep::UnicodeStringConversion::toUnicodeString( properURI ) );
			
			std::vector<UnicodeString>::const_iterator lazyInitResourceIterator;
			for( lazyInitResourceIterator = spepConfigData->getLazyInitResources().begin();
				lazyInitResourceIterator != spepConfigData->getLazyInitResources().end();
				++lazyInitResourceIterator )
			{
				// TODO Opportunity for caching of compiled regex patterns is here.
				UParseError parseError;
				UErrorCode errorCode = U_ZERO_ERROR;
				// Perform the regular expression matching here.
				UBool result = RegexPattern::matches( *lazyInitResourceIterator, properURIUnicode, parseError, errorCode );
				
				if ( U_FAILURE( errorCode ) )
				{
					// TODO throw u_errorName( errorCode )
					return HTTP_INTERNAL_SERVER_ERROR;
				}
				
				// FALSE is defined by ICU. This line for portability.
				if (result != FALSE)
				{
					matchedLazyInitResource = true;
					break;
				}
			}
			
			if( matchedLazyInitResource )
			{
				if( !spepConfigData->isLazyInitDefaultPermit() )
				{
					return DECLINED;
				}
			}
			else
			{
				if( spepConfigData->isLazyInitDefaultPermit() )
				{
					return DECLINED;
				}
			}
		}
	}
	
	boost::posix_time::ptime epoch( boost::gregorian::date( 1970, 1, 1 ) );
	boost::posix_time::time_duration timestamp = boost::posix_time::microsec_clock::local_time() - epoch;
	boost::posix_time::time_duration::tick_type currentTimeMillis = timestamp.total_milliseconds();
	
	apr_uri_t *uri = static_cast<apr_uri_t*>( apr_pcalloc( req->pool, sizeof(apr_uri_t) ) );
	apr_uri_parse( req->pool, this->_spep->getSPEPConfigData()->getServiceHost().c_str(), uri );
	
	const char *hostname = apr_table_get( req->headers_in, "Host" );
	if( hostname == NULL )
	{
		hostname = req->server->server_hostname;
	}
	
	const char *format = NULL;
	const char *base64RequestURI = NULL;
	// If we can't determine our own hostname, just fall through to the service host.
	// If the service host was requested obviously we want that.
	if( hostname == NULL || std::strcmp( uri->hostinfo, hostname ) == 0 )
	{
		// Join the service hostname and requested URI to form the return URL
		char *returnURL = apr_psprintf( req->pool, "%s%s", 
				this->_spep->getSPEPConfigData()->getServiceHost().c_str(), req->unparsed_uri );
		
		// Base64 encode this so that the HTTP redirect doesn't corrupt it.
		base64RequestURI = ap_pbase64encode( req->pool, returnURL );
		
		// Create the format string for building the redirect URL.
		format = apr_psprintf( req->pool, "%s%s", this->_spep->getSPEPConfigData()->getServiceHost().c_str(), 
					this->_spep->getSPEPConfigData()->getSSORedirect().c_str() );
	}
	else
	{
		base64RequestURI = ap_pbase64encode( req->pool, req->unparsed_uri );
		// getSSORedirect() will only give us a temporary.. dup it into the pool so we don't lose it when we leave this scope.
		format = apr_pstrdup( req->pool, this->_spep->getSPEPConfigData()->getSSORedirect().c_str() );
	}
	
	char *redirectURL = apr_psprintf( req->pool, format, base64RequestURI );
	
	std::stringstream timestampParameter;
	if( strchr( redirectURL, '?' ) != NULL )
	{
		// Query string already exists.. append the timestamp as another parameter
		timestampParameter << "&ts=" << currentTimeMillis;
		redirectURL = apr_psprintf( req->pool, "%s%s", redirectURL, timestampParameter.str().c_str() );
	}
	else
	{
		// No query string. Add one with the timestamp as a parameter.
		timestampParameter << "?ts=" << currentTimeMillis;
		redirectURL = apr_psprintf( req->pool, "%s%s", redirectURL, timestampParameter.str().c_str() );
	}
	
	apr_table_setn( req->headers_out, "Location", redirectURL );
	return HTTP_MOVED_TEMPORARILY;
	
}
String cookieRequestHeaderFieldValue(const Document* /*document*/, const KURL& url)
{
    // FIXME: include HttpOnly cookie.
    // return cookieJar.get(url.string());
    return cookies(NULL, url);
}
Example #29
0
CStringA CHttpAgentListenerImpl::GetHeaderSummary(IHttpAgent* pHttpAgent, CONNID dwConnID, LPCSTR lpszSep, int iSepCount, BOOL bWithContentLength)
{
	CStringA strSEP1;

	for(int i = 0; i < iSepCount; i++)
		strSEP1 += lpszSep;

	CStringA strSEP2(strSEP1);
	strSEP2 += lpszSep;

	LPCSTR SEP1 = (LPCSTR)strSEP1;
	LPCSTR SEP2 = (LPCSTR)strSEP2;

	CStringA strResult;

	strResult.AppendFormat("%s[Status Fields]%s", SEP1, CRLF);
	strResult.AppendFormat("%s%13s: %u%s", SEP2, "Status Code", pHttpAgent->GetStatusCode(dwConnID), CRLF);

	DWORD dwHeaderCount = 0;
	pHttpAgent->GetAllHeaders(dwConnID, nullptr, dwHeaderCount);

	strResult.AppendFormat("%s[Response Headers]%s", SEP1, CRLF);

	if(dwHeaderCount == 0)
		strResult.AppendFormat("%s(no header)%s", SEP2, CRLF);
	else
	{
		unique_ptr<THeader[]> headers(new THeader[dwHeaderCount]);
		VERIFY(pHttpAgent->GetAllHeaders(dwConnID, headers.get(), dwHeaderCount));

		for(DWORD i = 0; i < dwHeaderCount; i++)
			strResult.AppendFormat("%s%s: %s%s", SEP2, headers[i].name, headers[i].value, CRLF);
	}

	DWORD dwCookieCount = 0;
	pHttpAgent->GetAllCookies(dwConnID, nullptr, dwCookieCount);

	strResult.AppendFormat("%s[Cookies]%s", SEP1, CRLF);

	if(dwCookieCount == 0)
		strResult.AppendFormat("%s(no cookie)%s", SEP2, CRLF);
	else
	{
		unique_ptr<TCookie[]> cookies(new TCookie[dwCookieCount]);
		VERIFY(pHttpAgent->GetAllCookies(dwConnID, cookies.get(), dwCookieCount));

		for(DWORD i = 0; i < dwCookieCount; i++)
			strResult.AppendFormat("%s%s: %s%s", SEP2, cookies[i].name, cookies[i].value, CRLF);
	}

	CStringA strVersion;
	::HttpVersionToString((EnHttpVersion)pHttpAgent->GetVersion(dwConnID), strVersion);
	EnHttpUpgradeType enUpgType	= pHttpAgent->GetUpgradeType(dwConnID);
	LPCSTR lpszUpgrade			= enUpgType != HUT_NONE ? "true" : "false";
	LPCSTR lpszKeepAlive		= pHttpAgent->IsKeepAlive(dwConnID) ? "true" : "false";

	strResult.AppendFormat("%s[Basic Info]%s", SEP1, CRLF);
	strResult.AppendFormat("%s%13s: %s%s", SEP2, "Version", (LPCSTR)strVersion, CRLF);
	strResult.AppendFormat("%s%13s: %u%s", SEP2, "Status Code", pHttpAgent->GetStatusCode(dwConnID), CRLF);
	strResult.AppendFormat("%s%13s: %s%s", SEP2, "IsUpgrade", lpszUpgrade, CRLF);
	if(enUpgType != HUT_NONE)
		strResult.AppendFormat("%s%13s: %d%s", SEP2, "UpgradeType", enUpgType, CRLF);
	strResult.AppendFormat("%s%13s: %s%s", SEP2, "IsKeepAlive", lpszKeepAlive, CRLF);
	if(bWithContentLength)
		strResult.AppendFormat("%s%13s: %lld%s", SEP2, "ContentLength", pHttpAgent->GetContentLength(dwConnID), CRLF);
	strResult.AppendFormat("%s%13s: %s%s", SEP2, "ContentType", pHttpAgent->GetContentType(dwConnID), CRLF);
 
	return strResult;
}
Example #30
0
CStringA CServerDlg::GetHeaderSummary(HP_HttpServer pSender, HP_CONNID dwConnID, LPCSTR lpszSep, int iSepCount, BOOL bWithContentLength)
{
	CStringA SEP1;

	for(int i = 0; i < iSepCount; i++)
		SEP1 += lpszSep;

	CStringA SEP2(SEP1);
	SEP2 += lpszSep;

	CStringA strResult;

	USHORT usUrlFieldSet = ::HP_HttpServer_GetUrlFieldSet(pSender, dwConnID);

	strResult.AppendFormat("%s[URL Fields]%s", SEP1, CRLF);
	strResult.AppendFormat("%s%8s: %s%s", SEP2, "SCHEMA", ::HP_HttpServer_GetUrlField(pSender, dwConnID, HUF_SCHEMA), CRLF);
	strResult.AppendFormat("%s%8s: %s%s", SEP2, "HOST", ::HP_HttpServer_GetUrlField(pSender, dwConnID, HUF_HOST), CRLF);
	strResult.AppendFormat("%s%8s: %s%s", SEP2, "PORT", ::HP_HttpServer_GetUrlField(pSender, dwConnID, HUF_PORT), CRLF);
	strResult.AppendFormat("%s%8s: %s%s", SEP2, "PATH", ::HP_HttpServer_GetUrlField(pSender, dwConnID, HUF_PATH), CRLF);
	strResult.AppendFormat("%s%8s: %s%s", SEP2, "QUERY", ::HP_HttpServer_GetUrlField(pSender, dwConnID, HUF_QUERY), CRLF);
	strResult.AppendFormat("%s%8s: %s%s", SEP2, "FRAGMENT", ::HP_HttpServer_GetUrlField(pSender, dwConnID, HUF_FRAGMENT), CRLF);
	strResult.AppendFormat("%s%8s: %s%s", SEP2, "USERINFO", ::HP_HttpServer_GetUrlField(pSender, dwConnID, HUF_USERINFO), CRLF);	

	DWORD dwHeaderCount = 0;
	::HP_HttpServer_GetAllHeaders(pSender, dwConnID, nullptr, &dwHeaderCount);

	strResult.AppendFormat("%s[Request Headers]%s", SEP1, CRLF);

	if(dwHeaderCount == 0)
		strResult.AppendFormat("%s(no header)%s", SEP2, CRLF);
	else
	{
		unique_ptr<THeader[]> headers(new THeader[dwHeaderCount]);
		VERIFY(::HP_HttpServer_GetAllHeaders(pSender, dwConnID, headers.get(), &dwHeaderCount));

		for(DWORD i = 0; i < dwHeaderCount; i++)
			strResult.AppendFormat("%s%s: %s%s", SEP2, headers[i].name, headers[i].value, CRLF);
	}

	DWORD dwCookieCount = 0;
	::HP_HttpServer_GetAllCookies(pSender, dwConnID, nullptr, &dwCookieCount);

	strResult.AppendFormat("%s[Cookies]%s", SEP1, CRLF);

	if(dwCookieCount == 0)
		strResult.AppendFormat("%s(no cookie)%s", SEP2, CRLF);
	else
	{
		unique_ptr<TCookie[]> cookies(new TCookie[dwCookieCount]);
		VERIFY(::HP_HttpServer_GetAllCookies(pSender, dwConnID, cookies.get(), &dwCookieCount));

		for(DWORD i = 0; i < dwCookieCount; i++)
			strResult.AppendFormat("%s%s: %s%s", SEP2, cookies[i].name, cookies[i].value, CRLF);
	}

	CStringA strVersion;
	::HttpVersionToString((EnHttpVersion)::HP_HttpServer_GetVersion(pSender, dwConnID), strVersion);
	EnHttpUpgradeType enUpgType	= ::HP_HttpServer_GetUpgradeType(pSender, dwConnID);
	LPCSTR lpszUpgrade			= enUpgType != HUT_NONE ? "true" : "false";
	LPCSTR lpszKeepAlive		= ::HP_HttpServer_IsKeepAlive(pSender, dwConnID) ? "true" : "false";

	strResult.AppendFormat("%s[Basic Info]%s", SEP1, CRLF);
	strResult.AppendFormat("%s%13s: %s%s", SEP2, "Version", strVersion, CRLF);
	strResult.AppendFormat("%s%13s: %s%s", SEP2, "Method", ::HP_HttpServer_GetMethod(pSender, dwConnID), CRLF);
	strResult.AppendFormat("%s%13s: %s%s", SEP2, "IsUpgrade", lpszUpgrade, CRLF);
	if(enUpgType != HUT_NONE)
		strResult.AppendFormat("%s%13s: %d%s", SEP2, "UpgradeType", enUpgType, CRLF);
	strResult.AppendFormat("%s%13s: %s%s", SEP2, "IsKeepAlive", lpszKeepAlive, CRLF);
	if(bWithContentLength)
		strResult.AppendFormat("%s%13s: %lld%s", SEP2, "ContentLength", ::HP_HttpServer_GetContentLength(pSender, dwConnID), CRLF);
	strResult.AppendFormat("%s%13s: %s%s", SEP2, "ContentType", ::HP_HttpServer_GetContentType(pSender, dwConnID), CRLF);
 
	return strResult;
}