|
#define | API_URL "/_matrix/client/r0" |
| Root URL for the Matrix API.
|
|
#define | SYNC_URL API_URL "/sync" |
| URL for the synchronization endpoint.
|
|
#define | ROOM_FILTER "filter={\"room\":{\"timeline\":{\"limit\":1}}}" |
| Limits the number of synchronization events to one.
|
|
#define | ROOMS_URL API_URL "/rooms" |
| URL for the rooms endpoint.
|
|
#define | SEND_URL "/send/m.room.message" |
| URL fragment for the send-message enpoint for a room.
|
|
#define | SYNC_INTERVAL_MS_STR "30000" |
| Polling interval for the synchronization request.
|
|
#define | TIMEOUT_PARAM "timeout=" SYNC_INTERVAL_MS_STR |
| Sets the polling interval to SYNC_INTERVAL_MS_STR.
|
|
#define | URL_PARTS(c, ...) (c)->server, __VA_ARGS__, "access_token=", (c)->token |
| Prepends the server and appends the token from the configuration.
|
|
#define | BUILD_MATRIX_URL(c, url, ...) BUILD_URL(url, URL_PARTS((c), __VA_ARGS__)) |
| Builds a URL using URL_PARTS.
|
|
|
int | main (int argc, const char *const *argv) |
| Program entry point.
|
|
static bool | parse_args (int *argc, const char *const **argv, struct config *config) |
| Parses command-line arguments and fills config .
|
|
static void | usage (FILE *f) |
| Prints a usage message.
|
|
static bool | short_username (const char *user, char *out) |
| Extracts the short user name from a @user:server string.
|
|
static bool | read_token (struct mtrix_buffer b) |
| Reads the token from a file.
|
|
static void | config_destroy (struct config *config) |
| Destructs config .
|
|
static void | config_set_args (struct config *config, const char *const *argv) |
| Constructs the machinatrix command line with references to argv .
|
|
static void | config_verbose (const struct config *config, const char *fmt,...) |
| Logs a message if verbose output was requested.
|
|
static cJSON * | get_item (const cJSON *j, const char *k) |
| Shortcut for `cJSON_GetObjectItemCaseSensitive.
|
|
static bool | init_batch (const struct config *config, char *batch) |
| Fetches the inital batch for synchronization.
|
|
static bool | get_next_batch (cJSON *j, char *batch) |
| Extracts the next batch from a server response.
|
|
static bool | filter (const struct config *config, char *batch) |
| Main request/response loop in filter mode.
|
|
static bool | loop (const struct config *config, char *batch) |
| Main request/response loop.
|
|
static cJSON * | parse_json (const char *s) |
| Parses a string as JSON.
|
|
static bool | handle_request (const struct config *config, cJSON *root, size_t user_len, bool(*send_msg)(const struct config *, const char *, const char *)) |
| Handles a single request.
|
|
static bool | check_event_type (const cJSON *event, const char *value) |
| Checks that an event has the expected type.
|
|
static const char * | event_body (const cJSON *event) |
| Finds the event body, if it contains one.
|
|
static const char * | event_sender (const cJSON *event) |
| Finds the event sender, if it contains one.
|
|
static bool | check_mention (const char *text, const char *user) |
| Checks if the a user was mentioned.
|
|
static bool | process_input (const struct config *config, const char *input, struct mtrix_buffer *output) |
| Invokes the main program.
|
|
static bool | print_msg (const struct config *config, const char *room, const char *msg) |
| Prints a message to stdout.
|
|
static bool | send_msg (const struct config *config, const char *room, const char *msg) |
| Sends a message to the room.
|
|
static bool | read_output (FILE *f, struct mtrix_buffer *buf) |
| Consumes all output from f , appending it to buf .
|
|
Program that interacts with the Matrix server.
Executes the main program to handle the commands.