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 <adt/prodcons.h>
|
---|
40 | #include <fibril_synch.h>
|
---|
41 | #include <inet/tcp.h>
|
---|
42 | #include <inttypes.h>
|
---|
43 | #include <io/con_srv.h>
|
---|
44 |
|
---|
45 | #define BUFFER_SIZE 32
|
---|
46 | #define SEND_BUF_SIZE 512
|
---|
47 |
|
---|
48 | /** Representation of a connected (human) user. */
|
---|
49 | typedef struct {
|
---|
50 | /** Mutex guarding the whole structure. */
|
---|
51 | fibril_mutex_t guard;
|
---|
52 |
|
---|
53 | /** Internal id, used for creating locfs entries. */
|
---|
54 | int id;
|
---|
55 | /** Associated connection. */
|
---|
56 | tcp_conn_t *conn;
|
---|
57 | /** Location service id assigned to the virtual terminal. */
|
---|
58 | service_id_t service_id;
|
---|
59 | /** Path name of the service. */
|
---|
60 | char *service_name;
|
---|
61 | /** Console service setup */
|
---|
62 | con_srvs_t srvs;
|
---|
63 |
|
---|
64 | /** Producer-consumer of kbd_event_t. */
|
---|
65 | prodcons_t in_events;
|
---|
66 | link_t link;
|
---|
67 | char socket_buffer[BUFFER_SIZE];
|
---|
68 | size_t socket_buffer_len;
|
---|
69 | size_t socket_buffer_pos;
|
---|
70 | char send_buf[SEND_BUF_SIZE];
|
---|
71 | size_t send_buf_used;
|
---|
72 |
|
---|
73 | /** Task id of the launched application. */
|
---|
74 | task_id_t task_id;
|
---|
75 |
|
---|
76 | /* Reference counting. */
|
---|
77 | fibril_condvar_t refcount_cv;
|
---|
78 | bool task_finished;
|
---|
79 | int locsrv_connection_count;
|
---|
80 | bool socket_closed;
|
---|
81 |
|
---|
82 | /** X position of the cursor. */
|
---|
83 | int cursor_x;
|
---|
84 | /** Y position of the cursor. */
|
---|
85 | int cursor_y;
|
---|
86 | /** Total number of columns */
|
---|
87 | unsigned cols;
|
---|
88 | /** Total number of rows */
|
---|
89 | unsigned rows;
|
---|
90 | } telnet_user_t;
|
---|
91 |
|
---|
92 | extern telnet_user_t *telnet_user_create(tcp_conn_t *);
|
---|
93 | extern void telnet_user_add(telnet_user_t *);
|
---|
94 | extern void telnet_user_destroy(telnet_user_t *);
|
---|
95 | extern telnet_user_t *telnet_user_get_for_client_connection(service_id_t);
|
---|
96 | extern bool telnet_user_is_zombie(telnet_user_t *);
|
---|
97 | extern void telnet_user_notify_client_disconnected(telnet_user_t *);
|
---|
98 | extern errno_t telnet_user_get_next_keyboard_event(telnet_user_t *, kbd_event_t *);
|
---|
99 | extern errno_t telnet_user_send_data(telnet_user_t *, const char *, size_t);
|
---|
100 | extern errno_t telnet_user_flush(telnet_user_t *);
|
---|
101 | extern errno_t telnet_user_recv(telnet_user_t *, void *, size_t, size_t *);
|
---|
102 | extern void telnet_user_update_cursor_x(telnet_user_t *, int);
|
---|
103 |
|
---|
104 | /** Print informational message about connected user. */
|
---|
105 | #ifdef CONFIG_DEBUG
|
---|
106 | #define telnet_user_log(user, fmt, ...) \
|
---|
107 | printf(NAME " [console %d (%d)]: " fmt "\n", \
|
---|
108 | user->id, (int) user->service_id, ##__VA_ARGS__)
|
---|
109 | #else
|
---|
110 | #define telnet_user_log(user, fmt, ...) ((void) 0)
|
---|
111 | #endif
|
---|
112 |
|
---|
113 | /** Print error message associated with connected user. */
|
---|
114 | #define telnet_user_error(user, fmt, ...) \
|
---|
115 | fprintf(stderr, NAME " [console %d (%d)]: ERROR: " fmt "\n", \
|
---|
116 | user->id, (int) user->service_id, ##__VA_ARGS__)
|
---|
117 |
|
---|
118 | #endif
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * @}
|
---|
122 | */
|
---|