Session.lua: Difference between revisions

From Alpine Linux
Line 46: Line 46:
This library required the following inputs/parameters.
This library required the following inputs/parameters.
* name
* name
** What to use for the new elements
** Name of the variable / table to serialize
* value
* value
**value: table to serialize
** Value of the variable / table to serialize.
* saved
* saved
** not sure what its used of
** Used internally by recursive function to keep track of progress.
'''OUTPUT:'''<BR>
'''OUTPUT:'''<BR>
This library deliverers the following output/parameters.
This library deliverers the following output/parameters.
Line 58: Line 58:
  bobo = require "session"
  bobo = require "session"
  t = {foo={1,2,3,4}, "one", "two", "bar", "baz"}
  t = {foo={1,2,3,4}, "one", "two", "bar", "baz"}
  stuff = bobo.serialize(1,t)
  stuff = bobo.serialize("t",t)
  print(stuff)
  print(stuff)
  1 = {}
  t = {}
  1[1] = "one"
  t[1] = "one"
  1[2] = "two"
  t[2] = "two"
  1[3] = "bar"
  t[3] = "bar"
  1[4] = "baz"
  t[4] = "baz"
  1["foo"] = {}
  t["foo"] = {}
  1["foo"][1] = 1
  t["foo"][1] = 1
  1["foo"][2] = 2
  t["foo"][2] = 2
  1["foo"][3] = 3
  t["foo"][3] = 3
  1["foo"][4] = 4
  t["foo"][4] = 4


=== save_session ===
=== save_session ===

Revision as of 17:29, 8 July 2008

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