Session.lua

From Alpine Linux

random_hash

Returns a base64 encoded hash, using _- as the extra characters, as these are safe for using in a URL.

INPUT:
hash size, in bits OUTPUT:
A base64 encoded hash of at least bits length.

  • HASH
    • Comes from reading /dev/urandom

CODING EXAMPLE:

-- Set variable/Call for this library
bobo = require "session"
print(bobo.random_hash(100))

will output a hash from /dev/urandom that is 17 char long

hash_ip_addr

INPUT:
This library required the following inputs/parameters.

  • ip address

OUTPUT:
This library deliverers the following output/parameters.

  • HEX incoded ip address

CODING EXAMPLE:

-- Set variable/Call for this library
bobo = require "session"
print(bobo.hash_ip_addr("192.168.10.1))

Output could be:

c0a80a01

ip_addr_from_hash

INPUT:
This library required the following inputs/parameters.

  • HEX encoded ip address

OUTPUT:
This library deliverers the following output/parameters.

  • ip address

CODING EXAMPLE:

-- Set variable/Call for this library
bobo = require "session"
print(bobo.ip_addr_from_hash("c0a80a01")

Output could be:

192.168.10.1

serialize

INPUT:
This library required the following inputs/parameters.

  • name
    • Name of the variable / table to serialize
  • value
    • Value of the variable / table to serialize.
  • saved
    • Used internally by recursive function to keep track of progress.

OUTPUT:
This library deliverers the following output/parameters.

  • string with the table serialized

CODING EXAMPLE:

-- Set variable/Call for this library
bobo = require "session"
t = {foo={1,2,3,4}, "one", "two", "bar", "baz"}
stuff = bobo.serialize("t",t)
print(stuff)
t = {}
t[1] = "one"
t[2] = "two"
t[3] = "bar"
t[4] = "baz"
t["foo"] = {}
t["foo"][1] = 1
t["foo"][2] = 2
t["foo"][3] = 3
t["foo"][4] = 4

save_session

INPUT:
This library required the following inputs/parameters.

  • sessionpath,session,sessiontable

OUTPUT:
This library deliverers the following output/parameters.

  • true is success, false if error

CODING EXAMPLE:

-- Set variable/Call for this library
bobo = require "session"
print(bobo.save_session("tmp", session, sessiontable)
-- will print true is success
-- false if failed