Commit 233914019c9cbc7beb30cd12eea2e3993510f2e7
1 parent
988584bf
Exists in
master
and in
5 other branches
Incluindo funcoes extras do hllapi na classe base
Showing
7 changed files
with
376 additions
and
634 deletions
Show diff stats
src/plugins/hllapi/Makefile.in
| ... | ... | @@ -31,7 +31,9 @@ |
| 31 | 31 | MODULE_NAME=hllapi |
| 32 | 32 | DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile |
| 33 | 33 | PLUGIN_SRC=pluginmain.c |
| 34 | -HLLAPI_SRC=hllapi.c calls.c remote.c | |
| 34 | +HLLAPI_SRC=hllapi.c calls.c | |
| 35 | + | |
| 36 | +CLASSLIBDIR=../../classlib | |
| 35 | 37 | |
| 36 | 38 | #---[ Paths ]------------------------------------------------------------------ |
| 37 | 39 | |
| ... | ... | @@ -48,8 +50,8 @@ OBJEXT = o |
| 48 | 50 | #---[ Tools ]------------------------------------------------------------------ |
| 49 | 51 | |
| 50 | 52 | MKDIR=@MKDIR_P@ |
| 51 | -CC=@CC@ | |
| 52 | -LD=@CC@ | |
| 53 | +CC=@CXX@ | |
| 54 | +LD=@CXX@ | |
| 53 | 55 | MSGCAT=@MSGCAT@ |
| 54 | 56 | XGETTEXT=@XGETTEXT@ |
| 55 | 57 | |
| ... | ... | @@ -81,15 +83,26 @@ ifeq ($(LIB3270_MODE),Default) |
| 81 | 83 | PW3270_CFLAGS ?= `pkg-config --cflags pw3270 lib3270` |
| 82 | 84 | endif |
| 83 | 85 | |
| 84 | - | |
| 85 | 86 | GTK_CFLAGS ?= @GTK_CFLAGS@ @GTKMAC_CFLAGS@ |
| 86 | 87 | GTK_LIBS ?= @GTK_LIBS@ @GTKMAC_LIBS@ |
| 87 | 88 | |
| 89 | +include $(CLASSLIBDIR)/class.mak | |
| 90 | + | |
| 91 | +$(OBJDBG)/%.o: %.cc $(DEPENDS) | |
| 92 | + @echo " CC `basename $@`" | |
| 93 | + @$(MKDIR) `dirname $@` | |
| 94 | + @$(CXX) $(CFLAGS) $(DEBUG_CFLAGS) $(LIB3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< | |
| 95 | + | |
| 88 | 96 | $(OBJDBG)/%.o: %.c $(DEPENDS) |
| 89 | 97 | @echo " CC `basename $@`" |
| 90 | 98 | @$(MKDIR) `dirname $@` |
| 91 | 99 | @$(CC) $(CFLAGS) $(DEBUG_CFLAGS) $(LIB3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< |
| 92 | 100 | |
| 101 | +$(OBJRLS)/%.o: %.cc $(DEPENDS) | |
| 102 | + @echo " CC `basename $@`" | |
| 103 | + @$(MKDIR) `dirname $@` | |
| 104 | + @$(CXX) $(CFLAGS) $(LIB3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< | |
| 105 | + | |
| 93 | 106 | $(OBJRLS)/%.o: %.c $(DEPENDS) |
| 94 | 107 | @echo " CC `basename $@`" |
| 95 | 108 | @$(MKDIR) `dirname $@` |
| ... | ... | @@ -119,24 +132,24 @@ $(BINDBG)/plugins/$(MODULE_NAME)@DLLEXT@: $(foreach SRC, $(basename $(PLUGIN_SRC |
| 119 | 132 | @$(MKDIR) `dirname $@` |
| 120 | 133 | @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) -o $@ $^ $(LIBS) $(PW3270_LIBS) $(GTK_LIBS) |
| 121 | 134 | |
| 122 | -$(BINDBG)/libhllapi@DLLEXT@: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJDBG)/$(SRC).o) | |
| 135 | +$(BINDBG)/libhllapi@DLLEXT@: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJDBG)/$(SRC).o) $(CLASS_DEBUG_OBJECTS) | |
| 123 | 136 | @echo " CCLD `basename $@`" |
| 124 | 137 | @$(MKDIR) `dirname $@` |
| 125 | - @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) @LDLIBFLAGS@ -o $@ $^ $(LIBS) | |
| 138 | + @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) @LDLIBFLAGS@ -o $@ $^ $(LIBS) $(CLASS_LIBS) | |
| 126 | 139 | |
| 127 | 140 | #---[ Misc targets ]----------------------------------------------------------- |
| 128 | 141 | |
| 129 | -$(BINDBG)/testprogram@EXEEXT@: testprogram.c $(BINDBG)/libhllapi@DLLEXT@ | |
| 142 | +$(BINDBG)/testprogram@EXEEXT@: $(OBJDBG)/testprogram.o $(BINDBG)/libhllapi@DLLEXT@ | |
| 130 | 143 | @echo " CCLD `basename $@`" |
| 131 | 144 | @$(MKDIR) `dirname $@` |
| 132 | - @$(CC) $(CFLAGS) $(PW3270_CFLAGS) -L$(BINDBG) $(DEBUG_CFLAGS) -lhllapi -o $@ testprogram.c | |
| 145 | + @$(CXX) $(CFLAGS) $(PW3270_CFLAGS) -L$(BINDBG) $(DEBUG_CFLAGS) -lhllapi -o $@ $(OBJDBG)/testprogram.o | |
| 133 | 146 | |
| 134 | 147 | test: $(BINDBG)/testprogram@EXEEXT@ |
| 135 | - | |
| 136 | -run: $(BINDBG)/testprogram@EXEEXT@ | |
| 148 | + | |
| 149 | +run: $(BINDBG)/testprogram@EXEEXT@ | |
| 137 | 150 | @cd $(BINDBG) ; ./testprogram@EXEEXT@ |
| 138 | - | |
| 139 | -install: $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ | |
| 151 | + | |
| 152 | +install: $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ | |
| 140 | 153 | @$(MKDIR) $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins |
| 141 | 154 | @$(INSTALL_PROGRAM) $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins |
| 142 | 155 | ... | ... |
src/plugins/hllapi/calls.c
| ... | ... | @@ -1,599 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple | |
| 19 | - * Place, Suite 330, Boston, MA, 02111-1307, USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como calls.c e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | - #include <windows.h> | |
| 31 | - #include <lib3270.h> | |
| 32 | - #include <malloc.h> | |
| 33 | - #include <string.h> | |
| 34 | - #include <errno.h> | |
| 35 | - #include <pw3270/hllapi.h> | |
| 36 | - #include <stdio.h> | |
| 37 | - #include <lib3270/log.h> | |
| 38 | - #include <process.h> | |
| 39 | - #include <time.h> | |
| 40 | - #include "client.h" | |
| 41 | - | |
| 42 | - #undef trace | |
| 43 | - #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); } } | |
| 44 | - | |
| 45 | -/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
| 46 | - | |
| 47 | - HMODULE hModule = NULL; | |
| 48 | - void * hSession = NULL; | |
| 49 | - | |
| 50 | - | |
| 51 | - static void * (*session_new)(const char *model) = NULL; | |
| 52 | - static void (*session_free)(void *h) = NULL; | |
| 53 | - static const char * (*get_revision)(void) = NULL; | |
| 54 | - static int (*host_connect)(void *h,const char *n, int wait) = NULL; | |
| 55 | - static int (*host_is_connected)(void *h) = NULL; | |
| 56 | - static int (*wait_for_ready)(void *h, int seconds) = NULL; | |
| 57 | - static void (*host_disconnect)(void *h) = NULL; | |
| 58 | - static int (*script_sleep)(void *h, int seconds) = NULL; | |
| 59 | - static LIB3270_MESSAGE (*get_message)(void *h) = NULL; | |
| 60 | - static char * (*get_text)(void *h, int row, int col, int len) = NULL; | |
| 61 | - static char * (*get_text_at_offset)(void *h, int offset, int len) = NULL; | |
| 62 | - | |
| 63 | - static void * (*release_memory)(void *p) = NULL; | |
| 64 | - static int (*action_enter)(void *h) = NULL; | |
| 65 | - static int (*set_text_at)(void *h, int row, int col, const unsigned char *str) = NULL; | |
| 66 | - static int (*cmp_text_at)(void *h, int row, int col, const char *text) = NULL; | |
| 67 | - static int (*pfkey)(void *hSession, int key) = NULL; | |
| 68 | - static int (*pakey)(void *hSession, int key) = NULL; | |
| 69 | - static int (*getcursor)(void *hSession) = NULL; | |
| 70 | - static int (*setcursor)(void *hSession, int baddr) = NULL; | |
| 71 | - static int (*emulate_input)(void *hSession, const char *s, int len, int pasting) = NULL; | |
| 72 | - static int (*erase_eof)(void *hSession) = NULL; | |
| 73 | - static int (*do_print)(void *h) = NULL; | |
| 74 | - | |
| 75 | - static const struct _entry_point | |
| 76 | - { | |
| 77 | - void **call; | |
| 78 | - void * pipe; | |
| 79 | - const char * name; | |
| 80 | - } entry_point[] = | |
| 81 | - { | |
| 82 | - { (void **) &session_new, (void *) hllapi_pipe_init, "lib3270_session_new" }, | |
| 83 | - { (void **) &session_free, (void *) hllapi_pipe_deinit, "lib3270_session_free" }, | |
| 84 | - { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, | |
| 85 | - { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, | |
| 86 | - { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" }, | |
| 87 | - { (void **) &host_is_connected, (void *) hllapi_pipe_is_connected, "lib3270_in_tn3270e" }, | |
| 88 | - { (void **) &wait_for_ready, (void *) hllapi_pipe_wait_for_ready, "lib3270_wait_for_ready" }, | |
| 89 | - { (void **) &script_sleep, (void *) hllapi_pipe_sleep, "lib3270_wait" }, | |
| 90 | - { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, | |
| 91 | - { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, | |
| 92 | - { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, | |
| 93 | - { (void **) &action_enter, (void *) hllapi_pipe_enter, "lib3270_enter" }, | |
| 94 | - { (void **) &set_text_at, (void *) hllapi_pipe_set_text_at, "lib3270_set_string_at" }, | |
| 95 | - { (void **) &cmp_text_at, (void *) hllapi_pipe_cmp_text_at, "lib3270_cmp_text_at" }, | |
| 96 | - { (void **) &pfkey, (void *) hllapi_pipe_pfkey, "lib3270_pfkey" }, | |
| 97 | - { (void **) &pakey, (void *) hllapi_pipe_pakey, "lib3270_pakey" }, | |
| 98 | - { (void **) &setcursor, (void *) hllapi_pipe_setcursor, "lib3270_set_cursor_address" }, | |
| 99 | - { (void **) &getcursor, (void *) hllapi_pipe_getcursor, "lib3270_get_cursor_address" }, | |
| 100 | - { (void **) &get_text_at_offset, (void *) hllapi_pipe_get_text, "lib3270_get_text" }, | |
| 101 | - { (void **) &emulate_input, (void *) hllapi_pipe_emulate_input, "lib3270_emulate_input" }, | |
| 102 | - { (void **) &erase_eof, (void *) hllapi_pipe_erase_eof, "lib3270_eraseeof" }, | |
| 103 | - { (void **) &do_print, (void *) hllapi_pipe_print, "lib3270_print" }, | |
| 104 | - | |
| 105 | - { NULL, NULL, NULL } | |
| 106 | - }; | |
| 107 | - | |
| 108 | -// http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx | |
| 109 | -#ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
| 110 | - #define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000 | |
| 111 | -#endif // LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
| 112 | - | |
| 113 | -#ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
| 114 | - #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100 | |
| 115 | -#endif // LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
| 116 | - | |
| 117 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 118 | - | |
| 119 | - static DWORD load_remote(void) | |
| 120 | - { | |
| 121 | - // Get pointers to the pipe based calls | |
| 122 | - int f; | |
| 123 | - | |
| 124 | - trace("%s: Loading pipe based calls",__FUNCTION__); | |
| 125 | - for(f=0;entry_point[f].name;f++) | |
| 126 | - *entry_point[f].call = entry_point[f].pipe; | |
| 127 | - | |
| 128 | - return HLLAPI_STATUS_SUCCESS; | |
| 129 | - } | |
| 130 | - | |
| 131 | - static DWORD start_session(void) | |
| 132 | - { | |
| 133 | - char buffer[80]; | |
| 134 | - char appName[4096]; | |
| 135 | - HKEY hKey = 0; | |
| 136 | - unsigned long datalen = 4096; | |
| 137 | - DWORD ret; | |
| 138 | - STARTUPINFO si; | |
| 139 | - PROCESS_INFORMATION pi; | |
| 140 | - | |
| 141 | - // Get application path | |
| 142 | - *appName = 0; | |
| 143 | - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) | |
| 144 | - { | |
| 145 | - unsigned long datatype; // #defined in winnt.h (predefined types 0-11) | |
| 146 | - if(RegQueryValueExA(hKey,"appName",NULL,&datatype,(LPBYTE) appName,&datalen) != ERROR_SUCCESS) | |
| 147 | - *appName = 0; | |
| 148 | - RegCloseKey(hKey); | |
| 149 | - } | |
| 150 | - | |
| 151 | - trace("%s appname=%s\n",__FUNCTION__,appName); | |
| 152 | - | |
| 153 | - snprintf(buffer,79,"%s --session=\"H%06d\"",appName,getpid()); | |
| 154 | - | |
| 155 | - ZeroMemory( &si, sizeof(si) ); | |
| 156 | - si.cb = sizeof(si); | |
| 157 | - ZeroMemory( &pi, sizeof(pi) ); | |
| 158 | - | |
| 159 | - // si.dwFlags = STARTF_PREVENTPINNING; | |
| 160 | - trace("App: %s",appName); | |
| 161 | - trace("CmdLine: %s",buffer); | |
| 162 | - | |
| 163 | - if(!CreateProcess(NULL,buffer,NULL,NULL,0,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi)) | |
| 164 | - return GetLastError(); | |
| 165 | - | |
| 166 | - CloseHandle( pi.hProcess ); | |
| 167 | - CloseHandle( pi.hThread ); | |
| 168 | - | |
| 169 | - // Wait for pipe to be available | |
| 170 | - time_t timer = time(0)+5; | |
| 171 | - HANDLE hPipe = INVALID_HANDLE_VALUE; | |
| 172 | - WIN32_FIND_DATA FindFileData; | |
| 173 | - | |
| 174 | - snprintf(buffer,4095,"\\\\.\\pipe\\H%06d_a",getpid()); | |
| 175 | - | |
| 176 | - while(hPipe == INVALID_HANDLE_VALUE && time(0) < timer) | |
| 177 | - { | |
| 178 | - Sleep(10); | |
| 179 | - hPipe = FindFirstFile(buffer, &FindFileData); | |
| 180 | - } | |
| 181 | - | |
| 182 | - if(hPipe == INVALID_HANDLE_VALUE) | |
| 183 | - return - ETIMEDOUT; | |
| 184 | - | |
| 185 | - CloseHandle(hPipe); | |
| 186 | - | |
| 187 | - // Load PIPE calls for the created session | |
| 188 | - snprintf(buffer,79,"H%06d:a",getpid()); | |
| 189 | - ret = load_remote(); | |
| 190 | - if(ret) | |
| 191 | - return ret; | |
| 192 | - | |
| 193 | - snprintf(buffer,79,"H%06d:A",getpid()); | |
| 194 | - hSession = session_new((const char *) buffer); | |
| 195 | - trace("%s ok hSession=%p\n",__FUNCTION__,hSession); | |
| 196 | - | |
| 197 | - return hSession ? HLLAPI_STATUS_SUCCESS : HLLAPI_STATUS_SYSTEM_ERROR; | |
| 198 | - } | |
| 199 | - | |
| 200 | - static DWORD load_dll(void) | |
| 201 | - { | |
| 202 | - // Direct mode, load lib3270.dll, get pointers to the calls | |
| 203 | - static const char *dllname = "lib3270.dll." PACKAGE_VERSION; | |
| 204 | - | |
| 205 | - int f; | |
| 206 | - HMODULE kernel; | |
| 207 | - HANDLE cookie = NULL; | |
| 208 | - DWORD rc; | |
| 209 | - HANDLE (*AddDllDirectory)(PCWSTR NewDirectory); | |
| 210 | - BOOL (*RemoveDllDirectory)(HANDLE Cookie); | |
| 211 | - UINT errorMode; | |
| 212 | - char datadir[4096]; | |
| 213 | - | |
| 214 | - trace("hModule=%p",hModule); | |
| 215 | - if(hModule) | |
| 216 | - return -EBUSY; | |
| 217 | - | |
| 218 | - kernel = LoadLibrary("kernel32.dll"); | |
| 219 | - AddDllDirectory = (HANDLE (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory"); | |
| 220 | - RemoveDllDirectory = (BOOL (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory"); | |
| 221 | - | |
| 222 | - // Notify user in case of error loading protocol DLL | |
| 223 | - // http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v=vs.85).aspx | |
| 224 | - errorMode = SetErrorMode(1); | |
| 225 | - | |
| 226 | - memset(datadir,' ',4095); | |
| 227 | - datadir[4095] = 0; | |
| 228 | - | |
| 229 | - if(hllapi_get_datadir(datadir)) | |
| 230 | - { | |
| 231 | - char buffer[4096]; | |
| 232 | - wchar_t path[4096]; | |
| 233 | - | |
| 234 | - mbstowcs(path, datadir, 4095); | |
| 235 | - trace("Datadir=[%s] AddDllDirectory=%p RemoveDllDirectory=%p\n",datadir,AddDllDirectory,RemoveDllDirectory); | |
| 236 | - if(AddDllDirectory) | |
| 237 | - cookie = AddDllDirectory(path); | |
| 238 | - | |
| 239 | -#ifdef DEBUG | |
| 240 | - snprintf(buffer,4096,"%s\\.bin\\Debug\\%s",datadir,dllname); | |
| 241 | -#else | |
| 242 | - snprintf(buffer,4096,"%s\\%s",datadir,dllname); | |
| 243 | -#endif // DEBUG | |
| 244 | - | |
| 245 | - hModule = LoadLibrary(buffer); | |
| 246 | - | |
| 247 | - trace("%s hModule=%p rc=%d",buffer,hModule,(int) GetLastError()); | |
| 248 | - | |
| 249 | - if(hModule == NULL) | |
| 250 | - { | |
| 251 | - // Enable DLL error popup and try again with full path | |
| 252 | - SetErrorMode(0); | |
| 253 | - hModule = LoadLibraryEx(buffer,NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS|LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); | |
| 254 | - } | |
| 255 | - | |
| 256 | - rc = GetLastError(); | |
| 257 | - | |
| 258 | - trace("%s hModule=%p rc=%d",buffer,hModule,(int) rc); | |
| 259 | - } | |
| 260 | - else | |
| 261 | - { | |
| 262 | - hModule = LoadLibrary(dllname); | |
| 263 | - rc = GetLastError(); | |
| 264 | - } | |
| 265 | - | |
| 266 | - SetErrorMode(errorMode); | |
| 267 | - | |
| 268 | - trace("%s hModule=%p rc=%d",dllname,hModule,(int) rc); | |
| 269 | - | |
| 270 | - if(cookie && RemoveDllDirectory) | |
| 271 | - RemoveDllDirectory(cookie); | |
| 272 | - | |
| 273 | - if(kernel) | |
| 274 | - FreeLibrary(kernel); | |
| 275 | - | |
| 276 | - if(!hModule) | |
| 277 | - return rc; | |
| 278 | - | |
| 279 | - // Get library entry pointers | |
| 280 | - for(f=0;entry_point[f].name;f++) | |
| 281 | - { | |
| 282 | - void *ptr = (void *) GetProcAddress(hModule,entry_point[f].name); | |
| 283 | - | |
| 284 | - trace("%d %s=%p\n",f,entry_point[f].name,ptr); | |
| 285 | - | |
| 286 | - if(!ptr) | |
| 287 | - { | |
| 288 | - trace("Can´t load \"%s\"\n",entry_point[f].name); | |
| 289 | - hllapi_deinit(); | |
| 290 | - return -ENOENT; | |
| 291 | - } | |
| 292 | - *entry_point[f].call = ptr; | |
| 293 | - } | |
| 294 | - | |
| 295 | - return HLLAPI_STATUS_SUCCESS; | |
| 296 | - } | |
| 297 | - | |
| 298 | - __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode) | |
| 299 | - { | |
| 300 | - if(!mode) | |
| 301 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 302 | - | |
| 303 | - trace("%s(%s)",__FUNCTION__,(char *) mode); | |
| 304 | - | |
| 305 | - if(mode && *mode) | |
| 306 | - { | |
| 307 | - if(strcasecmp(mode,"start") == 0 || strcasecmp(mode,"new") == 0) | |
| 308 | - return start_session(); | |
| 309 | - | |
| 310 | - load_remote(); | |
| 311 | - } | |
| 312 | - else | |
| 313 | - { | |
| 314 | - load_dll(); | |
| 315 | - } | |
| 316 | - | |
| 317 | - // Get session handle | |
| 318 | - hSession = session_new((const char *) mode); | |
| 319 | - trace("%s ok hSession=%p\n",__FUNCTION__,hSession); | |
| 320 | - | |
| 321 | - return hSession ? HLLAPI_STATUS_SUCCESS : HLLAPI_STATUS_SYSTEM_ERROR; | |
| 322 | - } | |
| 323 | - | |
| 324 | - __declspec (dllexport) DWORD __stdcall hllapi_deinit(void) | |
| 325 | - { | |
| 326 | - int f; | |
| 327 | - | |
| 328 | - // Release session | |
| 329 | - if(hSession && session_free) | |
| 330 | - session_free(hSession); | |
| 331 | - | |
| 332 | - for(f=0;entry_point[f].name;f++) | |
| 333 | - *entry_point[f].call = NULL; | |
| 334 | - | |
| 335 | - if(hModule != NULL) | |
| 336 | - { | |
| 337 | - FreeLibrary(hModule); | |
| 338 | - hModule = NULL; | |
| 339 | - } | |
| 340 | - | |
| 341 | - return 0; | |
| 342 | - } | |
| 343 | - | |
| 344 | - __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void) | |
| 345 | - { | |
| 346 | - if(!get_revision) | |
| 347 | - return 0; | |
| 348 | - return (DWORD) atoi(get_revision()); | |
| 349 | - } | |
| 350 | - | |
| 351 | - __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait) | |
| 352 | - { | |
| 353 | - if(!(host_connect && hSession && uri)) | |
| 354 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 355 | - | |
| 356 | - return host_connect(hSession,uri,wait); | |
| 357 | - } | |
| 358 | - | |
| 359 | - __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void) | |
| 360 | - { | |
| 361 | - if(!(host_is_connected && hSession)) | |
| 362 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 363 | - | |
| 364 | - return host_is_connected(hSession); | |
| 365 | - } | |
| 366 | - | |
| 367 | - __declspec (dllexport) DWORD __stdcall hllapi_get_state(void) | |
| 368 | - { | |
| 369 | - switch(hllapi_get_message_id()) | |
| 370 | - { | |
| 371 | - case LIB3270_MESSAGE_NONE: /* 0 - No message */ | |
| 372 | - return HLLAPI_STATUS_SUCCESS; | |
| 373 | - | |
| 374 | - case LIB3270_MESSAGE_DISCONNECTED: /* 4 - Disconnected from host */ | |
| 375 | - return HLLAPI_STATUS_DISCONNECTED; | |
| 376 | - | |
| 377 | - case LIB3270_MESSAGE_MINUS: | |
| 378 | - case LIB3270_MESSAGE_PROTECTED: | |
| 379 | - case LIB3270_MESSAGE_NUMERIC: | |
| 380 | - case LIB3270_MESSAGE_OVERFLOW: | |
| 381 | - case LIB3270_MESSAGE_INHIBIT: | |
| 382 | - case LIB3270_MESSAGE_KYBDLOCK: | |
| 383 | - return HLLAPI_STATUS_KEYBOARD_LOCKED; | |
| 384 | - | |
| 385 | - case LIB3270_MESSAGE_SYSWAIT: | |
| 386 | - case LIB3270_MESSAGE_TWAIT: | |
| 387 | - case LIB3270_MESSAGE_AWAITING_FIRST: | |
| 388 | - case LIB3270_MESSAGE_X: | |
| 389 | - case LIB3270_MESSAGE_RESOLVING: | |
| 390 | - case LIB3270_MESSAGE_CONNECTING: | |
| 391 | - return HLLAPI_STATUS_WAITING; | |
| 392 | - } | |
| 393 | - | |
| 394 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 395 | - } | |
| 396 | - | |
| 397 | - __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void) | |
| 398 | - { | |
| 399 | - if(!(host_disconnect && hSession)) | |
| 400 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 401 | - | |
| 402 | - host_disconnect(hSession); | |
| 403 | - | |
| 404 | - return 0; | |
| 405 | - } | |
| 406 | - | |
| 407 | - __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds) | |
| 408 | - { | |
| 409 | - if(!(wait_for_ready && hSession)) | |
| 410 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 411 | - | |
| 412 | - trace("%s seconds=%d\n", __FUNCTION__, (int) seconds); | |
| 413 | - | |
| 414 | - return (DWORD) wait_for_ready(hSession,(int) seconds); | |
| 415 | - } | |
| 416 | - | |
| 417 | - __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds) | |
| 418 | - { | |
| 419 | - if(!(script_sleep && hSession)) | |
| 420 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 421 | - | |
| 422 | - return (DWORD) script_sleep(hSession,(int) seconds); | |
| 423 | - } | |
| 424 | - | |
| 425 | - __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void) | |
| 426 | - { | |
| 427 | - if(!(get_message && hSession)) | |
| 428 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 429 | - return (DWORD) get_message(hSession); | |
| 430 | - } | |
| 431 | - | |
| 432 | - __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer) | |
| 433 | - { | |
| 434 | - char * text; | |
| 435 | - int len; | |
| 436 | - | |
| 437 | - if(!(get_text && release_memory && hSession)) | |
| 438 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 439 | - | |
| 440 | - trace("%s row=%d col=%d buffer=%p",__FUNCTION__,row,col,buffer); | |
| 441 | - len = strlen(buffer); | |
| 442 | - | |
| 443 | - trace(" len=%d",len); | |
| 444 | - | |
| 445 | - text = get_text(hSession,row,col,len); | |
| 446 | - | |
| 447 | - trace(" text=%p errno=%d %s\n",text,errno,strerror(errno)); | |
| 448 | - | |
| 449 | - if(!text) | |
| 450 | - { | |
| 451 | - int rc = hllapi_get_state(); | |
| 452 | - return rc == HLLAPI_STATUS_SUCCESS ? -1 : rc; | |
| 453 | - } | |
| 454 | - | |
| 455 | - strncpy(buffer,text,len); | |
| 456 | - release_memory(text); | |
| 457 | - | |
| 458 | - trace("text:\n%s\n",buffer); | |
| 459 | - | |
| 460 | - return HLLAPI_STATUS_SUCCESS; | |
| 461 | - } | |
| 462 | - | |
| 463 | - __declspec (dllexport) DWORD __stdcall hllapi_enter(void) | |
| 464 | - { | |
| 465 | - if(!(action_enter && hSession)) | |
| 466 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 467 | - | |
| 468 | - return (DWORD) action_enter(hSession); | |
| 469 | - } | |
| 470 | - | |
| 471 | - __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text) | |
| 472 | - { | |
| 473 | - if(!(set_text_at && hSession)) | |
| 474 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 475 | - | |
| 476 | - return (DWORD) set_text_at(hSession,row,col,(const unsigned char *) text); | |
| 477 | - } | |
| 478 | - | |
| 479 | - __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text) | |
| 480 | - { | |
| 481 | - if(!(cmp_text_at && hSession)) | |
| 482 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 483 | - | |
| 484 | - return (DWORD) cmp_text_at(hSession,row,col,(const char *) text); | |
| 485 | - } | |
| 486 | - | |
| 487 | - __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key) | |
| 488 | - { | |
| 489 | - if(!(pfkey && hSession)) | |
| 490 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 491 | - | |
| 492 | - return (DWORD) pfkey(hSession,key); | |
| 493 | - } | |
| 494 | - | |
| 495 | - __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key) | |
| 496 | - { | |
| 497 | - if(!(pfkey && hSession)) | |
| 498 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 499 | - | |
| 500 | - return (DWORD) pakey(hSession,key); | |
| 501 | - } | |
| 502 | - | |
| 503 | - __declspec (dllexport) DWORD __stdcall hllapi_get_datadir(LPSTR datadir) | |
| 504 | - { | |
| 505 | - HKEY hKey = 0; | |
| 506 | - unsigned long datalen = strlen(datadir); | |
| 507 | - | |
| 508 | - *datadir = 0; | |
| 509 | - | |
| 510 | - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) | |
| 511 | - { | |
| 512 | - unsigned long datatype; // #defined in winnt.h (predefined types 0-11) | |
| 513 | - if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) != ERROR_SUCCESS) | |
| 514 | - *datadir = 0; | |
| 515 | - RegCloseKey(hKey); | |
| 516 | - } | |
| 517 | - | |
| 518 | - return *datadir; | |
| 519 | - } | |
| 520 | - | |
| 521 | - __declspec (dllexport) DWORD __stdcall hllapi_setcursor(WORD pos) | |
| 522 | - { | |
| 523 | - if(!(setcursor && hSession)) | |
| 524 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 525 | - trace("%s(%d)",__FUNCTION__,pos); | |
| 526 | - return setcursor(hSession,pos-1); | |
| 527 | - } | |
| 528 | - | |
| 529 | - __declspec (dllexport) DWORD __stdcall hllapi_getcursor() | |
| 530 | - { | |
| 531 | - if(!(getcursor && hSession)) | |
| 532 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 533 | - return getcursor(hSession)+1; | |
| 534 | - } | |
| 535 | - | |
| 536 | - __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD offset, LPSTR buffer, WORD len) | |
| 537 | - { | |
| 538 | - size_t szBuffer = strlen(buffer); | |
| 539 | - char * text; | |
| 540 | - | |
| 541 | - if(len < szBuffer && len > 0) | |
| 542 | - szBuffer = len; | |
| 543 | - | |
| 544 | - text = hllapi_get_string(offset, szBuffer); | |
| 545 | - if(!text) | |
| 546 | - { | |
| 547 | - int rc = hllapi_get_state(); | |
| 548 | - return rc == HLLAPI_STATUS_SUCCESS ? -1 : rc; | |
| 549 | - } | |
| 550 | - | |
| 551 | - memcpy(buffer,text,len); | |
| 552 | - | |
| 553 | - hllapi_free(text); | |
| 554 | - | |
| 555 | - return HLLAPI_STATUS_SUCCESS; | |
| 556 | - } | |
| 557 | - | |
| 558 | - __declspec (dllexport) DWORD __stdcall hllapi_emulate_input(LPSTR buffer, WORD len, WORD pasting) | |
| 559 | - { | |
| 560 | - | |
| 561 | - if(!(emulate_input && hSession)) | |
| 562 | - return HLLAPI_STATUS_DISCONNECTED; | |
| 563 | - trace("%s(%s)",__FUNCTION__,(char *) buffer); | |
| 564 | - | |
| 565 | - if(buffer && *buffer) | |
| 566 | - emulate_input(hSession, buffer, len, pasting); | |
| 567 | - | |
| 568 | - return HLLAPI_STATUS_SUCCESS; | |
| 569 | - } | |
| 570 | - | |
| 571 | - __declspec (dllexport) DWORD __stdcall hllapi_erase_eof(void) | |
| 572 | - { | |
| 573 | - if(!erase_eof && hSession) | |
| 574 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 575 | - trace("%s",__FUNCTION__); | |
| 576 | - return erase_eof(hSession); | |
| 577 | - } | |
| 578 | - | |
| 579 | - __declspec (dllexport) DWORD __stdcall hllapi_print(void) | |
| 580 | - { | |
| 581 | - if(!(do_print && hSession)) | |
| 582 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 583 | - | |
| 584 | - return do_print(hSession); | |
| 585 | - } | |
| 586 | - | |
| 587 | - char * hllapi_get_string(int offset, size_t len) | |
| 588 | - { | |
| 589 | - if(!(get_text_at_offset && hSession)) | |
| 590 | - return NULL; | |
| 591 | - | |
| 592 | - return get_text_at_offset(hSession,offset-1,len); | |
| 593 | - } | |
| 594 | - | |
| 595 | - void hllapi_free(void *p) | |
| 596 | - { | |
| 597 | - if(release_memory) | |
| 598 | - release_memory(p); | |
| 599 | - } |
| ... | ... | @@ -0,0 +1,329 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple | |
| 19 | + * Place, Suite 330, Boston, MA, 02111-1307, USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como calls.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include <exception> | |
| 31 | + #include <pw3270/class.h> | |
| 32 | + #include <pw3270/hllapi.h> | |
| 33 | + | |
| 34 | + #undef trace | |
| 35 | + #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); } } | |
| 36 | + | |
| 37 | + using namespace std; | |
| 38 | + using namespace PW3270_NAMESPACE; | |
| 39 | + | |
| 40 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
| 41 | + | |
| 42 | + static session * hSession = NULL; | |
| 43 | + | |
| 44 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 45 | + | |
| 46 | + __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode) | |
| 47 | + { | |
| 48 | + try | |
| 49 | + { | |
| 50 | + if(hSession) | |
| 51 | + delete hSession; | |
| 52 | + hSession = session::create(mode); | |
| 53 | + } | |
| 54 | + catch(std::exception &e) | |
| 55 | + { | |
| 56 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 57 | + } | |
| 58 | + | |
| 59 | + return hSession ? HLLAPI_STATUS_SUCCESS : HLLAPI_STATUS_SYSTEM_ERROR; | |
| 60 | + } | |
| 61 | + | |
| 62 | + __declspec (dllexport) DWORD __stdcall hllapi_deinit(void) | |
| 63 | + { | |
| 64 | + try | |
| 65 | + { | |
| 66 | + if(hSession) | |
| 67 | + { | |
| 68 | + delete hSession; | |
| 69 | + hSession = NULL; | |
| 70 | + } | |
| 71 | + } | |
| 72 | + catch(std::exception &e) | |
| 73 | + { | |
| 74 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 75 | + } | |
| 76 | + | |
| 77 | + return HLLAPI_STATUS_SUCCESS; | |
| 78 | + } | |
| 79 | + | |
| 80 | + __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void) | |
| 81 | + { | |
| 82 | + try | |
| 83 | + { | |
| 84 | + return atoi(session::get_default()->get_revision().c_str()); | |
| 85 | + } | |
| 86 | + catch(std::exception &e) | |
| 87 | + { | |
| 88 | + return -1; | |
| 89 | + } | |
| 90 | + return (DWORD) -1; | |
| 91 | + } | |
| 92 | + | |
| 93 | + __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait) | |
| 94 | + { | |
| 95 | + int rc = HLLAPI_STATUS_SUCCESS; | |
| 96 | + | |
| 97 | + try | |
| 98 | + { | |
| 99 | + rc = session::get_default()->connect(uri,wait); | |
| 100 | + } | |
| 101 | + catch(std::exception &e) | |
| 102 | + { | |
| 103 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 104 | + } | |
| 105 | + | |
| 106 | + return rc; | |
| 107 | + } | |
| 108 | + | |
| 109 | + __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void) | |
| 110 | + { | |
| 111 | + return session::get_default()->is_connected(); | |
| 112 | + } | |
| 113 | + | |
| 114 | + __declspec (dllexport) DWORD __stdcall hllapi_get_state(void) | |
| 115 | + { | |
| 116 | + switch(hllapi_get_message_id()) | |
| 117 | + { | |
| 118 | + case LIB3270_MESSAGE_NONE: /* 0 - No message */ | |
| 119 | + return HLLAPI_STATUS_SUCCESS; | |
| 120 | + | |
| 121 | + case LIB3270_MESSAGE_DISCONNECTED: /* 4 - Disconnected from host */ | |
| 122 | + return HLLAPI_STATUS_DISCONNECTED; | |
| 123 | + | |
| 124 | + case LIB3270_MESSAGE_MINUS: | |
| 125 | + case LIB3270_MESSAGE_PROTECTED: | |
| 126 | + case LIB3270_MESSAGE_NUMERIC: | |
| 127 | + case LIB3270_MESSAGE_OVERFLOW: | |
| 128 | + case LIB3270_MESSAGE_INHIBIT: | |
| 129 | + case LIB3270_MESSAGE_KYBDLOCK: | |
| 130 | + return HLLAPI_STATUS_KEYBOARD_LOCKED; | |
| 131 | + | |
| 132 | + case LIB3270_MESSAGE_SYSWAIT: | |
| 133 | + case LIB3270_MESSAGE_TWAIT: | |
| 134 | + case LIB3270_MESSAGE_AWAITING_FIRST: | |
| 135 | + case LIB3270_MESSAGE_X: | |
| 136 | + case LIB3270_MESSAGE_RESOLVING: | |
| 137 | + case LIB3270_MESSAGE_CONNECTING: | |
| 138 | + return HLLAPI_STATUS_WAITING; | |
| 139 | + } | |
| 140 | + | |
| 141 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 142 | + } | |
| 143 | + | |
| 144 | + __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void) | |
| 145 | + { | |
| 146 | + session::get_default()->disconnect(); | |
| 147 | + return HLLAPI_STATUS_SUCCESS; | |
| 148 | + } | |
| 149 | + | |
| 150 | + __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds) | |
| 151 | + { | |
| 152 | + return session::get_default()->wait_for_ready(seconds); | |
| 153 | + } | |
| 154 | + | |
| 155 | + __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds) | |
| 156 | + { | |
| 157 | + return session::get_default()->wait(seconds); | |
| 158 | + } | |
| 159 | + | |
| 160 | + __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void) | |
| 161 | + { | |
| 162 | + return session::get_default()->get_cstate(); | |
| 163 | + } | |
| 164 | + | |
| 165 | + __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer) | |
| 166 | + { | |
| 167 | + if(!(buffer && *buffer)) | |
| 168 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 169 | + | |
| 170 | + try | |
| 171 | + { | |
| 172 | + size_t sz = strlen(buffer); | |
| 173 | + string * str = session::get_default()->get_string_at(row,col,sz); | |
| 174 | + if(str) | |
| 175 | + { | |
| 176 | + strncpy(buffer,str->c_str(),sz); | |
| 177 | + delete str; | |
| 178 | + } | |
| 179 | + } | |
| 180 | + catch(std::exception &e) | |
| 181 | + { | |
| 182 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 183 | + } | |
| 184 | + | |
| 185 | + return HLLAPI_STATUS_SUCCESS; | |
| 186 | + } | |
| 187 | + | |
| 188 | + __declspec (dllexport) DWORD __stdcall hllapi_enter(void) | |
| 189 | + { | |
| 190 | + return session::get_default()->enter(); | |
| 191 | + } | |
| 192 | + | |
| 193 | + __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text) | |
| 194 | + { | |
| 195 | + try | |
| 196 | + { | |
| 197 | + session::get_default()->set_string_at(row,col,text); | |
| 198 | + } | |
| 199 | + catch(std::exception &e) | |
| 200 | + { | |
| 201 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 202 | + } | |
| 203 | + | |
| 204 | + return HLLAPI_STATUS_SUCCESS; | |
| 205 | + } | |
| 206 | + | |
| 207 | + __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text) | |
| 208 | + { | |
| 209 | + int rc = HLLAPI_STATUS_SYSTEM_ERROR; | |
| 210 | + try | |
| 211 | + { | |
| 212 | + rc = session::get_default()->cmp_string_at(row,col,text); | |
| 213 | + } | |
| 214 | + catch(std::exception &e) | |
| 215 | + { | |
| 216 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 217 | + } | |
| 218 | + | |
| 219 | + return rc; | |
| 220 | + } | |
| 221 | + | |
| 222 | + __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key) | |
| 223 | + { | |
| 224 | + return session::get_default()->pfkey(key); | |
| 225 | + } | |
| 226 | + | |
| 227 | + __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key) | |
| 228 | + { | |
| 229 | + return session::get_default()->pakey(key); | |
| 230 | + } | |
| 231 | + | |
| 232 | + __declspec (dllexport) DWORD __stdcall hllapi_get_datadir(LPSTR datadir) | |
| 233 | + { | |
| 234 | + HKEY hKey = 0; | |
| 235 | + unsigned long datalen = strlen(datadir); | |
| 236 | + | |
| 237 | + *datadir = 0; | |
| 238 | + | |
| 239 | + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) | |
| 240 | + { | |
| 241 | + unsigned long datatype; // #defined in winnt.h (predefined types 0-11) | |
| 242 | + if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) != ERROR_SUCCESS) | |
| 243 | + *datadir = 0; | |
| 244 | + RegCloseKey(hKey); | |
| 245 | + } | |
| 246 | + | |
| 247 | + return *datadir; | |
| 248 | + } | |
| 249 | + | |
| 250 | + __declspec (dllexport) DWORD __stdcall hllapi_setcursor(WORD pos) | |
| 251 | + { | |
| 252 | + return session::get_default()->set_cursor_addr(pos-1); | |
| 253 | + } | |
| 254 | + | |
| 255 | + __declspec (dllexport) DWORD __stdcall hllapi_getcursor() | |
| 256 | + { | |
| 257 | + return session::get_default()->get_cursor_addr()+1; | |
| 258 | + } | |
| 259 | + | |
| 260 | + __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD offset, LPSTR buffer, WORD len) | |
| 261 | + { | |
| 262 | + int rc = HLLAPI_STATUS_SYSTEM_ERROR; | |
| 263 | + | |
| 264 | + if(!(buffer && *buffer)) | |
| 265 | + return rc; | |
| 266 | + | |
| 267 | + try | |
| 268 | + { | |
| 269 | + size_t szBuffer = strlen(buffer); | |
| 270 | + | |
| 271 | + if(len < szBuffer && len > 0) | |
| 272 | + szBuffer = len; | |
| 273 | + | |
| 274 | + string *str = session::get_default()->get_string(offset,szBuffer); | |
| 275 | + if(str) | |
| 276 | + { | |
| 277 | + strncpy(buffer,str->c_str(),szBuffer); | |
| 278 | + delete str; | |
| 279 | + rc = HLLAPI_STATUS_SUCCESS; | |
| 280 | + } | |
| 281 | + } | |
| 282 | + catch(std::exception &e) | |
| 283 | + { | |
| 284 | + rc = HLLAPI_STATUS_SYSTEM_ERROR; | |
| 285 | + } | |
| 286 | + | |
| 287 | + return rc; | |
| 288 | + } | |
| 289 | + | |
| 290 | + __declspec (dllexport) DWORD __stdcall hllapi_emulate_input(LPSTR buffer, WORD len, WORD pasting) | |
| 291 | + { | |
| 292 | + session::get_default()->emulate_input(buffer); | |
| 293 | + return HLLAPI_STATUS_SUCCESS; | |
| 294 | + } | |
| 295 | + | |
| 296 | + __declspec (dllexport) DWORD __stdcall hllapi_erase_eof(void) | |
| 297 | + { | |
| 298 | + session::get_default()->erase_eof(); | |
| 299 | + return HLLAPI_STATUS_SUCCESS; | |
| 300 | + } | |
| 301 | + | |
| 302 | + __declspec (dllexport) DWORD __stdcall hllapi_print(void) | |
| 303 | + { | |
| 304 | + return session::get_default()->print(); | |
| 305 | + } | |
| 306 | + | |
| 307 | + char * hllapi_get_string(int offset, size_t len) | |
| 308 | + { | |
| 309 | + try | |
| 310 | + { | |
| 311 | + string *str = session::get_default()->get_string(offset-1,len); | |
| 312 | + if(str) | |
| 313 | + { | |
| 314 | + char * ret = strdup(str->c_str()); | |
| 315 | + delete str; | |
| 316 | + return ret; | |
| 317 | + } | |
| 318 | + } | |
| 319 | + catch(std::exception &e) | |
| 320 | + { | |
| 321 | + } | |
| 322 | + | |
| 323 | + return NULL; | |
| 324 | + } | |
| 325 | + | |
| 326 | + void hllapi_free(void *p) | |
| 327 | + { | |
| 328 | + free(p); | |
| 329 | + } | ... | ... |
src/plugins/hllapi/hllapi.c
| ... | ... | @@ -91,7 +91,7 @@ |
| 91 | 91 | LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc) |
| 92 | 92 | #endif // _WIN32 |
| 93 | 93 | { |
| 94 | - int f; | |
| 94 | + unsigned int f; | |
| 95 | 95 | |
| 96 | 96 | trace("%s(%d)",__FUNCTION__,*func); |
| 97 | 97 | |
| ... | ... | @@ -123,7 +123,7 @@ static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc) |
| 123 | 123 | { |
| 124 | 124 | int sz = strlen(buffer); |
| 125 | 125 | |
| 126 | - tempbuffer = malloc(sz+2); | |
| 126 | + tempbuffer = (char *) malloc(sz+2); | |
| 127 | 127 | strcpy(tempbuffer,buffer); |
| 128 | 128 | tempbuffer[sz-1] = ':'; |
| 129 | 129 | tempbuffer[sz] = buffer[sz-1]; |
| ... | ... | @@ -197,7 +197,7 @@ static int input_string(char *input, unsigned short *length, unsigned short *rc) |
| 197 | 197 | if(*length > 0 && *length < szText) |
| 198 | 198 | szText = *length; |
| 199 | 199 | |
| 200 | - text = malloc(szText+2); | |
| 200 | + text = (char *) malloc(szText+2); | |
| 201 | 201 | memcpy(text,input,szText); |
| 202 | 202 | text[szText] = 0; |
| 203 | 203 | ... | ... |
src/plugins/hllapi/hllapi.cbp
| ... | ... | @@ -37,9 +37,9 @@ |
| 37 | 37 | <Add option="-g" /> |
| 38 | 38 | </Compiler> |
| 39 | 39 | <Environment> |
| 40 | - <Variable name="LIB3270_CFLAGS" value='"-I../../../src/include"' /> | |
| 41 | - <Variable name="LIB3270_LIBS" value='"-L../../../.bin/Debug -l3270"' /> | |
| 42 | - <Variable name="PW3270_LIBS" value='"-L../../../.bin/Debug -lpw3270 -l3270"' /> | |
| 40 | + <Variable name="LIB3270_CFLAGS" value='"-I..\..\..\src\include"' /> | |
| 41 | + <Variable name="LIB3270_LIBS" value='"-L..\..\..\.bin\Debug -l3270"' /> | |
| 42 | + <Variable name="PW3270_LIBS" value='"-L..\..\..\.bin\Debug -lpw3270 -l3270"' /> | |
| 43 | 43 | </Environment> |
| 44 | 44 | <MakeCommands> |
| 45 | 45 | <Build command="$make LIB3270_MODE=Debug -f $makefile $target" /> |
| ... | ... | @@ -55,14 +55,11 @@ |
| 55 | 55 | <Add option="-Wall" /> |
| 56 | 56 | </Compiler> |
| 57 | 57 | <Unit filename="Makefile.in" /> |
| 58 | - <Unit filename="calls.c"> | |
| 59 | - <Option compilerVar="CC" /> | |
| 60 | - </Unit> | |
| 58 | + <Unit filename="calls.cc" /> | |
| 61 | 59 | <Unit filename="client.h" /> |
| 62 | 60 | <Unit filename="hllapi.c"> |
| 63 | 61 | <Option compilerVar="CC" /> |
| 64 | 62 | </Unit> |
| 65 | - <Unit filename="packets.h" /> | |
| 66 | 63 | <Unit filename="pluginmain.c"> |
| 67 | 64 | <Option compilerVar="CC" /> |
| 68 | 65 | </Unit> | ... | ... |
src/plugins/hllapi/pluginmain.c
| ... | ... | @@ -32,6 +32,7 @@ |
| 32 | 32 | */ |
| 33 | 33 | |
| 34 | 34 | #include "server.h" |
| 35 | + #include <windows.h> | |
| 35 | 36 | #include <pw3270/plugin.h> |
| 36 | 37 | #include <pw3270/v3270.h> |
| 37 | 38 | #include <pw3270/ipcpackets.h> |
| ... | ... | @@ -42,18 +43,20 @@ |
| 42 | 43 | |
| 43 | 44 | #pragma pack(1) |
| 44 | 45 | |
| 46 | + enum PIPE_STATE | |
| 47 | + { | |
| 48 | + PIPE_STATE_WAITING, | |
| 49 | + PIPE_STATE_READ, | |
| 50 | + PIPE_STATE_PENDING_READ, | |
| 51 | + PIPE_STATE_UNDEFINED | |
| 52 | + }; | |
| 53 | + | |
| 45 | 54 | typedef struct _pipe_source |
| 46 | 55 | { |
| 47 | 56 | GSource gsrc; |
| 48 | 57 | HANDLE hPipe; |
| 49 | 58 | |
| 50 | - enum _PIPE_STATE | |
| 51 | - { | |
| 52 | - PIPE_STATE_WAITING, | |
| 53 | - PIPE_STATE_READ, | |
| 54 | - PIPE_STATE_PENDING_READ, | |
| 55 | - PIPE_STATE_UNDEFINED, | |
| 56 | - } state; | |
| 59 | + enum PIPE_STATE state; | |
| 57 | 60 | |
| 58 | 61 | OVERLAPPED overlap; |
| 59 | 62 | unsigned char buffer[PIPE_BUFFER_LENGTH+1]; |
| ... | ... | @@ -145,7 +148,7 @@ |
| 145 | 148 | if(text) |
| 146 | 149 | { |
| 147 | 150 | szBlock = sizeof(struct hllapi_packet_text)+strlen(text); |
| 148 | - pkt = g_malloc0(szBlock); | |
| 151 | + pkt = (struct hllapi_packet_text *) g_malloc0(szBlock); | |
| 149 | 152 | pkt->packet_id = 0; |
| 150 | 153 | strcpy(pkt->text,text); |
| 151 | 154 | lib3270_free(text); |
| ... | ... | @@ -153,7 +156,7 @@ |
| 153 | 156 | else |
| 154 | 157 | { |
| 155 | 158 | szBlock = sizeof(struct hllapi_packet_text); |
| 156 | - pkt = g_malloc0(szBlock); | |
| 159 | + pkt = (struct hllapi_packet_text *) g_malloc0(szBlock); | |
| 157 | 160 | pkt->packet_id = errno ? errno : -1; |
| 158 | 161 | } |
| 159 | 162 | |
| ... | ... | @@ -280,7 +283,7 @@ |
| 280 | 283 | |
| 281 | 284 | case HLLAPI_PACKET_SET_TOGGLE: |
| 282 | 285 | send_result(source,lib3270_set_toggle(lib3270_get_default_session_handle(), |
| 283 | - ((struct hllapi_packet_set *) source->buffer)->id, | |
| 286 | + (LIB3270_TOGGLE) ((struct hllapi_packet_set *) source->buffer)->id, | |
| 284 | 287 | ((struct hllapi_packet_set *) source->buffer)->value)); |
| 285 | 288 | break; |
| 286 | 289 | |
| ... | ... | @@ -456,7 +459,7 @@ |
| 456 | 459 | |
| 457 | 460 | FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); |
| 458 | 461 | |
| 459 | - for(ptr=lpMsgBuf;*ptr && *ptr != '\n';ptr++); | |
| 462 | + for(ptr= (char *) lpMsgBuf;*ptr && *ptr != '\n';ptr++); | |
| 460 | 463 | *ptr = 0; |
| 461 | 464 | |
| 462 | 465 | va_start(arg_ptr, fmt); | ... | ... |
src/plugins/hllapi/testprogram.c
| ... | ... | @@ -27,7 +27,6 @@ |
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | - #include <windows.h> | |
| 31 | 30 | #include <stdio.h> |
| 32 | 31 | #include <time.h> |
| 33 | 32 | #include <pw3270/hllapi.h> |
| ... | ... | @@ -42,7 +41,7 @@ |
| 42 | 41 | |
| 43 | 42 | printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session)); |
| 44 | 43 | printf("revision=%d\n",(int) hllapi_get_revision()); |
| 45 | - printf("connect=%d\n",(int) hllapi_connect("fandezhi.efglobe.com:23",0)); | |
| 44 | + printf("connect=%d\n",(int) hllapi_connect((char *) "fandezhi.efglobe.com:23",0)); | |
| 46 | 45 | printf("wait=%d\n",(int) hllapi_wait(3)); |
| 47 | 46 | printf("connected=%s\n",(int) hllapi_is_connected() ? "Yes" : "No"); |
| 48 | 47 | ... | ... |