From 56b8c5497034ff29b5d39206e1b526dbb70e04b9 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 22 Feb 2019 09:17:27 -0300 Subject: [PATCH] Refactoring build process. --- Makefile.in | 65 +++++++++++++++++++++++++++++++++-------------------------------- configure.ac | 2 +- src/ipc3270c/linux/daemon.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/ipc3270c/linux/globals.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ipc3270c/linux/gobject.c | 620 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ipc3270c/linux/main.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ipc3270c/linux/misc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/ipc3270c/linux/service.h | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ipc3270c/windows/main.c | 675 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ipc3270c/windows/private.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/ipc3270c/windows/resources.rc.in | 29 +++++++++++++++++++++++++++++ src/plugin/linux/daemon.h | 46 ---------------------------------------------- src/plugin/linux/globals.h | 59 ----------------------------------------------------------- src/plugin/linux/gobject.c | 620 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/plugin/linux/main.c | 179 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/plugin/linux/misc.c | 47 ----------------------------------------------- src/plugin/linux/service.h | 138 ------------------------------------------------------------------------------------------------------------------------------------------ src/plugin/windows/main.c | 675 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/plugin/windows/private.h | 50 -------------------------------------------------- src/plugin/windows/resources.rc.in | 29 ----------------------------- src/testprogram/linux/test.sh | 126 ------------------------------------------------------------------------------------------------------------------------------ src/testprogram/testprogram.c | 248 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/testprograms/linux/test.sh | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/testprograms/plugin.c | 248 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 24 files changed, 2251 insertions(+), 2250 deletions(-) create mode 100644 src/ipc3270c/linux/daemon.h create mode 100644 src/ipc3270c/linux/globals.h create mode 100644 src/ipc3270c/linux/gobject.c create mode 100644 src/ipc3270c/linux/main.c create mode 100644 src/ipc3270c/linux/misc.c create mode 100644 src/ipc3270c/linux/service.h create mode 100644 src/ipc3270c/windows/main.c create mode 100644 src/ipc3270c/windows/private.h create mode 100644 src/ipc3270c/windows/resources.rc.in delete mode 100644 src/plugin/linux/daemon.h delete mode 100644 src/plugin/linux/globals.h delete mode 100644 src/plugin/linux/gobject.c delete mode 100644 src/plugin/linux/main.c delete mode 100644 src/plugin/linux/misc.c delete mode 100644 src/plugin/linux/service.h delete mode 100644 src/plugin/windows/main.c delete mode 100644 src/plugin/windows/private.h delete mode 100644 src/plugin/windows/resources.rc.in delete mode 100755 src/testprogram/linux/test.sh delete mode 100644 src/testprogram/testprogram.c create mode 100755 src/testprograms/linux/test.sh create mode 100644 src/testprograms/plugin.c diff --git a/Makefile.in b/Makefile.in index a689c7b..9e8eaaf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -24,18 +24,19 @@ # erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) # -#---[ Library configuration ]------------------------------------------------------------ - -MODULE_NAME=ipc3270c PACKAGE_NAME=@PACKAGE_NAME@ +#---[ PLugin configuration ]------------------------------------------------------------- + +PLUGIN_NAME=ipc3270c + PLUGIN_SOURCES= \ - $(wildcard src/plugin/*.c) \ - $(wildcard src/plugin/@OSNAME@/*.c) \ - $(wildcard src/plugin/@OSNAME@/*.rc) + $(wildcard src/$(PLUGIN_NAME)/*.c) \ + $(wildcard src/$(PLUGIN_NAME)/@OSNAME@/*.c) \ + $(wildcard src/$(PLUGIN_NAME)/@OSNAME@/*.rc) -TEST_SOURCES= \ - $(wildcard src/testprogram/*.c) +PLUGIN_TEST_SOURCES= \ + src/testprograms/plugin.c #---[ Tools ]---------------------------------------------------------------------------- @@ -69,7 +70,7 @@ BASEDIR=@BASEDIR@ POTDIR=$(BASEDIR)/.pot -OBJDIR=$(BASEDIR)/.obj/$(MODULE_NAME) +OBJDIR=$(BASEDIR)/.obj OBJDBG=$(OBJDIR)/Debug OBJRLS=$(OBJDIR)/Release @@ -160,7 +161,7 @@ $(OBJRLS)/%.o: \ #---[ Misc Rules ]----------------------------------------------------------------------- -$(POTDIR)/$(MODULE_NAME)/%.pot: \ +$(POTDIR)/$(PLUGIN_NAME)/%.pot: \ %.c @echo $(notdir $@) ... @@ -174,7 +175,7 @@ $(POTDIR)/$(MODULE_NAME)/%.pot: \ $< @touch $@ -$(POTDIR)/$(MODULE_NAME)/%.pot: \ +$(POTDIR)/$(PLUGIN_NAME)/%.pot: \ %.rc @echo $< ... @@ -185,13 +186,13 @@ $(POTDIR)/$(MODULE_NAME)/%.pot: \ #---[ Release Targets ]------------------------------------------------------------------ all: \ - $(BINRLS)/$(MODULE_NAME)@DLLEXT@ \ - $(POTDIR)/$(MODULE_NAME).pot + $(BINRLS)/$(PLUGIN_NAME)@DLLEXT@ \ + $(POTDIR)/$(PLUGIN_NAME).pot Release: \ - $(BINRLS)/$(MODULE_NAME)@DLLEXT@ + $(BINRLS)/$(PLUGIN_NAME)@DLLEXT@ -$(BINRLS)/$(MODULE_NAME)@DLLEXT@: \ +$(BINRLS)/$(PLUGIN_NAME)@DLLEXT@: \ $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJRLS)/$(SRC).o) @$(MKDIR) $(@D) @@ -213,39 +214,39 @@ install: \ install-plugin install-plugin: \ - $(BINRLS)/$(MODULE_NAME)@DLLEXT@ + $(BINRLS)/$(PLUGIN_NAME)@DLLEXT@ @$(MKDIR) $(DESTDIR)$(libdir)/pw3270-plugins @$(INSTALL_PROGRAM) \ - $(BINRLS)/$(MODULE_NAME)@DLLEXT@ \ + $(BINRLS)/$(PLUGIN_NAME)@DLLEXT@ \ $(DESTDIR)$(libdir)/pw3270-plugins #---[ Misc Targets ]--------------------------------------------------------------------- -$(POTDIR)/$(MODULE_NAME).pot: \ - $(foreach SRC, $(basename $(SOURCES)), $(POTDIR)/$(MODULE_NAME)/$(SRC).pot) +$(POTDIR)/$(PLUGIN_NAME).pot: \ + $(foreach SRC, $(basename $(SOURCES)), $(POTDIR)/$(PLUGIN_NAME)/$(SRC).pot) @rm -f $@ @mkdir -p `dirname $@` @$(MSGCAT) --sort-output $^ > $@ locale: \ - $(POTDIR)/$(MODULE_NAME).pot + $(POTDIR)/$(PLUGIN_NAME).pot -run: \ - $(BINDBG)/$(MODULE_NAME)@DLLEXT@ \ - $(BINDBG)/$(MODULE_NAME)@EXEEXT@ +run-plugin: \ + $(BINDBG)/$(PLUGIN_NAME)@DLLEXT@ \ + $(BINDBG)/$(PLUGIN_NAME)@EXEEXT@ - $(BINDBG)/$(MODULE_NAME)@EXEEXT@ + $(BINDBG)/$(PLUGIN_NAME)@EXEEXT@ #---[ Debug Targets ]-------------------------------------------------------------------- Debug: \ - $(BINDBG)/$(MODULE_NAME)@DLLEXT@ \ - $(BINDBG)/$(MODULE_NAME)@EXEEXT@ + $(BINDBG)/$(PLUGIN_NAME)@DLLEXT@ \ + $(BINDBG)/$(PLUGIN_NAME)@EXEEXT@ -$(BINDBG)/lib$(MODULE_NAME).a: \ +$(BINDBG)/lib$(PLUGIN_NAME).a: \ $(foreach SRC, $(basename $(CORE_SOURCES)), $(OBJDBG)/$(SRC).o) @$(MKDIR) $(@D) @@ -254,8 +255,8 @@ $(BINDBG)/lib$(MODULE_NAME).a: \ @$(AR) rcs $@ $^ -$(BINDBG)/$(MODULE_NAME)@EXEEXT@: \ - $(foreach SRC, $(basename $(TEST_SOURCES)), $(OBJDBG)/$(SRC).o) +$(BINDBG)/$(PLUGIN_NAME)@EXEEXT@: \ + $(foreach SRC, $(basename $(PLUGIN_TEST_SOURCES)), $(OBJDBG)/$(SRC).o) @$(MKDIR) $(@D) @echo $< ... @@ -270,7 +271,7 @@ $(BINDBG)/$(MODULE_NAME)@EXEEXT@: \ $(GTK_LIBS) \ $(GLIB_LIBS) -$(BINDBG)/$(MODULE_NAME)@DLLEXT@: \ +$(BINDBG)/$(PLUGIN_NAME)@DLLEXT@: \ $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o) @$(MKDIR) $(@D) @@ -293,8 +294,8 @@ clean: \ cleanDebug \ cleanRelease - @rm -fr $(BASEDIR)/.tmp/$(MODULE_NAME) - @rm -fr $(POTDIR)/$(MODULE_NAME) + @rm -fr $(BASEDIR)/.tmp/$(PLUGIN_NAME) + @rm -fr $(POTDIR)/$(PLUGIN_NAME) cleanDebug: diff --git a/configure.ac b/configure.ac index d5d9025..85e1a15 100644 --- a/configure.ac +++ b/configure.ac @@ -31,7 +31,7 @@ AC_PREREQ(2.61) dnl Initialise automake with the package name, version and dnl bug-reporting address. -AC_INIT([pw3270], [5.2], [perry.werneck@gmail.com]) +AC_INIT([ipc3270], [5.2], [perry.werneck@gmail.com]) dnl Place auxilliary scripts here. AC_CONFIG_AUX_DIR([scripts]) diff --git a/src/ipc3270c/linux/daemon.h b/src/ipc3270c/linux/daemon.h new file mode 100644 index 0000000..152a618 --- /dev/null +++ b/src/ipc3270c/linux/daemon.h @@ -0,0 +1,46 @@ +/* + * "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., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como daemon.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) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + * Referencias: + * + * https://live.gnome.org/DBusGlibBindings + * + */ + + #include "service.h" + +/*---[ Globals ]---------------------------------------------------------------------------------*/ + + G_GNUC_INTERNAL GMainLoop * main_loop; + + +/*---[ Prototipes ]------------------------------------------------------------------------------*/ + + G_GNUC_INTERNAL void pw3270_dbus_register_io_handlers(void); + diff --git a/src/ipc3270c/linux/globals.h b/src/ipc3270c/linux/globals.h new file mode 100644 index 0000000..ed4ccbc --- /dev/null +++ b/src/ipc3270c/linux/globals.h @@ -0,0 +1,59 @@ +/* + * "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., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como globals.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) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + */ + +#ifndef PW3270_DBUS_GLOBALS_H_INCLUDED + + #define PW3270_DBUS_GLOBALS_H_INCLUDED 1 + + #include + #include + + #include + #include + #include + #include + + // + // Disabling warning on unused-function defined in dbus-glib-bindings.h + // warning: 'org_freedesktop_DBus_reload_config' defined but not used [-Wunused-function] ... + // + #pragma GCC diagnostic ignored "-Wunused-function" + + #include + #include + #include + + #define ERROR_DOMAIN g_quark_from_static_string("pw3270DBUS") + + G_GNUC_INTERNAL gpointer pw3270_dbus_register_object (DBusGConnection *connection,DBusGProxy *proxy,GType object_type,const DBusGObjectInfo *info,const gchar *path); + + +#endif // PW3270_DBUS_GLOBALS_H_INCLUDED diff --git a/src/ipc3270c/linux/gobject.c b/src/ipc3270c/linux/gobject.c new file mode 100644 index 0000000..bde78e3 --- /dev/null +++ b/src/ipc3270c/linux/gobject.c @@ -0,0 +1,620 @@ +/* + * "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., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como gobject.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) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + * Referencias: + * + * https://live.gnome.org/DBusGlibBindings + * + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "service.h" + +/*---[ Globals ]---------------------------------------------------------------------------------*/ + + +/*---[ Implement ]-------------------------------------------------------------------------------*/ + +G_DEFINE_TYPE(PW3270Dbus, pw3270_dbus, G_TYPE_OBJECT) + +static void pw3270_dbus_finalize(GObject *object) +{ + G_OBJECT_CLASS(pw3270_dbus_parent_class)->finalize (object); +} + + +static void pw3270_dbus_class_init(PW3270DbusClass *klass) +{ + GObjectClass *object_class; + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = pw3270_dbus_finalize; + debug("%s",__FUNCTION__); +} + +static void pw3270_dbus_init(PW3270Dbus *object) +{ + debug("%s(%p)",__FUNCTION__,object); +} + +PW3270Dbus * pw3270_dbus_new(void) +{ + return (PW3270Dbus *) g_object_new(PW3270_TYPE_DBUS, NULL); +} + +void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + debug("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_revision()); +} + +void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context) +{ + H3270 *hSession = pw3270_dbus_get_session_handle(PW3270_DBUS(object)); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + if(uri && *uri) + { + lib3270_set_url(hSession,uri); + g_message("Connecting to \"%s\" by remote request",lib3270_get_url(hSession)); + } + else + { + g_message("%s","Connecting by remote request"); + } + + dbus_g_method_return(context,lib3270_reconnect(hSession,0)); +} + +void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + g_message("Changing host to \"%s\" by remote request",uri); + + dbus_g_method_return(context,lib3270_set_url(pw3270_dbus_get_session_handle(PW3270_DBUS(object)),uri) != 0); +} + +void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_url(pw3270_dbus_get_session_handle(PW3270_DBUS(object)))); +} + + +void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + g_message("Disconnecting by remote request"); + lib3270_disconnect(pw3270_dbus_get_session_handle(object)); + dbus_g_method_return(context,0); +} + +void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_program_message(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_connection_state(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_secure(pw3270_dbus_get_session_handle(object))); +} + +GError * pw3270_dbus_get_error_from_errno(int code) +{ + return g_error_new(ERROR_DOMAIN,code,"%s",g_strerror(code)); +} + +int pw3270_dbus_check_valid_state(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + H3270 * hSession = pw3270_dbus_get_session_handle(object); + GError * error = NULL; + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + if(!lib3270_is_connected(hSession)) + { + error = pw3270_dbus_get_error_from_errno(ENOTCONN); + } + else + { + LIB3270_MESSAGE state = lib3270_get_program_message(hSession); + + switch(state) + { + case LIB3270_MESSAGE_NONE: + return 0; + + case LIB3270_MESSAGE_DISCONNECTED: + error = pw3270_dbus_get_error_from_errno(ENOTCONN); + break; + + case LIB3270_MESSAGE_MINUS: + case LIB3270_MESSAGE_PROTECTED: + case LIB3270_MESSAGE_NUMERIC: + case LIB3270_MESSAGE_OVERFLOW: + case LIB3270_MESSAGE_INHIBIT: + case LIB3270_MESSAGE_KYBDLOCK: + case LIB3270_MESSAGE_X: + error = g_error_new(ERROR_DOMAIN,-1,_( "State %04d can't accept requests" ),state); + break; + + case LIB3270_MESSAGE_SYSWAIT: + case LIB3270_MESSAGE_TWAIT: + case LIB3270_MESSAGE_CONNECTED: + case LIB3270_MESSAGE_AWAITING_FIRST: + error = pw3270_dbus_get_error_from_errno(EBUSY); + break; + + case LIB3270_MESSAGE_RESOLVING: + case LIB3270_MESSAGE_CONNECTING: + error = g_error_new(ERROR_DOMAIN,EINPROGRESS,_( "Connecting to host" )); + break; + + case LIB3270_MESSAGE_USER: + error = g_error_new(ERROR_DOMAIN,-1,_( "Unexpected state %04d" ),state); + } + } + + if(error) + { + dbus_g_method_return_error(context,error); + g_error_free(error); + return -1; + } + + return 0; +} + +void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + char * text; + gchar * utftext; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = lib3270_get_string_at_address(hSession,0,-1,'\n'); + + utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); + + lib3270_free(text); + + dbus_g_method_return(context,utftext); + + g_free(utftext); + +} + +void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + dbus_g_method_return(context,lib3270_enter(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_set_text_at(PW3270Dbus *object, int row, int col, const gchar *utftext, DBusGMethodInvocation *context) +{ + gchar * text; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); + + int sz = lib3270_set_string_at(hSession,row,col,(const unsigned char *) text); + + trace("%s returns %d",__FUNCTION__,sz); + dbus_g_method_return(context,sz); + + g_free(text); +} + +void pw3270_dbus_input(PW3270Dbus *object, const gchar *utftext, DBusGMethodInvocation *context) +{ + gchar * text; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); + + dbus_g_method_return(context,lib3270_emulate_input(hSession,(const char *) text,-1,1)); + + g_free(text); +} + + +void pw3270_dbus_get_text_at(PW3270Dbus *object, int row, int col, int len, char lf, DBusGMethodInvocation *context) +{ + gchar * text; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = lib3270_get_string_at(hSession, row, col, len, lf); + if(!text) + { + GError *error = pw3270_dbus_get_error_from_errno(errno); + dbus_g_method_return_error(context,error); + g_error_free(error); + } + else + { + gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); + + lib3270_free(text); + + dbus_g_method_return(context,utftext); + + g_free(utftext); + } + } + + void pw3270_dbus_get_text(PW3270Dbus *object, int offset, int len, char lf, DBusGMethodInvocation *context) + { + gchar * text; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + + if(len < 0) { + len = lib3270_get_length(hSession); + } + + text = lib3270_get_string_at_address(hSession,offset,len,lf); + if(!text) + { + GError *error = pw3270_dbus_get_error_from_errno(errno); + dbus_g_method_return_error(context,error); + g_error_free(error); + } + else + { + gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); + + lib3270_free(text); + + debug("\n%s\n",utftext); + + dbus_g_method_return(context,utftext); + + g_free(utftext); + } + + } + + void pw3270_dbus_is_connected(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p connected=%s",__FUNCTION__,object,context, lib3270_is_connected(pw3270_dbus_get_session_handle(object)) ? "Yes" : "No"); + dbus_g_method_return(context,lib3270_is_connected(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_is_ready(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_in_tn3270e(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_wait_for_ready(pw3270_dbus_get_session_handle(object),timeout)); + } + + void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_set_cursor_position(pw3270_dbus_get_session_handle(object),row,col)); + } + + void pw3270_dbus_set_cursor_address(PW3270Dbus *object, int addr, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_set_cursor_address(pw3270_dbus_get_session_handle(object),addr)); + } + + void pw3270_dbus_get_cursor_address(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_cursor_address(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_get_screen_width(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_width(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_get_screen_height(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_height(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_get_screen_length(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_width(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_set_toggle(pw3270_dbus_get_session_handle(object),(LIB3270_TOGGLE) id,value)); + } + +void pw3270_dbus_cmp_text_at(PW3270Dbus *object, int row, int col, const gchar *utftext, char lf, DBusGMethodInvocation *context) +{ + gchar * text; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); + + dbus_g_method_return(context,lib3270_cmp_text_at(hSession,row,col,text,lf)); + + g_free(text); +} + +void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + dbus_g_method_return(context,lib3270_pfkey(pw3270_dbus_get_session_handle(object),key)); +} + +void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + dbus_g_method_return(context,lib3270_pakey(pw3270_dbus_get_session_handle(object),key)); +} + + void pw3270_dbus_get_field_start(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_field_start(pw3270_dbus_get_session_handle(object),baddr)); + } + + void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_field_len(pw3270_dbus_get_session_handle(object),baddr)); + } + + void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_next_unprotected(pw3270_dbus_get_session_handle(object),baddr)); + } + + void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_is_protected(pw3270_dbus_get_session_handle(object),baddr)); + } + + void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_is_protected_at(pw3270_dbus_get_session_handle(object),row,col)); + } + + void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_action(pw3270_dbus_get_session_handle(object),text)); + } + + void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context) + { + gchar *text; + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = gtk_clipboard_wait_for_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD)); + + trace("Clipboard:\n%s\n",text); + + if(!text) + { + GError *error = pw3270_dbus_get_error_from_errno(ENOENT); + dbus_g_method_return_error(context,error); + g_error_free(error); + } + else + { + dbus_g_method_return(context,text); + g_free(text); + } +} + +void pw3270_dbus_set_clipboard(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + gtk_clipboard_set_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD),(gchar *) text, -1); + dbus_g_method_return(context,0); +} + +void pw3270_dbus_set_script(PW3270Dbus *object, const gchar G_GNUC_UNUSED(*text), int mode, DBusGMethodInvocation *context) +{ + GtkWidget *widget = pw3270_get_terminal_widget(NULL); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + if(!widget) + { + GError *error = pw3270_dbus_get_error_from_errno(EINVAL); + dbus_g_method_return_error(context,error); + g_error_free(error); + return; + } + + dbus_g_method_return(context,v3270_set_script(widget,mode == 0 ? 0 : 'S')); +} + +void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context) +{ + lib3270_popup_dialog(pw3270_dbus_get_session_handle(object), (LIB3270_NOTIFY) id , title, msg, "%s", text); + dbus_g_method_return(context,0); +} + +void pw3270_dbus_get_host_charset(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + dbus_g_method_return(context,lib3270_get_host_charset(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_get_display_charset(PW3270Dbus G_GNUC_UNUSED(*object), DBusGMethodInvocation *context) +{ + // Allways return UTF-8 to avoid double conversion + dbus_g_method_return(context,"UTF-8"); +} + +void pw3270_dbus_set_host_charset(PW3270Dbus *object, const gchar *charset, DBusGMethodInvocation *context) +{ + dbus_g_method_return(context,lib3270_set_host_charset(pw3270_dbus_get_session_handle(object),charset)); +} + +void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_eraseeof(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + dbus_g_method_return(context,lib3270_print_all(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_set_unlock_delay(PW3270Dbus *object, int value, DBusGMethodInvocation *context) +{ + lib3270_set_unlock_delay(pw3270_dbus_get_session_handle(object),(unsigned short) value); + dbus_g_method_return(context,0); +} + + +void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context) +{ + int sz = strlen(from); + + if(sz > 0) + { + unsigned char buffer[sz+1]; + memcpy(buffer,from,sz); + dbus_g_method_return(context,lib3270_ebc2asc(pw3270_dbus_get_session_handle(object),buffer,sz)); + return; + } + + dbus_g_method_return(context,""); + +} + +void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context) +{ + int sz = strlen(from); + + if(sz > 0) + { + unsigned char buffer[sz+1]; + memcpy(buffer,from,sz); + dbus_g_method_return(context,lib3270_asc2ebc(pw3270_dbus_get_session_handle(object),buffer,sz)); + return; + } + + dbus_g_method_return(context,""); + +} + +void pw3270_dbus_filetransfer(PW3270Dbus *object, const gchar *local, const gchar *remote, int flags, int lrecl, int blksize, int primspace, int secspace, int dft, DBusGMethodInvocation *context) +{ + /* + dbus_g_method_return(context, + v3270_transfer_file( + v3270_get_default_widget(), + (LIB3270_FT_OPTION) flags, + local, + remote, + lrecl, + blksize, + primspace, + secspace, + dft + )); + */ + return; +} + diff --git a/src/ipc3270c/linux/main.c b/src/ipc3270c/linux/main.c new file mode 100644 index 0000000..9cb2bbc --- /dev/null +++ b/src/ipc3270c/linux/main.c @@ -0,0 +1,179 @@ +/* + * "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., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como main.c e possui - linhas de código. + * + * Referências: + * + * https://github.com/fbuihuu/samples-dbus/blob/master/dbus-server.c + * + * 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 + +#include "service.h" +#include "dbus-glue.h" + +#include + +/*---[ Globals ]---------------------------------------------------------------------------------*/ + + static DBusGConnection * connection = NULL; + static DBusGProxy * proxy = NULL; + static gchar * service_name = NULL; + + +/*---[ Implement ]-------------------------------------------------------------------------------*/ + + LIB3270_EXPORT int pw3270_plugin_start(GtkWidget G_GNUC_UNUSED(*window), GtkWidget *terminal) + { + GError * error = NULL; + guint result; + char session_id = 0; + char id = 'a'; + const gchar * name = "pw3270"; + + connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error); + if(error) + { + GtkWidget *dialog = gtk_message_dialog_new( + GTK_WINDOW(window), + (GtkDialogFlags) (GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT), + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + _( "Can't connect to DBUS server" )); + + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); + + g_message("Error \"%s\" getting session dbus",error->message); + + g_error_free(error); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + return -1; + } + + proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); + + for(id='a'; id < 'z' && !error && !service_name; id++) + { + gboolean has_owner = FALSE; + + service_name = g_strdup_printf("br.com.bb.%s.%c",name,(int) id); + + org_freedesktop_DBus_name_has_owner(proxy, service_name, &has_owner, NULL); + + if(has_owner) + { + trace("Service \"%s\" has owner",service_name) + g_free(service_name); + service_name = NULL; + } + else + { + session_id = id; + g_message("DBUS service name is %s",service_name); + org_freedesktop_DBus_request_name(proxy, service_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); + } + } + + if(error) + { + GtkWidget *dialog = gtk_message_dialog_new( + GTK_WINDOW(window), + (GtkDialogFlags) (GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT), + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + _( "Can't get DBUS object name" )); + + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); + + g_message("Error \"%s\" requesting DBUS name",error->message); + + g_error_free(error); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + return -1; + } + + if(session_id) + { + g_autofree gchar * path = g_strdup_printf("/br/com/bb/%s",name); + g_autofree gchar * session = g_strdup_printf("%s:%c",name,g_ascii_toupper(session_id)); + + // pw3270_set_session_name(window,session); + v3270_set_session_name(terminal,session); + + g_message("DBUS service path is %s, session name is %s",path,session); + + pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,path); + + } + + return 0; + } + + LIB3270_EXPORT int pw3270_plugin_stop(GtkWidget G_GNUC_UNUSED(*window), GtkWidget G_GNUC_UNUSED(*terminal)) + { + if(proxy) + { + debug("%s: Releasing proxy",__FUNCTION__); + g_object_unref(proxy); + proxy = NULL; + } + + if(service_name) + { + g_free(service_name); + service_name = NULL; + } + return 0; + } + + void pw3270_dbus_quit(PW3270Dbus G_GNUC_UNUSED(*object), DBusGMethodInvocation *context) + { + gtk_main_quit(); + dbus_g_method_return(context,0); + } + + H3270 * pw3270_dbus_get_session_handle(PW3270Dbus G_GNUC_UNUSED(*object)) + { + debug("%s=%p",__FUNCTION__,lib3270_get_default_session_handle()); + return lib3270_get_default_session_handle(); + } + + + diff --git a/src/ipc3270c/linux/misc.c b/src/ipc3270c/linux/misc.c new file mode 100644 index 0000000..08c5fa2 --- /dev/null +++ b/src/ipc3270c/linux/misc.c @@ -0,0 +1,47 @@ +/* + * "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., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como misc.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) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + * Referencias: + * + * https://live.gnome.org/DBusGlibBindings + * + */ + +#include "globals.h" + +/*---[ Implement ]-------------------------------------------------------------------------------*/ + +gpointer pw3270_dbus_register_object(DBusGConnection *connection,DBusGProxy G_GNUC_UNUSED(*proxy),GType object_type,const DBusGObjectInfo *info,const gchar *path) +{ + GObject *object = G_OBJECT(g_object_new(object_type, NULL)); + dbus_g_object_type_install_info (object_type, info); + dbus_g_connection_register_g_object (connection, path, object); + return object; +} + diff --git a/src/ipc3270c/linux/service.h b/src/ipc3270c/linux/service.h new file mode 100644 index 0000000..aba8322 --- /dev/null +++ b/src/ipc3270c/linux/service.h @@ -0,0 +1,138 @@ +/* + * "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., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como service.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) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + */ + +#ifndef _PW3270_DBUS_SERVICE_H + + #define _PW3270_DBUS_SERVICE_H 1 + + #define ENABLE_NLS + #define GETTEXT_PACKAGE PACKAGE_NAME + + #include "globals.h" + + #define PW3270_TYPE_DBUS (pw3270_dbus_get_type ()) + #define PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PW3270_TYPE_DBUS, PW3270Dbus)) + #define PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_DBUS, PW3270DbusClass)) + #define IS_PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PW3270_TYPE_DBUS)) + #define IS_PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PW3270_TYPE_DBUS)) + #define PW3270_DBUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PW3270_TYPE_DBUS, PW3270DbusClass)) + + G_BEGIN_DECLS + + typedef struct _PW3270Dbus PW3270Dbus; + typedef struct _PW3270DbusClass PW3270DbusClass; + + struct _PW3270Dbus + { + GObject parent; + }; + + struct _PW3270DbusClass + { + GObjectClass parent; + }; + + PW3270Dbus * pw3270_dbus_new (void); + GType pw3270_dbus_get_type (void); + + void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); + void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); + void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context); + H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object); + GError * pw3270_dbus_get_error_from_errno(int code); + + void pw3270_dbus_is_connected(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context); + void pw3270_dbus_set_cursor_address(PW3270Dbus *object, int addr, DBusGMethodInvocation *context); + void pw3270_dbus_get_cursor_address(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_get_screen_width(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_get_screen_height(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_get_screen_length(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context); + + void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context); + + void pw3270_dbus_get_field_start(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); + void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); + void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); + + void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); + void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context); + + void pw3270_dbus_set_script(PW3270Dbus *object, const gchar *text, int mode, DBusGMethodInvocation *context); + + void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context); + + void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context); + + // Actions + void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context); + void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context); + void pw3270_dbus_set_text_at(PW3270Dbus *object, int row, int col, const gchar *text, DBusGMethodInvocation *context); + void pw3270_dbus_get_text_at(PW3270Dbus *object, int row, int col, int len, char lf, DBusGMethodInvocation *context); + void pw3270_dbus_get_text(PW3270Dbus *object, int offset, int len, char lf, DBusGMethodInvocation *context); + void pw3270_dbus_cmp_text_at(PW3270Dbus *object, int row, int col, const gchar *text, char lf, DBusGMethodInvocation *context); + void pw3270_dbus_input(PW3270Dbus *object, const gchar *utftext, DBusGMethodInvocation *context); + + void pw3270_dbus_set_clipboard(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context); + void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_get_display_charset(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_get_host_charset(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_set_host_charset(PW3270Dbus *object, const gchar *charset, DBusGMethodInvocation *context); + void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context); + void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context); + + void pw3270_dbus_filetransfer(PW3270Dbus *object, const gchar *local, const gchar *remote, int flags, int lrecl, int blksize, int primspace, int secspace, int dft, DBusGMethodInvocation *context); + + void pw3270_dbus_set_unlock_delay(PW3270Dbus *object, int value, DBusGMethodInvocation *context); + + G_END_DECLS + +#endif // _PW3270_DBUS_SERVICE_H diff --git a/src/ipc3270c/windows/main.c b/src/ipc3270c/windows/main.c new file mode 100644 index 0000000..03a3b4d --- /dev/null +++ b/src/ipc3270c/windows/main.c @@ -0,0 +1,675 @@ +/* + * "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 - 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 "private.h" + +#ifdef _WIN32 + #include +#else + #error HLLAPI is designed for windows. +#endif // _WIN32 + + #include + #include + #include + #include + #include + +/*--[ Defines ]--------------------------------------------------------------------------------------*/ + + #pragma pack(1) + + enum PIPE_STATE + { + PIPE_STATE_WAITING, + PIPE_STATE_READ, + PIPE_STATE_PENDING_READ, + PIPE_STATE_UNDEFINED + }; + + typedef struct _pipe_source + { + GSource gsrc; + HANDLE hPipe; + + enum PIPE_STATE 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); + 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_text(pipe_source *source, char *text) + { + struct hllapi_packet_text *pkt; + DWORD szBlock; + int f; + + if(text) + { + szBlock = sizeof(struct hllapi_packet_text)+strlen(text); + pkt = (struct hllapi_packet_text *) g_malloc0(szBlock); + pkt->packet_id = 0; + strcpy(pkt->text,text); + lib3270_free(text); + } + else + { + szBlock = sizeof(struct hllapi_packet_text); + pkt = (struct hllapi_packet_text *) g_malloc0(szBlock); + pkt->packet_id = errno ? errno : -1; + } + + trace("szBlock=%d text=\"%s\"",szBlock, ( (struct hllapi_packet_text *) pkt)->text); + for(f=0;f< (int) szBlock;f++) + { + trace("rsp(%d)= %d \"%s\"",f,* (((char *) pkt)+f),((char *) pkt)+f); + } + + WriteFile(source->hPipe,pkt,szBlock,&szBlock,NULL); + + g_free(pkt); + } + + 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 int do_file_transfer(struct hllapi_packet_file_transfer * source) + { + /* + const gchar * local = (const char *) source->text; + const gchar * remote = (const char *) (local+strlen(local)+1); + + return v3270_transfer_file( v3270_get_default_widget(), + (LIB3270_FT_OPTION) source->options, + local, + remote, + source->lrecl, + source->blksize, + source->primspace, + source->secspace, + source->dft ); + */ + return EINVAL; + } + + static void get_host(pipe_source *source) { + send_text(source,strdup(lib3270_get_url(lib3270_get_default_session_handle()))); + } + + static void process_input(pipe_source *source, DWORD G_GNUC_UNUSED(cbRead)) + { + const struct hllapi_packet_query * query = ((struct hllapi_packet_query *) source->buffer); + + trace("%s id=%d",__FUNCTION__,query->packet_id); + + switch(query->packet_id) + { + case HLLAPI_PACKET_CONNECT: + send_result(source,lib3270_reconnect( lib3270_get_default_session_handle(), + ((struct hllapi_packet_connect *) source->buffer)->wait)); + break; + + case HLLAPI_PACKET_CONNECT_URL: + send_result(source,lib3270_connect_url(lib3270_get_default_session_handle(),(const char *) (query+1),0)); + break; + + case HLLAPI_PACKET_SET_HOST: + send_result(source,lib3270_set_url(lib3270_get_default_session_handle(), + ((struct hllapi_packet_text *) source->buffer)->text)); + break; + + case HLLAPI_PACKET_GET_HOST: + get_host(source); + break; + + case HLLAPI_PACKET_DISCONNECT: + send_result(source,lib3270_disconnect(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_IS_CONNECTED: + send_result(source,lib3270_in_tn3270e(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_IS_READY: + send_result(source,lib3270_is_ready(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_ENTER: + send_result(source,lib3270_enter(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_PRINT: + send_result(source,lib3270_print_all(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_ERASE: + send_result(source,lib3270_erase(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_ERASE_EOF: + send_result(source,lib3270_eraseeof(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_ERASE_EOL: + send_result(source,lib3270_eraseeol(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_ERASE_INPUT: + send_result(source,lib3270_eraseinput(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_GET_TEXT_AT: + send_text(source,lib3270_get_string_at( lib3270_get_default_session_handle(), + ((struct hllapi_packet_at *) source->buffer)->row, + ((struct hllapi_packet_at *) source->buffer)->col, + ((struct hllapi_packet_at *) source->buffer)->len, + ((struct hllapi_packet_at *) source->buffer)->lf)); + break; + + case HLLAPI_PACKET_GET_TEXT_AT_OFFSET: + send_text(source,lib3270_get_string_at_address( lib3270_get_default_session_handle(), + ((struct hllapi_packet_query_offset *) source->buffer)->addr, + ((struct hllapi_packet_query_offset *) source->buffer)->len, + ((struct hllapi_packet_query_offset *) source->buffer)->lf)); + 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, + ((struct hllapi_packet_text_at *) source->buffer)->lf)); + 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; + + case HLLAPI_PACKET_EMULATE_INPUT: + send_result(source,lib3270_emulate_input(lib3270_get_default_session_handle(), + (const char *) ((struct hllapi_packet_emulate_input *) source->buffer)->text, + (int) ((struct hllapi_packet_emulate_input *) source->buffer)->len, + (int) ((struct hllapi_packet_emulate_input *) source->buffer)->pasting)); + break; + + case HLLAPI_PACKET_SET_CURSOR: + send_result(source,lib3270_set_cursor_address(lib3270_get_default_session_handle(), + ((struct hllapi_packet_addr *) source->buffer)->addr)); + break; + + case HLLAPI_PACKET_GET_CURSOR: + send_result(source,lib3270_get_cursor_address(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_GET_WIDTH: + send_result(source,lib3270_get_width(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_GET_HEIGHT: + send_result(source,lib3270_get_height(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_GET_LENGTH: + send_result(source,lib3270_get_length(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_GET_SSL_STATE: + send_result(source,lib3270_get_secure(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_SET_UNLOCK_DELAY: + lib3270_set_unlock_delay(lib3270_get_default_session_handle(),(unsigned short) ((struct hllapi_packet_set_int *) source->buffer)->value); + send_result(source,0); + break; + + case HLLAPI_PACKET_SET_TOGGLE: + send_result(source,lib3270_set_toggle(lib3270_get_default_session_handle(), + (LIB3270_TOGGLE) ((struct hllapi_packet_set *) source->buffer)->id, + ((struct hllapi_packet_set *) source->buffer)->value)); + break; + + case HLLAPI_PACKET_FIELD_START: + send_result(source,lib3270_get_field_start(lib3270_get_default_session_handle(), + ((struct hllapi_packet_addr *) source->buffer)->addr)); + break; + + + case HLLAPI_PACKET_FIELD_LEN: + send_result(source,lib3270_get_field_len(lib3270_get_default_session_handle(), + ((struct hllapi_packet_addr *) source->buffer)->addr)); + break; + + case HLLAPI_PACKET_NEXT_UNPROTECTED: + send_result(source,lib3270_get_next_unprotected(lib3270_get_default_session_handle(), + ((struct hllapi_packet_addr *) source->buffer)->addr)); + break; + + case HLLAPI_PACKET_IS_PROTECTED: + send_result(source,lib3270_get_is_protected(lib3270_get_default_session_handle(), + ((struct hllapi_packet_addr *) source->buffer)->addr)); + break; + + case HLLAPI_PACKET_IS_PROTECTED_AT: + send_result(source,lib3270_get_is_protected_at( lib3270_get_default_session_handle(), + ((struct hllapi_packet_query_at *) source->buffer)->row, + ((struct hllapi_packet_query_at *) source->buffer)->col)); + break; + + case HLLAPI_PACKET_QUIT: + gtk_main_quit(); + send_result(source,0); + break; + + case HLLAPI_PACKET_SET_HOST_CHARSET: + send_result(source,lib3270_set_host_charset( lib3270_get_default_session_handle(), + (const char *) ((struct hllapi_packet_set_text *) source->buffer)->text)); + break; + + case HLLAPI_PACKET_ASC2EBC: + send_text(source,(char *) lib3270_asc2ebc( + lib3270_get_default_session_handle(), + (unsigned char *) ((struct hllapi_packet_set_text *) source->buffer)->text,-1 + )); + break; + + case HLLAPI_PACKET_EBC2ASC: + send_text(source,(char *) lib3270_ebc2asc( + lib3270_get_default_session_handle(), + (unsigned char *) ((struct hllapi_packet_set_text *) source->buffer)->text,-1 + )); + break; + + case HLLAPI_PACKET_FILE_TRANSFER: + send_result(source,do_file_transfer((struct hllapi_packet_file_transfer *) source)); + break; + + case HLLAPI_PACKET_GET_HOST_CHARSET: + trace("%s","HLLAPI_PACKET_GET_HOST_CHARSET"); + send_text(source,(char *) lib3270_get_host_charset(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_ACTION: + send_result(source,lib3270_action(lib3270_get_default_session_handle(), + (const 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 G_GNUC_UNUSED(callback), gpointer G_GNUC_UNUSED(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 G_GNUC_UNUSED(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= (char *) 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_start(GtkWidget *window, GtkWidget *terminal) + { + char id; + const gchar * name = "pw3270"; + + for(id='A';id < 'Z';id++) + { + gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s_%c",name,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",name,id); + + // pw3270_set_session_name(window,session); + v3270_set_session_name(terminal,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_stop(GtkWidget *window, GtkWidget *terminal) + { + + return 0; + } + + G_GNUC_INTERNAL void set_active(gboolean on) + { + trace("%s(%s)",__FUNCTION__,on ? "Active" : "Inactive"); + // v3270_set_script(v3270_get_default_widget(),'H'); + } diff --git a/src/ipc3270c/windows/private.h b/src/ipc3270c/windows/private.h new file mode 100644 index 0000000..c9494d2 --- /dev/null +++ b/src/ipc3270c/windows/private.h @@ -0,0 +1,50 @@ +/* + * "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 -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 + + G_GNUC_INTERNAL void popup_lasterror(const gchar *fmt, ...); + G_GNUC_INTERNAL void set_active(gboolean on); + + diff --git a/src/ipc3270c/windows/resources.rc.in b/src/ipc3270c/windows/resources.rc.in new file mode 100644 index 0000000..e3675ae --- /dev/null +++ b/src/ipc3270c/windows/resources.rc.in @@ -0,0 +1,29 @@ +#include + +VS_VERSION_INFO VERSIONINFO +FILEVERSION @PACKAGE_MAJOR_VERSION@,@PACKAGE_MINOR_VERSION@,@PACKAGE_MAJOR_RELEASE@,0 +PRODUCTVERSION @PACKAGE_MAJOR_VERSION@,@PACKAGE_MINOR_VERSION@,@PACKAGE_MAJOR_RELEASE@,0 + +BEGIN + + BLOCK "StringFileInfo" + BEGIN + BLOCK "080904E4" + BEGIN + VALUE "FileDescription", "@PACKAGE_NAME@ IPC Plugin\0" + VALUE "CompanyName", "Banco do Brasil S/A.\0" + VALUE "FileVersion", "@WIN32_VERSION@\0" + VALUE "LegalCopyright", "(C) 2017 Banco do Brasil S/A. All Rights Reserved\0" + VALUE "OriginalFilename", "ipc3270@DLLEXT@\0" + VALUE "ProductName", "@PACKAGE_NAME@\0" + VALUE "ProductVersion", "@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@.@PACKAGE_MAJOR_RELEASE@.0\0" + END + END + + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x809, 0x04E4 + END + +END + diff --git a/src/plugin/linux/daemon.h b/src/plugin/linux/daemon.h deleted file mode 100644 index 152a618..0000000 --- a/src/plugin/linux/daemon.h +++ /dev/null @@ -1,46 +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. - * - * 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 daemon.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) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - * Referencias: - * - * https://live.gnome.org/DBusGlibBindings - * - */ - - #include "service.h" - -/*---[ Globals ]---------------------------------------------------------------------------------*/ - - G_GNUC_INTERNAL GMainLoop * main_loop; - - -/*---[ Prototipes ]------------------------------------------------------------------------------*/ - - G_GNUC_INTERNAL void pw3270_dbus_register_io_handlers(void); - diff --git a/src/plugin/linux/globals.h b/src/plugin/linux/globals.h deleted file mode 100644 index ed4ccbc..0000000 --- a/src/plugin/linux/globals.h +++ /dev/null @@ -1,59 +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. - * - * 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 globals.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) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - */ - -#ifndef PW3270_DBUS_GLOBALS_H_INCLUDED - - #define PW3270_DBUS_GLOBALS_H_INCLUDED 1 - - #include - #include - - #include - #include - #include - #include - - // - // Disabling warning on unused-function defined in dbus-glib-bindings.h - // warning: 'org_freedesktop_DBus_reload_config' defined but not used [-Wunused-function] ... - // - #pragma GCC diagnostic ignored "-Wunused-function" - - #include - #include - #include - - #define ERROR_DOMAIN g_quark_from_static_string("pw3270DBUS") - - G_GNUC_INTERNAL gpointer pw3270_dbus_register_object (DBusGConnection *connection,DBusGProxy *proxy,GType object_type,const DBusGObjectInfo *info,const gchar *path); - - -#endif // PW3270_DBUS_GLOBALS_H_INCLUDED diff --git a/src/plugin/linux/gobject.c b/src/plugin/linux/gobject.c deleted file mode 100644 index bde78e3..0000000 --- a/src/plugin/linux/gobject.c +++ /dev/null @@ -1,620 +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. - * - * 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 gobject.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) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - * Referencias: - * - * https://live.gnome.org/DBusGlibBindings - * - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "service.h" - -/*---[ Globals ]---------------------------------------------------------------------------------*/ - - -/*---[ Implement ]-------------------------------------------------------------------------------*/ - -G_DEFINE_TYPE(PW3270Dbus, pw3270_dbus, G_TYPE_OBJECT) - -static void pw3270_dbus_finalize(GObject *object) -{ - G_OBJECT_CLASS(pw3270_dbus_parent_class)->finalize (object); -} - - -static void pw3270_dbus_class_init(PW3270DbusClass *klass) -{ - GObjectClass *object_class; - object_class = G_OBJECT_CLASS (klass); - object_class->finalize = pw3270_dbus_finalize; - debug("%s",__FUNCTION__); -} - -static void pw3270_dbus_init(PW3270Dbus *object) -{ - debug("%s(%p)",__FUNCTION__,object); -} - -PW3270Dbus * pw3270_dbus_new(void) -{ - return (PW3270Dbus *) g_object_new(PW3270_TYPE_DBUS, NULL); -} - -void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - debug("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_revision()); -} - -void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context) -{ - H3270 *hSession = pw3270_dbus_get_session_handle(PW3270_DBUS(object)); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - if(uri && *uri) - { - lib3270_set_url(hSession,uri); - g_message("Connecting to \"%s\" by remote request",lib3270_get_url(hSession)); - } - else - { - g_message("%s","Connecting by remote request"); - } - - dbus_g_method_return(context,lib3270_reconnect(hSession,0)); -} - -void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - g_message("Changing host to \"%s\" by remote request",uri); - - dbus_g_method_return(context,lib3270_set_url(pw3270_dbus_get_session_handle(PW3270_DBUS(object)),uri) != 0); -} - -void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_url(pw3270_dbus_get_session_handle(PW3270_DBUS(object)))); -} - - -void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - g_message("Disconnecting by remote request"); - lib3270_disconnect(pw3270_dbus_get_session_handle(object)); - dbus_g_method_return(context,0); -} - -void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_program_message(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_connection_state(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_secure(pw3270_dbus_get_session_handle(object))); -} - -GError * pw3270_dbus_get_error_from_errno(int code) -{ - return g_error_new(ERROR_DOMAIN,code,"%s",g_strerror(code)); -} - -int pw3270_dbus_check_valid_state(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - H3270 * hSession = pw3270_dbus_get_session_handle(object); - GError * error = NULL; - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - if(!lib3270_is_connected(hSession)) - { - error = pw3270_dbus_get_error_from_errno(ENOTCONN); - } - else - { - LIB3270_MESSAGE state = lib3270_get_program_message(hSession); - - switch(state) - { - case LIB3270_MESSAGE_NONE: - return 0; - - case LIB3270_MESSAGE_DISCONNECTED: - error = pw3270_dbus_get_error_from_errno(ENOTCONN); - break; - - case LIB3270_MESSAGE_MINUS: - case LIB3270_MESSAGE_PROTECTED: - case LIB3270_MESSAGE_NUMERIC: - case LIB3270_MESSAGE_OVERFLOW: - case LIB3270_MESSAGE_INHIBIT: - case LIB3270_MESSAGE_KYBDLOCK: - case LIB3270_MESSAGE_X: - error = g_error_new(ERROR_DOMAIN,-1,_( "State %04d can't accept requests" ),state); - break; - - case LIB3270_MESSAGE_SYSWAIT: - case LIB3270_MESSAGE_TWAIT: - case LIB3270_MESSAGE_CONNECTED: - case LIB3270_MESSAGE_AWAITING_FIRST: - error = pw3270_dbus_get_error_from_errno(EBUSY); - break; - - case LIB3270_MESSAGE_RESOLVING: - case LIB3270_MESSAGE_CONNECTING: - error = g_error_new(ERROR_DOMAIN,EINPROGRESS,_( "Connecting to host" )); - break; - - case LIB3270_MESSAGE_USER: - error = g_error_new(ERROR_DOMAIN,-1,_( "Unexpected state %04d" ),state); - } - } - - if(error) - { - dbus_g_method_return_error(context,error); - g_error_free(error); - return -1; - } - - return 0; -} - -void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - char * text; - gchar * utftext; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = lib3270_get_string_at_address(hSession,0,-1,'\n'); - - utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); - - lib3270_free(text); - - dbus_g_method_return(context,utftext); - - g_free(utftext); - -} - -void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - dbus_g_method_return(context,lib3270_enter(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_set_text_at(PW3270Dbus *object, int row, int col, const gchar *utftext, DBusGMethodInvocation *context) -{ - gchar * text; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); - - int sz = lib3270_set_string_at(hSession,row,col,(const unsigned char *) text); - - trace("%s returns %d",__FUNCTION__,sz); - dbus_g_method_return(context,sz); - - g_free(text); -} - -void pw3270_dbus_input(PW3270Dbus *object, const gchar *utftext, DBusGMethodInvocation *context) -{ - gchar * text; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); - - dbus_g_method_return(context,lib3270_emulate_input(hSession,(const char *) text,-1,1)); - - g_free(text); -} - - -void pw3270_dbus_get_text_at(PW3270Dbus *object, int row, int col, int len, char lf, DBusGMethodInvocation *context) -{ - gchar * text; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = lib3270_get_string_at(hSession, row, col, len, lf); - if(!text) - { - GError *error = pw3270_dbus_get_error_from_errno(errno); - dbus_g_method_return_error(context,error); - g_error_free(error); - } - else - { - gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); - - lib3270_free(text); - - dbus_g_method_return(context,utftext); - - g_free(utftext); - } - } - - void pw3270_dbus_get_text(PW3270Dbus *object, int offset, int len, char lf, DBusGMethodInvocation *context) - { - gchar * text; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - - if(len < 0) { - len = lib3270_get_length(hSession); - } - - text = lib3270_get_string_at_address(hSession,offset,len,lf); - if(!text) - { - GError *error = pw3270_dbus_get_error_from_errno(errno); - dbus_g_method_return_error(context,error); - g_error_free(error); - } - else - { - gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); - - lib3270_free(text); - - debug("\n%s\n",utftext); - - dbus_g_method_return(context,utftext); - - g_free(utftext); - } - - } - - void pw3270_dbus_is_connected(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p connected=%s",__FUNCTION__,object,context, lib3270_is_connected(pw3270_dbus_get_session_handle(object)) ? "Yes" : "No"); - dbus_g_method_return(context,lib3270_is_connected(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_is_ready(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_in_tn3270e(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_wait_for_ready(pw3270_dbus_get_session_handle(object),timeout)); - } - - void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_set_cursor_position(pw3270_dbus_get_session_handle(object),row,col)); - } - - void pw3270_dbus_set_cursor_address(PW3270Dbus *object, int addr, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_set_cursor_address(pw3270_dbus_get_session_handle(object),addr)); - } - - void pw3270_dbus_get_cursor_address(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_cursor_address(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_get_screen_width(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_width(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_get_screen_height(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_height(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_get_screen_length(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_width(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_set_toggle(pw3270_dbus_get_session_handle(object),(LIB3270_TOGGLE) id,value)); - } - -void pw3270_dbus_cmp_text_at(PW3270Dbus *object, int row, int col, const gchar *utftext, char lf, DBusGMethodInvocation *context) -{ - gchar * text; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); - - dbus_g_method_return(context,lib3270_cmp_text_at(hSession,row,col,text,lf)); - - g_free(text); -} - -void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - dbus_g_method_return(context,lib3270_pfkey(pw3270_dbus_get_session_handle(object),key)); -} - -void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - dbus_g_method_return(context,lib3270_pakey(pw3270_dbus_get_session_handle(object),key)); -} - - void pw3270_dbus_get_field_start(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_field_start(pw3270_dbus_get_session_handle(object),baddr)); - } - - void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_field_len(pw3270_dbus_get_session_handle(object),baddr)); - } - - void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_next_unprotected(pw3270_dbus_get_session_handle(object),baddr)); - } - - void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_is_protected(pw3270_dbus_get_session_handle(object),baddr)); - } - - void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_is_protected_at(pw3270_dbus_get_session_handle(object),row,col)); - } - - void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_action(pw3270_dbus_get_session_handle(object),text)); - } - - void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context) - { - gchar *text; - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = gtk_clipboard_wait_for_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD)); - - trace("Clipboard:\n%s\n",text); - - if(!text) - { - GError *error = pw3270_dbus_get_error_from_errno(ENOENT); - dbus_g_method_return_error(context,error); - g_error_free(error); - } - else - { - dbus_g_method_return(context,text); - g_free(text); - } -} - -void pw3270_dbus_set_clipboard(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - gtk_clipboard_set_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD),(gchar *) text, -1); - dbus_g_method_return(context,0); -} - -void pw3270_dbus_set_script(PW3270Dbus *object, const gchar G_GNUC_UNUSED(*text), int mode, DBusGMethodInvocation *context) -{ - GtkWidget *widget = pw3270_get_terminal_widget(NULL); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - if(!widget) - { - GError *error = pw3270_dbus_get_error_from_errno(EINVAL); - dbus_g_method_return_error(context,error); - g_error_free(error); - return; - } - - dbus_g_method_return(context,v3270_set_script(widget,mode == 0 ? 0 : 'S')); -} - -void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context) -{ - lib3270_popup_dialog(pw3270_dbus_get_session_handle(object), (LIB3270_NOTIFY) id , title, msg, "%s", text); - dbus_g_method_return(context,0); -} - -void pw3270_dbus_get_host_charset(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - dbus_g_method_return(context,lib3270_get_host_charset(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_get_display_charset(PW3270Dbus G_GNUC_UNUSED(*object), DBusGMethodInvocation *context) -{ - // Allways return UTF-8 to avoid double conversion - dbus_g_method_return(context,"UTF-8"); -} - -void pw3270_dbus_set_host_charset(PW3270Dbus *object, const gchar *charset, DBusGMethodInvocation *context) -{ - dbus_g_method_return(context,lib3270_set_host_charset(pw3270_dbus_get_session_handle(object),charset)); -} - -void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_eraseeof(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - dbus_g_method_return(context,lib3270_print_all(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_set_unlock_delay(PW3270Dbus *object, int value, DBusGMethodInvocation *context) -{ - lib3270_set_unlock_delay(pw3270_dbus_get_session_handle(object),(unsigned short) value); - dbus_g_method_return(context,0); -} - - -void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context) -{ - int sz = strlen(from); - - if(sz > 0) - { - unsigned char buffer[sz+1]; - memcpy(buffer,from,sz); - dbus_g_method_return(context,lib3270_ebc2asc(pw3270_dbus_get_session_handle(object),buffer,sz)); - return; - } - - dbus_g_method_return(context,""); - -} - -void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context) -{ - int sz = strlen(from); - - if(sz > 0) - { - unsigned char buffer[sz+1]; - memcpy(buffer,from,sz); - dbus_g_method_return(context,lib3270_asc2ebc(pw3270_dbus_get_session_handle(object),buffer,sz)); - return; - } - - dbus_g_method_return(context,""); - -} - -void pw3270_dbus_filetransfer(PW3270Dbus *object, const gchar *local, const gchar *remote, int flags, int lrecl, int blksize, int primspace, int secspace, int dft, DBusGMethodInvocation *context) -{ - /* - dbus_g_method_return(context, - v3270_transfer_file( - v3270_get_default_widget(), - (LIB3270_FT_OPTION) flags, - local, - remote, - lrecl, - blksize, - primspace, - secspace, - dft - )); - */ - return; -} - diff --git a/src/plugin/linux/main.c b/src/plugin/linux/main.c deleted file mode 100644 index 9cb2bbc..0000000 --- a/src/plugin/linux/main.c +++ /dev/null @@ -1,179 +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. - * - * 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 main.c e possui - linhas de código. - * - * Referências: - * - * https://github.com/fbuihuu/samples-dbus/blob/master/dbus-server.c - * - * 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 - -#include "service.h" -#include "dbus-glue.h" - -#include - -/*---[ Globals ]---------------------------------------------------------------------------------*/ - - static DBusGConnection * connection = NULL; - static DBusGProxy * proxy = NULL; - static gchar * service_name = NULL; - - -/*---[ Implement ]-------------------------------------------------------------------------------*/ - - LIB3270_EXPORT int pw3270_plugin_start(GtkWidget G_GNUC_UNUSED(*window), GtkWidget *terminal) - { - GError * error = NULL; - guint result; - char session_id = 0; - char id = 'a'; - const gchar * name = "pw3270"; - - connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error); - if(error) - { - GtkWidget *dialog = gtk_message_dialog_new( - GTK_WINDOW(window), - (GtkDialogFlags) (GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT), - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _( "Can't connect to DBUS server" )); - - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); - - g_message("Error \"%s\" getting session dbus",error->message); - - g_error_free(error); - - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - return -1; - } - - proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); - - for(id='a'; id < 'z' && !error && !service_name; id++) - { - gboolean has_owner = FALSE; - - service_name = g_strdup_printf("br.com.bb.%s.%c",name,(int) id); - - org_freedesktop_DBus_name_has_owner(proxy, service_name, &has_owner, NULL); - - if(has_owner) - { - trace("Service \"%s\" has owner",service_name) - g_free(service_name); - service_name = NULL; - } - else - { - session_id = id; - g_message("DBUS service name is %s",service_name); - org_freedesktop_DBus_request_name(proxy, service_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); - } - } - - if(error) - { - GtkWidget *dialog = gtk_message_dialog_new( - GTK_WINDOW(window), - (GtkDialogFlags) (GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT), - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _( "Can't get DBUS object name" )); - - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); - - g_message("Error \"%s\" requesting DBUS name",error->message); - - g_error_free(error); - - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - return -1; - } - - if(session_id) - { - g_autofree gchar * path = g_strdup_printf("/br/com/bb/%s",name); - g_autofree gchar * session = g_strdup_printf("%s:%c",name,g_ascii_toupper(session_id)); - - // pw3270_set_session_name(window,session); - v3270_set_session_name(terminal,session); - - g_message("DBUS service path is %s, session name is %s",path,session); - - pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,path); - - } - - return 0; - } - - LIB3270_EXPORT int pw3270_plugin_stop(GtkWidget G_GNUC_UNUSED(*window), GtkWidget G_GNUC_UNUSED(*terminal)) - { - if(proxy) - { - debug("%s: Releasing proxy",__FUNCTION__); - g_object_unref(proxy); - proxy = NULL; - } - - if(service_name) - { - g_free(service_name); - service_name = NULL; - } - return 0; - } - - void pw3270_dbus_quit(PW3270Dbus G_GNUC_UNUSED(*object), DBusGMethodInvocation *context) - { - gtk_main_quit(); - dbus_g_method_return(context,0); - } - - H3270 * pw3270_dbus_get_session_handle(PW3270Dbus G_GNUC_UNUSED(*object)) - { - debug("%s=%p",__FUNCTION__,lib3270_get_default_session_handle()); - return lib3270_get_default_session_handle(); - } - - - diff --git a/src/plugin/linux/misc.c b/src/plugin/linux/misc.c deleted file mode 100644 index 08c5fa2..0000000 --- a/src/plugin/linux/misc.c +++ /dev/null @@ -1,47 +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. - * - * 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 misc.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) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - * Referencias: - * - * https://live.gnome.org/DBusGlibBindings - * - */ - -#include "globals.h" - -/*---[ Implement ]-------------------------------------------------------------------------------*/ - -gpointer pw3270_dbus_register_object(DBusGConnection *connection,DBusGProxy G_GNUC_UNUSED(*proxy),GType object_type,const DBusGObjectInfo *info,const gchar *path) -{ - GObject *object = G_OBJECT(g_object_new(object_type, NULL)); - dbus_g_object_type_install_info (object_type, info); - dbus_g_connection_register_g_object (connection, path, object); - return object; -} - diff --git a/src/plugin/linux/service.h b/src/plugin/linux/service.h deleted file mode 100644 index aba8322..0000000 --- a/src/plugin/linux/service.h +++ /dev/null @@ -1,138 +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. - * - * 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 service.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) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - */ - -#ifndef _PW3270_DBUS_SERVICE_H - - #define _PW3270_DBUS_SERVICE_H 1 - - #define ENABLE_NLS - #define GETTEXT_PACKAGE PACKAGE_NAME - - #include "globals.h" - - #define PW3270_TYPE_DBUS (pw3270_dbus_get_type ()) - #define PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PW3270_TYPE_DBUS, PW3270Dbus)) - #define PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_DBUS, PW3270DbusClass)) - #define IS_PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PW3270_TYPE_DBUS)) - #define IS_PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PW3270_TYPE_DBUS)) - #define PW3270_DBUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PW3270_TYPE_DBUS, PW3270DbusClass)) - - G_BEGIN_DECLS - - typedef struct _PW3270Dbus PW3270Dbus; - typedef struct _PW3270DbusClass PW3270DbusClass; - - struct _PW3270Dbus - { - GObject parent; - }; - - struct _PW3270DbusClass - { - GObjectClass parent; - }; - - PW3270Dbus * pw3270_dbus_new (void); - GType pw3270_dbus_get_type (void); - - void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); - void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); - void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context); - H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object); - GError * pw3270_dbus_get_error_from_errno(int code); - - void pw3270_dbus_is_connected(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context); - void pw3270_dbus_set_cursor_address(PW3270Dbus *object, int addr, DBusGMethodInvocation *context); - void pw3270_dbus_get_cursor_address(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_get_screen_width(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_get_screen_height(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_get_screen_length(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context); - - void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context); - - void pw3270_dbus_get_field_start(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); - void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); - void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); - - void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); - void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context); - - void pw3270_dbus_set_script(PW3270Dbus *object, const gchar *text, int mode, DBusGMethodInvocation *context); - - void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context); - - void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context); - - // Actions - void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context); - void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context); - void pw3270_dbus_set_text_at(PW3270Dbus *object, int row, int col, const gchar *text, DBusGMethodInvocation *context); - void pw3270_dbus_get_text_at(PW3270Dbus *object, int row, int col, int len, char lf, DBusGMethodInvocation *context); - void pw3270_dbus_get_text(PW3270Dbus *object, int offset, int len, char lf, DBusGMethodInvocation *context); - void pw3270_dbus_cmp_text_at(PW3270Dbus *object, int row, int col, const gchar *text, char lf, DBusGMethodInvocation *context); - void pw3270_dbus_input(PW3270Dbus *object, const gchar *utftext, DBusGMethodInvocation *context); - - void pw3270_dbus_set_clipboard(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context); - void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_get_display_charset(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_get_host_charset(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_set_host_charset(PW3270Dbus *object, const gchar *charset, DBusGMethodInvocation *context); - void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context); - void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context); - - void pw3270_dbus_filetransfer(PW3270Dbus *object, const gchar *local, const gchar *remote, int flags, int lrecl, int blksize, int primspace, int secspace, int dft, DBusGMethodInvocation *context); - - void pw3270_dbus_set_unlock_delay(PW3270Dbus *object, int value, DBusGMethodInvocation *context); - - G_END_DECLS - -#endif // _PW3270_DBUS_SERVICE_H diff --git a/src/plugin/windows/main.c b/src/plugin/windows/main.c deleted file mode 100644 index 03a3b4d..0000000 --- a/src/plugin/windows/main.c +++ /dev/null @@ -1,675 +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 - 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 "private.h" - -#ifdef _WIN32 - #include -#else - #error HLLAPI is designed for windows. -#endif // _WIN32 - - #include - #include - #include - #include - #include - -/*--[ Defines ]--------------------------------------------------------------------------------------*/ - - #pragma pack(1) - - enum PIPE_STATE - { - PIPE_STATE_WAITING, - PIPE_STATE_READ, - PIPE_STATE_PENDING_READ, - PIPE_STATE_UNDEFINED - }; - - typedef struct _pipe_source - { - GSource gsrc; - HANDLE hPipe; - - enum PIPE_STATE 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); - 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_text(pipe_source *source, char *text) - { - struct hllapi_packet_text *pkt; - DWORD szBlock; - int f; - - if(text) - { - szBlock = sizeof(struct hllapi_packet_text)+strlen(text); - pkt = (struct hllapi_packet_text *) g_malloc0(szBlock); - pkt->packet_id = 0; - strcpy(pkt->text,text); - lib3270_free(text); - } - else - { - szBlock = sizeof(struct hllapi_packet_text); - pkt = (struct hllapi_packet_text *) g_malloc0(szBlock); - pkt->packet_id = errno ? errno : -1; - } - - trace("szBlock=%d text=\"%s\"",szBlock, ( (struct hllapi_packet_text *) pkt)->text); - for(f=0;f< (int) szBlock;f++) - { - trace("rsp(%d)= %d \"%s\"",f,* (((char *) pkt)+f),((char *) pkt)+f); - } - - WriteFile(source->hPipe,pkt,szBlock,&szBlock,NULL); - - g_free(pkt); - } - - 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 int do_file_transfer(struct hllapi_packet_file_transfer * source) - { - /* - const gchar * local = (const char *) source->text; - const gchar * remote = (const char *) (local+strlen(local)+1); - - return v3270_transfer_file( v3270_get_default_widget(), - (LIB3270_FT_OPTION) source->options, - local, - remote, - source->lrecl, - source->blksize, - source->primspace, - source->secspace, - source->dft ); - */ - return EINVAL; - } - - static void get_host(pipe_source *source) { - send_text(source,strdup(lib3270_get_url(lib3270_get_default_session_handle()))); - } - - static void process_input(pipe_source *source, DWORD G_GNUC_UNUSED(cbRead)) - { - const struct hllapi_packet_query * query = ((struct hllapi_packet_query *) source->buffer); - - trace("%s id=%d",__FUNCTION__,query->packet_id); - - switch(query->packet_id) - { - case HLLAPI_PACKET_CONNECT: - send_result(source,lib3270_reconnect( lib3270_get_default_session_handle(), - ((struct hllapi_packet_connect *) source->buffer)->wait)); - break; - - case HLLAPI_PACKET_CONNECT_URL: - send_result(source,lib3270_connect_url(lib3270_get_default_session_handle(),(const char *) (query+1),0)); - break; - - case HLLAPI_PACKET_SET_HOST: - send_result(source,lib3270_set_url(lib3270_get_default_session_handle(), - ((struct hllapi_packet_text *) source->buffer)->text)); - break; - - case HLLAPI_PACKET_GET_HOST: - get_host(source); - break; - - case HLLAPI_PACKET_DISCONNECT: - send_result(source,lib3270_disconnect(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_IS_CONNECTED: - send_result(source,lib3270_in_tn3270e(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_IS_READY: - send_result(source,lib3270_is_ready(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_ENTER: - send_result(source,lib3270_enter(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_PRINT: - send_result(source,lib3270_print_all(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_ERASE: - send_result(source,lib3270_erase(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_ERASE_EOF: - send_result(source,lib3270_eraseeof(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_ERASE_EOL: - send_result(source,lib3270_eraseeol(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_ERASE_INPUT: - send_result(source,lib3270_eraseinput(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_GET_TEXT_AT: - send_text(source,lib3270_get_string_at( lib3270_get_default_session_handle(), - ((struct hllapi_packet_at *) source->buffer)->row, - ((struct hllapi_packet_at *) source->buffer)->col, - ((struct hllapi_packet_at *) source->buffer)->len, - ((struct hllapi_packet_at *) source->buffer)->lf)); - break; - - case HLLAPI_PACKET_GET_TEXT_AT_OFFSET: - send_text(source,lib3270_get_string_at_address( lib3270_get_default_session_handle(), - ((struct hllapi_packet_query_offset *) source->buffer)->addr, - ((struct hllapi_packet_query_offset *) source->buffer)->len, - ((struct hllapi_packet_query_offset *) source->buffer)->lf)); - 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, - ((struct hllapi_packet_text_at *) source->buffer)->lf)); - 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; - - case HLLAPI_PACKET_EMULATE_INPUT: - send_result(source,lib3270_emulate_input(lib3270_get_default_session_handle(), - (const char *) ((struct hllapi_packet_emulate_input *) source->buffer)->text, - (int) ((struct hllapi_packet_emulate_input *) source->buffer)->len, - (int) ((struct hllapi_packet_emulate_input *) source->buffer)->pasting)); - break; - - case HLLAPI_PACKET_SET_CURSOR: - send_result(source,lib3270_set_cursor_address(lib3270_get_default_session_handle(), - ((struct hllapi_packet_addr *) source->buffer)->addr)); - break; - - case HLLAPI_PACKET_GET_CURSOR: - send_result(source,lib3270_get_cursor_address(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_GET_WIDTH: - send_result(source,lib3270_get_width(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_GET_HEIGHT: - send_result(source,lib3270_get_height(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_GET_LENGTH: - send_result(source,lib3270_get_length(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_GET_SSL_STATE: - send_result(source,lib3270_get_secure(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_SET_UNLOCK_DELAY: - lib3270_set_unlock_delay(lib3270_get_default_session_handle(),(unsigned short) ((struct hllapi_packet_set_int *) source->buffer)->value); - send_result(source,0); - break; - - case HLLAPI_PACKET_SET_TOGGLE: - send_result(source,lib3270_set_toggle(lib3270_get_default_session_handle(), - (LIB3270_TOGGLE) ((struct hllapi_packet_set *) source->buffer)->id, - ((struct hllapi_packet_set *) source->buffer)->value)); - break; - - case HLLAPI_PACKET_FIELD_START: - send_result(source,lib3270_get_field_start(lib3270_get_default_session_handle(), - ((struct hllapi_packet_addr *) source->buffer)->addr)); - break; - - - case HLLAPI_PACKET_FIELD_LEN: - send_result(source,lib3270_get_field_len(lib3270_get_default_session_handle(), - ((struct hllapi_packet_addr *) source->buffer)->addr)); - break; - - case HLLAPI_PACKET_NEXT_UNPROTECTED: - send_result(source,lib3270_get_next_unprotected(lib3270_get_default_session_handle(), - ((struct hllapi_packet_addr *) source->buffer)->addr)); - break; - - case HLLAPI_PACKET_IS_PROTECTED: - send_result(source,lib3270_get_is_protected(lib3270_get_default_session_handle(), - ((struct hllapi_packet_addr *) source->buffer)->addr)); - break; - - case HLLAPI_PACKET_IS_PROTECTED_AT: - send_result(source,lib3270_get_is_protected_at( lib3270_get_default_session_handle(), - ((struct hllapi_packet_query_at *) source->buffer)->row, - ((struct hllapi_packet_query_at *) source->buffer)->col)); - break; - - case HLLAPI_PACKET_QUIT: - gtk_main_quit(); - send_result(source,0); - break; - - case HLLAPI_PACKET_SET_HOST_CHARSET: - send_result(source,lib3270_set_host_charset( lib3270_get_default_session_handle(), - (const char *) ((struct hllapi_packet_set_text *) source->buffer)->text)); - break; - - case HLLAPI_PACKET_ASC2EBC: - send_text(source,(char *) lib3270_asc2ebc( - lib3270_get_default_session_handle(), - (unsigned char *) ((struct hllapi_packet_set_text *) source->buffer)->text,-1 - )); - break; - - case HLLAPI_PACKET_EBC2ASC: - send_text(source,(char *) lib3270_ebc2asc( - lib3270_get_default_session_handle(), - (unsigned char *) ((struct hllapi_packet_set_text *) source->buffer)->text,-1 - )); - break; - - case HLLAPI_PACKET_FILE_TRANSFER: - send_result(source,do_file_transfer((struct hllapi_packet_file_transfer *) source)); - break; - - case HLLAPI_PACKET_GET_HOST_CHARSET: - trace("%s","HLLAPI_PACKET_GET_HOST_CHARSET"); - send_text(source,(char *) lib3270_get_host_charset(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_ACTION: - send_result(source,lib3270_action(lib3270_get_default_session_handle(), - (const 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 G_GNUC_UNUSED(callback), gpointer G_GNUC_UNUSED(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 G_GNUC_UNUSED(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= (char *) 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_start(GtkWidget *window, GtkWidget *terminal) - { - char id; - const gchar * name = "pw3270"; - - for(id='A';id < 'Z';id++) - { - gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s_%c",name,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",name,id); - - // pw3270_set_session_name(window,session); - v3270_set_session_name(terminal,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_stop(GtkWidget *window, GtkWidget *terminal) - { - - return 0; - } - - G_GNUC_INTERNAL void set_active(gboolean on) - { - trace("%s(%s)",__FUNCTION__,on ? "Active" : "Inactive"); - // v3270_set_script(v3270_get_default_widget(),'H'); - } diff --git a/src/plugin/windows/private.h b/src/plugin/windows/private.h deleted file mode 100644 index c9494d2..0000000 --- a/src/plugin/windows/private.h +++ /dev/null @@ -1,50 +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. - * - * 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 -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 - - G_GNUC_INTERNAL void popup_lasterror(const gchar *fmt, ...); - G_GNUC_INTERNAL void set_active(gboolean on); - - diff --git a/src/plugin/windows/resources.rc.in b/src/plugin/windows/resources.rc.in deleted file mode 100644 index e3675ae..0000000 --- a/src/plugin/windows/resources.rc.in +++ /dev/null @@ -1,29 +0,0 @@ -#include - -VS_VERSION_INFO VERSIONINFO -FILEVERSION @PACKAGE_MAJOR_VERSION@,@PACKAGE_MINOR_VERSION@,@PACKAGE_MAJOR_RELEASE@,0 -PRODUCTVERSION @PACKAGE_MAJOR_VERSION@,@PACKAGE_MINOR_VERSION@,@PACKAGE_MAJOR_RELEASE@,0 - -BEGIN - - BLOCK "StringFileInfo" - BEGIN - BLOCK "080904E4" - BEGIN - VALUE "FileDescription", "@PACKAGE_NAME@ IPC Plugin\0" - VALUE "CompanyName", "Banco do Brasil S/A.\0" - VALUE "FileVersion", "@WIN32_VERSION@\0" - VALUE "LegalCopyright", "(C) 2017 Banco do Brasil S/A. All Rights Reserved\0" - VALUE "OriginalFilename", "ipc3270@DLLEXT@\0" - VALUE "ProductName", "@PACKAGE_NAME@\0" - VALUE "ProductVersion", "@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@.@PACKAGE_MAJOR_RELEASE@.0\0" - END - END - - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x809, 0x04E4 - END - -END - diff --git a/src/testprogram/linux/test.sh b/src/testprogram/linux/test.sh deleted file mode 100755 index 376ed60..0000000 --- a/src/testprogram/linux/test.sh +++ /dev/null @@ -1,126 +0,0 @@ -#!/bin/bash - -SESSION=a -DEST=br.com.bb.pw3270 -BPATH=/br/com/bb/pw3270 - -run_command() -{ - - case $1 in - - revision) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getRevision - ;; - - message) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getMessageID - ;; - - ssl) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getSecureState - ;; - - connect) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.connect string:$2 int32:10 - ;; - - disconnect) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.disconnect - ;; - - url) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getURL - ;; - - quit) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.quit - ;; - - get) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getScreenContents - ;; - - gettext) -# addr,len,lf -# dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getText int32:1 int32:-1 byte:0 - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getText int32:1 int32:-1 byte:10 - ;; - - protect) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getIsProtectedAt int32:$2 int32:$3 - ;; - - set) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.setTextAt int32:$2 int32:$3 string:$4 - ;; - - action) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.action string:$2 - ;; - - enter) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.enter - ;; - - isconnected) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.isConnected - ;; - - hostcharset) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getHostCharset - ;; - - displaycharset) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getDisplayCharset - ;; - - unlockdelay) - dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.setUnlockDelay int32:$2 - ;; - - *) - echo "Comando $1 desconhecido" - ;; - - esac -} - - - -until [ -z "$1" ] -do - if [ ${1:0:2} = '--' ]; then - tmp=${1:2} - parameter=${tmp%%=*} - parameter=$(echo $parameter | tr "[:lower:]" "[:upper:]") - value=${tmp##*=} - - case "$parameter" in - SESSION) - SESSION=$value - ;; - HELP) - echo "$0 options" - echo "" - echo "Options:" - echo "" - echo " --session pw3270's session manager" - echo "" - exit 0 - ;; - - *) - eval $parameter=$value - ;; - - esac - - else - run_command $@ - exit 0 - fi - - shift -done - diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c deleted file mode 100644 index b3918c2..0000000 --- a/src/testprogram/testprogram.c +++ /dev/null @@ -1,248 +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 testprogram.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) - * - */ - - - /** - * @brief Test program for pw3270 HLLAPI compatibility plugin. - * - */ - - #include - #include - #include - #include - #include - #include - #include - - /*---[ Globals ]------------------------------------------------------------------------------------*/ - - const gchar * plugin_path = ".bin/Debug"; - const gchar * session_name = "pw3270"; - const gchar * plugin_name = "ipc3270c." G_MODULE_SUFFIX; - - /*---[ Implement ]----------------------------------------------------------------------------------*/ - - static void close_module(GtkWidget *widget, GModule *module) - { - g_message("Closing module %p",module); - - static void (*stop)(GtkWidget *window, GtkWidget *terminal) = NULL; - if(!g_module_symbol(module,"pw3270_plugin_stop",(void **) &stop)) - { - g_message("Can't get stop method from plugin: %s",g_module_error()); - } - else - { - stop(gtk_widget_get_toplevel(widget),widget); - } - - g_module_close(module); - g_message("Module %p was closed",module); - } - - static void toggle_ds_trace(GtkToggleToolButton *button, GtkWidget *terminal) - { - v3270_set_toggle(terminal,LIB3270_TOGGLE_DS_TRACE,gtk_toggle_tool_button_get_active(button)); - } - - static void toggle_event_trace(GtkToggleToolButton *button, GtkWidget *terminal) - { - v3270_set_toggle(terminal,LIB3270_TOGGLE_EVENT_TRACE,gtk_toggle_tool_button_get_active(button)); - } - - static void toggle_ssl_trace(GtkToggleToolButton *button, GtkWidget *terminal) - { - v3270_set_toggle(terminal,LIB3270_TOGGLE_SSL_TRACE,gtk_toggle_tool_button_get_active(button)); - } - - static void toggle_screen_trace(GtkToggleToolButton *button, GtkWidget *terminal) - { - v3270_set_toggle(terminal,LIB3270_TOGGLE_SCREEN_TRACE,gtk_toggle_tool_button_get_active(button)); - } - - static void toggle_started_trace(GtkToggleToolButton *button, GModule *module) - { - if(!module) - return; - - GtkWidget * terminal = GTK_WIDGET(g_object_get_data(G_OBJECT(button),"terminal")); - - const gchar * method_name = (gtk_toggle_tool_button_get_active(button) ? "pw3270_plugin_start" : "pw3270_plugin_stop"); - - static void (*call)(GtkWidget *window, GtkWidget *terminal) = NULL; - if(!g_module_symbol(module,method_name,(void **) &call)) - { - g_message("Can't get method \"%s\": %s",method_name,g_module_error()); - return; - } - - g_message("Calling %s",method_name); - call(gtk_widget_get_toplevel(terminal), GTK_WIDGET(terminal)); - - } - - static GtkToolItem * create_tool_item(GtkWidget *terminal, const gchar *label, const gchar *tooltip, GCallback callback) - { - GtkToolItem * item = gtk_toggle_tool_button_new(); - gtk_tool_button_set_label(GTK_TOOL_BUTTON(item),label); - - g_signal_connect(GTK_WIDGET(item), "toggled", G_CALLBACK(callback), terminal); - - if(tooltip) - gtk_widget_set_tooltip_text(GTK_WIDGET(item),tooltip); - - return item; - } - - static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { - - GtkWidget * window = gtk_application_window_new(app); - GtkWidget * terminal = v3270_new(); - GtkWidget * notebook = gtk_notebook_new(); - GModule * module = NULL; - - gtk_widget_set_name(window,session_name); - - // Setup tabs - gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new(v3270_get_session_name(terminal))); - - // Load plugin - { - g_autofree gchar * plugin = g_build_filename(plugin_path,plugin_name,NULL); - - g_message("Loading %s",plugin); - - module = g_module_open(plugin,G_MODULE_BIND_LOCAL); - - if(module) - { - g_signal_connect (terminal, "destroy", G_CALLBACK(close_module), module); - } - else - { - g_message("Can't open \"%s\": %s",plugin,g_module_error()); - gtk_main_quit(); - } - - } - // Create trace window - { - GtkWidget * box = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); - GtkWidget * trace = v3270_trace_new(terminal); - GtkWidget * toolbar = gtk_toolbar_new(); - GtkToolItem * start = gtk_toggle_tool_button_new(); - - gtk_widget_set_sensitive(GTK_WIDGET(start),module != NULL); - - g_object_set_data(G_OBJECT(start),"terminal",terminal); - - gtk_tool_button_set_label(GTK_TOOL_BUTTON(start),"Enable"); - g_signal_connect(GTK_WIDGET(start), "toggled", G_CALLBACK(toggle_started_trace), module); - gtk_widget_set_tooltip_text(GTK_WIDGET(start),"Start/Stop plugin module"); - - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), start, -1); - - gtk_toolbar_insert(GTK_TOOLBAR(toolbar),gtk_separator_tool_item_new(),-1); - - gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "DS Trace","Toggle DS Trace",G_CALLBACK(toggle_ds_trace)),-1); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "Event Trace","Toggle Event Trace",G_CALLBACK(toggle_event_trace)),-1); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "Screen Trace","Toggle Screen Trace",G_CALLBACK(toggle_screen_trace)),-1); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "SSL Trace","Toggle SSL Trace",G_CALLBACK(toggle_ssl_trace)),-1); - - gtk_box_pack_start(GTK_BOX(box),toolbar,FALSE,FALSE,0); - gtk_box_pack_start(GTK_BOX(box),trace,TRUE,TRUE,0); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook),box,gtk_label_new("Trace")); - } - - // Setup and show main window - gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER); - gtk_window_set_default_size (GTK_WINDOW (window), 800, 500); - gtk_container_add(GTK_CONTAINER(window),notebook); - gtk_widget_show_all (window); - - // Setup title. - const gchar *url = lib3270_get_url(v3270_get_session(terminal)); - if(url) { - - v3270_set_url(terminal,url); - v3270_reconnect(terminal); - - gchar * title = g_strdup_printf("%s - %s", v3270_get_session_name(terminal), url); - gtk_window_set_title(GTK_WINDOW(window), title); - g_free(title); - - } else { - - gtk_window_set_title(GTK_WINDOW(window), v3270_get_session_name(terminal)); - - } - -} - -int main (int argc, char **argv) { - - /* - GVariantBuilder builder; - - g_variant_builder_init(&builder,G_VARIANT_TYPE("(isi)")); - - g_variant_builder_add(&builder, "i", 10); - g_variant_builder_add(&builder, "s", "teste"); - g_variant_builder_add(&builder, "i", 20); - - GVariant *value = g_variant_builder_end(&builder); - - size_t szPacket = 0; - g_autofree unsigned char * buffer = ipc3270_pack("teste", value, &szPacket); - g_variant_unref(value); - - debug("Package \"%s\" was created with %u bytes", buffer, (unsigned int) szPacket); - - value = ipc3270_unpack(buffer); - - g_variant_unref(value); - */ - - GtkApplication *app; - int status; - - app = gtk_application_new ("br.com.bb.pw3270",G_APPLICATION_FLAGS_NONE); - - g_signal_connect (app, "activate", G_CALLBACK(activate), NULL); - - status = g_application_run (G_APPLICATION (app), argc, argv); - g_object_unref (app); - - g_message("rc=%d",status); - return status; - -} - diff --git a/src/testprograms/linux/test.sh b/src/testprograms/linux/test.sh new file mode 100755 index 0000000..376ed60 --- /dev/null +++ b/src/testprograms/linux/test.sh @@ -0,0 +1,126 @@ +#!/bin/bash + +SESSION=a +DEST=br.com.bb.pw3270 +BPATH=/br/com/bb/pw3270 + +run_command() +{ + + case $1 in + + revision) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getRevision + ;; + + message) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getMessageID + ;; + + ssl) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getSecureState + ;; + + connect) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.connect string:$2 int32:10 + ;; + + disconnect) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.disconnect + ;; + + url) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getURL + ;; + + quit) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.quit + ;; + + get) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getScreenContents + ;; + + gettext) +# addr,len,lf +# dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getText int32:1 int32:-1 byte:0 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getText int32:1 int32:-1 byte:10 + ;; + + protect) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getIsProtectedAt int32:$2 int32:$3 + ;; + + set) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.setTextAt int32:$2 int32:$3 string:$4 + ;; + + action) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.action string:$2 + ;; + + enter) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.enter + ;; + + isconnected) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.isConnected + ;; + + hostcharset) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getHostCharset + ;; + + displaycharset) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getDisplayCharset + ;; + + unlockdelay) + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.setUnlockDelay int32:$2 + ;; + + *) + echo "Comando $1 desconhecido" + ;; + + esac +} + + + +until [ -z "$1" ] +do + if [ ${1:0:2} = '--' ]; then + tmp=${1:2} + parameter=${tmp%%=*} + parameter=$(echo $parameter | tr "[:lower:]" "[:upper:]") + value=${tmp##*=} + + case "$parameter" in + SESSION) + SESSION=$value + ;; + HELP) + echo "$0 options" + echo "" + echo "Options:" + echo "" + echo " --session pw3270's session manager" + echo "" + exit 0 + ;; + + *) + eval $parameter=$value + ;; + + esac + + else + run_command $@ + exit 0 + fi + + shift +done + diff --git a/src/testprograms/plugin.c b/src/testprograms/plugin.c new file mode 100644 index 0000000..b3918c2 --- /dev/null +++ b/src/testprograms/plugin.c @@ -0,0 +1,248 @@ +/* + * "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 testprogram.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) + * + */ + + + /** + * @brief Test program for pw3270 HLLAPI compatibility plugin. + * + */ + + #include + #include + #include + #include + #include + #include + #include + + /*---[ Globals ]------------------------------------------------------------------------------------*/ + + const gchar * plugin_path = ".bin/Debug"; + const gchar * session_name = "pw3270"; + const gchar * plugin_name = "ipc3270c." G_MODULE_SUFFIX; + + /*---[ Implement ]----------------------------------------------------------------------------------*/ + + static void close_module(GtkWidget *widget, GModule *module) + { + g_message("Closing module %p",module); + + static void (*stop)(GtkWidget *window, GtkWidget *terminal) = NULL; + if(!g_module_symbol(module,"pw3270_plugin_stop",(void **) &stop)) + { + g_message("Can't get stop method from plugin: %s",g_module_error()); + } + else + { + stop(gtk_widget_get_toplevel(widget),widget); + } + + g_module_close(module); + g_message("Module %p was closed",module); + } + + static void toggle_ds_trace(GtkToggleToolButton *button, GtkWidget *terminal) + { + v3270_set_toggle(terminal,LIB3270_TOGGLE_DS_TRACE,gtk_toggle_tool_button_get_active(button)); + } + + static void toggle_event_trace(GtkToggleToolButton *button, GtkWidget *terminal) + { + v3270_set_toggle(terminal,LIB3270_TOGGLE_EVENT_TRACE,gtk_toggle_tool_button_get_active(button)); + } + + static void toggle_ssl_trace(GtkToggleToolButton *button, GtkWidget *terminal) + { + v3270_set_toggle(terminal,LIB3270_TOGGLE_SSL_TRACE,gtk_toggle_tool_button_get_active(button)); + } + + static void toggle_screen_trace(GtkToggleToolButton *button, GtkWidget *terminal) + { + v3270_set_toggle(terminal,LIB3270_TOGGLE_SCREEN_TRACE,gtk_toggle_tool_button_get_active(button)); + } + + static void toggle_started_trace(GtkToggleToolButton *button, GModule *module) + { + if(!module) + return; + + GtkWidget * terminal = GTK_WIDGET(g_object_get_data(G_OBJECT(button),"terminal")); + + const gchar * method_name = (gtk_toggle_tool_button_get_active(button) ? "pw3270_plugin_start" : "pw3270_plugin_stop"); + + static void (*call)(GtkWidget *window, GtkWidget *terminal) = NULL; + if(!g_module_symbol(module,method_name,(void **) &call)) + { + g_message("Can't get method \"%s\": %s",method_name,g_module_error()); + return; + } + + g_message("Calling %s",method_name); + call(gtk_widget_get_toplevel(terminal), GTK_WIDGET(terminal)); + + } + + static GtkToolItem * create_tool_item(GtkWidget *terminal, const gchar *label, const gchar *tooltip, GCallback callback) + { + GtkToolItem * item = gtk_toggle_tool_button_new(); + gtk_tool_button_set_label(GTK_TOOL_BUTTON(item),label); + + g_signal_connect(GTK_WIDGET(item), "toggled", G_CALLBACK(callback), terminal); + + if(tooltip) + gtk_widget_set_tooltip_text(GTK_WIDGET(item),tooltip); + + return item; + } + + static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { + + GtkWidget * window = gtk_application_window_new(app); + GtkWidget * terminal = v3270_new(); + GtkWidget * notebook = gtk_notebook_new(); + GModule * module = NULL; + + gtk_widget_set_name(window,session_name); + + // Setup tabs + gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new(v3270_get_session_name(terminal))); + + // Load plugin + { + g_autofree gchar * plugin = g_build_filename(plugin_path,plugin_name,NULL); + + g_message("Loading %s",plugin); + + module = g_module_open(plugin,G_MODULE_BIND_LOCAL); + + if(module) + { + g_signal_connect (terminal, "destroy", G_CALLBACK(close_module), module); + } + else + { + g_message("Can't open \"%s\": %s",plugin,g_module_error()); + gtk_main_quit(); + } + + } + // Create trace window + { + GtkWidget * box = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); + GtkWidget * trace = v3270_trace_new(terminal); + GtkWidget * toolbar = gtk_toolbar_new(); + GtkToolItem * start = gtk_toggle_tool_button_new(); + + gtk_widget_set_sensitive(GTK_WIDGET(start),module != NULL); + + g_object_set_data(G_OBJECT(start),"terminal",terminal); + + gtk_tool_button_set_label(GTK_TOOL_BUTTON(start),"Enable"); + g_signal_connect(GTK_WIDGET(start), "toggled", G_CALLBACK(toggle_started_trace), module); + gtk_widget_set_tooltip_text(GTK_WIDGET(start),"Start/Stop plugin module"); + + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), start, -1); + + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),gtk_separator_tool_item_new(),-1); + + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "DS Trace","Toggle DS Trace",G_CALLBACK(toggle_ds_trace)),-1); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "Event Trace","Toggle Event Trace",G_CALLBACK(toggle_event_trace)),-1); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "Screen Trace","Toggle Screen Trace",G_CALLBACK(toggle_screen_trace)),-1); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "SSL Trace","Toggle SSL Trace",G_CALLBACK(toggle_ssl_trace)),-1); + + gtk_box_pack_start(GTK_BOX(box),toolbar,FALSE,FALSE,0); + gtk_box_pack_start(GTK_BOX(box),trace,TRUE,TRUE,0); + gtk_notebook_append_page(GTK_NOTEBOOK(notebook),box,gtk_label_new("Trace")); + } + + // Setup and show main window + gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER); + gtk_window_set_default_size (GTK_WINDOW (window), 800, 500); + gtk_container_add(GTK_CONTAINER(window),notebook); + gtk_widget_show_all (window); + + // Setup title. + const gchar *url = lib3270_get_url(v3270_get_session(terminal)); + if(url) { + + v3270_set_url(terminal,url); + v3270_reconnect(terminal); + + gchar * title = g_strdup_printf("%s - %s", v3270_get_session_name(terminal), url); + gtk_window_set_title(GTK_WINDOW(window), title); + g_free(title); + + } else { + + gtk_window_set_title(GTK_WINDOW(window), v3270_get_session_name(terminal)); + + } + +} + +int main (int argc, char **argv) { + + /* + GVariantBuilder builder; + + g_variant_builder_init(&builder,G_VARIANT_TYPE("(isi)")); + + g_variant_builder_add(&builder, "i", 10); + g_variant_builder_add(&builder, "s", "teste"); + g_variant_builder_add(&builder, "i", 20); + + GVariant *value = g_variant_builder_end(&builder); + + size_t szPacket = 0; + g_autofree unsigned char * buffer = ipc3270_pack("teste", value, &szPacket); + g_variant_unref(value); + + debug("Package \"%s\" was created with %u bytes", buffer, (unsigned int) szPacket); + + value = ipc3270_unpack(buffer); + + g_variant_unref(value); + */ + + GtkApplication *app; + int status; + + app = gtk_application_new ("br.com.bb.pw3270",G_APPLICATION_FLAGS_NONE); + + g_signal_connect (app, "activate", G_CALLBACK(activate), NULL); + + status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + + g_message("rc=%d",status); + return status; + +} + -- libgit2 0.21.2