Tchatator413
TripEnArvor instant messaging protocol - JSON-based
|
Tchatator413 request parsing and interpretation - Interface. More...
#include <json-c.h>
#include <stdbool.h>
#include <stdio.h>
#include "const.h"
#include "cfg.h"
#include "db.h"
#include "server.h"
#include "types.h"
Go to the source code of this file.
Data Structures | |
struct | action_error_t |
An error that occured while parsing or running an action. More... | |
struct | action_t |
An action. Actions represent the commands the protocol implements. More... | |
struct | response_t |
Macros | |
#define | X(name) action_type_##name, |
#define | ACTION_TYPE(name) CAT(action_type_, name) |
Expands to an identifier that is the type of the action of name name . | |
Enumerations | |
enum | status_t { status_bad_request = 400 , status_unauthorized = 401 , status_forbidden = 403 , status_not_found = 404 , status_payload_too_large = 413 , status_unprocessable_content = 422 , status_too_many_requests = 429 , status_internal_server_error = 500 } |
Status codes for the Tchatator413 protocol, modeled after HTTP status codes. More... | |
enum | action_error_type_t { action_error_type_type , action_error_type_missing_key , action_error_type_invalid , action_error_type_rate_limit , action_error_type_invariant , action_error_type_other } |
Enumerates the type of errors that occur while parsing or running an action. More... | |
enum | action_type_t { action_type_error } |
Enumerates the types of actions, representing the various commands available. More... | |
Functions | |
void | response_destroy (response_t *response) |
Destroy a response. | |
response_t | response_for_rate_limit (time_t next_request_at) |
Builds a response for a rate limit error. | |
void | put_role (role_flags_t role, FILE *stream) |
Put an user role. | |
action_t | action_parse (cfg_t *cfg, db_t *db, json_object *obj) |
Parse an action from a JSON object. | |
response_t | action_evaluate (action_t const *action, cfg_t *cfg, db_t *db, server_t *server) |
Evaluate an action. | |
json_object * | response_to_json (response_t *response) |
Convert an action response to JSON. | |
void | action_explain (action_t const *action, FILE *output) |
Explain an action. | |
Tchatator413 request parsing and interpretation - Interface.
Definition in file action.h.
#define ACTION_TYPE | ( | name | ) | CAT(action_type_, name) |
enum action_error_type_t |
Enumerates the type of errors that occur while parsing or running an action.
Definition at line 33 of file action.h.
enum action_type_t |
Enumerates the types of actions, representing the various commands available.
Enumerator | |
---|---|
action_type_error | Special value for an action triggered an error. |
Definition at line 85 of file action.h.
enum status_t |
Status codes for the Tchatator413 protocol, modeled after HTTP status codes.
Definition at line 21 of file action.h.
response_t action_evaluate | ( | action_t const * | action, |
cfg_t * | cfg, | ||
db_t * | db, | ||
server_t * | server | ||
) |
Evaluate an action.
action | The action to evaluate. |
cfg | The configuration. |
db | The database connection. |
server | The server |
void action_explain | ( | action_t const * | action, |
FILE * | output | ||
) |
Explain an action.
action | The action to explain. |
output | The stream to write the exlanation to. |
Parse an action from a JSON object.
db | The configuration. |
db | The database connection. |
obj | The JSON object allegedly containing an action. |
void put_role | ( | role_flags_t | role, |
FILE * | stream | ||
) |
Put an user role.
role | The role flags |
stream | The stream to write to. |
void response_destroy | ( | response_t * | response | ) |
Destroy a response.
response | The response to destroy. |
response_t response_for_rate_limit | ( | time_t | next_request_at | ) |
Builds a response for a rate limit error.
next_request_at | The time at which the next request will be allowed. |
json_object * response_to_json | ( | response_t * | response | ) |
Convert an action response to JSON.
response | The action response. |