summaryrefslogtreecommitdiff
path: root/include/hybbx/service.h
blob: 4730b8bbb64db75872e222b2148a3dbd2f060c90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#ifndef HYBBX_SERVICE_H
#define HYBBX_SERVICE_H

/**
 * Centralized HyBBX daemon API (`hybbx` binary).
 *
 * Loads INI ([service], [storage], [auth], [transport.*], [circuit]), starts
 * transport plugins and the HBX circuit hub. Edge link/repeater daemons attach
 * to [circuit]; see share/hybbx.ini.example and docs/TOPOLOGY.md.
 */

#include "hybbx/config.h"
#include "hybbx/plugin.h"
#include "hybbx/auth.h"
#include "hybbx/storage.h"
#include "hybbx/texts.h"

#ifdef __cplusplus
extern "C" {
#endif

/** Default global service name (`[service] name` in INI). */
#define HYBBX_DEFAULT_SERVICE_NAME "hyBBX"

typedef struct hybbx_service {
    const char *name;
    void *userdata;
} hybbx_service_t;

/** Create the main HyBBX service instance. */
hybbx_service_t *hybbx_service_create(const char *name);

/** Destroy the service and shut down all active transports. */
void hybbx_service_destroy(hybbx_service_t *service);

/**
 * Apply settings from an INI configuration (service name, enabled transports).
 */
hybbx_result_t hybbx_service_apply_config(hybbx_service_t *service,
                                          const hybbx_config_t *config,
                                          const char *config_path);

/**
 * Load a transport plugin by name (e.g. "telnet", "packet_radio").
 * Built-in plugins are linked statically; dynamic loading comes later.
 */
hybbx_result_t hybbx_service_load_transport(hybbx_service_t *service,
                                            const char *plugin_name);

/** Start a loaded transport with transport-specific configuration. */
hybbx_result_t hybbx_service_start_transport(hybbx_service_t *service,
                                               const char *plugin_name,
                                               const char *config);

/** Stop a running transport. */
hybbx_result_t hybbx_service_stop_transport(hybbx_service_t *service,
                                            const char *plugin_name);

/** Run the main event loop until hybbx_service_stop() is called. */
hybbx_result_t hybbx_service_run(hybbx_service_t *service);

/** Request the main loop to exit. */
void hybbx_service_stop(hybbx_service_t *service);

typedef enum hybbx_shutdown_mode {
    HYBBX_SHUTDOWN_NONE = 0,
    HYBBX_SHUTDOWN_STOP = 1,
    HYBBX_SHUTDOWN_RESTART = 2
} hybbx_shutdown_mode_t;

/** Store the daemon binary path used for /restart (typically argv[0]). */
void hybbx_service_set_launch_binary(hybbx_service_t *service, const char *argv0);

/** Sysop /shutdown or /restart — stops the main loop; restart re-execs after exit. */
void hybbx_service_request_shutdown(hybbx_service_t *service, int restart);

/** Shutdown mode requested while the service is still running. */
hybbx_shutdown_mode_t hybbx_service_shutdown_mode(const hybbx_service_t *service);

/**
 * Re-exec the daemon when @ref hybbx_service_shutdown_mode is
 * @ref HYBBX_SHUTDOWN_RESTART. Call before @ref hybbx_service_destroy.
 * Does not return on success.
 */
void hybbx_service_restart_exec(const hybbx_service_t *service);

const char *hybbx_service_config_path(const hybbx_service_t *service);

hybbx_storage_t *hybbx_service_get_storage(hybbx_service_t *service);
const hybbx_auth_config_t *hybbx_service_get_auth(hybbx_service_t *service);
const hybbx_texts_config_t *hybbx_service_get_texts(hybbx_service_t *service);

/**
 * Global input prompt shown to every connected user.
 * Empty string when unset (default): no visible prompt before input.
 */
const char *hybbx_service_get_prompt(const hybbx_service_t *service);

/** Global service name from configuration (default @ref HYBBX_DEFAULT_SERVICE_NAME). */
const char *hybbx_service_get_name(const hybbx_service_t *service);

/** Configured maximum simultaneous online sessions (default @ref HYBBX_DEFAULT_MAX_ONLINE). */
unsigned hybbx_service_max_online(const hybbx_service_t *service);

/**
 * Non-zero when `[service] login_announce=yes`:
 * broadcast "*** User login: user@plugin" and list /who as user@plugin.
 */
int hybbx_service_login_announce(const hybbx_service_t *service);

/** Currently connected sessions (all transports). */
unsigned hybbx_service_active_nodes(const hybbx_service_t *service);

/** Guest auto-disconnect timeout in seconds (from INI minutes setting). */
unsigned hybbx_service_guest_timeout_seconds(const hybbx_service_t *service);

struct hybbx_user_record;

/**
 * Assign the lowest free ephemeral guest slot (Guest1 … Guest25).
 * Guests are not written to user files.
 */
hybbx_result_t hybbx_service_guest_assign(hybbx_service_t *service,
                                          const char *guest_prefix,
                                          struct hybbx_user_record *out,
                                          unsigned *slot_out);

/** Release a guest slot when the session ends or leaves guest mode. */
void hybbx_service_guest_release(hybbx_service_t *service, unsigned slot);

/**
 * Reserve one node slot for a new connection.
 * @return HYBBX_ERR_BUSY when @ref hybbx_service_max_online is reached.
 */
hybbx_result_t hybbx_service_acquire_node(hybbx_service_t *service);

/** Release a node slot (pair with @ref hybbx_service_acquire_node). */
void hybbx_service_release_node(hybbx_service_t *service);

struct hybbx_session;

/** Track an active connection for chat broadcast and similar features. */
hybbx_result_t hybbx_service_attach_session(hybbx_service_t *service,
                                            struct hybbx_session *session);

/** Remove a session from the active connection list. */
void hybbx_service_detach_session(hybbx_service_t *service,
                                  struct hybbx_session *session);

typedef void (*hybbx_service_session_visit_fn)(struct hybbx_session *session,
                                               void *userdata);

/** Invoke @p fn for each attached session (snapshot; lock not held in @p fn). */
void hybbx_service_visit_sessions(hybbx_service_t *service,
                                  hybbx_service_session_visit_fn fn,
                                  void *userdata);

/**
 * Return a logged-in registered session for @p user_id on another connection,
 * or NULL when the account is not online elsewhere.
 */
struct hybbx_session *hybbx_service_find_registered_session(
    hybbx_service_t *service,
    uint64_t user_id,
    struct hybbx_session *exclude);

struct hybbx_circuit_hub;
struct hybbx_circuit_hub *hybbx_service_circuit_hub(hybbx_service_t *service);

#ifdef __cplusplus
}
#endif

#endif /* HYBBX_SERVICE_H */
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com