Esempio n. 1
0
void BaseSessionStore::destroySession(Poco::Net::HTTPServerRequest& request,
                                      Poco::Net::HTTPServerResponse& response)
{
    // Get the cookies from the client.
    Poco::Net::NameValueCollection cookies;

    // Get the cookies
    request.getCookies(cookies);

    // Try to find a cookie with our session key name.
    Poco::Net::NameValueCollection::ConstIterator cookieIter = cookies.begin();

    while (cookieIter != cookies.end())
    {
        if (0 == cookieIter->first.compare(_sessionKeyName))
        {
            // Destroy the session data.
            destroySession(cookieIter->second);

            // Invalidate the cookies.
            Poco::Net::HTTPCookie cookie(_sessionKeyName, cookieIter->second);

            cookie.setMaxAge(0);
            response.addCookie(cookie);
        }

        ++cookieIter;
    }
}
Esempio n. 2
0
AbstractSession& BaseSessionStore::getSession(Poco::Net::HTTPServerRequest& request,
                                              Poco::Net::HTTPServerResponse& response)
{
    // Get the cookies from the client.
    Poco::Net::NameValueCollection cookies;

    // Get the cookies
    request.getCookies(cookies);

    // Try to find a cookie with our session key name.
    Poco::Net::NameValueCollection::ConstIterator cookieIter = cookies.begin();

    std::string sessionId;

    while (cookieIter != cookies.end())
    {
        if (0 == cookieIter->first.compare(_sessionKeyName))
        {
            if (sessionId.empty())
            {
                sessionId = cookieIter->second;
            }
            else
            {
                Poco::Net::HTTPCookie cookie(_sessionKeyName);
                cookie.setMaxAge(0); // Invalidate the cookie.
                response.addCookie(cookie);
            }
        }

        ++cookieIter;
    }

    if (hasSession(sessionId))
    {
        return getSession(sessionId);
    }
    else
    {
        // Create a new sesssion and return a reference.
        AbstractSession& session = createSession();

        // Create a cookie with the session id.
        Poco::Net::HTTPCookie cookie(_sessionKeyName, session.getId());

        // Send our cookie with the response.
        response.addCookie(cookie);

        return session;
    }
}
Esempio n. 3
0
std::string HTTPUtils::makeQueryString(const Poco::Net::NameValueCollection& query)
{
    std::stringstream ostr;

    Poco::Net::NameValueCollection::ConstIterator it = query.begin();

    while (it != query.end())
    {
        if (it != query.begin())
            ostr << "&";

        std::string name;
        Poco::URI::encode(it->first, "=&+;", name);
        std::string value;
        Poco::URI::encode(it->second, "=&+;", value);
        ostr << name << "=" << value;
        ++it;
    }

    return ostr.str();
}