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