Commit 3337cc2a18fe62124dd3110614951c99f1dc2022

Authored by perry.werneck@gmail.com
1 parent a65fb47e

Melhorando plugin e servico HLLAPI

pw3270.cbp
... ... @@ -250,10 +250,14 @@
250 250 <Unit filename="src/plugins/remotectl/hllapi.c">
251 251 <Option compilerVar="CC" />
252 252 </Unit>
  253 + <Unit filename="src/plugins/remotectl/packets.h" />
253 254 <Unit filename="src/plugins/remotectl/pipesource.c">
254 255 <Option compilerVar="CC" />
255 256 </Unit>
256   - <Unit filename="src/plugins/remotectl/remotectl.c">
  257 + <Unit filename="src/plugins/remotectl/pluginmain.c">
  258 + <Option compilerVar="CC" />
  259 + </Unit>
  260 + <Unit filename="src/plugins/remotectl/remote.c">
257 261 <Option compilerVar="CC" />
258 262 </Unit>
259 263 <Unit filename="src/plugins/remotectl/remotectl.h" />
... ...
src/include/lib3270.h
... ... @@ -439,7 +439,7 @@
439 439 * @param h Session handle.
440 440 *
441 441 */
442   - LIB3270_EXPORT void lib3270_disconnect(H3270 *h);
  442 + LIB3270_EXPORT int lib3270_disconnect(H3270 *h);
443 443  
444 444 /**
445 445 * Reconnect.
... ... @@ -496,7 +496,7 @@
496 496  
497 497 #define lib3270_set_text_at(h,r,c,t) lib3270_set_string_at(h,r,c,t)
498 498 LIB3270_EXPORT int lib3270_set_string_at(H3270 *h, int row, int col, const unsigned char *str);
499   - LIB3270_EXPORT void lib3270_input_string(H3270 *hSession, const unsigned char *str);
  499 + LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *str);
500 500  
501 501 /**
502 502 * Set cursor address.
... ...
src/include/pw3270/hllapi.h
... ... @@ -38,11 +38,7 @@
38 38 extern "C" {
39 39 #endif
40 40  
41   - #define HLLAPI_REQUEST_QUERY 0x01
42   - #define HLLAPI_RESPONSE_VALUE 0x02
43   - #define HLLAPI_RESPONSE_TEXT 0x03
44   -
45   - #define HLLAPI_MAXLENGTH 32768
  41 + #define HLLAPI_MAXLENGTH 4096
46 42  
47 43 #define HLLAPI_CMD_CONNECTPS 1 /**< connect presentation space */
48 44 #define HLLAPI_CMD_DISCONNECTPS 2 /**< disconnect presentation space */
... ... @@ -58,43 +54,53 @@ extern &quot;C&quot; {
58 54 #define HLLAPI_CMD_RECEIVEFILE 91 /**< Receive a file from the host */
59 55  
60 56 #define HLLAPI_CMD_GETREVISION 2000 /**< Get lib3270 revision */
61   -
62   - #pragma pack(1)
63   - typedef struct _hllapi_data
64   - {
65   - unsigned char id; /**< Request id */
66   - unsigned long func; /**< Function number */
67   - unsigned short rc; /**< Short argument/return code */
68   - unsigned int value; /**< Requested value */
69   - char string[1]; /**< String argument */
70   - } HLLAPI_DATA;
71   -
72   - #pragma pack()
  57 +
  58 + typedef enum _hllapi_packet
  59 + {
  60 + HLLAPI_PACKET_CONNECT,
  61 + HLLAPI_PACKET_DISCONNECT,
  62 + HLLAPI_PACKET_GET_PROGRAM_MESSAGE,
  63 + HLLAPI_PACKET_GET_TEXT_AT,
  64 + HLLAPI_PACKET_SET_TEXT_AT,
  65 + HLLAPI_PACKET_CMP_TEXT_AT,
  66 + HLLAPI_PACKET_ENTER,
  67 + HLLAPI_PACKET_PFKEY,
  68 + HLLAPI_PACKET_PAKEY,
  69 + HLLAPI_PACKET_SET_CURSOR_POSITION,
  70 + HLLAPI_PACKET_GET_CURSOR_POSITION,
  71 + HLLAPI_PACKET_INPUT_STRING,
  72 +
  73 + HLLAPI_PACKET_INVALID
  74 +
  75 + } HLLAPI_PACKET;
  76 +
  77 +
73 78  
74 79 #ifdef _WIN32
75   - // http://www.mingw.org/wiki/Visual_Basic_DLL
76   - __declspec (dllexport) int __stdcall hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc);
  80 + // http://www.mingw.org/wiki/Visual_Basic_DLL
  81 + __declspec (dllexport) int __stdcall hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc);
77 82  
78   - __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode);
79   - __declspec (dllexport) DWORD __stdcall hllapi_deinit(void);
  83 + __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode);
  84 + __declspec (dllexport) DWORD __stdcall hllapi_deinit(void);
80 85  
81   - __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void);
  86 + __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void);
82 87  
83   - __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri);
84   - __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void);
85   - __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void);
86   - __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer);
87   - __declspec (dllexport) DWORD __stdcall hllapi_enter(void);
88   - __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text);
89   - __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text);
90   - __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds);
91   - __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds);
92   - __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key);
93   - __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key);
94   -
  88 + __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri);
  89 + __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void);
  90 + __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void);
  91 + __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer);
  92 + __declspec (dllexport) DWORD __stdcall hllapi_enter(void);
  93 + __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text);
  94 + __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text);
  95 + __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds);
  96 + __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds);
  97 + __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key);
  98 + __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key);
  99 +
  100 +#else
  101 +
  102 + #error NOT IMPLEMENTED
95 103  
96   -#else
97   - LIB3270_EXPORT int hllapi(const unsigned long *func, char *str, unsigned short *length, unsigned short *rc);
98 104 #endif // _WIN32
99 105  
100 106 #ifdef __cplusplus
... ...
src/lib3270/host.c
... ... @@ -494,9 +494,10 @@ static void try_reconnect(H3270 *session)
494 494 lib3270_reconnect(session,0);
495 495 }
496 496  
497   -LIB3270_EXPORT void lib3270_disconnect(H3270 *h)
  497 +LIB3270_EXPORT int lib3270_disconnect(H3270 *h)
498 498 {
499   - host_disconnect(h,0);
  499 + host_disconnect(h,0);
  500 + return 0;
500 501 }
501 502  
502 503 void host_disconnect(H3270 *hSession, int failed)
... ...
src/lib3270/kybd.c
... ... @@ -998,7 +998,7 @@ static Boolean key_Character(H3270 *hSession, int code, Boolean with_ge, Boolean
998 998 }
999 999  
1000 1000  
1001   -LIB3270_EXPORT void lib3270_input_string(H3270 *hSession, const unsigned char *str)
  1001 +LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *str)
