From 233914019c9cbc7beb30cd12eea2e3993510f2e7 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Wed, 20 Nov 2013 07:37:04 +0000 Subject: [PATCH] Incluindo funcoes extras do hllapi na classe base --- src/plugins/hllapi/Makefile.in | 37 +++++++++++++++++++++++++------------ src/plugins/hllapi/calls.c | 599 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/plugins/hllapi/calls.cc | 329 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/plugins/hllapi/hllapi.c | 6 +++--- src/plugins/hllapi/hllapi.cbp | 11 ++++------- src/plugins/hllapi/pluginmain.c | 25 ++++++++++++++----------- src/plugins/hllapi/testprogram.c | 3 +-- 7 files changed, 376 insertions(+), 634 deletions(-) delete mode 100644 src/plugins/hllapi/calls.c create mode 100644 src/plugins/hllapi/calls.cc diff --git a/src/plugins/hllapi/Makefile.in b/src/plugins/hllapi/Makefile.in index 396a032..8e9fcef 100644 --- a/src/plugins/hllapi/Makefile.in +++ b/src/plugins/hllapi/Makefile.in @@ -31,7 +31,9 @@ MODULE_NAME=hllapi DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile PLUGIN_SRC=pluginmain.c -HLLAPI_SRC=hllapi.c calls.c remote.c +HLLAPI_SRC=hllapi.c calls.c + +CLASSLIBDIR=../../classlib #---[ Paths ]------------------------------------------------------------------ @@ -48,8 +50,8 @@ OBJEXT = o #---[ Tools ]------------------------------------------------------------------ MKDIR=@MKDIR_P@ -CC=@CC@ -LD=@CC@ +CC=@CXX@ +LD=@CXX@ MSGCAT=@MSGCAT@ XGETTEXT=@XGETTEXT@ @@ -81,15 +83,26 @@ ifeq ($(LIB3270_MODE),Default) PW3270_CFLAGS ?= `pkg-config --cflags pw3270 lib3270` endif - GTK_CFLAGS ?= @GTK_CFLAGS@ @GTKMAC_CFLAGS@ GTK_LIBS ?= @GTK_LIBS@ @GTKMAC_LIBS@ +include $(CLASSLIBDIR)/class.mak + +$(OBJDBG)/%.o: %.cc $(DEPENDS) + @echo " CC `basename $@`" + @$(MKDIR) `dirname $@` + @$(CXX) $(CFLAGS) $(DEBUG_CFLAGS) $(LIB3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< + $(OBJDBG)/%.o: %.c $(DEPENDS) @echo " CC `basename $@`" @$(MKDIR) `dirname $@` @$(CC) $(CFLAGS) $(DEBUG_CFLAGS) $(LIB3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< +$(OBJRLS)/%.o: %.cc $(DEPENDS) + @echo " CC `basename $@`" + @$(MKDIR) `dirname $@` + @$(CXX) $(CFLAGS) $(LIB3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< + $(OBJRLS)/%.o: %.c $(DEPENDS) @echo " CC `basename $@`" @$(MKDIR) `dirname $@` @@ -119,24 +132,24 @@ $(BINDBG)/plugins/$(MODULE_NAME)@DLLEXT@: $(foreach SRC, $(basename $(PLUGIN_SRC @$(MKDIR) `dirname $@` @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) -o $@ $^ $(LIBS) $(PW3270_LIBS) $(GTK_LIBS) -$(BINDBG)/libhllapi@DLLEXT@: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJDBG)/$(SRC).o) +$(BINDBG)/libhllapi@DLLEXT@: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJDBG)/$(SRC).o) $(CLASS_DEBUG_OBJECTS) @echo " CCLD `basename $@`" @$(MKDIR) `dirname $@` - @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) @LDLIBFLAGS@ -o $@ $^ $(LIBS) + @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) @LDLIBFLAGS@ -o $@ $^ $(LIBS) $(CLASS_LIBS) #---[ Misc targets ]----------------------------------------------------------- -$(BINDBG)/testprogram@EXEEXT@: testprogram.c $(BINDBG)/libhllapi@DLLEXT@ +$(BINDBG)/testprogram@EXEEXT@: $(OBJDBG)/testprogram.o $(BINDBG)/libhllapi@DLLEXT@ @echo " CCLD `basename $@`" @$(MKDIR) `dirname $@` - @$(CC) $(CFLAGS) $(PW3270_CFLAGS) -L$(BINDBG) $(DEBUG_CFLAGS) -lhllapi -o $@ testprogram.c + @$(CXX) $(CFLAGS) $(PW3270_CFLAGS) -L$(BINDBG) $(DEBUG_CFLAGS) -lhllapi -o $@ $(OBJDBG)/testprogram.o test: $(BINDBG)/testprogram@EXEEXT@ - -run: $(BINDBG)/testprogram@EXEEXT@ + +run: $(BINDBG)/testprogram@EXEEXT@ @cd $(BINDBG) ; ./testprogram@EXEEXT@ - -install: $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ + +install: $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ @$(MKDIR) $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins @$(INSTALL_PROGRAM) $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins diff --git a/src/plugins/hllapi/calls.c b/src/plugins/hllapi/calls.c deleted file mode 100644 index ad98198..0000000 --- a/src/plugins/hllapi/calls.c +++ /dev/null @@ -1,599 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA, 02111-1307, USA - * - * Este programa está nomeado como calls.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include "client.h" - - #undef trace - #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } } - -/*--[ Globals ]--------------------------------------------------------------------------------------*/ - - HMODULE hModule = NULL; - void * hSession = NULL; - - - static void * (*session_new)(const char *model) = NULL; - static void (*session_free)(void *h) = NULL; - static const char * (*get_revision)(void) = NULL; - static int (*host_connect)(void *h,const char *n, int wait) = NULL; - static int (*host_is_connected)(void *h) = NULL; - static int (*wait_for_ready)(void *h, int seconds) = NULL; - static void (*host_disconnect)(void *h) = NULL; - static int (*script_sleep)(void *h, int seconds) = NULL; - static LIB3270_MESSAGE (*get_message)(void *h) = NULL; - static char * (*get_text)(void *h, int row, int col, int len) = NULL; - static char * (*get_text_at_offset)(void *h, int offset, int len) = NULL; - - static void * (*release_memory)(void *p) = NULL; - static int (*action_enter)(void *h) = NULL; - static int (*set_text_at)(void *h, int row, int col, const unsigned char *str) = NULL; - static int (*cmp_text_at)(void *h, int row, int col, const char *text) = NULL; - static int (*pfkey)(void *hSession, int key) = NULL; - static int (*pakey)(void *hSession, int key) = NULL; - static int (*getcursor)(void *hSession) = NULL; - static int (*setcursor)(void *hSession, int baddr) = NULL; - static int (*emulate_input)(void *hSession, const char *s, int len, int pasting) = NULL; - static int (*erase_eof)(void *hSession) = NULL; - static int (*do_print)(void *h) = NULL; - - static const struct _entry_point - { - void **call; - void * pipe; - const char * name; - } entry_point[] = - { - { (void **) &session_new, (void *) hllapi_pipe_init, "lib3270_session_new" }, - { (void **) &session_free, (void *) hllapi_pipe_deinit, "lib3270_session_free" }, - { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, - { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, - { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" }, - { (void **) &host_is_connected, (void *) hllapi_pipe_is_connected, "lib3270_in_tn3270e" }, - { (void **) &wait_for_ready, (void *) hllapi_pipe_wait_for_ready, "lib3270_wait_for_ready" }, - { (void **) &script_sleep, (void *) hllapi_pipe_sleep, "lib3270_wait" }, - { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, - { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, - { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, - { (void **) &action_enter, (void *) hllapi_pipe_enter, "lib3270_enter" }, - { (void **) &set_text_at, (void *) hllapi_pipe_set_text_at, "lib3270_set_string_at" }, - { (void **) &cmp_text_at, (void *) hllapi_pipe_cmp_text_at, "lib3270_cmp_text_at" }, - { (void **) &pfkey, (void *) hllapi_pipe_pfkey, "lib3270_pfkey" }, - { (void **) &pakey, (void *) hllapi_pipe_pakey, "lib3270_pakey" }, - { (void **) &setcursor, (void *) hllapi_pipe_setcursor, "lib3270_set_cursor_address" }, - { (void **) &getcursor, (void *) hllapi_pipe_getcursor, "lib3270_get_cursor_address" }, - { (void **) &get_text_at_offset, (void *) hllapi_pipe_get_text, "lib3270_get_text" }, - { (void **) &emulate_input, (void *) hllapi_pipe_emulate_input, "lib3270_emulate_input" }, - { (void **) &erase_eof, (void *) hllapi_pipe_erase_eof, "lib3270_eraseeof" }, - { (void **) &do_print, (void *) hllapi_pipe_print, "lib3270_print" }, - - { NULL, NULL, NULL } - }; - -// http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx -#ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS - #define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000 -#endif // LOAD_LIBRARY_SEARCH_DEFAULT_DIRS - -#ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR - #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100 -#endif // LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR - -/*--[ Implement ]------------------------------------------------------------------------------------*/ - - static DWORD load_remote(void) - { - // Get pointers to the pipe based calls - int f; - - trace("%s: Loading pipe based calls",__FUNCTION__); - for(f=0;entry_point[f].name;f++) - *entry_point[f].call = entry_point[f].pipe; - - return HLLAPI_STATUS_SUCCESS; - } - - static DWORD start_session(void) - { - char buffer[80]; - char appName[4096]; - HKEY hKey = 0; - unsigned long datalen = 4096; - DWORD ret; - STARTUPINFO si; - PROCESS_INFORMATION pi; - - // Get application path - *appName = 0; - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) - { - unsigned long datatype; // #defined in winnt.h (predefined types 0-11) - if(RegQueryValueExA(hKey,"appName",NULL,&datatype,(LPBYTE) appName,&datalen) != ERROR_SUCCESS) - *appName = 0; - RegCloseKey(hKey); - } - - trace("%s appname=%s\n",__FUNCTION__,appName); - - snprintf(buffer,79,"%s --session=\"H%06d\"",appName,getpid()); - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - // si.dwFlags = STARTF_PREVENTPINNING; - trace("App: %s",appName); - trace("CmdLine: %s",buffer); - - if(!CreateProcess(NULL,buffer,NULL,NULL,0,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi)) - return GetLastError(); - - CloseHandle( pi.hProcess ); - CloseHandle( pi.hThread ); - - // Wait for pipe to be available - time_t timer = time(0)+5; - HANDLE hPipe = INVALID_HANDLE_VALUE; - WIN32_FIND_DATA FindFileData; - - snprintf(buffer,4095,"\\\\.\\pipe\\H%06d_a",getpid()); - - while(hPipe == INVALID_HANDLE_VALUE && time(0) < timer) - { - Sleep(10); - hPipe = FindFirstFile(buffer, &FindFileData); - } - - if(hPipe == INVALID_HANDLE_VALUE) - return - ETIMEDOUT; - - CloseHandle(hPipe); - - // Load PIPE calls for the created session - snprintf(buffer,79,"H%06d:a",getpid()); - ret = load_remote(); - if(ret) - return ret; - - snprintf(buffer,79,"H%06d:A",getpid()); - hSession = session_new((const char *) buffer); - trace("%s ok hSession=%p\n",__FUNCTION__,hSession); - - return hSession ? HLLAPI_STATUS_SUCCESS : HLLAPI_STATUS_SYSTEM_ERROR; - } - - static DWORD load_dll(void) - { - // Direct mode, load lib3270.dll, get pointers to the calls - static const char *dllname = "lib3270.dll." PACKAGE_VERSION; - - int f; - HMODULE kernel; - HANDLE cookie = NULL; - DWORD rc; - HANDLE (*AddDllDirectory)(PCWSTR NewDirectory); - BOOL (*RemoveDllDirectory)(HANDLE Cookie); - UINT errorMode; - char datadir[4096]; - - trace("hModule=%p",hModule); - if(hModule) - return -EBUSY; - - kernel = LoadLibrary("kernel32.dll"); - AddDllDirectory = (HANDLE (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory"); - RemoveDllDirectory = (BOOL (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory"); - - // Notify user in case of error loading protocol DLL - // http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v=vs.85).aspx - errorMode = SetErrorMode(1); - - memset(datadir,' ',4095); - datadir[4095] = 0; - - if(hllapi_get_datadir(datadir)) - { - char buffer[4096]; - wchar_t path[4096]; - - mbstowcs(path, datadir, 4095); - trace("Datadir=[%s] AddDllDirectory=%p RemoveDllDirectory=%p\n",datadir,AddDllDirectory,RemoveDllDirectory); - if(AddDllDirectory) - cookie = AddDllDirectory(path); - -#ifdef DEBUG - snprintf(buffer,4096,"%s\\.bin\\Debug\\%s",datadir,dllname); -#else - snprintf(buffer,4096,"%s\\%s",datadir,dllname); -#endif // DEBUG - - hModule = LoadLibrary(buffer); - - trace("%s hModule=%p rc=%d",buffer,hModule,(int) GetLastError()); - - if(hModule == NULL) - { - // Enable DLL error popup and try again with full path - SetErrorMode(0); - hModule = LoadLibraryEx(buffer,NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS|LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); - } - - rc = GetLastError(); - - trace("%s hModule=%p rc=%d",buffer,hModule,(int) rc); - } - else - { - hModule = LoadLibrary(dllname); - rc = GetLastError(); - } - - SetErrorMode(errorMode); - - trace("%s hModule=%p rc=%d",dllname,hModule,(int) rc); - - if(cookie && RemoveDllDirectory) - RemoveDllDirectory(cookie); - - if(kernel) - FreeLibrary(kernel); - - if(!hModule) - return rc; - - // Get library entry pointers - for(f=0;entry_point[f].name;f++) - { - void *ptr = (void *) GetProcAddress(hModule,entry_point[f].name); - - trace("%d %s=%p\n",f,entry_point[f].name,ptr); - - if(!ptr) - { - trace("Can´t load \"%s\"\n",entry_point[f].name); - hllapi_deinit(); - return -ENOENT; - } - *entry_point[f].call = ptr; - } - - return HLLAPI_STATUS_SUCCESS; - } - - __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode) - { - if(!mode) - return HLLAPI_STATUS_SYSTEM_ERROR; - - trace("%s(%s)",__FUNCTION__,(char *) mode); - - if(mode && *mode) - { - if(strcasecmp(mode,"start") == 0 || strcasecmp(mode,"new") == 0) - return start_session(); - - load_remote(); - } - else - { - load_dll(); - } - - // Get session handle - hSession = session_new((const char *) mode); - trace("%s ok hSession=%p\n",__FUNCTION__,hSession); - - return hSession ? HLLAPI_STATUS_SUCCESS : HLLAPI_STATUS_SYSTEM_ERROR; - } - - __declspec (dllexport) DWORD __stdcall hllapi_deinit(void) - { - int f; - - // Release session - if(hSession && session_free) - session_free(hSession); - - for(f=0;entry_point[f].name;f++) - *entry_point[f].call = NULL; - - if(hModule != NULL) - { - FreeLibrary(hModule); - hModule = NULL; - } - - return 0; - } - - __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void) - { - if(!get_revision) - return 0; - return (DWORD) atoi(get_revision()); - } - - __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait) - { - if(!(host_connect && hSession && uri)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - return host_connect(hSession,uri,wait); - } - - __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void) - { - if(!(host_is_connected && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - return host_is_connected(hSession); - } - - __declspec (dllexport) DWORD __stdcall hllapi_get_state(void) - { - switch(hllapi_get_message_id()) - { - case LIB3270_MESSAGE_NONE: /* 0 - No message */ - return HLLAPI_STATUS_SUCCESS; - - case LIB3270_MESSAGE_DISCONNECTED: /* 4 - Disconnected from host */ - return HLLAPI_STATUS_DISCONNECTED; - - case LIB3270_MESSAGE_MINUS: - case LIB3270_MESSAGE_PROTECTED: - case LIB3270_MESSAGE_NUMERIC: - case LIB3270_MESSAGE_OVERFLOW: - case LIB3270_MESSAGE_INHIBIT: - case LIB3270_MESSAGE_KYBDLOCK: - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - case LIB3270_MESSAGE_SYSWAIT: - case LIB3270_MESSAGE_TWAIT: - case LIB3270_MESSAGE_AWAITING_FIRST: - case LIB3270_MESSAGE_X: - case LIB3270_MESSAGE_RESOLVING: - case LIB3270_MESSAGE_CONNECTING: - return HLLAPI_STATUS_WAITING; - } - - return HLLAPI_STATUS_SYSTEM_ERROR; - } - - __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void) - { - if(!(host_disconnect && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - host_disconnect(hSession); - - return 0; - } - - __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds) - { - if(!(wait_for_ready && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - trace("%s seconds=%d\n", __FUNCTION__, (int) seconds); - - return (DWORD) wait_for_ready(hSession,(int) seconds); - } - - __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds) - { - if(!(script_sleep && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - return (DWORD) script_sleep(hSession,(int) seconds); - } - - __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void) - { - if(!(get_message && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - return (DWORD) get_message(hSession); - } - - __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer) - { - char * text; - int len; - - if(!(get_text && release_memory && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - trace("%s row=%d col=%d buffer=%p",__FUNCTION__,row,col,buffer); - len = strlen(buffer); - - trace(" len=%d",len); - - text = get_text(hSession,row,col,len); - - trace(" text=%p errno=%d %s\n",text,errno,strerror(errno)); - - if(!text) - { - int rc = hllapi_get_state(); - return rc == HLLAPI_STATUS_SUCCESS ? -1 : rc; - } - - strncpy(buffer,text,len); - release_memory(text); - - trace("text:\n%s\n",buffer); - - return HLLAPI_STATUS_SUCCESS; - } - - __declspec (dllexport) DWORD __stdcall hllapi_enter(void) - { - if(!(action_enter && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - return (DWORD) action_enter(hSession); - } - - __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text) - { - if(!(set_text_at && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - return (DWORD) set_text_at(hSession,row,col,(const unsigned char *) text); - } - - __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text) - { - if(!(cmp_text_at && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - return (DWORD) cmp_text_at(hSession,row,col,(const char *) text); - } - - __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key) - { - if(!(pfkey && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - return (DWORD) pfkey(hSession,key); - } - - __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key) - { - if(!(pfkey && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - return (DWORD) pakey(hSession,key); - } - - __declspec (dllexport) DWORD __stdcall hllapi_get_datadir(LPSTR datadir) - { - HKEY hKey = 0; - unsigned long datalen = strlen(datadir); - - *datadir = 0; - - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) - { - unsigned long datatype; // #defined in winnt.h (predefined types 0-11) - if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) != ERROR_SUCCESS) - *datadir = 0; - RegCloseKey(hKey); - } - - return *datadir; - } - - __declspec (dllexport) DWORD __stdcall hllapi_setcursor(WORD pos) - { - if(!(setcursor && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - trace("%s(%d)",__FUNCTION__,pos); - return setcursor(hSession,pos-1); - } - - __declspec (dllexport) DWORD __stdcall hllapi_getcursor() - { - if(!(getcursor && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - return getcursor(hSession)+1; - } - - __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD offset, LPSTR buffer, WORD len) - { - size_t szBuffer = strlen(buffer); - char * text; - - if(len < szBuffer && len > 0) - szBuffer = len; - - text = hllapi_get_string(offset, szBuffer); - if(!text) - { - int rc = hllapi_get_state(); - return rc == HLLAPI_STATUS_SUCCESS ? -1 : rc; - } - - memcpy(buffer,text,len); - - hllapi_free(text); - - return HLLAPI_STATUS_SUCCESS; - } - - __declspec (dllexport) DWORD __stdcall hllapi_emulate_input(LPSTR buffer, WORD len, WORD pasting) - { - - if(!(emulate_input && hSession)) - return HLLAPI_STATUS_DISCONNECTED; - trace("%s(%s)",__FUNCTION__,(char *) buffer); - - if(buffer && *buffer) - emulate_input(hSession, buffer, len, pasting); - - return HLLAPI_STATUS_SUCCESS; - } - - __declspec (dllexport) DWORD __stdcall hllapi_erase_eof(void) - { - if(!erase_eof && hSession) - return HLLAPI_STATUS_SYSTEM_ERROR; - trace("%s",__FUNCTION__); - return erase_eof(hSession); - } - - __declspec (dllexport) DWORD __stdcall hllapi_print(void) - { - if(!(do_print && hSession)) - return HLLAPI_STATUS_SYSTEM_ERROR; - - return do_print(hSession); - } - - char * hllapi_get_string(int offset, size_t len) - { - if(!(get_text_at_offset && hSession)) - return NULL; - - return get_text_at_offset(hSession,offset-1,len); - } - - void hllapi_free(void *p) - { - if(release_memory) - release_memory(p); - } diff --git a/src/plugins/hllapi/calls.cc b/src/plugins/hllapi/calls.cc new file mode 100644 index 0000000..7472aaf --- /dev/null +++ b/src/plugins/hllapi/calls.cc @@ -0,0 +1,329 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como calls.cc e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include + #include + + #undef trace + #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } } + + using namespace std; + using namespace PW3270_NAMESPACE; + +/*--[ Globals ]--------------------------------------------------------------------------------------*/ + + static session * hSession = NULL; + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode) + { + try + { + if(hSession) + delete hSession; + hSession = session::create(mode); + } + catch(std::exception &e) + { + return HLLAPI_STATUS_SYSTEM_ERROR; + } + + return hSession ? HLLAPI_STATUS_SUCCESS : HLLAPI_STATUS_SYSTEM_ERROR; + } + + __declspec (dllexport) DWORD __stdcall hllapi_deinit(void) + { + try + { + if(hSession) + { + delete hSession; + hSession = NULL; + } + } + catch(std::exception &e) + { + return HLLAPI_STATUS_SYSTEM_ERROR; + } + + return HLLAPI_STATUS_SUCCESS; + } + + __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void) + { + try + { + return atoi(session::get_default()->get_revision().c_str()); + } + catch(std::exception &e) + { + return -1; + } + return (DWORD) -1; + } + + __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait) + { + int rc = HLLAPI_STATUS_SUCCESS; + + try + { + rc = session::get_default()->connect(uri,wait); + } + catch(std::exception &e) + { + return HLLAPI_STATUS_SYSTEM_ERROR; + } + + return rc; + } + + __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void) + { + return session::get_default()->is_connected(); + } + + __declspec (dllexport) DWORD __stdcall hllapi_get_state(void) + { + switch(hllapi_get_message_id()) + { + case LIB3270_MESSAGE_NONE: /* 0 - No message */ + return HLLAPI_STATUS_SUCCESS; + + case LIB3270_MESSAGE_DISCONNECTED: /* 4 - Disconnected from host */ + return HLLAPI_STATUS_DISCONNECTED; + + case LIB3270_MESSAGE_MINUS: + case LIB3270_MESSAGE_PROTECTED: + case LIB3270_MESSAGE_NUMERIC: + case LIB3270_MESSAGE_OVERFLOW: + case LIB3270_MESSAGE_INHIBIT: + case LIB3270_MESSAGE_KYBDLOCK: + return HLLAPI_STATUS_KEYBOARD_LOCKED; + + case LIB3270_MESSAGE_SYSWAIT: + case LIB3270_MESSAGE_TWAIT: + case LIB3270_MESSAGE_AWAITING_FIRST: + case LIB3270_MESSAGE_X: + case LIB3270_MESSAGE_RESOLVING: + case LIB3270_MESSAGE_CONNECTING: + return HLLAPI_STATUS_WAITING; + } + + return HLLAPI_STATUS_SYSTEM_ERROR; + } + + __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void) + { + session::get_default()->disconnect(); + return HLLAPI_STATUS_SUCCESS; + } + + __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds) + { + return session::get_default()->wait_for_ready(seconds); + } + + __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds) + { + return session::get_default()->wait(seconds); + } + + __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void) + { + return session::get_default()->get_cstate(); + } + + __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer) + { + if(!(buffer && *buffer)) + return HLLAPI_STATUS_SYSTEM_ERROR; + + try + { + size_t sz = strlen(buffer); + string * str = session::get_default()->get_string_at(row,col,sz); + if(str) + { + strncpy(buffer,str->c_str(),sz); + delete str; + } + } + catch(std::exception &e) + { + return HLLAPI_STATUS_SYSTEM_ERROR; + } + + return HLLAPI_STATUS_SUCCESS; + } + + __declspec (dllexport) DWORD __stdcall hllapi_enter(void) + { + return session::get_default()->enter(); + } + + __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text) + { + try + { + session::get_default()->set_string_at(row,col,text); + } + catch(std::exception &e) + { + return HLLAPI_STATUS_SYSTEM_ERROR; + } + + return HLLAPI_STATUS_SUCCESS; + } + + __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text) + { + int rc = HLLAPI_STATUS_SYSTEM_ERROR; + try + { + rc = session::get_default()->cmp_string_at(row,col,text); + } + catch(std::exception &e) + { + return HLLAPI_STATUS_SYSTEM_ERROR; + } + + return rc; + } + + __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key) + { + return session::get_default()->pfkey(key); + } + + __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key) + { + return session::get_default()->pakey(key); + } + + __declspec (dllexport) DWORD __stdcall hllapi_get_datadir(LPSTR datadir) + { + HKEY hKey = 0; + unsigned long datalen = strlen(datadir); + + *datadir = 0; + + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) + { + unsigned long datatype; // #defined in winnt.h (predefined types 0-11) + if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) != ERROR_SUCCESS) + *datadir = 0; + RegCloseKey(hKey); + } + + return *datadir; + } + + __declspec (dllexport) DWORD __stdcall hllapi_setcursor(WORD pos) + { + return session::get_default()->set_cursor_addr(pos-1); + } + + __declspec (dllexport) DWORD __stdcall hllapi_getcursor() + { + return session::get_default()->get_cursor_addr()+1; + } + + __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD offset, LPSTR buffer, WORD len) + { + int rc = HLLAPI_STATUS_SYSTEM_ERROR; + + if(!(buffer && *buffer)) + return rc; + + try + { + size_t szBuffer = strlen(buffer); + + if(len < szBuffer && len > 0) + szBuffer = len; + + string *str = session::get_default()->get_string(offset,szBuffer); + if(str) + { + strncpy(buffer,str->c_str(),szBuffer); + delete str; + rc = HLLAPI_STATUS_SUCCESS; + } + } + catch(std::exception &e) + { + rc = HLLAPI_STATUS_SYSTEM_ERROR; + } + + return rc; + } + + __declspec (dllexport) DWORD __stdcall hllapi_emulate_input(LPSTR buffer, WORD len, WORD pasting) + { + session::get_default()->emulate_input(buffer); + return HLLAPI_STATUS_SUCCESS; + } + + __declspec (dllexport) DWORD __stdcall hllapi_erase_eof(void) + { + session::get_default()->erase_eof(); + return HLLAPI_STATUS_SUCCESS; + } + + __declspec (dllexport) DWORD __stdcall hllapi_print(void) + { + return session::get_default()->print(); + } + + char * hllapi_get_string(int offset, size_t len) + { + try + { + string *str = session::get_default()->get_string(offset-1,len); + if(str) + { + char * ret = strdup(str->c_str()); + delete str; + return ret; + } + } + catch(std::exception &e) + { + } + + return NULL; + } + + void hllapi_free(void *p) + { + free(p); + } diff --git a/src/plugins/hllapi/hllapi.c b/src/plugins/hllapi/hllapi.c index aa92463..d04232b 100644 --- a/src/plugins/hllapi/hllapi.c +++ b/src/plugins/hllapi/hllapi.c @@ -91,7 +91,7 @@ LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc) #endif // _WIN32 { - int f; + unsigned int f; trace("%s(%d)",__FUNCTION__,*func); @@ -123,7 +123,7 @@ static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc) { int sz = strlen(buffer); - tempbuffer = malloc(sz+2); + tempbuffer = (char *) malloc(sz+2); strcpy(tempbuffer,buffer); tempbuffer[sz-1] = ':'; tempbuffer[sz] = buffer[sz-1]; @@ -197,7 +197,7 @@ static int input_string(char *input, unsigned short *length, unsigned short *rc) if(*length > 0 && *length < szText) szText = *length; - text = malloc(szText+2); + text = (char *) malloc(szText+2); memcpy(text,input,szText); text[szText] = 0; diff --git a/src/plugins/hllapi/hllapi.cbp b/src/plugins/hllapi/hllapi.cbp index 89cfc8e..b9dd724 100644 --- a/src/plugins/hllapi/hllapi.cbp +++ b/src/plugins/hllapi/hllapi.cbp @@ -37,9 +37,9 @@ - - - + + + @@ -55,14 +55,11 @@ - - + - diff --git a/src/plugins/hllapi/pluginmain.c b/src/plugins/hllapi/pluginmain.c index 68e6ed9..ddc41a6 100644 --- a/src/plugins/hllapi/pluginmain.c +++ b/src/plugins/hllapi/pluginmain.c @@ -32,6 +32,7 @@ */ #include "server.h" + #include #include #include #include @@ -42,18 +43,20 @@ #pragma pack(1) + enum PIPE_STATE + { + PIPE_STATE_WAITING, + PIPE_STATE_READ, + PIPE_STATE_PENDING_READ, + PIPE_STATE_UNDEFINED + }; + typedef struct _pipe_source { GSource gsrc; HANDLE hPipe; - enum _PIPE_STATE - { - PIPE_STATE_WAITING, - PIPE_STATE_READ, - PIPE_STATE_PENDING_READ, - PIPE_STATE_UNDEFINED, - } state; + enum PIPE_STATE state; OVERLAPPED overlap; unsigned char buffer[PIPE_BUFFER_LENGTH+1]; @@ -145,7 +148,7 @@ if(text) { szBlock = sizeof(struct hllapi_packet_text)+strlen(text); - pkt = g_malloc0(szBlock); + pkt = (struct hllapi_packet_text *) g_malloc0(szBlock); pkt->packet_id = 0; strcpy(pkt->text,text); lib3270_free(text); @@ -153,7 +156,7 @@ else { szBlock = sizeof(struct hllapi_packet_text); - pkt = g_malloc0(szBlock); + pkt = (struct hllapi_packet_text *) g_malloc0(szBlock); pkt->packet_id = errno ? errno : -1; } @@ -280,7 +283,7 @@ case HLLAPI_PACKET_SET_TOGGLE: send_result(source,lib3270_set_toggle(lib3270_get_default_session_handle(), - ((struct hllapi_packet_set *) source->buffer)->id, + (LIB3270_TOGGLE) ((struct hllapi_packet_set *) source->buffer)->id, ((struct hllapi_packet_set *) source->buffer)->value)); break; @@ -456,7 +459,7 @@ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); - for(ptr=lpMsgBuf;*ptr && *ptr != '\n';ptr++); + for(ptr= (char *) lpMsgBuf;*ptr && *ptr != '\n';ptr++); *ptr = 0; va_start(arg_ptr, fmt); diff --git a/src/plugins/hllapi/testprogram.c b/src/plugins/hllapi/testprogram.c index 63fabd2..e61d794 100644 --- a/src/plugins/hllapi/testprogram.c +++ b/src/plugins/hllapi/testprogram.c @@ -27,7 +27,6 @@ * */ - #include #include #include #include @@ -42,7 +41,7 @@ printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session)); printf("revision=%d\n",(int) hllapi_get_revision()); - printf("connect=%d\n",(int) hllapi_connect("fandezhi.efglobe.com:23",0)); + printf("connect=%d\n",(int) hllapi_connect((char *) "fandezhi.efglobe.com:23",0)); printf("wait=%d\n",(int) hllapi_wait(3)); printf("connected=%s\n",(int) hllapi_is_connected() ? "Yes" : "No"); -- libgit2 0.21.2