From b44182376011d616f819ae3d500845641155eec8 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 28 Dec 2018 16:33:31 -0200 Subject: [PATCH] Reorganizing modules. --- .gitignore | 4 +++- Makefile.in | 29 ++++++++++++++--------------- configure.ac | 3 ++- pw3270-plugin-ipc.cbp | 3 +++ src/constants.c | 51 --------------------------------------------------- src/convert.c | 59 ----------------------------------------------------------- src/core/constants.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/convert.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/getproperties.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/linux/dbus-definition.xml | 9 +++++++++ src/core/linux/gobject.c | 351 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/linux/gobject.h | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/linux/start.c.1 | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/methods.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/setproperties.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/windows/gobject.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/windows/gobject.h | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/windows/inout.c | 295 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/windows/pipesource.c | 214 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/windows/resources.rc.in | 29 +++++++++++++++++++++++++++++ src/getproperties.c | 128 -------------------------------------------------------------------------------------------------------------------------------- src/include/lib3270/ipc.h | 4 ++++ src/linux/dbus-definition.xml | 9 --------- src/linux/gobject.c | 351 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/linux/gobject.h | 77 ----------------------------------------------------------------------------- src/linux/start.c.1 | 191 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/methods.c | 172 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/plugin/windows/resources.rc.in | 29 +++++++++++++++++++++++++++++ src/setproperties.c | 151 ------------------------------------------------------------------------------------------------------------------------------------------------------- src/testprogram/testprogram.c | 40 +++++++++++++++++++++++++++++++--------- src/windows/gobject.c | 125 ----------------------------------------------------------------------------------------------------------------------------- src/windows/gobject.h | 97 ------------------------------------------------------------------------------------------------- src/windows/inout.c | 275 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/windows/pipesource.c | 214 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/windows/resources.rc.in | 29 ----------------------------- 35 files changed, 2040 insertions(+), 1955 deletions(-) delete mode 100644 src/constants.c delete mode 100644 src/convert.c create mode 100644 src/core/constants.c create mode 100644 src/core/convert.c create mode 100644 src/core/getproperties.c create mode 100644 src/core/linux/dbus-definition.xml create mode 100644 src/core/linux/gobject.c create mode 100644 src/core/linux/gobject.h create mode 100644 src/core/linux/start.c.1 create mode 100644 src/core/methods.c create mode 100644 src/core/setproperties.c create mode 100644 src/core/windows/gobject.c create mode 100644 src/core/windows/gobject.h create mode 100644 src/core/windows/inout.c create mode 100644 src/core/windows/pipesource.c create mode 100644 src/core/windows/resources.rc.in delete mode 100644 src/getproperties.c delete mode 100644 src/linux/dbus-definition.xml delete mode 100644 src/linux/gobject.c delete mode 100644 src/linux/gobject.h delete mode 100644 src/linux/start.c.1 delete mode 100644 src/methods.c create mode 100644 src/plugin/windows/resources.rc.in delete mode 100644 src/setproperties.c delete mode 100644 src/windows/gobject.c delete mode 100644 src/windows/gobject.h delete mode 100644 src/windows/inout.c delete mode 100644 src/windows/pipesource.c delete mode 100644 src/windows/resources.rc.in diff --git a/.gitignore b/.gitignore index dfe44fc..c6254da 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,6 @@ stamp-h1 Makefile *.[0-9] conf/systemd.service -src/windows/resources.rc +src/core/windows/resources.rc +src/plugin/windows/resources.rc + diff --git a/Makefile.in b/Makefile.in index afe6729..aef5ab5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -30,16 +30,16 @@ MODULE_NAME=ipc3270 PACKAGE_NAME=@PACKAGE_NAME@ CORE_SOURCES= \ - $(wildcard src/*.c) \ - $(wildcard src/@OSNAME@/*.c) + $(wildcard src/core/*.c) \ + $(wildcard src/core/@OSNAME@/*.c) PLUGIN_SOURCES= \ $(wildcard src/plugin/*.c) \ - $(wildcard src/@OSNAME@/*.rc) + $(wildcard src/plugin/@OSNAME@/*.rc) SERVICE_SOURCES= \ $(wildcard src/service/*.c) \ - $(wildcard src/@OSNAME@/*.rc) + $(wildcard src/service/@OSNAME@/*.rc) TEST_SOURCES= \ $(wildcard src/testprogram/*.c) @@ -88,8 +88,7 @@ BINRLS=$(BINDIR)/Release DEPENDS= \ Makefile \ src/include/*.h \ - src/include/lib3270/*.h \ - src/linux/*.h + src/include/lib3270/*.h CFLAGS= \ @CFLAGS@ \ @@ -195,7 +194,7 @@ $(BINRLS)/lib$(MODULE_NAME).a: \ $(BINRLS)/$(MODULE_NAME)@DLLEXT@: \ $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJRLS)/$(SRC).o) \ - $(foreach SRC, $(basename $(CORE_SOURCES)), $(OBJRLS)/$(SRC).o) + $(BINRLS)/lib$(MODULE_NAME).a @$(MKDIR) `dirname $@` @echo $< ... @@ -204,8 +203,8 @@ $(BINRLS)/$(MODULE_NAME)@DLLEXT@: \ -o $@ \ $(LDFLAGS) \ $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJRLS)/$(SRC).o) \ - $(foreach SRC, $(basename $(CORE_SOURCES)), $(OBJRLS)/$(SRC).o) \ - $(LIBS) + $(LIBS) \ + -L$(BINRLS) -l$(MODULE_NAME) #---[ Install Targets ]------------------------------------------------------------------ @@ -247,6 +246,9 @@ Debug-plugin: \ Debug-service: \ $(BINDBG)/$(PACKAGE_NAME)d@EXEEXT@ +x: + @echo $(foreach SRC, $(basename $(CORE_SOURCES)), $(OBJDBG)/$(SRC).o) + $(BINDBG)/lib$(MODULE_NAME).a: \ $(foreach SRC, $(basename $(CORE_SOURCES)), $(OBJDBG)/$(SRC).o) @@ -309,12 +311,9 @@ $(BINDBG)/@DLLPREFIX@$(MODULE_NAME)@DLLEXT@.@PACKAGE_MAJOR_VERSION@: \ @DLLPREFIX@$(MODULE_NAME)@DLLEXT@.@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@ \ $@ -x: \ - $(BINDBG)/@DLLPREFIX@$(MODULE_NAME)@DLLEXT@.@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@ - $(BINDBG)/@DLLPREFIX@$(MODULE_NAME)@DLLEXT@.@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@: \ $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o) \ - $(foreach SRC, $(basename $(CORE_SOURCES)), $(OBJDBG)/$(SRC).o) + $(BINDBG)/lib$(MODULE_NAME).a @$(MKDIR) `dirname $@` @echo $< ... @@ -323,8 +322,8 @@ $(BINDBG)/@DLLPREFIX@$(MODULE_NAME)@DLLEXT@.@PACKAGE_MAJOR_VERSION@.@PACKAGE_MIN -o $@ \ $(LDFLAGS) \ $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o) \ - $(foreach SRC, $(basename $(CORE_SOURCES)), $(OBJDBG)/$(SRC).o) \ - $(LIBS) + $(LIBS) \ + -L$(BINDBG) -l$(MODULE_NAME) #---[ Clean Targets ]-------------------------------------------------------------------- diff --git a/configure.ac b/configure.ac index ae464aa..177cb96 100644 --- a/configure.ac +++ b/configure.ac @@ -84,7 +84,8 @@ case "$host" in app_win32_revision=$(date +%y.%m.%d.%H) AC_SUBST(WIN32_VERSION,$app_win32_revision) - AC_CONFIG_FILES(src/windows/resources.rc) + AC_CONFIG_FILES(src/core/windows/resources.rc) + AC_CONFIG_FILES(src/plugin/windows/resources.rc) ;; s390x-*) diff --git a/pw3270-plugin-ipc.cbp b/pw3270-plugin-ipc.cbp index b2fa5ab..3253405 100644 --- a/pw3270-plugin-ipc.cbp +++ b/pw3270-plugin-ipc.cbp @@ -69,6 +69,9 @@ + + diff --git a/src/constants.c b/src/constants.c deleted file mode 100644 index 070f60a..0000000 --- a/src/constants.c +++ /dev/null @@ -1,51 +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/joprietoe/gdbus/blob/master/gdbus-example-server.c - * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - -#include -#include -#include - -const IPC_METHOD_INT_ARG * ipc3270_get_int_arg_methods() { - - static const IPC_METHOD_INT_ARG int_arg_methods[] = { - { "pfkey", lib3270_pfkey }, - { "pakey", lib3270_pakey }, - { NULL, NULL } - }; - - return int_arg_methods; - -} - - diff --git a/src/convert.c b/src/convert.c deleted file mode 100644 index 245f8cc..0000000 --- a/src/convert.c +++ /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 main.c e possui - linhas de código. - * - * Referências: - * - * https://github.com/joprietoe/gdbus/blob/master/gdbus-example-server.c - * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - -#include -#include -#include - -gchar * ipc3270_convert_output_string(GObject *object, const gchar *string, GError **error) { - return g_convert_with_fallback(string,-1,ipc3270_get_display_charset(object),"UTF-8","?",NULL,NULL,error); -} - -gchar * ipc3270_convert_input_string(GObject *object, const gchar *string, GError **error) { - return g_convert_with_fallback(string,-1,"UTF-8",ipc3270_get_display_charset(object),"?",NULL,NULL,error); -} - -GVariant * ipc3270_GVariant_from_input_string(GObject *object, char *string, GError **error) { - - if(string) { - g_autofree gchar * utfstring = ipc3270_convert_input_string(object,string,error); - lib3270_free(string); - return g_variant_new("(s)", utfstring); - } - - ipc3270_set_error(object,errno,error); - return g_variant_new("(s)", ""); -} - - diff --git a/src/core/constants.c b/src/core/constants.c new file mode 100644 index 0000000..070f60a --- /dev/null +++ b/src/core/constants.c @@ -0,0 +1,51 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 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/joprietoe/gdbus/blob/master/gdbus-example-server.c + * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#include +#include +#include + +const IPC_METHOD_INT_ARG * ipc3270_get_int_arg_methods() { + + static const IPC_METHOD_INT_ARG int_arg_methods[] = { + { "pfkey", lib3270_pfkey }, + { "pakey", lib3270_pakey }, + { NULL, NULL } + }; + + return int_arg_methods; + +} + + diff --git a/src/core/convert.c b/src/core/convert.c new file mode 100644 index 0000000..245f8cc --- /dev/null +++ b/src/core/convert.c @@ -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 main.c e possui - linhas de código. + * + * Referências: + * + * https://github.com/joprietoe/gdbus/blob/master/gdbus-example-server.c + * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#include +#include +#include + +gchar * ipc3270_convert_output_string(GObject *object, const gchar *string, GError **error) { + return g_convert_with_fallback(string,-1,ipc3270_get_display_charset(object),"UTF-8","?",NULL,NULL,error); +} + +gchar * ipc3270_convert_input_string(GObject *object, const gchar *string, GError **error) { + return g_convert_with_fallback(string,-1,"UTF-8",ipc3270_get_display_charset(object),"?",NULL,NULL,error); +} + +GVariant * ipc3270_GVariant_from_input_string(GObject *object, char *string, GError **error) { + + if(string) { + g_autofree gchar * utfstring = ipc3270_convert_input_string(object,string,error); + lib3270_free(string); + return g_variant_new("(s)", utfstring); + } + + ipc3270_set_error(object,errno,error); + return g_variant_new("(s)", ""); +} + + diff --git a/src/core/getproperties.c b/src/core/getproperties.c new file mode 100644 index 0000000..390b8e6 --- /dev/null +++ b/src/core/getproperties.c @@ -0,0 +1,128 @@ +/* + * "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/joprietoe/gdbus/blob/master/gdbus-example-server.c + * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.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 + +GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error) { + + size_t ix; + errno = 0; // Just in case. + + // Boolean properties + const LIB3270_INT_PROPERTY * boolprop = lib3270_get_boolean_properties_list(); + for(ix = 0; boolprop[ix].name; ix++) { + + if(boolprop[ix].get && !g_ascii_strcasecmp(boolprop[ix].name, property_name)) { + + // Found it! + int value = boolprop[ix].get(ipc3270_get_session(object)); + + debug("%s=%d",property_name,value); + + if(value > 0 || errno == 0) { + return g_variant_new_boolean(value != 0); + } + + // Erro! + ipc3270_set_error(object,ENOENT,error); + return NULL; + + } + + } + + // int properties + const LIB3270_INT_PROPERTY * intprop = lib3270_get_int_properties_list(); + for(ix = 0; intprop[ix].name; ix++) { + + if(intprop[ix].get && !g_ascii_strcasecmp(intprop[ix].name, property_name)) { + + // Found it! + int value = intprop[ix].get(ipc3270_get_session(object)); + + debug("%s=%d",property_name,value); + + if(value > 0 || errno == 0) { + return g_variant_new_int16((gint16) value); + } + + // Erro! + ipc3270_set_error(object,errno,error); + return NULL; + + } + + } + + // String properties + const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list(); + for(ix = 0; strprop[ix].name; ix++) { + + if(strprop[ix].get && !g_ascii_strcasecmp(strprop[ix].name, property_name)) { + + // Found it! + const char * value = strprop[ix].get(ipc3270_get_session(object)); + + if(value) { + debug("%s=%s",property_name,value); + return g_variant_new_string(value); + } + + // Erro! + ipc3270_set_error(object,errno,error); + return NULL; + + } + + } + + // Check for toggle + LIB3270_TOGGLE toggle = lib3270_get_toggle_id(property_name); + if(toggle != (LIB3270_TOGGLE) -1) { + + // Is a Tn3270 toggle, get it! + return g_variant_new_boolean(lib3270_get_toggle( (ipc3270_get_session(object)), toggle) != 0); + + } + + return NULL; + +} + diff --git a/src/core/linux/dbus-definition.xml b/src/core/linux/dbus-definition.xml new file mode 100644 index 0000000..5de6d0c --- /dev/null +++ b/src/core/linux/dbus-definition.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/core/linux/gobject.c b/src/core/linux/gobject.c new file mode 100644 index 0000000..28b949f --- /dev/null +++ b/src/core/linux/gobject.c @@ -0,0 +1,351 @@ +/* + * "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/joprietoe/gdbus/blob/master/gdbus-example-server.c + * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#include "gobject.h" +#include +#include +#include + +#include +#include + +G_DEFINE_TYPE(ipc3270, ipc3270, G_TYPE_OBJECT) + +static void ipc3270_finalize(GObject *object) { + + ipc3270 * ipc = IPC3270(object); + + debug("%s",__FUNCTION__); + if(ipc->id) { + g_dbus_connection_unregister_object(ipc->connection,ipc->id); + } + + G_OBJECT_CLASS(ipc3270_parent_class)->finalize(object); +} + + +static void ipc3270_class_init(ipc3270Class *klass) { + + debug("%s",__FUNCTION__); + + GObjectClass *object_class; + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = ipc3270_finalize; + +} + +static void ipc3270_init(ipc3270 *object) { + + debug("%s",__FUNCTION__); + object->error_domain = g_quark_from_static_string(PACKAGE_NAME); + +} + +GObject * ipc3270_new() { + return g_object_new(GLIB_TYPE_IPC3270, NULL); +} + +static void + method_call ( + G_GNUC_UNUSED GDBusConnection *connection, + G_GNUC_UNUSED const gchar *sender, + G_GNUC_UNUSED const gchar *object_path, + G_GNUC_UNUSED const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) { + + g_autoptr (GError) error = NULL; + + GVariant * rc = ipc3270_method_call(G_OBJECT(user_data), method_name, parameters, &error); + + if(error) { + + if(rc) { + g_variant_unref(rc); + } + + g_dbus_method_invocation_return_gerror(invocation, error); + + } else if(rc) { + + g_dbus_method_invocation_return_value(invocation, rc); + + } else { + + g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Invalid or unexpected method call"); + + } + + +} + +static GVariant * + get_property ( + G_GNUC_UNUSED GDBusConnection *connection, + G_GNUC_UNUSED const gchar *sender, + G_GNUC_UNUSED const gchar *object_path, + G_GNUC_UNUSED const gchar *interface_name, + const gchar *property_name, + GError **error, + gpointer user_data) +{ + + return ipc3270_get_property(G_OBJECT(user_data), property_name, error); + +} + +static gboolean + set_property ( + G_GNUC_UNUSED GDBusConnection *connection, + G_GNUC_UNUSED const gchar *sender, + G_GNUC_UNUSED const gchar *object_path, + G_GNUC_UNUSED const gchar *interface_name, + const gchar *property_name, + GVariant *value, + GError **error, + gpointer user_data) +{ + + return ipc3270_set_property(G_OBJECT(user_data), property_name, value, error); + +} + + +void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error) { + + char id; + int ix; + + static const GDBusInterfaceVTable interface_vtable = { + method_call, + get_property, + set_property + }; + + ipc3270 * ipc = IPC3270(object); + ipc->hSession = hSession; + + ipc->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error); + if(*error) { + g_message("Can't get session bus: %s",(*error)->message); + return; + } + + g_dbus_connection_set_exit_on_close(ipc->connection,FALSE); + + for(id='a'; id < 'z' && !ipc->id && !*error; id++) { + + gchar *object_name = g_strdup_printf("br.com.bb.%s.%c",name,id); + + debug("Requesting \"%s\"",object_name); + + // https://dbus.freedesktop.org/doc/dbus-specification.html + GError *err = NULL; + + GVariant * response = + g_dbus_connection_call_sync ( + ipc->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "RequestName", + g_variant_new ("(su)", object_name, DBUS_NAME_FLAG_DO_NOT_QUEUE), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &err + ); + + if(err) { + g_message("Can't request \"%s\": %s",object_name,err->message); + g_error_free(err); + err = NULL; + } + + if(response) { + + guint32 reply = 0; + g_variant_get(response, "(u)", &reply); + g_variant_unref(response); + + if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + + g_message("Got %s", object_name); + + lib3270_set_session_id(ipc->hSession, id); + + // Introspection data for the service we are exporting + GString * introspection = g_string_new( + "\n" + " " + " " + " " + " " \ + " " + " " \ + " " \ + " " \ + " " + " " \ + " " \ + " " \ + " " + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " + + ); + + // Constrói métodos usando a tabela de controle + const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table(); + for(ix = 0; actions[ix].name; ix++) + { + g_string_append_printf( + introspection, \ + " " \ + " ", actions[ix].name + ); + } + + // Toggle properties + for(ix = 0; ix < (int) LIB3270_TOGGLE_COUNT; ix++) { + g_string_append_printf(introspection, " ", lib3270_get_toggle_name((LIB3270_TOGGLE) ix)); + } + + // Boolean properties + const LIB3270_INT_PROPERTY * bol_props = lib3270_get_boolean_properties_list(); + for(ix = 0; bol_props[ix].name; ix++) { + debug("Boolean(%s)",bol_props[ix].name); + g_string_append_printf(introspection, " ", + bol_props[ix].name, + ((bol_props[ix].set == NULL) ? "read" : "readwrite") + ); + } + + // Integer properties + const LIB3270_INT_PROPERTY * int_props = lib3270_get_int_properties_list(); + for(ix = 0; int_props[ix].name; ix++) { + g_string_append_printf(introspection, " ", + int_props[ix].name, + ((int_props[ix].set == NULL) ? "read" : "readwrite") + ); + } + + // String properties + const LIB3270_STRING_PROPERTY * str_props = lib3270_get_string_properties_list(); + for(ix = 0; str_props[ix].name; ix++) { + g_string_append_printf(introspection, " ", + str_props[ix].name, + ((str_props[ix].set == NULL) ? "read" : "readwrite") + ); + } + + g_string_append(introspection, + " " + "" + ); + + gchar * introspection_xml = g_string_free(introspection,FALSE); + + debug("\n%s\n",introspection_xml); + + GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); + + // Register object-id + ipc->id = g_dbus_connection_register_object ( + ipc->connection, + "/br/com/bb/tn3270", + introspection_data->interfaces[0], + &interface_vtable, + ipc, + NULL, + error + ); + + g_dbus_node_info_unref(introspection_data); + g_free(introspection_xml); + + break; + } + + } + + g_free(object_name); + + } + +} + +const gchar * ipc3270_get_display_charset(GObject *object) { + return lib3270_get_display_charset(IPC3270(object)->hSession); +} + +H3270 * ipc3270_get_session(GObject *object) { + return IPC3270(object)->hSession; +} + +void ipc3270_set_error(GObject *object, int errcode, GError **error) { + g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode)); +} diff --git a/src/core/linux/gobject.h b/src/core/linux/gobject.h new file mode 100644 index 0000000..0241533 --- /dev/null +++ b/src/core/linux/gobject.h @@ -0,0 +1,77 @@ +/* + * "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) + * + */ + + /** + * @brief Private definitions for pw3270 IPC linux module. + * + */ + +#ifndef LINUX_GOBJECT_H_INCLUDED + + #define LINUX_GOBJECT_H_INCLUDED + + #include + + #define ENABLE_NLS + #define GETTEXT_PACKAGE PACKAGE_NAME + + #include + #include + #include + + #include + #include + + G_BEGIN_DECLS + + typedef struct _ipc3270 ipc3270; + typedef struct _ipc3270Class ipc3270Class; + + struct _ipc3270 { + GObject parent; + GDBusConnection * connection; + guint id; + H3270 * hSession; + GQuark error_domain; + }; + + struct _ipc3270Class { + GObjectClass parent; + }; + + /* + G_GNUC_INTERNAL void ipc3270_method_call (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data); + G_GNUC_INTERNAL gboolean ipc3270_set_property(GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GVariant *value, GError **error, gpointer user_data); + G_GNUC_INTERNAL GVariant * ipc3270_get_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data); + */ + + G_END_DECLS + +#endif // LINUX_GOBJECT_H_INCLUDED diff --git a/src/core/linux/start.c.1 b/src/core/linux/start.c.1 new file mode 100644 index 0000000..afddf4a --- /dev/null +++ b/src/core/linux/start.c.1 @@ -0,0 +1,191 @@ +/* + * "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 Plugin startup/stop for linux. + * + */ + + #include "private.h" + + #include + #include + + static void pw3270_dbus_cleanup(struct DBusSession * dBus) { + + if(dBus->proxy) { + g_object_unref(dBus); + } + + } + + int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) { + + struct DBusSession * dBus = g_new0(struct DBusSession,1); + GError * error = NULL; + int id; + + g_object_set_data_full(G_OBJECT(terminal), "dbus-session-info", dBus, (GDestroyNotify) pw3270_dbus_cleanup); + + dBus->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); + + if(error) { + GtkWidget *dialog = gtk_message_dialog_new( + GTK_WINDOW(window), + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + _( "Can't get D-Bus connection" )); + + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); + g_error_free(error); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + return -1; + } + + g_dbus_connection_set_exit_on_close(dBus->connection,FALSE); + + /* + dBus->proxy = g_dbus_proxy_new_sync( + dBus->connection, + G_DBUS_PROXY_FLAGS_NONE, + NULL, // GDBusInterfaceInfo + "br.com.bb." PACKAGE_NAME, // name + "/br/com/bb/" PACKAGE_NAME "/terminal", // object path + "br.com.bb." PACKAGE_NAME ".terminal", // interface + NULL, // GCancellable + &error ); + + if(error) { + + GtkWidget *dialog = gtk_message_dialog_new( + GTK_WINDOW(window), + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + _( "Can't get D-Bus proxy object" )); + + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); + g_error_free(error); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + return -1; + } + */ + + for(id='a'; id < 'z' && !error && !dBus->proxy; id++) { + + gchar *name = g_strdup_printf("br.com.bb.%s.%c",gtk_widget_get_name(window),id); + + debug("Requesting \"%s\"",name); + + // https://dbus.freedesktop.org/doc/dbus-specification.html + GVariant * response = + g_dbus_connection_call_sync ( + dBus->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "RequestName", + g_variant_new ("(su)", name, DBUS_NAME_FLAG_DO_NOT_QUEUE), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error + ); + + if(error) { + g_message("Can't request \"%s\": %s",name,error->message); + g_error_free(error); + error = NULL; + } + + if(response) { + + guint32 reply = 0; + g_variant_get(response, "(u)", &reply); + g_variant_unref(response); + + if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + + dBus->proxy = g_dbus_proxy_new_sync( + dBus->connection, + G_DBUS_PROXY_FLAGS_NONE, + NULL, // GDBusInterfaceInfo + name, // name + "/br/com/bb/" PACKAGE_NAME "/terminal", // object path + "br.com.bb." PACKAGE_NAME ".terminal", // interface + NULL, // GCancellable + &error ); + + gchar * widget_name = g_strdup_printf("%s:%c",gtk_widget_get_name(window),id); + v3270_set_session_name(terminal, widget_name); + g_free(widget_name); + + g_message("Got %s - %s", name, v3270_get_session_name(terminal)); + + } + + } + + g_free(name); + + } + + if(!dBus->proxy) { + GtkWidget *dialog = gtk_message_dialog_new( + GTK_WINDOW(window), + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + _( "Can't get DBUS object name" )); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + return -1; + } + + // Got D-Bus name, register object. + + return 0; + + } + + #endif // !_WIN32 + + diff --git a/src/core/methods.c b/src/core/methods.c new file mode 100644 index 0000000..39ccc83 --- /dev/null +++ b/src/core/methods.c @@ -0,0 +1,172 @@ +/* + * "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/joprietoe/gdbus/blob/master/gdbus-example-server.c + * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.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 + +GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error) { + + size_t ix; + + debug("%s(%s)",__FUNCTION__,method_name); + + if(!g_ascii_strcasecmp(method_name,"getString")) + { + return ipc3270_GVariant_from_input_string(object, lib3270_get_string_at_address(ipc3270_get_session(object),0,-1,'\n'), error); + } + else if(!g_ascii_strcasecmp(method_name,"setString")) + { + gchar *text = NULL; + g_variant_get(parameters, "(&s)", &text); + + g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error); + if(lib3270_input_string(ipc3270_get_session(object),(const unsigned char *) converted) < 0) + { + // Failed! + ipc3270_set_error(object,errno,error); + return NULL; + } + + // Suceeded + return g_variant_new_int16((gint16) 0); + + } + else if(!g_ascii_strcasecmp(method_name,"setStringAt")) + { + gint row,col; + gchar *text = NULL; + g_variant_get(parameters, "(ii&s)", &row, &col, &text); + + g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error); + if(lib3270_set_string_at(ipc3270_get_session(object),row,col,(const unsigned char *) converted) < 0) + { + // Failed! + ipc3270_set_error(object,errno,error); + return NULL; + } + + // Suceeded + return g_variant_new_int16((gint16) 0); + + } + else if(!g_ascii_strcasecmp(method_name,"getStringAt")) + { + gint row,col,len; + guchar lf; + g_variant_get(parameters, "(iiy)", &row, &col, &len,&lf); + + return ipc3270_GVariant_from_input_string(object,lib3270_get_string_at(ipc3270_get_session(object), row, col, len, lf),error); + + } + else if(!g_ascii_strcasecmp(method_name,"setStringAtAddress")) + { + gint addr; + gchar *text = NULL; + g_variant_get(parameters, "(i&s)", &addr, &text); + + g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error); + if(lib3270_set_string_at_address(ipc3270_get_session(object),addr,(unsigned char *) converted) < 0) + { + // Failed! + ipc3270_set_error(object,errno,error); + return NULL; + } + + // Suceeded + return g_variant_new_int16((gint16) 0); + + } + else if(!g_ascii_strcasecmp(method_name,"getStringAtAddress")) + { + gint addr,len; + guchar lf; + g_variant_get(parameters, "(iiy)", &addr, &len, &lf); + + return ipc3270_GVariant_from_input_string(object,lib3270_get_string_at_address(ipc3270_get_session(object), addr, len, lf),error); + + } + // Check action table. + const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table(); + for(ix = 0; actions[ix].name; ix++) + { + if(!g_ascii_strcasecmp(actions[ix].name,method_name)) { + + int rc = actions[ix].call(ipc3270_get_session(object)); + if(rc) + { + // Failed + ipc3270_set_error(object,errno,error); + return NULL; + } + + // Suceeded + return g_variant_new_int16((gint16) 0); + + } + } + + // Check int methods + const IPC_METHOD_INT_ARG * int_methods = ipc3270_get_int_arg_methods(); + + for(ix = 0; int_methods[ix].name; ix++) + { + if(!g_ascii_strcasecmp(int_methods[ix].name,method_name)) { + + gint value; + g_variant_get(parameters, "(i)", &value); + + int rc = int_methods[ix].call(ipc3270_get_session(object), value); + if(rc) + { + // Failed + ipc3270_set_error(object,errno,error); + return NULL; + } + + // Suceeded + return g_variant_new_int16((gint16) 0); + + } + + } + + return NULL; + +} diff --git a/src/core/setproperties.c b/src/core/setproperties.c new file mode 100644 index 0000000..551e574 --- /dev/null +++ b/src/core/setproperties.c @@ -0,0 +1,151 @@ +/* + * "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/joprietoe/gdbus/blob/master/gdbus-example-server.c + * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.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 + +gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error) { + + // Check for property + size_t ix; + + // Boolean properties + const LIB3270_INT_PROPERTY * boolprop = lib3270_get_boolean_properties_list(); + for(ix = 0; boolprop[ix].name; ix++) { + + if(boolprop[ix].set && !g_ascii_strcasecmp(boolprop[ix].name, property_name)) { + + // Found it! + if(boolprop[ix].set(ipc3270_get_session(object), (int) (g_variant_get_boolean(value) ? 1 : 0))) { + + // Erro! + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_FAILED, + g_strerror(errno) + ); + + return FALSE; + } + + return TRUE; + + } + + } + + // Integer properties + const LIB3270_INT_PROPERTY * intprop = lib3270_get_int_properties_list(); + for(ix = 0; intprop[ix].name; ix++) { + + if(intprop[ix].set && !g_ascii_strcasecmp(intprop[ix].name, property_name)) { + + // Found it! + if(intprop[ix].set(ipc3270_get_session(object), (int) (g_variant_get_boolean(value) ? 1 : 0))) { + + // Erro! + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_FAILED, + g_strerror(errno) + ); + + return FALSE; + } + + return TRUE; + + } + + } + + // String properties + const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list(); + for(ix = 0; strprop[ix].name; ix++) { + + if(strprop[ix].set && !g_ascii_strcasecmp(strprop[ix].name, property_name)) { + + // Found it! + if(strprop[ix].set(ipc3270_get_session(object), g_variant_get_string(value,NULL))) { + + // Erro! + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_FAILED, + g_strerror(errno) + ); + + return FALSE; + } + + return TRUE; + + } + + } + + // Check for toggle + LIB3270_TOGGLE toggle = lib3270_get_toggle_id(property_name); + if(toggle != (LIB3270_TOGGLE) -1) { + + // Is a Tn3270 toggle, get it! + if(lib3270_set_toggle(ipc3270_get_session(object),toggle,(int) g_variant_get_int32(value))) { + + // Erro! + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_FAILED, + g_strerror(errno) + ); + + return FALSE; + + } + + return TRUE; + } + + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_NOT_FOUND, + "Can't find any property named %s", property_name + ); + + return FALSE; +} diff --git a/src/core/windows/gobject.c b/src/core/windows/gobject.c new file mode 100644 index 0000000..dd23ed3 --- /dev/null +++ b/src/core/windows/gobject.c @@ -0,0 +1,132 @@ +/* + * "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) + * + */ + +#include "gobject.h" +#include +#include +#include + +G_DEFINE_TYPE(ipc3270, ipc3270, G_TYPE_OBJECT) + +static void ipc3270_finalize(GObject *object) { + + ipc3270 * ipc = IPC3270(object); + + + G_OBJECT_CLASS(ipc3270_parent_class)->finalize(object); +} + + +static void ipc3270_class_init(ipc3270Class *klass) { + + debug("%s",__FUNCTION__); + + GObjectClass *object_class; + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = ipc3270_finalize; + +} + +static void ipc3270_init(ipc3270 *object) { + + debug("%s",__FUNCTION__); + object->error_domain = g_quark_from_static_string(PACKAGE_NAME); + +} + +GObject * ipc3270_new() { + return g_object_new(GLIB_TYPE_IPC3270, NULL); +} + +void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error) { + + char id; + + ipc3270 * ipc = IPC3270(object); + ipc->hSession = hSession; + + 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 + + debug("%s = %p",pipename,hPipe); + g_free(pipename); + + if(hPipe != INVALID_HANDLE_VALUE) { + + ipc->source = (IPC3270_PIPE_SOURCE *) g_source_new(&ipc3270_source_funcs,sizeof(IPC3270_PIPE_SOURCE)); + + lib3270_set_session_id(ipc->hSession, id); + + ipc->source->hPipe = hPipe; + ipc->source->state = PIPE_STATE_WAITING; + ipc->source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL); + + g_source_attach((GSource *) ipc->source,NULL); + + // IO_accept(source); + ipc3270_wait_for_client(ipc->source); + + break; + } + + } + + +} + +const gchar * ipc3270_get_display_charset(GObject *object) { + return lib3270_get_display_charset(IPC3270(object)->hSession); +} + +H3270 * ipc3270_get_session(GObject *object) { + return IPC3270(object)->hSession; +} + +void ipc3270_set_error(GObject *object, int errcode, GError **error) { + g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode)); +} + diff --git a/src/core/windows/gobject.h b/src/core/windows/gobject.h new file mode 100644 index 0000000..8ef2598 --- /dev/null +++ b/src/core/windows/gobject.h @@ -0,0 +1,95 @@ +/* + * "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) + * + */ + + /** + * @brief Private definitions for pw3270 IPC windows module. + * + */ + +#ifndef WINDOWS_GOBJECT_H_INCLUDED + + #define WINDOWS_GOBJECT_H_INCLUDED + + #include + #include + + #define ENABLE_NLS + #define GETTEXT_PACKAGE PACKAGE_NAME + + #include + #include + #include + + #include + #include + + #define PIPE_BUFFER_LENGTH 8192 + + G_BEGIN_DECLS + + typedef struct _ipc3270 ipc3270; + typedef struct _ipc3270Class ipc3270Class; + typedef struct _ipc3270Request ipc3270Request; + + typedef enum _ipc3270_pipe_state { + PIPE_STATE_WAITING, + PIPE_STATE_READ, + PIPE_STATE_PENDING_READ, + PIPE_STATE_UNDEFINED + } IPC3270_PIPE_STATE; + + typedef struct _ipc3270_pipe_source { + GSource gsrc; + HANDLE hPipe; + + IPC3270_PIPE_STATE state; + + OVERLAPPED overlap; + unsigned char buffer[PIPE_BUFFER_LENGTH+1]; + + } IPC3270_PIPE_SOURCE; + + struct _ipc3270 { + H3270 * hSession; + IPC3270_PIPE_SOURCE * source; + GQuark error_domain; + }; + + struct _ipc3270Class { + GObjectClass parent; + }; + + G_GNUC_INTERNAL GSourceFuncs ipc3270_source_funcs; + + G_GNUC_INTERNAL void ipc3270_wait_for_client(IPC3270_PIPE_SOURCE *source); + + G_END_DECLS + +#endif // WINDOWS_GOBJECT_H_INCLUDED diff --git a/src/core/windows/inout.c b/src/core/windows/inout.c new file mode 100644 index 0000000..7edbd71 --- /dev/null +++ b/src/core/windows/inout.c @@ -0,0 +1,295 @@ +/* + * "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 inout.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 Pack/Unpack IPC data block. + * + */ + + #include + #include + #include + #include + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + +unsigned char * ipc3270_pack(const gchar * name, int id, GVariant *values, size_t * szPacket) { + + GVariantIter iter; + gsize count = g_variant_iter_init(&iter, values); + g_autofree char * types = g_new0(char, count); + GVariant * child; + size_t ix = 0; + + // Init packet size; + *szPacket = strlen(name) + 1 + (sizeof(guint16) * 2) ; + + g_print("Packaging %u itens for \"%s\"\n", (unsigned int) count, name); + while ((child = g_variant_iter_next_value (&iter))) { + + // g_print("type='%s' size=%u\n", g_variant_get_type_string(child), (unsigned int) g_variant_get_size(child)); + + types[ix] = g_variant_get_type_string(child)[0]; + *szPacket += (1+g_variant_get_size(child)); + + g_variant_unref(child); + ix++; + } + + // Allocate buffer + unsigned char * outputBuffer = g_malloc0(*szPacket); + unsigned char * txtptr = outputBuffer; + + // Add name + strcpy((char *) txtptr,name); + txtptr += strlen((char *) txtptr) + 1; + + // Add ID + *((guint16 *) txtptr) = (guint16) id; + txtptr += sizeof(guint16); + + // Update ptr; + *((guint16 *) txtptr) = (guint16) count; + txtptr += sizeof(guint16); + + ix = 0; + g_variant_iter_init(&iter, values); + while ((child = g_variant_iter_next_value (&iter))) { + + debug("type='%s' size=%u index=%u", g_variant_get_type_string(child), (unsigned int) g_variant_get_size(child), (unsigned int) (txtptr - outputBuffer)); + + *(txtptr++) = types[ix]; + + switch(types[ix]) { + + // https://developer.gnome.org/glib/stable/gvariant-format-strings.html + + case 's': + strcpy((char *) txtptr,g_variant_get_string(child,NULL)); + txtptr += (strlen((char *) txtptr)+1); + break; + + case 'b': // gboolean + *(txtptr++) = g_variant_get_boolean(child) ? 1 : 0; + break; + + case 'y': // guchar + *(txtptr++) = g_variant_get_byte(child); + break; + + case 'n': // gint16 + *((gint16 *) txtptr) = g_variant_get_int16(child); + txtptr += sizeof(gint16); + break; + + case 'q': // guint16 + *((guint16 *) txtptr) = g_variant_get_uint16(child); + txtptr += sizeof(guint16); + break; + + case 'i': // gint32 + case 'h': // gint32 + *((gint32 *) txtptr) = g_variant_get_int32(child); + txtptr += sizeof(gint32); + break; + + case 'u': // guint32 + *((guint32 *) txtptr) = g_variant_get_uint32(child); + txtptr += sizeof(guint32); + break; + + case 'x': // gint64 + *((gint64 *) txtptr) = g_variant_get_int64(child); + txtptr += sizeof(gint64); + break; + + case 't': // guint64 + *((guint64 *) txtptr) = g_variant_get_uint64(child); + txtptr += sizeof(guint64); + break; + + default: + errno = EINVAL; + g_free(outputBuffer); + return NULL; + } + + g_variant_unref(child); + ix++; + } + + return outputBuffer; +} + +GVariant * ipc3270_unpack(const unsigned char *packet, int *id) { + + const unsigned char *txtptr; + size_t ix; + + // Skip packet name. + packet += strlen((const char *) packet)+1; + + // Get Packet ID or error code. + if(id) { + *id = (int) *((guint16 *) packet); + } + packet += sizeof(guint16); + + // Get argument count. + size_t arguments = (size_t) * ((guint16 *) packet); + packet += sizeof(guint16); + + debug("Unpacking package with %u itens", (unsigned int) arguments); + + // Scan for argument types. + g_autofree gchar * descrs = g_malloc0(arguments+3); + descrs[0] = '('; + descrs[arguments+1] = ')'; + + txtptr = packet; + for(ix = 0; ix < arguments; ix++) { + + debug("Format(%u): %c",(unsigned int) ix, *txtptr); + + descrs[ix+1] = *(txtptr++); + + switch(descrs[ix+1]) { + case 's': + txtptr += strlen((char *) txtptr)+1; + break; + + case 'b': // gboolean + case 'y': // guchar + txtptr++; + break; + + case 'n': // gint16 + txtptr += sizeof(gint16); + break; + + case 'q': // guint16 + txtptr += sizeof(guint16); + break; + + case 'i': // gint32 + case 'h': // gint32 + txtptr += sizeof(gint32); + break; + + case 'u': // guint32 + txtptr += sizeof(guint32); + break; + + case 'x': // gint64 + txtptr += sizeof(gint64); + break; + + case 't': // guint64 + txtptr += sizeof(guint64); + break; + + default: + errno = EINVAL; + return NULL; + } + } + + debug("Format: \"%s\"\n",descrs); + + GVariantBuilder builder; + g_variant_builder_init(&builder,G_VARIANT_TYPE(descrs)); + + txtptr = packet; + for(ix = 0; ix < arguments; ix++) { + + debug("Format(%u): %c",(unsigned int) ix, *txtptr); + txtptr++; + + switch(descrs[ix+1]) { + case 's': + g_variant_builder_add(&builder, "s", txtptr); + txtptr += strlen((char *) txtptr)+1; + break; + + case 'b': // gboolean + g_variant_builder_add(&builder, "b", *((gboolean *) txtptr)); + txtptr++; + break; + + case 'y': // guchar + g_variant_builder_add(&builder, "y", *((guchar *) txtptr)); + txtptr++; + break; + + case 'n': // gint16 + g_variant_builder_add(&builder, "n", *((gint16 *) txtptr)); + txtptr += sizeof(gint16); + break; + + case 'q': // guint16 + g_variant_builder_add(&builder, "q", *((guint16 *) txtptr)); + txtptr += sizeof(guint16); + break; + + case 'i': // gint32 + g_variant_builder_add(&builder, "i", *((gint32 *) txtptr)); + txtptr += sizeof(gint32); + break; + + case 'h': // gint32 + g_variant_builder_add(&builder, "h", *((gint32 *) txtptr)); + txtptr += sizeof(gint32); + break; + + case 'u': // guint32 + g_variant_builder_add(&builder, "u", *((guint32 *) txtptr)); + txtptr += sizeof(guint32); + break; + + case 'x': // gint64 + g_variant_builder_add(&builder, "x", *((gint64 *) txtptr)); + txtptr += sizeof(gint64); + break; + + case 't': // guint64 + g_variant_builder_add(&builder, "t", *((guint64 *) txtptr)); + txtptr += sizeof(guint64); + break; + + default: + errno = EINVAL; + return NULL; + } + } + + return g_variant_builder_end(&builder); + +} diff --git a/src/core/windows/pipesource.c b/src/core/windows/pipesource.c new file mode 100644 index 0000000..4434ac0 --- /dev/null +++ b/src/core/windows/pipesource.c @@ -0,0 +1,214 @@ +/* + * "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 pipesource.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#include "gobject.h" + +void ipc3270_wait_for_client(IPC3270_PIPE_SOURCE *source) { + + if(ConnectNamedPipe(source->hPipe,&source->overlap)) { + g_message("Error %u in ConnectNamedPipe",(unsigned int) GetLastError()); + // popup_lasterror("%s",_( "Error in ConnectNamedPipe" )); + return; + } + + switch(GetLastError()) { + case ERROR_IO_PENDING: // The overlapped connection in progress. + source->state = PIPE_STATE_WAITING; + break; + + + case ERROR_PIPE_CONNECTED: // Client is already connected, so signal an event. + if(SetEvent(source->overlap.hEvent)) + break; + + default: + g_message("Error %u in ConnectNamedPipe",(unsigned int) GetLastError()); + // 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(((IPC3270_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(((IPC3270_PIPE_SOURCE *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) + return TRUE; + + return FALSE; +} + +static void process_input(IPC3270_PIPE_SOURCE *source, DWORD cbRead) { + +} + +static void read_input_pipe(IPC3270_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: + source->state = PIPE_STATE_PENDING_READ; + break; + + case ERROR_PIPE_LISTENING: + source->state = PIPE_STATE_READ; + break; + + case ERROR_BROKEN_PIPE: + + if(!DisconnectNamedPipe(source->hPipe)) { + + g_message("Error %u on DisconnectNamedPipe", (unsigned int) GetLastError()); + + } else { + + ipc3270_wait_for_client(source); + + } + break; + + case ERROR_PIPE_NOT_CONNECTED: + g_message("Cliente was disconnected"); + break; + + default: + if(source->hPipe != INVALID_HANDLE_VALUE) { + g_message( "Error %u receiving message from pipe", (unsigned int) GetLastError()); + } + } + +} + + +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer data) { + /* + * Called to dispatch the event source, + * after it has returned TRUE in either its prepare or its check function. + * The dispatch function is passed in a callback function and data. + * The callback function may be NULL if the source was never connected + * to a callback using g_source_set_callback(). The dispatch function + * should call the callback function with user_data and whatever additional + * parameters are needed for this type of event source. + */ + BOOL fSuccess; + DWORD cbRead = 0; + + fSuccess = GetOverlappedResult(((IPC3270_PIPE_SOURCE *) source)->hPipe,&((IPC3270_PIPE_SOURCE *) source)->overlap,&cbRead,FALSE ); + + switch(((IPC3270_PIPE_SOURCE *) source)->state) { + case PIPE_STATE_WAITING: + + if(fSuccess) { + + g_message("Client is connected"); + ((IPC3270_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( (IPC3270_PIPE_SOURCE *) source); + break; + + case PIPE_STATE_PENDING_READ: + if(fSuccess && cbRead > 0) + process_input((IPC3270_PIPE_SOURCE *) source,cbRead); + ((IPC3270_PIPE_SOURCE *) source)->state = PIPE_STATE_READ; + break; + + case PIPE_STATE_UNDEFINED: + break; + + } + + return TRUE; +} + +static gboolean IO_closure(gpointer data) { + return 0; +} + +static void IO_finalize(GSource *source) { + + if( ((IPC3270_PIPE_SOURCE *) source)->hPipe != INVALID_HANDLE_VALUE) { + CloseHandle(((IPC3270_PIPE_SOURCE *) source)->hPipe); + ((IPC3270_PIPE_SOURCE *) source)->hPipe = INVALID_HANDLE_VALUE; + } + +} + +GSourceFuncs ipc3270_source_funcs = { + IO_prepare, + IO_check, + IO_dispatch, + IO_finalize, + IO_closure, + NULL +}; diff --git a/src/core/windows/resources.rc.in b/src/core/windows/resources.rc.in new file mode 100644 index 0000000..2ca7c88 --- /dev/null +++ b/src/core/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_DESCRIPTION@\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", "@PACKAGE_TARNAME@@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/getproperties.c b/src/getproperties.c deleted file mode 100644 index 4e33b3d..0000000 --- a/src/getproperties.c +++ /dev/null @@ -1,128 +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/joprietoe/gdbus/blob/master/gdbus-example-server.c - * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.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 - -GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error) { - - size_t ix; - errno = 0; // Just in case. - - // Boolean properties - const LIB3270_INT_PROPERTY * boolprop = lib3270_get_boolean_properties_list(); - for(ix = 0; boolprop[ix].name; ix++) { - - if(boolprop[ix].get && !g_ascii_strcasecmp(boolprop[ix].name, property_name)) { - - // Found it! - int value = boolprop[ix].get(ipc3270_get_session(object)); - - debug("%s=%d",property_name,value); - - if(value > 0 || errno == 0) { - return g_variant_new_boolean(value != 0); - } - - // Erro! - ipc3270_set_error(object,ENOENT,error); - return NULL; - - } - - } - - // int properties - const LIB3270_INT_PROPERTY * intprop = lib3270_get_int_properties_list(); - for(ix = 0; intprop[ix].name; ix++) { - - if(intprop[ix].get && !g_ascii_strcasecmp(intprop[ix].name, property_name)) { - - // Found it! - int value = intprop[ix].get(ipc3270_get_session(object)); - - debug("%s=%d",property_name,value); - - if(value > 0 || errno == 0) { - return g_variant_new_int16((gint16) value); - } - - // Erro! - ipc3270_set_error(object,errno,error); - return NULL; - - } - - } - - // String properties - const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list(); - for(ix = 0; strprop[ix].name; ix++) { - - if(strprop[ix].get && !g_ascii_strcasecmp(strprop[ix].name, property_name)) { - - // Found it! - const char * value = strprop[ix].get(ipc3270_get_session(object)); - - if(value) { - debug("%s=%s",property_name,value); - return g_variant_new_string(value); - } - - // Erro! - ipc3270_set_error(object,errno,error); - return NULL; - - } - - } - - // Check for toggle - LIB3270_TOGGLE toggle = lib3270_get_toggle_id(property_name); - if(toggle != (LIB3270_TOGGLE) -1) { - - // Is a Tn3270 toggle, get it! - return g_variant_new_boolean(lib3270_get_toggle( (ipc3270_get_session(object)), toggle) != 0); - - } - - return NULL; - -} - diff --git a/src/include/lib3270/ipc.h b/src/include/lib3270/ipc.h index 7f8f9ff..5dc935f 100644 --- a/src/include/lib3270/ipc.h +++ b/src/include/lib3270/ipc.h @@ -69,6 +69,10 @@ gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error); GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error); + // TODO: Move for windows private.h + unsigned char * ipc3270_pack(const gchar *name, int id, GVariant *values, size_t * szPacket); + GVariant * ipc3270_unpack(const unsigned char *packet, int *id); + G_END_DECLS #ifdef DEBUG diff --git a/src/linux/dbus-definition.xml b/src/linux/dbus-definition.xml deleted file mode 100644 index 5de6d0c..0000000 --- a/src/linux/dbus-definition.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/src/linux/gobject.c b/src/linux/gobject.c deleted file mode 100644 index 28b949f..0000000 --- a/src/linux/gobject.c +++ /dev/null @@ -1,351 +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/joprietoe/gdbus/blob/master/gdbus-example-server.c - * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - -#include "gobject.h" -#include -#include -#include - -#include -#include - -G_DEFINE_TYPE(ipc3270, ipc3270, G_TYPE_OBJECT) - -static void ipc3270_finalize(GObject *object) { - - ipc3270 * ipc = IPC3270(object); - - debug("%s",__FUNCTION__); - if(ipc->id) { - g_dbus_connection_unregister_object(ipc->connection,ipc->id); - } - - G_OBJECT_CLASS(ipc3270_parent_class)->finalize(object); -} - - -static void ipc3270_class_init(ipc3270Class *klass) { - - debug("%s",__FUNCTION__); - - GObjectClass *object_class; - object_class = G_OBJECT_CLASS (klass); - object_class->finalize = ipc3270_finalize; - -} - -static void ipc3270_init(ipc3270 *object) { - - debug("%s",__FUNCTION__); - object->error_domain = g_quark_from_static_string(PACKAGE_NAME); - -} - -GObject * ipc3270_new() { - return g_object_new(GLIB_TYPE_IPC3270, NULL); -} - -static void - method_call ( - G_GNUC_UNUSED GDBusConnection *connection, - G_GNUC_UNUSED const gchar *sender, - G_GNUC_UNUSED const gchar *object_path, - G_GNUC_UNUSED const gchar *interface_name, - const gchar *method_name, - GVariant *parameters, - GDBusMethodInvocation *invocation, - gpointer user_data) { - - g_autoptr (GError) error = NULL; - - GVariant * rc = ipc3270_method_call(G_OBJECT(user_data), method_name, parameters, &error); - - if(error) { - - if(rc) { - g_variant_unref(rc); - } - - g_dbus_method_invocation_return_gerror(invocation, error); - - } else if(rc) { - - g_dbus_method_invocation_return_value(invocation, rc); - - } else { - - g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Invalid or unexpected method call"); - - } - - -} - -static GVariant * - get_property ( - G_GNUC_UNUSED GDBusConnection *connection, - G_GNUC_UNUSED const gchar *sender, - G_GNUC_UNUSED const gchar *object_path, - G_GNUC_UNUSED const gchar *interface_name, - const gchar *property_name, - GError **error, - gpointer user_data) -{ - - return ipc3270_get_property(G_OBJECT(user_data), property_name, error); - -} - -static gboolean - set_property ( - G_GNUC_UNUSED GDBusConnection *connection, - G_GNUC_UNUSED const gchar *sender, - G_GNUC_UNUSED const gchar *object_path, - G_GNUC_UNUSED const gchar *interface_name, - const gchar *property_name, - GVariant *value, - GError **error, - gpointer user_data) -{ - - return ipc3270_set_property(G_OBJECT(user_data), property_name, value, error); - -} - - -void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error) { - - char id; - int ix; - - static const GDBusInterfaceVTable interface_vtable = { - method_call, - get_property, - set_property - }; - - ipc3270 * ipc = IPC3270(object); - ipc->hSession = hSession; - - ipc->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error); - if(*error) { - g_message("Can't get session bus: %s",(*error)->message); - return; - } - - g_dbus_connection_set_exit_on_close(ipc->connection,FALSE); - - for(id='a'; id < 'z' && !ipc->id && !*error; id++) { - - gchar *object_name = g_strdup_printf("br.com.bb.%s.%c",name,id); - - debug("Requesting \"%s\"",object_name); - - // https://dbus.freedesktop.org/doc/dbus-specification.html - GError *err = NULL; - - GVariant * response = - g_dbus_connection_call_sync ( - ipc->connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "RequestName", - g_variant_new ("(su)", object_name, DBUS_NAME_FLAG_DO_NOT_QUEUE), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &err - ); - - if(err) { - g_message("Can't request \"%s\": %s",object_name,err->message); - g_error_free(err); - err = NULL; - } - - if(response) { - - guint32 reply = 0; - g_variant_get(response, "(u)", &reply); - g_variant_unref(response); - - if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - - g_message("Got %s", object_name); - - lib3270_set_session_id(ipc->hSession, id); - - // Introspection data for the service we are exporting - GString * introspection = g_string_new( - "\n" - " " - " " - " " - " " \ - " " - " " \ - " " \ - " " \ - " " - " " \ - " " \ - " " \ - " " - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " \ - " " - - ); - - // Constrói métodos usando a tabela de controle - const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table(); - for(ix = 0; actions[ix].name; ix++) - { - g_string_append_printf( - introspection, \ - " " \ - " ", actions[ix].name - ); - } - - // Toggle properties - for(ix = 0; ix < (int) LIB3270_TOGGLE_COUNT; ix++) { - g_string_append_printf(introspection, " ", lib3270_get_toggle_name((LIB3270_TOGGLE) ix)); - } - - // Boolean properties - const LIB3270_INT_PROPERTY * bol_props = lib3270_get_boolean_properties_list(); - for(ix = 0; bol_props[ix].name; ix++) { - debug("Boolean(%s)",bol_props[ix].name); - g_string_append_printf(introspection, " ", - bol_props[ix].name, - ((bol_props[ix].set == NULL) ? "read" : "readwrite") - ); - } - - // Integer properties - const LIB3270_INT_PROPERTY * int_props = lib3270_get_int_properties_list(); - for(ix = 0; int_props[ix].name; ix++) { - g_string_append_printf(introspection, " ", - int_props[ix].name, - ((int_props[ix].set == NULL) ? "read" : "readwrite") - ); - } - - // String properties - const LIB3270_STRING_PROPERTY * str_props = lib3270_get_string_properties_list(); - for(ix = 0; str_props[ix].name; ix++) { - g_string_append_printf(introspection, " ", - str_props[ix].name, - ((str_props[ix].set == NULL) ? "read" : "readwrite") - ); - } - - g_string_append(introspection, - " " - "" - ); - - gchar * introspection_xml = g_string_free(introspection,FALSE); - - debug("\n%s\n",introspection_xml); - - GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); - - // Register object-id - ipc->id = g_dbus_connection_register_object ( - ipc->connection, - "/br/com/bb/tn3270", - introspection_data->interfaces[0], - &interface_vtable, - ipc, - NULL, - error - ); - - g_dbus_node_info_unref(introspection_data); - g_free(introspection_xml); - - break; - } - - } - - g_free(object_name); - - } - -} - -const gchar * ipc3270_get_display_charset(GObject *object) { - return lib3270_get_display_charset(IPC3270(object)->hSession); -} - -H3270 * ipc3270_get_session(GObject *object) { - return IPC3270(object)->hSession; -} - -void ipc3270_set_error(GObject *object, int errcode, GError **error) { - g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode)); -} diff --git a/src/linux/gobject.h b/src/linux/gobject.h deleted file mode 100644 index 0241533..0000000 --- a/src/linux/gobject.h +++ /dev/null @@ -1,77 +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) - * - */ - - /** - * @brief Private definitions for pw3270 IPC linux module. - * - */ - -#ifndef LINUX_GOBJECT_H_INCLUDED - - #define LINUX_GOBJECT_H_INCLUDED - - #include - - #define ENABLE_NLS - #define GETTEXT_PACKAGE PACKAGE_NAME - - #include - #include - #include - - #include - #include - - G_BEGIN_DECLS - - typedef struct _ipc3270 ipc3270; - typedef struct _ipc3270Class ipc3270Class; - - struct _ipc3270 { - GObject parent; - GDBusConnection * connection; - guint id; - H3270 * hSession; - GQuark error_domain; - }; - - struct _ipc3270Class { - GObjectClass parent; - }; - - /* - G_GNUC_INTERNAL void ipc3270_method_call (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data); - G_GNUC_INTERNAL gboolean ipc3270_set_property(GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GVariant *value, GError **error, gpointer user_data); - G_GNUC_INTERNAL GVariant * ipc3270_get_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data); - */ - - G_END_DECLS - -#endif // LINUX_GOBJECT_H_INCLUDED diff --git a/src/linux/start.c.1 b/src/linux/start.c.1 deleted file mode 100644 index afddf4a..0000000 --- a/src/linux/start.c.1 +++ /dev/null @@ -1,191 +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 Plugin startup/stop for linux. - * - */ - - #include "private.h" - - #include - #include - - static void pw3270_dbus_cleanup(struct DBusSession * dBus) { - - if(dBus->proxy) { - g_object_unref(dBus); - } - - } - - int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) { - - struct DBusSession * dBus = g_new0(struct DBusSession,1); - GError * error = NULL; - int id; - - g_object_set_data_full(G_OBJECT(terminal), "dbus-session-info", dBus, (GDestroyNotify) pw3270_dbus_cleanup); - - dBus->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); - - if(error) { - GtkWidget *dialog = gtk_message_dialog_new( - GTK_WINDOW(window), - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _( "Can't get D-Bus connection" )); - - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); - g_error_free(error); - - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - return -1; - } - - g_dbus_connection_set_exit_on_close(dBus->connection,FALSE); - - /* - dBus->proxy = g_dbus_proxy_new_sync( - dBus->connection, - G_DBUS_PROXY_FLAGS_NONE, - NULL, // GDBusInterfaceInfo - "br.com.bb." PACKAGE_NAME, // name - "/br/com/bb/" PACKAGE_NAME "/terminal", // object path - "br.com.bb." PACKAGE_NAME ".terminal", // interface - NULL, // GCancellable - &error ); - - if(error) { - - GtkWidget *dialog = gtk_message_dialog_new( - GTK_WINDOW(window), - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _( "Can't get D-Bus proxy object" )); - - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); - g_error_free(error); - - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - return -1; - } - */ - - for(id='a'; id < 'z' && !error && !dBus->proxy; id++) { - - gchar *name = g_strdup_printf("br.com.bb.%s.%c",gtk_widget_get_name(window),id); - - debug("Requesting \"%s\"",name); - - // https://dbus.freedesktop.org/doc/dbus-specification.html - GVariant * response = - g_dbus_connection_call_sync ( - dBus->connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "RequestName", - g_variant_new ("(su)", name, DBUS_NAME_FLAG_DO_NOT_QUEUE), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error - ); - - if(error) { - g_message("Can't request \"%s\": %s",name,error->message); - g_error_free(error); - error = NULL; - } - - if(response) { - - guint32 reply = 0; - g_variant_get(response, "(u)", &reply); - g_variant_unref(response); - - if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - - dBus->proxy = g_dbus_proxy_new_sync( - dBus->connection, - G_DBUS_PROXY_FLAGS_NONE, - NULL, // GDBusInterfaceInfo - name, // name - "/br/com/bb/" PACKAGE_NAME "/terminal", // object path - "br.com.bb." PACKAGE_NAME ".terminal", // interface - NULL, // GCancellable - &error ); - - gchar * widget_name = g_strdup_printf("%s:%c",gtk_widget_get_name(window),id); - v3270_set_session_name(terminal, widget_name); - g_free(widget_name); - - g_message("Got %s - %s", name, v3270_get_session_name(terminal)); - - } - - } - - g_free(name); - - } - - if(!dBus->proxy) { - GtkWidget *dialog = gtk_message_dialog_new( - GTK_WINDOW(window), - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _( "Can't get DBUS object name" )); - - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - return -1; - } - - // Got D-Bus name, register object. - - return 0; - - } - - #endif // !_WIN32 - - diff --git a/src/methods.c b/src/methods.c deleted file mode 100644 index 8da10b9..0000000 --- a/src/methods.c +++ /dev/null @@ -1,172 +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/joprietoe/gdbus/blob/master/gdbus-example-server.c - * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.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 - -GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error) { - - size_t ix; - - debug("%s(%s)",__FUNCTION__,method_name); - - if(!g_ascii_strcasecmp(method_name,"getString")) - { - return ipc3270_GVariant_from_input_string(object, lib3270_get_string_at_address(ipc3270_get_session(object),0,-1,'\n'), error); - } - else if(!g_ascii_strcasecmp(method_name,"setString")) - { - gchar *text = NULL; - g_variant_get(parameters, "(&s)", &text); - - g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error); - if(lib3270_input_string(ipc3270_get_session(object),(const unsigned char *) converted) < 0) - { - // Failed! - ipc3270_set_error(object,errno,error); - return NULL; - } - - // Suceeded - return g_variant_new_int16((gint16) 0); - - } - else if(!g_ascii_strcasecmp(method_name,"setStringAt")) - { - gint row,col; - gchar *text = NULL; - g_variant_get(parameters, "(ii&s)", &row, &col, &text); - - g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error); - if(lib3270_set_string_at(ipc3270_get_session(object),row,col,(const unsigned char *) converted) < 0) - { - // Failed! - ipc3270_set_error(object,errno,error); - return NULL; - } - - // Suceeded - return g_variant_new_int16((gint16) 0); - - } - else if(!g_ascii_strcasecmp(method_name,"getStringAt")) - { - gint row,col,len; - guchar lf; - g_variant_get(parameters, "(iiy)", &row, &col, &len,&lf); - - return ipc3270_GVariant_from_input_string(object,lib3270_get_string_at(ipc3270_get_session(object), row, col, len, lf),error); - - } - else if(!g_ascii_strcasecmp(method_name,"setStringAtAddress")) - { - gint addr; - gchar *text = NULL; - g_variant_get(parameters, "(i&s)", &addr, &text); - - g_autofree gchar * converted = ipc3270_convert_output_string(object, text, error); - if(lib3270_set_string_at_address(ipc3270_get_session(object),addr,(unsigned char *) converted) < 0) - { - // Failed! - ipc3270_set_error(object,errno,error); - return NULL; - } - - // Suceeded - return g_variant_new_int16((gint16) 0); - - } - else if(!g_ascii_strcasecmp(method_name,"getStringAtAddress")) - { - gint addr,len; - guchar lf; - g_variant_get(parameters, "(iiy)", &addr, &len, &lf); - - return ipc3270_GVariant_from_input_string(object,lib3270_get_string_at_address(ipc3270_get_session(object), addr, len, lf),error); - - } - // Check action table. - const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table(); - for(ix = 0; actions[ix].name; ix++) - { - if(!g_ascii_strcasecmp(actions[ix].name,method_name)) { - - int rc = actions[ix].call(ipc3270_get_session(object)); - if(rc) - { - // Failed - ipc3270_set_error(object,errno,error); - return NULL; - } - - // Suceeded - return g_variant_new_int16((gint16) 0); - - } - } - - // Check int methods - const IPC_METHOD_INT_ARG * int_methods = ipc3270_get_int_arg_methods(); - - for(ix = 0; int_methods[ix].name; ix++) - { - if(!g_ascii_strcasecmp(int_methods[ix].name,method_name)) { - - gint value; - g_variant_get(parameters, "(i)", &value); - - int rc = int_methods[ix].call(ipc3270_get_session(object), value); - if(rc) - { - // Failed - ipc3270_set_error(object,errno,error); - return NULL; - } - - // Suceeded - return g_variant_new_int16((gint16) 0); - - } - - } - - return NULL; - -} diff --git a/src/plugin/windows/resources.rc.in b/src/plugin/windows/resources.rc.in new file mode 100644 index 0000000..e3675ae --- /dev/null +++ b/src/plugin/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/setproperties.c b/src/setproperties.c deleted file mode 100644 index b2be73f..0000000 --- a/src/setproperties.c +++ /dev/null @@ -1,151 +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/joprietoe/gdbus/blob/master/gdbus-example-server.c - * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.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 - -gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error) { - - // Check for property - size_t ix; - - // Boolean properties - const LIB3270_INT_PROPERTY * boolprop = lib3270_get_boolean_properties_list(); - for(ix = 0; boolprop[ix].name; ix++) { - - if(boolprop[ix].set && !g_ascii_strcasecmp(boolprop[ix].name, property_name)) { - - // Found it! - if(boolprop[ix].set(ipc3270_get_session(object), (int) (g_variant_get_boolean(value) ? 1 : 0))) { - - // Erro! - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_FAILED, - g_strerror(errno) - ); - - return FALSE; - } - - return TRUE; - - } - - } - - // Integer properties - const LIB3270_INT_PROPERTY * intprop = lib3270_get_int_properties_list(); - for(ix = 0; intprop[ix].name; ix++) { - - if(intprop[ix].set && !g_ascii_strcasecmp(intprop[ix].name, property_name)) { - - // Found it! - if(intprop[ix].set(ipc3270_get_session(object), (int) (g_variant_get_boolean(value) ? 1 : 0))) { - - // Erro! - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_FAILED, - g_strerror(errno) - ); - - return FALSE; - } - - return TRUE; - - } - - } - - // String properties - const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list(); - for(ix = 0; strprop[ix].name; ix++) { - - if(strprop[ix].set && !g_ascii_strcasecmp(strprop[ix].name, property_name)) { - - // Found it! - if(strprop[ix].set(ipc3270_get_session(object), g_variant_get_string(value,NULL))) { - - // Erro! - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_FAILED, - g_strerror(errno) - ); - - return FALSE; - } - - return TRUE; - - } - - } - - // Check for toggle - LIB3270_TOGGLE toggle = lib3270_get_toggle_id(property_name); - if(toggle != (LIB3270_TOGGLE) -1) { - - // Is a Tn3270 toggle, get it! - if(lib3270_set_toggle(ipc3270_get_session(object),toggle,(int) g_variant_get_int32(value))) { - - // Erro! - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_FAILED, - g_strerror(errno) - ); - - return FALSE; - - } - - return TRUE; - } - - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_NOT_FOUND, - "Can't find any property named %s", property_name - ); - - return FALSE; -} diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index f527124..8364ceb 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -41,7 +41,7 @@ /*---[ Implement ]----------------------------------------------------------------------------------*/ -static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { + static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { GtkWidget * window = gtk_application_window_new(app); GtkWidget * terminal = v3270_new(); @@ -75,18 +75,40 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { int main (int argc, char **argv) { - GtkApplication *app; - int status; + /* + GVariantBuilder builder; - app = gtk_application_new ("br.com.bb.pw3270",G_APPLICATION_FLAGS_NONE); + g_variant_builder_init(&builder,G_VARIANT_TYPE("(isi)")); - g_signal_connect (app, "activate", G_CALLBACK(activate), NULL); + g_variant_builder_add(&builder, "i", 10); + g_variant_builder_add(&builder, "s", "teste"); + g_variant_builder_add(&builder, "i", 20); - status = g_application_run (G_APPLICATION (app), argc, argv); - g_object_unref (app); + GVariant *value = g_variant_builder_end(&builder); - g_message("rc=%d",status); - return status; + 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/windows/gobject.c b/src/windows/gobject.c deleted file mode 100644 index d0243a7..0000000 --- a/src/windows/gobject.c +++ /dev/null @@ -1,125 +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) - * - */ - -#include "gobject.h" -#include -#include -#include - -G_DEFINE_TYPE(ipc3270, ipc3270, G_TYPE_OBJECT) - -static void ipc3270_finalize(GObject *object) { - - ipc3270 * ipc = IPC3270(object); - - - G_OBJECT_CLASS(ipc3270_parent_class)->finalize(object); -} - - -static void ipc3270_class_init(ipc3270Class *klass) { - - debug("%s",__FUNCTION__); - - GObjectClass *object_class; - object_class = G_OBJECT_CLASS (klass); - object_class->finalize = ipc3270_finalize; - -} - -static void ipc3270_init(ipc3270 *object) { - - debug("%s",__FUNCTION__); - object->error_domain = g_quark_from_static_string(PACKAGE_NAME); - -} - -GObject * ipc3270_new() { - return g_object_new(GLIB_TYPE_IPC3270, NULL); -} - -void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error) { - - char id; - - ipc3270 * ipc = IPC3270(object); - ipc->hSession = hSession; - - 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 - - debug("%s = %p",pipename,hPipe); - g_free(pipename); - - if(hPipe != INVALID_HANDLE_VALUE) { - - ipc->source = (IPC3270_PIPE_SOURCE *) g_source_new(&ipc3270_source_funcs,sizeof(IPC3270_PIPE_SOURCE)); - - lib3270_set_session_id(ipc->hSession, id); - - ipc->source->hPipe = hPipe; - ipc->source->state = PIPE_STATE_WAITING; - ipc->source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL); - - g_source_attach((GSource *) ipc->source,NULL); - - // IO_accept(source); - ipc3270_wait_for_client(ipc->source); - - break; - } - - } - - -} - -const gchar * ipc3270_get_display_charset(GObject *object) { - return lib3270_get_display_charset(IPC3270(object)->hSession); -} - - diff --git a/src/windows/gobject.h b/src/windows/gobject.h deleted file mode 100644 index 4c03060..0000000 --- a/src/windows/gobject.h +++ /dev/null @@ -1,97 +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) - * - */ - - /** - * @brief Private definitions for pw3270 IPC windows module. - * - */ - -#ifndef WINDOWS_GOBJECT_H_INCLUDED - - #define WINDOWS_GOBJECT_H_INCLUDED - - #include - #include - - #define ENABLE_NLS - #define GETTEXT_PACKAGE PACKAGE_NAME - - #include - #include - #include - - #include - #include - - #define PIPE_BUFFER_LENGTH 8192 - - G_BEGIN_DECLS - - typedef struct _ipc3270 ipc3270; - typedef struct _ipc3270Class ipc3270Class; - typedef struct _ipc3270Request ipc3270Request; - - typedef enum _ipc3270_pipe_state { - PIPE_STATE_WAITING, - PIPE_STATE_READ, - PIPE_STATE_PENDING_READ, - PIPE_STATE_UNDEFINED - } IPC3270_PIPE_STATE; - - typedef struct _ipc3270_pipe_source { - GSource gsrc; - HANDLE hPipe; - - IPC3270_PIPE_STATE state; - - OVERLAPPED overlap; - unsigned char buffer[PIPE_BUFFER_LENGTH+1]; - - } IPC3270_PIPE_SOURCE; - - struct _ipc3270 { - H3270 * hSession; - IPC3270_PIPE_SOURCE * source; - GQuark error_domain; - }; - - struct _ipc3270Class { - GObjectClass parent; - }; - - G_GNUC_INTERNAL GSourceFuncs ipc3270_source_funcs; - - G_GNUC_INTERNAL void ipc3270_wait_for_client(IPC3270_PIPE_SOURCE *source); - G_GNUC_INTERNAL unsigned char * ipc3270_pack(GVariant *values); - G_GNUC_INTERNAL GVariant * ipc3270_unpack(const unsigned char *packet); - - G_END_DECLS - -#endif // WINDOWS_GOBJECT_H_INCLUDED diff --git a/src/windows/inout.c b/src/windows/inout.c deleted file mode 100644 index 63fafde..0000000 --- a/src/windows/inout.c +++ /dev/null @@ -1,275 +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 inout.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 Pack/Unpack IPC data block. - * - */ - - #include - #include - #include - #include - -/*---[ Implement ]----------------------------------------------------------------------------------*/ - -unsigned char * ipc3270_pack(GVariant *values) { - - GVariantIter iter; - gsize count = g_variant_iter_init(&iter, values); - g_autofree char * types = g_new0(char, count); - GVariant * child; - size_t ix = 0; - size_t szBuffer = sizeof(gint16); - - g_print("Packaging %u itens\n", (unsigned int) count); - while ((child = g_variant_iter_next_value (&iter))) { - - // g_print("type='%s' size=%u\n", g_variant_get_type_string(child), (unsigned int) g_variant_get_size(child)); - - types[ix] = g_variant_get_type_string(child)[0]; - - szBuffer += (1+g_variant_get_size(child)); - if(types[ix] == 's') { - szBuffer += sizeof(gint16); - } - - g_variant_unref(child); - ix++; - } - - unsigned char * outputBuffer = g_malloc0(szBuffer); - unsigned char * txtptr = outputBuffer + sizeof(guint16) + sizeof(guint16); - - *((guint16 *) outputBuffer) = (guint16) szBuffer; - *((guint16 *) (outputBuffer + sizeof(guint16))) = (guint16) count; - - ix = 0; - g_variant_iter_init(&iter, values); - while ((child = g_variant_iter_next_value (&iter))) { - - debug("type='%s' size=%u index=%u", g_variant_get_type_string(child), (unsigned int) g_variant_get_size(child), (unsigned int) (txtptr - outputBuffer)); - - *(txtptr++) = types[ix]; - - switch(types[ix]) { - - // https://developer.gnome.org/glib/stable/gvariant-format-strings.html - - case 's': - strcpy((char *) txtptr,g_variant_get_string(child,NULL)); - txtptr += (strlen((char *) txtptr)+1); - break; - - case 'b': // gboolean - *(txtptr++) = g_variant_get_boolean(child) ? 1 : 0; - break; - - case 'y': // guchar - *(txtptr++) = g_variant_get_byte(child); - break; - - case 'n': // gint16 - *((gint16 *) txtptr) = g_variant_get_int16(child); - txtptr += sizeof(gint16); - break; - - case 'q': // guint16 - *((guint16 *) txtptr) = g_variant_get_uint16(child); - txtptr += sizeof(guint16); - break; - - case 'i': // gint32 - case 'h': // gint32 - *((gint32 *) txtptr) = g_variant_get_int32(child); - txtptr += sizeof(gint32); - break; - - case 'u': // guint32 - *((guint32 *) txtptr) = g_variant_get_uint32(child); - txtptr += sizeof(guint32); - break; - - case 'x': // gint64 - *((gint64 *) txtptr) = g_variant_get_int64(child); - txtptr += sizeof(gint64); - break; - - case 't': // guint64 - *((guint64 *) txtptr) = g_variant_get_uint64(child); - txtptr += sizeof(guint64); - break; - - default: - errno = EINVAL; - g_free(outputBuffer); - return NULL; - } - - g_variant_unref(child); - ix++; - } - - return outputBuffer; -} - -GVariant * ipc3270_unpack(const unsigned char *packet) { - - size_t szPacket = (size_t) * ((guint16 *) packet); - size_t count = (size_t) * ((guint16 *) (packet+sizeof(guint16))); - - const unsigned char *txtptr = packet + (sizeof(guint16) * 2); - size_t ix; - - g_autofree gchar * descrs = g_malloc0(count+3); - descrs[0] = '('; - descrs[count+1] = ')'; - - debug("Unpacking package with %u bytes and %u itens\n", (unsigned int) szPacket, (unsigned int) count); - - for(ix = 0; ix < count; ix++) { - - debug("Format(%u): %c at %u",(unsigned int) ix, *txtptr, (unsigned int) (txtptr - packet)); - - descrs[ix+1] = *(txtptr++); - - switch(descrs[ix+1]) { - case 's': - txtptr += strlen((char *) txtptr)+1; - break; - - case 'b': // gboolean - case 'y': // guchar - txtptr++; - break; - - case 'n': // gint16 - txtptr += sizeof(gint16); - break; - - case 'q': // guint16 - txtptr += sizeof(guint16); - break; - - case 'i': // gint32 - case 'h': // gint32 - txtptr += sizeof(gint32); - break; - - case 'u': // guint32 - txtptr += sizeof(guint32); - break; - - case 'x': // gint64 - txtptr += sizeof(gint64); - break; - - case 't': // guint64 - txtptr += sizeof(guint64); - break; - - default: - errno = EINVAL; - return NULL; - } - } - - debug("Format: \"%s\"\n",descrs); - - GVariantBuilder builder; - g_variant_builder_init(&builder,G_VARIANT_TYPE(descrs)); - - txtptr = packet + (sizeof(guint16) * 2); - for(ix = 0; ix < count; ix++) { - - debug("Format(%u): %c at %u",(unsigned int) ix, *txtptr, (unsigned int) (txtptr - packet)); - txtptr++; - - switch(descrs[ix+1]) { - case 's': - g_variant_builder_add(&builder, "s", txtptr); - txtptr += strlen((char *) txtptr)+1; - break; - - case 'b': // gboolean - g_variant_builder_add(&builder, "b", *((gboolean *) txtptr)); - txtptr++; - break; - - case 'y': // guchar - g_variant_builder_add(&builder, "y", *((guchar *) txtptr)); - txtptr++; - break; - - case 'n': // gint16 - g_variant_builder_add(&builder, "n", *((gint16 *) txtptr)); - txtptr += sizeof(gint16); - break; - - case 'q': // guint16 - g_variant_builder_add(&builder, "q", *((guint16 *) txtptr)); - txtptr += sizeof(guint16); - break; - - case 'i': // gint32 - g_variant_builder_add(&builder, "i", *((gint32 *) txtptr)); - txtptr += sizeof(gint32); - break; - - case 'h': // gint32 - g_variant_builder_add(&builder, "h", *((gint32 *) txtptr)); - txtptr += sizeof(gint32); - break; - - case 'u': // guint32 - g_variant_builder_add(&builder, "u", *((guint32 *) txtptr)); - txtptr += sizeof(guint32); - break; - - case 'x': // gint64 - g_variant_builder_add(&builder, "x", *((gint64 *) txtptr)); - txtptr += sizeof(gint64); - break; - - case 't': // guint64 - g_variant_builder_add(&builder, "t", *((guint64 *) txtptr)); - txtptr += sizeof(guint64); - break; - - default: - errno = EINVAL; - return NULL; - } - } - - return g_variant_builder_end(&builder); - -} diff --git a/src/windows/pipesource.c b/src/windows/pipesource.c deleted file mode 100644 index 4434ac0..0000000 --- a/src/windows/pipesource.c +++ /dev/null @@ -1,214 +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 pipesource.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - -#include "gobject.h" - -void ipc3270_wait_for_client(IPC3270_PIPE_SOURCE *source) { - - if(ConnectNamedPipe(source->hPipe,&source->overlap)) { - g_message("Error %u in ConnectNamedPipe",(unsigned int) GetLastError()); - // popup_lasterror("%s",_( "Error in ConnectNamedPipe" )); - return; - } - - switch(GetLastError()) { - case ERROR_IO_PENDING: // The overlapped connection in progress. - source->state = PIPE_STATE_WAITING; - break; - - - case ERROR_PIPE_CONNECTED: // Client is already connected, so signal an event. - if(SetEvent(source->overlap.hEvent)) - break; - - default: - g_message("Error %u in ConnectNamedPipe",(unsigned int) GetLastError()); - // 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(((IPC3270_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(((IPC3270_PIPE_SOURCE *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) - return TRUE; - - return FALSE; -} - -static void process_input(IPC3270_PIPE_SOURCE *source, DWORD cbRead) { - -} - -static void read_input_pipe(IPC3270_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: - source->state = PIPE_STATE_PENDING_READ; - break; - - case ERROR_PIPE_LISTENING: - source->state = PIPE_STATE_READ; - break; - - case ERROR_BROKEN_PIPE: - - if(!DisconnectNamedPipe(source->hPipe)) { - - g_message("Error %u on DisconnectNamedPipe", (unsigned int) GetLastError()); - - } else { - - ipc3270_wait_for_client(source); - - } - break; - - case ERROR_PIPE_NOT_CONNECTED: - g_message("Cliente was disconnected"); - break; - - default: - if(source->hPipe != INVALID_HANDLE_VALUE) { - g_message( "Error %u receiving message from pipe", (unsigned int) GetLastError()); - } - } - -} - - -static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer data) { - /* - * Called to dispatch the event source, - * after it has returned TRUE in either its prepare or its check function. - * The dispatch function is passed in a callback function and data. - * The callback function may be NULL if the source was never connected - * to a callback using g_source_set_callback(). The dispatch function - * should call the callback function with user_data and whatever additional - * parameters are needed for this type of event source. - */ - BOOL fSuccess; - DWORD cbRead = 0; - - fSuccess = GetOverlappedResult(((IPC3270_PIPE_SOURCE *) source)->hPipe,&((IPC3270_PIPE_SOURCE *) source)->overlap,&cbRead,FALSE ); - - switch(((IPC3270_PIPE_SOURCE *) source)->state) { - case PIPE_STATE_WAITING: - - if(fSuccess) { - - g_message("Client is connected"); - ((IPC3270_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( (IPC3270_PIPE_SOURCE *) source); - break; - - case PIPE_STATE_PENDING_READ: - if(fSuccess && cbRead > 0) - process_input((IPC3270_PIPE_SOURCE *) source,cbRead); - ((IPC3270_PIPE_SOURCE *) source)->state = PIPE_STATE_READ; - break; - - case PIPE_STATE_UNDEFINED: - break; - - } - - return TRUE; -} - -static gboolean IO_closure(gpointer data) { - return 0; -} - -static void IO_finalize(GSource *source) { - - if( ((IPC3270_PIPE_SOURCE *) source)->hPipe != INVALID_HANDLE_VALUE) { - CloseHandle(((IPC3270_PIPE_SOURCE *) source)->hPipe); - ((IPC3270_PIPE_SOURCE *) source)->hPipe = INVALID_HANDLE_VALUE; - } - -} - -GSourceFuncs ipc3270_source_funcs = { - IO_prepare, - IO_check, - IO_dispatch, - IO_finalize, - IO_closure, - NULL -}; diff --git a/src/windows/resources.rc.in b/src/windows/resources.rc.in deleted file mode 100644 index 2ca7c88..0000000 --- a/src/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_DESCRIPTION@\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", "@PACKAGE_TARNAME@@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 - -- libgit2 0.21.2