Robot
Move a little robot.
lib_server.h File Reference
#include <sys/types.h>
#include "string.h"
#include "base64.h"
Include dependency graph for lib_server.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  templates
 A structure for storing data used by HTTP responses. More...
 

Macros

#define string_append_literal(x, y)   string_append_with_size(x, y, (sizeof y) - 1)
 

Functions

void templates_init (struct templates *p_tem)
 Initializes a template structure by opening and reading all files. More...
 
void templates_deinit (struct templates *p_tem)
 Frees (de-initializes) memory used by a template structure. More...
 
void parse_client_request (const char *client_request, size_t data_len, char *method, char *path, char *version, int *p_cookie_x, int *p_cookie_y, int *p_cookie_found)
 Parses a client request and gets all needed information: More...
 
void generate_html_table (struct string *robot_grid, const int x_max, const int y_max, const int x_coord, const int y_coord)
 Generates the HTML table with the robot in the good case from given coordinates. More...
 

Macro Definition Documentation

◆ string_append_literal

#define string_append_literal (   x,
 
)    string_append_with_size(x, y, (sizeof y) - 1)

Function Documentation

◆ generate_html_table()

void generate_html_table ( struct string robot_grid,
const int  x_max,
const int  y_max,
const int  x_coord,
const int  y_coord 
)

Generates the HTML table with the robot in the good case from given coordinates.

Parameters
robot_gridPointer for the result.
x_maxValue max for x (so number of lines in the grid - 1).
y_maxValue max for y (so number of columns in the grid - 1).
x_coordRobot's x coordinate.
y_coordRobot's y coordinate.

◆ parse_client_request()

void parse_client_request ( const char *  client_request,
size_t  data_len,
char *  method,
char *  path,
char *  version,
int *  p_cookie_x,
int *  p_cookie_y,
int *  p_cookie_found 
)

Parses a client request and gets all needed information:

From the first line of the request:

  • method (e.g. GET, POST…)
  • path (e.g. /data/template.css)
  • HTTP version (e.g. HTTP/1)

From the cookies:

  • Are there cookies or not ?
  • If yes, x and y coordinates of robot.
Parameters
client_requestPointer to the client's request string.
data_lenSize of client's request.
methodPointer for the method (initialze with char method[16];).
pathPointer for the path. (initialze with char path[1024];).
versionPointer for the version (initialze with char version[16];).
p_cookie_xPointer for the x coordinate in the cookies.
p_cookie_yPointer for the y coordinate in the cookies.
p_cookie_foundPointer for a boolean to know if there is a cookie: 1 if cookie was found, otherwise 0.

◆ templates_deinit()

void templates_deinit ( struct templates p_tem)

Frees (de-initializes) memory used by a template structure.

Parameters
p_temPointer to the template structure to de-initialize.

◆ templates_init()

void templates_init ( struct templates p_tem)

Initializes a template structure by opening and reading all files.

Uses the open_and_read() function from base64.h.

Parameters
p_temPointer to the template structure to initialize.