Commit b0917b81 authored by Renato Figueiro Maia's avatar Renato Figueiro Maia
Browse files

[OPENBUS-2184] Adaptação do código para ser compatível também com Lua 5.2

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/core/branches/02_00_00@147336 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 7abd737d
......@@ -24,7 +24,12 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32)
#include <windows.h>
#else
#include <unistd.h>
#include <termios.h>
#endif
#define LPW_LIBNAME "lpw"
......@@ -35,17 +40,84 @@
const char const* OPENBUS_MAIN = "openbus.core.admin.main";
const char const* OPENBUS_PROGNAME = TECMAKE_APPNAME;
#if defined(_WIN32)
static void pusherror (lua_State *L) {
int error = GetLastError();
char buffer[128];
if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, error, 0, buffer, sizeof(buffer)/sizeof(char), NULL))
lua_pushstring(L, buffer);
else
lua_pushfstring(L, "system error %d\n", error);
}
#endif
static int lpw_getpass(lua_State *L)
{
char password[10];
const char *prompt = luaL_optstring(L, 1, "");
char *pass = getpass(prompt);
if (!pass) {
#if defined(_WIN32)
HANDLE hstdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD omode, nmode;
if (hstdin == INVALID_HANDLE_VALUE || !GetConsoleMode(hstdin, &omode)) {
lua_pushnil(L);
pusherror(L);
return 2;
}
nmode = omode;
nmode &= ~ENABLE_ECHO_INPUT;
if (!SetConsoleMode(hstdin, nmode)) {
lua_pushnil(L);
pusherror(L);
return 2;
}
#else
struct termios oflags, nflags;
/* disabling echo */
tcgetattr(fileno(stdin), &oflags);
nflags = oflags;
nflags.c_lflag &= ~ECHO;
nflags.c_lflag |= ECHONL;
if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) {
lua_pushnil(L);
lua_pushstring(L, strerror(errno));
return 2;
}
lua_pushstring(L, pass);
memset(pass, '\0', strlen(pass));
#endif
fputs(prompt, stdout);
if (fgets(password, sizeof(password), stdin) == NULL) {
if (ferror(stdin)) {
return luaL_fileresult(L, 0, "(stdin)");
} else {
lua_pushnil(L);
lua_pushliteral(L, "end of file");
return 2;
}
}
#if defined(_WIN32)
if (!SetConsoleMode(hstdin, omode)) {
lua_pushnil(L);
pusherror(L);
return 2;
}
#else
if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
lua_pushnil(L);
lua_pushstring(L, strerror(errno));
return 2;
}
#endif
lua_pushlstring(L, password, strlen(password)-1);
return 1;
}
......
PROJNAME= busadmin
APPNAME= $(PROJNAME)
OPENBUSINC= ${OPENBUS_HOME}/include
OPENBUSLIB= ${OPENBUS_HOME}/lib
OPENBUSIDL= ${OPENBUS_HOME}/idl/v2_0
SCSIDL= ${SCS_IDL1_2_HOME}/src
OPENBUSIDL= ${OPENBUS_IDL2_0_HOME}/src
SRC= \
launcher.c \
......@@ -16,9 +15,9 @@ IDLSRC= \
$(IDLDIR)/offer_authorization.idl
DEPENDENTIDLSRC= \
$(SCSIDL)/scs.idl \
$(OPENBUSIDL)/core.idl \
$(OPENBUSIDL)/credential.idl \
$(OPENBUSIDL)/scs.idl \
$(OPENBUSIDL)/access_control.idl \
$(OPENBUSIDL)/offer_registry.idl
......@@ -40,17 +39,37 @@ DEFINES= \
TECMAKE_APPNAME=\"$(APPNAME)\"
INCLUDES+= . $(SRCLUADIR) \
$(OPENBUSINC)/luuid \
$(OPENBUSINC)/lce \
$(OPENBUSINC)/luafilesystem \
$(OPENBUSINC)/luavararg \
$(OPENBUSINC)/luastruct \
$(OPENBUSINC)/luasocket2 \
$(OPENBUSINC)/loop \
$(OPENBUSINC)/oil \
$(OPENBUSINC)/scs/lua \
$(OPENBUSINC)/openbus/lua
LDIR+= $(OPENBUSLIB)
$(LCE_HOME)/include \
$(LUUID_HOME)/include \
$(LUAFILESYSTEM_HOME)/include \
$(LUASOCKET_HOME)/include \
$(LUASTRUCT_HOME)/src \
$(LUAVARARG_HOME)/src \
$(LUAINSPECTOR_HOME)/obj/$(TEC_UNAME) \
$(LUATUPLE_HOME)/obj/$(TEC_UNAME) \
$(LUACOROUTINE_HOME)/obj/$(TEC_UNAME) \
$(LUACOTHREAD_HOME)/obj/$(TEC_UNAME) \
$(LOOP_HOME)/obj/$(TEC_UNAME) \
$(LUAIDL_HOME)/obj/$(TEC_UNAME) \
$(OIL_HOME)/obj/$(TEC_UNAME) \
$(SCS_LUA_HOME)/obj/$(TEC_UNAME) \
$(OPENBUS_LUA_HOME)/obj/$(TEC_UNAME)
LDIR+= \
$(LCE_HOME)/lib/$(TEC_UNAME) \
$(LUUID_HOME)/lib/$(TEC_UNAME) \
$(LUAFILESYSTEM_HOME)/lib/$(TEC_UNAME) \
$(LUASOCKET_HOME)/lib/$(TEC_UNAME) \
$(LUASTRUCT_HOME)/lib/$(TEC_UNAME) \
$(LUAVARARG_HOME)/lib/$(TEC_UNAME) \
$(LUAINSPECTOR_HOME)/lib/$(TEC_UNAME) \
$(LUATUPLE_HOME)/lib/$(TEC_UNAME) \
$(LUACOROUTINE_HOME)/lib/$(TEC_UNAME) \
$(LUACOTHREAD_HOME)/lib/$(TEC_UNAME) \
$(LUAIDL_HOME)/lib/$(TEC_UNAME) \
$(LOOP_HOME)/lib/$(TEC_UNAME) \
$(OIL_HOME)/lib/$(TEC_UNAME) \
$(SCS_LUA_HOME)/lib/$(TEC_UNAME) \
$(OPENBUS_LUA_HOME)/lib/$(TEC_UNAME)
ifeq "$(TEC_SYSNAME)" "Linux"
LFLAGS = -Wl,-E
......@@ -65,22 +84,28 @@ ifeq "$(TEC_SYSNAME)" "SunOS"
endif
ifdef USE_STATIC
SLIB:= $(foreach libname, $(LIBS) uuid crypto, $(OPENBUSLIB)/lib$(libname).a)
SLIB:= $(foreach libname, $(LIBS) uuid crypto, ${OPENBUS_HOME}/lib/lib$(libname).a)
ifeq "$(TEC_SYSNAME)" "SunOS"
LIBS:= rt nsl socket resolv
else
LIBS:=
endif
else
ifneq "$(TEC_SYSNAME)" "Darwin"
LIBS+= uuid
ifneq "$(TEC_SYSNAME)" "Win32"
ifneq "$(TEC_SYSNAME)" "Darwin"
LIBS+= uuid
endif
endif
endif
LIBS+= dl
ifeq "$(TEC_SYSNAME)" "Win32"
APPTYPE= console
else
LIBS+= dl
endif
$(LUADIR)/openbus/core/admin/parsed.lua: $(IDL2LUA) $(IDLSRC) $(DEPENDENTIDLSRC)
$(OILBIN) $(IDL2LUA) -I $(OPENBUSIDL) -o $@ $(IDLSRC)
$(OILBIN) $(IDL2LUA) -I $(SCSIDL) -I $(OPENBUSIDL) -o $@ $(IDLSRC)
$(PRELOAD_DIR)/coreadmin.c $(PRELOAD_DIR)/coreadmin.h: $(LUAPRELOADER) $(LUASRC)
$(LOOPBIN) $(LUAPRELOADER) -l "$(LUADIR)/?.lua" \
......
PROJNAME= busservices
APPNAME= $(PROJNAME)
OPENBUSINC= ${OPENBUS_HOME}/include
OPENBUSLIB= ${OPENBUS_HOME}/lib
OPENBUSIDL= ${OPENBUS_HOME}/idl/v2_0
SCSIDL= ${SCS_IDL1_2_HOME}/src
OPENBUSIDL= ${OPENBUS_IDL2_0_HOME}/src
SRC= \
launcher.c \
......@@ -15,10 +14,10 @@ IDLSRC= \
$(IDLDIR)/access_management.idl \
$(IDLDIR)/offer_authorization.idl
DEPENDENTIDLSRC=\
DEPENDENTIDLSRC= \
$(SCSIDL)/scs.idl \
$(OPENBUSIDL)/core.idl \
$(OPENBUSIDL)/credential.idl \
$(OPENBUSIDL)/scs.idl \
$(OPENBUSIDL)/access_control.idl \
$(OPENBUSIDL)/offer_registry.idl
......@@ -39,25 +38,44 @@ LUASRC= \
include ${OIL_HOME}/openbus/base.mak
LIBS:= lce luuid lfs lualdap luavararg luastruct luasocket loop luatuple \
LIBS:= lce luuid lfs luavararg luastruct luasocket loop luatuple \
luacoroutine luacothread luainspector luaidl oil luascs luaopenbus
DEFINES= \
TECMAKE_APPNAME=\"$(APPNAME)\"
INCLUDES+= . $(SRCLUADIR) \
$(OPENBUSINC)/luuid \
$(OPENBUSINC)/lce \
$(OPENBUSINC)/luafilesystem \
$(OPENBUSINC)/lualdap-1.1.0 \
$(OPENBUSINC)/luavararg \
$(OPENBUSINC)/luastruct \
$(OPENBUSINC)/luasocket2 \
$(OPENBUSINC)/loop \
$(OPENBUSINC)/oil \
$(OPENBUSINC)/scs/lua \
$(OPENBUSINC)/openbus/lua
LDIR+= $(OPENBUSLIB)
$(LCE_HOME)/include \
$(LUUID_HOME)/include \
$(LUAFILESYSTEM_HOME)/include \
$(LUASOCKET_HOME)/include \
$(LUASTRUCT_HOME)/src \
$(LUAVARARG_HOME)/src \
$(LUAINSPECTOR_HOME)/obj/$(TEC_UNAME) \
$(LUATUPLE_HOME)/obj/$(TEC_UNAME) \
$(LUACOROUTINE_HOME)/obj/$(TEC_UNAME) \
$(LUACOTHREAD_HOME)/obj/$(TEC_UNAME) \
$(LOOP_HOME)/obj/$(TEC_UNAME) \
$(LUAIDL_HOME)/obj/$(TEC_UNAME) \
$(OIL_HOME)/obj/$(TEC_UNAME) \
$(SCS_LUA_HOME)/obj/$(TEC_UNAME) \
$(OPENBUS_LUA_HOME)/obj/$(TEC_UNAME)
LDIR+= \
$(LCE_HOME)/lib/$(TEC_UNAME) \
$(LUUID_HOME)/lib/$(TEC_UNAME) \
$(LUAFILESYSTEM_HOME)/lib/$(TEC_UNAME) \
$(LUASOCKET_HOME)/lib/$(TEC_UNAME) \
$(LUASTRUCT_HOME)/lib/$(TEC_UNAME) \
$(LUAVARARG_HOME)/lib/$(TEC_UNAME) \
$(LUAINSPECTOR_HOME)/lib/$(TEC_UNAME) \
$(LUATUPLE_HOME)/lib/$(TEC_UNAME) \
$(LUACOROUTINE_HOME)/lib/$(TEC_UNAME) \
$(LUACOTHREAD_HOME)/lib/$(TEC_UNAME) \
$(LUAIDL_HOME)/lib/$(TEC_UNAME) \
$(LOOP_HOME)/lib/$(TEC_UNAME) \
$(OIL_HOME)/lib/$(TEC_UNAME) \
$(SCS_LUA_HOME)/lib/$(TEC_UNAME) \
$(OPENBUS_LUA_HOME)/lib/$(TEC_UNAME)
ifeq "$(TEC_SYSNAME)" "Linux"
LFLAGS = -Wl,-E
......@@ -71,29 +89,41 @@ ifeq "$(TEC_SYSNAME)" "SunOS"
LFLAGS= $(CFLAGS) -xildoff
endif
ifneq "$(TEC_SYSNAME)" "Win32"
INCLUDES+= $(LUALDAP_HOME)/include
LDIR+= $(LUALDAP_HOME)/lib/$(TEC_UNAME)
LIBS+= lualdap
endif
ifdef USE_STATIC
SLIB:= $(foreach libname, $(LIBS) uuid ldap lber ssl crypto, $(OPENBUSLIB)/lib$(libname).a)
SLIB:= $(foreach libname, $(LIBS) uuid ldap lber ssl crypto, ${OPENBUS_HOME}/lib/lib$(libname).a)
ifeq "$(TEC_SYSNAME)" "SunOS"
LIBS:= rt nsl socket resolv
else
LIBS:=
endif
else
ifneq "$(TEC_SYSNAME)" "Darwin"
LIBS+= uuid
ifneq "$(TEC_SYSNAME)" "Win32"
ifneq "$(TEC_SYSNAME)" "Darwin"
LIBS+= uuid
endif
endif
endif
LIBS+= dl
ifeq "$(TEC_SYSNAME)" "Win32"
APPTYPE= console
else
LIBS+= dl
endif
$(LUADIR)/openbus/core/admin/parsed.lua: $(IDL2LUA) $(IDLSRC) $(DEPENDENTIDLSRC)
$(OILBIN) $(IDL2LUA) -I $(OPENBUSIDL) -o $@ $(IDLSRC)
$(OILBIN) $(IDL2LUA) -I $(SCSIDL) -I $(OPENBUSIDL) -o $@ $(IDLSRC)
$(PRELOAD_DIR)/coreservices.c $(PRELOAD_DIR)/coreservices.h: $(LUAPRELOADER) $(LUASRC)
$(LOOPBIN) $(LUAPRELOADER) -l "$(LUADIR)/?.lua" \
-d $(PRELOAD_DIR) \
-h coreservices.h \
-o coreservices.c \
$(LUASRC)
-d $(PRELOAD_DIR) \
-h coreservices.h \
-o coreservices.c \
$(LUASRC)
coreservlibs.c: $(PRELOAD_DIR)/coreservices.h
......@@ -6,7 +6,9 @@
#include "luuid.h"
#include "lce.h"
#include "lfs.h"
#ifndef _WIN32
#include "lualdap.h"
#endif
#include "luavararg.h"
#include "luastruct.h"
#include "luasocket.h"
......@@ -21,6 +23,7 @@
#include "luaopenbus.h"
#include "coreservices.h"
const char const* OPENBUS_MAIN = "openbus.core.services.main";
const char const* OPENBUS_PROGNAME = TECMAKE_APPNAME;
......@@ -34,7 +37,9 @@ void luapreload_extralibraries(lua_State *L)
#endif
lua_pushcfunction(L,luaopen_uuid);lua_setfield(L,-2,"uuid");
lua_pushcfunction(L,luaopen_lfs);lua_setfield(L,-2,"lfs");
#ifndef _WIN32
lua_pushcfunction(L,luaopen_lualdap);lua_setfield(L,-2,"lualdap");
#endif
lua_pushcfunction(L,luaopen_vararg);lua_setfield(L,-2,"vararg");
lua_pushcfunction(L,luaopen_struct);lua_setfield(L,-2,"struct");
lua_pushcfunction(L,luaopen_socket_core);lua_setfield(L,-2,"socket.core");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment