Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Unified Diff: remoting/host/gnubby_socket.h

Issue 205493005: Do minimal processing of gnubby data. Add request timeouts and send error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/gnubby_auth_handler_posix_unittest.cc ('k') | remoting/host/gnubby_socket.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/gnubby_socket.h
diff --git a/remoting/host/gnubby_socket.h b/remoting/host/gnubby_socket.h
new file mode 100644
index 0000000000000000000000000000000000000000..d1197629b80fdcd38c080ed123642070fdc7c2e5
--- /dev/null
+++ b/remoting/host/gnubby_socket.h
@@ -0,0 +1,80 @@
+// 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.
+
+#ifndef REMOTING_HOST_GNUBBY_SOCKET_H_
+#define REMOTING_HOST_GNUBBY_SOCKET_H_
+
+#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 {
+ public:
+ GnubbySocket(scoped_ptr<net::StreamListenSocket> socket,
+ const base::Closure& timeout_callback);
+ ~GnubbySocket();
+
+ // 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);
+
+ private:
+ // 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_;
+
+ DISALLOW_COPY_AND_ASSIGN(GnubbySocket);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_GNUBBY_SOCKET_H_
« no previous file with comments | « remoting/host/gnubby_auth_handler_posix_unittest.cc ('k') | remoting/host/gnubby_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698