blob: d1197629b80fdcd38c080ed123642070fdc7c2e5 [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/non_thread_safe.h"
namespace base {
class Timer;
} // namespace base
namespace net {
class StreamListenSocket;
} // namespace net
namespace remoting {
// Class that manages a socket used for gnubby requests.
class GnubbySocket : public base::NonThreadSafe {
GnubbySocket(scoped_ptr<net::StreamListenSocket> socket,
const base::Closure& timeout_callback);
// Adds data to the current request.
void AddRequestData(const char* data, int data_len);
// Gets the current request data and clears it.
void GetAndClearRequestData(std::string* data_out);
// Returns true if the current request is complete.
bool IsRequestComplete() const;
// Returns true if the stated request size is larger than the allowed maximum.
bool IsRequestTooLarge() const;
// Sends response data to the socket.
void SendResponse(const std::string& data);
// Sends an SSH error code to the socket.
void SendSshError();
// Returns true if |socket| is the same one owned by this object.
bool IsSocket(net::StreamListenSocket* socket) const;
// Sets a timer for testing.
void SetTimerForTesting(scoped_ptr<base::Timer> timer);
// Returns the stated request length.
size_t GetRequestLength() const;
// Returns the response length bytes.
std::string GetResponseLengthAsBytes(const std::string& response) const;
// Resets the socket activity timer.
void ResetTimer();
// The socket.
scoped_ptr<net::StreamListenSocket> socket_;
// Request data.
std::vector<char> request_data_;
// The activity timer.
scoped_ptr<base::Timer> timer_;
} // namespace remoting