diff --git a/pw3270.cbp b/pw3270.cbp
index b3dc6bd..3159e9e 100644
--- a/pw3270.cbp
+++ b/pw3270.cbp
@@ -250,10 +250,14 @@
+
-
+
+
+
+
diff --git a/src/include/lib3270.h b/src/include/lib3270.h
index 6f4250f..1781560 100644
--- a/src/include/lib3270.h
+++ b/src/include/lib3270.h
@@ -439,7 +439,7 @@
* @param h Session handle.
*
*/
- LIB3270_EXPORT void lib3270_disconnect(H3270 *h);
+ LIB3270_EXPORT int lib3270_disconnect(H3270 *h);
/**
* Reconnect.
@@ -496,7 +496,7 @@
#define lib3270_set_text_at(h,r,c,t) lib3270_set_string_at(h,r,c,t)
LIB3270_EXPORT int lib3270_set_string_at(H3270 *h, int row, int col, const unsigned char *str);
- LIB3270_EXPORT void lib3270_input_string(H3270 *hSession, const unsigned char *str);
+ LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *str);
/**
* Set cursor address.
diff --git a/src/include/pw3270/hllapi.h b/src/include/pw3270/hllapi.h
index 58355b1..743828b 100644
--- a/src/include/pw3270/hllapi.h
+++ b/src/include/pw3270/hllapi.h
@@ -38,11 +38,7 @@
extern "C" {
#endif
- #define HLLAPI_REQUEST_QUERY 0x01
- #define HLLAPI_RESPONSE_VALUE 0x02
- #define HLLAPI_RESPONSE_TEXT 0x03
-
- #define HLLAPI_MAXLENGTH 32768
+ #define HLLAPI_MAXLENGTH 4096
#define HLLAPI_CMD_CONNECTPS 1 /**< connect presentation space */
#define HLLAPI_CMD_DISCONNECTPS 2 /**< disconnect presentation space */
@@ -58,43 +54,53 @@ extern "C" {
#define HLLAPI_CMD_RECEIVEFILE 91 /**< Receive a file from the host */
#define HLLAPI_CMD_GETREVISION 2000 /**< Get lib3270 revision */
-
- #pragma pack(1)
- typedef struct _hllapi_data
- {
- unsigned char id; /**< Request id */
- unsigned long func; /**< Function number */
- unsigned short rc; /**< Short argument/return code */
- unsigned int value; /**< Requested value */
- char string[1]; /**< String argument */
- } HLLAPI_DATA;
-
- #pragma pack()
+
+ typedef enum _hllapi_packet
+ {
+ HLLAPI_PACKET_CONNECT,
+ HLLAPI_PACKET_DISCONNECT,
+ HLLAPI_PACKET_GET_PROGRAM_MESSAGE,
+ HLLAPI_PACKET_GET_TEXT_AT,
+ HLLAPI_PACKET_SET_TEXT_AT,
+ HLLAPI_PACKET_CMP_TEXT_AT,
+ HLLAPI_PACKET_ENTER,
+ HLLAPI_PACKET_PFKEY,
+ HLLAPI_PACKET_PAKEY,
+ HLLAPI_PACKET_SET_CURSOR_POSITION,
+ HLLAPI_PACKET_GET_CURSOR_POSITION,
+ HLLAPI_PACKET_INPUT_STRING,
+
+ HLLAPI_PACKET_INVALID
+
+ } HLLAPI_PACKET;
+
+
#ifdef _WIN32
- // http://www.mingw.org/wiki/Visual_Basic_DLL
- __declspec (dllexport) int __stdcall hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc);
+ // http://www.mingw.org/wiki/Visual_Basic_DLL
+ __declspec (dllexport) int __stdcall hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc);
- __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode);
- __declspec (dllexport) DWORD __stdcall hllapi_deinit(void);
+ __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode);
+ __declspec (dllexport) DWORD __stdcall hllapi_deinit(void);
- __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void);
+ __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void);
- __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri);
- __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void);
- __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void);
- __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer);
- __declspec (dllexport) DWORD __stdcall hllapi_enter(void);
- __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text);
- __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text);
- __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds);
- __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds);
- __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key);
- __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key);
-
+ __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri);
+ __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void);
+ __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void);
+ __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer);
+ __declspec (dllexport) DWORD __stdcall hllapi_enter(void);
+ __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text);
+ __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text);
+ __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds);
+ __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds);
+ __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key);
+ __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key);
+
+#else
+
+ #error NOT IMPLEMENTED
-#else
- LIB3270_EXPORT int hllapi(const unsigned long *func, char *str, unsigned short *length, unsigned short *rc);
#endif // _WIN32
#ifdef __cplusplus
diff --git a/src/lib3270/host.c b/src/lib3270/host.c
index 616691f..8a3a7a7 100644
--- a/src/lib3270/host.c
+++ b/src/lib3270/host.c
@@ -494,9 +494,10 @@ static void try_reconnect(H3270 *session)
lib3270_reconnect(session,0);
}
-LIB3270_EXPORT void lib3270_disconnect(H3270 *h)
+LIB3270_EXPORT int lib3270_disconnect(H3270 *h)
{
- host_disconnect(h,0);
+ host_disconnect(h,0);
+ return 0;
}
void host_disconnect(H3270 *hSession, int failed)
diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c
index 13f8a80..22f294f 100644
--- a/src/lib3270/kybd.c
+++ b/src/lib3270/kybd.c
@@ -998,7 +998,7 @@ static Boolean key_Character(H3270 *hSession, int code, Boolean with_ge, Boolean
}
-LIB3270_EXPORT void lib3270_input_string(H3270 *hSession, const unsigned char *str)
+LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *str)
{
while(*str)
{
@@ -1006,7 +1006,9 @@ LIB3270_EXPORT void lib3270_input_string(H3270 *hSession, const unsigned char *s
str++;
}
- screen_update(hSession,0,hSession->rows*hSession->cols);
+ screen_update(hSession,0,hSession->rows*hSession->cols);
+
+ return 0;
}
/**
diff --git a/src/plugins/remotectl/Makefile.in b/src/plugins/remotectl/Makefile.in
index f7966ab..604737e 100644
--- a/src/plugins/remotectl/Makefile.in
+++ b/src/plugins/remotectl/Makefile.in
@@ -30,8 +30,8 @@
MODULE_NAME=remotectl
DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile
-PLUGIN_SRC=remotectl.c pipesource.c
-HLLAPI_SRC=hllapi.c calls.c
+PLUGIN_SRC=pluginmain.c
+HLLAPI_SRC=hllapi.c calls.c remote.c
#---[ Paths ]------------------------------------------------------------------
@@ -126,13 +126,15 @@ $(BINDBG)/libhllapi@DLLEXT@: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJDBG)
#---[ Misc targets ]-----------------------------------------------------------
-testprogram@EXEEXT@: testprogram.c
+$(BINDBG)/testprogram@EXEEXT@: testprogram.c $(BINDBG)/libhllapi@DLLEXT@
@echo " CCLD `basename $@`"
@$(MKDIR) `dirname $@`
- @$(CC) $(CFLAGS) -I../../../src/include -L../../../$(BINDIR)/Debug $(DEBUG_CFLAGS) -lhllapi -o $@ $<
+ @$(CC) $(CFLAGS) $(PW3270_CFLAGS) -L$(BINDBG) $(DEBUG_CFLAGS) -lhllapi -o $@ testprogram.c
-test: testprogram@EXEEXT@
- @PATH="../../../$(BINDIR)/Debug:$(PATH)" ./testprogram@EXEEXT@
+test: $(BINDBG)/testprogram@EXEEXT@
+
+run: $(BINDBG)/testprogram@EXEEXT@
+ @cd $(BINDBG) ; ./testprogram@EXEEXT@
install: $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@
@$(MKDIR) $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins
diff --git a/src/plugins/remotectl/calls.c b/src/plugins/remotectl/calls.c
index b664bc9..d4bdca9 100644
--- a/src/plugins/remotectl/calls.c
+++ b/src/plugins/remotectl/calls.c
@@ -34,62 +34,56 @@
#include
#include
#include
- #include
+ #include
+ #include "client.h"
/*--[ Globals ]--------------------------------------------------------------------------------------*/
HMODULE hModule = NULL;
- H3270 * hSession = NULL;
+ void * hSession = NULL;
- static H3270 * (*session_new)(const char *model) = NULL;
- static void (*session_free)(H3270 *h) = NULL;
+ static void * (*session_new)(const char *model) = NULL;
+ static void (*session_free)(void *h) = NULL;
static const char * (*get_revision)(void) = NULL;
- static int (*host_connect)(H3270 *h,const char *n, int wait) = NULL;
- static int (*wait_for_ready)(H3270 *h, int seconds) = NULL;
- static void (*host_disconnect)(H3270 *h) = NULL;
- static int (*script_sleep)(H3270 *h, int seconds) = NULL;
- static LIB3270_MESSAGE (*get_message)(H3270 *h) = NULL;
- static char * (*get_text)(H3270 *h, int row, int col, int len) = NULL;
+ static int (*host_connect)(void *h,const char *n, int wait) = NULL;
+ static int (*wait_for_ready)(void *h, int seconds) = NULL;
+ static void (*host_disconnect)(void *h) = NULL;
+ static int (*script_sleep)(void *h, int seconds) = NULL;
+ static LIB3270_MESSAGE (*get_message)(void *h) = NULL;
+ static char * (*get_text)(void *h, int row, int col, int len) = NULL;
static void * (*release_memory)(void *p) = NULL;
- static int (*action_enter)(H3270 *h) = NULL;
- static int (*set_text_at)(H3270 *h, int row, int col, const unsigned char *str) = NULL;
- static int (*cmp_text_at)(H3270 *h, int row, int col, const char *text) = NULL;
- static int (*pfkey)(H3270 *hSession, int key) = NULL;
- static int (*pakey)(H3270 *hSession, int key) = NULL;
+ static int (*action_enter)(void *h) = NULL;
+ static int (*set_text_at)(void *h, int row, int col, const unsigned char *str) = NULL;
+ static int (*cmp_text_at)(void *h, int row, int col, const char *text) = NULL;
+ static int (*pfkey)(void *hSession, int key) = NULL;
+ static int (*pakey)(void *hSession, int key) = NULL;
static const struct _entry_point
{
void **call;
+ void * pipe;
const char * name;
} entry_point[] =
{
- { (void **) &session_new, "lib3270_session_new" },
- { (void **) &session_free, "lib3270_session_free" },
- { (void **) &get_revision, "lib3270_get_revision" },
- { (void **) &host_connect, "lib3270_connect" },
- { (void **) &host_disconnect, "lib3270_disconnect" },
- { (void **) &wait_for_ready, "lib3270_wait_for_ready" },
- { (void **) &script_sleep, "lib3270_wait" },
- { (void **) &get_message, "lib3270_get_program_message" },
- { (void **) &get_text, "lib3270_get_text_at" },
- { (void **) &release_memory, "lib3270_free" },
- { (void **) &action_enter, "lib3270_enter" },
- { (void **) &set_text_at, "lib3270_set_string_at" },
- { (void **) &cmp_text_at, "lib3270_cmp_text_at" },
- { (void **) &pfkey, "lib3270_pfkey" },
- { (void **) &pakey, "lib3270_pakey" },
+ { (void **) &session_new, (void *) hllapi_pipe_init, "lib3270_session_new" },
+ { (void **) &session_free, (void *) hllapi_pipe_deinit, "lib3270_session_free" },
+ { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" },
+ { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" },
+ { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" },
+ { (void **) &wait_for_ready, (void *) NULL, "lib3270_wait_for_ready" },
+ { (void **) &script_sleep, (void *) NULL, "lib3270_wait" },
+ { (void **) &get_message, (void *) NULL, "lib3270_get_program_message" },
+ { (void **) &get_text, (void *) NULL, "lib3270_get_text_at" },
+ { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" },
+ { (void **) &action_enter, (void *) NULL, "lib3270_enter" },
+ { (void **) &set_text_at, (void *) NULL, "lib3270_set_string_at" },
+ { (void **) &cmp_text_at, (void *) NULL, "lib3270_cmp_text_at" },
+ { (void **) &pfkey, (void *) NULL, "lib3270_pfkey" },
+ { (void **) &pakey, (void *) NULL, "lib3270_pakey" },
{ NULL, NULL }
};
-#undef trace
-
-#ifdef DEBUG
- #define trace(...) { FILE *__dbg = fopen("c:\\users\\perry\\debug.txt","a"); if(__dbg) { fprintf(__dbg,__VA_ARGS__); fclose(__dbg); }; }
-#else
- #define trace(...) /* */
-#endif // DEBUG
-
#ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx
#define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000
@@ -102,22 +96,30 @@
if(!mode)
return EINVAL;
- if(hModule)
- return EBUSY;
+ trace("%s(%s)",__FUNCTION__,(char *) mode);
if(!(mode && *mode))
{
// Direct mode, load lib3270.dll, get pointers to the calls
int f;
HKEY hKey = 0;
- HMODULE kernel = LoadLibrary("kernel32.dll");
+ HMODULE kernel;
HANDLE cookie = NULL;
DWORD rc;
- HANDLE (*AddDllDirectory)(PCWSTR NewDirectory) = (HANDLE (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory");
- BOOL (*RemoveDllDirectory)(HANDLE Cookie) = (BOOL (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory");
+ HANDLE (*AddDllDirectory)(PCWSTR NewDirectory);
+ BOOL (*RemoveDllDirectory)(HANDLE Cookie);
+ UINT errorMode;
+
+ trace("hModule=%p",hModule);
+ if(hModule)
+ return EBUSY;
+
+ kernel = LoadLibrary("kernel32.dll");
+ AddDllDirectory = (HANDLE (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory");
+ RemoveDllDirectory = (BOOL (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory");
// Notify user in case of error loading protocol DLL
- UINT errorMode = SetErrorMode(0);
+ errorMode = SetErrorMode(0);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS)
{
@@ -138,6 +140,7 @@
hModule = LoadLibraryEx("lib3270.dll.5.0",NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
rc = GetLastError();
+ trace("hModule=%p rc=%d",hModule,(int) rc);
SetErrorMode(errorMode);
@@ -166,18 +169,22 @@
*entry_point[f].call = ptr;
}
- // Get session handle
- hSession = session_new("");
+ }
+ else
+ {
+ // Get pointers to the pipe based calls
+ int f;
- trace("%s ok hSession=%p\n",__FUNCTION__,hSession);
+ for(f=0;entry_point[f].name;f++)
+ *entry_point[f].call = entry_point[f].pipe;
- return 0;
}
- // Set entry points to pipe based calls
-
+ // Get session handle
+ hSession = session_new((const char *) mode);
+ trace("%s ok hSession=%p\n",__FUNCTION__,hSession);
- return -1;
+ return hSession ? 0 : -1;
}
__declspec (dllexport) DWORD __stdcall hllapi_deinit(void)
diff --git a/src/plugins/remotectl/client.h b/src/plugins/remotectl/client.h
new file mode 100644
index 0000000..3e6bb3a
--- /dev/null
+++ b/src/plugins/remotectl/client.h
@@ -0,0 +1,58 @@
+/*
+ * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
+ * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
+ * aplicativos mainframe. Registro no INPI sob o nome G3270.
+ *
+ * Copyright (C) <2008>
+ *
+ * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
+ * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
+ * Free Software Foundation.
+ *
+ * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
+ * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
+ * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
+ * obter mais detalhes.
+ *
+ * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
+ * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA, 02111-1307, USA
+ *
+ * Este programa está nomeado como private.h e possui - linhas de código.
+ *
+ * Contatos:
+ *
+ * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
+ * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
+ *
+ */
+
+ #include
+ #include
+
+ #ifndef ETIMEDOUT
+ #define ETIMEDOUT 1238
+ #endif // ETIMEDOUT
+
+ #define PIPE_BUFFER_LENGTH 8192
+
+ #define set_active(x) /* x */
+
+ void * hllapi_pipe_init(const char *id);
+ void hllapi_pipe_deinit(void *h);
+ const char * hllapi_pipe_get_revision(void);
+ void hllapi_pipe_release_memory(void *p);
+ int hllapi_pipe_connect(void *h, const char *n, int wait);
+ void hllapi_pipe_disconnect(void *h);
+
+/*
+ int hllapi_pipe_wait_for_ready(void *h, int seconds);
+ int hllapi_pipe_sleep(void *h, int seconds);
+ LIB3270_MESSAGE hllapi_pipe_get_message(void *h);
+ char * hllapi_pipe_get_text(void *h, int row, int col, int len);
+ int hllapi_pipe_enter(void *h);
+ int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str);
+ int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text);
+ int hllapi_pipe_pfkey(void *h, int key);
+ int hllapi_pipe_pakey(void *h, int key);
+*/
diff --git a/src/plugins/remotectl/hllapi.c b/src/plugins/remotectl/hllapi.c
index 96ba93e..41bf934 100644
--- a/src/plugins/remotectl/hllapi.c
+++ b/src/plugins/remotectl/hllapi.c
@@ -37,14 +37,22 @@
/*--[ Globals ]--------------------------------------------------------------------------------------*/
-#ifdef WIN32
-
- static HANDLE hPipe = INVALID_HANDLE_VALUE;
-
-#endif // WIN32
+// static HANDLE hPipe = INVALID_HANDLE_VALUE;
/*--[ Implement ]------------------------------------------------------------------------------------*/
-
+
+#ifdef _WIN32
+ __declspec (dllexport) int __stdcall hllapi(LPWORD func, LPSTR buffer, LPWORD length, LPWORD rc)
+#else
+ LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc)
+#endif // _WIN32
+{
+
+
+ return -1;
+}
+
+/*
static int cmd_connect_ps(const char *name)
{
#ifdef WIN32
@@ -237,3 +245,4 @@
return 0;
}
+*/
diff --git a/src/plugins/remotectl/hllapi.cbp b/src/plugins/remotectl/hllapi.cbp
new file mode 100644
index 0000000..89cfc8e
--- /dev/null
+++ b/src/plugins/remotectl/hllapi.cbp
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/plugins/remotectl/packets.h b/src/plugins/remotectl/packets.h
new file mode 100644
index 0000000..db07d63
--- /dev/null
+++ b/src/plugins/remotectl/packets.h
@@ -0,0 +1,78 @@
+/*
+ * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
+ * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
+ * aplicativos mainframe. Registro no INPI sob o nome G3270.
+ *
+ * Copyright (C) <2008>
+ *
+ * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
+ * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
+ * Free Software Foundation.
+ *
+ * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
+ * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
+ * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
+ * obter mais detalhes.
+ *
+ * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
+ * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA, 02111-1307, USA
+ *
+ * Este programa está nomeado como packets.h e possui - linhas de código.
+ *
+ * Contatos:
+ *
+ * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
+ * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
+ *
+ */
+
+#pragma pack(1)
+
+struct hllapi_packet_result
+{
+ int rc;
+};
+
+struct hllapi_packet_query
+{
+ unsigned char packet_id;
+};
+
+struct hllapi_packet_connect
+{
+ unsigned char packet_id;
+ unsigned char wait;
+ char hostname[1];
+};
+
+struct hllapi_packet_keycode
+{
+ unsigned char packet_id;
+ unsigned short keycode;
+};
+
+struct hllapi_packet_cursor
+{
+ unsigned char packet_id;
+ unsigned short row;
+ unsigned short col;
+};
+
+struct hllapi_packet_text
+{
+ unsigned char packet_id;
+ char text[1];
+};
+
+
+struct hllapi_packet_text_at
+{
+ unsigned char packet_id;
+ unsigned short row;
+ unsigned short col;
+ char text[1];
+};
+
+#pragma pack()
+
diff --git a/src/plugins/remotectl/pipesource.c b/src/plugins/remotectl/pipesource.c
index 9877d13..b72c56b 100644
--- a/src/plugins/remotectl/pipesource.c
+++ b/src/plugins/remotectl/pipesource.c
@@ -32,8 +32,6 @@
#include
#include
-#ifdef WIN32
-
#include
#include
#include "remotectl.h"
@@ -385,4 +383,3 @@ static void wait_for_client(pipe_source *source)
return;
}
-#endif // WIN32
diff --git a/src/plugins/remotectl/pluginmain.c b/src/plugins/remotectl/pluginmain.c
new file mode 100644
index 0000000..9458bfa
--- /dev/null
+++ b/src/plugins/remotectl/pluginmain.c
@@ -0,0 +1,763 @@
+/*
+ * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
+ * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
+ * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270.
+ *
+ * Copyright (C) <2008>
+ *
+ * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
+ * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
+ * Free Software Foundation.
+ *
+ * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
+ * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
+ * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
+ * obter mais detalhes.
+ *
+ * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
+ * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
+ * St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Este programa está nomeado como pluginmain.c e possui - linhas de código.
+ *
+ * Contatos:
+ *
+ * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
+ * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
+ *
+ * Agradecimento:
+ *
+ * Hélio Passos
+ *
+ */
+
+ #include "server.h"
+ #include "packets.h"
+ #include
+
+/*--[ Defines ]--------------------------------------------------------------------------------------*/
+
+ #pragma pack(1)
+
+ typedef struct _pipe_source
+ {
+ GSource gsrc;
+ HANDLE hPipe;
+
+ enum _PIPE_STATE
+ {
+ PIPE_STATE_WAITING,
+ PIPE_STATE_READ,
+ PIPE_STATE_PENDING_READ,
+ PIPE_STATE_UNDEFINED,
+ } state;
+
+ OVERLAPPED overlap;
+ unsigned char buffer[PIPE_BUFFER_LENGTH+1];
+ } pipe_source;
+
+ #pragma pack()
+
+
+/*--[ Globals ]--------------------------------------------------------------------------------------*/
+
+ static const gchar control_char = '@';
+
+/*--[ Implement ]------------------------------------------------------------------------------------*/
+
+ static void IO_accept(pipe_source *source)
+ {
+ set_active(FALSE);
+
+ if(ConnectNamedPipe(source->hPipe,&source->overlap))
+ {
+ popup_lasterror("%s",_( "Error in ConnectNamedPipe" ));
+ return;
+ }
+
+ switch(GetLastError())
+ {
+ // The overlapped connection in progress.
+ case ERROR_IO_PENDING:
+ // trace("%s: ERROR_IO_PENDING",__FUNCTION__);
+ source->state = PIPE_STATE_WAITING;
+ break;
+
+ // Client is already connected, so signal an event.
+ case ERROR_PIPE_CONNECTED:
+ trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__);
+ set_active(TRUE);
+ if(SetEvent(source->overlap.hEvent))
+ break;
+
+ // If an error occurs during the connect operation...
+ default:
+ popup_lasterror("%s", _( "ConnectNamedPipe failed" ));
+ }
+
+ }
+
+ static gboolean IO_prepare(GSource *source, gint *timeout)
+ {
+ /*
+ * Called before all the file descriptors are polled.
+ * If the source can determine that it is ready here
+ * (without waiting for the results of the poll() call)
+ * it should return TRUE.
+ *
+ * It can also return a timeout_ value which should be the maximum
+ * timeout (in milliseconds) which should be passed to the poll() call.
+ * The actual timeout used will be -1 if all sources returned -1,
+ * or it will be the minimum of all the timeout_ values
+ * returned which were >= 0.
+ *
+ */
+ if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0)
+ return TRUE;
+
+ *timeout = 10;
+ return FALSE;
+ }
+
+ static gboolean IO_check(GSource *source)
+ {
+ /*
+ * Called after all the file descriptors are polled.
+ * The source should return TRUE if it is ready to be dispatched.
+ * Note that some time may have passed since the previous prepare
+ * function was called, so the source should be checked again here.
+ *
+ */
+ if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0)
+ return TRUE;
+
+ return FALSE;
+ }
+
+/*
+ static void send_message(pipe_source *source, const void *pkt, int sz)
+ {
+ WriteFile(qry->hPipe,&data,wrote,&wrote,NULL);
+
+ }
+*/
+
+ static void send_result(pipe_source *source, int rc)
+ {
+ struct hllapi_packet_result pkt = { rc };
+ DWORD wrote = sizeof(pkt);
+ WriteFile(source->hPipe,&pkt,wrote,&wrote,NULL);
+ }
+
+ static void process_input(pipe_source *source, DWORD cbRead)
+ {
+
+ trace("%s id=%d",__FUNCTION__,source->buffer[0]);
+
+ switch(source->buffer[0])
+ {
+ case HLLAPI_PACKET_CONNECT:
+ send_result(source,lib3270_connect( lib3270_get_default_session_handle(),
+ ((struct hllapi_packet_connect *) source->buffer)->hostname,
+ ((struct hllapi_packet_connect *) source->buffer)->wait));
+ break;
+
+ case HLLAPI_PACKET_DISCONNECT:
+ send_result(source,lib3270_disconnect(lib3270_get_default_session_handle()));
+ break;
+
+ case HLLAPI_PACKET_GET_PROGRAM_MESSAGE:
+ send_result(source,lib3270_get_program_message(lib3270_get_default_session_handle()));
+ break;
+
+ case HLLAPI_PACKET_ENTER:
+ send_result(source,lib3270_enter(lib3270_get_default_session_handle()));
+ break;
+
+ case HLLAPI_PACKET_PFKEY:
+ send_result(source,lib3270_pfkey( lib3270_get_default_session_handle(),
+ ((struct hllapi_packet_keycode *) source->buffer)->keycode));
+ break;
+
+ case HLLAPI_PACKET_PAKEY:
+ send_result(source,lib3270_pakey( lib3270_get_default_session_handle(),
+ ((struct hllapi_packet_keycode *) source->buffer)->keycode));
+ break;
+
+ case HLLAPI_PACKET_SET_CURSOR_POSITION:
+ send_result(source,lib3270_set_cursor_position( lib3270_get_default_session_handle(),
+ ((struct hllapi_packet_cursor *) source->buffer)->row,
+ ((struct hllapi_packet_cursor *) source->buffer)->col));
+ break;
+
+ case HLLAPI_PACKET_SET_TEXT_AT:
+ send_result(source,lib3270_set_text_at( lib3270_get_default_session_handle(),
+ ((struct hllapi_packet_text_at *) source->buffer)->row,
+ ((struct hllapi_packet_text_at *) source->buffer)->col,
+ (unsigned char *) ((struct hllapi_packet_text_at *) source->buffer)->text));
+ break;
+
+ case HLLAPI_PACKET_CMP_TEXT_AT:
+ send_result(source,lib3270_cmp_text_at( lib3270_get_default_session_handle(),
+ ((struct hllapi_packet_text_at *) source->buffer)->row,
+ ((struct hllapi_packet_text_at *) source->buffer)->col,
+ ((struct hllapi_packet_text_at *) source->buffer)->text));
+ break;
+
+ case HLLAPI_PACKET_INPUT_STRING:
+ send_result(source,lib3270_input_string(lib3270_get_default_session_handle(),
+ (unsigned char *) ((struct hllapi_packet_text *) source->buffer)->text));
+ break;
+
+ default:
+ send_result(source, EINVAL);
+ g_message("Invalid remote request (id=%d)",source->buffer[0]);
+ }
+
+ }
+
+ static void read_input_pipe(pipe_source *source)
+ {
+ DWORD cbRead = 0;
+
+ if(ReadFile(source->hPipe,source->buffer,PIPE_BUFFER_LENGTH,&cbRead,&source->overlap) && cbRead > 0)
+ process_input(source,cbRead);
+
+ // The read operation is still pending.
+ switch(GetLastError())
+ {
+ case 0:
+ break;
+
+ case ERROR_IO_PENDING:
+ // trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__);
+ source->state = PIPE_STATE_PENDING_READ;
+ break;
+
+ case ERROR_PIPE_LISTENING:
+ // trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__);
+ source->state = PIPE_STATE_READ;
+ break;
+
+ case ERROR_BROKEN_PIPE:
+ trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__);
+
+ if(!DisconnectNamedPipe(source->hPipe))
+ {
+ set_active(FALSE);
+ popup_lasterror("%s",_( "Error in DisconnectNamedPipe" ));
+ }
+ else
+ {
+ IO_accept(source);
+ }
+ break;
+
+ case ERROR_PIPE_NOT_CONNECTED:
+ trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__);
+ set_active(FALSE);
+ break;
+
+ default:
+ if(source->hPipe != INVALID_HANDLE_VALUE)
+ popup_lasterror("%s",_( "Error receiving message from pipe" ) );
+ }
+
+ }
+
+ static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer data)
+ {
+ /*
+ * Called to dispatch the event source,
+ * after it has returned TRUE in either its prepare or its check function.
+ * The dispatch function is passed in a callback function and data.
+ * The callback function may be NULL if the source was never connected
+ * to a callback using g_source_set_callback(). The dispatch function
+ * should call the callback function with user_data and whatever additional
+ * parameters are needed for this type of event source.
+ */
+ BOOL fSuccess;
+ DWORD cbRead = 0;
+// DWORD dwErr = 0;
+
+ fSuccess = GetOverlappedResult(((pipe_source *) source)->hPipe,&((pipe_source *) source)->overlap,&cbRead,FALSE );
+
+ // trace("%s: source=%p data=%p Result=%s cbRead=%d",__FUNCTION__,source,data,fSuccess ? "Success" : "Unsuccess",(int) cbRead);
+
+ switch(((pipe_source *) source)->state)
+ {
+ case PIPE_STATE_WAITING:
+ if(fSuccess)
+ {
+ trace("Pipe connected (cbRet=%d)",(int) cbRead);
+ set_active(TRUE);
+ ((pipe_source *) source)->state = PIPE_STATE_READ;
+ }
+ else
+ {
+ popup_lasterror("%s", _( "Pipe connection failed" ));
+ }
+ break;
+
+ case PIPE_STATE_READ:
+ // trace("Reading pipe (cbRead=%d)",(int) cbRead);
+ read_input_pipe( (pipe_source *) source);
+ break;
+
+ case PIPE_STATE_PENDING_READ:
+ if(fSuccess && cbRead > 0)
+ process_input((pipe_source *) source,cbRead);
+ ((pipe_source *) source)->state = PIPE_STATE_READ;
+ break;
+
+ case PIPE_STATE_UNDEFINED:
+ break;
+
+//#ifdef DEBUG
+// default:
+// trace("%s: source=%p data=%p Unexpected mode %d",__FUNCTION__,source,data,((pipe_source *) source)->state);
+//#endif
+ }
+
+ return TRUE;
+ }
+
+ static void IO_finalize(GSource *source)
+ {
+// trace("%s: source=%p",__FUNCTION__,source);
+
+ if( ((pipe_source *) source)->hPipe != INVALID_HANDLE_VALUE)
+ {
+ CloseHandle(((pipe_source *) source)->hPipe);
+ ((pipe_source *) source)->hPipe = INVALID_HANDLE_VALUE;
+ }
+
+ }
+
+ static gboolean IO_closure(gpointer data)
+ {
+// trace("%s: data=%p",__FUNCTION__,data);
+ return 0;
+ }
+
+ void popup_lasterror(const gchar *fmt, ...)
+ {
+ char buffer[4096];
+ va_list arg_ptr;
+ int sz;
+ DWORD errcode = GetLastError();
+ char *ptr;
+ LPVOID lpMsgBuf = 0;
+
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
+
+ for(ptr=lpMsgBuf;*ptr && *ptr != '\n';ptr++);
+ *ptr = 0;
+
+ va_start(arg_ptr, fmt);
+ vsnprintf(buffer,4095,fmt,arg_ptr);
+ va_end(arg_ptr);
+
+ sz = strlen(buffer);
+ snprintf(buffer+sz,4096-sz,": %s\n(rc=%d)",lpMsgBuf,(int) errcode);
+
+ printf("%s\n",buffer);
+
+#ifdef DEBUG
+ fprintf(stderr,"%s\n",buffer);
+ fflush(stderr);
+#endif
+
+ LocalFree(lpMsgBuf);
+ }
+
+ LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window)
+ {
+ char id;
+
+ for(id='A';id < 'Z';id++)
+ {
+ gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s_%c",pw3270_get_session_name(window),id);
+ gchar * ptr;
+ HANDLE hPipe;
+
+ for(ptr=pipename;*ptr;ptr++)
+ *ptr = g_ascii_tolower(*ptr);
+
+ hPipe = CreateNamedPipe( TEXT(pipename), // pipe name
+ PIPE_ACCESS_DUPLEX | // read/write access
+ FILE_FLAG_OVERLAPPED, // overlapped mode
+ PIPE_TYPE_MESSAGE | // pipe type
+ PIPE_READMODE_MESSAGE | // pipe mode
+ PIPE_WAIT, // blocking mode
+ 1, // number of instances
+ PIPE_BUFFER_LENGTH, // output buffer size
+ PIPE_BUFFER_LENGTH, // input buffer size
+ NMPWAIT_USE_DEFAULT_WAIT, // client time-out
+ NULL); // default security attributes
+
+ trace("%s = %p",pipename,hPipe);
+ g_free(pipename);
+
+ if(hPipe != INVALID_HANDLE_VALUE)
+ {
+ static GSourceFuncs pipe_source_funcs =
+ {
+ IO_prepare,
+ IO_check,
+ IO_dispatch,
+ IO_finalize,
+ IO_closure,
+ NULL
+ };
+ pipe_source * source;
+ gchar * session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),id);
+
+ pw3270_set_session_name(window,session);
+ g_free(session);
+
+ source = (pipe_source *) g_source_new(&pipe_source_funcs,sizeof(pipe_source));
+
+ source->hPipe = hPipe;
+ source->state = PIPE_STATE_WAITING;
+ source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL);
+
+ g_source_attach((GSource *) source,NULL);
+ IO_accept(source);
+
+ return 0;
+ }
+
+ }
+
+ popup_lasterror( "%s", _( "Can´t create remote control pipe" ));
+
+ return -1;
+ }
+
+ LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window)
+ {
+
+ return 0;
+ }
+
+/*
+ static void cmd_connectps(QUERY *qry)
+ {
+ g_message("%s","HLLAPI ConnectPS request received");
+ request_status(qry,v3270_set_script(pw3270_get_terminal_widget(NULL),'H',TRUE));
+ }
+
+ static void cmd_disconnectps(QUERY *qry)
+ {
+ g_message("%s","HLLAPI DisconnectPS request received");
+ request_status(qry,0);
+ }
+
+ static void cmd_getrevision(QUERY *qry)
+ {
+ request_complete(qry,0,lib3270_get_revision());
+ }
+
+ static void cmd_setcursor(QUERY *qry)
+ {
+ int rc = ENOTCONN;
+
+ if(lib3270_connected(qry->hSession))
+ {
+ trace("%s: pos=%d row=%d col=%d",__FUNCTION__,rc,rc/80,rc%80);
+ lib3270_set_cursor_address(qry->hSession,qry->pos -1);
+ rc = 0;
+ }
+
+ request_status(qry,rc);
+ }
+
+ static void cmd_sendstring(QUERY *qry)
+ {
+ gchar * text;
+ GError * error = NULL;
+ gsize bytes_read;
+ gsize bytes_written;
+ const gchar * charset;
+
+ if(!lib3270_connected(qry->hSession))
+ {
+ request_status(qry,ENOTCONN);
+ return;
+ }
+
+ g_get_charset(&charset);
+
+ text = g_convert(qry->text,qry->length,lib3270_get_charset(qry->hSession),charset,&bytes_read,&bytes_written,&error);
+ if(text)
+ {
+ int rc = 0;
+
+ if(strchr(text,control_char))
+ {
+ // Convert control char
+ gchar * buffer = text;
+ char * ptr;
+
+ for(ptr = strchr(text,control_char);ptr;ptr = strchr(buffer,control_char))
+ {
+ *(ptr++) = 0;
+
+ lib3270_emulate_input(qry->hSession,buffer,-1,0);
+
+ switch(*(ptr++))
+ {
+ case 'P': // Print
+ rc = pw3270_print(pw3270_get_terminal_widget(NULL), NULL, GTK_PRINT_OPERATION_ACTION_PRINT, PW3270_SRC_ALL);
+ break;
+
+ case 'E': // Enter
+ lib3270_enter(qry->hSession);
+ break;
+
+ case 'F': // Erase EOF
+ lib3270_eraseeof(qry->hSession);
+ break;
+
+ case '1': // PF1
+ lib3270_pfkey(qry->hSession,1);
+ break;
+
+ case '2': // PF2
+ lib3270_pfkey(qry->hSession,2);
+ break;
+
+ case '3': // PF3
+ lib3270_pfkey(qry->hSession,3);
+ break;
+
+ case '4': // PF4
+ lib3270_pfkey(qry->hSession,4);
+ break;
+
+ case '5': // PF5
+ lib3270_pfkey(qry->hSession,5);
+ break;
+
+ case '6': // PF6
+ lib3270_pfkey(qry->hSession,6);
+ break;
+
+ case '7': // PF7
+ lib3270_pfkey(qry->hSession,7);
+ break;
+
+ case '8': // PF8
+ lib3270_pfkey(qry->hSession,8);
+ break;
+
+ case '9': // PF9
+ lib3270_pfkey(qry->hSession,9);
+ break;
+
+ case 'a': // PF10
+ lib3270_pfkey(qry->hSession,10);
+ break;
+
+ case 'b': // PF11
+ lib3270_pfkey(qry->hSession,11);
+ break;
+
+ case 'c': // PF12
+ lib3270_pfkey(qry->hSession,12);
+ break;
+ }
+
+ }
+
+ lib3270_emulate_input(qry->hSession,buffer,-1,0);
+
+ }
+ else
+ {
+ lib3270_emulate_input(qry->hSession,text,strlen(text),0);
+ }
+ g_free(text);
+
+ request_status(qry,rc);
+
+ return;
+ }
+
+ request_complete(qry, error->code, error->message);
+ g_error_free(error);
+
+ }
+
+ struct wait
+ {
+ QUERY * qry;
+ time_t end;
+ };
+
+ static gboolean do_wait(struct wait *w)
+ {
+ if(lib3270_get_program_message(w->qry->hSession) == LIB3270_MESSAGE_NONE)
+ {
+ request_status(w->qry,0);
+ return FALSE;
+ }
+
+ if(time(0) > w->end)
+ {
+ trace("%s: TIMEOUT",__FUNCTION__);
+ request_status(w->qry,ETIMEDOUT);
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ static void cmd_wait(QUERY *qry)
+ {
+ struct wait *w;
+
+ if(lib3270_get_program_message(qry->hSession) == LIB3270_MESSAGE_NONE)
+ {
+ request_status(qry,0);
+ return;
+ }
+
+ w = g_malloc0(sizeof(struct wait));
+ w->qry = qry;
+ w->end = time(0)+pw3270_get_integer(pw3270_get_toplevel(),"hllapi","wait",2);
+
+ g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) 300, (GSourceFunc) do_wait, w, g_free);
+ }
+
+ static void cmd_copypstostr(QUERY *qry)
+ {
+ int rows;
+ int cols;
+ unsigned short * attr;
+ unsigned char * text;
+ int rc;
+ unsigned char * buffer;
+ size_t length;
+
+ if(!lib3270_connected(qry->hSession))
+ {
+ request_status(qry,ENOTCONN);
+ return;
+ }
+
+ lib3270_get_screen_size(qry->hSession,&rows,&cols);
+
+ if(qry->pos < 1 || (qry->pos+qry->length) >= (rows*cols))
+ {
+ request_status(qry,EINVAL);
+ return;
+ }
+
+ qry->pos--;
+
+ length = (qry->length * sizeof(unsigned short)) + qry->length + 2;
+ text = buffer = g_malloc0(length+1);
+ attr = (unsigned short *) (text+qry->length+1);
+
+ trace("%s: pos=%d length=%d",__FUNCTION__,qry->pos,qry->length);
+ rc = lib3270_get_contents(qry->hSession,qry->pos,qry->pos+(qry->length-1),text,attr);
+
+ if(rc)
+ {
+ request_status(qry,rc);
+ }
+ else
+ {
+ const gchar * charset;
+ gchar * local;
+ gsize bytes_read;
+ gsize bytes_written;
+ GError * error = NULL;
+
+ trace("Text: [%s]",text);
+
+ g_get_charset(&charset);
+
+ local = g_convert((const gchar *) text,-1,charset,lib3270_get_charset(qry->hSession),&bytes_read,&bytes_written,&error);
+
+ if(!local)
+ {
+ request_complete(qry,error->code,error->message);
+ g_error_free(error);
+ }
+ else
+ {
+ strncpy((char *) text,(const char *) local,qry->length);
+
+ trace("response: [%s] len=%d",buffer,length);
+ request_buffer(qry,0,length,buffer);
+ g_free(local);
+ }
+ }
+
+ g_free(buffer);
+ }
+
+ static void cmd_querycursor(QUERY *qry)
+ {
+ request_value(qry,0,lib3270_get_cursor_address(qry->hSession));
+ }
+
+ void enqueue_request(QUERY *qry)
+ {
+ static const struct _cmd
+ {
+ int cmd;
+ void (*exec)(QUERY *qry);
+ } cmd[] =
+ {
+ { HLLAPI_CMD_CONNECTPS, cmd_connectps }, // 1
+ { HLLAPI_CMD_DISCONNECTPS, cmd_disconnectps }, // 2
+ { HLLAPI_CMD_INPUTSTRING, cmd_sendstring }, // 3
+ { HLLAPI_CMD_WAIT, cmd_wait }, // 4
+// { HLLAPI_CMD_COPYPS, }, // 5
+// { HLLAPI_CMD_SEARCHPS, }, // 6
+ { HLLAPI_CMD_QUERYCURSOR, cmd_querycursor }, // 7
+
+ { HLLAPI_CMD_COPYPSTOSTR, cmd_copypstostr }, // 8
+
+// { HLLAPI_CMD_COPYSTRTOPS }, // 15
+
+ { HLLAPI_CMD_SETCURSOR, cmd_setcursor }, // 40
+
+// { HLLAPI_CMD_SENDFILE }, // 90
+// { HLLAPI_CMD_RECEIVEFILE },
+
+
+ { HLLAPI_CMD_GETREVISION, cmd_getrevision },
+ };
+
+
+
+ int f;
+
+ trace("HLLAPI function %d",(int) qry->cmd);
+
+ qry->hSession = lib3270_get_default_session_handle();
+
+ for(f=0;fcmd)
+ {
+ cmd[f].exec(qry);
+ return;
+ }
+ }
+
+ g_warning("Unexpected HLLAPI function %d",(int) qry->cmd);
+ request_status(qry,EINVAL);
+ }
+
+ G_GNUC_INTERNAL void set_active(gboolean on)
+ {
+ v3270_set_script(pw3270_get_terminal_widget(NULL),'H',on);
+ }
+
+*/
diff --git a/src/plugins/remotectl/remotectl.c b/src/plugins/remotectl/remotectl.c
deleted file mode 100644
index 709b10a..0000000
--- a/src/plugins/remotectl/remotectl.c
+++ /dev/null
@@ -1,468 +0,0 @@
-/*
- * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
- * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
- * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270.
- *
- * Copyright (C) <2008>
- *
- * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
- * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
- * Free Software Foundation.
- *
- * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
- * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
- * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
- * obter mais detalhes.
- *
- * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
- * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
- * St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Este programa está nomeado como remotectl.c e possui - linhas de código.
- *
- * Contatos:
- *
- * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
- * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
- *
- * Agradecimento:
- *
- * Hélio Passos
- *
- */
-
- #include "remotectl.h"
- #include
- #include
- #include
- #include
- #include
- #include
-
-#ifndef ETIMEDOUT
- #define ETIMEDOUT 1238
-#endif // ETIMEDOUT
-
-/*--[ Globals ]--------------------------------------------------------------------------------------*/
-
- static const gchar control_char = '@';
-
-/*--[ Implement ]------------------------------------------------------------------------------------*/
-
-#ifdef WIN32
-
- void popup_lasterror(const gchar *fmt, ...)
- {
- char buffer[4096];
- va_list arg_ptr;
- int sz;
- DWORD errcode = GetLastError();
- char *ptr;
- LPVOID lpMsgBuf = 0;
-
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
-
- for(ptr=lpMsgBuf;*ptr && *ptr != '\n';ptr++);
- *ptr = 0;
-
- va_start(arg_ptr, fmt);
- vsnprintf(buffer,4095,fmt,arg_ptr);
- va_end(arg_ptr);
-
- sz = strlen(buffer);
- snprintf(buffer+sz,4096-sz,": %s\n(rc=%d)",lpMsgBuf,(int) errcode);
-
- printf("%s\n",buffer);
-
-#ifdef DEBUG
- fprintf(stderr,"%s\n",buffer);
- fflush(stderr);
-#endif
-
- LocalFree(lpMsgBuf);
- }
-
-#endif // WIN32
-
- LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window)
- {
-#ifdef WIN32
- char id;
-
- for(id='A';id < 'Z';id++)
- {
- gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s%c",pw3270_get_session_name(window),id);
-
- HANDLE hPipe = CreateNamedPipe( TEXT(pipename), // pipe name
- PIPE_ACCESS_DUPLEX | // read/write access
- FILE_FLAG_OVERLAPPED, // overlapped mode
- PIPE_TYPE_MESSAGE | // pipe type
- PIPE_READMODE_MESSAGE | // pipe mode
- PIPE_WAIT, // blocking mode
- 1, // number of instances
- PIPE_BUFFER_LENGTH, // output buffer size
- PIPE_BUFFER_LENGTH, // input buffer size
- NMPWAIT_USE_DEFAULT_WAIT, // client time-out
- NULL); // default security attributes
-
- trace("%s = %p",pipename,hPipe);
- g_free(pipename);
-
- if(hPipe != INVALID_HANDLE_VALUE)
- {
- gchar *session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),id);
- pw3270_set_session_name(window,session);
- g_free(session);
-
- init_source_pipe(hPipe);
- return 0;
- }
-
- }
-
- popup_lasterror( "%s", _( "Can´t create remote control pipe" ));
- return -1;
-
-#else
-
- #error Nao implementado
-
-#endif // WIN32
-
- return 0;
- }
-
- LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window)
- {
-#ifdef WIN32
-
-#else
-
- #error Nao implementado
-
-#endif // WIN32
-
- set_active(FALSE);
-
- return 0;
- }
-
- static void cmd_connectps(QUERY *qry)
- {
- g_message("%s","HLLAPI ConnectPS request received");
- request_status(qry,v3270_set_script(pw3270_get_terminal_widget(NULL),'H',TRUE));
- }
-
- static void cmd_disconnectps(QUERY *qry)
- {
- g_message("%s","HLLAPI DisconnectPS request received");
- request_status(qry,0);
- }
-
- static void cmd_getrevision(QUERY *qry)
- {
- request_complete(qry,0,lib3270_get_revision());
- }
-
- static void cmd_setcursor(QUERY *qry)
- {
- int rc = ENOTCONN;
-
- if(lib3270_connected(qry->hSession))
- {
- trace("%s: pos=%d row=%d col=%d",__FUNCTION__,rc,rc/80,rc%80);
- lib3270_set_cursor_address(qry->hSession,qry->pos -1);
- rc = 0;
- }
-
- request_status(qry,rc);
- }
-
- static void cmd_sendstring(QUERY *qry)
- {
- gchar * text;
- GError * error = NULL;
- gsize bytes_read;
- gsize bytes_written;
- const gchar * charset;
-
- if(!lib3270_connected(qry->hSession))
- {
- request_status(qry,ENOTCONN);
- return;
- }
-
- g_get_charset(&charset);
-
- text = g_convert(qry->text,qry->length,lib3270_get_charset(qry->hSession),charset,&bytes_read,&bytes_written,&error);
- if(text)
- {
- int rc = 0;
-
- if(strchr(text,control_char))
- {
- // Convert control char
- gchar * buffer = text;
- char * ptr;
-
- for(ptr = strchr(text,control_char);ptr;ptr = strchr(buffer,control_char))
- {
- *(ptr++) = 0;
-
- lib3270_emulate_input(qry->hSession,buffer,-1,0);
-
- switch(*(ptr++))
- {
- case 'P': // Print
- rc = pw3270_print(pw3270_get_terminal_widget(NULL), NULL, GTK_PRINT_OPERATION_ACTION_PRINT, PW3270_SRC_ALL);
- break;
-
- case 'E': // Enter
- lib3270_enter(qry->hSession);
- break;
-
- case 'F': // Erase EOF
- lib3270_eraseeof(qry->hSession);
- break;
-
- case '1': // PF1
- lib3270_pfkey(qry->hSession,1);
- break;
-
- case '2': // PF2
- lib3270_pfkey(qry->hSession,2);
- break;
-
- case '3': // PF3
- lib3270_pfkey(qry->hSession,3);
- break;
-
- case '4': // PF4
- lib3270_pfkey(qry->hSession,4);
- break;
-
- case '5': // PF5
- lib3270_pfkey(qry->hSession,5);
- break;
-
- case '6': // PF6
- lib3270_pfkey(qry->hSession,6);
- break;
-
- case '7': // PF7
- lib3270_pfkey(qry->hSession,7);
- break;
-
- case '8': // PF8
- lib3270_pfkey(qry->hSession,8);
- break;
-
- case '9': // PF9
- lib3270_pfkey(qry->hSession,9);
- break;
-
- case 'a': // PF10
- lib3270_pfkey(qry->hSession,10);
- break;
-
- case 'b': // PF11
- lib3270_pfkey(qry->hSession,11);
- break;
-
- case 'c': // PF12
- lib3270_pfkey(qry->hSession,12);
- break;
- }
-
- }
-
- lib3270_emulate_input(qry->hSession,buffer,-1,0);
-
- }
- else
- {
- lib3270_emulate_input(qry->hSession,text,strlen(text),0);
- }
- g_free(text);
-
- request_status(qry,rc);
-
- return;
- }
-
- request_complete(qry, error->code, error->message);
- g_error_free(error);
-
- }
-
- struct wait
- {
- QUERY * qry;
- time_t end;
- };
-
- static gboolean do_wait(struct wait *w)
- {
- if(lib3270_get_program_message(w->qry->hSession) == LIB3270_MESSAGE_NONE)
- {
- request_status(w->qry,0);
- return FALSE;
- }
-
- if(time(0) > w->end)
- {
- trace("%s: TIMEOUT",__FUNCTION__);
- request_status(w->qry,ETIMEDOUT);
- return FALSE;
- }
-
- return TRUE;
- }
-
- static void cmd_wait(QUERY *qry)
- {
- struct wait *w;
-
- if(lib3270_get_program_message(qry->hSession) == LIB3270_MESSAGE_NONE)
- {
- request_status(qry,0);
- return;
- }
-
- w = g_malloc0(sizeof(struct wait));
- w->qry = qry;
- w->end = time(0)+pw3270_get_integer(pw3270_get_toplevel(),"hllapi","wait",2);
-
- g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) 300, (GSourceFunc) do_wait, w, g_free);
- }
-
- static void cmd_copypstostr(QUERY *qry)
- {
- int rows;
- int cols;
- unsigned short * attr;
- unsigned char * text;
- int rc;
- unsigned char * buffer;
- size_t length;
-
- if(!lib3270_connected(qry->hSession))
- {
- request_status(qry,ENOTCONN);
- return;
- }
-
- lib3270_get_screen_size(qry->hSession,&rows,&cols);
-
- if(qry->pos < 1 || (qry->pos+qry->length) >= (rows*cols))
- {
- request_status(qry,EINVAL);
- return;
- }
-
- qry->pos--;
-
- length = (qry->length * sizeof(unsigned short)) + qry->length + 2;
- text = buffer = g_malloc0(length+1);
- attr = (unsigned short *) (text+qry->length+1);
-
- trace("%s: pos=%d length=%d",__FUNCTION__,qry->pos,qry->length);
- rc = lib3270_get_contents(qry->hSession,qry->pos,qry->pos+(qry->length-1),text,attr);
-
- if(rc)
- {
- request_status(qry,rc);
- }
- else
- {
- const gchar * charset;
- gchar * local;
- gsize bytes_read;
- gsize bytes_written;
- GError * error = NULL;
-
- trace("Text: [%s]",text);
-
- g_get_charset(&charset);
-
- local = g_convert((const gchar *) text,-1,charset,lib3270_get_charset(qry->hSession),&bytes_read,&bytes_written,&error);
-
- if(!local)
- {
- request_complete(qry,error->code,error->message);
- g_error_free(error);
- }
- else
- {
- strncpy((char *) text,(const char *) local,qry->length);
-
- trace("response: [%s] len=%d",buffer,length);
- request_buffer(qry,0,length,buffer);
- g_free(local);
- }
- }
-
- g_free(buffer);
- }
-
- static void cmd_querycursor(QUERY *qry)
- {
- request_value(qry,0,lib3270_get_cursor_address(qry->hSession));
- }
-
- void enqueue_request(QUERY *qry)
- {
- static const struct _cmd
- {
- int cmd;
- void (*exec)(QUERY *qry);
- } cmd[] =
- {
- { HLLAPI_CMD_CONNECTPS, cmd_connectps }, // 1
- { HLLAPI_CMD_DISCONNECTPS, cmd_disconnectps }, // 2
- { HLLAPI_CMD_INPUTSTRING, cmd_sendstring }, // 3
- { HLLAPI_CMD_WAIT, cmd_wait }, // 4
-// { HLLAPI_CMD_COPYPS, }, // 5
-// { HLLAPI_CMD_SEARCHPS, }, // 6
- { HLLAPI_CMD_QUERYCURSOR, cmd_querycursor }, // 7
-
- { HLLAPI_CMD_COPYPSTOSTR, cmd_copypstostr }, // 8
-
-// { HLLAPI_CMD_COPYSTRTOPS }, // 15
-
- { HLLAPI_CMD_SETCURSOR, cmd_setcursor }, // 40
-
-// { HLLAPI_CMD_SENDFILE }, // 90
-// { HLLAPI_CMD_RECEIVEFILE },
-
-
- { HLLAPI_CMD_GETREVISION, cmd_getrevision },
- };
-
-
-
- int f;
-
- trace("HLLAPI function %d",(int) qry->cmd);
-
- qry->hSession = lib3270_get_default_session_handle();
-
- for(f=0;fcmd)
- {
- cmd[f].exec(qry);
- return;
- }
- }
-
- g_warning("Unexpected HLLAPI function %d",(int) qry->cmd);
- request_status(qry,EINVAL);
- }
-
- G_GNUC_INTERNAL void set_active(gboolean on)
- {
- v3270_set_script(pw3270_get_terminal_widget(NULL),'H',on);
- }
-
-
diff --git a/src/plugins/remotectl/server.h b/src/plugins/remotectl/server.h
new file mode 100644
index 0000000..65e70df
--- /dev/null
+++ b/src/plugins/remotectl/server.h
@@ -0,0 +1,51 @@
+/*
+ * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
+ * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
+ * aplicativos mainframe. Registro no INPI sob o nome G3270.
+ *
+ * Copyright (C) <2008>
+ *
+ * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
+ * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
+ * Free Software Foundation.
+ *
+ * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
+ * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
+ * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
+ * obter mais detalhes.
+ *
+ * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
+ * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA, 02111-1307, USA
+ *
+ * Este programa está nomeado como server.h e possui - linhas de código.
+ *
+ * Contatos:
+ *
+ * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
+ * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
+ *
+ */
+
+ #include
+ #define ENABLE_NLS
+ #define GETTEXT_PACKAGE PACKAGE_NAME
+
+ #include
+ #include
+ #include
+
+ #include
+ #include
+ #include
+ #include
+
+ #include
+
+ #define PIPE_BUFFER_LENGTH HLLAPI_MAXLENGTH+30
+
+ #define set_active(x) /* x */
+
+
+ G_GNUC_INTERNAL void popup_lasterror(const gchar *fmt, ...);
+
diff --git a/src/plugins/remotectl/testprogram.c b/src/plugins/remotectl/testprogram.c
index e607ee3..0f0b1d0 100644
--- a/src/plugins/remotectl/testprogram.c
+++ b/src/plugins/remotectl/testprogram.c
@@ -38,6 +38,15 @@
int main(int numpar, char *param[])
{
+ const char *session = "pw3270:a";
+
+ printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session));
+ printf("revision=%d\n",(int) hllapi_get_revision());
+ printf("connect=%d\n",(int) hllapi_connect("fandezhi.efglobe.com:23"));
+
+ printf("deinit=%d\n",(int) hllapi_deinit());
+
+/*
DWORD revision;
int rc;
@@ -54,8 +63,8 @@
printf("Deinit exits with rc=%d\n",rc);
rc = hllapi_deinit();
-
- return rc;
+*/
+ return 0;
}
/*
diff --git a/src/pw3270/common/config.c b/src/pw3270/common/config.c
index d93ebaa..3a0693c 100644
--- a/src/pw3270/common/config.c
+++ b/src/pw3270/common/config.c
@@ -111,7 +111,7 @@ gchar * get_last_error_msg(void)
}
}
- trace("Cant open \"%s\"",path);
+// trace("Cant open \"%s\"",path);
g_free(path);
return FALSE;
@@ -602,8 +602,10 @@ gchar * filename_from_va(const gchar *first_element, va_list args)
}
else
{
- gchar *msg = g_win32_error_message(rc);
- g_message("Error \"%s\" when getting application datadir from registry",msg);
+ gchar *msg = g_win32_error_message(rc);
+#ifndef DEBUG
+ g_message("Error \"%s\" when getting application datadir from registry",msg);
+#endif // !DEBUG
g_free(msg);
}
RegCloseKey(hKey);
@@ -611,7 +613,9 @@ gchar * filename_from_va(const gchar *first_element, va_list args)
else
{
gchar *msg = g_win32_error_message(rc);
- g_message("Error \"%s\" when opening datadir key from registry",msg);
+#ifndef DEBUG
+ g_message("Error \"%s\" when opening datadir key from registry",msg);
+#endif // !DEBUG
g_free(msg);
}
@@ -633,7 +637,7 @@ gchar * filename_from_va(const gchar *first_element, va_list args)
for(f=0;dir[f] && !datadir;f++)
{
gchar *name = g_build_filename(dir[f],appname[p],NULL);
- trace("Searching for %s: %s",name,g_file_test(name,G_FILE_TEST_IS_DIR) ? "Ok" : "Not found");
+// trace("Searching for %s: %s",name,g_file_test(name,G_FILE_TEST_IS_DIR) ? "Ok" : "Not found");
if(g_file_test(name,G_FILE_TEST_IS_DIR))
result = g_string_new(datadir = name);
else
diff --git a/src/pw3270/plugin.c b/src/pw3270/plugin.c
index 18873df..83e05fe 100644
--- a/src/pw3270/plugin.c
+++ b/src/pw3270/plugin.c
@@ -46,11 +46,11 @@
GError * err = NULL;
GList * lst = NULL;
+ trace("Loading plugins from %s",path);
+
if(!g_file_test(path,G_FILE_TEST_IS_DIR))
return;
- trace("Loading plugins from %s",path);
-
dir = g_dir_open(path,0,&err);
if(!dir)
{
@@ -135,7 +135,31 @@
LIB3270_EXPORT void pw3270_init_plugins(GtkWidget *widget)
{
-#if ! defined(DEBUG)
+#if defined( DEBUG )
+
+ gchar * dir = g_get_current_dir();
+ gchar * path = g_build_filename(dir,"plugins",NULL);
+
+ trace("%s testing [%s]",__FUNCTION__,path);
+
+ if(!g_file_test(path,G_FILE_TEST_IS_DIR))
+ {
+ g_free(path);
+ path = pw3270_build_filename(widget,"plugins",NULL);
+ }
+
+ load(path,widget);
+
+ g_free(path);
+ g_free(dir);
+
+#elif defined( WIN32 )
+
+ gchar * path = pw3270_build_filename(widget,"plugins",NULL);
+ load(path, widget);
+ g_free(path);
+
+#else
const gchar * appname[] = { g_get_application_name(), PACKAGE_NAME };
int f;
@@ -143,7 +167,7 @@
for(f=0;f