File: session.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (112 lines) | stat: -rw-r--r-- 3,534 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_PROTOCOL_SESSION_H_
#define REMOTING_PROTOCOL_SESSION_H_

#include <memory>
#include <string>
#include <string_view>

#include "remoting/base/source_location.h"
#include "remoting/protocol/errors.h"
#include "remoting/protocol/session_config.h"
#include "remoting/protocol/transport.h"

namespace remoting::protocol {

class Authenticator;
class SessionPlugin;
class Transport;

// Session is responsible for initializing and authenticating both incoming and
// outgoing connections. It uses TransportInfoSink interface to pass
// transport-info messages to the transport.
class Session {
 public:
  enum State {
    // Created, but not connecting yet.
    INITIALIZING,

    // Sent session-initiate, but haven't received session-accept.
    CONNECTING,

    // Received session-initiate, but haven't sent session-accept.
    ACCEPTING,

    // Session has been accepted and is pending authentication.
    ACCEPTED,

    // Session has started authenticating.
    AUTHENTICATING,

    // Session has been connected and authenticated.
    AUTHENTICATED,

    // Session has been closed.
    CLOSED,

    // Connection has failed.
    FAILED,
  };

  class EventHandler {
   public:
    EventHandler() = default;
    virtual ~EventHandler() = default;

    // Called after session state has changed. It is safe to destroy
    // the session from within the handler if |state| is AUTHENTICATING
    // or CLOSED or FAILED.
    virtual void OnSessionStateChange(State state) = 0;
  };

  Session() = default;

  Session(const Session&) = delete;
  Session& operator=(const Session&) = delete;

  virtual ~Session() = default;

  // Set event handler for this session. |event_handler| must outlive
  // this object.
  virtual void SetEventHandler(EventHandler* event_handler) = 0;

  // Returns error code for a failed session.
  virtual ErrorCode error() const = 0;

  // JID of the other side.
  virtual const std::string& jid() = 0;

  // Protocol configuration. Can be called only after session has been accepted.
  // Returned pointer is valid until connection is closed.
  virtual const SessionConfig& config() = 0;

  virtual const Authenticator& authenticator() const = 0;

  // Sets Transport to be used by the session. Must be called before the
  // session becomes AUTHENTICATED. The transport must outlive the session.
  virtual void SetTransport(Transport* transport) = 0;

  // Closes connection. EventHandler is guaranteed not to be called after this
  // method returns.
  // |error| specifies the error code in case when the session is being closed
  //   due to an error.
  // |error_details| is a free-form human-readable string that describes the
  //   reason for closing the connection.
  // |error_location| denotes where the error occurs in the code.
  virtual void Close(ErrorCode error,
                     std::string_view error_details,
                     const SourceLocation& error_location) = 0;

  // Adds a SessionPlugin to handle attachments. To ensure plugin attachments
  // are processed correctly for session-initiate message, this function must be
  // called immediately after SessionManager::Connect() for outgoing connections
  // or in the IncomingSessionCallback handler for incoming connections.
  virtual void AddPlugin(SessionPlugin* plugin) = 0;
};

}  // namespace remoting::protocol

#endif  // REMOTING_PROTOCOL_SESSION_H_