Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

mdlv API reference

Mariusz Krzyżok edited this page Sep 20, 2024 · 2 revisions

Refer to server.c and web_root/script.js for working server and browser client implementation.

Server

mdlv_script_t

typedef struct mdlv_script {
    char* name;                 // Name of script
    cdlv* instance;             // cdlv instance handling this script
    struct mdlv_script* next;   // Pointer to next struct in linked list
} mdlv_script_t;

Linked list holding cdlv instances with scripts found by mdlv.

mdlv

typedef struct mdlv {
    char* host;               // Host URL
    char* path;               // Path to scripts files
    char* web_root;           // Path to web_root
    mdlv_script_t* scripts;   // Scripts list
    struct mg_mgr manager;    // Mongoose HTTP server manager
} mdlv;

mdlv_init

cdlv_error mdlv_init(mdlv* base);

Initialize mdlv server, scripts found within mdlv->path and start listening on mdlv->host.

Parameters:

  • base - a pointer to mdlv base

mdlv_free

void mdlv_free(mdlv* base);

Free all resources.

Parameters:

  • base - a pointer to mdlv base

HTTP API Endpoints

All responses have Content-Type; application/json (unless specified otherwise).

/list

Lists loaded and parsed scripts.

Parameters:

  • None

Response:

  • 200 - OK

Example:

curl http://localhost:8080/list
{"type": "list", "files": ["test.cdlv","sample.cdlv"]}

/script

Get script file data.

Parameters:

  • filename - one of filenames listed in files array from /list

Response:

  • 200 - OK
  • 400 - filename was not sent by user or wrong file specified
  • 500 - File could not loaded or JSON error

Example:

curl http://localhost:8080/script -d '{"filename":"test.cdlv"}'
{"type":"script","global_resources":[],"scenes":[{"name":"one","resources":[{"1":"../res/sample/images/scene/1.png"}],"resources_path":"../res/sample/images/scene/","script":["@bg 1","I just displayed empty background.","dXd"]},{"name":"two","resources":[],"resources_path":"../res/sample/images/scene/","script":["@bg 2.png","It's another scene.","Aand it's working!!"]}]}
curl http://localhost:8080/script
{"type": "error", "msg": "No filename found"}

/anim

Get video as a response with Content-Type: video/mp4 on 200. Other responses return Content-Type: application/json.

Parameters:

  • filename - one of filenames listed in resources with resource_path appended

Response:

  • 200 - OK
  • 400 - filename was not sent by user
  • 500 - File could not be read

Example:

curl http://localhost:8080/anim -d '{"filename":"../res/sample/images/scene/anim.mp4"}' -o anim.mp4

/bg

Get image as a response with Content-Type: image/jpeg on 200. Other responses return Content-Type: application/json.

Parameters:

  • filename - one of filenames listed in resources

Response:

  • 200 - OK
  • 400 - filename was not sent by user
  • 500 - File could not be read

Example:

curl http://localhost:8080/bg -d '{"filename":"../res/sample/images/white.png"}' -o white.png

Clone this wiki locally