Tchatator413
TripEnArvor instant messaging protocol - JSON-based
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
action.h File Reference

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.
 

Detailed Description

Tchatator413 request parsing and interpretation - Interface.

Author
Raphaƫl
Date
23/01/2025

Definition in file action.h.

Macro Definition Documentation

◆ ACTION_TYPE

#define ACTION_TYPE (   name)    CAT(action_type_, name)

Expands to an identifier that is the type of the action of name name.

Definition at line 95 of file action.h.

◆ X

#define X (   name)    action_type_##name,

Definition at line 89 of file action.h.

Enumeration Type Documentation

◆ action_error_type_t

Enumerates the type of errors that occur while parsing or running an action.

Enumerator
action_error_type_type 

Parsing JSON type error.

action_error_type_missing_key 

Parsing JSON missing key.

action_error_type_invalid 

Parsing JSON invalid value.

action_error_type_rate_limit 

The rate limit has been reached.

action_error_type_invariant 

An invariant was broken.

action_error_type_other 

Another error occured.

Definition at line 33 of file action.h.

33 {
action_error_type_t
Enumerates the type of errors that occur while parsing or running an action.
Definition action.h:33
@ action_error_type_missing_key
Parsing JSON missing key.
Definition action.h:35
@ action_error_type_type
Parsing JSON type error.
Definition action.h:34
@ action_error_type_other
Another error occured.
Definition action.h:39
@ action_error_type_invalid
Parsing JSON invalid value.
Definition action.h:36
@ action_error_type_invariant
An invariant was broken.
Definition action.h:38
@ action_error_type_rate_limit
The rate limit has been reached.
Definition action.h:37

◆ 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.

85 {
88
89#define X(name) action_type_##name,
90 X_ACTIONS(X)
91#undef X
action_type_t
Enumerates the types of actions, representing the various commands available.
Definition action.h:85
@ action_type_error
Special value for an action triggered an error.
Definition action.h:87
#define X_ACTIONS(X)
X-macro that expands to the list of actions.
Definition const.h:18

◆ status_t

enum status_t

Status codes for the Tchatator413 protocol, modeled after HTTP status codes.

Remarks
The resemblance with HTTP status codes is only for familiarity.
Enumerator
status_bad_request 

Bad request.

status_unauthorized 

Unauthorized.

status_forbidden 

Forbidden.

status_not_found 

Not found.

status_payload_too_large 

Payload too large.

status_unprocessable_content 

Unprocessable content.

status_too_many_requests 

Too many requests.

status_internal_server_error 

Internal server error.

Definition at line 21 of file action.h.

21 {
22 status_bad_request = 400,
24 status_forbidden = 403,
25 status_not_found = 404,
30} status_t;
status_t
Status codes for the Tchatator413 protocol, modeled after HTTP status codes.
Definition action.h:21
@ status_bad_request
Bad request.
Definition action.h:22
@ status_payload_too_large
Payload too large.
Definition action.h:26
@ status_unauthorized
Unauthorized.
Definition action.h:23
@ status_internal_server_error
Internal server error.
Definition action.h:29
@ status_too_many_requests
Too many requests.
Definition action.h:28
@ status_forbidden
Forbidden.
Definition action.h:24
@ status_unprocessable_content
Unprocessable content.
Definition action.h:27
@ status_not_found
Not found.
Definition action.h:25

Function Documentation

◆ action_evaluate()

response_t action_evaluate ( action_t const *  action,
cfg_t cfg,
db_t db,
server_t server 
)

Evaluate an action.

Parameters
actionThe action to evaluate.
cfgThe configuration.
dbThe database connection.
serverThe server
Returns
The response to the action.

◆ action_explain()

void action_explain ( action_t const *  action,
FILE *  output 
)

Explain an action.

Parameters
actionThe action to explain.
outputThe stream to write the exlanation to.

◆ action_parse()

action_t action_parse ( cfg_t cfg,
db_t db,
json_object *  obj 
)

Parse an action from a JSON object.

Parameters
dbThe configuration.
dbThe database connection.
objThe JSON object allegedly containing an action.
Returns
The parsed action.

◆ put_role()

void put_role ( role_flags_t  role,
FILE *  stream 
)

Put an user role.

Parameters
roleThe role flags
streamThe stream to write to.

◆ response_destroy()

void response_destroy ( response_t response)

Destroy a response.

Parameters
responseThe response to destroy.

◆ response_for_rate_limit()

response_t response_for_rate_limit ( time_t  next_request_at)

Builds a response for a rate limit error.

Parameters
next_request_atThe time at which the next request will be allowed.
Returns
A new response.

◆ response_to_json()

json_object * response_to_json ( response_t response)

Convert an action response to JSON.

Parameters
responseThe action response.
Returns
A new JSON object.