C/C++ Reference
balua.h
00001 /*
00002  *     ____             _________                __                _
00003  *    / __ \___  ____ _/ /_  __(_)___ ___  ___  / /   ____  ____ _(_)____
00004  *   / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ /   / __ \/ __ `/ / ___/
00005  *  / _, _/  __/ /_/ / / / / / / / / / / /  __/ /___/ /_/ / /_/ / / /__
00006  * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
00007  *                                                       /____/
00008  *
00009  *                  Barracuda Embedded Web-Server
00010  *
00011  ****************************************************************************
00012  *                            HEADER
00013  *
00014  *   $Id$
00015  *
00016  *   COPYRIGHT:  Real Time Logic LLC, 2008 - 2011
00017  *               http://www.realtimelogic.com
00018  *
00019  *   The copyright to the program herein is the property of
00020  *   Real Time Logic. The program may be used or copied only
00021  *   with the written permission from Real Time Logic LLC or
00022  *   in accordance with the terms and conditions stipulated in
00023  *   the agreement under which the program has been supplied.
00024  ****************************************************************************
00025  *
00026  *
00027  */
00028 
00029  
00030 #ifndef _balua_h
00031 #define _balua_h
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 #include "lua.h"
00038 #include "lauxlib.h"
00039 
00040 #ifdef __cplusplus
00041 }
00042 #endif 
00043 
00044 #include "AuthenticatedUser.h"
00045 #include "ThreadLib.h"
00046 
00066 #ifdef __cplusplus
00067 extern "C" {
00068 #endif
00069 
00070 #define BALUA_VERSION 20
00071 #define BA_ENV_IX lua_upvalueindex(1)
00072 #define BA_TABLE "_BA_"
00073 #define BA_WKTABLE "_BAWK"
00074 #define balua_create(p) _balua_create(p, BALUA_VERSION)
00075 #define balua_optboolean(L,narg,def) luaL_opt(L, balua_checkboolean, narg, def)
00076 #define baluaENV_getmetatable(L,mtId) lua_rawgeti(L, BA_ENV_IX, mtId)
00077 #define baluaENV_checkudata(L,ud,mtid) _baluaENV_isudtype(L,ud,mtid,TRUE)
00078 #define baluaENV_isudtype(L,ud,mtid) _baluaENV_isudtype(L,ud,mtid,FALSE)
00079 #define balua_pushbatab(L) lua_getfield(L,LUA_REGISTRYINDEX,BA_TABLE)
00080 #define balua_pushwktab(L) lua_getfield(L,LUA_REGISTRYINDEX,BA_WKTABLE)
00081 #define balua_newlib(L,l) \
00082   (luaL_newlibtable(L,l), balua_pushbatab(L), luaL_setfuncs(L,l,1))
00083 #define baluaENV_getmutex(L) baluaENV_getparam(L)->mutex
00084 
00085 #define GET_BAMUTEX ThreadMutex* m = baluaENV_getmutex(L)
00086 #define balua_releasemutex(m) if(m) ThreadMutex_release(m)
00087 #define balua_setmutex(m) if(m) ThreadMutex_set(m)
00088 
00089 #ifdef NDEBUG
00090 #define balua_check(x,y) x
00091 #else
00092 #define balua_check(x,y) baAssert(y == x)
00093 #endif
00094 
00095 
00096 #define dmpstk1(L,x) \
00097   fprintf(stderr," %s %p : %d\n", lua_typename(L,lua_type(L,(x))), \
00098          lua_topointer(L,x),__LINE__)
00099 
00100 struct BaTimer;
00101 struct LoginTracker;
00102 
00105 typedef struct
00106 {
00107       lua_State* L; /* The lua universe */
00108       HttpServer* server; /* Pointer to server for this vm */
00109       struct BaTimer* timer; /* Timer bindings activated if not NULL. */
00110       IoIntf* vmio; /* The required VM (Lua) IO */
00111       ThreadMutex* mutex; /*The mutex used by the server's socket dispatcher*/
00112       struct LoginTracker* tracker; /* The optional tracker */
00113       int errHndRef; /* Internal: The ba.seterrh(func) ref */
00114 } BaLua_param;
00115 
00119 BA_API lua_State* _balua_create(const BaLua_param* p, int version);
00120 
00124 BA_API int balua_usertracker_create(
00125    lua_State* L, U32 noOfLoginTrackerNodes, U32 maxNumberOfLogins,
00126    BaTime banTime);
00127 
00128 
00129 BA_API const char* balua_baerrorstr(int ecode);
00130 BA_API lua_State* balua_getmainthread(lua_State* L);
00131 BA_API int balua_typeerror(lua_State *L, int narg, const char *tname);
00132 BA_API int balua_checkboolean(lua_State *L, int narg);
00133 BA_API int baluaENV_newmetatable(lua_State *L, int mtid, int inheritmtid);
00134 BA_API void baluaENV_register(
00135    lua_State *L, int mtid, int inheritmtid, const luaL_Reg* lib);
00136 BA_API void* baluaENV_newuserdata(lua_State *L, int mtid, size_t size);
00137 BA_API void* _baluaENV_isudtype(lua_State* L, int udIx, int mtid, int check);
00138 BA_API HttpCommand* baluaENV_checkcmd(lua_State* L, int ix);
00139 BA_API BaLua_param* balua_getparam(lua_State* L);
00140 BA_API BaLua_param* baluaENV_getparam(lua_State* L);
00141 BA_API int balua_errorhandler(lua_State* L);
00142 BA_API void balua_manageerr(
00143    lua_State* L,const char* ewhere,const char* emsg,HttpCommand* cmd);
00144 BA_API void balua_resumeerr(lua_State* L,const char* ewhere);
00145 BA_API int balua_loadconfig(lua_State* L,struct IoIntf* io,const char* file);
00146 BA_API IoIntf* baluaENV_checkIoIntf(lua_State *L, int udIx);
00147 BA_API IoIntf* balua_iointf(
00148    lua_State* L, const char* name, struct IoIntf* newio);
00149 BA_API struct IoIntf** balua_createiointf(lua_State* L);
00150 BA_API HttpDir* baluaENV_toDir(lua_State* L, int ix);
00151 BA_API HttpDir* baluaENV_createDir(lua_State* L,int mtId,size_t dirSize);
00152 
00153 
00154 /* Internally used by the xrc code */
00155 
00156 typedef int (*PushCertificate)(lua_State *L, SoDispCon* con);
00157 
00158 enum BaUserDataTypesG {
00159    /* Note must be larger than src/plugins/lua/ext/lbaint.h BaUserDataTypes */
00160    BA_CERTFUNC=200 /* pushCertificate */
00161 };
00162 
00163 
00164 #ifdef __cplusplus
00165 }
00166 #endif
00167 
00168  /* LSP Plugin */
00170 
00171 #endif