Пример #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;
    }
}
Пример #2
0
void Susi::WebSocketRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request,
                       							Poco::Net::HTTPServerResponse& response) {
	Poco::Net::WebSocket socket(request,response);
	Poco::Net::NameValueCollection cookies;
	request.getCookies(cookies);
	std::string id = cookies["susisession"];
    Susi::Logger::debug("register sender in ws");
    apiServer->registerSender(id,[&socket](Susi::Util::Any & arg){
    	std::string msg = arg.toString();
    	Susi::Logger::debug("send frame to websocket");
    	socket.sendFrame(msg.data(), msg.length(), Poco::Net::WebSocket::FRAME_TEXT);        
    });
    
    apiServer->onConnect(id);

    char buffer[4096];
	int flags;
	size_t n;

	while (true) {
		n = socket.receiveFrame(buffer, sizeof(buffer), flags);
    	Susi::Logger::debug("got frame");
    	Susi::Logger::debug(std::to_string(n));
		if(n==0 || (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) == Poco::Net::WebSocket::FRAME_OP_CLOSE){
			break;
		}
		std::string str(buffer, n);
		Susi::Util::Any packet = Susi::Util::Any::fromString(str);
		apiServer->onMessage(id,packet);   			
	}
	Susi::Logger::debug("closing websocket");
	apiServer->onClose(id);
}
Пример #3
0
std::string WebSessionManager::getId(const std::string& appName, const Poco::Net::HTTPServerRequest& request)
{
	std::string id;
	std::string name(cookieName(appName));
	NameValueCollection cookies;
	request.getCookies(cookies);
	NameValueCollection::ConstIterator it = cookies.find(name);
	if (it != cookies.end())
		id = it->second;
	
	return id;
}