| 1 | /* |
|---|
| 2 | * This file is part of Partty |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki |
|---|
| 5 | * |
|---|
| 6 | * This program is free software: you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation, either version 3 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #include "partty.h" |
|---|
| 21 | #include "emtelnet.h" |
|---|
| 22 | #include <string> |
|---|
| 23 | |
|---|
| 24 | namespace Partty { |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | class phrase_telnetd : public emtelnet { |
|---|
| 28 | private: |
|---|
| 29 | static void pass_through_handler(char cmd, bool sw, emtelnet& base) {} |
|---|
| 30 | public: |
|---|
| 31 | phrase_telnetd(); |
|---|
| 32 | private: |
|---|
| 33 | phrase_telnetd(const phrase_telnetd&); |
|---|
| 34 | }; |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | class GateIMPL { |
|---|
| 38 | public: |
|---|
| 39 | GateIMPL(Gate::config_t& config); |
|---|
| 40 | ~GateIMPL(); |
|---|
| 41 | int run(void); |
|---|
| 42 | void signal_end(void); |
|---|
| 43 | private: |
|---|
| 44 | int accept_guest(void); |
|---|
| 45 | static ssize_t write_message(phrase_telnetd& td, int guest, const char* buf, size_t count); |
|---|
| 46 | static ssize_t read_line(phrase_telnetd& td, int guest, char* buf, size_t count); |
|---|
| 47 | private: |
|---|
| 48 | int socket; |
|---|
| 49 | char gate_path[PATH_MAX + MAX_SESSION_NAME_LENGTH]; |
|---|
| 50 | size_t gate_dir_len; |
|---|
| 51 | std::string m_session_banner; |
|---|
| 52 | std::string m_password_banner; |
|---|
| 53 | pid_t m_parent_pid; |
|---|
| 54 | sig_atomic_t m_end; |
|---|
| 55 | private: |
|---|
| 56 | GateIMPL(); |
|---|
| 57 | GateIMPL(const GateIMPL&); |
|---|
| 58 | private: |
|---|
| 59 | static const int E_SUCCESS = 0; |
|---|
| 60 | static const int E_ACCEPT = 1; |
|---|
| 61 | static const int E_FINISH = 2; |
|---|
| 62 | static const int E_SESSION_NAME = 3; |
|---|
| 63 | static const int E_PASSWORD = 4; |
|---|
| 64 | static const int E_SENDFD = 5; |
|---|
| 65 | }; |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | } // namespace Partty |
|---|
| 69 | |
|---|