/* * plugintime.h - shared declarations for plugin_time. * * NOT time.h: gcc searches -I directories for #include <...> as well, so a * local time.h silently shadows the C library's and every struct tm * in the tree stops existing. * * plugin_time is a SCORPIOX BOT connector plugin that reimplements the * reference MCP "time" server in pure C99: IANA timezone queries and * wall-clock conversions, served as MCP tools over stdio and as a JSON API * behind a browser UI. * * plugin_time.c main(), --meta, --mcp loop, CGI dispatch, auth, HTML * timeutil.c the three tools, ISO formatting, tool schemas * tz.c the embedded IANA table: keys, offsets, wall resolution * * MIT License. Copyright (c) 2026 SCORPIOX INC. */ #ifndef SX_PLUGIN_TIME_H #define SX_PLUGIN_TIME_H #include #include #include "yyjson.h" #define PLUGIN_SLUG "time" #define PLUGIN_ID "plugin_time" #define PLUGIN_VER "1.0.2" #define PLUGIN_NAME "time" #define PLUGIN_DESC "World time MCP" #define MCP_PROTOCOL "2025-06-18" #define SERVER_NAME "time-server" #define TZ_NAME_MAX 96 #define STDIN_LINE_MAX (1024 * 1024) #define REQ_BODY_MAX (1024 * 1024) /* ------------------------------------------------------------------ */ /* Growable byte buffer (timeutil.c) */ /* ------------------------------------------------------------------ */ typedef struct { char *p; size_t n; size_t cap; } buf_t; void buf_init(buf_t *b); int buf_need(buf_t *b, size_t extra); void buf_add(buf_t *b, const char *s, size_t n); void buf_puts(buf_t *b, const char *s); void buf_putc(buf_t *b, int c); void buf_printf(buf_t *b, const char *fmt, ...); const char *buf_str(const buf_t *b); void buf_free(buf_t *b); /* JSON string escape into a buf_t (safe against control characters). */ void json_str(buf_t *b, const char *s); /* ------------------------------------------------------------------ */ /* Time formatting */ /* ------------------------------------------------------------------ */ /* Local wall time for a UTC instant in `offset` (east of UTC, seconds). */ void time_split(int64_t utc, int offset, int *year, int *month, int *day, int *hour, int *min, int *sec, int *weekday); /* ISO-8601 with seconds precision and a numeric offset, e.g. * 2026-11-14T13:21:10+13:00. `out` needs ~40 bytes. */ void time_iso(int64_t utc, int offset, char *out, size_t outsz); /* "+13:00", "-05:00", "+05:45", "+00:00". */ void time_offset_str(int offset, char *out, size_t outsz); /* "Friday" */ const char *time_weekday_name(int weekday); /* The current UTC instant; SX_TIME_NOW pins it for deterministic tests. */ int64_t time_now_utc(void); /* "+3.0h" / "+5.75h" / "-0.5h" - the reference server's format. */ void time_diff_str(int source_off, int target_off, char *out, size_t outsz); /* ------------------------------------------------------------------ */ /* Tool results */ /* ------------------------------------------------------------------ */ typedef struct { yyjson_mut_doc *md; /* owns root */ yyjson_mut_val *root; char *error; /* error text when is_error */ int is_error; } tool_out_t; void tool_out_init(tool_out_t *t); void tool_err(tool_out_t *t, const char *fmt, ...); void tool_free(tool_out_t *t); void tool_get_current_time(yyjson_val *args, tool_out_t *t); void tool_convert_time(yyjson_val *args, tool_out_t *t); void tool_get_time_ago(yyjson_val *args, tool_out_t *t); /* The full tools/list array as JSON text (caller frees). */ char *tools_list_json(void); int tool_dispatch(const char *name, yyjson_val *args, tool_out_t *out); /* MCP result: content[] + structuredContent + isError. Caller frees. */ char *tool_mcp_result(tool_out_t *t); /* HTTP API result: {"ok":true,...} or {"ok":false,"error":"..."}. Caller frees. */ char *tool_api_result(tool_out_t *t); /* The three tool names, for --help and the page's tool list. */ extern const char *const TOOL_NAMES[]; extern const int TOOL_COUNT; #endif /* SX_PLUGIN_TIME_H */