unit fn_cookies

#FujiNet library for using APPKEY storage build in #FujiNet device.

author: bocianu bocianu@gmail.com


This library provides an easy interface to store so called APPKEYS or cookies on SD card of your fujinet device.
Those tiny data blobs can be used by applications to store some data, like configuration, keys, tokens on the device itself.
They are not public, and persistent on your device, until you will remove them manually from your SD card.
Maximum size of single cookie is 64 bytes.
https://fujinet.online/
This library is a part of 'blibs' - set of custom Mad-Pascal libraries.
https://gitlab.com/bocianu/blibs

Constants:

name:value:description:
MAX_COOKIE_SIZE64

Types:

name:type:description:
TCookieFramerecord
  • len: word;
  • body: array [0..MAX_COOKIE_SIZE-1] of byte;

end;
Structure used to retrieve cookie from storage
TCookieInforecord
  • creator: word;
  • app: byte;
  • key: byte;
  • mode: byte;
  • reserved: byte;

end;
Structure used to set cookie info in Open Command

Interface:

name:description:
InitCookie

procedure InitCookie(creator: word; app, key: byte);


Inits cookie storage params, and sets unique filename based on provided ID_keys. Must be called at least once, before any Set or Get command is issued.
    parameters:
  • (word) creator - creator ID number
  • (byte) app - application ID number
  • (byte) key - key ID number
SetCookie

function SetCookie(val: pointer; vlength: word):byte;


Stores new cookie value.
    parameters:
  • (pointer) val - value to be stored
  • (word) vlength - length of data in bytes (max. 64)
  • returns:
  • (byte) - sio operation result
GetCookie

function GetCookie(val: pointer):byte;


Restores cookie value from device, to buffer.
Size of received data is returned in cookie.len field.
    parameters:
  • (pointer) val - pointer to receive buffer
  • returns:
  • (byte) - sio operation result