45#ifndef BALUA_ENABLE_LEGACY_PEM_KEY_API
46#define BALUA_ENABLE_LEGACY_PEM_KEY_API (!SHARKSSL_PSA_CONSUMER)
48#if SHARKSSL_PSA_CONSUMER && BALUA_ENABLE_LEGACY_PEM_KEY_API
49#error Legacy PEM private-key bindings require the native SharkSSL backend
67#include "DoubleList.h"
99#define BALUA_VERSION BASLIB_VER_NO
101#define BALUA_VERSION 1
103#define BA_ENV_IX lua_upvalueindex(1)
104#define BA_TABLE "_BA"
115#define balua_create(p) _balua_create(p, BALUA_VERSION)
117#define baluaENV_getmetatable(L,mtId) lua_rawgeti(L, BA_ENV_IX, mtId)
118#define baluaENV_checkudata(L,ud,mtid) _baluaENV_isudtype(L,ud,mtid,TRUE)
119#define baluaENV_isudtype(L,ud,mtid) _baluaENV_isudtype(L,ud,mtid,FALSE)
120#define balua_pushbatab(L) lua_getfield(L,LUA_REGISTRYINDEX,BA_TABLE)
122#define balua_newlib(L,l) \
123 (luaL_newlibtable(L,l), balua_pushbatab(L), luaL_setfuncs(L,l,1))
124#define baluaENV_getmutex(L) baluaENV_getparam(L)->mutex
129#define balua_getmutex(L) balua_getparam(L)->mutex
136#define BA_LUA_DECLARE_MUTEX(name, L) ThreadMutex* name = baluaENV_getmutex(L)
141#define balua_releasemutex(m) if(m) ThreadMutex_release(m)
145#define balua_setmutex(m) if(m) ThreadMutex_set(m)
148#define balua_check(x,y) x
150#define balua_check(x,y) baAssert(y == x)
157#define dmpstk1(L,x) \
158 HttpTrace_printf(0,"%d: %s %p\n", __LINE__,lua_typename(L,lua_type(L,(x))), \
160#define dmpstk2(L,x) { \
161 int ix=lua_absindex(L,x); \
162 HttpTrace_printf(0,"%4d: %2d %s\n",__LINE__,ix,luaL_tolstring(L,x,0)); \
166 HttpTrace_printf(0,"%d: top %d\n",__LINE__,lua_gettop(L))
167#define dmpTab(L, ix) do { \
168 HttpTrace_printf(0,"%d: TAB %d %p\n", \
169 __LINE__, lua_absindex(L,ix), lua_topointer(L,ix)); \
171 while(lua_next(L, ix < 0 ? ix-1: ix) != 0) \
173 HttpTrace_printf(0,"\t%s = %s\n", \
174 luaL_tolstring(L,-3,0), \
175 luaL_tolstring(L,-1,0)); \
213BA_API
void* baLMallocL(lua_State* L,
size_t size,
const char* file,
int line);
214#define baLMalloc(L,size) baLMallocL(L,size,__FILE__,__LINE__)
215BA_API
void* baLReallocL(lua_State* L,
void* p,
size_t size,
216 const char* file,
int line);
217#define baLRealloc(L,p,size) baLReallocL(L,p,size,__FILE__,__LINE__)
218BA_API
char* baLStrdupL(lua_State* L,
const char* str,
219 const char* file,
int line);
220#define baLStrdup(L,str) baLStrdupL(L,str,__FILE__,__LINE__)
281 lua_State* L,
U32 noOfLoginTrackerNodes,
U32 maxNumberOfLogins,
289BA_API
int balua_typeerror(lua_State *L,
int narg,
const char *tname);
290#define balua_optboolean(L,narg,def) luaL_opt(L, balua_checkboolean, narg, def)
291BA_API
int balua_checkboolean(lua_State *L,
int narg);
292BA_API
int baluaENV_newmetatable(lua_State *L,
int mtid,
int inheritmtid);
293BA_API
void baluaENV_register(
294 lua_State *L,
int mtid,
int inheritmtid,
const luaL_Reg* lib);
295BA_API
void* baluaENV_newuserdata(lua_State *L,
int mtid,
size_t size);
296BA_API
void* _baluaENV_isudtype(lua_State* L,
int udIx,
int mtid,
int check);
297BA_API
HttpCommand* baluaENV_checkcmd(lua_State* L,
int ix);
303BA_API
BaLua_param* baluaENV_getparam(lua_State* L);
304BA_API
int balua_errorhandler(lua_State* L);
305BA_API
void balua_manageerr(
306 lua_State* L,
const char* ewhere,
const char* emsg,
HttpCommand* cmd);
307BA_API
void balua_resumeerr(lua_State* L,
const char* ewhere);
320 lua_State *L,
const char *filename,
struct IoIntf* io,
int envix);
389 lua_State* L,
struct IoIntf* io,
const char* filename);
391#define balua_loadconfig(L, io, filename) \
392 balua_loadconfigExt(L, io, filename, 0)
409 lua_State* L,
struct IoIntf* io,
const char* filename,
int nresults);
412BA_API
IoIntf* baluaENV_checkIoIntf(lua_State *L,
int udIx);
430 lua_State* L,
const char* name,
struct IoIntf* newio);
439BA_API
HttpDir* baluaENV_toDir(lua_State* L,
int ix);
440BA_API
HttpDir* baluaENV_createDir(lua_State* L,
int mtId,
size_t dirSize);
441BA_API
const char* balua_getStringField(
442 lua_State *L,
int ix,
const char *k,
const char *def);
443BA_API lua_Integer balua_getIntField(
444 lua_State *L,
int ix,
const char *k, lua_Integer defVal);
445BA_API
BaBool balua_getBoolField(
446 lua_State *L,
int ix,
const char *k,
BaBool defVal);
447BA_API
int balua_getTabField(lua_State *L,
int ix,
const char *k);
448BA_API
const char* balua_checkStringField(lua_State *L,
int ix,
const char *k);
449BA_API lua_Integer balua_checkIntField(lua_State *L,
int ix,
const char *k);
453BAI_FUNC
void balua_setEncodedField(
454 lua_State *L,
int idx,
const U8 k[],
size_t kz);
455BAI_FUNC
void balua_setEncodedFunc(
456 lua_State *L, lua_CFunction f,
const U8 k[],
size_t kz,
int nup);
458#if BA_ENABLE_SHARKSSL
461 int (*pushCertificate)(lua_State *L,
SoDispCon* con);
462 int (*pushCipher)(lua_State *L,
SoDispCon* con);
463 void (*unlockSharkSSL)(lua_State *L,
struct SharkSsl* super);
464 struct SharkSsl* (*lockSharkSSL)(
465 lua_State *L,
int tabIx,SharkSsl_Role role,SharkSsl* lockedShark);
468extern const LSharkSSLFuncs* lSharkSSLFuncs;
470extern const void* lSharkSSLFuncs;
473enum BaUserDataTypes {
495 BA_TAUTHENTICATORINTF,
526 int authenticatorRef;
532BA_API
int LHttpResRdr_loadLsp(
533 lua_State* L,
IoIntf* io,
const char* pathname,
IoStat* st);
539BA_API
void luaopen_ba_redirector(lua_State *L);
540BA_API
void ba_ldbgmon(
541 lua_State* L,
void (*exitCb)(
void*,
BaBool),
void* exitCbData);
542BA_API
void balua_revcon(lua_State* L);
543BA_API
void balua_mallinfo(lua_State* L);
BA_API void balua_luaio(lua_State *L)
Install the LuaIo Lua bindings.
BA_API int balua_usertracker_create(lua_State *L, U32 noOfLoginTrackerNodes, U32 maxNumberOfLogins, BaTime banTime)
Install Lua bindings for the default login tracker.
BA_API void * baLRealloc(lua_State *L, void *p, size_t size)
Resize application memory, retrying after a full Lua GC on allocation failure.
BA_API void balua_close(lua_State *L)
Close the BAS Lua VM, run finalizers, and free its copied parameters.
BA_API void balua_ubjson(lua_State *L)
Install the UBJSON Lua API.
BA_API void balua_installZIO(lua_State *L, const char *name, struct ZipReader *reader)
Install a Zip I/O interface into the Lua environment.
BA_API struct IoIntf ** balua_createiointf(lua_State *L)
Push a Lua I/O userdata whose underlying interface is owned by Lua.
struct LHttpDir LHttpDir
LHttpDir is the HttpDir instance used by Lua bindings and can be used by advanced Lua bindings creati...
BA_API int baCheckZipSignature(const U8 *pubKey, U32 fileSize, struct CspReader *reader)
Verify the signature of a ZIP file using a public key.
BA_API BaLua_param * balua_getparam(lua_State *L)
Get the VM's stored parameter copy without changing the stack.
BA_API int balua_loadconfigExt(lua_State *L, struct IoIntf *io, const char *filename, int nresults)
Load a Lua script and run the script at startup.
BA_API lua_State * _balua_create(const BaLua_param *p, int version)
Create a BAS Lua VM.
BA_API lua_State * balua_getmainthread(lua_State *L)
Get the main state without changing the stack.
BA_API int balua_loadfile(lua_State *L, const char *filename, struct IoIntf *io, int envix)
Compile a Lua source or bytecode file without executing it.
BA_API void balua_getuservalue(lua_State *L, int index)
Pushes onto the stack the first user value associated with the full userdata at the given index.
BA_API IoIntf * balua_iointf(lua_State *L, const char *name, struct IoIntf *newio)
Register an IoIntf instance with the Lua VM.
BA_API void * baLMalloc(lua_State *L, size_t size)
Allocate application memory, retrying after a full Lua GC on allocation failure.
BA_API int balua_loadconfig(lua_State *L, struct IoIntf *io, const char *filename)
Load a Lua script and run the script at startup.
BA_API char * baLStrdup(lua_State *L, const char *str)
Duplicate a string using baLMalloc, including its full-GC retry on failure.
int(* HttpDir_Service)(struct HttpDir *o, const char *relPath, HttpCommand *cmd)
The HttpDir service callback function.
Definition: HttpServer.h:2794
uint16_t U16
Unsigned 16-bit integer.
Definition: GenPrimT.h:94
S64 BaTime
An arithmetic type representing calendar time with epoch of 1970-01-01 00:00:00 UTC,...
Definition: GenPrimT.h:106
uint32_t U32
Unsigned 32-bit integer.
Definition: GenPrimT.h:96
uint8_t U8
Unsigned 8-bit integer.
Definition: GenPrimT.h:92
U8 BaBool
Boolean stored in an unsigned byte; FALSE is zero and TRUE is one.
Definition: GenPrimT.h:121
BA_API int balua_wkRefIx(lua_State *L, int index)
Create a weak reference without popping the referenced value.
BA_API void balua_wkUnref(lua_State *L, int reference)
Releases the reference ref from the weak table.
BA_API int balua_wkRef(lua_State *L)
Creates and returns a reference in the weak table, for the object on the top of the stack (and pops t...
BA_API void balua_wkPush(lua_State *L, int reference)
Pushes the value associated with the key 'index' on top of the stack.
Startup and runtime parameters for a BAS Lua VM.
Definition: balua.h:191
struct BaTimer * timer
Timer bindings activated if not NULL.
Definition: balua.h:194
struct LoginTracker * tracker
Optional login tracker.
Definition: balua.h:197
const U8 * zipBinPwd
Borrowed password bytes, or NULL for no default ZIP password.
Definition: balua.h:200
ThreadMutex * mutex
Derived from server with BA_ENABLE_SERVER=1; supplied directly with BA_ENABLE_SERVER=0.
Definition: balua.h:196
const U8 * zipPubKey
Borrowed SharkSSL ECC public key, or NULL to disable ZIP signature checks.
Definition: balua.h:199
BaBool pwdRequired
Nonzero requires encryption on all files in ZIP I/O using this policy.
Definition: balua.h:202
lua_State * L
Input NULL with BA_ENABLE_SERVER=1; existing state with BA_ENABLE_SERVER=0.
Definition: balua.h:192
IoIntf * vmio
Required VM I/O interface used for Lua resources.
Definition: balua.h:195
HttpServer * server
Borrowed server, or NULL when server bindings are not needed.
Definition: balua.h:193
U16 zipBinPwdLen
Password byte count, matching zipBinPwd.
Definition: balua.h:201
int errHndRef
Initialize to zero; internal ba.seterrh reference.
Definition: balua.h:198
Timer manager used for one-shot and periodic callbacks.
Definition: BaTimer.h:67
Abstract interface class for reading the "dat" file generated by HttpLink.
Definition: CspRunTm.h:126
The HttpCommand class is a container class for the HttpRequest and HttpResponse command pair.
Definition: HttpServer.h:2179
An instance of the HttpDir class, which is a collection of zero or more resources,...
Definition: HttpServer.h:2824
Route and process HTTP requests using a borrowed dispatcher.
Definition: HttpServer.h:3463
The IoIntf class specifies an abstract file API, implementations include ZipIo, DiskIo,...
Definition: IoIntf.h:482
Resource information.
Definition: IoIntf.h:170
LHttpDir is the HttpDir instance used by Lua bindings and can be used by advanced Lua bindings creati...
Definition: balua.h:520
The LoginTracker class is an optional security enhancement that can be installed in an instance of on...
Definition: AuthenticatedUser.h:892
Contains information about the physical socket connection.
Definition: SoDispCon.h:120
A mutual exclusion class.
Definition: ThreadLib.h:196
Abstract interface class for reading a ZipFile.
Definition: ZipFileIterator.h:74