1 | /*
|
---|
2 | * Copyright (c) 2024 Jiri Svoboda
|
---|
3 | * Copyright (c) 2012 Vojtech Horky
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /** @addtogroup remcons
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /** @file
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef TELNET_USER_H_
|
---|
37 | #define TELNET_USER_H_
|
---|
38 |
|
---|
39 | #include <fibril_synch.h>
|
---|
40 | #include <inet/tcp.h>
|
---|
41 | #include <inttypes.h>
|
---|
42 | #include <io/con_srv.h>
|
---|
43 |
|
---|
44 | #define BUFFER_SIZE 32
|
---|
45 | #define SEND_BUF_SIZE 512
|
---|
46 |
|
---|
47 | /** Telnet callbacks */
|
---|
48 | typedef struct {
|
---|
49 | void (*ws_update)(void *, unsigned, unsigned);
|
---|
50 | } telnet_cb_t;
|
---|
51 |
|
---|
52 | /** Representation of a connected (human) user. */
|
---|
53 | typedef struct {
|
---|
54 | /** Synchronize send operations */
|
---|
55 | fibril_mutex_t send_lock;
|
---|
56 | /** Synchronize receive operations */
|
---|
57 | fibril_mutex_t recv_lock;
|
---|
58 | /** Callback functions */
|
---|
59 | telnet_cb_t *cb;
|
---|
60 | /** Argument to callback functions */
|
---|
61 | void *arg;
|
---|
62 |
|
---|
63 | /** Internal id, used for creating locfs entries. */
|
---|
64 | int id;
|
---|
65 | /** Associated connection. */
|
---|
66 | tcp_conn_t *conn;
|
---|
67 | /** Location service id assigned to the virtual terminal. */
|
---|
68 | service_id_t service_id;
|
---|
69 | /** Path name of the service. */
|
---|
70 | char *service_name;
|
---|
71 | /** Console service setup */
|
---|
72 | con_srvs_t srvs;
|
---|
73 |
|
---|
74 | link_t link;
|
---|
75 | char socket_buffer[BUFFER_SIZE];
|
---|
76 | size_t socket_buffer_len;
|
---|
77 | size_t socket_buffer_pos;
|
---|
78 | char send_buf[SEND_BUF_SIZE];
|
---|
79 | size_t send_buf_used;
|
---|
80 |
|
---|
81 | /** Task id of the launched application. */
|
---|
82 | task_id_t task_id;
|
---|
83 |
|
---|
84 | /* Reference counting. */
|
---|
85 | fibril_condvar_t refcount_cv;
|
---|
86 | bool task_finished;
|
---|
87 | int locsrv_connection_count;
|
---|
88 | bool socket_closed;
|
---|
89 |
|
---|
90 | /** X position of the cursor. */
|
---|
91 | int cursor_x;
|
---|
92 | /** Y position of the cursor. */
|
---|
93 | int cursor_y;
|
---|
94 | /** Total number of columns */
|
---|
95 | unsigned cols;
|
---|
96 | /** Total number of rows */
|
---|
97 | unsigned rows;
|
---|
98 | } telnet_user_t;
|
---|
99 |
|
---|
100 | extern telnet_user_t *telnet_user_create(tcp_conn_t *, telnet_cb_t *, void *);
|
---|
101 | extern void telnet_user_add(telnet_user_t *);
|
---|
102 | extern void telnet_user_destroy(telnet_user_t *);
|
---|
103 | extern telnet_user_t *telnet_user_get_for_client_connection(service_id_t);
|
---|
104 | extern bool telnet_user_is_zombie(telnet_user_t *);
|
---|
105 | extern void telnet_user_notify_client_disconnected(telnet_user_t *);
|
---|
106 | extern errno_t telnet_user_get_next_keyboard_event(telnet_user_t *, kbd_event_t *);
|
---|
107 | extern errno_t telnet_user_send_data(telnet_user_t *, const char *, size_t);
|
---|
108 | extern errno_t telnet_user_send_raw(telnet_user_t *, const char *, size_t);
|
---|
109 | extern errno_t telnet_user_flush(telnet_user_t *);
|
---|
110 | extern errno_t telnet_user_recv(telnet_user_t *, void *, size_t, size_t *);
|
---|
111 | extern void telnet_user_update_cursor_x(telnet_user_t *, int);
|
---|
112 | extern void telnet_user_resize(telnet_user_t *, unsigned, unsigned);
|
---|
113 |
|
---|
114 | /** Print informational message about connected user. */
|
---|
115 | #ifdef CONFIG_DEBUG
|
---|
116 | #define telnet_user_log(user, fmt, ...) \
|
---|
117 | printf(NAME " [console %d (%d)]: " fmt "\n", \
|
---|
118 | user->id, (int) user->service_id, ##__VA_ARGS__)
|
---|
119 | #else
|
---|
120 | #define telnet_user_log(user, fmt, ...) ((void) 0)
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | /** Print error message associated with connected user. */
|
---|
124 | #define telnet_user_error(user, fmt, ...) \
|
---|
125 | fprintf(stderr, NAME " [console %d (%d)]: ERROR: " fmt "\n", \
|
---|
126 | user->id, (int) user->service_id, ##__VA_ARGS__)
|
---|
127 |
|
---|
128 | #endif
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * @}
|
---|
132 | */
|
---|