1002 1002 {
1003 1003 while(*str)
1004 1004 {
... ... @@ -1006,7 +1006,9 @@ LIB3270_EXPORT void lib3270_input_string(H3270 *hSession, const unsigned char *s
1006 1006 str++;
1007 1007 }
1008 1008  
1009   - screen_update(hSession,0,hSession->rows*hSession->cols);
  1009 + screen_update(hSession,0,hSession->rows*hSession->cols);
  1010 +
  1011 + return 0;
1010 1012 }
1011 1013  
1012 1014 /**
... ...
src/plugins/remotectl/Makefile.in
... ... @@ -30,8 +30,8 @@
30 30  
31 31 MODULE_NAME=remotectl
32 32 DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile
33   -PLUGIN_SRC=remotectl.c pipesource.c
34   -HLLAPI_SRC=hllapi.c calls.c
  33 +PLUGIN_SRC=pluginmain.c
  34 +HLLAPI_SRC=hllapi.c calls.c remote.c
35 35  
36 36 #---[ Paths ]------------------------------------------------------------------
37 37  
... ... @@ -126,13 +126,15 @@ $(BINDBG)/libhllapi@DLLEXT@: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJDBG)
126 126  
127 127 #---[ Misc targets ]-----------------------------------------------------------
128 128  
129   -testprogram@EXEEXT@: testprogram.c
  129 +$(BINDBG)/testprogram@EXEEXT@: testprogram.c $(BINDBG)/libhllapi@DLLEXT@
130 130 @echo " CCLD `basename $@`"
131 131 @$(MKDIR) `dirname $@`
132   - @$(CC) $(CFLAGS) -I../../../src/include -L../../../$(BINDIR)/Debug $(DEBUG_CFLAGS) -lhllapi -o $@ $<
  132 + @$(CC) $(CFLAGS) $(PW3270_CFLAGS) -L$(BINDBG) $(DEBUG_CFLAGS) -lhllapi -o $@ testprogram.c
133 133  
134   -test: testprogram@EXEEXT@
135   - @PATH="../../../$(BINDIR)/Debug:$(PATH)" ./testprogram@EXEEXT@
  134 +test: $(BINDBG)/testprogram@EXEEXT@
  135 +
  136 +run: $(BINDBG)/testprogram@EXEEXT@
  137 + @cd $(BINDBG) ; ./testprogram@EXEEXT@
136 138  
137 139 install: $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@
138 140 @$(MKDIR) $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins
... ...
src/plugins/remotectl/calls.c
... ... @@ -34,62 +34,56 @@
34 34 #include <errno.h>
35 35 #include <pw3270/hllapi.h>
36 36 #include <stdio.h>
37   - #include <lib3270/log.h>
  37 + #include <lib3270/log.h>
  38 + #include "client.h"
38 39  
39 40 /*--[ Globals ]--------------------------------------------------------------------------------------*/
40 41  
41 42 HMODULE hModule = NULL;
42   - H3270 * hSession = NULL;
  43 + void * hSession = NULL;
43 44  
44   - static H3270 * (*session_new)(const char *model) = NULL;
45   - static void (*session_free)(H3270 *h) = NULL;
  45 + static void * (*session_new)(const char *model) = NULL;
  46 + static void (*session_free)(void *h) = NULL;
46 47 static const char * (*get_revision)(void) = NULL;
47   - static int (*host_connect)(H3270 *h,const char *n, int wait) = NULL;
48   - static int (*wait_for_ready)(H3270 *h, int seconds) = NULL;
49   - static void (*host_disconnect)(H3270 *h) = NULL;
50   - static int (*script_sleep)(H3270 *h, int seconds) = NULL;
51   - static LIB3270_MESSAGE (*get_message)(H3270 *h) = NULL;
52   - static char * (*get_text)(H3270 *h, int row, int col, int len) = NULL;
  48 + static int (*host_connect)(void *h,const char *n, int wait) = NULL;
  49 + static int (*wait_for_ready)(void *h, int seconds) = NULL;
  50 + static void (*host_disconnect)(void *h) = NULL;
  51 + static int (*script_sleep)(void *h, int seconds) = NULL;
  52 + static LIB3270_MESSAGE (*get_message)(void *h) = NULL;
  53 + static char * (*get_text)(void *h, int row, int col, int len) = NULL;
53 54 static void * (*release_memory)(void *p) = NULL;
54   - static int (*action_enter)(H3270 *h) = NULL;
55   - static int (*set_text_at)(H3270 *h, int row, int col, const unsigned char *str) = NULL;
56   - static int (*cmp_text_at)(H3270 *h, int row, int col, const char *text) = NULL;
57   - static int (*pfkey)(H3270 *hSession, int key) = NULL;
58   - static int (*pakey)(H3270 *hSession, int key) = NULL;
  55 + static int (*action_enter)(void *h) = NULL;
  56 + static int (*set_text_at)(void *h, int row, int col, const unsigned char *str) = NULL;
  57 + static int (*cmp_text_at)(void *h, int row, int col, const char *text) = NULL;
  58 + static int (*pfkey)(void *hSession, int key) = NULL;
  59 + static int (*pakey)(void *hSession, int key) = NULL;
59 60  
60 61 static const struct _entry_point
61 62 {
62 63 void **call;
  64 + void * pipe;
63 65 const char * name;
64 66 } entry_point[] =
65 67 {
66   - { (void **) &session_new, "lib3270_session_new" },
67   - { (void **) &session_free, "lib3270_session_free" },
68   - { (void **) &get_revision, "lib3270_get_revision" },
69   - { (void **) &host_connect, "lib3270_connect" },
70   - { (void **) &host_disconnect, "lib3270_disconnect" },
71   - { (void **) &wait_for_ready, "lib3270_wait_for_ready" },
72   - { (void **) &script_sleep, "lib3270_wait" },
73   - { (void **) &get_message, "lib3270_get_program_message" },
74   - { (void **) &get_text, "lib3270_get_text_at" },
75   - { (void **) &release_memory, "lib3270_free" },
76   - { (void **) &action_enter, "lib3270_enter" },
77   - { (void **) &set_text_at, "lib3270_set_string_at" },
78   - { (void **) &cmp_text_at, "lib3270_cmp_text_at" },
79   - { (void **) &pfkey, "lib3270_pfkey" },
80   - { (void **) &pakey, "lib3270_pakey" },
  68 + { (void **) &session_new, (void *) hllapi_pipe_init, "lib3270_session_new" },
  69 + { (void **) &session_free, (void *) hllapi_pipe_deinit, "lib3270_session_free" },
  70 + { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" },
  71 + { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" },
  72 + { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" },
  73 + { (void **) &wait_for_ready, (void *) NULL, "lib3270_wait_for_ready" },
  74 + { (void **) &script_sleep, (void *) NULL, "lib3270_wait" },
  75 + { (void **) &get_message, (void *) NULL, "lib3270_get_program_message" },
  76 + { (void **) &get_text, (void *) NULL, "lib3270_get_text_at" },
  77 + { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" },
  78 + { (void **) &action_enter, (void *) NULL, "lib3270_enter" },
  79 + { (void **) &set_text_at, (void *) NULL, "lib3270_set_string_at" },
  80 + { (void **) &cmp_text_at, (void *) NULL, "lib3270_cmp_text_at" },
  81 + { (void **) &pfkey, (void *) NULL, "lib3270_pfkey" },
  82 + { (void **) &pakey, (void *) NULL, "lib3270_pakey" },
81 83  
82 84 { NULL, NULL }
83 85 };
84 86  
85   -#undef trace
86   -
87   -#ifdef DEBUG
88   - #define trace(...) { FILE *__dbg = fopen("c:\\users\\perry\\debug.txt","a"); if(__dbg) { fprintf(__dbg,__VA_ARGS__); fclose(__dbg); }; }
89   -#else
90   - #define trace(...) /* */
91   -#endif // DEBUG
92   -
93 87 #ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
94 88 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx
95 89 #define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000
... ... @@ -102,22 +96,30 @@
102 96 if(!mode)
103 97 return EINVAL;
104 98  
105   - if(hModule)
106   - return EBUSY;
  99 + trace("%s(%s)",__FUNCTION__,(char *) mode);
107 100  
108 101 if(!(mode && *mode))
109 102 {
110 103 // Direct mode, load lib3270.dll, get pointers to the calls
111 104 int f;
112 105 HKEY hKey = 0;
113   - HMODULE kernel = LoadLibrary("kernel32.dll");
  106 + HMODULE kernel;
114 107 HANDLE cookie = NULL;
115 108 DWORD rc;
116   - HANDLE (*AddDllDirectory)(PCWSTR NewDirectory) = (HANDLE (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory");
117   - BOOL (*RemoveDllDirectory)(HANDLE Cookie) = (BOOL (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory");
  109 + HANDLE (*AddDllDirectory)(PCWSTR NewDirectory);
  110 + BOOL (*RemoveDllDirectory)(HANDLE Cookie);
  111 + UINT errorMode;
  112 +
  113 + trace("hModule=%p",hModule);
  114 + if(hModule)
  115 + return EBUSY;
  116 +
  117 + kernel = LoadLibrary("kernel32.dll");
  118 + AddDllDirectory = (HANDLE (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory");
  119 + RemoveDllDirectory = (BOOL (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory");
118 120  
119 121 // Notify user in case of error loading protocol DLL
120   - UINT errorMode = SetErrorMode(0);
  122 + errorMode = SetErrorMode(0);
121 123  
122 124 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS)
123 125 {
... ... @@ -138,6 +140,7 @@
138 140  
139 141 hModule = LoadLibraryEx("lib3270.dll.5.0",NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
140 142 rc = GetLastError();
  143 + trace("hModule=%p rc=%d",hModule,(int) rc);
141 144  
142 145 SetErrorMode(errorMode);
143 146  
... ... @@ -166,18 +169,22 @@
166 169 *entry_point[f].call = ptr;
167 170 }
168 171  
169   - // Get session handle
170   - hSession = session_new("");
  172 + }
  173 + else
  174 + {
  175 + // Get pointers to the pipe based calls
  176 + int f;
171 177  
172   - trace("%s ok hSession=%p\n",__FUNCTION__,hSession);
  178 + for(f=0;entry_point[f].name;f++)
  179 + *entry_point[f].call = entry_point[f].pipe;
173 180  
174   - return 0;
175 181 }
176 182  
177   - // Set entry points to pipe based calls
178   -
  183 + // Get session handle
  184 + hSession = session_new((const char *) mode);
  185 + trace("%s ok hSession=%p\n",__FUNCTION__,hSession);
179 186  
180   - return -1;
  187 + return hSession ? 0 : -1;
181 188 }
182 189  
183 190 __declspec (dllexport) DWORD __stdcall hllapi_deinit(void)
... ...
src/plugins/remotectl/client.h 0 → 100644
... ... @@ -0,0 +1,58 @@
  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 private.h 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 <pw3270/hllapi.h>
  32 +
  33 + #ifndef ETIMEDOUT
  34 + #define ETIMEDOUT 1238
  35 + #endif // ETIMEDOUT
  36 +
  37 + #define PIPE_BUFFER_LENGTH 8192
  38 +
  39 + #define set_active(x) /* x */
  40 +
  41 + void * hllapi_pipe_init(const char *id);
  42 + void hllapi_pipe_deinit(void *h);
  43 + const char * hllapi_pipe_get_revision(void);
  44 + void hllapi_pipe_release_memory(void *p);
  45 + int hllapi_pipe_connect(void *h, const char *n, int wait);
  46 + void hllapi_pipe_disconnect(void *h);
  47 +
  48 +/*
  49 + int hllapi_pipe_wait_for_ready(void *h, int seconds);
  50 + int hllapi_pipe_sleep(void *h, int seconds);
  51 + LIB3270_MESSAGE hllapi_pipe_get_message(void *h);
  52 + char * hllapi_pipe_get_text(void *h, int row, int col, int len);
  53 + int hllapi_pipe_enter(void *h);
  54 + int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str);
  55 + int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text);
  56 + int hllapi_pipe_pfkey(void *h, int key);
  57 + int hllapi_pipe_pakey(void *h, int key);
  58 +*/
... ...
src/plugins/remotectl/hllapi.c
... ... @@ -37,14 +37,22 @@
37 37  
38 38 /*--[ Globals ]--------------------------------------------------------------------------------------*/
39 39  
40   -#ifdef WIN32
41   -
42   - static HANDLE hPipe = INVALID_HANDLE_VALUE;
43   -
44   -#endif // WIN32
  40 +// static HANDLE hPipe = INVALID_HANDLE_VALUE;
45 41  
46 42 /*--[ Implement ]------------------------------------------------------------------------------------*/
47   -
  43 +
  44 +#ifdef _WIN32
  45 + __declspec (dllexport) int __stdcall hllapi(LPWORD func, LPSTR buffer, LPWORD length, LPWORD rc)
  46 +#else
  47 + LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc)
  48 +#endif // _WIN32
  49 +{
  50 +
  51 +
  52 + return -1;
  53 +}
  54 +
  55 +/*
48 56 static int cmd_connect_ps(const char *name)
49 57 {
50 58 #ifdef WIN32
... ... @@ -237,3 +245,4 @@
237 245 return 0;
238 246 }
239 247  
  248 +*/
... ...
src/plugins/remotectl/hllapi.cbp 0 → 100644
... ... @@ -0,0 +1,84 @@
  1 +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
  2 +<CodeBlocks_project_file>
  3 + <FileVersion major="1" minor="6" />
  4 + <Project>
  5 + <Option title="pw3270 HLLAPI" />
  6 + <Option makefile_is_custom="1" />
  7 + <Option pch_mode="2" />
  8 + <Option compiler="gcc" />
  9 + <Build>
  10 + <Target title="Debug">
  11 + <Option output=".bin/Debug/pw3270 HLLAPI" prefix_auto="1" extension_auto="1" />
  12 + <Option object_output=".obj/Debug/" />
  13 + <Option type="1" />
  14 + <Option compiler="gcc" />
  15 + <Compiler>
  16 + <Add option="-g" />
  17 + </Compiler>
  18 + </Target>
  19 + <Target title="Release">
  20 + <Option output=".bin/Release/pw3270 HLLAPI" prefix_auto="1" extension_auto="1" />
  21 + <Option object_output=".obj/Release/" />
  22 + <Option type="1" />
  23 + <Option compiler="gcc" />
  24 + <Compiler>
  25 + <Add option="-O2" />
  26 + </Compiler>
  27 + <Linker>
  28 + <Add option="-s" />
  29 + </Linker>
  30 + </Target>
  31 + <Target title="test">
  32 + <Option output=".bin/Debug/testprogram" prefix_auto="1" extension_auto="1" />
  33 + <Option object_output=".obj/Debug/" />
  34 + <Option type="1" />
  35 + <Option compiler="gcc" />
  36 + <Compiler>
  37 + <Add option="-g" />
  38 + </Compiler>
  39 + <Environment>
  40 + <Variable name="LIB3270_CFLAGS" value='&quot;-I../../../src/include&quot;' />
  41 + <Variable name="LIB3270_LIBS" value='&quot;-L../../../.bin/Debug -l3270&quot;' />
  42 + <Variable name="PW3270_LIBS" value='&quot;-L../../../.bin/Debug -lpw3270 -l3270&quot;' />
  43 + </Environment>
  44 + <MakeCommands>
  45 + <Build command="$make LIB3270_MODE=Debug -f $makefile $target" />
  46 + <CompileFile command="$make -f $makefile $file" />
  47 + <Clean command="$make -f $makefile clean$target" />
  48 + <DistClean command="$make -f $makefile distclean$target" />
  49 + <AskRebuildNeeded command="$make -q -f $makefile $target" />
  50 + <SilentBuild command="$make LIB3270_MODE=Debug -f $makefile $target &gt; $(CMD_NULL)" />
  51 + </MakeCommands>
  52 + </Target>
  53 + </Build>
  54 + <Compiler>
  55 + <Add option="-Wall" />
  56 + </Compiler>
  57 + <Unit filename="Makefile.in" />
  58 + <Unit filename="calls.c">
  59 + <Option compilerVar="CC" />
  60 + </Unit>
  61 + <Unit filename="client.h" />
  62 + <Unit filename="hllapi.c">
  63 + <Option compilerVar="CC" />
  64 + </Unit>
  65 + <Unit filename="packets.h" />
  66 + <Unit filename="pluginmain.c">
  67 + <Option compilerVar="CC" />
  68 + </Unit>
  69 + <Unit filename="remote.c">
  70 + <Option compilerVar="CC" />
  71 + </Unit>
  72 + <Unit filename="remotectl.h" />
  73 + <Unit filename="server.h" />
  74 + <Unit filename="testprogram.c">
  75 + <Option compilerVar="CC" />
  76 + </Unit>
  77 + <Extensions>
  78 + <code_completion />
  79 + <envvars />
  80 + <debugger />
  81 + <lib_finder disable_auto="1" />
  82 + </Extensions>
  83 + </Project>
  84 +</CodeBlocks_project_file>
... ...
src/plugins/remotectl/packets.h 0 → 100644
... ... @@ -0,0 +1,78 @@
  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 packets.h 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 +#pragma pack(1)
  31 +
  32 +struct hllapi_packet_result
  33 +{
  34 + int rc;
  35 +};
  36 +
  37 +struct hllapi_packet_query
  38 +{
  39 + unsigned char packet_id;
  40 +};
  41 +
  42 +struct hllapi_packet_connect
  43 +{
  44 + unsigned char packet_id;
  45 + unsigned char wait;
  46 + char hostname[1];
  47 +};
  48 +
  49 +struct hllapi_packet_keycode
  50 +{
  51 + unsigned char packet_id;
  52 + unsigned short keycode;
  53 +};
  54 +
  55 +struct hllapi_packet_cursor
  56 +{
  57 + unsigned char packet_id;
  58 + unsigned short row;
  59 + unsigned short col;
  60 +};
  61 +
  62 +struct hllapi_packet_text
  63 +{
  64 + unsigned char packet_id;
  65 + char text[1];
  66 +};
  67 +
  68 +
  69 +struct hllapi_packet_text_at
  70 +{
  71 + unsigned char packet_id;
  72 + unsigned short row;
  73 + unsigned short col;
  74 + char text[1];
  75 +};
  76 +
  77 +#pragma pack()
  78 +
... ...
src/plugins/remotectl/pipesource.c
... ... @@ -32,8 +32,6 @@
32 32 #include <pw3270.h>
33 33 #include <pw3270/v3270.h>
34 34  
35   -#ifdef WIN32
36   -
37 35 #include <windows.h>
38 36 #include <stdarg.h>
39 37 #include "remotectl.h"
... ... @@ -385,4 +383,3 @@ static void wait_for_client(pipe_source *source)
385 383 return;
386 384 }
387 385  
388   -#endif // WIN32
... ...
src/plugins/remotectl/pluginmain.c 0 → 100644
... ... @@ -0,0 +1,763 @@
  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. 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., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como pluginmain.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 + * Agradecimento:
  29 + *
  30 + * Hélio Passos
  31 + *
  32 + */
  33 +
  34 + #include "server.h"
  35 + #include "packets.h"
  36 + #include <lib3270/actions.h>
  37 +
  38 +/*--[ Defines ]--------------------------------------------------------------------------------------*/
  39 +
  40 + #pragma pack(1)
  41 +
  42 + typedef struct _pipe_source
  43 + {
  44 + GSource gsrc;
  45 + HANDLE hPipe;
  46 +
  47 + enum _PIPE_STATE
  48 + {
  49 + PIPE_STATE_WAITING,
  50 + PIPE_STATE_READ,
  51 + PIPE_STATE_PENDING_READ,
  52 + PIPE_STATE_UNDEFINED,
  53 + } state;
  54 +
  55 + OVERLAPPED overlap;
  56 + unsigned char buffer[PIPE_BUFFER_LENGTH+1];
  57 + } pipe_source;
  58 +
  59 + #pragma pack()
  60 +
  61 +
  62 +/*--[ Globals ]--------------------------------------------------------------------------------------*/
  63 +
  64 + static const gchar control_char = '@';
  65 +
  66 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  67 +
  68 + static void IO_accept(pipe_source *source)
  69 + {
  70 + set_active(FALSE);
  71 +
  72 + if(ConnectNamedPipe(source->hPipe,&source->overlap))
  73 + {
  74 + popup_lasterror("%s",_( "Error in ConnectNamedPipe" ));
  75 + return;
  76 + }
  77 +
  78 + switch(GetLastError())
  79 + {
  80 + // The overlapped connection in progress.
  81 + case ERROR_IO_PENDING:
  82 + // trace("%s: ERROR_IO_PENDING",__FUNCTION__);
  83 + source->state = PIPE_STATE_WAITING;
  84 + break;
  85 +
  86 + // Client is already connected, so signal an event.
  87 + case ERROR_PIPE_CONNECTED:
  88 + trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__);
  89 + set_active(TRUE);
  90 + if(SetEvent(source->overlap.hEvent))
  91 + break;
  92 +
  93 + // If an error occurs during the connect operation...
  94 + default:
  95 + popup_lasterror("%s", _( "ConnectNamedPipe failed" ));
  96 + }
  97 +
  98 + }
  99 +
  100 + static gboolean IO_prepare(GSource *source, gint *timeout)
  101 + {
  102 + /*
  103 + * Called before all the file descriptors are polled.
  104 + * If the source can determine that it is ready here
  105 + * (without waiting for the results of the poll() call)
  106 + * it should return TRUE.
  107 + *
  108 + * It can also return a timeout_ value which should be the maximum
  109 + * timeout (in milliseconds) which should be passed to the poll() call.
  110 + * The actual timeout used will be -1 if all sources returned -1,
  111 + * or it will be the minimum of all the timeout_ values
  112 + * returned which were >= 0.
  113 + *
  114 + */
  115 + if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0)
  116 + return TRUE;
  117 +
  118 + *timeout = 10;
  119 + return FALSE;
  120 + }
  121 +
  122 + static gboolean IO_check(GSource *source)
  123 + {
  124 + /*
  125 + * Called after all the file descriptors are polled.
  126 + * The source should return TRUE if it is ready to be dispatched.
  127 + * Note that some time may have passed since the previous prepare
  128 + * function was called, so the source should be checked again here.
  129 + *
  130 + */
  131 + if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0)
  132 + return TRUE;
  133 +
  134 + return FALSE;
  135 + }
  136 +
  137 +/*
  138 + static void send_message(pipe_source *source, const void *pkt, int sz)
  139 + {
  140 + WriteFile(qry->hPipe,&data,wrote,&wrote,NULL);
  141 +
  142 + }
  143 +*/
  144 +
  145 + static void send_result(pipe_source *source, int rc)
  146 + {
  147 + struct hllapi_packet_result pkt = { rc };
  148 + DWORD wrote = sizeof(pkt);
  149 + WriteFile(source->hPipe,&pkt,wrote,&wrote,NULL);
  150 + }
  151 +
  152 + static void process_input(pipe_source *source, DWORD cbRead)
  153 + {
  154 +
  155 + trace("%s id=%d",__FUNCTION__,source->buffer[0]);
  156 +
  157 + switch(source->buffer[0])
  158 + {
  159 + case HLLAPI_PACKET_CONNECT:
  160 + send_result(source,lib3270_connect( lib3270_get_default_session_handle(),
  161 + ((struct hllapi_packet_connect *) source->buffer)->hostname,
  162 + ((struct hllapi_packet_connect *) source->buffer)->wait));
  163 + break;
  164 +
  165 + case HLLAPI_PACKET_DISCONNECT:
  166 + send_result(source,lib3270_disconnect(lib3270_get_default_session_handle()));
  167 + break;
  168 +
  169 + case HLLAPI_PACKET_GET_PROGRAM_MESSAGE:
  170 + send_result(source,lib3270_get_program_message(lib3270_get_default_session_handle()));
  171 + break;
  172 +
  173 + case HLLAPI_PACKET_ENTER:
  174 + send_result(source,lib3270_enter(lib3270_get_default_session_handle()));
  175 + break;
  176 +
  177 + case HLLAPI_PACKET_PFKEY:
  178 + send_result(source,lib3270_pfkey( lib3270_get_default_session_handle(),
  179 + ((struct hllapi_packet_keycode *) source->buffer)->keycode));
  180 + break;
  181 +
  182 + case HLLAPI_PACKET_PAKEY:
  183 + send_result(source,lib3270_pakey( lib3270_get_default_session_handle(),
  184 + ((struct hllapi_packet_keycode *) source->buffer)->keycode));
  185 + break;
  186 +
  187 + case HLLAPI_PACKET_SET_CURSOR_POSITION:
  188 + send_result(source,lib3270_set_cursor_position( lib3270_get_default_session_handle(),
  189 + ((struct hllapi_packet_cursor *) source->buffer)->row,
  190 + ((struct hllapi_packet_cursor *) source->buffer)->col));
  191 + break;
  192 +
  193 + case HLLAPI_PACKET_SET_TEXT_AT:
  194 + send_result(source,lib3270_set_text_at( lib3270_get_default_session_handle(),
  195 + ((struct hllapi_packet_text_at *) source->buffer)->row,
  196 + ((struct hllapi_packet_text_at *) source->buffer)->col,
  197 + (unsigned char *) ((struct hllapi_packet_text_at *) source->buffer)->text));
  198 + break;
  199 +
  200 + case HLLAPI_PACKET_CMP_TEXT_AT:
  201 + send_result(source,lib3270_cmp_text_at( lib3270_get_default_session_handle(),
  202 + ((struct hllapi_packet_text_at *) source->buffer)->row,
  203 + ((struct hllapi_packet_text_at *) source->buffer)->col,
  204 + ((struct hllapi_packet_text_at *) source->buffer)->text));
  205 + break;
  206 +
  207 + case HLLAPI_PACKET_INPUT_STRING:
  208 + send_result(source,lib3270_input_string(lib3270_get_default_session_handle(),
  209 + (unsigned char *) ((struct hllapi_packet_text *) source->buffer)->text));
  210 + break;
  211 +
  212 + default:
  213 + send_result(source, EINVAL);
  214 + g_message("Invalid remote request (id=%d)",source->buffer[0]);
  215 + }
  216 +
  217 + }
  218 +
  219 + static void read_input_pipe(pipe_source *source)
  220 + {
  221 + DWORD cbRead = 0;
  222 +
  223 + if(ReadFile(source->hPipe,source->buffer,PIPE_BUFFER_LENGTH,&cbRead,&source->overlap) && cbRead > 0)
  224 + process_input(source,cbRead);
  225 +
  226 + // The read operation is still pending.
  227 + switch(GetLastError())
  228 + {
  229 + case 0:
  230 + break;
  231 +
  232 + case ERROR_IO_PENDING:
  233 + // trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__);
  234 + source->state = PIPE_STATE_PENDING_READ;
  235 + break;
  236 +
  237 + case ERROR_PIPE_LISTENING:
  238 + // trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__);
  239 + source->state = PIPE_STATE_READ;
  240 + break;
  241 +
  242 + case ERROR_BROKEN_PIPE:
  243 + trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__);
  244 +
  245 + if(!DisconnectNamedPipe(source->hPipe))
  246 + {
  247 + set_active(FALSE);
  248 + popup_lasterror("%s",_( "Error in DisconnectNamedPipe" ));
  249 + }
  250 + else
  251 + {
  252 + IO_accept(source);
  253 + }
  254 + break;
  255 +
  256 + case ERROR_PIPE_NOT_CONNECTED:
  257 + trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__);
  258 + set_active(FALSE);
  259 + break;
  260 +
  261 + default:
  262 + if(source->hPipe != INVALID_HANDLE_VALUE)
  263 + popup_lasterror("%s",_( "Error receiving message from pipe" ) );
  264 + }
  265 +
  266 + }
  267 +
  268 + static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer data)
  269 + {
  270 + /*
  271 + * Called to dispatch the event source,
  272 + * after it has returned TRUE in either its prepare or its check function.
  273 + * The dispatch function is passed in a callback function and data.
  274 + * The callback function may be NULL if the source was never connected
  275 + * to a callback using g_source_set_callback(). The dispatch function
  276 + * should call the callback function with user_data and whatever additional
  277 + * parameters are needed for this type of event source.
  278 + */
  279 + BOOL fSuccess;
  280 + DWORD cbRead = 0;
  281 +// DWORD dwErr = 0;
  282 +
  283 + fSuccess = GetOverlappedResult(((pipe_source *) source)->hPipe,&((pipe_source *) source)->overlap,&cbRead,FALSE );
  284 +
  285 + // trace("%s: source=%p data=%p Result=%s cbRead=%d",__FUNCTION__,source,data,fSuccess ? "Success" : "Unsuccess",(int) cbRead);
  286 +
  287 + switch(((pipe_source *) source)->state)
  288 + {
  289 + case PIPE_STATE_WAITING:
  290 + if(fSuccess)
  291 + {
  292 + trace("Pipe connected (cbRet=%d)",(int) cbRead);
  293 + set_active(TRUE);
  294 + ((pipe_source *) source)->state = PIPE_STATE_READ;
  295 + }
  296 + else
  297 + {
  298 + popup_lasterror("%s", _( "Pipe connection failed" ));
  299 + }
  300 + break;
  301 +
  302 + case PIPE_STATE_READ:
  303 + // trace("Reading pipe (cbRead=%d)",(int) cbRead);
  304 + read_input_pipe( (pipe_source *) source);
  305 + break;
  306 +
  307 + case PIPE_STATE_PENDING_READ:
  308 + if(fSuccess && cbRead > 0)
  309 + process_input((pipe_source *) source,cbRead);
  310 + ((pipe_source *) source)->state = PIPE_STATE_READ;
  311 + break;
  312 +
  313 + case PIPE_STATE_UNDEFINED:
  314 + break;
  315 +
  316 +//#ifdef DEBUG
  317 +// default:
  318 +// trace("%s: source=%p data=%p Unexpected mode %d",__FUNCTION__,source,data,((pipe_source *) source)->state);
  319 +//#endif
  320 + }
  321 +
  322 + return TRUE;
  323 + }
  324 +
  325 + static void IO_finalize(GSource *source)
  326 + {
  327 +// trace("%s: source=%p",__FUNCTION__,source);
  328 +
  329 + if( ((pipe_source *) source)->hPipe != INVALID_HANDLE_VALUE)
  330 + {
  331 + CloseHandle(((pipe_source *) source)->hPipe);
  332 + ((pipe_source *) source)->hPipe = INVALID_HANDLE_VALUE;
  333 + }
  334 +
  335 + }
  336 +
  337 + static gboolean IO_closure(gpointer data)
  338 + {
  339 +// trace("%s: data=%p",__FUNCTION__,data);
  340 + return 0;
  341 + }
  342 +
  343 + void popup_lasterror(const gchar *fmt, ...)
  344 + {
  345 + char buffer[4096];
  346 + va_list arg_ptr;
  347 + int sz;
  348 + DWORD errcode = GetLastError();
  349 + char *ptr;
  350 + LPVOID lpMsgBuf = 0;
  351 +
  352 + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
  353 +
  354 + for(ptr=lpMsgBuf;*ptr && *ptr != '\n';ptr++);
  355 + *ptr = 0;
  356 +
  357 + va_start(arg_ptr, fmt);
  358 + vsnprintf(buffer,4095,fmt,arg_ptr);
  359 + va_end(arg_ptr);
  360 +
  361 + sz = strlen(buffer);
  362 + snprintf(buffer+sz,4096-sz,": %s\n(rc=%d)",lpMsgBuf,(int) errcode);
  363 +
  364 + printf("%s\n",buffer);
  365 +
  366 +#ifdef DEBUG
  367 + fprintf(stderr,"%s\n",buffer);
  368 + fflush(stderr);
  369 +#endif
  370 +
  371 + LocalFree(lpMsgBuf);
  372 + }
  373 +
  374 + LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window)
  375 + {
  376 + char id;
  377 +
  378 + for(id='A';id < 'Z';id++)
  379 + {
  380 + gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s_%c",pw3270_get_session_name(window),id);
  381 + gchar * ptr;
  382 + HANDLE hPipe;
  383 +
  384 + for(ptr=pipename;*ptr;ptr++)
  385 + *ptr = g_ascii_tolower(*ptr);
  386 +
  387 + hPipe = CreateNamedPipe( TEXT(pipename), // pipe name
  388 + PIPE_ACCESS_DUPLEX | // read/write access
  389 + FILE_FLAG_OVERLAPPED, // overlapped mode
  390 + PIPE_TYPE_MESSAGE | // pipe type
  391 + PIPE_READMODE_MESSAGE | // pipe mode
  392 + PIPE_WAIT, // blocking mode
  393 + 1, // number of instances
  394 + PIPE_BUFFER_LENGTH, // output buffer size
  395 + PIPE_BUFFER_LENGTH, // input buffer size
  396 + NMPWAIT_USE_DEFAULT_WAIT, // client time-out
  397 + NULL); // default security attributes
  398 +
  399 + trace("%s = %p",pipename,hPipe);
  400 + g_free(pipename);
  401 +
  402 + if(hPipe != INVALID_HANDLE_VALUE)
  403 + {
  404 + static GSourceFuncs pipe_source_funcs =
  405 + {
  406 + IO_prepare,
  407 + IO_check,
  408 + IO_dispatch,
  409 + IO_finalize,
  410 + IO_closure,
  411 + NULL
  412 + };
  413 + pipe_source * source;
  414 + gchar * session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),id);
  415 +
  416 + pw3270_set_session_name(window,session);
  417 + g_free(session);
  418 +
  419 + source = (pipe_source *) g_source_new(&pipe_source_funcs,sizeof(pipe_source));
  420 +
  421 + source->hPipe = hPipe;
  422 + source->state = PIPE_STATE_WAITING;
  423 + source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL);
  424 +
  425 + g_source_attach((GSource *) source,NULL);
  426 + IO_accept(source);
  427 +
  428 + return 0;
  429 + }
  430 +
  431 + }
  432 +
  433 + popup_lasterror( "%s", _( "Can´t create remote control pipe" ));
  434 +
  435 + return -1;
  436 + }
  437 +
  438 + LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window)
  439 + {
  440 +
  441 + return 0;
  442 + }
  443 +
  444 +/*
  445 + static void cmd_connectps(QUERY *qry)
  446 + {
  447 + g_message("%s","HLLAPI ConnectPS request received");
  448 + request_status(qry,v3270_set_script(pw3270_get_terminal_widget(NULL),'H',TRUE));
  449 + }
  450 +
  451 + static void cmd_disconnectps(QUERY *qry)
  452 + {
  453 + g_message("%s","HLLAPI DisconnectPS request received");
  454 + request_status(qry,0);
  455 + }
  456 +
  457 + static void cmd_getrevision(QUERY *qry)
  458 + {
  459 + request_complete(qry,0,lib3270_get_revision());
  460 + }
  461 +
  462 + static void cmd_setcursor(QUERY *qry)
  463 + {
  464 + int rc = ENOTCONN;
  465 +
  466 + if(lib3270_connected(qry->hSession))
  467 + {
  468 + trace("%s: pos=%d row=%d col=%d",__FUNCTION__,rc,rc/80,rc%80);
  469 + lib3270_set_cursor_address(qry->hSession,qry->pos -1);
  470 + rc = 0;
  471 + }
  472 +
  473 + request_status(qry,rc);
  474 + }
  475 +
  476 + static void cmd_sendstring(QUERY *qry)
  477 + {
  478 + gchar * text;
  479 + GError * error = NULL;
  480 + gsize bytes_read;
  481 + gsize bytes_written;
  482 + const gchar * charset;
  483 +
  484 + if(!lib3270_connected(qry->hSession))
  485 + {
  486 + request_status(qry,ENOTCONN);
  487 + return;
  488 + }
  489 +
  490 + g_get_charset(&charset);
  491 +
  492 + text = g_convert(qry->text,qry->length,lib3270_get_charset(qry->hSession),charset,&bytes_read,&bytes_written,&error);
  493 + if(text)
  494 + {
  495 + int rc = 0;
  496 +
  497 + if(strchr(text,control_char))
  498 + {
  499 + // Convert control char
  500 + gchar * buffer = text;
  501 + char * ptr;
  502 +
  503 + for(ptr = strchr(text,control_char);ptr;ptr = strchr(buffer,control_char))
  504 + {
  505 + *(ptr++) = 0;
  506 +
  507 + lib3270_emulate_input(qry->hSession,buffer,-1,0);
  508 +
  509 + switch(*(ptr++))
  510 + {
  511 + case 'P': // Print
  512 + rc = pw3270_print(pw3270_get_terminal_widget(NULL), NULL, GTK_PRINT_OPERATION_ACTION_PRINT, PW3270_SRC_ALL);
  513 + break;
  514 +
  515 + case 'E': // Enter
  516 + lib3270_enter(qry->hSession);
  517 + break;
  518 +
  519 + case 'F': // Erase EOF
  520 + lib3270_eraseeof(qry->hSession);
  521 + break;
  522 +
  523 + case '1': // PF1
  524 + lib3270_pfkey(qry->hSession,1);
  525 + break;
  526 +
  527 + case '2': // PF2
  528 + lib3270_pfkey(qry->hSession,2);
  529 + break;
  530 +
  531 + case '3': // PF3
  532 + lib3270_pfkey(qry->hSession,3);
  533 + break;
  534 +
  535 + case '4': // PF4
  536 + lib3270_pfkey(qry->hSession,4);
  537 + break;
  538 +
  539 + case '5': // PF5
  540 + lib3270_pfkey(qry->hSession,5);
  541 + break;
  542 +
  543 + case '6': // PF6
  544 + lib3270_pfkey(qry->hSession,6);
  545 + break;
  546 +
  547 + case '7': // PF7
  548 + lib3270_pfkey(qry->hSession,7);
  549 + break;
  550 +
  551 + case '8': // PF8
  552 + lib3270_pfkey(qry->hSession,8);
  553 + break;
  554 +
  555 + case '9': // PF9
  556 + lib3270_pfkey(qry->hSession,9);
  557 + break;
  558 +
  559 + case 'a': // PF10
  560 + lib3270_pfkey(qry->hSession,10);
  561 + break;
  562 +
  563 + case 'b': // PF11
  564 + lib3270_pfkey(qry->hSession,11);
  565 + break;
  566 +
  567 + case 'c': // PF12
  568 + lib3270_pfkey(qry->hSession,12);
  569 + break;
  570 + }
  571 +
  572 + }
  573 +
  574 + lib3270_emulate_input(qry->hSession,buffer,-1,0);
  575 +
  576 + }
  577 + else
  578 + {
  579 + lib3270_emulate_input(qry->hSession,text,strlen(text),0);
  580 + }
  581 + g_free(text);
  582 +
  583 + request_status(qry,rc);
  584 +
  585 + return;
  586 + }
  587 +
  588 + request_complete(qry, error->code, error->message);
  589 + g_error_free(error);
  590 +
  591 + }
  592 +
  593 + struct wait
  594 + {
  595 + QUERY * qry;
  596 + time_t end;
  597 + };
  598 +
  599 + static gboolean do_wait(struct wait *w)
  600 + {
  601 + if(lib3270_get_program_message(w->qry->hSession) == LIB3270_MESSAGE_NONE)
  602 + {
  603 + request_status(w->qry,0);
  604 + return FALSE;
  605 + }
  606 +
  607 + if(time(0) > w->end)
  608 + {
  609 + trace("%s: TIMEOUT",__FUNCTION__);
  610 + request_status(w->qry,ETIMEDOUT);
  611 + return FALSE;
  612 + }
  613 +
  614 + return TRUE;
  615 + }
  616 +
  617 + static void cmd_wait(QUERY *qry)
  618 + {
  619 + struct wait *w;
  620 +
  621 + if(lib3270_get_program_message(qry->hSession) == LIB3270_MESSAGE_NONE)
  622 + {
  623 + request_status(qry,0);
  624 + return;
  625 + }
  626 +
  627 + w = g_malloc0(sizeof(struct wait));
  628 + w->qry = qry;
  629 + w->end = time(0)+pw3270_get_integer(pw3270_get_toplevel(),"hllapi","wait",2);
  630 +
  631 + g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) 300, (GSourceFunc) do_wait, w, g_free);
  632 + }
  633 +
  634 + static void cmd_copypstostr(QUERY *qry)
  635 + {
  636 + int rows;
  637 + int cols;
  638 + unsigned short * attr;
  639 + unsigned char * text;
  640 + int rc;
  641 + unsigned char * buffer;
  642 + size_t length;
  643 +
  644 + if(!lib3270_connected(qry->hSession))
  645 + {
  646 + request_status(qry,ENOTCONN);
  647 + return;
  648 + }
  649 +
  650 + lib3270_get_screen_size(qry->hSession,&rows,&cols);
  651 +
  652 + if(qry->pos < 1 || (qry->pos+qry->length) >= (rows*cols))
  653 + {
  654 + request_status(qry,EINVAL);
  655 + return;
  656 + }
  657 +
  658 + qry->pos--;
  659 +
  660 + length = (qry->length * sizeof(unsigned short)) + qry->length + 2;
  661 + text = buffer = g_malloc0(length+1);
  662 + attr = (unsigned short *) (text+qry->length+1);
  663 +
  664 + trace("%s: pos=%d length=%d",__FUNCTION__,qry->pos,qry->length);
  665 + rc = lib3270_get_contents(qry->hSession,qry->pos,qry->pos+(qry->length-1),text,attr);
  666 +
  667 + if(rc)
  668 + {
  669 + request_status(qry,rc);
  670 + }
  671 + else
  672 + {
  673 + const gchar * charset;
  674 + gchar * local;
  675 + gsize bytes_read;
  676 + gsize bytes_written;
  677 + GError * error = NULL;
  678 +
  679 + trace("Text: [%s]",text);
  680 +
  681 + g_get_charset(&charset);
  682 +
  683 + local = g_convert((const gchar *) text,-1,charset,lib3270_get_charset(qry->hSession),&bytes_read,&bytes_written,&error);
  684 +
  685 + if(!local)
  686 + {
  687 + request_complete(qry,error->code,error->message);
  688 + g_error_free(error);
  689 + }
  690 + else
  691 + {
  692 + strncpy((char *) text,(const char *) local,qry->length);
  693 +
  694 + trace("response: [%s] len=%d",buffer,length);
  695 + request_buffer(qry,0,length,buffer);
  696 + g_free(local);
  697 + }
  698 + }
  699 +
  700 + g_free(buffer);
  701 + }
  702 +
  703 + static void cmd_querycursor(QUERY *qry)
  704 + {
  705 + request_value(qry,0,lib3270_get_cursor_address(qry->hSession));
  706 + }
  707 +
  708 + void enqueue_request(QUERY *qry)
  709 + {
  710 + static const struct _cmd
  711 + {
  712 + int cmd;
  713 + void (*exec)(QUERY *qry);
  714 + } cmd[] =
  715 + {
  716 + { HLLAPI_CMD_CONNECTPS, cmd_connectps }, // 1
  717 + { HLLAPI_CMD_DISCONNECTPS, cmd_disconnectps }, // 2
  718 + { HLLAPI_CMD_INPUTSTRING, cmd_sendstring }, // 3
  719 + { HLLAPI_CMD_WAIT, cmd_wait }, // 4
  720 +// { HLLAPI_CMD_COPYPS, }, // 5
  721 +// { HLLAPI_CMD_SEARCHPS, }, // 6
  722 + { HLLAPI_CMD_QUERYCURSOR, cmd_querycursor }, // 7
  723 +
  724 + { HLLAPI_CMD_COPYPSTOSTR, cmd_copypstostr }, // 8
  725 +
  726 +// { HLLAPI_CMD_COPYSTRTOPS }, // 15
  727 +
  728 + { HLLAPI_CMD_SETCURSOR, cmd_setcursor }, // 40
  729 +
  730 +// { HLLAPI_CMD_SENDFILE }, // 90
  731 +// { HLLAPI_CMD_RECEIVEFILE },
  732 +
  733 +
  734 + { HLLAPI_CMD_GETREVISION, cmd_getrevision },
  735 + };
  736 +
  737 +
  738 +
  739 + int f;
  740 +
  741 + trace("HLLAPI function %d",(int) qry->cmd);
  742 +
  743 + qry->hSession = lib3270_get_default_session_handle();
  744 +
  745 + for(f=0;f<G_N_ELEMENTS(cmd);f++)
  746 + {
  747 + if(cmd[f].cmd == qry->cmd)
  748 + {
  749 + cmd[f].exec(qry);
  750 + return;
  751 + }
  752 + }
  753 +
  754 + g_warning("Unexpected HLLAPI function %d",(int) qry->cmd);
  755 + request_status(qry,EINVAL);
  756 + }
  757 +
  758 + G_GNUC_INTERNAL void set_active(gboolean on)
  759 + {
  760 + v3270_set_script(pw3270_get_terminal_widget(NULL),'H',on);
  761 + }
  762 +
  763 +*/
