Commit b906fa92de7870c80166e9bb7c9fe81adeef8844
1 parent
95eb08ec
Exists in
master
and in
5 other branches
Implementando modulo hllapi
Showing
10 changed files
with
766 additions
and
1 deletions
Show diff stats
Makefile.in
| ... | ... | @@ -126,6 +126,9 @@ src/tools/%@EXEEXT@: src/tools/%.c |
| 126 | 126 | $(BINDIR)/Debug/plugins/%@DLLEXT@: src/plugins/%/* $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) |
| 127 | 127 | @make BINDIR="../../../$(BINDIR)" PW3270_LIBS="-L../../../$(BINDIR)/Debug@DLLDIR@ -l3270 -lpw3270" PW3270_CFLAGS="-I../../../src/include" -C $(dir $<) Debug |
| 128 | 128 | |
| 129 | +$(BINDIR)/Release/plugins/%@DLLEXT@: src/plugins/%/* $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) | |
| 130 | + @make BINDIR="../../../$(BINDIR)" PW3270_LIBS="-L../../../$(BINDIR)/Release@DLLDIR@ -l3270 -lpw3270" PW3270_CFLAGS="-I../../../src/include" -C $(dir $<) Release | |
| 131 | + | |
| 129 | 132 | #---[ Release targets ]-------------------------------------------------------- |
| 130 | 133 | |
| 131 | 134 | all: $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) locale filelist |
| ... | ... | @@ -292,6 +295,7 @@ clean: |
| 292 | 295 | @make -C src/lib3270 clean |
| 293 | 296 | @make -C src/pw3270 clean |
| 294 | 297 | @make -C src/tools clean |
| 298 | + @make -C src/plugins/remotectl clean | |
| 295 | 299 | @rm -f $(PACKAGE_NAME).png |
| 296 | 300 | @rm -f $(PACKAGE_NAME)-logo.png |
| 297 | 301 | @rm -f *.log | ... | ... |
configure.ac
pw3270.cbp
| ... | ... | @@ -68,6 +68,7 @@ |
| 68 | 68 | <Unit filename="src\include\lib3270\session.h" /> |
| 69 | 69 | <Unit filename="src\include\lib3270\trace.h" /> |
| 70 | 70 | <Unit filename="src\include\pw3270.h" /> |
| 71 | + <Unit filename="src\include\pw3270\hllapi.h" /> | |
| 71 | 72 | <Unit filename="src\include\pw3270\plugin.h" /> |
| 72 | 73 | <Unit filename="src\include\rules.mak.in" /> |
| 73 | 74 | <Unit filename="src\include\v3270.h" /> |
| ... | ... | @@ -213,6 +214,17 @@ |
| 213 | 214 | <Unit filename="src\lib3270\winversc.h" /> |
| 214 | 215 | <Unit filename="src\lib3270\xioc.h" /> |
| 215 | 216 | <Unit filename="src\lib3270\xl.h" /> |
| 217 | + <Unit filename="src\plugins\remotectl\Makefile.in" /> | |
| 218 | + <Unit filename="src\plugins\remotectl\hllapi.c"> | |
| 219 | + <Option compilerVar="CC" /> | |
| 220 | + </Unit> | |
| 221 | + <Unit filename="src\plugins\remotectl\pipesource.c"> | |
| 222 | + <Option compilerVar="CC" /> | |
| 223 | + </Unit> | |
| 224 | + <Unit filename="src\plugins\remotectl\remotectl.c"> | |
| 225 | + <Option compilerVar="CC" /> | |
| 226 | + </Unit> | |
| 227 | + <Unit filename="src\plugins\remotectl\remotectl.h" /> | |
| 216 | 228 | <Unit filename="src\pw3270\Makefile.in" /> |
| 217 | 229 | <Unit filename="src\pw3270\actions.c"> |
| 218 | 230 | <Option compilerVar="CC" /> | ... | ... |
| ... | ... | @@ -0,0 +1,61 @@ |
| 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 hllapi.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 | + * licinio@bb.com.br (Licínio Luis Branco) | |
| 28 | + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
| 29 | + * | |
| 30 | + */ | |
| 31 | + | |
| 32 | +#ifdef __cplusplus | |
| 33 | +extern "C" { | |
| 34 | +#endif | |
| 35 | + | |
| 36 | + #define HLLAPI_REQUEST_ID 0x01 | |
| 37 | + #define HLLAPI_MAXLENGTH 32768 | |
| 38 | + | |
| 39 | + #define HLLAPI_CMD_CONNECTPS 1 /**< connect presentation space */ | |
| 40 | + #define HLLAPI_CMD_SENDSTRING 3 /**< send string */ | |
| 41 | + #define HLLAPI_CMD_COPYPSTOSTR 8 /**< copy presentation space to string */ | |
| 42 | + #define HLLAPI_CMD_SETCURSOR 40 /**< set cursor */ | |
| 43 | + #define HLLAPI_CMD_GETREVISION 2000 /**< Get lib3270 revision */ | |
| 44 | + | |
| 45 | + #pragma pack(1) | |
| 46 | + typedef struct _hllapi_data | |
| 47 | + { | |
| 48 | + unsigned char id; /**< Request id */ | |
| 49 | + unsigned long func; /**< Function number */ | |
| 50 | + unsigned short rc; /**< Short argument/return code */ | |
| 51 | + unsigned short len; /**< Text length */ | |
| 52 | + char string[1]; /**< String argument */ | |
| 53 | + } HLLAPI_DATA; | |
| 54 | + #pragma pack() | |
| 55 | + | |
| 56 | + LIB3270_EXPORT int hllapi(unsigned long function, const char *string, unsigned short length, unsigned short *rc); | |
| 57 | + | |
| 58 | +#ifdef __cplusplus | |
| 59 | +} /* end of extern "C" */ | |
| 60 | +#endif | |
| 61 | + | ... | ... |
src/include/pw3270/plugin.h
| ... | ... | @@ -34,10 +34,13 @@ |
| 34 | 34 | #define PW3270_PLUGIN_INCLUDED 1 |
| 35 | 35 | |
| 36 | 36 | #include <gtk/gtk.h> |
| 37 | - #include <lib3270/config.h> | |
| 37 | + #include <lib3270.h> | |
| 38 | 38 | |
| 39 | 39 | LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window); |
| 40 | 40 | LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window); |
| 41 | 41 | |
| 42 | + LIB3270_EXPORT void pw3270_plugin_start(GtkWidget *window); | |
| 43 | + LIB3270_EXPORT void pw3270_plugin_stop(GtkWidget *window); | |
| 44 | + | |
| 42 | 45 | #endif // PW3270_PLUGIN_INCLUDED |
| 43 | 46 | ... | ... |
| ... | ... | @@ -0,0 +1,110 @@ |
| 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 | +# Contatos: | |
| 22 | +# | |
| 23 | +# perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 24 | +# erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) | |
| 25 | +# licinio@bb.com.br (Licínio Luis Branco) | |
| 26 | +# kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
| 27 | +# | |
| 28 | + | |
| 29 | +#---[ Sources ]---------------------------------------------------------------- | |
| 30 | + | |
| 31 | +MODULE_NAME=remotectl | |
| 32 | +DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile | |
| 33 | +PLUGIN_SRC=remotectl.c pipesource.c | |
| 34 | +HLLAPI_SRC=hllapi.c | |
| 35 | + | |
| 36 | +#---[ Paths ]------------------------------------------------------------------ | |
| 37 | + | |
| 38 | +ROOTDIR ?= . | |
| 39 | +OBJDIR ?= $(ROOTDIR)/.obj | |
| 40 | +BINDIR ?= $(ROOTDIR)/.bin | |
| 41 | +BINDBG ?= $(BINDIR)/Debug | |
| 42 | +BINRLS ?= $(BINDIR)/Release | |
| 43 | + | |
| 44 | +OBJDBG = $(OBJDIR)/Debug | |
| 45 | +OBJRLS = $(OBJDIR)/Release | |
| 46 | +OBJEXT = o | |
| 47 | + | |
| 48 | +#---[ Tools ]------------------------------------------------------------------ | |
| 49 | + | |
| 50 | +MKDIR=@MKDIR_P@ | |
| 51 | +CC=@CC@ | |
| 52 | +LD=@CC@ | |
| 53 | +MSGCAT=@MSGCAT@ | |
| 54 | +XGETTEXT=@XGETTEXT@ | |
| 55 | + | |
| 56 | +#---[ Rules ]------------------------------------------------------------------ | |
| 57 | + | |
| 58 | +DLL_FLAGS=@DLL_FLAGS@ | |
| 59 | +DEBUG_CFLAGS=-DDEBUG=1 -g -Wall | |
| 60 | + | |
| 61 | +PW3270_LIBS ?= `pkg-config --libs pw3270 lib3270` | |
| 62 | +PW3270_CFLAGS ?= `pkg-config --cflags pw3270 lib3270` | |
| 63 | +GTK_CFLAGS ?= @GTK_CFLAGS@ @GTKMAC_CFLAGS@ | |
| 64 | +GTK_LIBS ?= @GTK_LIBS@ @GTKMAC_LIBS@ | |
| 65 | + | |
| 66 | +$(OBJDBG)/%.o: %.c $(DEPENDS) | |
| 67 | + @echo " CC `basename $@`" | |
| 68 | + @$(MKDIR) `dirname $@` | |
| 69 | + @$(CC) $(CFLAGS) $(DEBUG_CFLAGS) $(PW3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< | |
| 70 | + | |
| 71 | +$(OBJRLS)/%.o: %.c $(DEPENDS) | |
| 72 | + @echo " CC `basename $@`" | |
| 73 | + @$(MKDIR) `dirname $@` | |
| 74 | + @$(CC) $(CFLAGS) $(PW3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< | |
| 75 | + | |
| 76 | + | |
| 77 | +#---[ Release targets ]-------------------------------------------------------- | |
| 78 | + | |
| 79 | +Release: $(BINRLS)/plugins/$(MODULE_NAME).dll $(BINRLS)/libhllapi.dll | |
| 80 | + | |
| 81 | +$(BINRLS)/plugins/$(MODULE_NAME).dll: $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJRLS)/$(SRC).o) | |
| 82 | + @echo " CCLD `basename $@`" | |
| 83 | + @$(MKDIR) `dirname $@` | |
| 84 | + @$(LD) $(DLL_FLAGS) -Wl,-soname,`basename $@` $(LDFLAGS) -o $@ $^ $(LIBS) $(PW3270_LIBS) $(GTK_LIBS) | |
| 85 | + | |
| 86 | +$(BINRLS)/libhllapi.dll: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJRLS)/$(SRC).o) | |
| 87 | + @echo " CCLD `basename $@`" | |
| 88 | + @$(MKDIR) `dirname $@` | |
| 89 | + @$(LD) $(DLL_FLAGS) -Wl,-soname,`basename $@` $(LDFLAGS) -o $@ $^ $(LIBS) | |
| 90 | + | |
| 91 | +#---[ Debug targets ]---------------------------------------------------------- | |
| 92 | + | |
| 93 | +Debug: $(BINDBG)/plugins/$(MODULE_NAME).dll $(BINDBG)/libhllapi.dll | |
| 94 | + | |
| 95 | +$(BINDBG)/plugins/$(MODULE_NAME).dll: $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJDBG)/$(SRC).o) | |
| 96 | + @echo " CCLD `basename $@`" | |
| 97 | + @$(MKDIR) `dirname $@` | |
| 98 | + @$(LD) $(DLL_FLAGS) -Wl,-soname,`basename $@` $(LDFLAGS) -o $@ $^ $(LIBS) $(PW3270_LIBS) $(GTK_LIBS) | |
| 99 | + | |
| 100 | +$(BINDBG)/libhllapi.dll: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJDBG)/$(SRC).o) | |
| 101 | + @echo " CCLD `basename $@`" | |
| 102 | + @$(MKDIR) `dirname $@` | |
| 103 | + @$(LD) $(DLL_FLAGS) -Wl,-soname,`basename $@` $(LDFLAGS) -o $@ $^ $(LIBS) | |
| 104 | + | |
| 105 | +#---[ Misc targets ]----------------------------------------------------------- | |
| 106 | + | |
| 107 | +clean: | |
| 108 | + @rm -fr $(OBJDIR) | |
| 109 | + @rm -fr $(BINDIR) | |
| 110 | + @find . -name "*~" -exec rm -f {} \; | ... | ... |
| ... | ... | @@ -0,0 +1,110 @@ |
| 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 hllapi.c e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include <lib3270.h> | |
| 31 | + #include <malloc.h> | |
| 32 | + #include <string.h> | |
| 33 | + #include <errno.h> | |
| 34 | + #include <pw3270/hllapi.h> | |
| 35 | + | |
| 36 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 37 | + | |
| 38 | + LIB3270_EXPORT int hllapi(unsigned long func, const char *string, unsigned short length, unsigned short *rc) | |
| 39 | + { | |
| 40 | + int result = -1; | |
| 41 | + | |
| 42 | +#ifdef WIN32 | |
| 43 | + | |
| 44 | + static DWORD dwMode = PIPE_READMODE_MESSAGE; | |
| 45 | + static const LPTSTR lpszPipeName = TEXT( "\\\\.\\pipe\\pw3270" ); | |
| 46 | + HANDLE hPipe = INVALID_HANDLE_VALUE; | |
| 47 | + | |
| 48 | + if(length < 0 && string) | |
| 49 | + length = strlen(string); | |
| 50 | + | |
| 51 | + if(!WaitNamedPipe(lpszPipeName,10000)) | |
| 52 | + return ETIMEDOUT; | |
| 53 | + | |
| 54 | + hPipe = CreateFile( lpszPipeName, // pipe name | |
| 55 | + GENERIC_WRITE|GENERIC_READ, // Read/Write access | |
| 56 | + 0, // no sharing | |
| 57 | + NULL, // default security attributes | |
| 58 | + OPEN_EXISTING, // opens existing pipe | |
| 59 | + 0, // Attributes | |
| 60 | + NULL); // no template file | |
| 61 | + | |
| 62 | + if(hPipe == INVALID_HANDLE_VALUE) | |
| 63 | + return -1; | |
| 64 | + | |
| 65 | + if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) | |
| 66 | + { | |
| 67 | + result = -1; | |
| 68 | + } | |
| 69 | + else | |
| 70 | + { | |
| 71 | + HLLAPI_DATA *buffer = malloc(HLLAPI_MAXLENGTH+1); | |
| 72 | + DWORD cbSize = 0; | |
| 73 | + HLLAPI_DATA *data = malloc(sizeof(HLLAPI_DATA) + length); | |
| 74 | + | |
| 75 | + data->id = HLLAPI_REQUEST_ID; | |
| 76 | + data->func = func; | |
| 77 | + data->rc = *rc; | |
| 78 | + data->len = length; | |
| 79 | + | |
| 80 | + if(string && length > 0) | |
| 81 | + memcpy(data->string,string,length); | |
| 82 | + | |
| 83 | + if(!TransactNamedPipe(hPipe,(LPVOID) data,sizeof(HLLAPI_DATA) + length,buffer,HLLAPI_MAXLENGTH,&cbSize,NULL)) | |
| 84 | + { | |
| 85 | + result = -1; | |
| 86 | + } | |
| 87 | + else | |
| 88 | + { | |
| 89 | + *rc = buffer->rc; | |
| 90 | + | |
| 91 | + if(string && length > 0) | |
| 92 | + memcpy(string,buffer->string,length); | |
| 93 | + | |
| 94 | + result = 0; | |
| 95 | + } | |
| 96 | + | |
| 97 | + free(data); | |
| 98 | + free(buffer); | |
| 99 | + } | |
| 100 | + | |
| 101 | + CloseHandle(hPipe); | |
| 102 | + | |
| 103 | +#else | |
| 104 | + | |
| 105 | + #error NOT IMPLEMENTED | |
| 106 | + | |
| 107 | +#endif // WIN32 | |
| 108 | + | |
| 109 | + return result; | |
| 110 | + } | ... | ... |
| ... | ... | @@ -0,0 +1,282 @@ |
| 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 pipesource.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 | + * licinio@bb.com.br (Licínio Luis Branco) | |
| 28 | + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
| 29 | + * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) | |
| 30 | + * | |
| 31 | + */ | |
| 32 | + | |
| 33 | +#ifdef WIN32 | |
| 34 | + | |
| 35 | + #include <windows.h> | |
| 36 | + #include <stdarg.h> | |
| 37 | + #include <lib3270.h> | |
| 38 | + #include "remotectl.h" | |
| 39 | + | |
| 40 | +/*---[ Defines ]----------------------------------------------------------------------------*/ | |
| 41 | + | |
| 42 | + #pragma pack(1) | |
| 43 | + | |
| 44 | + typedef struct _pipe_source | |
| 45 | + { | |
| 46 | + GSource gsrc; | |
| 47 | + HANDLE hPipe; | |
| 48 | + | |
| 49 | + enum _PIPE_STATE | |
| 50 | + { | |
| 51 | + PIPE_STATE_WAITING, | |
| 52 | + PIPE_STATE_READ, | |
| 53 | + PIPE_STATE_PENDING_READ, | |
| 54 | + | |
| 55 | + PIPE_STATE_UNDEFINED, | |
| 56 | + } state; | |
| 57 | + | |
| 58 | + OVERLAPPED overlap; | |
| 59 | + unsigned char buffer[PIPE_BUFFER_LENGTH+1]; | |
| 60 | + } pipe_source; | |
| 61 | + | |
| 62 | + #pragma pack() | |
| 63 | + | |
| 64 | +/*---[ GSource ]----------------------------------------------------------------------------*/ | |
| 65 | + | |
| 66 | +static void wait_for_client(pipe_source *source) | |
| 67 | +{ | |
| 68 | + if(ConnectNamedPipe(source->hPipe,&source->overlap)) | |
| 69 | + { | |
| 70 | + popup_lasterror("%s",_( "Error in ConnectNamedPipe" )); | |
| 71 | + return; | |
| 72 | + } | |
| 73 | + | |
| 74 | + switch(GetLastError()) | |
| 75 | + { | |
| 76 | + // The overlapped connection in progress. | |
| 77 | + case ERROR_IO_PENDING: | |
| 78 | + trace("%s: ERROR_IO_PENDING",__FUNCTION__); | |
| 79 | + source->state = PIPE_STATE_WAITING; | |
| 80 | + break; | |
| 81 | + | |
| 82 | + // Client is already connected, so signal an event. | |
| 83 | + case ERROR_PIPE_CONNECTED: | |
| 84 | + trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__); | |
| 85 | + if(SetEvent(source->overlap.hEvent)) | |
| 86 | + break; | |
| 87 | + | |
| 88 | + // If an error occurs during the connect operation... | |
| 89 | + default: | |
| 90 | + popup_lasterror("%s", _( "ConnectNamedPipe failed" )); | |
| 91 | + } | |
| 92 | + | |
| 93 | + } | |
| 94 | + | |
| 95 | + static gboolean IO_prepare(GSource *source, gint *timeout) | |
| 96 | + { | |
| 97 | + /* | |
| 98 | + * Called before all the file descriptors are polled. | |
| 99 | + * If the source can determine that it is ready here | |
| 100 | + * (without waiting for the results of the poll() call) | |
| 101 | + * it should return TRUE. | |
| 102 | + * | |
| 103 | + * It can also return a timeout_ value which should be the maximum | |
| 104 | + * timeout (in milliseconds) which should be passed to the poll() call. | |
| 105 | + * The actual timeout used will be -1 if all sources returned -1, | |
| 106 | + * or it will be the minimum of all the timeout_ values | |
| 107 | + * returned which were >= 0. | |
| 108 | + * | |
| 109 | + */ | |
| 110 | + if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) | |
| 111 | + { | |
| 112 | + trace("%s: source=%p",__FUNCTION__,source); | |
| 113 | + return TRUE; | |
| 114 | + } | |
| 115 | + | |
| 116 | + *timeout = 10; | |
| 117 | + return FALSE; | |
| 118 | + } | |
| 119 | + | |
| 120 | + static gboolean IO_check(GSource *source) | |
| 121 | + { | |
| 122 | + /* | |
| 123 | + * Called after all the file descriptors are polled. | |
| 124 | + * The source should return TRUE if it is ready to be dispatched. | |
| 125 | + * Note that some time may have passed since the previous prepare | |
| 126 | + * function was called, so the source should be checked again here. | |
| 127 | + * | |
| 128 | + */ | |
| 129 | + if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) | |
| 130 | + return TRUE; | |
| 131 | + | |
| 132 | + return FALSE; | |
| 133 | + } | |
| 134 | + | |
| 135 | + static void process_input(pipe_source *source, DWORD cbRead) | |
| 136 | + { | |
| 137 | + gint argc = 0; | |
| 138 | + gchar **argv; | |
| 139 | + GError * error = NULL; | |
| 140 | + gchar * cmd; | |
| 141 | + | |
| 142 | + source->buffer[cbRead] = 0; | |
| 143 | + | |
| 144 | + } | |
| 145 | + | |
| 146 | + static void read_input_pipe(pipe_source *source) | |
| 147 | + { | |
| 148 | + DWORD cbRead = 0; | |
| 149 | + | |
| 150 | + if(ReadFile(source->hPipe,source->buffer,PIPE_BUFFER_LENGTH,&cbRead,&source->overlap) && cbRead > 0) | |
| 151 | + process_input(source,cbRead); | |
| 152 | + | |
| 153 | + // The read operation is still pending. | |
| 154 | + switch(GetLastError()) | |
| 155 | + { | |
| 156 | + case ERROR_IO_PENDING: | |
| 157 | + trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__); | |
| 158 | + source->state = PIPE_STATE_PENDING_READ; | |
| 159 | + break; | |
| 160 | + | |
| 161 | + case ERROR_PIPE_LISTENING: | |
| 162 | + trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__); | |
| 163 | + source->state = PIPE_STATE_READ; | |
| 164 | + break; | |
| 165 | + | |
| 166 | + case ERROR_BROKEN_PIPE: | |
| 167 | + trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__); | |
| 168 | + if(!DisconnectNamedPipe(source->hPipe)) | |
| 169 | + popup_lasterror("%s",_( "Error in DisconnectNamedPipe" )); | |
| 170 | + else | |
| 171 | + wait_for_client(source); | |
| 172 | + break; | |
| 173 | + | |
| 174 | + case ERROR_PIPE_NOT_CONNECTED: | |
| 175 | + trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__); | |
| 176 | + break; | |
| 177 | + | |
| 178 | + default: | |
| 179 | + if(source->hPipe != INVALID_HANDLE_VALUE) | |
| 180 | + popup_lasterror("%s",_( "Error receiving message from pipe" ) ); | |
| 181 | + } | |
| 182 | + | |
| 183 | + } | |
| 184 | + | |
| 185 | + static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer data) | |
| 186 | + { | |
| 187 | + /* | |
| 188 | + * Called to dispatch the event source, | |
| 189 | + * after it has returned TRUE in either its prepare or its check function. | |
| 190 | + * The dispatch function is passed in a callback function and data. | |
| 191 | + * The callback function may be NULL if the source was never connected | |
| 192 | + * to a callback using g_source_set_callback(). The dispatch function | |
| 193 | + * should call the callback function with user_data and whatever additional | |
| 194 | + * parameters are needed for this type of event source. | |
| 195 | + */ | |
| 196 | + BOOL fSuccess; | |
| 197 | + DWORD cbRead = 0; | |
| 198 | + DWORD dwErr = 0; | |
| 199 | + | |
| 200 | + fSuccess = GetOverlappedResult(((pipe_source *) source)->hPipe,&((pipe_source *) source)->overlap,&cbRead,FALSE ); | |
| 201 | + | |
| 202 | + trace("%s: source=%p data=%p Result=%s cbRead=%d",__FUNCTION__,source,data,fSuccess ? "Success" : "Unsuccess",(int) cbRead); | |
| 203 | + | |
| 204 | + switch(((pipe_source *) source)->state) | |
| 205 | + { | |
| 206 | + case PIPE_STATE_WAITING: | |
| 207 | + if(fSuccess) | |
| 208 | + { | |
| 209 | + trace("Pipe connected (cbRet=%d)",(int) cbRead); | |
| 210 | + ((pipe_source *) source)->state = PIPE_STATE_READ; | |
| 211 | + } | |
| 212 | + else | |
| 213 | + { | |
| 214 | + popup_lasterror("%s", _( "Pipe connection failed" )); | |
| 215 | + } | |
| 216 | + break; | |
| 217 | + | |
| 218 | + case PIPE_STATE_READ: | |
| 219 | + trace("Reading pipe (cbRead=%d)",(int) cbRead); | |
| 220 | + read_input_pipe( (pipe_source *) source); | |
| 221 | + break; | |
| 222 | + | |
| 223 | + case PIPE_STATE_PENDING_READ: | |
| 224 | + if(fSuccess && cbRead > 0) | |
| 225 | + process_input((pipe_source *) source,cbRead); | |
| 226 | + ((pipe_source *) source)->state = PIPE_STATE_READ; | |
| 227 | + break; | |
| 228 | + | |
| 229 | +#ifdef DEBUG | |
| 230 | + default: | |
| 231 | + trace("%s: source=%p data=%p Unexpected mode %d",__FUNCTION__,source,data,((pipe_source *) source)->state); | |
| 232 | +#endif | |
| 233 | + } | |
| 234 | + | |
| 235 | + return TRUE; | |
| 236 | + } | |
| 237 | + | |
| 238 | + static void IO_finalize(GSource *source) | |
| 239 | + { | |
| 240 | + trace("%s: source=%p",__FUNCTION__,source); | |
| 241 | + | |
| 242 | + if( ((pipe_source *) source)->hPipe != INVALID_HANDLE_VALUE) | |
| 243 | + { | |
| 244 | + CloseHandle(((pipe_source *) source)->hPipe); | |
| 245 | + ((pipe_source *) source)->hPipe = INVALID_HANDLE_VALUE; | |
| 246 | + } | |
| 247 | + | |
| 248 | + } | |
| 249 | + | |
| 250 | + static gboolean IO_closure(gpointer data) | |
| 251 | + { | |
| 252 | + trace("%s: data=%p",__FUNCTION__,data); | |
| 253 | + return 0; | |
| 254 | + } | |
| 255 | + | |
| 256 | + | |
| 257 | + void init_source_pipe(HANDLE hPipe) | |
| 258 | + { | |
| 259 | + static GSourceFuncs pipe_source_funcs = | |
| 260 | + { | |
| 261 | + IO_prepare, | |
| 262 | + IO_check, | |
| 263 | + IO_dispatch, | |
| 264 | + IO_finalize, | |
| 265 | + IO_closure, | |
| 266 | + NULL | |
| 267 | + }; | |
| 268 | + | |
| 269 | + pipe_source *source = (pipe_source *) g_source_new(&pipe_source_funcs,sizeof(pipe_source)); | |
| 270 | + | |
| 271 | + source->hPipe = hPipe; | |
| 272 | + source->state = PIPE_STATE_WAITING; | |
| 273 | + source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL); | |
| 274 | + | |
| 275 | + g_source_attach((GSource *) source,NULL); | |
| 276 | + | |
| 277 | + wait_for_client(source); | |
| 278 | + | |
| 279 | + return; | |
| 280 | + } | |
| 281 | + | |
| 282 | +#endif // WIN32 | ... | ... |
| ... | ... | @@ -0,0 +1,124 @@ |
| 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/plugin.h> | |
| 36 | + | |
| 37 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 38 | + | |
| 39 | +#ifdef WIN32 | |
| 40 | + | |
| 41 | + void popup_lasterror(const gchar *fmt, ...) | |
| 42 | + { | |
| 43 | + char buffer[4096]; | |
| 44 | + va_list arg_ptr; | |
| 45 | + int sz; | |
| 46 | + DWORD errcode = GetLastError(); | |
| 47 | + char *ptr; | |
| 48 | + LPVOID lpMsgBuf = 0; | |
| 49 | + | |
| 50 | + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); | |
| 51 | + | |
| 52 | + for(ptr=lpMsgBuf;*ptr && *ptr != '\n';ptr++); | |
| 53 | + *ptr = 0; | |
| 54 | + | |
| 55 | + va_start(arg_ptr, fmt); | |
| 56 | + vsnprintf(buffer,4095,fmt,arg_ptr); | |
| 57 | + va_end(arg_ptr); | |
| 58 | + | |
| 59 | + sz = strlen(buffer); | |
| 60 | + snprintf(buffer+sz,4096-sz,": %s\n(rc=%d)",lpMsgBuf,(int) errcode); | |
| 61 | + | |
| 62 | + printf("%s\n",buffer); | |
| 63 | + | |
| 64 | +#ifdef DEBUG | |
| 65 | + fprintf(stderr,"%s\n",buffer); | |
| 66 | + fflush(stderr); | |
| 67 | +#endif | |
| 68 | + | |
| 69 | + LocalFree(lpMsgBuf); | |
| 70 | + } | |
| 71 | + | |
| 72 | +#endif // WIN32 | |
| 73 | + | |
| 74 | + LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window) | |
| 75 | + { | |
| 76 | +#ifdef WIN32 | |
| 77 | + static const LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\" PACKAGE_NAME ); | |
| 78 | + HANDLE hPipe; | |
| 79 | + | |
| 80 | + trace("\n\n%s\n\n",__FUNCTION__); | |
| 81 | + | |
| 82 | + hPipe = CreateNamedPipe( lpszPipename, // pipe name | |
| 83 | + PIPE_ACCESS_DUPLEX | // read/write access | |
| 84 | + FILE_FLAG_OVERLAPPED, // overlapped mode | |
| 85 | + PIPE_TYPE_MESSAGE | // pipe type | |
| 86 | + PIPE_READMODE_MESSAGE | // pipe mode | |
| 87 | + PIPE_WAIT, // blocking mode | |
| 88 | + 1, // number of instances | |
| 89 | + PIPE_BUFFER_LENGTH, // output buffer size | |
| 90 | + PIPE_BUFFER_LENGTH, // input buffer size | |
| 91 | + 0, // client time-out | |
| 92 | + NULL); // default security attributes | |
| 93 | + | |
| 94 | + | |
| 95 | + if (hPipe == INVALID_HANDLE_VALUE) | |
| 96 | + { | |
| 97 | + popup_lasterror( _( "Can´t create pipe %s" ),lpszPipename); | |
| 98 | + return -1; | |
| 99 | + } | |
| 100 | + | |
| 101 | + init_source_pipe(hPipe); | |
| 102 | + | |
| 103 | +#else | |
| 104 | + | |
| 105 | + #error Nao implementado | |
| 106 | + | |
| 107 | +#endif // WIN32 | |
| 108 | + | |
| 109 | + return 0; | |
| 110 | + } | |
| 111 | + | |
| 112 | + LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window) | |
| 113 | + { | |
| 114 | +#ifdef WIN32 | |
| 115 | + | |
| 116 | +#else | |
| 117 | + | |
| 118 | + #error Nao implementado | |
| 119 | + | |
| 120 | +#endif // WIN32 | |
| 121 | + return 0; | |
| 122 | + } | |
| 123 | + | |
| 124 | + | ... | ... |
| ... | ... | @@ -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. 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.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 | + * Agradecimento: | |
| 29 | + * | |
| 30 | + * Hélio Passos | |
| 31 | + * | |
| 32 | + */ | |
| 33 | + | |
| 34 | + #define ENABLE_NLS | |
| 35 | + #define GETTEXT_PACKAGE PACKAGE_NAME | |
| 36 | + | |
| 37 | + #include <libintl.h> | |
| 38 | + #include <glib/gi18n.h> | |
| 39 | + #include <gtk/gtk.h> | |
| 40 | + | |
| 41 | + #include <lib3270.h> | |
| 42 | + #include <lib3270/log.h> | |
| 43 | + #include <pw3270/hllapi.h> | |
| 44 | + | |
| 45 | +#ifdef WIN32 | |
| 46 | + | |
| 47 | + #define PIPE_BUFFER_LENGTH 4096 | |
| 48 | + | |
| 49 | + void init_source_pipe(HANDLE hPipe); | |
| 50 | + void popup_lasterror(const gchar *fmt, ...); | |
| 51 | + | |
| 52 | +#endif // WIN32 | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | ... | ... |