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

Tchatator413 dynamic server state - Interface. More...

#include "types.h"
#include <stdbool.h>
#include <time.h>

Go to the source code of this file.

Data Structures

struct  user_stats_t
 

Typedefs

typedef struct server server_t
 Opaque type handle representing a server instance.
 

Functions

server_tserver_create (api_key_t admin_api_key, char const *admin_password)
 Creates a new server instance.
 
void server_destroy (server_t *server)
 Destroys the specified server instance.
 
token_t server_login (server_t *server, serial_t user_id)
 Creates a new session, logging in an user.
 
bool server_is_admin_api_key (server_t *server, api_key_t api_key)
 Checks if an API key is the admin API key.
 
bool server_check_admin_password (server_t *server, char const *password)
 Check a password against the admin password.
 
bool server_logout (server_t *server, token_t token)
 Deletes a session, logging out an user.
 
serial_t server_verify_token (server_t *server, token_t token)
 Verifies a token, returning its owning user ID.
 

Detailed Description

Tchatator413 dynamic server state - Interface.

Author
Raphaƫl
Date
29/01/2025

Definition in file server.h.

Typedef Documentation

◆ server_t

typedef struct server server_t

Opaque type handle representing a server instance.

Definition at line 23 of file server.h.

Function Documentation

◆ server_check_admin_password()

bool server_check_admin_password ( server_t server,
char const *  password 
)

Check a password against the admin password.

Parameters
serverThe server.
passwordThe password to check.
Returns
true if the provided password matches the admin password.
false otherwise.

◆ server_create()

server_t * server_create ( api_key_t  admin_api_key,
char const *  admin_password 
)

Creates a new server instance.

Parameters
admin_api_keyThe admin API key.
admin_passwordThe admin password.
Returns
A new server instance.

◆ server_destroy()

void server_destroy ( server_t server)

Destroys the specified server instance.

Parameters
serverThe server instance to destroy.

◆ server_is_admin_api_key()

bool server_is_admin_api_key ( server_t server,
api_key_t  api_key 
)

Checks if an API key is the admin API key.

Parameters
serverThe server.
api_keyThe API key to check.
Returns
true if api_key is the admin API key.
false otherwise.

◆ server_login()

token_t server_login ( server_t server,
serial_t  user_id 
)

Creates a new session, logging in an user.

Parameters
serverThe server.
user_idThe ID of the user to login.
Returns
The new session token.
0 if the the session could not be created. This happens if the same user tries logs in twice in the same second.

◆ server_logout()

bool server_logout ( server_t server,
token_t  token 
)

Deletes a session, logging out an user.

Parameters
serverThe server.
tokenThe session token to invalidate.
Returns
true on successful log out.
false if the token is invalid.

◆ server_verify_token()

serial_t server_verify_token ( server_t server,
token_t  token 
)

Verifies a token, returning its owning user ID.

Parameters
serverThe server.
tokenThe session token to verify.
Returns
-1 if the session token is invalid.
The ID of the user that owns token if it is valid.