... ...
src/plugins/remotectl/remotectl.c
... ... @@ -1,468 +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. 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., 51 Franklin
19   - * St, Fifth Floor, Boston, MA 02110-1301 USA
20   - *
21   - * Este programa está nomeado como remotectl.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   - * Agradecimento:
29   - *
30   - * Hélio Passos
31   - *
32   - */
33   -
34   - #include "remotectl.h"
35   - #include <pw3270.h>
36   - #include <pw3270/plugin.h>
37   - #include <pw3270/v3270.h>
38   - #include <lib3270/actions.h>
39   - #include <errno.h>
40   - #include <string.h>
41   -
42   -#ifndef ETIMEDOUT
43   - #define ETIMEDOUT 1238
44   -#endif // ETIMEDOUT
45   -
46   -/*--[ Globals ]--------------------------------------------------------------------------------------*/
47   -
48   - static const gchar control_char = '@';
49   -
50   -/*--[ Implement ]------------------------------------------------------------------------------------*/
51   -
52   -#ifdef WIN32
53   -
54   - void popup_lasterror(const gchar *fmt, ...)
55   - {
56   - char buffer[4096];
57   - va_list arg_ptr;
58   - int sz;
59   - DWORD errcode = GetLastError();
60   - char *ptr;
61   - LPVOID lpMsgBuf = 0;
62   -
63   - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
64   -
65   - for(ptr=lpMsgBuf;*ptr && *ptr != '\n';ptr++);
66   - *ptr = 0;
67   -
68   - va_start(arg_ptr, fmt);
69   - vsnprintf(buffer,4095,fmt,arg_ptr);
70   - va_end(arg_ptr);
71   -
72   - sz = strlen(buffer);
73   - snprintf(buffer+sz,4096-sz,": %s\n(rc=%d)",lpMsgBuf,(int) errcode);
74   -
75   - printf("%s\n",buffer);
76   -
77   -#ifdef DEBUG
78   - fprintf(stderr,"%s\n",buffer);
79   - fflush(stderr);
80   -#endif
81   -
82   - LocalFree(lpMsgBuf);
83   - }
84   -
85   -#endif // WIN32
86   -
87   - LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window)
88   - {
89   -#ifdef WIN32
90   - char id;
91   -
92   - for(id='A';id < 'Z';id++)
93   - {
94   - gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s%c",pw3270_get_session_name(window),id);
95   -
96   - HANDLE hPipe = CreateNamedPipe( TEXT(pipename), // pipe name
97   - PIPE_ACCESS_DUPLEX | // read/write access
98   - FILE_FLAG_OVERLAPPED, // overlapped mode
99   - PIPE_TYPE_MESSAGE | // pipe type
100   - PIPE_READMODE_MESSAGE | // pipe mode
101   - PIPE_WAIT, // blocking mode
102   - 1, // number of instances
103   - PIPE_BUFFER_LENGTH, // output buffer size
104   - PIPE_BUFFER_LENGTH, // input buffer size
105   - NMPWAIT_USE_DEFAULT_WAIT, // client time-out
106   - NULL); // default security attributes
107   -
108   - trace("%s = %p",pipename,hPipe);
109   - g_free(pipename);
110   -
111   - if(hPipe != INVALID_HANDLE_VALUE)
112   - {
113   - gchar *session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),id);
114   - pw3270_set_session_name(window,session);
115   - g_free(session);
116   -
117   - init_source_pipe(hPipe);
118   - return 0;
119   - }
120   -
121   - }
122   -
123   - popup_lasterror( "%s", _( "Can´t create remote control pipe" ));
124   - return -1;
125   -
126   -#else
127   -
128   - #error Nao implementado
129   -
130   -#endif // WIN32
131   -
132   - return 0;
133   - }
134   -
135   - LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window)
136   - {
137   -#ifdef WIN32
138   -
139   -#else
140   -
141   - #error Nao implementado
142   -
143   -#endif // WIN32
144   -
145   - set_active(FALSE);
146   -
147   - return 0;
148   - }
149   -
150   - static void cmd_connectps(QUERY *qry)
151   - {
152   - g_message("%s","HLLAPI ConnectPS request received");
153   - request_status(qry,v3270_set_script(pw3270_get_terminal_widget(NULL),'H',TRUE));
154   - }
155   -
156   - static void cmd_disconnectps(QUERY *qry)
157   - {
158   - g_message("%s","HLLAPI DisconnectPS request received");
159   - request_status(qry,0);
160   - }
161   -
162   - static void cmd_getrevision(QUERY *qry)
163   - {
164   - request_complete(qry,0,lib3270_get_revision());
165   - }
166   -
167   - static void cmd_setcursor(QUERY *qry)
168   - {
169   - int rc = ENOTCONN;
170   -
171   - if(lib3270_connected(qry->hSession))
172   - {
173   - trace("%s: pos=%d row=%d col=%d",__FUNCTION__,rc,rc/80,rc%80);
174   - lib3270_set_cursor_address(qry->hSession,qry->pos -1);
175   - rc = 0;
176   - }
177   -
178   - request_status(qry,rc);
179   - }
180   -
181   - static void cmd_sendstring(QUERY *qry)
182   - {
183   - gchar * text;
184   - GError * error = NULL;
185   - gsize bytes_read;
186   - gsize bytes_written;
187   - const gchar * charset;
188   -
189   - if(!lib3270_connected(qry->hSession))
190   - {
191   - request_status(qry,ENOTCONN);
192   - return;
193   - }
194   -
195   - g_get_charset(&charset);
196   -
197   - text = g_convert(qry->text,qry->length,lib3270_get_charset(qry->hSession),charset,&bytes_read,&bytes_written,&error);
198   - if(text)
199   - {
200   - int rc = 0;
201   -
202   - if(strchr(text,control_char))
203   - {
204   - // Convert control char
205   - gchar * buffer = text;
206   - char * ptr;
207   -
208   - for(ptr = strchr(text,control_char);ptr;ptr = strchr(buffer,control_char))
209   - {
210   - *(ptr++) = 0;
211   -
212   - lib3270_emulate_input(qry->hSession,buffer,-1,0);
213   -
214   - switch(*(ptr++))
215   - {
216   - case 'P': // Print
217   - rc = pw3270_print(pw3270_get_terminal_widget(NULL), NULL, GTK_PRINT_OPERATION_ACTION_PRINT, PW3270_SRC_ALL);
218   - break;
219   -
220   - case 'E': // Enter
221   - lib3270_enter(qry->hSession);
222   - break;
223   -
224   - case 'F': // Erase EOF
225   - lib3270_eraseeof(qry->hSession);
226   - break;
227   -
228   - case '1': // PF1
229   - lib3270_pfkey(qry->hSession,1);
230   - break;
231   -
232   - case '2': // PF2
233   - lib3270_pfkey(qry->hSession,2);
234   - break;
235   -
236   - case '3': // PF3
237   - lib3270_pfkey(qry->hSession,3);
238   - break;
239   -
240   - case '4': // PF4
241   - lib3270_pfkey(qry->hSession,4);
242   - break;
243   -
244   - case '5': // PF5
245   - lib3270_pfkey(qry->hSession,5);
246   - break;
247   -
248   - case '6': // PF6
249   - lib3270_pfkey(qry->hSession,6);
250   - break;
251   -
252   - case '7': // PF7
253   - lib3270_pfkey(qry->hSession,7);
254   - break;
255   -
256   - case '8': // PF8
257   - lib3270_pfkey(qry->hSession,8);
258   - break;
259   -
260   - case '9': // PF9
261   - lib3270_pfkey(qry->hSession,9);
262   - break;
263   -
264   - case 'a': // PF10
265   - lib3270_pfkey(qry->hSession,10);
266   - break;
267   -
268   - case 'b': // PF11
269   - lib3270_pfkey(qry->hSession,11);
270   - break;
271   -
272   - case 'c': // PF12
273   - lib3270_pfkey(qry->hSession,12);
274   - break;
275   - }
276   -
277   - }
278   -
279   - lib3270_emulate_input(qry->hSession,buffer,-1,0);
280   -
281   - }
282   - else
283   - {
284   - lib3270_emulate_input(qry->hSession,text,strlen(text),0);
285   - }
286   - g_free(text);
287   -
288   - request_status(qry,rc);
289   -
290   - return;
291   - }
292   -
293   - request_complete(qry, error->code, error->message);
294   - g_error_free(error);
295   -
296   - }
297   -
298   - struct wait
299   - {
300   - QUERY * qry;
301   - time_t end;
302   - };
303   -
304   - static gboolean do_wait(struct wait *w)
305   - {
306   - if(lib3270_get_program_message(w->qry->hSession) == LIB3270_MESSAGE_NONE)
307   - {
308   - request_status(w->qry,0);
309   - return FALSE;
310   - }
311   -
312   - if(time(0) > w->end)
313   - {
314   - trace("%s: TIMEOUT",__FUNCTION__);
315   - request_status(w->qry,ETIMEDOUT);
316   - return FALSE;
317   - }
318   -
319   - return TRUE;
320   - }
321   -
322   - static void cmd_wait(QUERY *qry)
323   - {
324   - struct wait *w;
325   -
326   - if(lib3270_get_program_message(qry->hSession) == LIB3270_MESSAGE_NONE)
327   - {
328   - request_status(qry,0);
329   - return;
330   - }
331   -
332   - w = g_malloc0(sizeof(struct wait));
333   - w->qry = qry;
334   - w->end = time(0)+pw3270_get_integer(pw3270_get_toplevel(),"hllapi","wait",2);
335   -
336   - g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) 300, (GSourceFunc) do_wait, w, g_free);
337   - }
338   -
339   - static void cmd_copypstostr(QUERY *qry)
340   - {
341   - int rows;
342   - int cols;
343   - unsigned short * attr;
344   - unsigned char * text;
345   - int rc;
346   - unsigned char * buffer;
347   - size_t length;
348   -
349   - if(!lib3270_connected(qry->hSession))
350   - {
351   - request_status(qry,ENOTCONN);
352   - return;
353   - }
354   -
355   - lib3270_get_screen_size(qry->hSession,&rows,&cols);
356   -
357   - if(qry->pos < 1 || (qry->pos+qry->length) >= (rows*cols))
358   - {
359   - request_status(qry,EINVAL);
360   - return;
361   - }
362   -
363   - qry->pos--;
364   -
365   - length = (qry->length * sizeof(unsigned short)) + qry->length + 2;
366   - text = buffer = g_malloc0(length+1);
367   - attr = (unsigned short *) (text+qry->length+1);
368   -
369   - trace("%s: pos=%d length=%d",__FUNCTION__,qry->pos,qry->length);
370   - rc = lib3270_get_contents(qry->hSession,qry->pos,qry->pos+(qry->length-1),text,attr);
371   -
372   - if(rc)
373   - {
374   - request_status(qry,rc);
375   - }
376   - else
377   - {
378   - const gchar * charset;
379   - gchar * local;
380   - gsize bytes_read;
381   - gsize bytes_written;
382   - GError * error = NULL;
383   -
384   - trace("Text: [%s]",text);
385   -
386   - g_get_charset(&charset);
387   -
388   - local = g_convert((const gchar *) text,-1,charset,lib3270_get_charset(qry->hSession),&bytes_read,&bytes_written,&error);
389   -
390   - if(!local)
391   - {
392   - request_complete(qry,error->code,error->message);
393   - g_error_free(error);
394   - }
395   - else
396   - {
397   - strncpy((char *) text,(const char *) local,qry->length);
398   -
399   - trace("response: [%s] len=%d",buffer,length);
400   - request_buffer(qry,0,length,buffer);
401   - g_free(local);
402   - }
403   - }
404   -
405   - g_free(buffer);
406   - }
407   -
408   - static void cmd_querycursor(QUERY *qry)
409   - {
410   - request_value(qry,0,lib3270_get_cursor_address(qry->hSession));
411   - }
412   -
413   - void enqueue_request(QUERY *qry)
414   - {
415   - static const struct _cmd
416   - {
417   - int cmd;
418   - void (*exec)(QUERY *qry);
419   - } cmd[] =
420   - {
421   - { HLLAPI_CMD_CONNECTPS, cmd_connectps }, // 1
422   - { HLLAPI_CMD_DISCONNECTPS, cmd_disconnectps }, // 2
423   - { HLLAPI_CMD_INPUTSTRING, cmd_sendstring }, // 3
424   - { HLLAPI_CMD_WAIT, cmd_wait }, // 4
425   -// { HLLAPI_CMD_COPYPS, }, // 5
426   -// { HLLAPI_CMD_SEARCHPS, }, // 6
427   - { HLLAPI_CMD_QUERYCURSOR, cmd_querycursor }, // 7
428   -
429   - { HLLAPI_CMD_COPYPSTOSTR, cmd_copypstostr }, // 8
430   -
431   -// { HLLAPI_CMD_COPYSTRTOPS }, // 15
432   -
433   - { HLLAPI_CMD_SETCURSOR, cmd_setcursor }, // 40
434   -
435   -// { HLLAPI_CMD_SENDFILE }, // 90
436   -// { HLLAPI_CMD_RECEIVEFILE },
437   -
438   -
439   - { HLLAPI_CMD_GETREVISION, cmd_getrevision },
440   - };
441   -
442   -
443   -
444   - int f;
445   -
446   - trace("HLLAPI function %d",(int) qry->cmd);
447   -
448   - qry->hSession = lib3270_get_default_session_handle();
449   -
450   - for(f=0;f<G_N_ELEMENTS(cmd);f++)
451   - {
452   - if(cmd[f].cmd == qry->cmd)
453   - {
454   - cmd[f].exec(qry);
455   - return;
456   - }
457   - }
458   -
459   - g_warning("Unexpected HLLAPI function %d",(int) qry->cmd);
460   - request_status(qry,EINVAL);
461   - }
462   -
463   - G_GNUC_INTERNAL void set_active(gboolean on)
464   - {
465   - v3270_set_script(pw3270_get_terminal_widget(NULL),'H',on);
466   - }
467   -
468   -
src/plugins/remotectl/server.h 0 → 100644
... ... @@ -0,0 +1,51 @@
  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 server.h 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 <lib3270/config.h>
  31 + #define ENABLE_NLS
  32 + #define GETTEXT_PACKAGE PACKAGE_NAME
  33 +
  34 + #include <libintl.h>
  35 + #include <glib/gi18n.h>
  36 + #include <gtk/gtk.h>
  37 +
  38 + #include <lib3270.h>
  39 + #include <lib3270/log.h>
  40 + #include <pw3270.h>
  41 + #include <pw3270/hllapi.h>
  42 +
  43 + #include <windows.h>
  44 +
  45 + #define PIPE_BUFFER_LENGTH HLLAPI_MAXLENGTH+30
  46 +
  47 + #define set_active(x) /* x */
  48 +
  49 +
  50 + G_GNUC_INTERNAL void popup_lasterror(const gchar *fmt, ...);
  51 +
