1. Overview
Local IPC server that listens on a Unix-domain socket, exchanges framed JSON messages with the BastionGuard daemon, converts messages into typed connection and alert structures, sends verdict replies, queues notifications, and dispatches events onto the GTK main thread.
File role: Header Interface. The file contains 98 lines and belongs to the ipc/UIServer.hpp path.
The companion file is ipc/UIServer.cpp.
2. Component Responsibilities
- Declare the component API, owned state, callbacks, and data structures.
- Normalize and bind the Unix-socket path
- Accept the daemon connection in a worker thread
- Read length-prefixed frames
- Parse JSON messages into ConnectionInfo or AlertInfo
- Dispatch UI signals through GLib idle/dispatcher mechanisms
- Send rule replies and queued notifications
- Detect disconnects and return to the accept loop
3. Dependencies and Integration
Project-level dependencies:
glibmm/dispatcher.hsigc++/sigc++.h
System and library dependencies:
atomiccondition_variablecstdintdequememorymutexstringthreadunordered_mapvector
4. Declared Types
ConnectionInfo
Declares a struct.
DaemonNotification
Declares a struct.
AlertInfo
Declares a struct.
UIServer
Declares a class.
ReplyAction
Defines the following closed set of values:
ALLOW_ONCEALLOW_ALWAYSDENY_ONCEDENY_ALWAYS
5. Owned State and UI Members
Data and configuration state
std::string app_path;std::string app_comm;std::string app_cwd;std::vector<std::string> app_args;uint32_t pid = 0;uint32_t uid = 0;std::string protocol;std::string src_ip;uint32_t src_port = 0;std::string dest_host;std::string dest_ip;uint32_t dest_port = 0;uint64_t id = 0;int type = 0;std::string data;int action = 0;int priority = 0;int what = 0;std::string text;std::string rule_name;std::string firewall_table;std::string firewall_chain;ConnectionInfo connection;bool has_connection = false;std::unique_ptr<Impl> impl_;
6. Signals and Event Integration
The file exposes or connects the following signal-related elements:
// ── Segnali emessi nel thread principale GTK via Glib::Dispatcher ──sigc::signal<void()> signal_daemon_connected;sigc::signal<void()> signal_daemon_disconnected;sigc::signal<void(const ConnectionInfo&)> signal_new_connection;sigc::signal<void(const AlertInfo&)> signal_alert;
GTK-facing callbacks must execute on the main UI context. Components with worker threads use dispatchers or idle callbacks to cross the thread boundary.
7. Functions and Methods
The file exposes or implements 6 detected function or method signatures.
1. UIServer
UIServer()
Implements the uiserver operation declared by this component.
2. ~UIServer
~UIServer()
Releases resources owned by the object and stops any active background integration.
3. start
void start(const std::string& socketPath = "unix:///tmp/bsd-daemon.sock")
Starts start and activates the associated runtime resources.
4. stop
void stop()
Stops stop and releases or signals its active resources.
5. sendReply
void sendReply(ReplyAction action)
Sends reply to the connected peer or subsystem.
6. queueNotification
void queueNotification(int type, const std::string& data = {})
Queues notification for deferred processing.
8. Filesystem, IPC, Network, and Command Interfaces
Relevant literal paths, endpoints, or resource locations include:
/tmp/x.sockunix:///tmp/x.sockunix:///tmp/bsd-daemon.sock
9. Runtime Flow
- Normalize and bind the Unix-socket path
- Accept the daemon connection in a worker thread
- Read length-prefixed frames
- Parse JSON messages into ConnectionInfo or AlertInfo
- Dispatch UI signals through GLib idle/dispatcher mechanisms
- Send rule replies and queued notifications
- Detect disconnects and return to the accept loop
10. Concurrency and Main-Loop Behavior
- Uses a condition variable for worker wake-up and shutdown coordination.
- Uses atomic state for cross-thread lifecycle control.
- Marshals results or callbacks onto the GLib/GTK main context.
11. Runtime and Security Considerations
- Uses a local Unix-domain socket rather than a network listener.
- Reads exact framed message lengths before parsing payloads.
- Separates the socket worker thread from the GTK signal thread.
- Represents user decisions with a closed ReplyAction enumeration.
- Socket lifecycle and framing errors are handled without performing GTK operations directly from the I/O thread.
- Temporary paths are used; file naming, permissions, and replacement behavior form part of the privilege boundary.
12. Error Handling and Operational Notes
- Errors are propagated through the return type, callbacks, or the owning controller.
13. Source Integrity
Relative source path: ipc/UIServer.hpp
SHA-256:
ccfb5e9d4f18bd6e3ec298c6b20fa48ea131aa58943db155140e89c2de77afc6
14. Licensing
The source header identifies this component as distributed under the GNU General Public License version 3. BastionGuard branding and trademarks remain subject to the notices stated in the source file.
