TNT/include/input.h
m1ngsama 3b8a1d18d8 refactor: extract input module (PR2-M5)
Move the interactive session — username read, vim-style key dispatcher,
main poll/redraw/keepalive/idle-timeout loop, the @mention bell, and
the tear-down path — out of ssh_server.c into a dedicated module.

New API (include/input.h):
- input_init()                 -- read TNT_IDLE_TIMEOUT once at startup
- input_run_session(client_t*) -- run the interactive session for an
                                  already-bootstrapped client_t,
                                  including exec_dispatch() short-circuit
                                  when client->exec_command is set
- notify_mentions(content, sender) -- moved from ssh_server.h since
                                  the INSERT-mode send path lives here
                                  too

Renamed: client_handle_session(void *arg) -> input_run_session(client_t *).
The old void* signature was a fossil from when this was a pthread entry;
bootstrap.c calls it synchronously inside its own detached thread.
bootstrap_run() now ends with `input_run_session(client); return NULL;`.

g_idle_timeout is now private to input.c; ssh_server_init() calls
input_init() instead of reading the env directly.

ssh_server.c shrinks from 1026 to 402 lines (-624) -- now down to just
the accept loop, ssh_server_init / ssh_server_start, host-key setup,
client_t I/O API (send/printf/addref/release), and the post-bootstrap
client_channel_* callbacks.  M6 will give those a proper home.

Behaviour is preserved: all moved code is byte-for-byte identical.
2026-05-17 10:01:48 +08:00

31 lines
1.2 KiB
C

#ifndef INPUT_H
#define INPUT_H
#include "ssh_server.h" /* for client_t */
/* Read TNT_IDLE_TIMEOUT from the environment. Idempotent. Call once at
* startup before any session can run. */
void input_init(void);
/* Run the interactive session for an already-bootstrapped client_t.
*
* Sequence:
* 1. If client->exec_command is set, dispatch it via exec_dispatch and
* return (no chat-room join).
* 2. Read the desired username from the channel.
* 3. Add the client to g_room and broadcast a system join message.
* 4. Optionally show the MOTD if state-dir/motd.txt exists.
* 5. Drive the keyboard / room-update / keepalive / idle-timeout loop
* until the client disconnects.
* 6. Broadcast a system leave message and release all refs / counters.
*
* Owns the client_t after entry: callers must NOT touch it once this
* returns. Always returns regardless of how the session ended. */
void input_run_session(client_t *client);
/* Bell-notify any clients whose @username appears in the broadcast
* content, skipping the sender. Used by the INSERT-mode send path
* inside input_run_session and by exec_command_post. */
void notify_mentions(const char *content, const client_t *sender);
#endif /* INPUT_H */