... ...
src/plugins/remotectl/testprogram.c
... ... @@ -38,6 +38,15 @@
38 38  
39 39 int main(int numpar, char *param[])
40 40 {
  41 + const char *session = "pw3270:a";
  42 +
  43 + printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session));
  44 + printf("revision=%d\n",(int) hllapi_get_revision());
  45 + printf("connect=%d\n",(int) hllapi_connect("fandezhi.efglobe.com:23"));
  46 +
  47 + printf("deinit=%d\n",(int) hllapi_deinit());
  48 +
  49 +/*
41 50 DWORD revision;
42 51 int rc;
43 52  
... ... @@ -54,8 +63,8 @@
54 63  
55 64 printf("Deinit exits with rc=%d\n",rc);
56 65 rc = hllapi_deinit();
57   -
58   - return rc;
  66 +*/
  67 + return 0;
59 68 }
60 69  
61 70 /*
... ...
src/pw3270/common/config.c
... ... @@ -111,7 +111,7 @@ gchar * get_last_error_msg(void)
111 111 }
112 112 }
113 113  
114   - trace("Cant open \"%s\"",path);
  114 +// trace("Cant open \"%s\"",path);
115 115 g_free(path);
116 116  
117 117 return FALSE;
... ... @@ -602,8 +602,10 @@ gchar * filename_from_va(const gchar *first_element, va_list args)
602 602 }
603 603 else
604 604 {
605   - gchar *msg = g_win32_error_message(rc);
606   - g_message("Error \"%s\" when getting application datadir from registry",msg);
  605 + gchar *msg = g_win32_error_message(rc);
  606 +#ifndef DEBUG
  607 + g_message("Error \"%s\" when getting application datadir from registry",msg);
  608 +#endif // !DEBUG
607 609 g_free(msg);
608 610 }
609 611 RegCloseKey(hKey);
... ... @@ -611,7 +613,9 @@ gchar * filename_from_va(const gchar *first_element, va_list args)
611 613 else
612 614 {
613 615 gchar *msg = g_win32_error_message(rc);
614   - g_message("Error \"%s\" when opening datadir key from registry",msg);
  616 +#ifndef DEBUG
  617 + g_message("Error \"%s\" when opening datadir key from registry",msg);
  618 +#endif // !DEBUG
615 619 g_free(msg);
616 620 }
617 621  
... ... @@ -633,7 +637,7 @@ gchar * filename_from_va(const gchar *first_element, va_list args)
633 637 for(f=0;dir[f] && !datadir;f++)
634 638 {
635 639 gchar *name = g_build_filename(dir[f],appname[p],NULL);
636   - trace("Searching for %s: %s",name,g_file_test(name,G_FILE_TEST_IS_DIR) ? "Ok" : "Not found");
  640 +// trace("Searching for %s: %s",name,g_file_test(name,G_FILE_TEST_IS_DIR) ? "Ok" : "Not found");
637 641 if(g_file_test(name,G_FILE_TEST_IS_DIR))
638 642 result = g_string_new(datadir = name);
639 643 else
... ...
src/pw3270/plugin.c
... ... @@ -46,11 +46,11 @@
46 46 GError * err = NULL;
47 47 GList * lst = NULL;
48 48  
  49 + trace("Loading plugins from %s",path);
  50 +
49 51 if(!g_file_test(path,G_FILE_TEST_IS_DIR))
50 52 return;
51 53  
52   - trace("Loading plugins from %s",path);
53   -
54 54 dir = g_dir_open(path,0,&err);
55 55 if(!dir)
56 56 {
... ... @@ -135,7 +135,31 @@
135 135  
136 136 LIB3270_EXPORT void pw3270_init_plugins(GtkWidget *widget)
137 137 {
138   -#if ! defined(DEBUG)
  138 +#if defined( DEBUG )
  139 +
  140 + gchar * dir = g_get_current_dir();
  141 + gchar * path = g_build_filename(dir,"plugins",NULL);
  142 +
  143 + trace("%s testing [%s]",__FUNCTION__,path);
  144 +
  145 + if(!g_file_test(path,G_FILE_TEST_IS_DIR))
  146 + {
  147 + g_free(path);
  148 + path = pw3270_build_filename(widget,"plugins",NULL);
  149 + }
  150 +
  151 + load(path,widget);
  152 +
  153 + g_free(path);
  154 + g_free(dir);
  155 +
  156 +#elif defined( WIN32 )
  157 +
  158 + gchar * path = pw3270_build_filename(widget,"plugins",NULL);
  159 + load(path, widget);
  160 + g_free(path);
  161 +
  162 +#else
139 163  
140 164 const gchar * appname[] = { g_get_application_name(), PACKAGE_NAME };
141 165 int f;
... ... @@ -143,7 +167,7 @@
143 167 for(f=0;f<G_N_ELEMENTS(appname);f++)
144 168 {
145 169 gchar *path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s-plugins",LIBDIR,appname[f]);
146   -
  170 +
147 171 if(g_file_test(path,G_FILE_TEST_IS_DIR))
148 172 {
149 173 load(path, widget);
... ... @@ -154,30 +178,6 @@
154 178 g_free(path);
155 179 }
156 180  
157   -#elif defined( win32 )
158   -
159   - gchar * appdir = g_win32_get_package_installation_directory_of_module(NULL);
160   - gchar * path = pw3270_build_filename(widget,"plugins",NULL);
161   - load(path, widget);
162   - g_free(path);
163   - g_free(appdir);
164   -
165   -#else
166   -
167   - gchar * dir = g_get_current_dir();
168   - gchar * path = g_build_filename(dir,".bin","Debug","plugins",NULL);
169   -
170   - if(!g_file_test(path,G_FILE_TEST_IS_DIR))
171   - {
172   - g_free(path);
173   - path = pw3270_build_filename(widget,"plugins",NULL);
174   - }
175   -
176   - load(path,widget);
177   -
178   - g_free(path);
179   - g_free(dir);
180   -
181 181 #endif
182 182 }
183 183  
... ...