diff --git a/pw3270.cbp b/pw3270.cbp
index 3159e9e..c570b5d 100644
--- a/pw3270.cbp
+++ b/pw3270.cbp
@@ -247,6 +247,7 @@
+
diff --git a/src/include/pw3270/hllapi.h b/src/include/pw3270/hllapi.h
index 743828b..473bdfe 100644
--- a/src/include/pw3270/hllapi.h
+++ b/src/include/pw3270/hllapi.h
@@ -85,9 +85,10 @@ extern "C" {
__declspec (dllexport) DWORD __stdcall hllapi_get_revision(void);
- __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri);
+ __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait);
__declspec (dllexport) DWORD __stdcall hllapi_disconnect(void);
__declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void);
+ __declspec (dllexport) DWORD __stdcall hllapi_is_connected(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);
diff --git a/src/plugins/remotectl/calls.c b/src/plugins/remotectl/calls.c
index cc9bc2b..e1729f2 100644
--- a/src/plugins/remotectl/calls.c
+++ b/src/plugins/remotectl/calls.c
@@ -36,6 +36,9 @@
#include
#include
#include "client.h"
+
+ #undef trace
+ #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } }
/*--[ Globals ]--------------------------------------------------------------------------------------*/
@@ -46,6 +49,7 @@
static void (*session_free)(void *h) = NULL;
static const char * (*get_revision)(void) = NULL;
static int (*host_connect)(void *h,const char *n, int wait) = NULL;
+ static int (*host_is_connected)(void *h) = NULL;
static int (*wait_for_ready)(void *h, int seconds) = NULL;
static void (*host_disconnect)(void *h) = NULL;
static int (*script_sleep)(void *h, int seconds) = NULL;
@@ -70,8 +74,9 @@
{ (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 **) &host_is_connected, (void *) NULL, "lib3270_in_tn3270e" },
+ { (void **) &wait_for_ready, (void *) NULL, "lib3270_wait_for_ready" },
+ { (void **) &script_sleep, (void *) NULL, "lib3270_wait" },
{ (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" },
{ (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" },
{ (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" },
@@ -98,9 +103,21 @@
trace("%s(%s)",__FUNCTION__,(char *) mode);
- if(!(mode && *mode))
+ if(mode && *mode)
+ {
+ // Get pointers to the pipe based calls
+ int f;
+
+ trace("%s: Loading pipe based calls",__FUNCTION__);
+ for(f=0;entry_point[f].name;f++)
+ *entry_point[f].call = entry_point[f].pipe;
+
+ }
+ else
{
// Direct mode, load lib3270.dll, get pointers to the calls
+ static const char *dllname = "lib3270.dll." PACKAGE_VERSION;
+
int f;
HKEY hKey = 0;
HMODULE kernel;
@@ -109,11 +126,13 @@
HANDLE (*AddDllDirectory)(PCWSTR NewDirectory);
BOOL (*RemoveDllDirectory)(HANDLE Cookie);
UINT errorMode;
+ char datadir[4096];
trace("hModule=%p",hModule);
if(hModule)
return EBUSY;
+ *datadir = 0;
kernel = LoadLibrary("kernel32.dll");
AddDllDirectory = (HANDLE (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory");
RemoveDllDirectory = (BOOL (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory");
@@ -123,27 +142,41 @@
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS)
{
- char data[4096];
- unsigned long datalen = sizeof(data); // data field length(in), data returned length(out)
+ unsigned long datalen = sizeof(datadir); // data field length(in), data returned length(out)
unsigned long datatype; // #defined in winnt.h (predefined types 0-11)
- if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) data,&datalen) == ERROR_SUCCESS)
+ if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) == ERROR_SUCCESS)
{
// Datadir is set, add it to DLL load path
wchar_t path[4096];
- mbstowcs(path, data, 4095);
- trace("Datadir=[%s] AddDllDirectory=%p RemoveDllDirectory=%p\n",data,AddDllDirectory,RemoveDllDirectory);
+ mbstowcs(path, datadir, 4095);
+ trace("Datadir=[%s] AddDllDirectory=%p RemoveDllDirectory=%p\n",datadir,AddDllDirectory,RemoveDllDirectory);
if(AddDllDirectory)
cookie = AddDllDirectory(path);
}
RegCloseKey(hKey);
}
- hModule = LoadLibraryEx("lib3270.dll.5.0",NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
+// hModule = LoadLibraryEx("lib3270.dll.5.0",NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS|LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
+ hModule = LoadLibrary(dllname);
rc = GetLastError();
- trace("hModule=%p rc=%d",hModule,(int) rc);
SetErrorMode(errorMode);
+ trace("%s hModule=%p rc=%d",dllname,hModule,(int) rc);
+
+ if(rc == ERROR_MOD_NOT_FOUND && *datadir)
+ {
+ char buffer[4096];
+#ifdef DEBUG
+ snprintf(buffer,4096,"%s\\.bin\\Debug\\%s",datadir,dllname);
+#else
+ snprintf(buffer,4096,"%s\\%s",datadir,dllname);
+#endif // DEBUG
+
+ hModule = LoadLibrary(buffer);
+ trace("%s hModule=%p rc=%d",buffer,hModule,(int) rc);
+ }
+
if(cookie && RemoveDllDirectory)
RemoveDllDirectory(cookie);
@@ -170,16 +203,6 @@
}
}
- else
- {
- // Get pointers to the pipe based calls
- int f;
-
- for(f=0;entry_point[f].name;f++)
- *entry_point[f].call = entry_point[f].pipe;
-
- }
-
// Get session handle
hSession = session_new((const char *) mode);
trace("%s ok hSession=%p\n",__FUNCTION__,hSession);
@@ -214,12 +237,20 @@
return (DWORD) atoi(get_revision());
}
- __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri)
+ __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait)
{
if(!(host_connect && hSession && uri))
return EINVAL;
- return host_connect(hSession,uri,0);
+ return host_connect(hSession,uri,wait);
+ }
+
+ __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void)
+ {
+ if(!(host_is_connected && hSession))
+ return EINVAL;
+
+ return host_is_connected(hSession);
}
__declspec (dllexport) DWORD __stdcall hllapi_disconnect(void)
diff --git a/src/plugins/remotectl/hllapi.c b/src/plugins/remotectl/hllapi.c
index 41bf934..f6e497a 100644
--- a/src/plugins/remotectl/hllapi.c
+++ b/src/plugins/remotectl/hllapi.c
@@ -47,9 +47,54 @@
LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc)
#endif // _WIN32
{
+ switch(*func)
+ {
+ case HLLAPI_CMD_CONNECTPS:
+ break;
+ case HLLAPI_CMD_DISCONNECTPS:
+ break;
- return -1;
+ case HLLAPI_CMD_INPUTSTRING:
+ break;
+
+ case HLLAPI_CMD_WAIT:
+ break;
+
+ case HLLAPI_CMD_COPYPS:
+ break;
+
+ case HLLAPI_CMD_SEARCHPS:
+ break;
+
+ case HLLAPI_CMD_QUERYCURSOR:
+ break;
+
+ case HLLAPI_CMD_COPYPSTOSTR:
+ break;
+
+ case HLLAPI_CMD_COPYSTRTOPS:
+ break;
+
+ case HLLAPI_CMD_SETCURSOR:
+ break;
+
+ case HLLAPI_CMD_SENDFILE:
+ break;
+
+ case HLLAPI_CMD_RECEIVEFILE:
+ break;
+
+ case HLLAPI_CMD_GETREVISION:
+ break;
+
+ default:
+ *rc = EINVAL;
+ return EINVAL;
+ }
+
+
+ return 0;
}
/*
diff --git a/src/plugins/remotectl/remote.c b/src/plugins/remotectl/remote.c
new file mode 100644
index 0000000..0c18c5e
--- /dev/null
+++ b/src/plugins/remotectl/remote.c
@@ -0,0 +1,242 @@
+/*
+ * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
+ * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
+ * aplicativos mainframe. Registro no INPI sob o nome G3270.
+ *
+ * Copyright (C) <2008>
+ *
+ * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
+ * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
+ * Free Software Foundation.
+ *
+ * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
+ * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
+ * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
+ * obter mais detalhes.
+ *
+ * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
+ * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA, 02111-1307, USA
+ *
+ * Este programa está nomeado como calls.c e possui - linhas de código.
+ *
+ * Contatos:
+ *
+ * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
+ * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
+ *
+ */
+
+ #include
+ #include
+ #include
+ #include
+ #include
+ #include
+
+ #include "client.h"
+ #include "packets.h"
+
+/*--[ Globals ]--------------------------------------------------------------------------------------*/
+
+/*--[ Implement ]------------------------------------------------------------------------------------*/
+
+ void * hllapi_pipe_init(const char *id)
+ {
+ HANDLE hPipe = INVALID_HANDLE_VALUE;
+ static DWORD dwMode = PIPE_READMODE_MESSAGE;
+ char buffer[4096];
+ char * name = strdup(id);
+ char * ptr;
+
+ trace("%s(%s)",__FUNCTION__,id);
+
+ for(ptr=name;*ptr;ptr++)
+ {
+ if(*ptr == ':')
+ *ptr = '_';
+ }
+
+ snprintf(buffer,4095,"\\\\.\\pipe\\%s",name);
+
+ free(name);
+
+ trace("Opening \"%s\"",buffer);
+
+ if(!WaitNamedPipe(buffer,NMPWAIT_USE_DEFAULT_WAIT))
+ {
+ trace("%s: Pipe not found",__FUNCTION__);
+ errno = ENOENT;
+ return NULL;
+ }
+
+ hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
+
+ if(hPipe == INVALID_HANDLE_VALUE)
+ {
+ errno = GetLastError();
+ return NULL;
+ }
+
+ if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL))
+ {
+ errno = GetLastError();
+ return NULL;
+ }
+
+ trace("hPipe=%p",(void *) hPipe);
+ return hPipe;
+ }
+
+ void hllapi_pipe_deinit(void *h)
+ {
+ trace("%s(%p)",__FUNCTION__,h);
+
+ if(!h)
+ return;
+
+ CloseHandle((HANDLE) h);
+ }
+
+ const char * hllapi_pipe_get_revision(void)
+ {
+ return PACKAGE_REVISION;
+ }
+
+ int hllapi_pipe_connect(void *h, const char *n, int wait)
+ {
+ struct hllapi_packet_connect * pkt;
+ struct hllapi_packet_result response;
+ DWORD cbSize;
+
+ if(!n)
+ n = "";
+
+ cbSize = sizeof(struct hllapi_packet_connect)+strlen(n);
+ pkt = malloc(cbSize);
+
+ pkt->packet_id = HLLAPI_PACKET_CONNECT;
+ pkt->wait = (unsigned char) wait;
+ strcpy(pkt->hostname,n);
+
+ trace("Sending %s",pkt->hostname);
+
+ if(!TransactNamedPipe((HANDLE) h,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL))
+ {
+ errno = GetLastError();
+ response.rc = -1;
+ }
+
+ free(pkt);
+
+ return response.rc;
+ }
+
+ void hllapi_pipe_disconnect(void *h)
+ {
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_DISCONNECT };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ }
+
+ LIB3270_MESSAGE hllapi_pipe_get_message(void *h)
+ {
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_PROGRAM_MESSAGE };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return (LIB3270_MESSAGE) response.rc;
+ }
+
+ char * hllapi_pipe_get_text_at(void *h, int row, int col, int len)
+ {
+ struct hllapi_packet_query_at query = { HLLAPI_PACKET_GET_TEXT_AT, };
+ struct hllapi_packet_text * response;
+ DWORD cbSize = sizeof(struct hllapi_packet_text)+len;
+ char * text = NULL;
+
+ response = malloc(cbSize+2);
+ memset(response,0,cbSize+2);
+
+ if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(struct hllapi_packet_query_at), &response, cbSize, &cbSize,NULL))
+ return NULL;
+
+ if(response->packet_id)
+ errno = response->packet_id;
+ else
+ text = strdup(response->text);
+
+ free(response);
+ return text;
+ }
+
+ int hllapi_pipe_enter(void *h)
+ {
+ static const struct hllapi_packet_query query = { HLLAPI_PACKET_ENTER };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
+ }
+
+ int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str)
+ {
+ struct hllapi_packet_text_at * query;
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen((const char *) str);
+
+ query = malloc(cbSize);
+ query->packet_id = HLLAPI_PACKET_SET_TEXT_AT;
+ query->row = row;
+ query->col = col;
+ strcpy(query->text,(const char *) str);
+
+ TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
+
+ free(query);
+
+ return response.rc;
+ }
+
+ int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text)
+ {
+ struct hllapi_packet_text_at * query;
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text);
+
+ query = malloc(cbSize);
+ query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT;
+ query->row = row;
+ query->col = col;
+ strcpy(query->text,text);
+
+ TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL);
+
+ free(query);
+
+ return response.rc;
+ }
+
+ int hllapi_pipe_pfkey(void *h, int key)
+ {
+ struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, key };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
+ }
+
+ int hllapi_pipe_pakey(void *h, int key)
+ {
+ struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, key };
+ struct hllapi_packet_result response;
+ DWORD cbSize = sizeof(query);
+ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
+ return response.rc;
+ }
+
+ void hllapi_pipe_release_memory(void *p)
+ {
+ free(p);
+ }
--
libgit2 0.21.2