mirror of
https://oauth2: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@github.com/m1ngsama/TNT.git
synced 2026-06-26 06:44:39 +08:00
Fixes: - message_load() now holds g_message_file_lock for the read, so :last [N] can no longer observe a half-written line while message_save() is flushing. - constant_time_strcmp() accumulates the length difference in size_t. The old code truncated to unsigned char, which collapsed pairs whose lengths differed by a multiple of 256 down to 0 and lost the signal. Refactor: - buffer_appendf() / buffer_append_bytes() moved to common.c; the two identical copies in ssh_server.c and tui.c have been removed. Docs / cleanup: - README clarifies that exec 'post' uses the SSH login name as the author and that anonymous mode performs no identity check. - Removed TODO.md (both items completed) and docs/README.old. - Trimmed the auto-generated 2025 entry block from docs/CHANGELOG.md and added a 2026-05-16 entry summarising this change.
65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
#ifndef COMMON_H
|
|
#define COMMON_H
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stdatomic.h>
|
|
#include <time.h>
|
|
#include <limits.h>
|
|
#include <pthread.h>
|
|
|
|
/* Project Metadata */
|
|
#define TNT_VERSION "1.0.0"
|
|
|
|
/* Configuration constants */
|
|
#define DEFAULT_PORT 2222
|
|
#define MAX_MESSAGES 100
|
|
#define MAX_USERNAME_LEN 64
|
|
#define MAX_MESSAGE_LEN 1024
|
|
#define MAX_EXEC_COMMAND_LEN 1024
|
|
#define MAX_CLIENTS 64
|
|
#define LOG_FILE "messages.log"
|
|
#define MAX_LOG_SIZE (10 * 1024 * 1024) /* 10 MiB */
|
|
#define HOST_KEY_FILE "host_key"
|
|
#define TNT_DEFAULT_STATE_DIR "."
|
|
#define DEFAULT_IDLE_TIMEOUT 1800 /* 30 minutes */
|
|
|
|
/* ANSI color codes */
|
|
#define ANSI_RESET "\033[0m"
|
|
#define ANSI_BOLD "\033[1m"
|
|
#define ANSI_REVERSE "\033[7m"
|
|
#define ANSI_CLEAR "\033[2J"
|
|
#define ANSI_HOME "\033[H"
|
|
#define ANSI_CLEAR_LINE "\033[K"
|
|
|
|
/* Operating modes */
|
|
typedef enum {
|
|
MODE_INSERT,
|
|
MODE_NORMAL,
|
|
MODE_COMMAND,
|
|
MODE_HELP
|
|
} client_mode_t;
|
|
|
|
/* Help language */
|
|
typedef enum {
|
|
LANG_EN,
|
|
LANG_ZH
|
|
} help_lang_t;
|
|
|
|
/* Runtime helpers */
|
|
const char* tnt_state_dir(void);
|
|
int tnt_ensure_state_dir(void);
|
|
int tnt_state_path(char *buffer, size_t buf_size, const char *filename);
|
|
|
|
/* Bounded string buffer builders. Both append to `buffer[*pos..]`, advance
|
|
* `*pos`, and always keep the buffer NUL-terminated. They never write past
|
|
* `buf_size - 1` and become no-ops once the buffer is full. */
|
|
void buffer_append_bytes(char *buffer, size_t buf_size, size_t *pos,
|
|
const char *data, size_t len);
|
|
void buffer_appendf(char *buffer, size_t buf_size, size_t *pos,
|
|
const char *fmt, ...);
|
|
|
|
#endif /* COMMON_H */
|