Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
RASocket.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
9
10#ifndef _RASOCKET_H
11#define _RASOCKET_H
12
13#include "Common.h"
15
16#include <boost/asio/ip/tcp.hpp>
17#include <boost/asio/steady_timer.hpp>
18#include <boost/asio/streambuf.hpp>
19#include <array>
20#include <atomic>
21#include <deque>
22#include <functional>
23#include <memory>
24#include <mutex>
25#include <queue>
26#include <string>
27
28typedef boost::asio::ip::tcp::socket RASocketHandle;
29
31class RASocket : public std::enable_shared_from_this<RASocket>
32{
33public:
34 RASocket(std::shared_ptr<Skyfire::Asio::IoContextExecutor> executor, std::unique_ptr<RASocketHandle> socket, std::string const& remoteAddress);
35 virtual ~RASocket();
36
37 void start();
38
39private:
40 typedef std::function<void(bool)> WriteCallback;
41 typedef std::function<void(bool, std::string)> ReadLineCallback;
42
44 {
45 std::string Data;
47 };
48
49 void close();
50 bool is_open() const;
52 void handle_subnegotiation_read(boost::system::error_code const& error, size_t transferredBytes);
55 void prompt_username();
56 void prompt_password();
57 void handle_credentials();
58 void prompt_command();
59 void handle_command(std::string const& command);
60 void start_command(std::string const& command);
61 void queue_write(std::string data, WriteCallback callback = WriteCallback());
62 void start_async_write();
63 void handle_async_write(boost::system::error_code const& error);
64 void async_read_line(ReadLineCallback callback);
65 void handle_read_line(boost::system::error_code const& error, size_t transferredBytes, ReadLineCallback callback);
67 int check_access_level(const std::string& user);
68 int check_password(const std::string& user, const std::string& pass);
69
70 static void zprint(void* callbackArg, const char* szText);
71 static void commandFinished(void* callbackArg, bool success);
72
73private:
74 std::shared_ptr<Skyfire::Asio::IoContextExecutor> _executor;
75 std::unique_ptr<RASocketHandle> _socket;
76 boost::asio::steady_timer _subnegotiationTimer;
77 std::string _remoteAddress;
78 std::array<char, 1024> _subnegotiationBuffer;
79 boost::asio::streambuf _lineBuffer;
80 std::deque<PendingWrite> _writeQueue;
82 std::atomic<bool> _closed;
85 std::string _user;
86 std::string _pass;
88 std::atomic<bool> _commandExecuting;
89 std::mutex _commandLock;
90 std::queue<std::string> _commandOutput;
93 std::shared_ptr<RASocket> _commandSelf;
94};
95
96#endif
97
std::uint8_t uint8
Definition Define.h:79
void prompt_command()
Definition RASocket.cpp:295
void handle_async_write(boost::system::error_code const &error)
Definition RASocket.cpp:390
bool _commandOutputDrainInProgress
Definition RASocket.h:92
std::unique_ptr< RASocketHandle > _socket
Definition RASocket.h:75
void queue_write(std::string data, WriteCallback callback=WriteCallback())
Definition RASocket.cpp:359
boost::asio::streambuf _lineBuffer
Definition RASocket.h:79
void send_authentication_required()
Definition RASocket.cpp:207
std::function< void(bool, std::string)> ReadLineCallback
Definition RASocket.h:41
void async_read_line(ReadLineCallback callback)
Definition RASocket.cpp:418
std::string _remoteAddress
Definition RASocket.h:77
void start_command(std::string const &command)
Definition RASocket.cpp:342
void finish_subnegotiation()
Definition RASocket.cpp:202
void start()
Definition RASocket.cpp:59
std::shared_ptr< Skyfire::Asio::IoContextExecutor > _executor
Definition RASocket.h:74
uint8 _minLevel
Minimum security level required to connect.
Definition RASocket.h:87
RASocket(std::shared_ptr< Skyfire::Asio::IoContextExecutor > executor, std::unique_ptr< RASocketHandle > socket, std::string const &remoteAddress)
Definition RASocket.cpp:30
std::function< void(bool)> WriteCallback
Definition RASocket.h:40
void handle_subnegotiation_read(boost::system::error_code const &error, size_t transferredBytes)
Definition RASocket.cpp:119
boost::asio::steady_timer _subnegotiationTimer
Definition RASocket.h:76
int check_password(const std::string &user, const std::string &pass)
Definition RASocket.cpp:540
virtual ~RASocket()
Definition RASocket.cpp:54
std::string _pass
Definition RASocket.h:86
bool _subnegotiationTimedOut
Definition RASocket.h:84
void drain_command_output()
Definition RASocket.cpp:453
void start_async_write()
Definition RASocket.cpp:375
std::shared_ptr< RASocket > _commandSelf
Definition RASocket.h:93
void prompt_password()
Definition RASocket.cpp:244
std::string _user
Definition RASocket.h:85
void close()
Definition RASocket.cpp:68
std::atomic< bool > _commandExecuting
Definition RASocket.h:88
void prompt_username()
Definition RASocket.cpp:219
static void zprint(void *callbackArg, const char *szText)
Definition RASocket.cpp:564
bool _subnegotiationDone
Definition RASocket.h:83
int check_access_level(const std::string &user)
Definition RASocket.cpp:508
void handle_command(std::string const &command)
Definition RASocket.cpp:319
static void commandFinished(void *callbackArg, bool success)
Definition RASocket.cpp:589
std::mutex _commandLock
Definition RASocket.h:89
std::array< char, 1024 > _subnegotiationBuffer
Definition RASocket.h:78
void handle_credentials()
Definition RASocket.cpp:269
bool _writeInProgress
Definition RASocket.h:81
void start_subnegotiation()
Used by telnet protocol RFC 854 / 855.
Definition RASocket.cpp:86
bool is_open() const
Definition RASocket.cpp:81
bool _commandComplete
Definition RASocket.h:91
void handle_read_line(boost::system::error_code const &error, size_t transferredBytes, ReadLineCallback callback)
Definition RASocket.cpp:434
std::queue< std::string > _commandOutput
Definition RASocket.h:90
std::atomic< bool > _closed
Definition RASocket.h:82
std::deque< PendingWrite > _writeQueue
Definition RASocket.h:80
boost::asio::ip::tcp::socket RASocketHandle
Definition RASocket.h:28
WriteCallback Callback
Definition RASocket.h:46