[30d4706] | 1 | /*
|
---|
[d3109ff] | 2 | * Copyright (c) 2024 Jiri Svoboda
|
---|
[30d4706] | 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>
|
---|
[fab2746] | 40 | #include <inet/tcp.h>
|
---|
[30d4706] | 41 | #include <inttypes.h>
|
---|
[5d94b16c] | 42 | #include <io/con_srv.h>
|
---|
[30d4706] | 43 |
|
---|
[99c2e9f3] | 44 | #define BUFFER_SIZE 32
|
---|
[c23a1fe] | 45 | #define SEND_BUF_SIZE 512
|
---|
[30d4706] | 46 |
|
---|
[47d060d] | 47 | /** Telnet callbacks */
|
---|
| 48 | typedef struct {
|
---|
| 49 | void (*ws_update)(void *, unsigned, unsigned);
|
---|
| 50 | } telnet_cb_t;
|
---|
| 51 |
|
---|
[5923cf82] | 52 | /** Representation of a connected (human) user. */
|
---|
[30d4706] | 53 | typedef struct {
|
---|
[5f5d375] | 54 | /** Synchronize send operations */
|
---|
| 55 | fibril_mutex_t send_lock;
|
---|
| 56 | /** Synchronize receive operations */
|
---|
| 57 | fibril_mutex_t recv_lock;
|
---|
[47d060d] | 58 | /** Callback functions */
|
---|
| 59 | telnet_cb_t *cb;
|
---|
| 60 | /** Argument to callback functions */
|
---|
| 61 | void *arg;
|
---|
[261bbdc] | 62 |
|
---|
[5923cf82] | 63 | /** Internal id, used for creating locfs entries. */
|
---|
[30d4706] | 64 | int id;
|
---|
[fab2746] | 65 | /** Associated connection. */
|
---|
| 66 | tcp_conn_t *conn;
|
---|
[5923cf82] | 67 | /** Location service id assigned to the virtual terminal. */
|
---|
[30d4706] | 68 | service_id_t service_id;
|
---|
[5923cf82] | 69 | /** Path name of the service. */
|
---|
[30d4706] | 70 | char *service_name;
|
---|
[5d94b16c] | 71 | /** Console service setup */
|
---|
| 72 | con_srvs_t srvs;
|
---|
[5923cf82] | 73 |
|
---|
[30d4706] | 74 | link_t link;
|
---|
| 75 | char socket_buffer[BUFFER_SIZE];
|
---|
| 76 | size_t socket_buffer_len;
|
---|
| 77 | size_t socket_buffer_pos;
|
---|
[c23a1fe] | 78 | char send_buf[SEND_BUF_SIZE];
|
---|
| 79 | size_t send_buf_used;
|
---|
[30d4706] | 80 |
|
---|
[5923cf82] | 81 | /** Task id of the launched application. */
|
---|
[30d4706] | 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;
|
---|
[178d6a3] | 89 |
|
---|
| 90 | /** X position of the cursor. */
|
---|
| 91 | int cursor_x;
|
---|
[d3109ff] | 92 | /** Y position of the cursor. */
|
---|
| 93 | int cursor_y;
|
---|
[c23a1fe] | 94 | /** Total number of columns */
|
---|
| 95 | unsigned cols;
|
---|
[d3109ff] | 96 | /** Total number of rows */
|
---|
[c23a1fe] | 97 | unsigned rows;
|
---|
[30d4706] | 98 | } telnet_user_t;
|
---|
| 99 |
|
---|
[47d060d] | 100 | extern telnet_user_t *telnet_user_create(tcp_conn_t *, telnet_cb_t *, void *);
|
---|
[5d94b16c] | 101 | extern void telnet_user_add(telnet_user_t *);
|
---|
[3123d2a] | 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 *);
|
---|
[b7fd2a0] | 106 | extern errno_t telnet_user_get_next_keyboard_event(telnet_user_t *, kbd_event_t *);
|
---|
[d3109ff] | 107 | extern errno_t telnet_user_send_data(telnet_user_t *, const char *, size_t);
|
---|
[89e5c0c7] | 108 | extern errno_t telnet_user_send_raw(telnet_user_t *, const char *, size_t);
|
---|
[c23a1fe] | 109 | extern errno_t telnet_user_flush(telnet_user_t *);
|
---|
[d3109ff] | 110 | extern errno_t telnet_user_recv(telnet_user_t *, void *, size_t, size_t *);
|
---|
[3123d2a] | 111 | extern void telnet_user_update_cursor_x(telnet_user_t *, int);
|
---|
[47d060d] | 112 | extern void telnet_user_resize(telnet_user_t *, unsigned, unsigned);
|
---|
[30d4706] | 113 |
|
---|
[5923cf82] | 114 | /** Print informational message about connected user. */
|
---|
[bd79281] | 115 | #ifdef CONFIG_DEBUG
|
---|
[d545d03] | 116 | #define telnet_user_log(user, fmt, ...) \
|
---|
[3123d2a] | 117 | printf(NAME " [console %d (%d)]: " fmt "\n", \
|
---|
| 118 | user->id, (int) user->service_id, ##__VA_ARGS__)
|
---|
[bd79281] | 119 | #else
|
---|
[3123d2a] | 120 | #define telnet_user_log(user, fmt, ...) ((void) 0)
|
---|
[bd79281] | 121 | #endif
|
---|
[d545d03] | 122 |
|
---|
[5923cf82] | 123 | /** Print error message associated with connected user. */
|
---|
[d545d03] | 124 | #define telnet_user_error(user, fmt, ...) \
|
---|
[3123d2a] | 125 | fprintf(stderr, NAME " [console %d (%d)]: ERROR: " fmt "\n", \
|
---|
| 126 | user->id, (int) user->service_id, ##__VA_ARGS__)
|
---|
[d545d03] | 127 |
|
---|
[30d4706] | 128 | #endif
|
---|
| 129 |
|
---|
| 130 | /**
|
---|
| 131 | * @}
|
---|
| 132 | */
|
---|