ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libptytty/src/libptytty.h
Revision: 1.19
Committed: Sun Jun 27 15:30:07 2021 UTC (2 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.18: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #ifndef LIBPTYTTY_H_ /* public libptytty header file */
2 #define LIBPTYTTY_H_
3
4 #ifdef __cplusplus
5
6 // C++ API
7
8 #include <stdlib.h>
9 #include <string.h>
10 #include <exception>
11
12 class ptytty_error : public std::exception
13 {
14 private:
15 char *msg;
16
17 public:
18 ptytty_error (const char *what_arg)
19 {
20 msg = strdup (what_arg);
21 }
22
23 ~ptytty_error ()
24 {
25 free (msg);
26 }
27
28 const char *
29 what () const noexcept override
30 {
31 return msg;
32 }
33 };
34
35 struct ptytty
36 {
37 int pty; // pty file descriptor; connected to terminal emulator
38 int tty; // tty file descriptor; connected to child
39
40 virtual ~ptytty ()
41 {
42 }
43
44 virtual bool get () = 0;
45 virtual void login (int cmd_pid, bool login_shell, const char *hostname) = 0;
46
47 void close_tty ();
48 bool make_controlling_tty ();
49 void set_utf8_mode (bool on);
50
51 static void sanitise_stdfd ();
52 static void init ();
53 static ptytty *create (); // create a new pty object
54
55 static void drop_privileges ();
56 static void use_helper ();
57
58 static bool send_fd (int socket, int fd);
59 static int recv_fd (int socket);
60
61 protected:
62
63 ptytty ()
64 : pty(-1), tty(-1)
65 {
66 }
67 };
68
69 #else
70
71 // C API
72
73 typedef void *PTYTTY;
74
75 int ptytty_pty (PTYTTY ptytty);
76 int ptytty_tty (PTYTTY ptytty);
77 void ptytty_delete (PTYTTY ptytty);
78 int ptytty_get (PTYTTY ptytty);
79 void ptytty_login (PTYTTY ptytty, int cmd_pid, int login_shell, const char *hostname);
80
81 void ptytty_close_tty (PTYTTY ptytty);
82 int ptytty_make_controlling_tty (PTYTTY ptytty);
83 void ptytty_set_utf8_mode (PTYTTY ptytty, int on);
84
85 void ptytty_sanitise_stdfd ();
86 void ptytty_init ();
87 PTYTTY ptytty_create ();
88
89 void ptytty_drop_privileges ();
90 void ptytty_use_helper ();
91
92 #endif
93
94 #endif
95