Commit 57d9adebfccf1ad41b27ff12e179715c0abc7d46
1 parent
0e4b8d43
Exists in
master
and in
5 other branches
Atualizando empacotamento.
Showing
26 changed files
with
3971 additions
and
3979 deletions
Show diff stats
Makefile.in
| ... | ... | @@ -120,6 +120,13 @@ $(DESTDIR)$(libdir)/%@DLLEXT@: \ |
| 120 | 120 | |
| 121 | 121 | @$(MAKE) DESTDIR=$(DESTDIR) -C src/$(basename $(notdir $@)) install |
| 122 | 122 | |
| 123 | +$(DESTDIR)$(libdir)/%.a: \ | |
| 124 | + $(DEPENDS) \ | |
| 125 | + ./src/%/* | |
| 126 | + | |
| 127 | + @$(MAKE) DESTDIR=$(DESTDIR) -C src/$(basename $(notdir $@)) $@ | |
| 128 | + | |
| 129 | + | |
| 123 | 130 | $(DESTDIR)$(libdir)/$(PACKAGE_TARNAME)-plugins/%@DLLEXT@: \ |
| 124 | 131 | $(DEPENDS) \ |
| 125 | 132 | ./src/plugins/%/* |
| ... | ... | @@ -185,6 +192,7 @@ locale/$(PACKAGE_TARNAME).pot: \ |
| 185 | 192 | install: \ |
| 186 | 193 | $(DESTDIR)$(libdir)/lib3270@DLLEXT@ \ |
| 187 | 194 | $(DESTDIR)$(libdir)/$(PACKAGE_TARNAME)@EXEEXT@ \ |
| 195 | + $(DESTDIR)$(libdir)/libpw3270cpp.a \ | |
| 188 | 196 | $(foreach PLG, $(PLUGINS), $(DESTDIR)$(libdir)/$(PACKAGE_TARNAME)-plugins/$(PLG)@DLLEXT@) \ |
| 189 | 197 | locale/$(PACKAGE_TARNAME).pot |
| 190 | 198 | |
| ... | ... | @@ -255,6 +263,7 @@ $(SRCDIR): \ |
| 255 | 263 | $(SRCDIR)/ui \ |
| 256 | 264 | $(SRCDIR)/src/lib3270 \ |
| 257 | 265 | $(SRCDIR)/src/pw3270 \ |
| 266 | + $(SRCDIR)/src/libpw3270cpp \ | |
| 258 | 267 | $(SRCDIR)/sdk \ |
| 259 | 268 | $(SRCDIR)/src/plugins/dbus3270 |
| 260 | 269 | ... | ... |
configure.ac
| ... | ... | @@ -356,6 +356,7 @@ AC_CONFIG_FILES(src/pw3270/v3270/Makefile) |
| 356 | 356 | AC_CONFIG_FILES(src/pw3270/v3270ft/Makefile) |
| 357 | 357 | AC_CONFIG_FILES(src/pw3270/uiparser/Makefile) |
| 358 | 358 | AC_CONFIG_FILES(src/pw3270/common/Makefile) |
| 359 | +AC_CONFIG_FILES(src/libpw3270cpp/Makefile) | |
| 359 | 360 | |
| 360 | 361 | AC_CONFIG_FILES(ui/Makefile) |
| 361 | 362 | AC_CONFIG_FILES(locale/Makefile) | ... | ... |
locale/pw3270.pot
| ... | ... | @@ -9,7 +9,7 @@ msgstr "" |
| 9 | 9 | "#-#-#-#-# lib3270.pot (PACKAGE VERSION) #-#-#-#-#\n" |
| 10 | 10 | "Project-Id-Version: PACKAGE VERSION\n" |
| 11 | 11 | "Report-Msgid-Bugs-To: \n" |
| 12 | -"POT-Creation-Date: 2017-01-19 10:28-0200\n" | |
| 12 | +"POT-Creation-Date: 2017-01-19 11:07-0200\n" | |
| 13 | 13 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
| 14 | 14 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 15 | 15 | "Language-Team: LANGUAGE <LL@li.org>\n" |
| ... | ... | @@ -20,7 +20,7 @@ msgstr "" |
| 20 | 20 | "#-#-#-#-# pw3270.pot (PACKAGE VERSION) #-#-#-#-#\n" |
| 21 | 21 | "Project-Id-Version: PACKAGE VERSION\n" |
| 22 | 22 | "Report-Msgid-Bugs-To: \n" |
| 23 | -"POT-Creation-Date: 2017-01-19 10:28-0200\n" | |
| 23 | +"POT-Creation-Date: 2017-01-19 11:07-0200\n" | |
| 24 | 24 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
| 25 | 25 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 26 | 26 | "Language-Team: LANGUAGE <LL@li.org>\n" |
| ... | ... | @@ -42,7 +42,7 @@ msgstr "" |
| 42 | 42 | "#-#-#-#-# dbus3270.pot (PACKAGE VERSION) #-#-#-#-#\n" |
| 43 | 43 | "Project-Id-Version: PACKAGE VERSION\n" |
| 44 | 44 | "Report-Msgid-Bugs-To: \n" |
| 45 | -"POT-Creation-Date: 2017-01-19 10:28-0200\n" | |
| 45 | +"POT-Creation-Date: 2017-01-19 11:07-0200\n" | |
| 46 | 46 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
| 47 | 47 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 48 | 48 | "Language-Team: LANGUAGE <LL@li.org>\n" | ... | ... |
rpm/pw3270.spec
| ... | ... | @@ -44,8 +44,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-build |
| 44 | 44 | Requires: lib3270-%{_libvrs} = %{version} |
| 45 | 45 | Requires: shared-mime-info |
| 46 | 46 | |
| 47 | -Provides: libpw3270 = %{version} | |
| 48 | -Provides: libpw3270.so = %{version} | |
| 47 | +Requires: libpw3270-%{MAJOR_VERSION}_%{MINOR_VERSION} | |
| 49 | 48 | |
| 50 | 49 | #--[ Setup by distribution ]------------------------------------------------------------------------------------------ |
| 51 | 50 | # |
| ... | ... | @@ -130,6 +129,7 @@ BuildRequires: m4 |
| 130 | 129 | BuildRequires: pkgconfig |
| 131 | 130 | BuildRequires: sed |
| 132 | 131 | BuildRequires: optipng |
| 132 | +BuildRequires: fdupes | |
| 133 | 133 | |
| 134 | 134 | %description |
| 135 | 135 | Open-source GTK-based IBM 3270 terminal emulator with many advanced features. It can be used to communicate with any IBM host that supports 3270-style connections over TELNET. |
| ... | ... | @@ -153,7 +153,8 @@ This package contains the tn3270 protocol library for %{name} |
| 153 | 153 | %package -n lib3270-devel |
| 154 | 154 | Summary: Devel for 3270 Communication library for %{name} |
| 155 | 155 | Group: Development/Libraries/C and C++ |
| 156 | -Requires: lib3270 = %{version} | |
| 156 | +Provides: lib3270-devel-%{MAJOR_VERSION}_%{MINOR_VERSION} | |
| 157 | +Requires: lib3270-%{MAJOR_VERSION}_%{MINOR_VERSION} | |
| 157 | 158 | |
| 158 | 159 | %description -n lib3270-devel |
| 159 | 160 | Open-source GTK-based IBM 3270 terminal emulator with many advanced features. It can be used to communicate with any IBM host that supports 3270-style connections over TELNET. |
| ... | ... | @@ -162,11 +163,8 @@ This package contains the development files for tn3270 protocol library for %{na |
| 162 | 163 | %package -n %{name}-devel |
| 163 | 164 | Summary: Files required for development of %{name} plugins |
| 164 | 165 | Group: Development/Libraries/C and C++ |
| 165 | - | |
| 166 | -Requires: lib3270-devel = %{version} | |
| 167 | -Requires: %{name} = %{version} | |
| 168 | - | |
| 169 | -Provides: pw3270-devel = %{MAJOR_VERSION}.%{MINOR_VERSION} | |
| 166 | +Requires: lib3270-devel-%{MAJOR_VERSION}_%{MINOR_VERSION} | |
| 167 | +Requires: libpw3270-%{MAJOR_VERSION}_%{MINOR_VERSION} | |
| 170 | 168 | |
| 171 | 169 | %description -n %{name}-devel |
| 172 | 170 | Open-source GTK-based IBM 3270 terminal emulator with many advanced features. It can be used to communicate with any IBM host that supports 3270-style connections over TELNET. |
| ... | ... | @@ -240,6 +238,8 @@ rm ${RPM_BUILD_ROOT}/%{_datadir}/pw3270/ui/*java*.xml |
| 240 | 238 | # ooRexx now lives in another package |
| 241 | 239 | rm ${RPM_BUILD_ROOT}/%{_datadir}/pw3270/ui/*rexx*.xml |
| 242 | 240 | |
| 241 | +%fdupes $RPM_BUILD_ROOT | |
| 242 | + | |
| 243 | 243 | %clean |
| 244 | 244 | rm -rf %{buildroot} |
| 245 | 245 | |
| ... | ... | @@ -265,7 +265,6 @@ rm -rf %{buildroot} |
| 265 | 265 | %{_datadir}/pw3270/colors.conf |
| 266 | 266 | %{_datadir}/pw3270/pw3270.png |
| 267 | 267 | %{_datadir}/pw3270/pw3270-logo.png |
| 268 | -%{_datadir}/locale/pt_BR/LC_MESSAGES/pw3270.mo | |
| 269 | 268 | %dir %{_libdir}/pw3270-plugins |
| 270 | 269 | |
| 271 | 270 | %files -n lib3270-%{_libvrs} |
| ... | ... | @@ -279,6 +278,7 @@ rm -rf %{buildroot} |
| 279 | 278 | %{_includedir}/lib3270.h |
| 280 | 279 | %{_libdir}/pkgconfig/lib3270.pc |
| 281 | 280 | %{_libdir}/lib3270.so |
| 281 | +%{_datadir}/pw3270/locale | |
| 282 | 282 | |
| 283 | 283 | %files -n %{name}-devel |
| 284 | 284 | %defattr(-,root,root) |
| ... | ... | @@ -292,9 +292,6 @@ rm -rf %{buildroot} |
| 292 | 292 | %{_libdir}/libpw3270cpp.a |
| 293 | 293 | %{_includedir}/pw3270cpp.h |
| 294 | 294 | |
| 295 | -%dir %{_datadir}/pw3270/sample | |
| 296 | -%{_datadir}/pw3270/sample/* | |
| 297 | - | |
| 298 | 295 | %if 0%{?_dbus} |
| 299 | 296 | %files plugin-dbus |
| 300 | 297 | %defattr(-,root,root) | ... | ... |
sdk/Makefile.in
| ... | ... | @@ -71,14 +71,16 @@ install: \ |
| 71 | 71 | $(foreach SRC, $(notdir $(wildcard $(BASEDIR)/src/include/lib3270/*.h)), $(DESTDIR)$(includedir)/lib3270/$(SRC)) \ |
| 72 | 72 | $(foreach SRC, $(notdir $(wildcard $(BASEDIR)/src/include/pw3270/*.h)), $(DESTDIR)$(includedir)/pw3270/$(SRC)) \ |
| 73 | 73 | $(DESTDIR)$(includedir)/lib3270.h \ |
| 74 | - $(DESTDIR)$(includedir)/pw3270.h | |
| 74 | + $(DESTDIR)$(includedir)/pw3270.h \ | |
| 75 | + $(DESTDIR)$(includedir)/pw3270cpp.h \ | |
| 75 | 76 | |
| 76 | 77 | |
| 77 | 78 | $(SRCDIR)/sdk: \ |
| 78 | 79 | $(foreach SRC, $(notdir $(wildcard $(BASEDIR)/src/include/lib3270/*.h)), $(SRCDIR)/src/include/lib3270/$(SRC)) \ |
| 79 | 80 | $(foreach SRC, $(notdir $(wildcard $(BASEDIR)/src/include/pw3270/*.h)), $(SRCDIR)/src/include/pw3270/$(SRC)) \ |
| 80 | 81 | $(SRCDIR)/src/include/lib3270.h \ |
| 81 | - $(SRCDIR)/src/include/pw3270.h | |
| 82 | + $(SRCDIR)/src/include/pw3270.h \ | |
| 83 | + $(SRCDIR)/src/include/pw3270cpp.h | |
| 82 | 84 | |
| 83 | 85 | @$(MKDIR) $@ |
| 84 | 86 | @$(INSTALL_DATA) *.in $@ | ... | ... |
src/include/pw3270/class.h
| ... | ... | @@ -1,284 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como class.h e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | -#ifndef PW3270_CLASS_H_INCLUDED | |
| 31 | - | |
| 32 | - #define PW3270_CLASS_H_INCLUDED 1 | |
| 33 | - | |
| 34 | - #ifdef WIN32 | |
| 35 | - #define SYSTEM_CHARSET "CP1252" | |
| 36 | - #else | |
| 37 | - #define SYSTEM_CHARSET "UTF-8" | |
| 38 | - #endif // WIN32 | |
| 39 | - | |
| 40 | - #include <exception> | |
| 41 | - #include <errno.h> | |
| 42 | - #include <lib3270/config.h> | |
| 43 | - #include <lib3270.h> | |
| 44 | - #include <lib3270/popup.h> | |
| 45 | - #include <lib3270/filetransfer.h> | |
| 46 | - | |
| 47 | - #ifdef HAVE_ICONV | |
| 48 | - #include <iconv.h> | |
| 49 | - #endif // HAVE_ICONV | |
| 50 | - | |
| 51 | - #include <string> | |
| 52 | - #include <stdarg.h> | |
| 53 | - #include <lib3270.h> | |
| 54 | - #include <errno.h> | |
| 55 | - | |
| 56 | - #ifdef DEBUG | |
| 57 | - #include <stdio.h> | |
| 58 | - #define trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr); | |
| 59 | - #else | |
| 60 | - #define trace(x, ...) // __VA_ARGS__ | |
| 61 | - #endif | |
| 62 | - | |
| 63 | - #ifndef ETIMEDOUT | |
| 64 | - #define ETIMEDOUT 1238 | |
| 65 | - #endif // !ETIMEDOUT | |
| 66 | - | |
| 67 | - #define PW3270_NAMESPACE h3270 | |
| 68 | - | |
| 69 | - namespace PW3270_NAMESPACE | |
| 70 | - { | |
| 71 | - using namespace std; | |
| 72 | - | |
| 73 | - class exception : public std::exception | |
| 74 | - { | |
| 75 | - public: | |
| 76 | - exception(int syserror = errno); | |
| 77 | - exception(const char *fmt, ...); | |
| 78 | - | |
| 79 | -#ifdef WIN32 | |
| 80 | - exception(DWORD error, const char *fmt, ...); | |
| 81 | -#else | |
| 82 | - exception(int error, const char *fmt, ...); | |
| 83 | -#endif // WIN32 | |
| 84 | - | |
| 85 | - virtual const char * what() const throw(); | |
| 86 | - | |
| 87 | - private: | |
| 88 | - char msg[4096]; | |
| 89 | - | |
| 90 | - }; | |
| 91 | - | |
| 92 | - class module | |
| 93 | - { | |
| 94 | - private: | |
| 95 | -#ifdef WIN32 | |
| 96 | - HMODULE hModule; | |
| 97 | - int get_datadir(LPSTR datadir); | |
| 98 | -#else | |
| 99 | - void * hModule; | |
| 100 | - | |
| 101 | -#endif // WIN32 | |
| 102 | - | |
| 103 | - public: | |
| 104 | - module(const char *name, const char *version = NULL) throw (std::exception); | |
| 105 | - ~module(); | |
| 106 | - | |
| 107 | - void * get_symbol(const char *name); | |
| 108 | - | |
| 109 | - }; | |
| 110 | - | |
| 111 | - class session | |
| 112 | - { | |
| 113 | - public: | |
| 114 | - | |
| 115 | - virtual ~session(); | |
| 116 | - | |
| 117 | - // Internal methods, used to init/deinit control tables. | |
| 118 | - static void init(); | |
| 119 | - static void deinit(); | |
| 120 | - | |
| 121 | - // Factory methods and settings | |
| 122 | - static session * start(const char *name = 0); | |
| 123 | - static session * create(const char *name = 0) throw (std::exception); | |
| 124 | - static session * create_local(H3270 *hSession) throw (std::exception); | |
| 125 | - static session * create_local() throw (std::exception); | |
| 126 | - | |
| 127 | - static session * get_default(void); | |
| 128 | - static bool has_default(void); | |
| 129 | - static void set_plugin(session * (*factory)(const char *name)); | |
| 130 | - | |
| 131 | - // Log management | |
| 132 | - void log(const char *fmt, ...); | |
| 133 | - void logva(const char *fmt, va_list args); | |
| 134 | - | |
| 135 | - // Information | |
| 136 | - virtual const string get_version(void); | |
| 137 | - virtual const string get_revision(void); | |
| 138 | - | |
| 139 | - virtual bool is_connected(void) = 0; | |
| 140 | - virtual bool is_ready(void) = 0; | |
| 141 | - | |
| 142 | - virtual LIB3270_CSTATE get_cstate(void) = 0; | |
| 143 | - virtual LIB3270_MESSAGE get_program_message(void) = 0; | |
| 144 | - virtual LIB3270_SSL_STATE get_secure(void) = 0; | |
| 145 | - | |
| 146 | - virtual int get_width(void) = 0; | |
| 147 | - virtual int get_height(void) = 0; | |
| 148 | - virtual int get_length(void) = 0; | |
| 149 | - | |
| 150 | - // Misc | |
| 151 | - virtual void set_unlock_delay(unsigned short ms) = 0; | |
| 152 | - | |
| 153 | - // charset | |
| 154 | -#ifdef WIN32 | |
| 155 | - void set_display_charset(const char *remote = 0, const char *local = "CP1252"); | |
| 156 | - static string win32_strerror(int e); | |
| 157 | -#else | |
| 158 | - void set_display_charset(const char *remote = 0, const char *local = "UTF-8"); | |
| 159 | -#endif // WIN32 | |
| 160 | - | |
| 161 | - virtual int set_host_charset(const char *charset) = 0; | |
| 162 | - virtual string get_host_charset(void) = 0; | |
| 163 | - virtual string get_display_charset(void); | |
| 164 | - | |
| 165 | - // Connection & Network | |
| 166 | - int connect(const char *host, time_t wait = 0); | |
| 167 | - int set_host(const char *host); | |
| 168 | - virtual int connect(void) = 0; | |
| 169 | - | |
| 170 | - virtual int set_url(const char *hostname) = 0; | |
| 171 | - virtual string get_url() = 0; | |
| 172 | - | |
| 173 | - virtual int disconnect(void) = 0; | |
| 174 | - virtual int wait_for_ready(int seconds) = 0; | |
| 175 | - virtual int wait(int seconds) = 0; | |
| 176 | - virtual int iterate(bool wait = true) = 0; | |
| 177 | - | |
| 178 | - // Ascii<->EBCDIC translation | |
| 179 | - virtual const char * asc2ebc(unsigned char *str, int sz = -1) = 0; | |
| 180 | - virtual const char * ebc2asc(unsigned char *str, int sz = -1) = 0; | |
| 181 | - string asc2ebc(string &str); | |
| 182 | - string ebc2asc(string &str); | |
| 183 | - | |
| 184 | - // Get/Set/Text with charset translation | |
| 185 | - string get_string(int baddr = 0, size_t len = -1); | |
| 186 | - string get_string_at(int row, int col, size_t sz); | |
| 187 | - int set_string_at(int row, int col, const char *str); | |
| 188 | - int cmp_string_at(int row, int col, const char *text); | |
| 189 | - int wait_for_string_at(int row, int col, const char *key, int timeout); | |
| 190 | - int input_string(const char *str); | |
| 191 | - | |
| 192 | - inline operator string() { | |
| 193 | - return get_string(); | |
| 194 | - } | |
| 195 | - | |
| 196 | - // Cursor management | |
| 197 | - virtual int set_cursor_position(int row, int col) = 0; | |
| 198 | - virtual int set_cursor_addr(int addr) = 0; | |
| 199 | - virtual int get_cursor_addr(void) = 0; | |
| 200 | - | |
| 201 | - // Toggle management | |
| 202 | - virtual int set_toggle(LIB3270_TOGGLE ix, bool value) = 0; | |
| 203 | - | |
| 204 | - // Keyboard actions | |
| 205 | - virtual int enter(void) = 0; | |
| 206 | - virtual int pfkey(int key) = 0; | |
| 207 | - virtual int pakey(int key) = 0; | |
| 208 | - | |
| 209 | - // Actions | |
| 210 | - virtual int quit(void) = 0; | |
| 211 | - virtual int action(const char *name) = 0; | |
| 212 | - | |
| 213 | - int erase(int mode); | |
| 214 | - | |
| 215 | - virtual int erase(void) = 0; | |
| 216 | - virtual int erase_eof(void) = 0; | |
| 217 | - virtual int erase_eol(void) = 0; | |
| 218 | - virtual int erase_input(void) = 0; | |
| 219 | - | |
| 220 | - virtual int print(void) = 0; | |
| 221 | - | |
| 222 | - // Field management | |
| 223 | - virtual int get_field_start(int baddr = -1) = 0; | |
| 224 | - virtual int get_field_len(int baddr = -1) = 0; | |
| 225 | - virtual int get_next_unprotected(int baddr = -1) = 0; | |
| 226 | - | |
| 227 | - virtual int get_is_protected(int baddr = -1) = 0; | |
| 228 | - virtual int get_is_protected_at(int row, int col) = 0; | |
| 229 | - | |
| 230 | - // Clipboard management | |
| 231 | - virtual int set_copy(const char *text); | |
| 232 | - virtual string get_copy(void); | |
| 233 | - | |
| 234 | - virtual string get_clipboard(void); | |
| 235 | - virtual int set_clipboard(const char *text); | |
| 236 | - | |
| 237 | - // Dialogs | |
| 238 | - virtual int popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...); | |
| 239 | - virtual string file_chooser_dialog(int action, const char *title, const char *extension, const char *filename); | |
| 240 | - | |
| 241 | - // File transfer | |
| 242 | - virtual int file_transfer(LIB3270_FT_OPTION options, const char *local, const char *remote, int lrecl = 0, int blksize = 0, int primspace = 0, int secspace = 0, int dft = 4096); | |
| 243 | - | |
| 244 | - // Charset translation | |
| 245 | - const char * get_encoding(void); | |
| 246 | - | |
| 247 | - string get_3270_text(const char *str); | |
| 248 | - string get_local_text(const char *str); | |
| 249 | - | |
| 250 | - protected: | |
| 251 | - session(); | |
| 252 | - | |
| 253 | - // Get/Set/Test without charset translation | |
| 254 | - virtual string get_text(int baddr = 0, size_t len = 1) = 0; | |
| 255 | - virtual string get_text_at(int row, int col, size_t sz) = 0; | |
| 256 | - virtual int set_text_at(int row, int col, const char *str) = 0; | |
| 257 | - virtual int cmp_text_at(int row, int col, const char *text) = 0; | |
| 258 | - virtual int wait_for_text_at(int row, int col, const char *key, int timeout); | |
| 259 | - virtual int emulate_input(const char *str) = 0; | |
| 260 | - | |
| 261 | - private: | |
| 262 | - | |
| 263 | - session * prev; | |
| 264 | - session * next; | |
| 265 | - | |
| 266 | - static session * first; | |
| 267 | - static session * last; | |
| 268 | - | |
| 269 | - static session * (*factory)(const char *name); | |
| 270 | - | |
| 271 | - static session * create_remote(const char *name) throw (std::exception); | |
| 272 | - | |
| 273 | -#ifdef HAVE_ICONV | |
| 274 | - iconv_t conv2Local; | |
| 275 | - iconv_t conv2Host; | |
| 276 | -#endif | |
| 277 | - | |
| 278 | - }; | |
| 279 | - | |
| 280 | - | |
| 281 | - } | |
| 282 | - | |
| 283 | - | |
| 284 | -#endif // PW3270_CLASS_H_INCLUDED |
| ... | ... | @@ -0,0 +1,301 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como class.h e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | +#ifndef PW3270_CLASS_H_INCLUDED | |
| 31 | + | |
| 32 | + #define PW3270_CLASS_H_INCLUDED 1 | |
| 33 | + | |
| 34 | + #ifdef WIN32 | |
| 35 | + #define SYSTEM_CHARSET "CP1252" | |
| 36 | + #else | |
| 37 | + #define SYSTEM_CHARSET "UTF-8" | |
| 38 | + #endif // WIN32 | |
| 39 | + | |
| 40 | + #include <exception> | |
| 41 | + #include <errno.h> | |
| 42 | + #include <lib3270/config.h> | |
| 43 | + #include <lib3270.h> | |
| 44 | + #include <lib3270/popup.h> | |
| 45 | + #include <lib3270/filetransfer.h> | |
| 46 | + | |
| 47 | + #ifdef HAVE_ICONV | |
| 48 | + #include <iconv.h> | |
| 49 | + #endif // HAVE_ICONV | |
| 50 | + | |
| 51 | + #include <string> | |
| 52 | + #include <stdarg.h> | |
| 53 | + #include <lib3270.h> | |
| 54 | + #include <errno.h> | |
| 55 | + | |
| 56 | + #ifdef DEBUG | |
| 57 | + #include <stdio.h> | |
| 58 | + #define trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr); | |
| 59 | + #else | |
| 60 | + #define trace(x, ...) // __VA_ARGS__ | |
| 61 | + #endif | |
| 62 | + | |
| 63 | + #ifndef ETIMEDOUT | |
| 64 | + #define ETIMEDOUT 1238 | |
| 65 | + #endif // !ETIMEDOUT | |
| 66 | + | |
| 67 | +/** | |
| 68 | + * @brief Obtém nome de variável como string. | |
| 69 | + * | |
| 70 | + */ | |
| 71 | + #define STRINGIZE(x) #x | |
| 72 | + | |
| 73 | +/** | |
| 74 | + * @brief Converte valor passado ao gcc via linha de comando em string. | |
| 75 | + * | |
| 76 | + * Macro usada para converter valores passados ao gcc via definições de | |
| 77 | + * linha de comando em uma string. Geralmente usado para converter os | |
| 78 | + * nomes de diretórios ajustados pelo ./configure. | |
| 79 | + * | |
| 80 | + * <http://stackoverflow.com/questions/2410976/how-to-define-a-string-in-gcc-command-line> | |
| 81 | + */ | |
| 82 | + #define STRINGIZE_VALUE_OF(x) STRINGIZE(x) | |
| 83 | + | |
| 84 | + #define PW3270_NAMESPACE h3270 | |
| 85 | + | |
| 86 | + namespace PW3270_NAMESPACE | |
| 87 | + { | |
| 88 | + using namespace std; | |
| 89 | + | |
| 90 | + class exception : public std::exception | |
| 91 | + { | |
| 92 | + public: | |
| 93 | + exception(int syserror = errno); | |
| 94 | + exception(const char *fmt, ...); | |
| 95 | + | |
| 96 | +#ifdef WIN32 | |
| 97 | + exception(DWORD error, const char *fmt, ...); | |
| 98 | +#else | |
| 99 | + exception(int error, const char *fmt, ...); | |
| 100 | +#endif // WIN32 | |
| 101 | + | |
| 102 | + virtual const char * what() const throw(); | |
| 103 | + | |
| 104 | + private: | |
| 105 | + char msg[4096]; | |
| 106 | + | |
| 107 | + }; | |
| 108 | + | |
| 109 | + class module | |
| 110 | + { | |
| 111 | + private: | |
| 112 | +#ifdef WIN32 | |
| 113 | + HMODULE hModule; | |
| 114 | + int get_datadir(LPSTR datadir); | |
| 115 | +#else | |
| 116 | + void * hModule; | |
| 117 | + | |
| 118 | +#endif // WIN32 | |
| 119 | + | |
| 120 | + public: | |
| 121 | + module(const char *name, const char *version = NULL) throw (std::exception); | |
| 122 | + ~module(); | |
| 123 | + | |
| 124 | + void * get_symbol(const char *name); | |
| 125 | + | |
| 126 | + }; | |
| 127 | + | |
| 128 | + class session | |
| 129 | + { | |
| 130 | + public: | |
| 131 | + | |
| 132 | + virtual ~session(); | |
| 133 | + | |
| 134 | + // Internal methods, used to init/deinit control tables. | |
| 135 | + static void init(); | |
| 136 | + static void deinit(); | |
| 137 | + | |
| 138 | + // Factory methods and settings | |
| 139 | + static session * start(const char *name = 0); | |
| 140 | + static session * create(const char *name = 0) throw (std::exception); | |
| 141 | + static session * create_local(H3270 *hSession) throw (std::exception); | |
| 142 | + static session * create_local() throw (std::exception); | |
| 143 | + | |
| 144 | + static session * get_default(void); | |
| 145 | + static bool has_default(void); | |
| 146 | + static void set_plugin(session * (*factory)(const char *name)); | |
| 147 | + | |
| 148 | + // Log management | |
| 149 | + void log(const char *fmt, ...); | |
| 150 | + void logva(const char *fmt, va_list args); | |
| 151 | + | |
| 152 | + // Information | |
| 153 | + virtual const string get_version(void); | |
| 154 | + virtual const string get_revision(void); | |
| 155 | + | |
| 156 | + virtual bool is_connected(void) = 0; | |
| 157 | + virtual bool is_ready(void) = 0; | |
| 158 | + | |
| 159 | + virtual LIB3270_CSTATE get_cstate(void) = 0; | |
| 160 | + virtual LIB3270_MESSAGE get_program_message(void) = 0; | |
| 161 | + virtual LIB3270_SSL_STATE get_secure(void) = 0; | |
| 162 | + | |
| 163 | + virtual int get_width(void) = 0; | |
| 164 | + virtual int get_height(void) = 0; | |
| 165 | + virtual int get_length(void) = 0; | |
| 166 | + | |
| 167 | + // Misc | |
| 168 | + virtual void set_unlock_delay(unsigned short ms) = 0; | |
| 169 | + | |
| 170 | + // charset | |
| 171 | +#ifdef WIN32 | |
| 172 | + void set_display_charset(const char *remote = 0, const char *local = "CP1252"); | |
| 173 | + static string win32_strerror(int e); | |
| 174 | +#else | |
| 175 | + void set_display_charset(const char *remote = 0, const char *local = "UTF-8"); | |
| 176 | +#endif // WIN32 | |
| 177 | + | |
| 178 | + virtual int set_host_charset(const char *charset) = 0; | |
| 179 | + virtual string get_host_charset(void) = 0; | |
| 180 | + virtual string get_display_charset(void); | |
| 181 | + | |
| 182 | + // Connection & Network | |
| 183 | + int connect(const char *host, time_t wait = 0); | |
| 184 | + int set_host(const char *host); | |
| 185 | + virtual int connect(void) = 0; | |
| 186 | + | |
| 187 | + virtual int set_url(const char *hostname) = 0; | |
| 188 | + virtual string get_url() = 0; | |
| 189 | + | |
| 190 | + virtual int disconnect(void) = 0; | |
| 191 | + virtual int wait_for_ready(int seconds) = 0; | |
| 192 | + virtual int wait(int seconds) = 0; | |
| 193 | + virtual int iterate(bool wait = true) = 0; | |
| 194 | + | |
| 195 | + // Ascii<->EBCDIC translation | |
| 196 | + virtual const char * asc2ebc(unsigned char *str, int sz = -1) = 0; | |
| 197 | + virtual const char * ebc2asc(unsigned char *str, int sz = -1) = 0; | |
| 198 | + string asc2ebc(string &str); | |
| 199 | + string ebc2asc(string &str); | |
| 200 | + | |
| 201 | + // Get/Set/Text with charset translation | |
| 202 | + string get_string(int baddr = 0, size_t len = -1); | |
| 203 | + string get_string_at(int row, int col, size_t sz); | |
| 204 | + int set_string_at(int row, int col, const char *str); | |
| 205 | + int cmp_string_at(int row, int col, const char *text); | |
| 206 | + int wait_for_string_at(int row, int col, const char *key, int timeout); | |
| 207 | + int input_string(const char *str); | |
| 208 | + | |
| 209 | + inline operator string() { | |
| 210 | + return get_string(); | |
| 211 | + } | |
| 212 | + | |
| 213 | + // Cursor management | |
| 214 | + virtual int set_cursor_position(int row, int col) = 0; | |
| 215 | + virtual int set_cursor_addr(int addr) = 0; | |
| 216 | + virtual int get_cursor_addr(void) = 0; | |
| 217 | + | |
| 218 | + // Toggle management | |
| 219 | + virtual int set_toggle(LIB3270_TOGGLE ix, bool value) = 0; | |
| 220 | + | |
| 221 | + // Keyboard actions | |
| 222 | + virtual int enter(void) = 0; | |
| 223 | + virtual int pfkey(int key) = 0; | |
| 224 | + virtual int pakey(int key) = 0; | |
| 225 | + | |
| 226 | + // Actions | |
| 227 | + virtual int quit(void) = 0; | |
| 228 | + virtual int action(const char *name) = 0; | |
| 229 | + | |
| 230 | + int erase(int mode); | |
| 231 | + | |
| 232 | + virtual int erase(void) = 0; | |
| 233 | + virtual int erase_eof(void) = 0; | |
| 234 | + virtual int erase_eol(void) = 0; | |
| 235 | + virtual int erase_input(void) = 0; | |
| 236 | + | |
| 237 | + virtual int print(void) = 0; | |
| 238 | + | |
| 239 | + // Field management | |
| 240 | + virtual int get_field_start(int baddr = -1) = 0; | |
| 241 | + virtual int get_field_len(int baddr = -1) = 0; | |
| 242 | + virtual int get_next_unprotected(int baddr = -1) = 0; | |
| 243 | + | |
| 244 | + virtual int get_is_protected(int baddr = -1) = 0; | |
| 245 | + virtual int get_is_protected_at(int row, int col) = 0; | |
| 246 | + | |
| 247 | + // Clipboard management | |
| 248 | + virtual int set_copy(const char *text); | |
| 249 | + virtual string get_copy(void); | |
| 250 | + | |
| 251 | + virtual string get_clipboard(void); | |
| 252 | + virtual int set_clipboard(const char *text); | |
| 253 | + | |
| 254 | + // Dialogs | |
| 255 | + virtual int popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...); | |
| 256 | + virtual string file_chooser_dialog(int action, const char *title, const char *extension, const char *filename); | |
| 257 | + | |
| 258 | + // File transfer | |
| 259 | + virtual int file_transfer(LIB3270_FT_OPTION options, const char *local, const char *remote, int lrecl = 0, int blksize = 0, int primspace = 0, int secspace = 0, int dft = 4096); | |
| 260 | + | |
| 261 | + // Charset translation | |
| 262 | + const char * get_encoding(void); | |
| 263 | + | |
| 264 | + string get_3270_text(const char *str); | |
| 265 | + string get_local_text(const char *str); | |
| 266 | + | |
| 267 | + protected: | |
| 268 | + session(); | |
| 269 | + | |
| 270 | + // Get/Set/Test without charset translation | |
| 271 | + virtual string get_text(int baddr = 0, size_t len = 1) = 0; | |
| 272 | + virtual string get_text_at(int row, int col, size_t sz) = 0; | |
| 273 | + virtual int set_text_at(int row, int col, const char *str) = 0; | |
| 274 | + virtual int cmp_text_at(int row, int col, const char *text) = 0; | |
| 275 | + virtual int wait_for_text_at(int row, int col, const char *key, int timeout); | |
| 276 | + virtual int emulate_input(const char *str) = 0; | |
| 277 | + | |
| 278 | + private: | |
| 279 | + | |
| 280 | + session * prev; | |
| 281 | + session * next; | |
| 282 | + | |
| 283 | + static session * first; | |
| 284 | + static session * last; | |
| 285 | + | |
| 286 | + static session * (*factory)(const char *name); | |
| 287 | + | |
| 288 | + static session * create_remote(const char *name) throw (std::exception); | |
| 289 | + | |
| 290 | +#ifdef HAVE_ICONV | |
| 291 | + iconv_t conv2Local; | |
| 292 | + iconv_t conv2Host; | |
| 293 | +#endif | |
| 294 | + | |
| 295 | + }; | |
| 296 | + | |
| 297 | + | |
| 298 | + } | |
| 299 | + | |
| 300 | + | |
| 301 | +#endif // PW3270_CLASS_H_INCLUDED | ... | ... |
| ... | ... | @@ -0,0 +1,172 @@ |
| 1 | +# | |
| 2 | +# "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | +# (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | +# aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | +# | |
| 6 | +# Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | +# | |
| 8 | +# Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | +# os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | +# Free Software Foundation. | |
| 11 | +# | |
| 12 | +# Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | +# GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | +# A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | +# obter mais detalhes. | |
| 16 | +# | |
| 17 | +# Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | +# programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple | |
| 19 | +# Place, Suite 330, Boston, MA, 02111-1307, USA | |
| 20 | +# | |
| 21 | +# Contatos: | |
| 22 | +# | |
| 23 | +# perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 24 | +# erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) | |
| 25 | +# | |
| 26 | + | |
| 27 | +MODULE_NAME=libpw3270cpp | |
| 28 | + | |
| 29 | +SOURCES=session.cc exception.cc local.cc remote.cc module.cc | |
| 30 | + | |
| 31 | +#---[ Configuration values ]------------------------------------------------------------- | |
| 32 | + | |
| 33 | +PACKAGE_NAME=@PACKAGE_NAME@ | |
| 34 | +PACKAGE_VERSION=@PACKAGE_VERSION@ | |
| 35 | +PACKAGE_TARNAME=@PACKAGE_TARNAME@ | |
| 36 | + | |
| 37 | +prefix=@prefix@ | |
| 38 | +exec_prefix=@exec_prefix@ | |
| 39 | +bindir=@bindir@ | |
| 40 | +sbindir=@sbindir@ | |
| 41 | +libdir=@libdir@ | |
| 42 | + | |
| 43 | +BASEDIR=@BASEDIR@ | |
| 44 | +SRCDIR=$(BASEDIR)/.src/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/src/$(MODULE_NAME) | |
| 45 | +POTDIR=$(BASEDIR)/.pot/$(PACKAGE_TARNAME)/$(MODULE_NAME) | |
| 46 | + | |
| 47 | +OBJDIR=.obj | |
| 48 | +OBJDBG=$(OBJDIR)/Debug | |
| 49 | +OBJRLS=$(OBJDIR)/Release | |
| 50 | + | |
| 51 | +MKDIR=@MKDIR_P@ | |
| 52 | +CC=@CXX@ | |
| 53 | +AR=@AR@ | |
| 54 | +XGETTEXT=@XGETTEXT@ | |
| 55 | +MSGCAT=@MSGCAT@ | |
| 56 | +INSTALL=@INSTALL@ | |
| 57 | +INSTALL_DATA=@INSTALL_DATA@ | |
| 58 | +INSTALL_PROGRAM=@INSTALL_PROGRAM@ | |
| 59 | + | |
| 60 | +CFLAGS=@CFLAGS@ @LIB3270_CFLAGS@ -Wno-deprecated-declarations @GTK_CFLAGS@ -I$(BASEDIR)/src/include/pw3270 | |
| 61 | + | |
| 62 | +#---[ Rules ]---------------------------------------------------------------------------- | |
| 63 | + | |
| 64 | +DEPENDS=$(BASEDIR)/src/include/*.h $(BASEDIR)/src/include/lib3270/*.h $(BASEDIR)/src/include/pw3270/*.h *.h Makefile | |
| 65 | + | |
| 66 | +$(OBJDBG)/%.o: \ | |
| 67 | + %.cc \ | |
| 68 | + $(DEPENDS) | |
| 69 | + | |
| 70 | + @echo $< ... | |
| 71 | + @$(MKDIR) `dirname $@` | |
| 72 | + @$(CC) $(CFLAGS) \ | |
| 73 | + @DBG_CFLAGS@ \ | |
| 74 | + -DBUILD_DATE=`date +"0x%Y%m%d"`\ | |
| 75 | + -o $@ -c $< | |
| 76 | + | |
| 77 | +$(OBJRLS)/%.o: \ | |
| 78 | + %.cc \ | |
| 79 | + $(DEPENDS) | |
| 80 | + | |
| 81 | + @echo $< ... | |
| 82 | + @$(MKDIR) `dirname $@` | |
| 83 | + @$(CC) $(CFLAGS) \ | |
| 84 | + @RLS_CFLAGS@ \ | |
| 85 | + -DBUILD_DATE=`date +"0x%Y%m%d"` \ | |
| 86 | + -o $@ -c $< | |
| 87 | + | |
| 88 | +$(POTDIR)/%.pot: %.c | |
| 89 | + | |
| 90 | + @echo $(notdir $@) ... | |
| 91 | + @$(MKDIR) `dirname $@` | |
| 92 | + @$(XGETTEXT) \ | |
| 93 | + --default-domain=$(PACKAGE) \ | |
| 94 | + --language=C \ | |
| 95 | + --keyword=_ \ | |
| 96 | + --keyword=N_ \ | |
| 97 | + --keyword=MSG_:2 \ | |
| 98 | + --output=$@ \ | |
| 99 | + $< | |
| 100 | + | |
| 101 | + @touch $@ | |
| 102 | + | |
| 103 | +#---[ Release Targets ]------------------------------------------------------------------ | |
| 104 | + | |
| 105 | +Release: \ | |
| 106 | + $(BASEDIR)/.obj/Release/$(MODULE_NAME).a | |
| 107 | + | |
| 108 | +install: \ | |
| 109 | + $(DESTDIR)$(libdir)/$(MODULE_NAME).a | |
| 110 | + | |
| 111 | +$(DESTDIR)$(libdir)/$(MODULE_NAME).a: \ | |
| 112 | + $(BASEDIR)/.obj/Release/$(MODULE_NAME).a | |
| 113 | + | |
| 114 | + @echo $@ ... | |
| 115 | + @$(MKDIR) `dirname $@` | |
| 116 | + @$(INSTALL_PROGRAM) $^ $@ | |
| 117 | + | |
| 118 | +$(BASEDIR)/.obj/Release/$(MODULE_NAME).a: \ | |
| 119 | + $(foreach SRC, $(basename $(SOURCES)), $(OBJRLS)/$(SRC).o) | |
| 120 | + | |
| 121 | + @echo $@ ... | |
| 122 | + @$(MKDIR) `dirname $@` | |
| 123 | + @$(AR) rcs $@ $^ | |
| 124 | + | |
| 125 | +pot: \ | |
| 126 | + $(BASEDIR)/.pot/$(PACKAGE_TARNAME)/$(MODULE_NAME).pot | |
| 127 | + | |
| 128 | +$(BASEDIR)/.pot/$(PACKAGE_TARNAME)/$(MODULE_NAME).pot: \ | |
| 129 | + $(foreach SRC, $(basename $(SOURCES)), $(POTDIR)/$(SRC).pot) | |
| 130 | + | |
| 131 | + @rm -f $@ | |
| 132 | + @mkdir -p `dirname $@` | |
| 133 | + @$(MSGCAT) --sort-output $^ > $@ | |
| 134 | + | |
| 135 | +$(SRCDIR): \ | |
| 136 | + clean | |
| 137 | + | |
| 138 | + @$(MKDIR) $@ | |
| 139 | + @$(INSTALL_DATA) *.cc *.h *.in *.cbp $@ | |
| 140 | + | |
| 141 | + | |
| 142 | +#---[ Debug Targets ]-------------------------------------------------------------------- | |
| 143 | + | |
| 144 | +Debug: \ | |
| 145 | + $(BASEDIR)/.obj/Debug/$(MODULE_NAME).a | |
| 146 | + | |
| 147 | +$(BASEDIR)/.obj/Debug/$(MODULE_NAME).a: \ | |
| 148 | + $(foreach SRC, $(basename $(SOURCES)), $(OBJDBG)/$(SRC).o) | |
| 149 | + | |
| 150 | + @echo $@ ... | |
| 151 | + @$(MKDIR) `dirname $@` | |
| 152 | + @$(AR) rcs $@ $^ | |
| 153 | + | |
| 154 | +#---[ Clean Targets]--------------------------------------------------------------------- | |
| 155 | + | |
| 156 | +cleanDebug: | |
| 157 | + | |
| 158 | + @rm -fr $(BASEDIR)/.obj/Debug/$(MODULE_NAME).a \ | |
| 159 | + $(OBJDBG) | |
| 160 | + | |
| 161 | +cleanRelease: | |
| 162 | + | |
| 163 | + @rm -fr $(BASEDIR)/.obj/Release/$(MODULE_NAME).a \ | |
| 164 | + $(OBJRLS) | |
| 165 | + | |
| 166 | + @rm -fr $(POTDIR) | |
| 167 | + | |
| 168 | +clean: \ | |
| 169 | + cleanDebug \ | |
| 170 | + cleanRelease | |
| 171 | + | |
| 172 | + | ... | ... |
| ... | ... | @@ -0,0 +1,50 @@ |
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | |
| 2 | +<CodeBlocks_project_file> | |
| 3 | + <FileVersion major="1" minor="6" /> | |
| 4 | + <Project> | |
| 5 | + <Option title="pw3270 Class Library" /> | |
| 6 | + <Option makefile_is_custom="1" /> | |
| 7 | + <Option pch_mode="2" /> | |
| 8 | + <Option compiler="gcc" /> | |
| 9 | + <Build> | |
| 10 | + <Target title="Debug"> | |
| 11 | + <Option output=".bin/Debug/testprogram" prefix_auto="1" extension_auto="1" /> | |
| 12 | + <Option object_output=".obj/Debug/" /> | |
| 13 | + <Option type="1" /> | |
| 14 | + <Option compiler="gcc" /> | |
| 15 | + <Compiler> | |
| 16 | + <Add option="-g" /> | |
| 17 | + </Compiler> | |
| 18 | + </Target> | |
| 19 | + <Target title="Release"> | |
| 20 | + <Option output=".bin/Release/pw3270 Class Library" prefix_auto="1" extension_auto="1" /> | |
| 21 | + <Option working_dir="" /> | |
| 22 | + <Option object_output=".obj/Release/" /> | |
| 23 | + <Option type="2" /> | |
| 24 | + <Option compiler="gcc" /> | |
| 25 | + <Compiler> | |
| 26 | + <Add option="-O2" /> | |
| 27 | + </Compiler> | |
| 28 | + <Linker> | |
| 29 | + <Add option="-s" /> | |
| 30 | + </Linker> | |
| 31 | + </Target> | |
| 32 | + </Build> | |
| 33 | + <Compiler> | |
| 34 | + <Add option="-Wall" /> | |
| 35 | + </Compiler> | |
| 36 | + <Unit filename="../include/pw3270cpp.h" /> | |
| 37 | + <Unit filename="Makefile.in" /> | |
| 38 | + <Unit filename="exception.cc" /> | |
| 39 | + <Unit filename="local.cc" /> | |
| 40 | + <Unit filename="private.h" /> | |
| 41 | + <Unit filename="remote.cc" /> | |
| 42 | + <Unit filename="session.cc" /> | |
| 43 | + <Unit filename="testprogram.cc" /> | |
| 44 | + <Extensions> | |
| 45 | + <envvars /> | |
| 46 | + <code_completion /> | |
| 47 | + <debugger /> | |
| 48 | + </Extensions> | |
| 49 | + </Project> | |
| 50 | +</CodeBlocks_project_file> | ... | ... |
| ... | ... | @@ -0,0 +1,100 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como exception.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include <stdarg.h> | |
| 31 | + #include <stdio.h> | |
| 32 | + #include <string.h> | |
| 33 | + | |
| 34 | + #include <pw3270/class.h> | |
| 35 | + | |
| 36 | +/*--[ Implement ]--------------------------------------------------------------------------------------------------*/ | |
| 37 | + | |
| 38 | + namespace PW3270_NAMESPACE | |
| 39 | + { | |
| 40 | + | |
| 41 | + exception::exception(int syscode) | |
| 42 | + { | |
| 43 | + snprintf(this->msg,4095,"%s",strerror(syscode)); | |
| 44 | + } | |
| 45 | + | |
| 46 | + exception::exception(const char *fmt, ...) | |
| 47 | + { | |
| 48 | + va_list arg_ptr; | |
| 49 | + va_start(arg_ptr, fmt); | |
| 50 | + vsnprintf(this->msg,4095,fmt,arg_ptr); | |
| 51 | + va_end(arg_ptr); | |
| 52 | + } | |
| 53 | + | |
| 54 | +#ifdef WIN32 | |
| 55 | + exception::exception(DWORD error, const char *fmt, ...) | |
| 56 | + { | |
| 57 | + LPVOID lpMsgBuf = 0; | |
| 58 | + char * ptr; | |
| 59 | + size_t szPrefix; | |
| 60 | + | |
| 61 | + va_list arg_ptr; | |
| 62 | + va_start(arg_ptr, fmt); | |
| 63 | + vsnprintf(this->msg,4095,fmt,arg_ptr); | |
| 64 | + va_end(arg_ptr); | |
| 65 | + | |
| 66 | + szPrefix = strlen(this->msg); | |
| 67 | + | |
| 68 | + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); | |
| 69 | + | |
| 70 | + for(ptr= (char *) lpMsgBuf;*ptr && *ptr != '\n';ptr++); | |
| 71 | + *ptr = 0; | |
| 72 | + | |
| 73 | + snprintf(this->msg+szPrefix,4095-szPrefix,": %s (rc=%d)",(char *) lpMsgBuf,(int) error); | |
| 74 | + | |
| 75 | + LocalFree(lpMsgBuf); | |
| 76 | + | |
| 77 | + } | |
| 78 | +#else | |
| 79 | + exception::exception(int error, const char *fmt, ...) | |
| 80 | + { | |
| 81 | + size_t szPrefix; | |
| 82 | + | |
| 83 | + va_list arg_ptr; | |
| 84 | + va_start(arg_ptr, fmt); | |
| 85 | + vsnprintf(this->msg,4095,fmt,arg_ptr); | |
| 86 | + va_end(arg_ptr); | |
| 87 | + | |
| 88 | + szPrefix = strlen(this->msg); | |
| 89 | + | |
| 90 | + snprintf(this->msg+szPrefix,4095-szPrefix,": %s (rc=%d)",strerror(error),(int) error); | |
| 91 | + | |
| 92 | + } | |
| 93 | +#endif // WIN32 | |
| 94 | + | |
| 95 | + const char * exception::what() const throw() | |
| 96 | + { | |
| 97 | + return this->msg; | |
| 98 | + } | |
| 99 | + | |
| 100 | + } | ... | ... |
| ... | ... | @@ -0,0 +1,599 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como local.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | +#if defined WIN32 | |
| 31 | + | |
| 32 | + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx | |
| 33 | + #ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
| 34 | + #define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000 | |
| 35 | + #endif // LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
| 36 | + | |
| 37 | + #ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
| 38 | + #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100 | |
| 39 | + #endif // LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
| 40 | + | |
| 41 | + #include <windows.h> | |
| 42 | + | |
| 43 | +#else | |
| 44 | + | |
| 45 | + #include <dlfcn.h> | |
| 46 | + | |
| 47 | +#endif | |
| 48 | + | |
| 49 | +#include "private.h" | |
| 50 | + | |
| 51 | +#include <lib3270/log.h> | |
| 52 | +#include <lib3270/popup.h> | |
| 53 | +#include <string.h> | |
| 54 | +#include <stdio.h> | |
| 55 | + | |
| 56 | +#ifdef HAVE_SYSLOG | |
| 57 | + #include <syslog.h> | |
| 58 | + #include <stdarg.h> | |
| 59 | +#endif // HAVE_SYSLOG | |
| 60 | + | |
| 61 | +/*--[ Implement ]--------------------------------------------------------------------------------------------------*/ | |
| 62 | + | |
| 63 | + extern "C" | |
| 64 | + { | |
| 65 | + static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) | |
| 66 | + { | |
| 67 | + #ifdef HAVE_SYSLOG | |
| 68 | + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
| 69 | + vsyslog(LOG_INFO,fmt,args); | |
| 70 | + closelog(); | |
| 71 | + #endif // HAVE_SYSLOG | |
| 72 | + } | |
| 73 | + | |
| 74 | + static void tracehandler(H3270 *session, const char *fmt, va_list args) | |
| 75 | + { | |
| 76 | + #ifdef HAVE_SYSLOG | |
| 77 | + | |
| 78 | + #define MAX_LOG_LENGTH 200 | |
| 79 | + | |
| 80 | + static char line[MAX_LOG_LENGTH+1]; | |
| 81 | + char temp[MAX_LOG_LENGTH]; | |
| 82 | + char * ptr; | |
| 83 | + size_t len = strlen(line); | |
| 84 | + | |
| 85 | + vsnprintf(temp,MAX_LOG_LENGTH-len,fmt,args); | |
| 86 | + | |
| 87 | + ptr = strchr(temp,'\n'); | |
| 88 | + if(!ptr) | |
| 89 | + { | |
| 90 | + strncat(line,temp,MAX_LOG_LENGTH); | |
| 91 | + if(strlen(line) >= MAX_LOG_LENGTH) | |
| 92 | + { | |
| 93 | + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
| 94 | + syslog(LOG_INFO,"%s",line); | |
| 95 | + closelog(); | |
| 96 | + *line = 0; | |
| 97 | + } | |
| 98 | + return; | |
| 99 | + } | |
| 100 | + | |
| 101 | + *ptr = 0; | |
| 102 | + strncat(line,temp,MAX_LOG_LENGTH); | |
| 103 | + | |
| 104 | + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
| 105 | + syslog(LOG_DEBUG,"%s",line); | |
| 106 | + closelog(); | |
| 107 | + | |
| 108 | + strncpy(line,ptr+1,MAX_LOG_LENGTH); | |
| 109 | + | |
| 110 | + #endif // HAVE_SYSLOG | |
| 111 | + } | |
| 112 | + | |
| 113 | + } | |
| 114 | + | |
| 115 | + namespace PW3270_NAMESPACE | |
| 116 | + { | |
| 117 | + | |
| 118 | + class local : public session, protected module, protected recursive_mutex | |
| 119 | + { | |
| 120 | + private: | |
| 121 | + | |
| 122 | + // Lib3270 entry points | |
| 123 | + const char * (*_get_version)(void); | |
| 124 | + LIB3270_CSTATE (*_get_connection_state)(H3270 *h); | |
| 125 | + LIB3270_MESSAGE (*_get_program_message)(H3270 *h); | |
| 126 | + LIB3270_SSL_STATE (*_get_secure)(H3270 *h); | |
| 127 | + | |
| 128 | + | |
| 129 | + int (*_disconnect)(H3270 *h); | |
| 130 | + int (*_connect)(H3270 *h,int wait); | |
| 131 | + const char (*_set_url)(H3270 *h, const char *n); | |
| 132 | + const char * (*_get_url)(H3270 *h, char *str, int len); | |
| 133 | + int (*_is_connected)(H3270 *h); | |
| 134 | + void (*_main_iterate)(H3270 *h, int wait); | |
| 135 | + int (*_wait)(H3270 *hSession, int seconds); | |
| 136 | + int (*_enter)(H3270 *hSession); | |
| 137 | + int (*_pfkey)(H3270 *hSession, int key); | |
| 138 | + int (*_pakey)(H3270 *hSession, int key); | |
| 139 | + int (*_wait_for_ready)(H3270 *hSession, int seconds); | |
| 140 | + char * (*_get_text)(H3270 *h, int offset, int len); | |
| 141 | + char * (*_get_text_at)(H3270 *h, int row, int col, int len); | |
| 142 | + int (*_cmp_text_at)(H3270 *h, int row, int col, const char *text); | |
| 143 | + int (*_set_text_at)(H3270 *h, int row, int col, const unsigned char *str); | |
| 144 | + int (*_is_ready)(H3270 *h); | |
| 145 | + int (*_set_cursor_position)(H3270 *h, int row, int col); | |
| 146 | + int (*_set_toggle)(H3270 *h, LIB3270_TOGGLE ix, int value); | |
| 147 | + int (*_get_field_start)(H3270 *h, int baddr); | |
| 148 | + int (*_get_field_len)(H3270 *h, int baddr); | |
| 149 | + int (*_set_cursor_addr)(H3270 *h, int addr); | |
| 150 | + int (*_get_cursor_addr)(H3270 *h); | |
| 151 | + int (*_emulate_input)(H3270 *session, const char *s, int len, int pasting); | |
| 152 | + int (*_get_next_unprotected)(H3270 *hSession, int baddr0); | |
| 153 | + int (*_get_is_protected)(H3270 *hSession, int baddr); | |
| 154 | + int (*_get_is_protected_at)(H3270 *hSession, int row, int col); | |
| 155 | + void (*_popup_va)(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, va_list); | |
| 156 | + void * (*_free)(void *); | |
| 157 | + const char * (*_get_display_charset)(H3270 *hSession); | |
| 158 | + int (*_set_host_charset)(H3270 *hSession, const char *name); | |
| 159 | + const char * (*_get_host_charset)(H3270 *hSession); | |
| 160 | + int (*_print)(H3270 *hSession); | |
| 161 | + int (*_erase)(H3270 *hSession); | |
| 162 | + int (*_erase_eof)(H3270 *hSession); | |
| 163 | + int (*_erase_eol)(H3270 *hSession); | |
| 164 | + int (*_erase_input)(H3270 *hSession); | |
| 165 | + int (*_action)(H3270 *hSession, const char *name); | |
| 166 | + int (*_set_unlock_delay)(H3270 *hSession, unsigned short ms); | |
| 167 | + | |
| 168 | + int (*_get_width)(H3270 *hSession); | |
| 169 | + int (*_get_height)(H3270 *hSession); | |
| 170 | + int (*_get_length)(H3270 *hSession); | |
| 171 | + | |
| 172 | + const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, int sz); | |
| 173 | + const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, int sz); | |
| 174 | + | |
| 175 | + protected: | |
| 176 | + | |
| 177 | + H3270 * hSession; | |
| 178 | + | |
| 179 | + void load_methods() { | |
| 180 | + | |
| 181 | + void (*set_log_handler)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list)); | |
| 182 | + void (*set_trace_handler)( void (*handler)(H3270 *session, const char *fmt, va_list args) ); | |
| 183 | + | |
| 184 | + struct _call | |
| 185 | + { | |
| 186 | + void **entry; | |
| 187 | + const char * name; | |
| 188 | + } call[] = | |
| 189 | + { | |
| 190 | + { (void **) & set_log_handler, "lib3270_set_log_handler" }, | |
| 191 | + { (void **) & set_trace_handler, "lib3270_set_trace_handler" }, | |
| 192 | + | |
| 193 | + { (void **) & _is_connected, "lib3270_is_connected" }, | |
| 194 | + { (void **) & _get_connection_state, "lib3270_get_connection_state" }, | |
| 195 | + { (void **) & _get_program_message, "lib3270_get_program_message" }, | |
| 196 | + { (void **) & _get_secure, "lib3270_get_secure" }, | |
| 197 | + | |
| 198 | + { (void **) & _get_version, "lib3270_get_version" }, | |
| 199 | + { (void **) & _disconnect, "lib3270_disconnect" }, | |
| 200 | + { (void **) & _connect, "lib3270_connect" }, | |
| 201 | + { (void **) & _set_url, "lib3270_set_url" }, | |
| 202 | + { (void **) & _get_url, "lib3270_get_url" }, | |
| 203 | + { (void **) & _main_iterate, "lib3270_main_iterate" }, | |
| 204 | + { (void **) & _wait, "lib3270_wait" }, | |
| 205 | + { (void **) & _enter, "lib3270_enter" }, | |
| 206 | + { (void **) & _pfkey, "lib3270_pfkey" }, | |
| 207 | + { (void **) & _pakey, "lib3270_pakey" }, | |
| 208 | + { (void **) & _wait_for_ready, "lib3270_wait_for_ready" }, | |
| 209 | + { (void **) & _get_text, "lib3270_get_text" }, | |
| 210 | + { (void **) & _get_text_at, "lib3270_get_text_at" }, | |
| 211 | + { (void **) & _cmp_text_at, "lib3270_cmp_text_at" }, | |
| 212 | + { (void **) & _set_text_at, "lib3270_set_string_at" }, | |
| 213 | + { (void **) & _is_ready, "lib3270_is_ready" }, | |
| 214 | + { (void **) & _set_cursor_position, "lib3270_set_cursor_position" }, | |
| 215 | + { (void **) & _set_toggle, "lib3270_set_toggle" }, | |
| 216 | + { (void **) & _get_field_start, "lib3270_get_field_start" }, | |
| 217 | + { (void **) & _get_field_len, "lib3270_get_field_len" }, | |
| 218 | + { (void **) & _set_cursor_addr, "lib3270_set_cursor_address" }, | |
| 219 | + { (void **) & _get_cursor_addr, "lib3270_get_cursor_address" }, | |
| 220 | + { (void **) & _emulate_input, "lib3270_emulate_input" }, | |
| 221 | + { (void **) & _get_next_unprotected, "lib3270_get_next_unprotected" }, | |
| 222 | + { (void **) & _get_is_protected, "lib3270_get_is_protected" }, | |
| 223 | + { (void **) & _get_is_protected_at, "lib3270_get_is_protected_at" }, | |
| 224 | + { (void **) & _popup_va, "lib3270_popup_va" }, | |
| 225 | + { (void **) & _free, "lib3270_free" }, | |
| 226 | + { (void **) & _get_display_charset, "lib3270_get_display_charset" }, | |
| 227 | + { (void **) & _set_host_charset, "lib3270_set_host_charset" }, | |
| 228 | + { (void **) & _get_host_charset, "lib3270_get_host_charset" }, | |
| 229 | + | |
| 230 | + { (void **) & _erase, "lib3270_erase" }, | |
| 231 | + { (void **) & _erase_eof, "lib3270_eraseeof" }, | |
| 232 | + { (void **) & _erase_eol, "lib3270_eraseeol" }, | |
| 233 | + { (void **) & _erase_input, "lib3270_eraseinput" }, | |
| 234 | + | |
| 235 | + { (void **) & _print, "lib3270_print" }, | |
| 236 | + { (void **) & _ebc2asc, "lib3270_ebc2asc" }, | |
| 237 | + { (void **) & _asc2ebc, "lib3270_asc2ebc" }, | |
| 238 | + | |
| 239 | + { (void **) & _action, "lib3270_action" }, | |
| 240 | + { (void **) & _set_unlock_delay, "lib3270_set_unlock_delay" }, | |
| 241 | + | |
| 242 | + { (void **) & _get_width, "lib3270_get_width" }, | |
| 243 | + { (void **) & _get_height, "lib3270_get_height" }, | |
| 244 | + { (void **) & _get_length, "lib3270_get_length" }, | |
| 245 | + | |
| 246 | + }; | |
| 247 | + | |
| 248 | + for(unsigned int f = 0; f < (sizeof (call) / sizeof ((call)[0]));f++) | |
| 249 | + { | |
| 250 | + *call[f].entry = (void *) get_symbol(call[f].name); | |
| 251 | + if(!*call[f].entry) | |
| 252 | + throw exception("Can't find symbol %s",call[f].name); | |
| 253 | + } | |
| 254 | + | |
| 255 | + // Get Session handle, setup base callbacks | |
| 256 | + set_log_handler(loghandler); | |
| 257 | + set_trace_handler(tracehandler); | |
| 258 | + | |
| 259 | + set_display_charset(); | |
| 260 | + | |
| 261 | + } | |
| 262 | + | |
| 263 | + public: | |
| 264 | + | |
| 265 | + local() throw(std::exception) : module("lib3270",PACKAGE_VERSION) | |
| 266 | + { | |
| 267 | + } | |
| 268 | + | |
| 269 | + virtual ~local() | |
| 270 | + { | |
| 271 | + } | |
| 272 | + | |
| 273 | + bool is_connected(void) | |
| 274 | + { | |
| 275 | + return _is_connected(hSession); | |
| 276 | + } | |
| 277 | + | |
| 278 | + LIB3270_CSTATE get_cstate(void) | |
| 279 | + { | |
| 280 | + return _get_connection_state(hSession); | |
| 281 | + } | |
| 282 | + | |
| 283 | + LIB3270_MESSAGE get_program_message(void) { | |
| 284 | + return _get_program_message(hSession); | |
| 285 | + } | |
| 286 | + | |
| 287 | + LIB3270_SSL_STATE get_secure(void) { | |
| 288 | + return _get_secure(hSession); | |
| 289 | + }; | |
| 290 | + | |
| 291 | + int connect(void) | |
| 292 | + { | |
| 293 | + this->lock(); | |
| 294 | + int rc = _connect(hSession,0); | |
| 295 | + this->unlock(); | |
| 296 | + | |
| 297 | + return rc; | |
| 298 | + } | |
| 299 | + | |
| 300 | + int set_url(const char *uri) | |
| 301 | + { | |
| 302 | + return (_set_url(hSession,uri) == 0); | |
| 303 | + } | |
| 304 | + | |
| 305 | + string get_url() | |
| 306 | + { | |
| 307 | + char buffer[1024]; | |
| 308 | + return string(_get_url(hSession,buffer,sizeof(buffer))); | |
| 309 | + } | |
| 310 | + | |
| 311 | + int disconnect(void) | |
| 312 | + { | |
| 313 | + this->lock(); | |
| 314 | + int rc = _disconnect(hSession); | |
| 315 | + this->unlock(); | |
| 316 | + | |
| 317 | + return rc; | |
| 318 | + } | |
| 319 | + | |
| 320 | + bool is_ready(void) | |
| 321 | + { | |
| 322 | + return _is_ready(hSession) != 0; | |
| 323 | + } | |
| 324 | + | |
| 325 | + int wait_for_ready(int seconds) | |
| 326 | + { | |
| 327 | + return _wait_for_ready(hSession,seconds); | |
| 328 | + } | |
| 329 | + | |
| 330 | + int wait(int seconds) | |
| 331 | + { | |
| 332 | + return _wait(hSession,seconds); | |
| 333 | + } | |
| 334 | + | |
| 335 | + int iterate(bool wait) | |
| 336 | + { | |
| 337 | + this->lock(); | |
| 338 | + _main_iterate(hSession,wait); | |
| 339 | + this->unlock(); | |
| 340 | + return 0; | |
| 341 | + } | |
| 342 | + | |
| 343 | + string get_text_at(int row, int col, size_t sz) | |
| 344 | + { | |
| 345 | + string rc; | |
| 346 | + char * ptr = _get_text_at(hSession,row,col,sz); | |
| 347 | + | |
| 348 | + if(ptr) | |
| 349 | + { | |
| 350 | + rc.assign(ptr); | |
| 351 | + _free(ptr); | |
| 352 | + } | |
| 353 | + | |
| 354 | + return rc; | |
| 355 | + } | |
| 356 | + | |
| 357 | + int set_text_at(int row, int col, const char *str) | |
| 358 | + { | |
| 359 | + return _set_text_at(hSession,row,col,(const unsigned char *) str); | |
| 360 | + } | |
| 361 | + | |
| 362 | + int cmp_text_at(int row, int col, const char *text) | |
| 363 | + { | |
| 364 | + return _cmp_text_at(hSession,row,col,text); | |
| 365 | + } | |
| 366 | + | |
| 367 | + string get_text(int offset, size_t len) | |
| 368 | + { | |
| 369 | + string rc; | |
| 370 | + char * ptr = _get_text(hSession,offset,len); | |
| 371 | + | |
| 372 | + if(ptr) | |
| 373 | + { | |
| 374 | + rc.assign(ptr); | |
| 375 | + _free(ptr); | |
| 376 | + } | |
| 377 | + | |
| 378 | + return rc; | |
| 379 | + } | |
| 380 | + | |
| 381 | + int set_cursor_position(int row, int col) | |
| 382 | + { | |
| 383 | + return _set_cursor_position(hSession,row,col); | |
| 384 | + } | |
| 385 | + | |
| 386 | + int set_cursor_addr(int addr) | |
| 387 | + { | |
| 388 | + return _set_cursor_addr(hSession,addr); | |
| 389 | + } | |
| 390 | + | |
| 391 | + int get_cursor_addr(void) | |
| 392 | + { | |
| 393 | + return _get_cursor_addr(hSession); | |
| 394 | + } | |
| 395 | + | |
| 396 | + int enter(void) | |
| 397 | + { | |
| 398 | + return _enter(hSession); | |
| 399 | + } | |
| 400 | + | |
| 401 | + int pfkey(int key) | |
| 402 | + { | |
| 403 | + return _pfkey(hSession,key); | |
| 404 | + } | |
| 405 | + | |
| 406 | + int pakey(int key) | |
| 407 | + { | |
| 408 | + return _pakey(hSession,key); | |
| 409 | + } | |
| 410 | + | |
| 411 | + int quit(void) | |
| 412 | + { | |
| 413 | + return EINVAL; | |
| 414 | + } | |
| 415 | + | |
| 416 | + int set_toggle(LIB3270_TOGGLE ix, bool value) | |
| 417 | + { | |
| 418 | + return _set_toggle(hSession, ix, (int) value); | |
| 419 | + } | |
| 420 | + | |
| 421 | + int emulate_input(const char *str) | |
| 422 | + { | |
| 423 | + return _emulate_input(hSession,str,-1,1); | |
| 424 | + } | |
| 425 | + | |
| 426 | + int get_field_start(int baddr) | |
| 427 | + { | |
| 428 | + return _get_field_start(hSession,baddr); | |
| 429 | + } | |
| 430 | + | |
| 431 | + int get_field_len(int baddr) | |
| 432 | + { | |
| 433 | + return _get_field_len(hSession,baddr); | |
| 434 | + } | |
| 435 | + | |
| 436 | + int get_next_unprotected(int baddr) | |
| 437 | + { | |
| 438 | + return _get_next_unprotected(hSession,baddr); | |
| 439 | + } | |
| 440 | + | |
| 441 | + int get_is_protected(int baddr) | |
| 442 | + { | |
| 443 | + return _get_is_protected(hSession,baddr); | |
| 444 | + } | |
| 445 | + | |
| 446 | + int get_is_protected_at(int row, int col) | |
| 447 | + { | |
| 448 | + return _get_is_protected_at(hSession,row,col); | |
| 449 | + } | |
| 450 | + | |
| 451 | + int popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...) | |
| 452 | + { | |
| 453 | + va_list args; | |
| 454 | + va_start(args, fmt); | |
| 455 | + _popup_va(hSession, id, title, message, fmt, args); | |
| 456 | + va_end(args); | |
| 457 | + return 0; | |
| 458 | + } | |
| 459 | + | |
| 460 | + string get_display_charset(void) | |
| 461 | + { | |
| 462 | + return string(_get_display_charset(hSession)); | |
| 463 | + } | |
| 464 | + | |
| 465 | + int set_host_charset(const char *charset) | |
| 466 | + { | |
| 467 | + return _set_host_charset(hSession,charset); | |
| 468 | + } | |
| 469 | + | |
| 470 | + string get_host_charset(void) | |
| 471 | + { | |
| 472 | + return string(_get_host_charset(hSession)); | |
| 473 | + } | |
| 474 | + | |
| 475 | + int erase(void) | |
| 476 | + { | |
| 477 | + return _erase(hSession); | |
| 478 | + } | |
| 479 | + | |
| 480 | + int erase_eof(void) | |
| 481 | + { | |
| 482 | + return _erase_eof(hSession); | |
| 483 | + } | |
| 484 | + | |
| 485 | + int erase_eol(void) | |
| 486 | + { | |
| 487 | + return _erase_eol(hSession); | |
| 488 | + } | |
| 489 | + | |
| 490 | + int erase_input(void) | |
| 491 | + { | |
| 492 | + return _erase_input(hSession); | |
| 493 | + } | |
| 494 | + | |
| 495 | + int print(void) | |
| 496 | + { | |
| 497 | + return _print(hSession); | |
| 498 | + } | |
| 499 | + | |
| 500 | + | |
| 501 | + const char * asc2ebc(unsigned char *str, int sz) | |
| 502 | + { | |
| 503 | + return _asc2ebc(hSession,str,sz); | |
| 504 | + } | |
| 505 | + | |
| 506 | + const char * ebc2asc(unsigned char *str, int sz) | |
| 507 | + { | |
| 508 | + return _ebc2asc(hSession,str,sz); | |
| 509 | + } | |
| 510 | + | |
| 511 | + int action(const char *name) | |
| 512 | + { | |
| 513 | + return _action(hSession,name); | |
| 514 | + } | |
| 515 | + | |
| 516 | + void set_unlock_delay(unsigned short ms) | |
| 517 | + { | |
| 518 | + _set_unlock_delay(hSession,ms); | |
| 519 | + } | |
| 520 | + | |
| 521 | + int get_width(void) { | |
| 522 | + return _get_width(hSession); | |
| 523 | + } | |
| 524 | + | |
| 525 | + int get_height(void) { | |
| 526 | + return _get_height(hSession); | |
| 527 | + } | |
| 528 | + | |
| 529 | + int get_length(void) { | |
| 530 | + return _get_length(hSession); | |
| 531 | + } | |
| 532 | + | |
| 533 | + }; | |
| 534 | + | |
| 535 | + session * session::create_local(void) throw (std::exception) | |
| 536 | + { | |
| 537 | + class obj : public local { | |
| 538 | + public: | |
| 539 | + obj() : local() { | |
| 540 | + | |
| 541 | + H3270 * (*lib3270_new)(const char *) = (H3270 * (*)(const char *)) get_symbol("lib3270_session_new"); | |
| 542 | + | |
| 543 | + if(!lib3270_new) | |
| 544 | + throw exception("Can't find symbol %s","lib3270_session_new"); | |
| 545 | + | |
| 546 | + this->hSession = lib3270_new(""); | |
| 547 | + | |
| 548 | + load_methods(); | |
| 549 | + | |
| 550 | + } | |
| 551 | + | |
| 552 | + virtual ~obj() { | |
| 553 | + | |
| 554 | + this->lock(); | |
| 555 | + | |
| 556 | + if(is_connected()) { | |
| 557 | + disconnect(); | |
| 558 | + } | |
| 559 | + | |
| 560 | + try | |
| 561 | + { | |
| 562 | + static void (*session_free)(H3270 *h) = (void (*)(H3270 *)) get_symbol("lib3270_session_free"); | |
| 563 | + | |
| 564 | + if(session_free && this->hSession) | |
| 565 | + session_free(this->hSession); | |
| 566 | + | |
| 567 | + this->hSession = 0; | |
| 568 | + | |
| 569 | + } | |
| 570 | + catch(exception e) { } | |
| 571 | + | |
| 572 | + this->unlock(); | |
| 573 | + | |
| 574 | + } | |
| 575 | + }; | |
| 576 | + | |
| 577 | + return new obj(); | |
| 578 | + } | |
| 579 | + | |
| 580 | + session * session::create_local(H3270 *hSession) throw (std::exception) | |
| 581 | + { | |
| 582 | + class obj : public local { | |
| 583 | + public: | |
| 584 | + obj(H3270 *hSession) : local() | |
| 585 | + { | |
| 586 | + this->hSession = hSession; | |
| 587 | + load_methods(); | |
| 588 | + } | |
| 589 | + | |
| 590 | + virtual ~obj() { | |
| 591 | + } | |
| 592 | + | |
| 593 | + }; | |
| 594 | + | |
| 595 | + return new obj(hSession); | |
| 596 | + } | |
| 597 | + | |
| 598 | + } | |
| 599 | + | ... | ... |
| ... | ... | @@ -0,0 +1,217 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como module.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | +#if defined WIN32 | |
| 31 | + | |
| 32 | + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx | |
| 33 | + #ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
| 34 | + #define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000 | |
| 35 | + #endif // LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
| 36 | + | |
| 37 | + #ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
| 38 | + #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100 | |
| 39 | + #endif // LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
| 40 | + | |
| 41 | + #include <windows.h> | |
| 42 | + | |
| 43 | +#else | |
| 44 | + | |
| 45 | + #include <dlfcn.h> | |
| 46 | + | |
| 47 | +#endif | |
| 48 | + | |
| 49 | +#include <pw3270/class.h> | |
| 50 | + | |
| 51 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 52 | + | |
| 53 | + | |
| 54 | +namespace PW3270_NAMESPACE | |
| 55 | +{ | |
| 56 | + | |
| 57 | +#ifdef WIN32 | |
| 58 | + int module::get_datadir(LPSTR datadir) | |
| 59 | + { | |
| 60 | + HKEY hKey = 0; | |
| 61 | + unsigned long datalen = strlen(datadir); | |
| 62 | + | |
| 63 | + *datadir = 0; | |
| 64 | + | |
| 65 | + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) | |
| 66 | + { | |
| 67 | + unsigned long datatype; // #defined in winnt.h (predefined types 0-11) | |
| 68 | + if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) != ERROR_SUCCESS) | |
| 69 | + *datadir = 0; | |
| 70 | + RegCloseKey(hKey); | |
| 71 | + } | |
| 72 | + | |
| 73 | + return *datadir; | |
| 74 | + } | |
| 75 | +#endif // WIN32 | |
| 76 | + | |
| 77 | + module::module(const char *name, const char *version) throw (std::exception) | |
| 78 | + { | |
| 79 | + string dllname = name; | |
| 80 | + | |
| 81 | +#ifdef WIN32 | |
| 82 | + | |
| 83 | + dllname += ".dll"; | |
| 84 | + if(version) | |
| 85 | + { | |
| 86 | + dllname += "."; | |
| 87 | + dllname += version; | |
| 88 | + } | |
| 89 | + | |
| 90 | + HMODULE kernel; | |
| 91 | + HANDLE cookie = NULL; | |
| 92 | + DWORD rc; | |
| 93 | + HANDLE WINAPI (*AddDllDirectory)(PCWSTR NewDirectory); | |
| 94 | + BOOL WINAPI (*RemoveDllDirectory)(HANDLE Cookie); | |
| 95 | + UINT errorMode; | |
| 96 | + char datadir[4096]; | |
| 97 | + char buffer[4096]; | |
| 98 | + | |
| 99 | + kernel = LoadLibrary("kernel32.dll"); | |
| 100 | + AddDllDirectory = (HANDLE WINAPI (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory"); | |
| 101 | + RemoveDllDirectory = (BOOL WINAPI (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory"); | |
| 102 | + | |
| 103 | + // Notify user in case of error loading protocol DLL | |
| 104 | + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v=vs.85).aspx | |
| 105 | + errorMode = SetErrorMode(1); | |
| 106 | + | |
| 107 | + memset(datadir,' ',4095); | |
| 108 | + datadir[4095] = 0; | |
| 109 | + | |
| 110 | + if(get_datadir(datadir)) | |
| 111 | + { | |
| 112 | + trace("Datadir=[%s] AddDllDirectory=%p RemoveDllDirectory=%p\n",datadir,AddDllDirectory,RemoveDllDirectory); | |
| 113 | + | |
| 114 | + if(AddDllDirectory) | |
| 115 | + { | |
| 116 | + wchar_t *path = (wchar_t *) malloc(4096*sizeof(wchar_t)); | |
| 117 | + mbstowcs(path, datadir, 4095); | |
| 118 | + cookie = AddDllDirectory(path); | |
| 119 | + free(path); | |
| 120 | + } | |
| 121 | + | |
| 122 | +#ifdef DEBUG | |
| 123 | + snprintf(buffer,4096,"%s\\.bin\\Debug\\%s",datadir,dllname.c_str()); | |
| 124 | +#else | |
| 125 | + snprintf(buffer,4096,"%s\\%s",datadir,dllname.c_str()); | |
| 126 | +#endif // DEBUG | |
| 127 | + | |
| 128 | + trace("Loading [%s] [%s]",buffer,datadir); | |
| 129 | + hModule = LoadLibrary(buffer); | |
| 130 | + | |
| 131 | + trace("Module=%p rc=%d",hModule,(int) GetLastError()); | |
| 132 | + | |
| 133 | + if(hModule == NULL) | |
| 134 | + { | |
| 135 | + // Enable DLL error popup and try again with full path | |
| 136 | + SetErrorMode(0); | |
| 137 | + hModule = LoadLibraryEx(buffer,NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS|LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); | |
| 138 | + } | |
| 139 | + | |
| 140 | + rc = GetLastError(); | |
| 141 | + | |
| 142 | + trace("%s hModule=%p rc=%d",buffer,hModule,(int) rc); | |
| 143 | + } | |
| 144 | + else | |
| 145 | + { | |
| 146 | + hModule = LoadLibrary(dllname.c_str()); | |
| 147 | + rc = GetLastError(); | |
| 148 | + } | |
| 149 | + | |
| 150 | + SetErrorMode(errorMode); | |
| 151 | + | |
| 152 | + trace("%s hModule=%p rc=%d",dllname.c_str(),hModule,(int) rc); | |
| 153 | + | |
| 154 | + if(cookie && RemoveDllDirectory) | |
| 155 | + RemoveDllDirectory(cookie); | |
| 156 | + | |
| 157 | + if(kernel) | |
| 158 | + FreeLibrary(kernel); | |
| 159 | + | |
| 160 | + if(!hModule) | |
| 161 | + { | |
| 162 | + throw exception("%s: %s",dllname.c_str(),session::win32_strerror(rc).c_str()); | |
| 163 | + } | |
| 164 | + | |
| 165 | +#else | |
| 166 | + dllname += ".so"; | |
| 167 | + if(version) | |
| 168 | + { | |
| 169 | + dllname += "."; | |
| 170 | + dllname += version; | |
| 171 | + } | |
| 172 | + | |
| 173 | + dlerror(); | |
| 174 | + | |
| 175 | + hModule = dlopen(dllname.c_str(), RTLD_NOW); | |
| 176 | + if(!hModule) | |
| 177 | + throw exception("Can't load lib3270: %s",dllname.c_str()); | |
| 178 | + | |
| 179 | +#endif // WIN32 | |
| 180 | + | |
| 181 | + | |
| 182 | + } | |
| 183 | + | |
| 184 | + module::~module() | |
| 185 | + { | |
| 186 | +#ifdef WIN32 | |
| 187 | + FreeLibrary(hModule); | |
| 188 | +#else | |
| 189 | + dlclose(hModule); | |
| 190 | +#endif // WIN32 | |
| 191 | + } | |
| 192 | + | |
| 193 | + | |
| 194 | + void * module::get_symbol(const char *name) | |
| 195 | + { | |
| 196 | + void *symbol; | |
| 197 | + | |
| 198 | +#ifdef WIN32 | |
| 199 | + | |
| 200 | + symbol = (void *) GetProcAddress(hModule,name); | |
| 201 | + | |
| 202 | + if(!symbol) | |
| 203 | + throw exception("Can't load symbol %s",name); | |
| 204 | + | |
| 205 | +#else | |
| 206 | + symbol = dlsym(hModule,name); | |
| 207 | + | |
| 208 | + if(!symbol) | |
| 209 | + throw exception("Can't load symbol %s dlerror was \"%s\"",name,dlerror()); | |
| 210 | + | |
| 211 | +#endif // WIN32 | |
| 212 | + | |
| 213 | + return symbol; | |
| 214 | + } | |
| 215 | + | |
| 216 | +} | |
| 217 | + | ... | ... |
| ... | ... | @@ -0,0 +1,113 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como private.h e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | +#ifndef PRIVATE_H_INCLUDED | |
| 31 | + | |
| 32 | + #define PRIVATE_H_INCLUDED | |
| 33 | + | |
| 34 | + #include <cstring> | |
| 35 | + #include <pw3270cpp.h> | |
| 36 | + | |
| 37 | + #if defined(_WIN32) | |
| 38 | + | |
| 39 | + class recursive_mutex { | |
| 40 | + private: | |
| 41 | + HANDLE hMutex; | |
| 42 | + | |
| 43 | + public: | |
| 44 | + recursive_mutex() { | |
| 45 | + hMutex = CreateMutex(NULL,FALSE,NULL); | |
| 46 | + }; | |
| 47 | + | |
| 48 | + ~recursive_mutex() { | |
| 49 | + CloseHandle(hMutex); | |
| 50 | + }; | |
| 51 | + | |
| 52 | + void lock(void) { | |
| 53 | + WaitForSingleObject(hMutex,INFINITE); | |
| 54 | + }; | |
| 55 | + | |
| 56 | + void unlock(void) { | |
| 57 | + ReleaseMutex(hMutex); | |
| 58 | + }; | |
| 59 | + | |
| 60 | + bool try_lock(void) { | |
| 61 | + if(WaitForSingleObject(hMutex,1) == WAIT_OBJECT_0) | |
| 62 | + return true; | |
| 63 | + return false; | |
| 64 | + }; | |
| 65 | + }; | |
| 66 | + | |
| 67 | + #elif __cplusplus < 201103L | |
| 68 | + | |
| 69 | + #define nullptr NULL | |
| 70 | + | |
| 71 | + class recursive_mutex { | |
| 72 | + private: | |
| 73 | + pthread_mutex_t mtx; | |
| 74 | + pthread_mutexattr_t mtxAttr; | |
| 75 | + | |
| 76 | + public: | |
| 77 | + recursive_mutex() { | |
| 78 | + | |
| 79 | + memset(&mtx,0,sizeof(mtx)); | |
| 80 | + memset(&mtxAttr,0,sizeof(mtxAttr)); | |
| 81 | + | |
| 82 | + pthread_mutexattr_init(&mtxAttr); | |
| 83 | + pthread_mutexattr_settype(&mtxAttr, PTHREAD_MUTEX_RECURSIVE); | |
| 84 | + pthread_mutex_init(&mtx, &mtxAttr); | |
| 85 | + }; | |
| 86 | + | |
| 87 | + ~recursive_mutex() { | |
| 88 | + pthread_mutex_destroy(&mtx); | |
| 89 | + }; | |
| 90 | + | |
| 91 | + void lock(void) { | |
| 92 | + pthread_mutex_lock(&mtx); | |
| 93 | + }; | |
| 94 | + | |
| 95 | + void unlock(void) { | |
| 96 | + pthread_mutex_unlock(&mtx); | |
| 97 | + }; | |
| 98 | + | |
| 99 | + bool try_lock(void) { | |
| 100 | + return pthread_mutex_trylock(&mtx) == 0; | |
| 101 | + }; | |
| 102 | + }; | |
| 103 | + | |
| 104 | + #else | |
| 105 | + | |
| 106 | + #include <mutex> | |
| 107 | + | |
| 108 | + #endif // !c11 | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | +#endif // PRIVATE_H_INCLUDED | ... | ... |
| ... | ... | @@ -0,0 +1,1599 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como remote.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include <lib3270/config.h> | |
| 31 | + #include <iostream> | |
| 32 | + | |
| 33 | + #if defined(HAVE_DBUS) | |
| 34 | + #include <stdio.h> | |
| 35 | + #include <dbus/dbus.h> | |
| 36 | + #include <string.h> | |
| 37 | + #include <malloc.h> | |
| 38 | + #include <sys/types.h> | |
| 39 | + #include <unistd.h> | |
| 40 | + #include <limits.h> | |
| 41 | + | |
| 42 | + #ifndef DBUS_TIMEOUT_INFINITE | |
| 43 | + #define DBUS_TIMEOUT_INFINITE ((int) 0x7fffffff) | |
| 44 | + #endif // !DBUS_TIMEOUT_INFINITE | |
| 45 | + | |
| 46 | + #endif // HAVE_DBUS | |
| 47 | + | |
| 48 | + #if defined(WIN32) | |
| 49 | + #include <windows.h> | |
| 50 | + #include <pw3270/ipcpackets.h> | |
| 51 | + #include <process.h> | |
| 52 | + #else | |
| 53 | + #define HLLAPI_PACKET_IS_CONNECTED "isConnected" | |
| 54 | + #define HLLAPI_PACKET_GET_CSTATE "getConnectionState" | |
| 55 | + #define HLLAPI_PACKET_GET_PROGRAM_MESSAGE "getProgramMessage" | |
| 56 | + #define HLLAPI_PACKET_GET_SSL_STATE "getSecureState" | |
| 57 | + #define HLLAPI_PACKET_IS_READY "isReady" | |
| 58 | + #define HLLAPI_PACKET_DISCONNECT "disconnect" | |
| 59 | + #define HLLAPI_PACKET_GET_HOST "getURL" | |
| 60 | + #define HLLAPI_PACKET_SET_HOST "setURL" | |
| 61 | + #define HLLAPI_PACKET_GET_CURSOR "getCursorAddress" | |
| 62 | + #define HLLAPI_PACKET_GET_WIDTH "getScreenWidth" | |
| 63 | + #define HLLAPI_PACKET_GET_HEIGHT "getScreenHeight" | |
| 64 | + #define HLLAPI_PACKET_GET_LENGTH "getScreenLength" | |
| 65 | + #define HLLAPI_PACKET_ENTER "enter" | |
| 66 | + #define HLLAPI_PACKET_QUIT "quit" | |
| 67 | + #define HLLAPI_PACKET_ERASE "erase" | |
| 68 | + #define HLLAPI_PACKET_ERASE_EOF "eraseEOF" | |
| 69 | + #define HLLAPI_PACKET_ERASE_EOL "eraseEOL" | |
| 70 | + #define HLLAPI_PACKET_ERASE_INPUT "eraseInput" | |
| 71 | + #define HLLAPI_PACKET_PRINT "print" | |
| 72 | + #define HLLAPI_PACKET_ASC2EBC "asc2ebc" | |
| 73 | + #define HLLAPI_PACKET_EBC2ASC "ebc2asc" | |
| 74 | + #define HLLAPI_PACKET_SET_UNLOCK_DELAY "setUnlockDelay" | |
| 75 | + #endif // WIN32 | |
| 76 | + | |
| 77 | + #include <pw3270/class.h> | |
| 78 | + #include <lib3270/log.h> | |
| 79 | + | |
| 80 | +#if defined(HAVE_DBUS) | |
| 81 | + static const char * prefix_dest = "br.com.bb."; | |
| 82 | + static const char * prefix_path = "/br/com/bb/"; | |
| 83 | +#endif // HAVE_DBUS | |
| 84 | + | |
| 85 | +/*--[ Implement ]--------------------------------------------------------------------------------------------------*/ | |
| 86 | + | |
| 87 | + namespace PW3270_NAMESPACE | |
| 88 | + { | |
| 89 | + | |
| 90 | + class remote : public session | |
| 91 | + { | |
| 92 | + private: | |
| 93 | + | |
| 94 | +#if defined(WIN32) | |
| 95 | + | |
| 96 | + HANDLE hPipe; | |
| 97 | + | |
| 98 | + int query_intval(HLLAPI_PACKET id) | |
| 99 | + { | |
| 100 | + struct hllapi_packet_query query = { id }; | |
| 101 | + struct hllapi_packet_result response; | |
| 102 | + DWORD cbSize = sizeof(query); | |
| 103 | + if(TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL)) | |
| 104 | + return response.rc; | |
| 105 | + | |
| 106 | + throw exception(GetLastError(),"%s","Transaction error"); | |
| 107 | + } | |
| 108 | + | |
| 109 | + int query_strval(HLLAPI_PACKET id, unsigned char *buffer, size_t sz) | |
| 110 | + { | |
| 111 | + DWORD cbSize = sizeof(struct hllapi_packet_text)+sz; | |
| 112 | + struct hllapi_packet_text * query; | |
| 113 | + struct hllapi_packet_text * response; | |
| 114 | + int rc = -1; | |
| 115 | + | |
| 116 | + query = (struct hllapi_packet_text *) malloc(cbSize+2); | |
| 117 | + memset(query,0,cbSize+2); | |
| 118 | + query->packet_id = id; | |
| 119 | + memcpy(query->text,buffer,sz); | |
| 120 | + | |
| 121 | + response = (struct hllapi_packet_text *) malloc(cbSize+2); | |
| 122 | + memset(response,0,cbSize+2); | |
| 123 | + | |
| 124 | + if(TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, cbSize, &cbSize,NULL)) | |
| 125 | + { | |
| 126 | + if(response->packet_id) | |
| 127 | + { | |
| 128 | + rc = response->packet_id; | |
| 129 | + } | |
| 130 | + else | |
| 131 | + { | |
| 132 | + rc = 0; | |
| 133 | + strncpy((char *) buffer,response->text,sz); | |
| 134 | + } | |
| 135 | + } | |
| 136 | + | |
| 137 | + free(response); | |
| 138 | + free(query); | |
| 139 | + | |
| 140 | + return rc; | |
| 141 | + | |
| 142 | + } | |
| 143 | + | |
| 144 | + string query_string(void *query, size_t szQuery, size_t len) | |
| 145 | + { | |
| 146 | + struct hllapi_packet_text * response; | |
| 147 | + DWORD sz = sizeof(struct hllapi_packet_text)+len; | |
| 148 | + DWORD cbSize = (DWORD) sz; | |
| 149 | + string s; | |
| 150 | + char buffer[sz+2]; | |
| 151 | + | |
| 152 | + memset(buffer,0,sz+2); | |
| 153 | + | |
| 154 | + response = (struct hllapi_packet_text *) buffer; | |
| 155 | + | |
| 156 | + if(TransactNamedPipe(hPipe,(LPVOID) query, szQuery, response, sz, &cbSize,NULL)) | |
| 157 | + { | |
| 158 | + buffer[min(cbSize,sz)] = 0; | |
| 159 | + | |
| 160 | + trace("TransactNamedPipe call %d returns \"%s\"",(int) *( (unsigned char *) query), response->text); | |
| 161 | + | |
| 162 | + if(!response->packet_id) | |
| 163 | + s.assign(response->text); | |
| 164 | + } | |
| 165 | + else | |
| 166 | + { | |
| 167 | + trace("TransactNamedPipe error on call %d",(int) *( (unsigned char *) query)); | |
| 168 | + s.assign(""); | |
| 169 | + } | |
| 170 | + | |
| 171 | + return s; | |
| 172 | + } | |
| 173 | + | |
| 174 | + int query_intval(void *pkt, size_t szQuery, bool dynamic = false) | |
| 175 | + { | |
| 176 | + struct hllapi_packet_result response; | |
| 177 | + DWORD cbSize = (DWORD) szQuery; | |
| 178 | + BOOL status; | |
| 179 | + | |
| 180 | + status = TransactNamedPipe(hPipe,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL); | |
| 181 | + | |
| 182 | + if(dynamic) | |
| 183 | + free(pkt); | |
| 184 | + | |
| 185 | + if(status) | |
| 186 | + return response.rc; | |
| 187 | + | |
| 188 | + throw exception(GetLastError(),"%s","Transaction error"); | |
| 189 | + | |
| 190 | + } | |
| 191 | + | |
| 192 | + void set_intval(HLLAPI_PACKET id, int value) | |
| 193 | + { | |
| 194 | + struct hllapi_packet_set_int packet; | |
| 195 | + DWORD cbSize = (DWORD) sizeof(packet); | |
| 196 | + BOOL status; | |
| 197 | + | |
| 198 | + memset(&packet,0,sizeof(packet)); | |
| 199 | + packet.packet_id = id; | |
| 200 | + packet.value = value; | |
| 201 | + | |
| 202 | + status = TransactNamedPipe(hPipe,(LPVOID) &packet, cbSize, &packet, sizeof(packet), &cbSize,NULL); | |
| 203 | + | |
| 204 | + if(!status) | |
| 205 | + throw exception(GetLastError(),"%s","Transaction error"); | |
| 206 | + | |
| 207 | + } | |
| 208 | + | |
| 209 | + | |
| 210 | +#elif defined(HAVE_DBUS) | |
| 211 | + | |
| 212 | + DBusConnection * conn; | |
| 213 | + char * dest; | |
| 214 | + char * path; | |
| 215 | + char * intf; | |
| 216 | + int sequence; | |
| 217 | + | |
| 218 | + DBusMessage * create_message(const char *method) | |
| 219 | + { | |
| 220 | + DBusMessage * msg = dbus_message_new_method_call( this->dest, // Destination | |
| 221 | + this->path, // Path | |
| 222 | + this->intf, // Interface | |
| 223 | + method); // method | |
| 224 | + | |
| 225 | + if (!msg) | |
| 226 | + throw exception("Error creating DBUS message for method %s",method); | |
| 227 | + | |
| 228 | + return msg; | |
| 229 | + | |
| 230 | + } | |
| 231 | + | |
| 232 | + DBusMessage * call(DBusMessage *msg) | |
| 233 | + { | |
| 234 | + DBusMessage * reply; | |
| 235 | + DBusError error; | |
| 236 | + | |
| 237 | + dbus_error_init(&error); | |
| 238 | + reply = dbus_connection_send_with_reply_and_block(conn,msg,10000,&error); | |
| 239 | + dbus_message_unref(msg); | |
| 240 | + | |
| 241 | + if(!reply) | |
| 242 | + { | |
| 243 | + exception e = exception("%s",error.message); | |
| 244 | + dbus_error_free(&error); | |
| 245 | + throw e; | |
| 246 | + } | |
| 247 | + return reply; | |
| 248 | + } | |
| 249 | + | |
| 250 | + string get_string(DBusMessage * msg) | |
| 251 | + { | |
| 252 | + string rc; | |
| 253 | + | |
| 254 | + if(msg) | |
| 255 | + { | |
| 256 | + DBusMessageIter iter; | |
| 257 | + | |
| 258 | + if(dbus_message_iter_init(msg, &iter)) | |
| 259 | + { | |
| 260 | + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) | |
| 261 | + { | |
| 262 | + const char * str; | |
| 263 | + dbus_message_iter_get_basic(&iter, &str); | |
| 264 | + trace("Response: [%s]",str); | |
| 265 | + rc.assign(str); | |
| 266 | + dbus_message_unref(msg); | |
| 267 | + return rc; | |
| 268 | + } | |
| 269 | + | |
| 270 | + exception e = exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | |
| 271 | + dbus_message_unref(msg); | |
| 272 | + | |
| 273 | + throw e; | |
| 274 | + | |
| 275 | + } | |
| 276 | + | |
| 277 | + } | |
| 278 | + | |
| 279 | + return rc; | |
| 280 | + } | |
| 281 | + | |
| 282 | + string query_string(const char *method) | |
| 283 | + { | |
| 284 | + return get_string(call(create_message(method))); | |
| 285 | + } | |
| 286 | + | |
| 287 | + int get_intval(DBusMessage * msg) | |
| 288 | + { | |
| 289 | + if(msg) | |
| 290 | + { | |
| 291 | + DBusMessageIter iter; | |
| 292 | + | |
| 293 | + if(dbus_message_iter_init(msg, &iter)) | |
| 294 | + { | |
| 295 | + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32) | |
| 296 | + { | |
| 297 | + dbus_int32_t iSigned; | |
| 298 | + dbus_message_iter_get_basic(&iter, &iSigned); | |
| 299 | + dbus_message_unref(msg); | |
| 300 | + return (int) iSigned; | |
| 301 | + } | |
| 302 | + | |
| 303 | + exception e = exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | |
| 304 | + | |
| 305 | + dbus_message_unref(msg); | |
| 306 | + throw e; | |
| 307 | + return -1; | |
| 308 | + } | |
| 309 | + dbus_message_unref(msg); | |
| 310 | + } | |
| 311 | + return -1; | |
| 312 | + } | |
| 313 | + | |
| 314 | + int query_intval(const char *method) | |
| 315 | + { | |
| 316 | + return get_intval(call(create_message(method))); | |
| 317 | + } | |
| 318 | + | |
| 319 | + int query_intval(const char *method, int first_arg_type, ...) | |
| 320 | + { | |
| 321 | + va_list var_args; | |
| 322 | + DBusMessage * msg = dbus_message_new_method_call( this->dest, // Destination | |
| 323 | + this->path, // Path | |
| 324 | + this->intf, // Interface | |
| 325 | + method); // method | |
| 326 | + | |
| 327 | + if (!msg) | |
| 328 | + { | |
| 329 | + throw exception("Error creating DBUS message for method %s",method); | |
| 330 | + return -1; | |
| 331 | + } | |
| 332 | + | |
| 333 | + va_start(var_args, first_arg_type); | |
| 334 | + dbus_message_append_args_valist(msg,first_arg_type,var_args); | |
| 335 | + va_end(var_args); | |
| 336 | + | |
| 337 | + return get_intval(call(msg)); | |
| 338 | + } | |
| 339 | + | |
| 340 | + int query_strval(const char *method, unsigned char *buffer, size_t sz) | |
| 341 | + { | |
| 342 | + DBusMessage * outMsg = create_message(method); | |
| 343 | + | |
| 344 | + if(outMsg) | |
| 345 | + { | |
| 346 | + dbus_message_append_args(outMsg, DBUS_TYPE_STRING, &buffer, DBUS_TYPE_INVALID); | |
| 347 | + | |
| 348 | + DBusMessage * rspMsg = call(outMsg); | |
| 349 | + if(rspMsg) | |
| 350 | + { | |
| 351 | + DBusMessageIter iter; | |
| 352 | + | |
| 353 | + if(dbus_message_iter_init(rspMsg, &iter)) | |
| 354 | + { | |
| 355 | + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) | |
| 356 | + { | |
| 357 | + const char * str; | |
| 358 | + dbus_message_iter_get_basic(&iter, &str); | |
| 359 | + trace("Response: [%s]",str); | |
| 360 | + strncpy((char *) buffer,str,sz); | |
| 361 | + dbus_message_unref(rspMsg); | |
| 362 | + return 0; | |
| 363 | + } | |
| 364 | + | |
| 365 | + exception e = exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | |
| 366 | + dbus_message_unref(rspMsg); | |
| 367 | + | |
| 368 | + throw e; | |
| 369 | + | |
| 370 | + } | |
| 371 | + } | |
| 372 | + } | |
| 373 | + | |
| 374 | + return -1; | |
| 375 | + } | |
| 376 | + | |
| 377 | + void set_intval(const char *method, int value) | |
| 378 | + { | |
| 379 | + DBusMessage * outMsg = create_message(method); | |
| 380 | + | |
| 381 | + if(outMsg) | |
| 382 | + { | |
| 383 | + dbus_int32_t v = (dbus_int32_t) value; | |
| 384 | + | |
| 385 | + dbus_message_append_args(outMsg, DBUS_TYPE_INT32, &v, DBUS_TYPE_INVALID); | |
| 386 | + | |
| 387 | + DBusMessage * rspMsg = call(outMsg); | |
| 388 | + dbus_message_unref(rspMsg); | |
| 389 | + | |
| 390 | + } | |
| 391 | + } | |
| 392 | + | |
| 393 | +#else | |
| 394 | + | |
| 395 | + | |
| 396 | + int query_intval(const char *method) | |
| 397 | + { | |
| 398 | + throw exception("Call to unimplemented RPC method \"%s\"",method); | |
| 399 | + return -1; | |
| 400 | + } | |
| 401 | + | |
| 402 | + int query_strval(const char *method, unsigned char *buffer, size_t sz) | |
| 403 | + { | |
| 404 | + throw exception("Call to unimplemented RPC method \"%s\"",method); | |
| 405 | + return -1; | |
| 406 | + } | |
| 407 | + | |
| 408 | + | |
| 409 | +#endif | |
| 410 | + | |
| 411 | + public: | |
| 412 | + | |
| 413 | +#if defined(HAVE_DBUS) | |
| 414 | + const char * makeBusName(char *buffer, size_t sz) | |
| 415 | + { | |
| 416 | + size_t bytes = strlen(buffer); | |
| 417 | + char * ptr = buffer; | |
| 418 | + int val; | |
| 419 | + | |
| 420 | + sz -= 2; | |
| 421 | + | |
| 422 | + // First uses the object ID | |
| 423 | + val = this->sequence; | |
| 424 | + while(bytes < sz && val > 0) | |
| 425 | + { | |
| 426 | + *(ptr++) = 'a'+(val % 25); | |
| 427 | + val /= 25; | |
| 428 | + bytes++; | |
| 429 | + } | |
| 430 | + *(ptr++) = '.'; | |
| 431 | + | |
| 432 | + // Then the PID | |
| 433 | + val = (int) getpid(); | |
| 434 | + while(bytes < sz && val > 0) | |
| 435 | + { | |
| 436 | + *(ptr++) = 'a'+(val % 25); | |
| 437 | + val /= 25; | |
| 438 | + bytes++; | |
| 439 | + } | |
| 440 | + *(ptr++) = '.'; | |
| 441 | + | |
| 442 | + // And last, the project info | |
| 443 | + strncpy(ptr,intf,sz); | |
| 444 | + | |
| 445 | + trace("Busname=\"%s\" sequence=%d this=%p",buffer,sequence,this); | |
| 446 | + | |
| 447 | + return buffer; | |
| 448 | + | |
| 449 | + } | |
| 450 | +#endif // HAVE_DBUS | |
| 451 | + | |
| 452 | +#if defined(WIN32) | |
| 453 | + | |
| 454 | + static string getRegistryKey(const char *name) throw (std::exception) | |
| 455 | + { | |
| 456 | + char buffer[4096]; | |
| 457 | + HKEY hKey = 0; | |
| 458 | + unsigned long datalen = sizeof(buffer); | |
| 459 | + | |
| 460 | + debug("%s(%s)",__FUNCTION__,name); | |
| 461 | + | |
| 462 | + *buffer = 0; | |
| 463 | + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) != ERROR_SUCCESS) | |
| 464 | + { | |
| 465 | + throw exception("Can't open key %s","HKLM\\Software\\pw3270"); | |
| 466 | + } | |
| 467 | + else | |
| 468 | + { | |
| 469 | + unsigned long datatype; // #defined in winnt.h (predefined types 0-11) | |
| 470 | + | |
| 471 | + if(RegQueryValueExA(hKey,name,NULL,&datatype,(LPBYTE) buffer,&datalen) != ERROR_SUCCESS) | |
| 472 | + *buffer = 0; | |
| 473 | + RegCloseKey(hKey); | |
| 474 | + } | |
| 475 | + | |
| 476 | + return string(buffer); | |
| 477 | + | |
| 478 | + } | |
| 479 | + | |
| 480 | +#endif // defined | |
| 481 | + | |
| 482 | + remote(const char *session) throw (std::exception) | |
| 483 | + { | |
| 484 | +#if defined(WIN32) | |
| 485 | + static DWORD dwMode = PIPE_READMODE_MESSAGE; | |
| 486 | + char buffer[4096]; | |
| 487 | + char * str; | |
| 488 | + char * ptr; | |
| 489 | + time_t timer = time(0)+1; | |
| 490 | + | |
| 491 | + hPipe = INVALID_HANDLE_VALUE; | |
| 492 | + | |
| 493 | + trace("%s(%s)",__FUNCTION__,session); | |
| 494 | + | |
| 495 | + if(strcasecmp(session,"start") == 0 || strcasecmp(session,"new") == 0) | |
| 496 | + { | |
| 497 | + // Start a new session | |
| 498 | + string appName = getRegistryKey("appName"); | |
| 499 | + char buffer[80]; | |
| 500 | + STARTUPINFO si; | |
| 501 | + PROCESS_INFORMATION pi; | |
| 502 | + | |
| 503 | + // Get application path | |
| 504 | + | |
| 505 | + if(!appName.size()) | |
| 506 | + { | |
| 507 | + throw exception("key %s\\appName is invalid","HKLM\\Software\\pw3270"); | |
| 508 | + return; | |
| 509 | + } | |
| 510 | + | |
| 511 | + trace("%s appname=%s\n",__FUNCTION__,appName.c_str()); | |
| 512 | + | |
| 513 | + snprintf(buffer,79,"%s --session=\"H%06d\"",appName.c_str(),getpid()); | |
| 514 | + | |
| 515 | + ZeroMemory( &si, sizeof(si) ); | |
| 516 | + si.cb = sizeof(si); | |
| 517 | + ZeroMemory( &pi, sizeof(pi) ); | |
| 518 | + | |
| 519 | + // si.dwFlags = STARTF_PREVENTPINNING; | |
| 520 | + trace("App: %s",appName.c_str()); | |
| 521 | + trace("CmdLine: %s",buffer); | |
| 522 | + | |
| 523 | + if(CreateProcess(NULL,buffer,NULL,NULL,0,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi)) | |
| 524 | + { | |
| 525 | + CloseHandle( pi.hProcess ); | |
| 526 | + CloseHandle( pi.hThread ); | |
| 527 | + } | |
| 528 | + else | |
| 529 | + { | |
| 530 | + throw exception("Can't start %s",appName.c_str()); | |
| 531 | + return; | |
| 532 | + } | |
| 533 | + | |
| 534 | + snprintf(buffer,4095,"H%06d_a",getpid()); | |
| 535 | + str = strdup(buffer); | |
| 536 | + | |
| 537 | + // Até 20 segundos para o processo iniciar. | |
| 538 | + timer = time(0)+20; | |
| 539 | + | |
| 540 | + } | |
| 541 | + else | |
| 542 | + { | |
| 543 | + // Use an existing session | |
| 544 | + str = strdup(session); | |
| 545 | + | |
| 546 | + // Convert session name | |
| 547 | + for(ptr=str;*ptr;ptr++) | |
| 548 | + { | |
| 549 | + if(*ptr == ':') | |
| 550 | + *ptr = '_'; | |
| 551 | + else | |
| 552 | + *ptr = tolower(*ptr); | |
| 553 | + } | |
| 554 | + | |
| 555 | + // Wait? | |
| 556 | + int delay; | |
| 557 | + | |
| 558 | + try | |
| 559 | + { | |
| 560 | + delay = atoi(getRegistryKey("hllapiWait").c_str()); | |
| 561 | + } | |
| 562 | + catch(std::exception &e) | |
| 563 | + { | |
| 564 | + delay = 0; | |
| 565 | + } | |
| 566 | + | |
| 567 | + if(delay) { | |
| 568 | + timer = time(0) + delay; | |
| 569 | + } | |
| 570 | + | |
| 571 | + | |
| 572 | + } | |
| 573 | + | |
| 574 | + snprintf(buffer,4095,"\\\\.\\pipe\\%s",str); | |
| 575 | + | |
| 576 | + free(str); | |
| 577 | + | |
| 578 | + trace("Searching for \"%s\"",buffer); | |
| 579 | + | |
| 580 | + hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); | |
| 581 | + | |
| 582 | + if(hPipe == INVALID_HANDLE_VALUE) | |
| 583 | + { | |
| 584 | + // Cant get session, wait. | |
| 585 | + while(hPipe == INVALID_HANDLE_VALUE && time(0) < timer) | |
| 586 | + { | |
| 587 | + hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); | |
| 588 | + Sleep(1); | |
| 589 | + } | |
| 590 | + } | |
| 591 | + | |
| 592 | + if(hPipe == INVALID_HANDLE_VALUE) | |
| 593 | + { | |
| 594 | + throw exception("Can´t create service pipe %s",buffer); | |
| 595 | + } | |
| 596 | + else if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) | |
| 597 | + { | |
| 598 | + exception e = exception(GetLastError(),"%s","Can´t set pipe state"); | |
| 599 | + CloseHandle(hPipe); | |
| 600 | + hPipe = INVALID_HANDLE_VALUE; | |
| 601 | + throw e; | |
| 602 | + } | |
| 603 | + | |
| 604 | +#elif defined(HAVE_DBUS) | |
| 605 | + | |
| 606 | + static int sq = 0; | |
| 607 | + DBusError err; | |
| 608 | + int rc; | |
| 609 | + char * str = strdup(session); | |
| 610 | + char * ptr; | |
| 611 | + char busname[4096]; | |
| 612 | + | |
| 613 | + this->sequence = (++sq) + time(0); | |
| 614 | + | |
| 615 | + trace("%s str=%p sequence=%d",__FUNCTION__,str,sequence); | |
| 616 | + | |
| 617 | + for(ptr=str;*ptr;ptr++) | |
| 618 | + *ptr = tolower(*ptr); | |
| 619 | + | |
| 620 | + ptr = strchr(str,':'); | |
| 621 | + | |
| 622 | + if(ptr) | |
| 623 | + { | |
| 624 | + size_t sz; | |
| 625 | + | |
| 626 | + *(ptr++) = 0; | |
| 627 | + | |
| 628 | + // Build destination | |
| 629 | + sz = strlen(ptr)+strlen(str)+strlen(prefix_dest)+2; | |
| 630 | + dest = (char *) malloc(sz+1); | |
| 631 | + strncpy(dest,prefix_dest,sz); | |
| 632 | + strncat(dest,str,sz); | |
| 633 | + strncat(dest,".",sz); | |
| 634 | + strncat(dest,ptr,sz); | |
| 635 | + | |
| 636 | + // Build path | |
| 637 | + sz = strlen(str)+strlen(prefix_path); | |
| 638 | + path = (char *) malloc(sz+1); | |
| 639 | + strncpy(path,prefix_path,sz); | |
| 640 | + strncat(path,str,sz); | |
| 641 | + | |
| 642 | + // Build intf | |
| 643 | + sz = strlen(str)+strlen(prefix_dest)+1; | |
| 644 | + intf = (char *) malloc(sz+1); | |
| 645 | + strncpy(intf,prefix_dest,sz); | |
| 646 | + strncat(intf,str,sz); | |
| 647 | + | |
| 648 | + } | |
| 649 | + else | |
| 650 | + { | |
| 651 | + size_t sz; | |
| 652 | + | |
| 653 | + // Build destination | |
| 654 | + sz = strlen(str)+strlen(prefix_dest)+2; | |
| 655 | + dest = (char *) malloc(sz+1); | |
| 656 | + strncpy(dest,prefix_dest,sz); | |
| 657 | + strncat(dest,str,sz); | |
| 658 | + | |
| 659 | + // Build path | |
| 660 | + sz = strlen(str)+strlen(prefix_path); | |
| 661 | + path = (char *) malloc(sz+1); | |
| 662 | + strncpy(path,prefix_path,sz); | |
| 663 | + strncat(path,str,sz); | |
| 664 | + | |
| 665 | + // Build intf | |
| 666 | + sz = strlen(str)+strlen(prefix_dest)+1; | |
| 667 | + intf = (char *) malloc(sz+1); | |
| 668 | + strncpy(intf,prefix_dest,sz); | |
| 669 | + strncat(intf,str,sz); | |
| 670 | + | |
| 671 | + } | |
| 672 | + | |
| 673 | + trace("DBUS:\nDestination:\t[%s]\nPath:\t\t[%s]\nInterface:\t[%s]",dest,path,intf); | |
| 674 | + | |
| 675 | + free(str); | |
| 676 | + | |
| 677 | + dbus_error_init(&err); | |
| 678 | + | |
| 679 | + conn = dbus_bus_get(DBUS_BUS_SESSION, &err); | |
| 680 | + trace("dbus_bus_get conn=%p",conn); | |
| 681 | + | |
| 682 | + if (dbus_error_is_set(&err)) | |
| 683 | + { | |
| 684 | + exception e = exception("DBUS Connection Error (%s)", err.message); | |
| 685 | + dbus_error_free(&err); | |
| 686 | + throw e; | |
| 687 | + return; | |
| 688 | + } | |
| 689 | + | |
| 690 | + if(!conn) | |
| 691 | + { | |
| 692 | + throw exception("%s", "DBUS Connection failed"); | |
| 693 | + return; | |
| 694 | + } | |
| 695 | + | |
| 696 | + | |
| 697 | + rc = dbus_bus_request_name(conn, makeBusName(busname,4095), DBUS_NAME_FLAG_REPLACE_EXISTING , &err); | |
| 698 | + trace("dbus_bus_request_name(%s) rc=%d",busname,rc); | |
| 699 | + | |
| 700 | + if (dbus_error_is_set(&err)) | |
| 701 | + { | |
| 702 | + exception e = exception("Name Error (%s)", err.message); | |
| 703 | + dbus_error_free(&err); | |
| 704 | + throw e; | |
| 705 | + return; | |
| 706 | + } | |
| 707 | + | |
| 708 | + if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) | |
| 709 | + { | |
| 710 | + trace("%s: DBUS request for name %s failed",__FUNCTION__, busname); | |
| 711 | + throw exception("DBUS request for \"%s\" failed",session); | |
| 712 | + return; | |
| 713 | + } | |
| 714 | + | |
| 715 | + trace("%s: Using DBUS name %s",__FUNCTION__,busname); | |
| 716 | + | |
| 717 | + const char * id = "r"; | |
| 718 | + static const dbus_int32_t flag = 1; | |
| 719 | + query_intval("setScript", DBUS_TYPE_STRING, &id, DBUS_TYPE_INT32, &flag, DBUS_TYPE_INVALID); | |
| 720 | + | |
| 721 | + | |
| 722 | +#else | |
| 723 | + | |
| 724 | + throw exception("%s","RPC support is incomplete."); | |
| 725 | + | |
| 726 | +#endif | |
| 727 | + } | |
| 728 | + | |
| 729 | + virtual ~remote() | |
| 730 | + { | |
| 731 | +#if defined(WIN32) | |
| 732 | + | |
| 733 | + if(hPipe != INVALID_HANDLE_VALUE) | |
| 734 | + CloseHandle(hPipe); | |
| 735 | + | |
| 736 | +#elif defined(HAVE_DBUS) | |
| 737 | + | |
| 738 | + try | |
| 739 | + { | |
| 740 | + const char * id = "r"; | |
| 741 | + static const dbus_int32_t flag = 0; | |
| 742 | + query_intval("setScript", DBUS_TYPE_STRING, &id, DBUS_TYPE_INT32, &flag, DBUS_TYPE_INVALID); | |
| 743 | + } | |
| 744 | + catch(exception e) | |
| 745 | + { | |
| 746 | + std::cerr << e.what(); | |
| 747 | + } | |
| 748 | + | |
| 749 | + char busname[4096]; | |
| 750 | + makeBusName(busname,4096); | |
| 751 | + | |
| 752 | + free(dest); | |
| 753 | + free(path); | |
| 754 | + free(intf); | |
| 755 | + | |
| 756 | + DBusError err; | |
| 757 | + | |
| 758 | + dbus_error_init(&err); | |
| 759 | + dbus_bus_release_name(conn,busname,&err); | |
| 760 | + | |
| 761 | + if (dbus_error_is_set(&err)) | |
| 762 | + { | |
| 763 | + //exception e = exception("Error when releasing DBUS name (%s)", err.message); | |
| 764 | + std::cerr << err.message; | |
| 765 | + dbus_error_free(&err); | |
| 766 | + //throw e; | |
| 767 | + } | |
| 768 | + | |
| 769 | +#else | |
| 770 | + | |
| 771 | +#endif | |
| 772 | + } | |
| 773 | + | |
| 774 | + bool is_connected(void) | |
| 775 | + { | |
| 776 | + return query_intval(HLLAPI_PACKET_IS_CONNECTED) != 0; | |
| 777 | + } | |
| 778 | + | |
| 779 | + LIB3270_CSTATE get_cstate(void) | |
| 780 | + { | |
| 781 | + return (LIB3270_CSTATE) query_intval(HLLAPI_PACKET_GET_CSTATE); | |
| 782 | + } | |
| 783 | + | |
| 784 | + LIB3270_MESSAGE get_program_message(void) { | |
| 785 | + return (LIB3270_MESSAGE) query_intval(HLLAPI_PACKET_GET_PROGRAM_MESSAGE); | |
| 786 | + } | |
| 787 | + | |
| 788 | + LIB3270_SSL_STATE get_secure(void) { | |
| 789 | + return (LIB3270_SSL_STATE) query_intval(HLLAPI_PACKET_GET_SSL_STATE); | |
| 790 | + } | |
| 791 | + | |
| 792 | + | |
| 793 | + int connect(void) | |
| 794 | + { | |
| 795 | + int rc; | |
| 796 | + | |
| 797 | +#if defined(WIN32) | |
| 798 | + | |
| 799 | + size_t cbSize = sizeof(struct hllapi_packet_connect); | |
| 800 | + struct hllapi_packet_connect * pkt = (struct hllapi_packet_connect *) malloc(cbSize); | |
| 801 | + | |
| 802 | + memset(pkt,0,cbSize); | |
| 803 | + | |
| 804 | + pkt->packet_id = HLLAPI_PACKET_CONNECT; | |
| 805 | + pkt->wait = 0; | |
| 806 | + | |
| 807 | + rc = query_intval((void *) pkt,cbSize,true); | |
| 808 | + | |
| 809 | +#elif defined(HAVE_DBUS) | |
| 810 | + | |
| 811 | + static const char * str = ""; | |
| 812 | + | |
| 813 | + rc = query_intval("connect", DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); | |
| 814 | + | |
| 815 | +#else | |
| 816 | + rc = -1; | |
| 817 | + | |
| 818 | +#endif | |
| 819 | + return rc; | |
| 820 | + | |
| 821 | + } | |
| 822 | + | |
| 823 | + int set_url(const char *uri) | |
| 824 | + { | |
| 825 | + int rc; | |
| 826 | + | |
| 827 | +#if defined(WIN32) | |
| 828 | + | |
| 829 | + size_t cbSize = sizeof(struct hllapi_packet_text)+strlen(uri); | |
| 830 | + struct hllapi_packet_text * pkt = (struct hllapi_packet_text *) malloc(cbSize); | |
| 831 | + | |
| 832 | + pkt->packet_id = HLLAPI_PACKET_SET_HOST; | |
| 833 | + strcpy(pkt->text,uri); | |
| 834 | + | |
| 835 | + rc = query_intval((void *) pkt,cbSize,true); | |
| 836 | + | |
| 837 | +#elif defined(HAVE_DBUS) | |
| 838 | + | |
| 839 | + rc = query_intval(HLLAPI_PACKET_SET_HOST, DBUS_TYPE_STRING, &uri, DBUS_TYPE_INVALID); | |
| 840 | + | |
| 841 | +#else | |
| 842 | + | |
| 843 | + rc = -1; | |
| 844 | + | |
| 845 | +#endif | |
| 846 | + | |
| 847 | + return rc; | |
| 848 | + | |
| 849 | + } | |
| 850 | + | |
| 851 | + string get_url() | |
| 852 | + { | |
| 853 | +#if defined(WIN32) | |
| 854 | + | |
| 855 | + struct hllapi_packet_query query = { HLLAPI_PACKET_GET_HOST }; | |
| 856 | + return query_string(&query,sizeof(query),1024); | |
| 857 | + | |
| 858 | +#elif defined(HAVE_DBUS) | |
| 859 | + | |
| 860 | + return query_string(HLLAPI_PACKET_GET_HOST); | |
| 861 | + | |
| 862 | +#else | |
| 863 | + return string(); | |
| 864 | +#endif | |
| 865 | + } | |
| 866 | + | |
| 867 | + int wait_for_ready(int seconds) | |
| 868 | + { | |
| 869 | +#if defined(WIN32) | |
| 870 | + | |
| 871 | + time_t end = time(0)+seconds; | |
| 872 | + | |
| 873 | + while(time(0) < end) | |
| 874 | + { | |
| 875 | + if(!is_connected()) | |
| 876 | + return ENOTCONN; | |
| 877 | + | |
| 878 | + if(is_ready()) | |
| 879 | + return 0; | |
| 880 | + | |
| 881 | + Sleep(250); | |
| 882 | + } | |
| 883 | + | |
| 884 | + return ETIMEDOUT; | |
| 885 | + | |
| 886 | +#elif defined(HAVE_DBUS) | |
| 887 | + | |
| 888 | + time_t end = time(0)+seconds; | |
| 889 | + | |
| 890 | + while(time(0) < end) | |
| 891 | + { | |
| 892 | + static const dbus_int32_t delay = 2; | |
| 893 | + | |
| 894 | + int rc = query_intval("waitForReady", DBUS_TYPE_INT32, &delay, DBUS_TYPE_INVALID); | |
| 895 | + | |
| 896 | + trace("waitForReady exits with rc=%d",rc); | |
| 897 | + | |
| 898 | + if(rc != ETIMEDOUT) | |
| 899 | + return rc; | |
| 900 | + } | |
| 901 | + | |
| 902 | + return ETIMEDOUT; | |
| 903 | + | |
| 904 | +#else | |
| 905 | + | |
| 906 | + return -1; | |
| 907 | + | |
| 908 | +#endif | |
| 909 | + | |
| 910 | + } | |
| 911 | + | |
| 912 | + bool is_ready(void) | |
| 913 | + { | |
| 914 | + return query_intval(HLLAPI_PACKET_IS_READY) != 0; | |
| 915 | + } | |
| 916 | + | |
| 917 | + | |
| 918 | + int disconnect(void) | |
| 919 | + { | |
| 920 | + return query_intval(HLLAPI_PACKET_DISCONNECT); | |
| 921 | + } | |
| 922 | + | |
| 923 | + | |
| 924 | + int wait(int seconds) | |
| 925 | + { | |
| 926 | +#if defined(WIN32) | |
| 927 | + | |
| 928 | + time_t end = time(0)+seconds; | |
| 929 | + | |
| 930 | + while(time(0) < end) | |
| 931 | + { | |
| 932 | + if(!is_connected()) | |
| 933 | + return ENOTCONN; | |
| 934 | + Sleep(500); | |
| 935 | + } | |
| 936 | + | |
| 937 | + return 0; | |
| 938 | + | |
| 939 | +#elif defined(HAVE_DBUS) | |
| 940 | + | |
| 941 | + time_t end = time(0)+seconds; | |
| 942 | + | |
| 943 | + while(time(0) < end) | |
| 944 | + { | |
| 945 | + if(!is_connected()) | |
| 946 | + return ENOTCONN; | |
| 947 | + usleep(500); | |
| 948 | + } | |
| 949 | + | |
| 950 | + return 0; | |
| 951 | + | |
| 952 | +#else | |
| 953 | + | |
| 954 | + return -1; | |
| 955 | + | |
| 956 | +#endif | |
| 957 | + | |
| 958 | + } | |
| 959 | + | |
| 960 | + int iterate(bool wait) | |
| 961 | + { | |
| 962 | +#if defined(WIN32) | |
| 963 | + if(wait) | |
| 964 | + Sleep(250); | |
| 965 | + return 0; | |
| 966 | +#elif defined(HAVE_DBUS) | |
| 967 | + if(wait) | |
| 968 | + usleep(250); | |
| 969 | + return 0; | |
| 970 | +#else | |
| 971 | + return -1; | |
| 972 | +#endif | |
| 973 | + } | |
| 974 | + | |
| 975 | + string get_text_at(int row, int col, size_t sz) | |
| 976 | + { | |
| 977 | +#if defined(WIN32) | |
| 978 | + | |
| 979 | + struct hllapi_packet_query_at query = { HLLAPI_PACKET_GET_TEXT_AT, (unsigned short) row, (unsigned short) col, (unsigned short) sz }; | |
| 980 | + | |
| 981 | + return query_string(&query,sizeof(query),sz); | |
| 982 | + | |
| 983 | +#elif defined(HAVE_DBUS) | |
| 984 | + | |
| 985 | + dbus_int32_t r = (dbus_int32_t) row; | |
| 986 | + dbus_int32_t c = (dbus_int32_t) col; | |
| 987 | + dbus_int32_t l = (dbus_int32_t) sz; | |
| 988 | + | |
| 989 | + DBusMessage * msg = create_message("getTextAt"); | |
| 990 | + if(!msg) | |
| 991 | + return NULL; | |
| 992 | + | |
| 993 | + trace("%s(%d,%d,%d)",__FUNCTION__,r,c,l); | |
| 994 | + dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INT32, &l, DBUS_TYPE_INVALID); | |
| 995 | + | |
| 996 | + return get_string(call(msg)); | |
| 997 | + | |
| 998 | +#else | |
| 999 | + | |
| 1000 | + return string(); | |
| 1001 | + | |
| 1002 | +#endif | |
| 1003 | + | |
| 1004 | + } | |
| 1005 | + | |
| 1006 | + int set_text_at(int row, int col, const char *str) | |
| 1007 | + { | |
| 1008 | +#if defined(WIN32) | |
| 1009 | + | |
| 1010 | + struct hllapi_packet_text_at * query; | |
| 1011 | + struct hllapi_packet_result response; | |
| 1012 | + DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen((const char *) str); | |
| 1013 | + | |
| 1014 | + query = (struct hllapi_packet_text_at *) malloc(cbSize); | |
| 1015 | + query->packet_id = HLLAPI_PACKET_SET_TEXT_AT; | |
| 1016 | + query->row = row; | |
| 1017 | + query->col = col; | |
| 1018 | + strcpy(query->text,(const char *) str); | |
| 1019 | + | |
| 1020 | + TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
| 1021 | + | |
| 1022 | + free(query); | |
| 1023 | + | |
| 1024 | + return response.rc; | |
| 1025 | + | |
| 1026 | +#elif defined(HAVE_DBUS) | |
| 1027 | + | |
| 1028 | + dbus_int32_t r = (dbus_int32_t) row; | |
| 1029 | + dbus_int32_t c = (dbus_int32_t) col; | |
| 1030 | + | |
| 1031 | + return query_intval("setTextAt", DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); | |
| 1032 | + | |
| 1033 | +#else | |
| 1034 | + | |
| 1035 | + return -1; | |
| 1036 | + | |
| 1037 | +#endif | |
| 1038 | + | |
| 1039 | + } | |
| 1040 | + | |
| 1041 | + int cmp_text_at(int row, int col, const char *text) | |
| 1042 | + { | |
| 1043 | + debug("%s(%d,%d,\"%s\")",__FUNCTION__,row,col,text); | |
| 1044 | + | |
| 1045 | +#if defined(WIN32) | |
| 1046 | + | |
| 1047 | + struct hllapi_packet_text_at * query; | |
| 1048 | + size_t cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text); | |
| 1049 | + | |
| 1050 | + query = (struct hllapi_packet_text_at *) malloc(cbSize); | |
| 1051 | + query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT; | |
| 1052 | + query->row = row; | |
| 1053 | + query->col = col; | |
| 1054 | + strcpy(query->text,text); | |
| 1055 | + | |
| 1056 | + return query_intval((void *) query, cbSize, true); | |
| 1057 | + | |
| 1058 | +#elif defined(HAVE_DBUS) | |
| 1059 | + | |
| 1060 | + dbus_int32_t r = (dbus_int32_t) row; | |
| 1061 | + dbus_int32_t c = (dbus_int32_t) col; | |
| 1062 | + | |
| 1063 | + return query_intval("cmpTextAt", DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID); | |
| 1064 | + | |
| 1065 | +#endif | |
| 1066 | + | |
| 1067 | + return 0; | |
| 1068 | + } | |
| 1069 | + | |
| 1070 | + int wait_for_text_at(int row, int col, const char *key, int timeout) | |
| 1071 | + { | |
| 1072 | + time_t end = time(0)+timeout; | |
| 1073 | + | |
| 1074 | + while(time(0) < end) | |
| 1075 | + { | |
| 1076 | + if(!is_connected()) | |
| 1077 | + return ENOTCONN; | |
| 1078 | + | |
| 1079 | + if(!cmp_text_at(row,col,key)) | |
| 1080 | + return 0; | |
| 1081 | + | |
| 1082 | +#ifdef WIN32 | |
| 1083 | + Sleep(500); | |
| 1084 | +#else | |
| 1085 | + usleep(500); | |
| 1086 | +#endif | |
| 1087 | + } | |
| 1088 | + | |
| 1089 | + return ETIMEDOUT; | |
| 1090 | + } | |
| 1091 | + | |
| 1092 | + string get_text(int baddr, size_t len) | |
| 1093 | + { | |
| 1094 | +#if defined(WIN32) | |
| 1095 | + struct hllapi_packet_query_offset query = { HLLAPI_PACKET_GET_TEXT_AT_OFFSET, (unsigned short) baddr, (unsigned short) len }; | |
| 1096 | + return query_string(&query,sizeof(query),len); | |
| 1097 | + | |
| 1098 | +#elif defined(HAVE_DBUS) | |
| 1099 | + | |
| 1100 | + dbus_int32_t b = (dbus_int32_t) baddr; | |
| 1101 | + dbus_int32_t l = (dbus_int32_t) len; | |
| 1102 | + | |
| 1103 | + DBusMessage * msg = create_message("getText"); | |
| 1104 | + if(!msg) | |
| 1105 | + return NULL; | |
| 1106 | + | |
| 1107 | + trace("%s(%d,%d)",__FUNCTION__,b,l); | |
| 1108 | + dbus_message_append_args(msg, DBUS_TYPE_INT32, &b, DBUS_TYPE_INT32, &l, DBUS_TYPE_INVALID); | |
| 1109 | + | |
| 1110 | + return get_string(call(msg)); | |
| 1111 | +#else | |
| 1112 | + throw exception("%s","IPC support is unavailable"); | |
| 1113 | + return string(); | |
| 1114 | +#endif | |
| 1115 | + } | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + int set_cursor_position(int row, int col) | |
| 1119 | + { | |
| 1120 | +#if defined(WIN32) | |
| 1121 | + | |
| 1122 | + struct hllapi_packet_cursor query = { HLLAPI_PACKET_SET_CURSOR_POSITION, (unsigned short) row, (unsigned short) col }; | |
| 1123 | + | |
| 1124 | + return query_intval((void *) &query, sizeof(query)); | |
| 1125 | + | |
| 1126 | +#elif defined(HAVE_DBUS) | |
| 1127 | + | |
| 1128 | + dbus_int32_t r = (dbus_int32_t) row; | |
| 1129 | + dbus_int32_t c = (dbus_int32_t) col; | |
| 1130 | + | |
| 1131 | + return query_intval("setCursorAt", DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INVALID); | |
| 1132 | + | |
| 1133 | +#endif | |
| 1134 | + | |
| 1135 | + return -1; | |
| 1136 | + } | |
| 1137 | + | |
| 1138 | + int set_cursor_addr(int addr) | |
| 1139 | + { | |
| 1140 | +#if defined(WIN32) | |
| 1141 | + | |
| 1142 | + struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, (unsigned short) addr }; | |
| 1143 | + | |
| 1144 | + return query_intval((void *) &query, sizeof(query)); | |
| 1145 | + | |
| 1146 | +#elif defined(HAVE_DBUS) | |
| 1147 | + | |
| 1148 | + dbus_int32_t k = (dbus_int32_t) addr; | |
| 1149 | + | |
| 1150 | + return query_intval("setCursorAddress", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1151 | + | |
| 1152 | +#endif | |
| 1153 | + | |
| 1154 | + return -1; | |
| 1155 | + } | |
| 1156 | + | |
| 1157 | + int get_cursor_addr(void) | |
| 1158 | + { | |
| 1159 | + return query_intval(HLLAPI_PACKET_GET_CURSOR); | |
| 1160 | + } | |
| 1161 | + | |
| 1162 | + int get_width(void) { | |
| 1163 | + return query_intval(HLLAPI_PACKET_GET_WIDTH); | |
| 1164 | + } | |
| 1165 | + | |
| 1166 | + int get_height(void) { | |
| 1167 | + return query_intval(HLLAPI_PACKET_GET_HEIGHT); | |
| 1168 | + } | |
| 1169 | + | |
| 1170 | + int get_length(void) { | |
| 1171 | + return query_intval(HLLAPI_PACKET_GET_LENGTH); | |
| 1172 | + } | |
| 1173 | + | |
| 1174 | + int enter(void) | |
| 1175 | + { | |
| 1176 | + return query_intval(HLLAPI_PACKET_ENTER); | |
| 1177 | + } | |
| 1178 | + | |
| 1179 | + int pfkey(int key) | |
| 1180 | + { | |
| 1181 | +#if defined(WIN32) | |
| 1182 | + | |
| 1183 | + struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, (unsigned short) key }; | |
| 1184 | + | |
| 1185 | + return query_intval((void *) &query, sizeof(query)); | |
| 1186 | + | |
| 1187 | +#elif defined(HAVE_DBUS) | |
| 1188 | + | |
| 1189 | + dbus_int32_t k = (dbus_int32_t) key; | |
| 1190 | + | |
| 1191 | + return query_intval("pfKey", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1192 | + | |
| 1193 | +#else | |
| 1194 | + | |
| 1195 | + return -1; | |
| 1196 | + | |
| 1197 | +#endif | |
| 1198 | + | |
| 1199 | + } | |
| 1200 | + | |
| 1201 | + int pakey(int key) | |
| 1202 | + { | |
| 1203 | +#if defined(WIN32) | |
| 1204 | + | |
| 1205 | + struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, (unsigned short) key }; | |
| 1206 | + | |
| 1207 | + return query_intval((void *) &query, sizeof(query)); | |
| 1208 | + | |
| 1209 | +#elif defined(HAVE_DBUS) | |
| 1210 | + | |
| 1211 | + dbus_int32_t k = (dbus_int32_t) key; | |
| 1212 | + | |
| 1213 | + return query_intval("paKey", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1214 | + | |
| 1215 | +#else | |
| 1216 | + | |
| 1217 | + return -1; | |
| 1218 | + | |
| 1219 | +#endif | |
| 1220 | + | |
| 1221 | + } | |
| 1222 | + | |
| 1223 | + int quit(void) | |
| 1224 | + { | |
| 1225 | + return query_intval(HLLAPI_PACKET_QUIT); | |
| 1226 | + } | |
| 1227 | + | |
| 1228 | + int set_toggle(LIB3270_TOGGLE ix, bool value) | |
| 1229 | + { | |
| 1230 | +#if defined(WIN32) | |
| 1231 | + | |
| 1232 | + struct hllapi_packet_set query = { HLLAPI_PACKET_SET_TOGGLE, (unsigned short) ix, (unsigned short) value }; | |
| 1233 | + | |
| 1234 | + return query_intval((void *) &query, sizeof(query)); | |
| 1235 | + | |
| 1236 | +#elif defined(HAVE_DBUS) | |
| 1237 | + | |
| 1238 | + dbus_int32_t i = (dbus_int32_t) ix; | |
| 1239 | + dbus_int32_t v = (dbus_int32_t) value; | |
| 1240 | + | |
| 1241 | + return query_intval("setToggle", DBUS_TYPE_INT32, &i, DBUS_TYPE_INT32, &v, DBUS_TYPE_INVALID); | |
| 1242 | + | |
| 1243 | +#else | |
| 1244 | + return -1; | |
| 1245 | + | |
| 1246 | +#endif | |
| 1247 | + | |
| 1248 | + } | |
| 1249 | + | |
| 1250 | + int emulate_input(const char *str) | |
| 1251 | + { | |
| 1252 | +#if defined(WIN32) | |
| 1253 | + | |
| 1254 | + size_t len = strlen(str); | |
| 1255 | + struct hllapi_packet_emulate_input * query; | |
| 1256 | + size_t cbSize = sizeof(struct hllapi_packet_emulate_input)+len; | |
| 1257 | + | |
| 1258 | + query = (struct hllapi_packet_emulate_input *) malloc(cbSize); | |
| 1259 | + query->packet_id = HLLAPI_PACKET_EMULATE_INPUT; | |
| 1260 | + query->len = len; | |
| 1261 | + query->pasting = 1; | |
| 1262 | + strcpy(query->text,str); | |
| 1263 | + | |
| 1264 | + return query_intval((void *) query, cbSize, true); | |
| 1265 | + | |
| 1266 | +#elif defined(HAVE_DBUS) | |
| 1267 | + | |
| 1268 | + return query_intval("input", DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); | |
| 1269 | +#else | |
| 1270 | + | |
| 1271 | + return -1; | |
| 1272 | + | |
| 1273 | +#endif | |
| 1274 | + | |
| 1275 | + } | |
| 1276 | + | |
| 1277 | + int action(const char *str) | |
| 1278 | + { | |
| 1279 | + | |
| 1280 | +#if defined(WIN32) | |
| 1281 | + | |
| 1282 | + size_t len = strlen(str); | |
| 1283 | + struct hllapi_packet_text * query; | |
| 1284 | + size_t cbSize = sizeof(struct hllapi_packet_text)+len; | |
| 1285 | + | |
| 1286 | + query = (struct hllapi_packet_text *) malloc(cbSize); | |
| 1287 | + query->packet_id = HLLAPI_PACKET_ACTION; | |
| 1288 | + strcpy(query->text,str); | |
| 1289 | + | |
| 1290 | + return query_intval((void *) query, cbSize, true); | |
| 1291 | + | |
| 1292 | +#elif defined(HAVE_DBUS) | |
| 1293 | + | |
| 1294 | + return query_intval("action", DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); | |
| 1295 | +#else | |
| 1296 | + | |
| 1297 | + return -1; | |
| 1298 | + | |
| 1299 | +#endif | |
| 1300 | + | |
| 1301 | + } | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + int get_field_start(int baddr) | |
| 1305 | + { | |
| 1306 | +#if defined(WIN32) | |
| 1307 | + | |
| 1308 | + struct hllapi_packet_addr query = { HLLAPI_PACKET_FIELD_START, (unsigned short) baddr }; | |
| 1309 | + | |
| 1310 | + return query_intval((void *) &query, sizeof(query)); | |
| 1311 | + | |
| 1312 | +#elif defined(HAVE_DBUS) | |
| 1313 | + | |
| 1314 | + dbus_int32_t k = (dbus_int32_t) baddr; | |
| 1315 | + | |
| 1316 | + return query_intval("getFieldStart", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1317 | + | |
| 1318 | +#else | |
| 1319 | + | |
| 1320 | + return -1; | |
| 1321 | + | |
| 1322 | +#endif | |
| 1323 | + | |
| 1324 | + } | |
| 1325 | + | |
| 1326 | + int get_field_len(int baddr) | |
| 1327 | + { | |
| 1328 | +#if defined(WIN32) | |
| 1329 | + | |
| 1330 | + struct hllapi_packet_addr query = { HLLAPI_PACKET_FIELD_LEN, (unsigned short) baddr }; | |
| 1331 | + | |
| 1332 | + return query_intval((void *) &query, sizeof(query)); | |
| 1333 | + | |
| 1334 | +#elif defined(HAVE_DBUS) | |
| 1335 | + | |
| 1336 | + dbus_int32_t k = (dbus_int32_t) baddr; | |
| 1337 | + | |
| 1338 | + return query_intval("getFieldLength", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1339 | + | |
| 1340 | +#else | |
| 1341 | + | |
| 1342 | + return -1; | |
| 1343 | + | |
| 1344 | +#endif | |
| 1345 | + } | |
| 1346 | + | |
| 1347 | + int get_next_unprotected(int baddr) | |
| 1348 | + { | |
| 1349 | +#if defined(WIN32) | |
| 1350 | + | |
| 1351 | + struct hllapi_packet_addr query = { HLLAPI_PACKET_NEXT_UNPROTECTED, (unsigned short) baddr }; | |
| 1352 | + | |
| 1353 | + return query_intval((void *) &query, sizeof(query)); | |
| 1354 | + | |
| 1355 | +#elif defined(HAVE_DBUS) | |
| 1356 | + | |
| 1357 | + dbus_int32_t k = (dbus_int32_t) baddr; | |
| 1358 | + | |
| 1359 | + DBusMessage * msg = create_message("getNextUnprotected"); | |
| 1360 | + if(msg) | |
| 1361 | + { | |
| 1362 | + dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1363 | + return get_intval(call(msg)); | |
| 1364 | + } | |
| 1365 | + | |
| 1366 | + return -1; | |
| 1367 | + | |
| 1368 | +#else | |
| 1369 | + | |
| 1370 | + return -1; | |
| 1371 | + | |
| 1372 | +#endif | |
| 1373 | + | |
| 1374 | + } | |
| 1375 | + | |
| 1376 | + int get_is_protected(int baddr) | |
| 1377 | + { | |
| 1378 | +#if defined(WIN32) | |
| 1379 | + | |
| 1380 | + struct hllapi_packet_addr query = { HLLAPI_PACKET_IS_PROTECTED, (unsigned short) baddr }; | |
| 1381 | + | |
| 1382 | + return query_intval((void *) &query, sizeof(query)); | |
| 1383 | + | |
| 1384 | +#elif defined(HAVE_DBUS) | |
| 1385 | + | |
| 1386 | + dbus_int32_t k = (dbus_int32_t) baddr; | |
| 1387 | + | |
| 1388 | + DBusMessage * msg = create_message("getIsProtected"); | |
| 1389 | + if(msg) | |
| 1390 | + { | |
| 1391 | + dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1392 | + return get_intval(call(msg)); | |
| 1393 | + } | |
| 1394 | + | |
| 1395 | + return -1; | |
| 1396 | + | |
| 1397 | +#else | |
| 1398 | + | |
| 1399 | + return -1; | |
| 1400 | + | |
| 1401 | +#endif | |
| 1402 | + | |
| 1403 | + } | |
| 1404 | + | |
| 1405 | + int get_is_protected_at(int row,int col) | |
| 1406 | + { | |
| 1407 | +#if defined(WIN32) | |
| 1408 | + | |
| 1409 | + struct hllapi_packet_query_at query = { HLLAPI_PACKET_IS_PROTECTED_AT, (unsigned short) row, (unsigned short) col, 0 }; | |
| 1410 | + | |
| 1411 | + return query_intval((void *) &query, sizeof(query)); | |
| 1412 | + | |
| 1413 | +#elif defined(HAVE_DBUS) | |
| 1414 | + | |
| 1415 | + dbus_int32_t r = (dbus_int32_t) row; | |
| 1416 | + dbus_int32_t c = (dbus_int32_t) col; | |
| 1417 | + | |
| 1418 | + DBusMessage * msg = create_message("getIsProtectedAt"); | |
| 1419 | + if(msg) | |
| 1420 | + { | |
| 1421 | + dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INVALID); | |
| 1422 | + return get_intval(call(msg)); | |
| 1423 | + } | |
| 1424 | + | |
| 1425 | + return -1; | |
| 1426 | + | |
| 1427 | +#else | |
| 1428 | + | |
| 1429 | + return -1; | |
| 1430 | + | |
| 1431 | +#endif | |
| 1432 | + | |
| 1433 | + } | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + int set_host_charset(const char *charset) | |
| 1437 | + { | |
| 1438 | +#if defined(WIN32) | |
| 1439 | + | |
| 1440 | + size_t len = strlen(charset); | |
| 1441 | + struct hllapi_packet_set_text * query; | |
| 1442 | + size_t cbSize = sizeof(struct hllapi_packet_set_text)+len; | |
| 1443 | + | |
| 1444 | + query = (struct hllapi_packet_set_text *) malloc(cbSize); | |
| 1445 | + query->packet_id = HLLAPI_PACKET_SET_HOST_CHARSET; | |
| 1446 | + query->len = len; | |
| 1447 | + strcpy(query->text,charset); | |
| 1448 | + | |
| 1449 | + return query_intval((void *) query, cbSize, true); | |
| 1450 | + | |
| 1451 | +#elif defined(HAVE_DBUS) | |
| 1452 | + | |
| 1453 | + return query_intval("setHostCharset", DBUS_TYPE_STRING, &charset, DBUS_TYPE_INVALID); | |
| 1454 | + | |
| 1455 | +#else | |
| 1456 | + return -1; | |
| 1457 | +#endif | |
| 1458 | + } | |
| 1459 | + | |
| 1460 | + string get_host_charset(void) | |
| 1461 | + { | |
| 1462 | +#if defined(WIN32) | |
| 1463 | + | |
| 1464 | + struct hllapi_packet_query query = { HLLAPI_PACKET_GET_HOST_CHARSET }; | |
| 1465 | + return query_string(&query,sizeof(query),100); | |
| 1466 | + | |
| 1467 | +#elif defined(HAVE_DBUS) | |
| 1468 | + | |
| 1469 | + return query_string("getHostCharset"); | |
| 1470 | + | |
| 1471 | +#else | |
| 1472 | + | |
| 1473 | + return NULL; | |
| 1474 | + | |
| 1475 | +#endif | |
| 1476 | + } | |
| 1477 | + | |
| 1478 | + | |
| 1479 | +#if defined(HAVE_DBUS) | |
| 1480 | + string get_clipboard(void) | |
| 1481 | + { | |
| 1482 | + return query_string("getClipboard"); | |
| 1483 | + } | |
| 1484 | + | |
| 1485 | + int set_clipboard(const char *text) | |
| 1486 | + { | |
| 1487 | + return query_intval("setClipboard", DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID); | |
| 1488 | + } | |
| 1489 | + | |
| 1490 | + string get_display_charset(void) | |
| 1491 | + { | |
| 1492 | + return query_string("getDisplayCharset"); | |
| 1493 | + } | |
| 1494 | + | |
| 1495 | + int popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...) | |
| 1496 | + { | |
| 1497 | + DBusMessage * msg = dbus_message_new_method_call( this->dest, // Destination | |
| 1498 | + this->path, // Path | |
| 1499 | + this->intf, // Interface | |
| 1500 | + "showPopup"); // method | |
| 1501 | + | |
| 1502 | + if (!msg) | |
| 1503 | + { | |
| 1504 | + throw exception("%s","Error creating DBUS message for popup"); | |
| 1505 | + return -1; | |
| 1506 | + } | |
| 1507 | + else | |
| 1508 | + { | |
| 1509 | + char text[4096]; | |
| 1510 | + char * ptr = text; | |
| 1511 | + va_list arg_ptr; | |
| 1512 | + dbus_int32_t i = (dbus_int32_t) id; | |
| 1513 | + | |
| 1514 | + va_start(arg_ptr, fmt); | |
| 1515 | + vsnprintf(text,4095,fmt,arg_ptr); | |
| 1516 | + va_end(arg_ptr); | |
| 1517 | + | |
| 1518 | + if(!dbus_message_append_args(msg, DBUS_TYPE_INT32, &i, DBUS_TYPE_STRING, &title, DBUS_TYPE_STRING, &message, DBUS_TYPE_STRING, &ptr, DBUS_TYPE_INVALID)) | |
| 1519 | + { | |
| 1520 | + dbus_message_unref(msg); | |
| 1521 | + throw exception("%s","Cant append args for popup message"); | |
| 1522 | + } | |
| 1523 | + else | |
| 1524 | + { | |
| 1525 | + DBusMessage * reply; | |
| 1526 | + DBusError error; | |
| 1527 | + | |
| 1528 | + dbus_error_init(&error); | |
| 1529 | + reply = dbus_connection_send_with_reply_and_block(conn,msg,DBUS_TIMEOUT_INFINITE,&error); | |
| 1530 | + dbus_message_unref(msg); | |
| 1531 | + | |
| 1532 | + if(!reply) | |
| 1533 | + { | |
| 1534 | + exception e = exception("%s",error.message); | |
| 1535 | + dbus_error_free(&error); | |
| 1536 | + throw e; | |
| 1537 | + return -1; | |
| 1538 | + } | |
| 1539 | + | |
| 1540 | + return get_intval(reply); | |
| 1541 | + | |
| 1542 | + } | |
| 1543 | + } | |
| 1544 | + return 0; | |
| 1545 | + } | |
| 1546 | + | |
| 1547 | +#endif // HAVE_DBUS | |
| 1548 | + | |
| 1549 | + int erase(void) | |
| 1550 | + { | |
| 1551 | + return query_intval(HLLAPI_PACKET_ERASE); | |
| 1552 | + } | |
| 1553 | + | |
| 1554 | + int erase_eof(void) | |
| 1555 | + { | |
| 1556 | + return query_intval(HLLAPI_PACKET_ERASE_EOF); | |
| 1557 | + } | |
| 1558 | + | |
| 1559 | + int erase_eol(void) | |
| 1560 | + { | |
| 1561 | + return query_intval(HLLAPI_PACKET_ERASE_EOL); | |
| 1562 | + } | |
| 1563 | + | |
| 1564 | + int erase_input(void) | |
| 1565 | + { | |
| 1566 | + return query_intval(HLLAPI_PACKET_ERASE_INPUT); | |
| 1567 | + } | |
| 1568 | + | |
| 1569 | + int print(void) | |
| 1570 | + { | |
| 1571 | + return query_intval(HLLAPI_PACKET_PRINT); | |
| 1572 | + } | |
| 1573 | + | |
| 1574 | + const char * asc2ebc(unsigned char *text, int sz) | |
| 1575 | + { | |
| 1576 | + query_strval(HLLAPI_PACKET_ASC2EBC,text,sz); | |
| 1577 | + return (const char *) text; | |
| 1578 | + } | |
| 1579 | + | |
| 1580 | + const char * ebc2asc(unsigned char *text, int sz) | |
| 1581 | + { | |
| 1582 | + query_strval(HLLAPI_PACKET_EBC2ASC,text,sz); | |
| 1583 | + return (const char *) text; | |
| 1584 | + } | |
| 1585 | + | |
| 1586 | + void set_unlock_delay(unsigned short ms) | |
| 1587 | + { | |
| 1588 | + set_intval(HLLAPI_PACKET_SET_UNLOCK_DELAY,(int) ms); | |
| 1589 | + } | |
| 1590 | + | |
| 1591 | + }; | |
| 1592 | + | |
| 1593 | + session * session::create_remote(const char *session) throw (std::exception) | |
| 1594 | + { | |
| 1595 | + return new remote(session); | |
| 1596 | + } | |
| 1597 | + | |
| 1598 | + } | |
| 1599 | + | ... | ... |
| ... | ... | @@ -0,0 +1,702 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como session.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include <stdarg.h> | |
| 31 | + #include <stdio.h> | |
| 32 | + #include <string.h> | |
| 33 | + #include <malloc.h> | |
| 34 | + | |
| 35 | + #include "private.h" | |
| 36 | + | |
| 37 | +#ifndef WIN32 | |
| 38 | + #include <unistd.h> | |
| 39 | +#endif // !WIN32 | |
| 40 | + | |
| 41 | +#ifdef HAVE_SYSLOG | |
| 42 | + #include <syslog.h> | |
| 43 | +#endif // HAVE_SYSLOG | |
| 44 | + | |
| 45 | + | |
| 46 | +/*--[ Implement ]--------------------------------------------------------------------------------------------------*/ | |
| 47 | + | |
| 48 | + using namespace PW3270_NAMESPACE; | |
| 49 | + | |
| 50 | +#if defined(linux) | |
| 51 | + static void onLoad() __attribute__((constructor)); | |
| 52 | + static void onUnLoad() __attribute__((destructor)); | |
| 53 | + | |
| 54 | + static void onLoad() | |
| 55 | + { | |
| 56 | + session::init(); | |
| 57 | + } | |
| 58 | + | |
| 59 | + static void onUnLoad() | |
| 60 | + { | |
| 61 | + session::deinit(); | |
| 62 | + } | |
| 63 | + | |
| 64 | +#endif // linux | |
| 65 | + | |
| 66 | +#ifdef _WIN32 | |
| 67 | + | |
| 68 | + BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) | |
| 69 | + { | |
| 70 | + switch(fdwReason) | |
| 71 | + { | |
| 72 | + case DLL_PROCESS_ATTACH: | |
| 73 | + session::init(); | |
| 74 | + break; | |
| 75 | + | |
| 76 | + case DLL_PROCESS_DETACH: | |
| 77 | + session::deinit(); | |
| 78 | + break; | |
| 79 | + } | |
| 80 | + | |
| 81 | + return TRUE; | |
| 82 | + } | |
| 83 | + | |
| 84 | +#endif // _WIN32 | |
| 85 | + | |
| 86 | + | |
| 87 | + namespace PW3270_NAMESPACE { | |
| 88 | + | |
| 89 | + session * session::first = nullptr; | |
| 90 | + session * session::last = nullptr; | |
| 91 | + session * (*session::factory)(const char *name) = nullptr; | |
| 92 | + | |
| 93 | + static recursive_mutex mtx; | |
| 94 | + | |
| 95 | + inline void lock() | |
| 96 | + { | |
| 97 | + mtx.lock(); | |
| 98 | + } | |
| 99 | + | |
| 100 | + inline void unlock() | |
| 101 | + { | |
| 102 | + mtx.unlock(); | |
| 103 | + } | |
| 104 | + | |
| 105 | + void session::init() | |
| 106 | + { | |
| 107 | + trace("Loading %s objects",PACKAGE_NAME); | |
| 108 | + } | |
| 109 | + | |
| 110 | + void session::deinit() | |
| 111 | + { | |
| 112 | + trace("Unloading %s objects",PACKAGE_NAME); | |
| 113 | + while(first) | |
| 114 | + { | |
| 115 | + delete first; | |
| 116 | + } | |
| 117 | + | |
| 118 | + } | |
| 119 | + | |
| 120 | + session::session() | |
| 121 | + { | |
| 122 | + | |
| 123 | +#ifdef HAVE_ICONV | |
| 124 | + this->conv2Local = (iconv_t) (-1); | |
| 125 | + this->conv2Host = (iconv_t) (-1); | |
| 126 | +#endif | |
| 127 | + | |
| 128 | + if(first) | |
| 129 | + { | |
| 130 | + prev = last; | |
| 131 | + next = 0; | |
| 132 | + last->next = this; | |
| 133 | + last = this; | |
| 134 | + } | |
| 135 | + else | |
| 136 | + { | |
| 137 | + prev = next = 0; | |
| 138 | + first = last = this; | |
| 139 | + } | |
| 140 | + | |
| 141 | + } | |
| 142 | + | |
| 143 | + session::~session() | |
| 144 | + { | |
| 145 | +#ifdef HAVE_ICONV | |
| 146 | + | |
| 147 | + if(this->conv2Local != (iconv_t) (-1)) | |
| 148 | + iconv_close(this->conv2Local); | |
| 149 | + | |
| 150 | + if(this->conv2Host != (iconv_t) (-1)) | |
| 151 | + iconv_close(this->conv2Host); | |
| 152 | + | |
| 153 | +#endif | |
| 154 | + | |
| 155 | + if(prev) | |
| 156 | + prev->next = next; | |
| 157 | + else | |
| 158 | + first = next; | |
| 159 | + | |
| 160 | + if(next) | |
| 161 | + next->prev = prev; | |
| 162 | + else | |
| 163 | + last = prev; | |
| 164 | + } | |
| 165 | + | |
| 166 | + // Factory methods and settings | |
| 167 | + session * session::create(const char *name) throw (std::exception) | |
| 168 | + { | |
| 169 | + session *rc = nullptr; | |
| 170 | + | |
| 171 | + trace("%s(%s)",__FUNCTION__,name); | |
| 172 | + | |
| 173 | + lock(); | |
| 174 | + | |
| 175 | + try | |
| 176 | + { | |
| 177 | + if(factory) | |
| 178 | + rc = factory(name); | |
| 179 | + else if(name && *name) | |
| 180 | + rc = create_remote(name); | |
| 181 | + else | |
| 182 | + rc = create_local(); | |
| 183 | + | |
| 184 | + } | |
| 185 | + catch(std::exception &e) | |
| 186 | + { | |
| 187 | + unlock(); | |
| 188 | + throw e; | |
| 189 | + } | |
| 190 | + | |
| 191 | + unlock(); | |
| 192 | + | |
| 193 | + return rc; | |
| 194 | + } | |
| 195 | + | |
| 196 | + session * session::start(const char *name) | |
| 197 | + { | |
| 198 | + return create(name); | |
| 199 | + } | |
| 200 | + | |
| 201 | + bool session::has_default(void) | |
| 202 | + { | |
| 203 | + return first != nullptr; | |
| 204 | + } | |
| 205 | + | |
| 206 | + session * session::get_default(void) | |
| 207 | + { | |
| 208 | + if(first) | |
| 209 | + return first; | |
| 210 | + return create(NULL); | |
| 211 | + } | |
| 212 | + | |
| 213 | + void session::set_plugin(session * (*factory)(const char *name)) | |
| 214 | + { | |
| 215 | + trace("%s(%p)",__FUNCTION__,factory); | |
| 216 | + session::factory = factory; | |
| 217 | + } | |
| 218 | + | |
| 219 | + // Object settings | |
| 220 | + void session::set_display_charset(const char *remote, const char *local) | |
| 221 | + { | |
| 222 | + trace("%s(%s,%s)",__FUNCTION__,remote,local); | |
| 223 | + | |
| 224 | +#ifdef HAVE_ICONV | |
| 225 | + string display_charset = this->get_display_charset(); | |
| 226 | + | |
| 227 | + if(this->conv2Local != (iconv_t) (-1)) | |
| 228 | + iconv_close(this->conv2Local); | |
| 229 | + | |
| 230 | + if(this->conv2Host != (iconv_t) (-1)) | |
| 231 | + iconv_close(this->conv2Host); | |
| 232 | + | |
| 233 | + if(!remote) | |
| 234 | + remote = display_charset.c_str(); | |
| 235 | + | |
| 236 | + trace("%s remote=%s local=%s",__FUNCTION__,remote,local); | |
| 237 | + | |
| 238 | + if(strcmp(local,remote)) | |
| 239 | + { | |
| 240 | + // Local and remote charsets aren't the same, setup conversion | |
| 241 | + conv2Local = iconv_open(local, remote); | |
| 242 | + conv2Host = iconv_open(remote,local); | |
| 243 | + } | |
| 244 | + else | |
| 245 | + { | |
| 246 | + conv2Local = conv2Host = (iconv_t)(-1); | |
| 247 | + } | |
| 248 | + | |
| 249 | +#endif | |
| 250 | + | |
| 251 | + } | |
| 252 | + | |
| 253 | + string session::get_display_charset(void) | |
| 254 | + { | |
| 255 | + return string(get_encoding()); | |
| 256 | + } | |
| 257 | + | |
| 258 | + const char * session::get_encoding(void) | |
| 259 | + { | |
| 260 | + return "ISO-8859-1"; | |
| 261 | + } | |
| 262 | + | |
| 263 | + // 3270 methods | |
| 264 | + const string session::get_version(void) | |
| 265 | + { | |
| 266 | + return string(PACKAGE_VERSION); | |
| 267 | + } | |
| 268 | + | |
| 269 | + const string session::get_revision(void) | |
| 270 | + { | |
| 271 | +#ifdef PACKAGE_REVISION | |
| 272 | + return string(PACKAGE_REVISION); | |
| 273 | +#else | |
| 274 | + return string(STRINGIZE_VALUE_OF(BUILD_DATE)); | |
| 275 | +#endif // PACKAGE_REVISION | |
| 276 | + } | |
| 277 | + | |
| 278 | + void session::log(const char *fmt, ...) | |
| 279 | + { | |
| 280 | + va_list arg_ptr; | |
| 281 | + va_start(arg_ptr, fmt); | |
| 282 | + this->logva(fmt,arg_ptr); | |
| 283 | + va_end(arg_ptr); | |
| 284 | + } | |
| 285 | + | |
| 286 | + void session::logva(const char *fmt, va_list args) | |
| 287 | + { | |
| 288 | + #ifdef HAVE_SYSLOG | |
| 289 | + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
| 290 | + vsyslog(LOG_INFO,fmt,args); | |
| 291 | + closelog(); | |
| 292 | + #else | |
| 293 | + vfprintf(stderr,fmt,args); | |
| 294 | + #endif | |
| 295 | + } | |
| 296 | + | |
| 297 | + int session::wait_for_text_at(int row, int col, const char *key, int timeout) | |
| 298 | + { | |
| 299 | + time_t end = time(0)+timeout; | |
| 300 | + | |
| 301 | + trace("%s(%d,%d,%s,%d)",__FUNCTION__,row,col,key,timeout); | |
| 302 | + | |
| 303 | + iterate(false); | |
| 304 | + while(time(0) < end) | |
| 305 | + { | |
| 306 | + trace("Aguardar %d segundos por \"%s\" @%d,%d (%s)",(int) (end - time(0)),key,row,col,get_text_at(row,col,strlen(key)).c_str()); | |
| 307 | + | |
| 308 | + int rc = wait_for_ready(end - time(0)); | |
| 309 | + if(rc) { | |
| 310 | + return rc; | |
| 311 | + } | |
| 312 | + | |
| 313 | + if(!cmp_text_at(row,col,key)) { | |
| 314 | + return 0; | |
| 315 | + } | |
| 316 | + | |
| 317 | + iterate(true); | |
| 318 | + | |
| 319 | + } | |
| 320 | + | |
| 321 | + trace("Tela:\n%s\n", ((string) *this).c_str()); | |
| 322 | + | |
| 323 | + return ETIMEDOUT; | |
| 324 | + } | |
| 325 | + | |
| 326 | + int session::set_copy(const char *text) | |
| 327 | + { | |
| 328 | + return EINVAL; | |
| 329 | + } | |
| 330 | + | |
| 331 | + string session::get_copy(void) | |
| 332 | + { | |
| 333 | + errno = EINVAL; | |
| 334 | + return string(); | |
| 335 | + } | |
| 336 | + | |
| 337 | + string session::get_clipboard(void) | |
| 338 | + { | |
| 339 | +#if defined(WIN32) | |
| 340 | + | |
| 341 | + if (! OpenClipboard(0)) | |
| 342 | + { | |
| 343 | + throw exception(GetLastError(),"%s","Can´t open system clipboard"); | |
| 344 | + return NULL; | |
| 345 | + } | |
| 346 | + | |
| 347 | + HANDLE hData = GetClipboardData(CF_TEXT); | |
| 348 | + if(!hData) | |
| 349 | + { | |
| 350 | + throw exception(GetLastError(),"%s","Can´t get clipboard data"); | |
| 351 | + return NULL; | |
| 352 | + } | |
| 353 | + | |
| 354 | + char * pszText = static_cast<char*>( GlobalLock(hData) ); | |
| 355 | + if(!pszText) | |
| 356 | + { | |
| 357 | + throw exception(GetLastError(),"%s","Can´t lock clipboard"); | |
| 358 | + return NULL; | |
| 359 | + } | |
| 360 | + | |
| 361 | + string text = string ( pszText ); | |
| 362 | + | |
| 363 | + GlobalUnlock( hData ); | |
| 364 | + | |
| 365 | + CloseClipboard(); | |
| 366 | + | |
| 367 | + return text; | |
| 368 | + | |
| 369 | +#else | |
| 370 | + errno = EINVAL; | |
| 371 | + return NULL; | |
| 372 | + | |
| 373 | +#endif // WIN32 | |
| 374 | + } | |
| 375 | + | |
| 376 | + int session::set_clipboard(const char *text) | |
| 377 | + { | |
| 378 | +#if defined(WIN32) | |
| 379 | + if (! OpenClipboard(0)) | |
| 380 | + { | |
| 381 | + throw exception(GetLastError(),"%s","Can´t open system clipboard"); | |
| 382 | + return -1; | |
| 383 | + } | |
| 384 | + | |
| 385 | + EmptyClipboard(); | |
| 386 | + | |
| 387 | + size_t size = strlen(text)+1; | |
| 388 | + HGLOBAL hClipboardData = GlobalAlloc(GMEM_MOVEABLE , size); | |
| 389 | + | |
| 390 | + strcpy((char *) GlobalLock(hClipboardData), text); | |
| 391 | + | |
| 392 | + if(!SetClipboardData(CF_TEXT, hClipboardData)) | |
| 393 | + { | |
| 394 | + GlobalUnlock(hClipboardData); | |
| 395 | + CloseClipboard(); | |
| 396 | + throw exception(GetLastError(),"%s","Can´t set system clipboard"); | |
| 397 | + } | |
| 398 | + | |
| 399 | + GlobalUnlock(hClipboardData); | |
| 400 | + CloseClipboard(); | |
| 401 | + | |
| 402 | + return 0; | |
| 403 | +#else | |
| 404 | + | |
| 405 | + return EINVAL; | |
| 406 | + | |
| 407 | +#endif // WIN32 | |
| 408 | + } | |
| 409 | + | |
| 410 | + | |
| 411 | + int session::popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...) | |
| 412 | + { | |
| 413 | + return -1; | |
| 414 | + } | |
| 415 | + | |
| 416 | + string session::file_chooser_dialog(int action, const char *title, const char *extension, const char *filename) | |
| 417 | + { | |
| 418 | + return string(""); | |
| 419 | + } | |
| 420 | + | |
| 421 | + string session::get_3270_text(const char *str) | |
| 422 | + { | |
| 423 | + string rc; | |
| 424 | + | |
| 425 | +#ifdef HAVE_ICONV | |
| 426 | + size_t in = strlen(str); | |
| 427 | + | |
| 428 | + if(in && conv2Host != (iconv_t)(-1)) | |
| 429 | + { | |
| 430 | + size_t out = (in << 1); | |
| 431 | + char * ptr; | |
| 432 | + char * outBuffer = (char *) malloc(out); | |
| 433 | + ICONV_CONST char * inBuffer = (ICONV_CONST char *) str; | |
| 434 | + | |
| 435 | + memset(ptr=outBuffer,0,out); | |
| 436 | + | |
| 437 | + iconv(conv2Host,NULL,NULL,NULL,NULL); // Reset state | |
| 438 | + | |
| 439 | + if(iconv(conv2Host,&inBuffer,&in,&ptr,&out) == ((size_t) -1)) { | |
| 440 | + rc.assign(str); | |
| 441 | + } else { | |
| 442 | + rc.assign(outBuffer); | |
| 443 | + } | |
| 444 | + | |
| 445 | + free(outBuffer); | |
| 446 | + } else { | |
| 447 | + rc.assign(str); | |
| 448 | + } | |
| 449 | +#else | |
| 450 | + rc.assign(str); | |
| 451 | +#endif // HAVE_ICONV | |
| 452 | + | |
| 453 | + trace("%s(\"%s\")=\"%s\"",__FUNCTION__,str,rc.c_str()); | |
| 454 | + | |
| 455 | + return rc; | |
| 456 | + } | |
| 457 | + | |
| 458 | + string session::get_local_text(const char *str) | |
| 459 | + { | |
| 460 | + string rc; | |
| 461 | + | |
| 462 | +#ifdef HAVE_ICONV | |
| 463 | + size_t in = strlen(str); | |
| 464 | + | |
| 465 | + if(in && conv2Local != (iconv_t)(-1)) | |
| 466 | + { | |
| 467 | + size_t out = (in << 1); | |
| 468 | + char * ptr; | |
| 469 | + char * outBuffer = (char *) malloc(out); | |
| 470 | + ICONV_CONST char * inBuffer = (ICONV_CONST char *) str; | |
| 471 | + | |
| 472 | + memset(ptr=outBuffer,0,out); | |
| 473 | + | |
| 474 | + iconv(conv2Local,NULL,NULL,NULL,NULL); // Reset state | |
| 475 | + | |
| 476 | + if(iconv(conv2Local,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) | |
| 477 | + rc.assign(outBuffer); | |
| 478 | + | |
| 479 | + free(outBuffer); | |
| 480 | + } | |
| 481 | + else | |
| 482 | + { | |
| 483 | + char * text = strdup(str); | |
| 484 | + for(char *ptr = text;*ptr;ptr++) | |
| 485 | + { | |
| 486 | + if(*ptr < ' ' || *ptr > 128) | |
| 487 | + { | |
| 488 | + *ptr = '?'; | |
| 489 | + } | |
| 490 | + } | |
| 491 | + rc = text; | |
| 492 | + free(text); | |
| 493 | + } | |
| 494 | +#else | |
| 495 | + char * text = strdup(str); | |
| 496 | + for(char *ptr = text;*ptr;ptr++) | |
| 497 | + { | |
| 498 | + if(*ptr < ' ' || *ptr > 128) | |
| 499 | + { | |
| 500 | + *ptr = '?'; | |
| 501 | + } | |
| 502 | + } | |
| 503 | + rc = text; | |
| 504 | + free(text); | |
| 505 | +#endif // HAVE_ICONV | |
| 506 | + | |
| 507 | + return rc; | |
| 508 | + } | |
| 509 | + | |
| 510 | + string session::get_string_at(int row, int col, size_t sz) | |
| 511 | + { | |
| 512 | + return this->get_local_text(this->get_text_at(row,col,sz).c_str()); | |
| 513 | + } | |
| 514 | + | |
| 515 | + int session::set_string_at(int row, int col, const char *str) | |
| 516 | + { | |
| 517 | + if(!str) | |
| 518 | + return -1; | |
| 519 | + | |
| 520 | +#ifdef HAVE_ICONV | |
| 521 | + if(conv2Host != (iconv_t)(-1)) | |
| 522 | + { | |
| 523 | + size_t in = strlen(str); | |
| 524 | + size_t out = (in << 1); | |
| 525 | + char * ptr; | |
| 526 | + char * outBuffer = (char *) malloc(out); | |
| 527 | + ICONV_CONST char * inBuffer = (ICONV_CONST char *) str; | |
| 528 | + | |
| 529 | + memset(ptr=outBuffer,0,out); | |
| 530 | + | |
| 531 | + iconv(conv2Host,NULL,NULL,NULL,NULL); // Reset state | |
| 532 | + | |
| 533 | + if(iconv(conv2Host,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) | |
| 534 | + { | |
| 535 | + int rc = this->set_text_at(row,col,outBuffer); | |
| 536 | + free(outBuffer); | |
| 537 | + return rc; | |
| 538 | + } | |
| 539 | + | |
| 540 | + free(outBuffer); | |
| 541 | + } | |
| 542 | +#endif // HAVE_ICONV | |
| 543 | + | |
| 544 | + return this->set_text_at(row,col,str); | |
| 545 | + | |
| 546 | + } | |
| 547 | + | |
| 548 | + int session::input_string(const char *str) | |
| 549 | + { | |
| 550 | + if(!str) | |
| 551 | + return -1; | |
| 552 | + | |
| 553 | +#ifdef HAVE_ICONV | |
| 554 | + if(conv2Host != (iconv_t)(-1)) | |
| 555 | + { | |
| 556 | + size_t in = strlen(str); | |
| 557 | + size_t out = (in << 1); | |
| 558 | + char * ptr; | |
| 559 | + char * outBuffer = (char *) malloc(out); | |
| 560 | + ICONV_CONST char * inBuffer = (ICONV_CONST char *) str; | |
| 561 | + | |
| 562 | + memset(ptr=outBuffer,0,out); | |
| 563 | + | |
| 564 | + iconv(conv2Host,NULL,NULL,NULL,NULL); // Reset state | |
| 565 | + | |
| 566 | + if(iconv(conv2Host,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) | |
| 567 | + { | |
| 568 | + int rc = this->emulate_input(outBuffer); | |
| 569 | + free(outBuffer); | |
| 570 | + return rc; | |
| 571 | + } | |
| 572 | + | |
| 573 | + free(outBuffer); | |
| 574 | + } | |
| 575 | +#endif // HAVE_ICONV | |
| 576 | + | |
| 577 | + return this->emulate_input(str); | |
| 578 | + | |
| 579 | + } | |
| 580 | + | |
| 581 | + int session::cmp_string_at(int row, int col, const char *text) | |
| 582 | + { | |
| 583 | + return cmp_text_at(row,col,get_3270_text(text).c_str()); | |
| 584 | + } | |
| 585 | + | |
| 586 | + int session::wait_for_string_at(int row, int col, const char *key, int timeout) | |
| 587 | + { | |
| 588 | + return wait_for_text_at(row,col,get_3270_text(key).c_str(),timeout); | |
| 589 | + } | |
| 590 | + | |
| 591 | + string session::get_string(int baddr, size_t len) | |
| 592 | + { | |
| 593 | + return get_local_text(get_text(baddr,len).c_str()); | |
| 594 | + } | |
| 595 | + | |
| 596 | + string session::asc2ebc(string &str) | |
| 597 | + { | |
| 598 | + size_t sz = str.size(); | |
| 599 | + unsigned char buffer[sz+1]; | |
| 600 | + | |
| 601 | + memcpy(buffer,str.c_str(),sz); | |
| 602 | + return string(asc2ebc(buffer,sz)); | |
| 603 | + } | |
| 604 | + | |
| 605 | + string session::ebc2asc(string &str) | |
| 606 | + { | |
| 607 | + size_t sz = str.size(); | |
| 608 | + unsigned char buffer[sz+1]; | |
| 609 | + memcpy(buffer,str.c_str(),sz); | |
| 610 | + return string(ebc2asc(buffer,sz)); | |
| 611 | + } | |
| 612 | + | |
| 613 | + int session::file_transfer(LIB3270_FT_OPTION options, const char *local, const char *remote, int lrecl, int blksize, int primspace, int secspace, int dft) | |
| 614 | + { | |
| 615 | + log("Can't transfer %s: File transfer is unavailable", local ? local : "file"); | |
| 616 | + return EINVAL; | |
| 617 | + } | |
| 618 | + | |
| 619 | + int session::set_host(const char *host) | |
| 620 | + { | |
| 621 | + return set_url(host); | |
| 622 | + } | |
| 623 | + | |
| 624 | + int session::connect(const char *host, time_t wait) | |
| 625 | + { | |
| 626 | + int rc = 0; | |
| 627 | + | |
| 628 | + if(host && *host) | |
| 629 | + { | |
| 630 | + rc = set_url(host); | |
| 631 | + trace("%s: set_url(%s) = %d",__FUNCTION__,host,rc); | |
| 632 | + } | |
| 633 | + | |
| 634 | + rc = connect(); | |
| 635 | + trace("%s: connect=%d",__FUNCTION__,rc); | |
| 636 | + | |
| 637 | + if(!rc && wait) | |
| 638 | + { | |
| 639 | + time_t timeout = time(0)+wait; | |
| 640 | + rc = ETIMEDOUT; | |
| 641 | + | |
| 642 | + while(time(0) < timeout && rc == ETIMEDOUT) | |
| 643 | + { | |
| 644 | + trace("%s: Waiting",__FUNCTION__); | |
| 645 | + if(is_connected()) | |
| 646 | + rc = 0; | |
| 647 | + iterate(true); | |
| 648 | + } | |
| 649 | + } | |
| 650 | + | |
| 651 | + return rc; | |
| 652 | + } | |
| 653 | + | |
| 654 | +#ifdef WIN32 | |
| 655 | + string session::win32_strerror(int e) | |
| 656 | + { | |
| 657 | + static char buffer[4096]; | |
| 658 | + | |
| 659 | + memset(buffer,0,sizeof(buffer)); | |
| 660 | + | |
| 661 | + if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,e,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),buffer,sizeof(buffer),NULL) == 0) | |
| 662 | + { | |
| 663 | + snprintf(buffer,4095,"Windows error %d", e); | |
| 664 | + } | |
| 665 | + | |
| 666 | + for(size_t f=0;f<sizeof(buffer);f++) | |
| 667 | + { | |
| 668 | + if(buffer[f] < ' ') | |
| 669 | + { | |
| 670 | + buffer[f] = 0; | |
| 671 | + break; | |
| 672 | + } | |
| 673 | + } | |
| 674 | + | |
| 675 | + return string(buffer); | |
| 676 | + } | |
| 677 | +#endif // WIN32 | |
| 678 | + | |
| 679 | + int session::erase(int mode) { | |
| 680 | + | |
| 681 | + switch(mode) { | |
| 682 | + case 0: | |
| 683 | + return erase(); | |
| 684 | + | |
| 685 | + case 1: | |
| 686 | + return erase_eof(); | |
| 687 | + | |
| 688 | + case 2: | |
| 689 | + return erase_eol(); | |
| 690 | + | |
| 691 | + case 3: | |
| 692 | + return erase_input(); | |
| 693 | + | |
| 694 | + } | |
| 695 | + | |
| 696 | + return -1; | |
| 697 | + } | |
| 698 | + | |
| 699 | + | |
| 700 | + } | |
| 701 | + | |
| 702 | + | ... | ... |
| ... | ... | @@ -0,0 +1,92 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como testprogram.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include <pw3270/class.h> | |
| 31 | + #include <unistd.h> | |
| 32 | + #include <iostream> | |
| 33 | + | |
| 34 | + using namespace std; | |
| 35 | + using namespace PW3270_NAMESPACE; | |
| 36 | + | |
| 37 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 38 | + | |
| 39 | + int main(int numpar, char *param[]) | |
| 40 | + { | |
| 41 | + | |
| 42 | + { | |
| 43 | + string s; | |
| 44 | + session *session = session::start(""); | |
| 45 | + // session *session = session::start("new"); | |
| 46 | + | |
| 47 | + cout << "pw3270 version: " << session->get_version() << endl; | |
| 48 | + cout << "pw3270 revision: " << session->get_revision() << endl << endl; | |
| 49 | + | |
| 50 | + if(session->is_connected()) | |
| 51 | + cout << "\tConnected to host" << endl; | |
| 52 | + else | |
| 53 | + cout << "\tDisconnected" << endl; | |
| 54 | + | |
| 55 | + cout << "\tSession state: " << session->get_cstate() << endl; | |
| 56 | + | |
| 57 | + s = session->get_display_charset(); | |
| 58 | + cout << "\tDisplay charset: " << s.c_str() << endl; | |
| 59 | + | |
| 60 | + s = session->get_host_charset(); | |
| 61 | + cout << "\tHost charset: " << s.c_str() << endl; | |
| 62 | + | |
| 63 | + cout << "Connect: " << session->connect("fandezhi.efglobe.com:23",60) << endl << endl; | |
| 64 | + | |
| 65 | + cout << "\tWaitForReady: " << session->wait_for_ready(10) << endl; | |
| 66 | + | |
| 67 | + cout << "\tIsConnected: " << session->is_connected() << endl; | |
| 68 | + cout << "\tIsReady: " << session->is_ready() << endl; | |
| 69 | + cout << "\tString(3,2,14) " << session->get_string_at(3,2,14) << endl; | |
| 70 | + | |
| 71 | + delete session; | |
| 72 | + } | |
| 73 | + | |
| 74 | + // Waits | |
| 75 | + sleep(2); | |
| 76 | + | |
| 77 | + // Create another session | |
| 78 | + /* | |
| 79 | + { | |
| 80 | + session *session = session::start("pw3270:a"); | |
| 81 | + | |
| 82 | + session->disconnect(); | |
| 83 | + delete session; | |
| 84 | + | |
| 85 | + } | |
| 86 | + */ | |
| 87 | + | |
| 88 | + | |
| 89 | + return 0; | |
| 90 | + } | |
| 91 | + | |
| 92 | + | ... | ... |
src/pw3270cpp/Makefile.in
| ... | ... | @@ -1,161 +0,0 @@ |
| 1 | -# | |
| 2 | -# "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | -# (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | -# aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | -# | |
| 6 | -# Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | -# | |
| 8 | -# Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | -# os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | -# Free Software Foundation. | |
| 11 | -# | |
| 12 | -# Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | -# GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | -# A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | -# obter mais detalhes. | |
| 16 | -# | |
| 17 | -# Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | -# programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple | |
| 19 | -# Place, Suite 330, Boston, MA, 02111-1307, USA | |
| 20 | -# | |
| 21 | -# Contatos: | |
| 22 | -# | |
| 23 | -# perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 24 | -# erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) | |
| 25 | -# | |
| 26 | - | |
| 27 | -PACKAGE=@PACKAGE_NAME@ | |
| 28 | -LIBNAME=lib$(PACKAGE)cpp.a | |
| 29 | - | |
| 30 | -#---[ Sources ]---------------------------------------------------------------- | |
| 31 | - | |
| 32 | -include class.mak | |
| 33 | - | |
| 34 | -#---[ Paths ]------------------------------------------------------------------ | |
| 35 | - | |
| 36 | -prefix=@prefix@ | |
| 37 | -exec_prefix=@exec_prefix@ | |
| 38 | -datarootdir=@datarootdir@ | |
| 39 | -includedir=@includedir@ | |
| 40 | -libdir=@libdir@ | |
| 41 | - | |
| 42 | -ROOTDIR ?= . | |
| 43 | -OBJDIR ?= $(ROOTDIR)/.obj | |
| 44 | -BINDIR ?= $(ROOTDIR)/.bin | |
| 45 | -BINDBG ?= $(BINDIR)/Debug | |
| 46 | -BINRLS ?= $(BINDIR)/Release | |
| 47 | - | |
| 48 | -OBJDBG = $(OBJDIR)/Debug | |
| 49 | -OBJRLS = $(OBJDIR)/Release | |
| 50 | - | |
| 51 | -#---[ Tools ]------------------------------------------------------------------ | |
| 52 | - | |
| 53 | -MKDIR=@MKDIR_P@ | |
| 54 | -LN_S=@LN_S@ | |
| 55 | -INSTALL=@INSTALL@ | |
| 56 | -INSTALL_DATA=$(INSTALL) -m 644 | |
| 57 | -INSTALL_PROGRAM=@INSTALL_PROGRAM@ | |
| 58 | - | |
| 59 | -#---[ Flags ]------------------------------------------------------------------ | |
| 60 | - | |
| 61 | -CFLAGS=$(CLASS_CFLAGS) -I../include | |
| 62 | -LIBS=@LIBS@ $(CLASS_LIBS) | |
| 63 | - | |
| 64 | -DEBUG_CFLAGS=-DDEBUG=1 -g -Wall | |
| 65 | - | |
| 66 | -EXEEXT=@EXEEXT@ | |
| 67 | - | |
| 68 | -#---[ Rules ]------------------------------------------------------------------ | |
| 69 | - | |
| 70 | -CXX=@CXX@ | |
| 71 | -LD=@CXX@ | |
| 72 | - | |
| 73 | -DEPENDS=../include/*.h ../include/lib3270/*.h ../include/pw3270/*.h Makefile | |
| 74 | - | |
| 75 | -#---[ Rules ]------------------------------------------------------------------ | |
| 76 | - | |
| 77 | -$(OBJDBG)/%.o: %.cc $(DEPENDS) | |
| 78 | - @echo " CC `basename $@`" | |
| 79 | - @$(MKDIR) `dirname $@` | |
| 80 | - @$(CXX) $(CFLAGS) $(DEBUG_CFLAGS) -o $@ -c $< | |
| 81 | - | |
| 82 | -$(OBJRLS)/%.o: %.cc $(DEPENDS) | |
| 83 | - @echo " CC `basename $@`" | |
| 84 | - @$(MKDIR) `dirname $@` | |
| 85 | - @$(CXX) $(CFLAGS) -o $@ -c $< | |
| 86 | - | |
| 87 | -#---[ Release targets ]-------------------------------------------------------- | |
| 88 | - | |
| 89 | -Release: \ | |
| 90 | - $(BINRLS)/$(LIBNAME) | |
| 91 | - | |
| 92 | -$(BINRLS)/$(LIBNAME): \ | |
| 93 | - $(foreach SRC, $(basename $(CLASS_SRC)), $(OBJRLS)/$(SRC).o) | |
| 94 | - | |
| 95 | - @echo " CCLD `basename $@`" | |
| 96 | - @$(MKDIR) `dirname $@` | |
| 97 | - @ar rs $@ $^ | |
| 98 | - | |
| 99 | -install: \ | |
| 100 | - Release | |
| 101 | - | |
| 102 | - @$(MKDIR) $(DESTDIR)$(libdir) | |
| 103 | - @$(INSTALL_PROGRAM) $(BINRLS)/$(LIBNAME) $(DESTDIR)$(libdir) | |
| 104 | - | |
| 105 | - @$(MKDIR) $(DESTDIR)$(includedir) | |
| 106 | - @$(INSTALL_DATA) ../include/pw3270/class.h $(DESTDIR)/$(includedir)/@PACKAGE_NAME@cpp.h | |
| 107 | - | |
| 108 | -zip: \ | |
| 109 | - lib$(PACKAGE)cpp-@PACKAGE_VERSION@.@PACKAGE_REVISION@.@host@.zip | |
| 110 | - | |
| 111 | -lib$(PACKAGE)cpp-@PACKAGE_VERSION@.@PACKAGE_REVISION@.@host@.zip: \ | |
| 112 | - $(BINRLS)/$(LIBNAME) | |
| 113 | - | |
| 114 | - @rm -f $@ | |
| 115 | - | |
| 116 | - @$(INSTALL_DATA) ../include/pw3270/class.h $(BINRLS)/@PACKAGE_NAME@cpp.h | |
| 117 | - | |
| 118 | - @zip -9 -j $@ \ | |
| 119 | - $(BINRLS)/$(LIBNAME) \ | |
| 120 | - $(BINRLS)/@PACKAGE_NAME@cpp.h | |
| 121 | - | |
| 122 | - | |
| 123 | -#---[ Debug targets ]---------------------------------------------------------- | |
| 124 | - | |
| 125 | -Debug: $(BINDBG)/testprogram$(EXEEXT) | |
| 126 | - | |
| 127 | -run: $(BINDBG)/testprogram$(EXEEXT) | |
| 128 | - $(BINDBG)/testprogram$(EXEEXT) | |
| 129 | - | |
| 130 | -$(BINDBG)/testprogram$(EXEEXT): $(OBJDBG)/testprogram.o $(BINDBG)/$(LIBNAME) | |
| 131 | - @echo " CCLD `basename $@`" | |
| 132 | - @$(MKDIR) `dirname $@` | |
| 133 | - @$(LD) $(LIBS) -o $@ $^ | |
| 134 | - | |
| 135 | -$(BINDBG)/$(LIBNAME): $(foreach SRC, $(basename $(CLASS_SRC)), $(OBJDBG)/$(SRC).o) | |
| 136 | - @echo " CCLD `basename $@`" | |
| 137 | - @$(MKDIR) `dirname $@` | |
| 138 | - @ar rs $@ $^ | |
| 139 | - | |
| 140 | -#---[ Misc targets ]----------------------------------------------------------- | |
| 141 | -install-sdk: \ | |
| 142 | - $(BINRLS)/$(LIBNAME) | |
| 143 | - | |
| 144 | - @$(MKDIR) $(DESTDIR)$(datarootdir)/$(PACKAGE)/sample/classlib | |
| 145 | - @$(INSTALL_DATA) *.cc $(DESTDIR)$(datarootdir)/$(PACKAGE)/sample/classlib | |
| 146 | - | |
| 147 | - @$(MKDIR) $(DESTDIR)/$(includedir)/pw3270 | |
| 148 | - @$(INSTALL_DATA) ../include/pw3270/class.h $(DESTDIR)/$(includedir)/pw3270 | |
| 149 | - | |
| 150 | - @$(LN_S) ./pw3270/class.h $(DESTDIR)/$(includedir)/$(PACKAGE)cpp.h | |
| 151 | - | |
| 152 | - @$(MKDIR) $(DESTDIR)/$(libdir) | |
| 153 | - @$(INSTALL_DATA) $(BINRLS)/$(LIBNAME) $(DESTDIR)/$(libdir) | |
| 154 | - | |
| 155 | -cleanDebug: clean | |
| 156 | - | |
| 157 | -clean: | |
| 158 | - @rm -fr $(OBJDIR) | |
| 159 | - @rm -fr $(BINDIR) | |
| 160 | - @rm -f testprogram | |
| 161 | - |
src/pw3270cpp/class.mak.in
| ... | ... | @@ -1,50 +0,0 @@ |
| 1 | -# | |
| 2 | -# "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | -# (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | -# aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | -# | |
| 6 | -# Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | -# | |
| 8 | -# Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | -# os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | -# Free Software Foundation. | |
| 11 | -# | |
| 12 | -# Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | -# GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | -# A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | -# obter mais detalhes. | |
| 16 | -# | |
| 17 | -# Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | -# programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple | |
| 19 | -# Place, Suite 330, Boston, MA, 02111-1307, USA | |
| 20 | -# | |
| 21 | -# Contatos: | |
| 22 | -# | |
| 23 | -# perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 24 | -# erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) | |
| 25 | -# | |
| 26 | - | |
| 27 | -CLASS_CFLAGS=@CFLAGS@ @DLL_CFLAGS@ @DBUS_CFLAGS@ | |
| 28 | -CLASS_LIBS=@LIBICONV@ @DBUS_LIBS@ | |
| 29 | - | |
| 30 | -CLASS_SRC=session.cc exception.cc local.cc remote.cc module.cc | |
| 31 | - | |
| 32 | -CLASS_DEBUG_OBJECTS=$(foreach SRC, $(basename $(CLASS_SRC)), $(OBJDBG)/classlib/$(SRC)@OBJEXT@) | |
| 33 | -CLASS_RELEASE_OBJECTS=$(foreach SRC, $(basename $(CLASS_SRC)), $(OBJRLS)/classlib/$(SRC)@OBJEXT@) | |
| 34 | - | |
| 35 | -#---[ Rules ]------------------------------------------------------------------ | |
| 36 | - | |
| 37 | -$(OBJDBG)/classlib/%.o: \ | |
| 38 | - $(CLASSLIBDIR)/%.cc | |
| 39 | - | |
| 40 | - @echo " CC `basename $@`" | |
| 41 | - @$(MKDIR) `dirname $@` | |
| 42 | - @$(CXX) $(CLASS_CFLAGS) $(PW3270_CFLAGS) $(LIB3270_CFLAGS) $(DEBUG_CFLAGS) -o $@ -c $< | |
| 43 | - | |
| 44 | -$(OBJRLS)/classlib/%.o: \ | |
| 45 | - $(CLASSLIBDIR)/%.cc | |
| 46 | - | |
| 47 | - @echo " CC `basename $@`" | |
| 48 | - @$(MKDIR) `dirname $@` | |
| 49 | - @$(CXX) $(CLASS_CFLAGS) $(PW3270_CFLAGS) $(LIB3270_CFLAGS) -o $@ -c $< | |
| 50 | - |
src/pw3270cpp/classlib.cbp
| ... | ... | @@ -1,49 +0,0 @@ |
| 1 | -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | |
| 2 | -<CodeBlocks_project_file> | |
| 3 | - <FileVersion major="1" minor="6" /> | |
| 4 | - <Project> | |
| 5 | - <Option title="pw3270 Class Library" /> | |
| 6 | - <Option makefile_is_custom="1" /> | |
| 7 | - <Option pch_mode="2" /> | |
| 8 | - <Option compiler="gcc" /> | |
| 9 | - <Build> | |
| 10 | - <Target title="Debug"> | |
| 11 | - <Option output=".bin/Debug/testprogram" prefix_auto="1" extension_auto="1" /> | |
| 12 | - <Option object_output=".obj/Debug/" /> | |
| 13 | - <Option type="1" /> | |
| 14 | - <Option compiler="gcc" /> | |
| 15 | - <Compiler> | |
| 16 | - <Add option="-g" /> | |
| 17 | - </Compiler> | |
| 18 | - </Target> | |
| 19 | - <Target title="Release"> | |
| 20 | - <Option output=".bin/Release/pw3270 Class Library" prefix_auto="1" extension_auto="1" /> | |
| 21 | - <Option working_dir="" /> | |
| 22 | - <Option object_output=".obj/Release/" /> | |
| 23 | - <Option type="2" /> | |
| 24 | - <Option compiler="gcc" /> | |
| 25 | - <Compiler> | |
| 26 | - <Add option="-O2" /> | |
| 27 | - </Compiler> | |
| 28 | - <Linker> | |
| 29 | - <Add option="-s" /> | |
| 30 | - </Linker> | |
| 31 | - </Target> | |
| 32 | - </Build> | |
| 33 | - <Compiler> | |
| 34 | - <Add option="-Wall" /> | |
| 35 | - </Compiler> | |
| 36 | - <Unit filename="../include/pw3270/class.h" /> | |
| 37 | - <Unit filename="Makefile.in" /> | |
| 38 | - <Unit filename="exception.cc" /> | |
| 39 | - <Unit filename="local.cc" /> | |
| 40 | - <Unit filename="remote.cc" /> | |
| 41 | - <Unit filename="session.cc" /> | |
| 42 | - <Unit filename="testprogram.cc" /> | |
| 43 | - <Extensions> | |
| 44 | - <envvars /> | |
| 45 | - <code_completion /> | |
| 46 | - <debugger /> | |
| 47 | - </Extensions> | |
| 48 | - </Project> | |
| 49 | -</CodeBlocks_project_file> |
src/pw3270cpp/exception.cc
| ... | ... | @@ -1,100 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como exception.cc e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | - #include <stdarg.h> | |
| 31 | - #include <stdio.h> | |
| 32 | - #include <string.h> | |
| 33 | - | |
| 34 | - #include <pw3270/class.h> | |
| 35 | - | |
| 36 | -/*--[ Implement ]--------------------------------------------------------------------------------------------------*/ | |
| 37 | - | |
| 38 | - namespace PW3270_NAMESPACE | |
| 39 | - { | |
| 40 | - | |
| 41 | - exception::exception(int syscode) | |
| 42 | - { | |
| 43 | - snprintf(this->msg,4095,"%s",strerror(syscode)); | |
| 44 | - } | |
| 45 | - | |
| 46 | - exception::exception(const char *fmt, ...) | |
| 47 | - { | |
| 48 | - va_list arg_ptr; | |
| 49 | - va_start(arg_ptr, fmt); | |
| 50 | - vsnprintf(this->msg,4095,fmt,arg_ptr); | |
| 51 | - va_end(arg_ptr); | |
| 52 | - } | |
| 53 | - | |
| 54 | -#ifdef WIN32 | |
| 55 | - exception::exception(DWORD error, const char *fmt, ...) | |
| 56 | - { | |
| 57 | - LPVOID lpMsgBuf = 0; | |
| 58 | - char * ptr; | |
| 59 | - size_t szPrefix; | |
| 60 | - | |
| 61 | - va_list arg_ptr; | |
| 62 | - va_start(arg_ptr, fmt); | |
| 63 | - vsnprintf(this->msg,4095,fmt,arg_ptr); | |
| 64 | - va_end(arg_ptr); | |
| 65 | - | |
| 66 | - szPrefix = strlen(this->msg); | |
| 67 | - | |
| 68 | - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); | |
| 69 | - | |
| 70 | - for(ptr= (char *) lpMsgBuf;*ptr && *ptr != '\n';ptr++); | |
| 71 | - *ptr = 0; | |
| 72 | - | |
| 73 | - snprintf(this->msg+szPrefix,4095-szPrefix,": %s (rc=%d)",(char *) lpMsgBuf,(int) error); | |
| 74 | - | |
| 75 | - LocalFree(lpMsgBuf); | |
| 76 | - | |
| 77 | - } | |
| 78 | -#else | |
| 79 | - exception::exception(int error, const char *fmt, ...) | |
| 80 | - { | |
| 81 | - size_t szPrefix; | |
| 82 | - | |
| 83 | - va_list arg_ptr; | |
| 84 | - va_start(arg_ptr, fmt); | |
| 85 | - vsnprintf(this->msg,4095,fmt,arg_ptr); | |
| 86 | - va_end(arg_ptr); | |
| 87 | - | |
| 88 | - szPrefix = strlen(this->msg); | |
| 89 | - | |
| 90 | - snprintf(this->msg+szPrefix,4095-szPrefix,": %s (rc=%d)",strerror(error),(int) error); | |
| 91 | - | |
| 92 | - } | |
| 93 | -#endif // WIN32 | |
| 94 | - | |
| 95 | - const char * exception::what() const throw() | |
| 96 | - { | |
| 97 | - return this->msg; | |
| 98 | - } | |
| 99 | - | |
| 100 | - } |
src/pw3270cpp/local.cc
| ... | ... | @@ -1,599 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como local.cc e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | -#if defined WIN32 | |
| 31 | - | |
| 32 | - // http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx | |
| 33 | - #ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
| 34 | - #define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000 | |
| 35 | - #endif // LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
| 36 | - | |
| 37 | - #ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
| 38 | - #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100 | |
| 39 | - #endif // LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
| 40 | - | |
| 41 | - #include <windows.h> | |
| 42 | - | |
| 43 | -#else | |
| 44 | - | |
| 45 | - #include <dlfcn.h> | |
| 46 | - | |
| 47 | -#endif | |
| 48 | - | |
| 49 | -#include "private.h" | |
| 50 | - | |
| 51 | -#include <lib3270/log.h> | |
| 52 | -#include <lib3270/popup.h> | |
| 53 | -#include <string.h> | |
| 54 | -#include <stdio.h> | |
| 55 | - | |
| 56 | -#ifdef HAVE_SYSLOG | |
| 57 | - #include <syslog.h> | |
| 58 | - #include <stdarg.h> | |
| 59 | -#endif // HAVE_SYSLOG | |
| 60 | - | |
| 61 | -/*--[ Implement ]--------------------------------------------------------------------------------------------------*/ | |
| 62 | - | |
| 63 | - extern "C" | |
| 64 | - { | |
| 65 | - static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) | |
| 66 | - { | |
| 67 | - #ifdef HAVE_SYSLOG | |
| 68 | - openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
| 69 | - vsyslog(LOG_INFO,fmt,args); | |
| 70 | - closelog(); | |
| 71 | - #endif // HAVE_SYSLOG | |
| 72 | - } | |
| 73 | - | |
| 74 | - static void tracehandler(H3270 *session, const char *fmt, va_list args) | |
| 75 | - { | |
| 76 | - #ifdef HAVE_SYSLOG | |
| 77 | - | |
| 78 | - #define MAX_LOG_LENGTH 200 | |
| 79 | - | |
| 80 | - static char line[MAX_LOG_LENGTH+1]; | |
| 81 | - char temp[MAX_LOG_LENGTH]; | |
| 82 | - char * ptr; | |
| 83 | - size_t len = strlen(line); | |
| 84 | - | |
| 85 | - vsnprintf(temp,MAX_LOG_LENGTH-len,fmt,args); | |
| 86 | - | |
| 87 | - ptr = strchr(temp,'\n'); | |
| 88 | - if(!ptr) | |
| 89 | - { | |
| 90 | - strncat(line,temp,MAX_LOG_LENGTH); | |
| 91 | - if(strlen(line) >= MAX_LOG_LENGTH) | |
| 92 | - { | |
| 93 | - openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
| 94 | - syslog(LOG_INFO,"%s",line); | |
| 95 | - closelog(); | |
| 96 | - *line = 0; | |
| 97 | - } | |
| 98 | - return; | |
| 99 | - } | |
| 100 | - | |
| 101 | - *ptr = 0; | |
| 102 | - strncat(line,temp,MAX_LOG_LENGTH); | |
| 103 | - | |
| 104 | - openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
| 105 | - syslog(LOG_DEBUG,"%s",line); | |
| 106 | - closelog(); | |
| 107 | - | |
| 108 | - strncpy(line,ptr+1,MAX_LOG_LENGTH); | |
| 109 | - | |
| 110 | - #endif // HAVE_SYSLOG | |
| 111 | - } | |
| 112 | - | |
| 113 | - } | |
| 114 | - | |
| 115 | - namespace PW3270_NAMESPACE | |
| 116 | - { | |
| 117 | - | |
| 118 | - class local : public session, protected module, protected recursive_mutex | |
| 119 | - { | |
| 120 | - private: | |
| 121 | - | |
| 122 | - // Lib3270 entry points | |
| 123 | - const char * (*_get_version)(void); | |
| 124 | - LIB3270_CSTATE (*_get_connection_state)(H3270 *h); | |
| 125 | - LIB3270_MESSAGE (*_get_program_message)(H3270 *h); | |
| 126 | - LIB3270_SSL_STATE (*_get_secure)(H3270 *h); | |
| 127 | - | |
| 128 | - | |
| 129 | - int (*_disconnect)(H3270 *h); | |
| 130 | - int (*_connect)(H3270 *h,int wait); | |
| 131 | - const char (*_set_url)(H3270 *h, const char *n); | |
| 132 | - const char * (*_get_url)(H3270 *h, char *str, int len); | |
| 133 | - int (*_is_connected)(H3270 *h); | |
| 134 | - void (*_main_iterate)(H3270 *h, int wait); | |
| 135 | - int (*_wait)(H3270 *hSession, int seconds); | |
| 136 | - int (*_enter)(H3270 *hSession); | |
| 137 | - int (*_pfkey)(H3270 *hSession, int key); | |
| 138 | - int (*_pakey)(H3270 *hSession, int key); | |
| 139 | - int (*_wait_for_ready)(H3270 *hSession, int seconds); | |
| 140 | - char * (*_get_text)(H3270 *h, int offset, int len); | |
| 141 | - char * (*_get_text_at)(H3270 *h, int row, int col, int len); | |
| 142 | - int (*_cmp_text_at)(H3270 *h, int row, int col, const char *text); | |
| 143 | - int (*_set_text_at)(H3270 *h, int row, int col, const unsigned char *str); | |
| 144 | - int (*_is_ready)(H3270 *h); | |
| 145 | - int (*_set_cursor_position)(H3270 *h, int row, int col); | |
| 146 | - int (*_set_toggle)(H3270 *h, LIB3270_TOGGLE ix, int value); | |
| 147 | - int (*_get_field_start)(H3270 *h, int baddr); | |
| 148 | - int (*_get_field_len)(H3270 *h, int baddr); | |
| 149 | - int (*_set_cursor_addr)(H3270 *h, int addr); | |
| 150 | - int (*_get_cursor_addr)(H3270 *h); | |
| 151 | - int (*_emulate_input)(H3270 *session, const char *s, int len, int pasting); | |
| 152 | - int (*_get_next_unprotected)(H3270 *hSession, int baddr0); | |
| 153 | - int (*_get_is_protected)(H3270 *hSession, int baddr); | |
| 154 | - int (*_get_is_protected_at)(H3270 *hSession, int row, int col); | |
| 155 | - void (*_popup_va)(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, va_list); | |
| 156 | - void * (*_free)(void *); | |
| 157 | - const char * (*_get_display_charset)(H3270 *hSession); | |
| 158 | - int (*_set_host_charset)(H3270 *hSession, const char *name); | |
| 159 | - const char * (*_get_host_charset)(H3270 *hSession); | |
| 160 | - int (*_print)(H3270 *hSession); | |
| 161 | - int (*_erase)(H3270 *hSession); | |
| 162 | - int (*_erase_eof)(H3270 *hSession); | |
| 163 | - int (*_erase_eol)(H3270 *hSession); | |
| 164 | - int (*_erase_input)(H3270 *hSession); | |
| 165 | - int (*_action)(H3270 *hSession, const char *name); | |
| 166 | - int (*_set_unlock_delay)(H3270 *hSession, unsigned short ms); | |
| 167 | - | |
| 168 | - int (*_get_width)(H3270 *hSession); | |
| 169 | - int (*_get_height)(H3270 *hSession); | |
| 170 | - int (*_get_length)(H3270 *hSession); | |
| 171 | - | |
| 172 | - const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, int sz); | |
| 173 | - const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, int sz); | |
| 174 | - | |
| 175 | - protected: | |
| 176 | - | |
| 177 | - H3270 * hSession; | |
| 178 | - | |
| 179 | - void load_methods() { | |
| 180 | - | |
| 181 | - void (*set_log_handler)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list)); | |
| 182 | - void (*set_trace_handler)( void (*handler)(H3270 *session, const char *fmt, va_list args) ); | |
| 183 | - | |
| 184 | - struct _call | |
| 185 | - { | |
| 186 | - void **entry; | |
| 187 | - const char * name; | |
| 188 | - } call[] = | |
| 189 | - { | |
| 190 | - { (void **) & set_log_handler, "lib3270_set_log_handler" }, | |
| 191 | - { (void **) & set_trace_handler, "lib3270_set_trace_handler" }, | |
| 192 | - | |
| 193 | - { (void **) & _is_connected, "lib3270_is_connected" }, | |
| 194 | - { (void **) & _get_connection_state, "lib3270_get_connection_state" }, | |
| 195 | - { (void **) & _get_program_message, "lib3270_get_program_message" }, | |
| 196 | - { (void **) & _get_secure, "lib3270_get_secure" }, | |
| 197 | - | |
| 198 | - { (void **) & _get_version, "lib3270_get_version" }, | |
| 199 | - { (void **) & _disconnect, "lib3270_disconnect" }, | |
| 200 | - { (void **) & _connect, "lib3270_connect" }, | |
| 201 | - { (void **) & _set_url, "lib3270_set_url" }, | |
| 202 | - { (void **) & _get_url, "lib3270_get_url" }, | |
| 203 | - { (void **) & _main_iterate, "lib3270_main_iterate" }, | |
| 204 | - { (void **) & _wait, "lib3270_wait" }, | |
| 205 | - { (void **) & _enter, "lib3270_enter" }, | |
| 206 | - { (void **) & _pfkey, "lib3270_pfkey" }, | |
| 207 | - { (void **) & _pakey, "lib3270_pakey" }, | |
| 208 | - { (void **) & _wait_for_ready, "lib3270_wait_for_ready" }, | |
| 209 | - { (void **) & _get_text, "lib3270_get_text" }, | |
| 210 | - { (void **) & _get_text_at, "lib3270_get_text_at" }, | |
| 211 | - { (void **) & _cmp_text_at, "lib3270_cmp_text_at" }, | |
| 212 | - { (void **) & _set_text_at, "lib3270_set_string_at" }, | |
| 213 | - { (void **) & _is_ready, "lib3270_is_ready" }, | |
| 214 | - { (void **) & _set_cursor_position, "lib3270_set_cursor_position" }, | |
| 215 | - { (void **) & _set_toggle, "lib3270_set_toggle" }, | |
| 216 | - { (void **) & _get_field_start, "lib3270_get_field_start" }, | |
| 217 | - { (void **) & _get_field_len, "lib3270_get_field_len" }, | |
| 218 | - { (void **) & _set_cursor_addr, "lib3270_set_cursor_address" }, | |
| 219 | - { (void **) & _get_cursor_addr, "lib3270_get_cursor_address" }, | |
| 220 | - { (void **) & _emulate_input, "lib3270_emulate_input" }, | |
| 221 | - { (void **) & _get_next_unprotected, "lib3270_get_next_unprotected" }, | |
| 222 | - { (void **) & _get_is_protected, "lib3270_get_is_protected" }, | |
| 223 | - { (void **) & _get_is_protected_at, "lib3270_get_is_protected_at" }, | |
| 224 | - { (void **) & _popup_va, "lib3270_popup_va" }, | |
| 225 | - { (void **) & _free, "lib3270_free" }, | |
| 226 | - { (void **) & _get_display_charset, "lib3270_get_display_charset" }, | |
| 227 | - { (void **) & _set_host_charset, "lib3270_set_host_charset" }, | |
| 228 | - { (void **) & _get_host_charset, "lib3270_get_host_charset" }, | |
| 229 | - | |
| 230 | - { (void **) & _erase, "lib3270_erase" }, | |
| 231 | - { (void **) & _erase_eof, "lib3270_eraseeof" }, | |
| 232 | - { (void **) & _erase_eol, "lib3270_eraseeol" }, | |
| 233 | - { (void **) & _erase_input, "lib3270_eraseinput" }, | |
| 234 | - | |
| 235 | - { (void **) & _print, "lib3270_print" }, | |
| 236 | - { (void **) & _ebc2asc, "lib3270_ebc2asc" }, | |
| 237 | - { (void **) & _asc2ebc, "lib3270_asc2ebc" }, | |
| 238 | - | |
| 239 | - { (void **) & _action, "lib3270_action" }, | |
| 240 | - { (void **) & _set_unlock_delay, "lib3270_set_unlock_delay" }, | |
| 241 | - | |
| 242 | - { (void **) & _get_width, "lib3270_get_width" }, | |
| 243 | - { (void **) & _get_height, "lib3270_get_height" }, | |
| 244 | - { (void **) & _get_length, "lib3270_get_length" }, | |
| 245 | - | |
| 246 | - }; | |
| 247 | - | |
| 248 | - for(unsigned int f = 0; f < (sizeof (call) / sizeof ((call)[0]));f++) | |
| 249 | - { | |
| 250 | - *call[f].entry = (void *) get_symbol(call[f].name); | |
| 251 | - if(!*call[f].entry) | |
| 252 | - throw exception("Can't find symbol %s",call[f].name); | |
| 253 | - } | |
| 254 | - | |
| 255 | - // Get Session handle, setup base callbacks | |
| 256 | - set_log_handler(loghandler); | |
| 257 | - set_trace_handler(tracehandler); | |
| 258 | - | |
| 259 | - set_display_charset(); | |
| 260 | - | |
| 261 | - } | |
| 262 | - | |
| 263 | - public: | |
| 264 | - | |
| 265 | - local() throw(std::exception) : module("lib3270",PACKAGE_VERSION) | |
| 266 | - { | |
| 267 | - } | |
| 268 | - | |
| 269 | - virtual ~local() | |
| 270 | - { | |
| 271 | - } | |
| 272 | - | |
| 273 | - bool is_connected(void) | |
| 274 | - { | |
| 275 | - return _is_connected(hSession); | |
| 276 | - } | |
| 277 | - | |
| 278 | - LIB3270_CSTATE get_cstate(void) | |
| 279 | - { | |
| 280 | - return _get_connection_state(hSession); | |
| 281 | - } | |
| 282 | - | |
| 283 | - LIB3270_MESSAGE get_program_message(void) { | |
| 284 | - return _get_program_message(hSession); | |
| 285 | - } | |
| 286 | - | |
| 287 | - LIB3270_SSL_STATE get_secure(void) { | |
| 288 | - return _get_secure(hSession); | |
| 289 | - }; | |
| 290 | - | |
| 291 | - int connect(void) | |
| 292 | - { | |
| 293 | - this->lock(); | |
| 294 | - int rc = _connect(hSession,0); | |
| 295 | - this->unlock(); | |
| 296 | - | |
| 297 | - return rc; | |
| 298 | - } | |
| 299 | - | |
| 300 | - int set_url(const char *uri) | |
| 301 | - { | |
| 302 | - return (_set_url(hSession,uri) == 0); | |
| 303 | - } | |
| 304 | - | |
| 305 | - string get_url() | |
| 306 | - { | |
| 307 | - char buffer[1024]; | |
| 308 | - return string(_get_url(hSession,buffer,sizeof(buffer))); | |
| 309 | - } | |
| 310 | - | |
| 311 | - int disconnect(void) | |
| 312 | - { | |
| 313 | - this->lock(); | |
| 314 | - int rc = _disconnect(hSession); | |
| 315 | - this->unlock(); | |
| 316 | - | |
| 317 | - return rc; | |
| 318 | - } | |
| 319 | - | |
| 320 | - bool is_ready(void) | |
| 321 | - { | |
| 322 | - return _is_ready(hSession) != 0; | |
| 323 | - } | |
| 324 | - | |
| 325 | - int wait_for_ready(int seconds) | |
| 326 | - { | |
| 327 | - return _wait_for_ready(hSession,seconds); | |
| 328 | - } | |
| 329 | - | |
| 330 | - int wait(int seconds) | |
| 331 | - { | |
| 332 | - return _wait(hSession,seconds); | |
| 333 | - } | |
| 334 | - | |
| 335 | - int iterate(bool wait) | |
| 336 | - { | |
| 337 | - this->lock(); | |
| 338 | - _main_iterate(hSession,wait); | |
| 339 | - this->unlock(); | |
| 340 | - return 0; | |
| 341 | - } | |
| 342 | - | |
| 343 | - string get_text_at(int row, int col, size_t sz) | |
| 344 | - { | |
| 345 | - string rc; | |
| 346 | - char * ptr = _get_text_at(hSession,row,col,sz); | |
| 347 | - | |
| 348 | - if(ptr) | |
| 349 | - { | |
| 350 | - rc.assign(ptr); | |
| 351 | - _free(ptr); | |
| 352 | - } | |
| 353 | - | |
| 354 | - return rc; | |
| 355 | - } | |
| 356 | - | |
| 357 | - int set_text_at(int row, int col, const char *str) | |
| 358 | - { | |
| 359 | - return _set_text_at(hSession,row,col,(const unsigned char *) str); | |
| 360 | - } | |
| 361 | - | |
| 362 | - int cmp_text_at(int row, int col, const char *text) | |
| 363 | - { | |
| 364 | - return _cmp_text_at(hSession,row,col,text); | |
| 365 | - } | |
| 366 | - | |
| 367 | - string get_text(int offset, size_t len) | |
| 368 | - { | |
| 369 | - string rc; | |
| 370 | - char * ptr = _get_text(hSession,offset,len); | |
| 371 | - | |
| 372 | - if(ptr) | |
| 373 | - { | |
| 374 | - rc.assign(ptr); | |
| 375 | - _free(ptr); | |
| 376 | - } | |
| 377 | - | |
| 378 | - return rc; | |
| 379 | - } | |
| 380 | - | |
| 381 | - int set_cursor_position(int row, int col) | |
| 382 | - { | |
| 383 | - return _set_cursor_position(hSession,row,col); | |
| 384 | - } | |
| 385 | - | |
| 386 | - int set_cursor_addr(int addr) | |
| 387 | - { | |
| 388 | - return _set_cursor_addr(hSession,addr); | |
| 389 | - } | |
| 390 | - | |
| 391 | - int get_cursor_addr(void) | |
| 392 | - { | |
| 393 | - return _get_cursor_addr(hSession); | |
| 394 | - } | |
| 395 | - | |
| 396 | - int enter(void) | |
| 397 | - { | |
| 398 | - return _enter(hSession); | |
| 399 | - } | |
| 400 | - | |
| 401 | - int pfkey(int key) | |
| 402 | - { | |
| 403 | - return _pfkey(hSession,key); | |
| 404 | - } | |
| 405 | - | |
| 406 | - int pakey(int key) | |
| 407 | - { | |
| 408 | - return _pakey(hSession,key); | |
| 409 | - } | |
| 410 | - | |
| 411 | - int quit(void) | |
| 412 | - { | |
| 413 | - return EINVAL; | |
| 414 | - } | |
| 415 | - | |
| 416 | - int set_toggle(LIB3270_TOGGLE ix, bool value) | |
| 417 | - { | |
| 418 | - return _set_toggle(hSession, ix, (int) value); | |
| 419 | - } | |
| 420 | - | |
| 421 | - int emulate_input(const char *str) | |
| 422 | - { | |
| 423 | - return _emulate_input(hSession,str,-1,1); | |
| 424 | - } | |
| 425 | - | |
| 426 | - int get_field_start(int baddr) | |
| 427 | - { | |
| 428 | - return _get_field_start(hSession,baddr); | |
| 429 | - } | |
| 430 | - | |
| 431 | - int get_field_len(int baddr) | |
| 432 | - { | |
| 433 | - return _get_field_len(hSession,baddr); | |
| 434 | - } | |
| 435 | - | |
| 436 | - int get_next_unprotected(int baddr) | |
| 437 | - { | |
| 438 | - return _get_next_unprotected(hSession,baddr); | |
| 439 | - } | |
| 440 | - | |
| 441 | - int get_is_protected(int baddr) | |
| 442 | - { | |
| 443 | - return _get_is_protected(hSession,baddr); | |
| 444 | - } | |
| 445 | - | |
| 446 | - int get_is_protected_at(int row, int col) | |
| 447 | - { | |
| 448 | - return _get_is_protected_at(hSession,row,col); | |
| 449 | - } | |
| 450 | - | |
| 451 | - int popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...) | |
| 452 | - { | |
| 453 | - va_list args; | |
| 454 | - va_start(args, fmt); | |
| 455 | - _popup_va(hSession, id, title, message, fmt, args); | |
| 456 | - va_end(args); | |
| 457 | - return 0; | |
| 458 | - } | |
| 459 | - | |
| 460 | - string get_display_charset(void) | |
| 461 | - { | |
| 462 | - return string(_get_display_charset(hSession)); | |
| 463 | - } | |
| 464 | - | |
| 465 | - int set_host_charset(const char *charset) | |
| 466 | - { | |
| 467 | - return _set_host_charset(hSession,charset); | |
| 468 | - } | |
| 469 | - | |
| 470 | - string get_host_charset(void) | |
| 471 | - { | |
| 472 | - return string(_get_host_charset(hSession)); | |
| 473 | - } | |
| 474 | - | |
| 475 | - int erase(void) | |
| 476 | - { | |
| 477 | - return _erase(hSession); | |
| 478 | - } | |
| 479 | - | |
| 480 | - int erase_eof(void) | |
| 481 | - { | |
| 482 | - return _erase_eof(hSession); | |
| 483 | - } | |
| 484 | - | |
| 485 | - int erase_eol(void) | |
| 486 | - { | |
| 487 | - return _erase_eol(hSession); | |
| 488 | - } | |
| 489 | - | |
| 490 | - int erase_input(void) | |
| 491 | - { | |
| 492 | - return _erase_input(hSession); | |
| 493 | - } | |
| 494 | - | |
| 495 | - int print(void) | |
| 496 | - { | |
| 497 | - return _print(hSession); | |
| 498 | - } | |
| 499 | - | |
| 500 | - | |
| 501 | - const char * asc2ebc(unsigned char *str, int sz) | |
| 502 | - { | |
| 503 | - return _asc2ebc(hSession,str,sz); | |
| 504 | - } | |
| 505 | - | |
| 506 | - const char * ebc2asc(unsigned char *str, int sz) | |
| 507 | - { | |
| 508 | - return _ebc2asc(hSession,str,sz); | |
| 509 | - } | |
| 510 | - | |
| 511 | - int action(const char *name) | |
| 512 | - { | |
| 513 | - return _action(hSession,name); | |
| 514 | - } | |
| 515 | - | |
| 516 | - void set_unlock_delay(unsigned short ms) | |
| 517 | - { | |
| 518 | - _set_unlock_delay(hSession,ms); | |
| 519 | - } | |
| 520 | - | |
| 521 | - int get_width(void) { | |
| 522 | - return _get_width(hSession); | |
| 523 | - } | |
| 524 | - | |
| 525 | - int get_height(void) { | |
| 526 | - return _get_height(hSession); | |
| 527 | - } | |
| 528 | - | |
| 529 | - int get_length(void) { | |
| 530 | - return _get_length(hSession); | |
| 531 | - } | |
| 532 | - | |
| 533 | - }; | |
| 534 | - | |
| 535 | - session * session::create_local(void) throw (std::exception) | |
| 536 | - { | |
| 537 | - class obj : public local { | |
| 538 | - public: | |
| 539 | - obj() : local() { | |
| 540 | - | |
| 541 | - H3270 * (*lib3270_new)(const char *) = (H3270 * (*)(const char *)) get_symbol("lib3270_session_new"); | |
| 542 | - | |
| 543 | - if(!lib3270_new) | |
| 544 | - throw exception("Can't find symbol %s","lib3270_session_new"); | |
| 545 | - | |
| 546 | - this->hSession = lib3270_new(""); | |
| 547 | - | |
| 548 | - load_methods(); | |
| 549 | - | |
| 550 | - } | |
| 551 | - | |
| 552 | - virtual ~obj() { | |
| 553 | - | |
| 554 | - this->lock(); | |
| 555 | - | |
| 556 | - if(is_connected()) { | |
| 557 | - disconnect(); | |
| 558 | - } | |
| 559 | - | |
| 560 | - try | |
| 561 | - { | |
| 562 | - static void (*session_free)(H3270 *h) = (void (*)(H3270 *)) get_symbol("lib3270_session_free"); | |
| 563 | - | |
| 564 | - if(session_free && this->hSession) | |
| 565 | - session_free(this->hSession); | |
| 566 | - | |
| 567 | - this->hSession = 0; | |
| 568 | - | |
| 569 | - } | |
| 570 | - catch(exception e) { } | |
| 571 | - | |
| 572 | - this->unlock(); | |
| 573 | - | |
| 574 | - } | |
| 575 | - }; | |
| 576 | - | |
| 577 | - return new obj(); | |
| 578 | - } | |
| 579 | - | |
| 580 | - session * session::create_local(H3270 *hSession) throw (std::exception) | |
| 581 | - { | |
| 582 | - class obj : public local { | |
| 583 | - public: | |
| 584 | - obj(H3270 *hSession) : local() | |
| 585 | - { | |
| 586 | - this->hSession = hSession; | |
| 587 | - load_methods(); | |
| 588 | - } | |
| 589 | - | |
| 590 | - virtual ~obj() { | |
| 591 | - } | |
| 592 | - | |
| 593 | - }; | |
| 594 | - | |
| 595 | - return new obj(hSession); | |
| 596 | - } | |
| 597 | - | |
| 598 | - } | |
| 599 | - |
src/pw3270cpp/module.cc
| ... | ... | @@ -1,217 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como module.cc e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | -#if defined WIN32 | |
| 31 | - | |
| 32 | - // http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx | |
| 33 | - #ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
| 34 | - #define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000 | |
| 35 | - #endif // LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | |
| 36 | - | |
| 37 | - #ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
| 38 | - #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100 | |
| 39 | - #endif // LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | |
| 40 | - | |
| 41 | - #include <windows.h> | |
| 42 | - | |
| 43 | -#else | |
| 44 | - | |
| 45 | - #include <dlfcn.h> | |
| 46 | - | |
| 47 | -#endif | |
| 48 | - | |
| 49 | -#include <pw3270/class.h> | |
| 50 | - | |
| 51 | -/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 52 | - | |
| 53 | - | |
| 54 | -namespace PW3270_NAMESPACE | |
| 55 | -{ | |
| 56 | - | |
| 57 | -#ifdef WIN32 | |
| 58 | - int module::get_datadir(LPSTR datadir) | |
| 59 | - { | |
| 60 | - HKEY hKey = 0; | |
| 61 | - unsigned long datalen = strlen(datadir); | |
| 62 | - | |
| 63 | - *datadir = 0; | |
| 64 | - | |
| 65 | - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) | |
| 66 | - { | |
| 67 | - unsigned long datatype; // #defined in winnt.h (predefined types 0-11) | |
| 68 | - if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) != ERROR_SUCCESS) | |
| 69 | - *datadir = 0; | |
| 70 | - RegCloseKey(hKey); | |
| 71 | - } | |
| 72 | - | |
| 73 | - return *datadir; | |
| 74 | - } | |
| 75 | -#endif // WIN32 | |
| 76 | - | |
| 77 | - module::module(const char *name, const char *version) throw (std::exception) | |
| 78 | - { | |
| 79 | - string dllname = name; | |
| 80 | - | |
| 81 | -#ifdef WIN32 | |
| 82 | - | |
| 83 | - dllname += ".dll"; | |
| 84 | - if(version) | |
| 85 | - { | |
| 86 | - dllname += "."; | |
| 87 | - dllname += version; | |
| 88 | - } | |
| 89 | - | |
| 90 | - HMODULE kernel; | |
| 91 | - HANDLE cookie = NULL; | |
| 92 | - DWORD rc; | |
| 93 | - HANDLE WINAPI (*AddDllDirectory)(PCWSTR NewDirectory); | |
| 94 | - BOOL WINAPI (*RemoveDllDirectory)(HANDLE Cookie); | |
| 95 | - UINT errorMode; | |
| 96 | - char datadir[4096]; | |
| 97 | - char buffer[4096]; | |
| 98 | - | |
| 99 | - kernel = LoadLibrary("kernel32.dll"); | |
| 100 | - AddDllDirectory = (HANDLE WINAPI (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory"); | |
| 101 | - RemoveDllDirectory = (BOOL WINAPI (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory"); | |
| 102 | - | |
| 103 | - // Notify user in case of error loading protocol DLL | |
| 104 | - // http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v=vs.85).aspx | |
| 105 | - errorMode = SetErrorMode(1); | |
| 106 | - | |
| 107 | - memset(datadir,' ',4095); | |
| 108 | - datadir[4095] = 0; | |
| 109 | - | |
| 110 | - if(get_datadir(datadir)) | |
| 111 | - { | |
| 112 | - trace("Datadir=[%s] AddDllDirectory=%p RemoveDllDirectory=%p\n",datadir,AddDllDirectory,RemoveDllDirectory); | |
| 113 | - | |
| 114 | - if(AddDllDirectory) | |
| 115 | - { | |
| 116 | - wchar_t *path = (wchar_t *) malloc(4096*sizeof(wchar_t)); | |
| 117 | - mbstowcs(path, datadir, 4095); | |
| 118 | - cookie = AddDllDirectory(path); | |
| 119 | - free(path); | |
| 120 | - } | |
| 121 | - | |
| 122 | -#ifdef DEBUG | |
| 123 | - snprintf(buffer,4096,"%s\\.bin\\Debug\\%s",datadir,dllname.c_str()); | |
| 124 | -#else | |
| 125 | - snprintf(buffer,4096,"%s\\%s",datadir,dllname.c_str()); | |
| 126 | -#endif // DEBUG | |
| 127 | - | |
| 128 | - trace("Loading [%s] [%s]",buffer,datadir); | |
| 129 | - hModule = LoadLibrary(buffer); | |
| 130 | - | |
| 131 | - trace("Module=%p rc=%d",hModule,(int) GetLastError()); | |
| 132 | - | |
| 133 | - if(hModule == NULL) | |
| 134 | - { | |
| 135 | - // Enable DLL error popup and try again with full path | |
| 136 | - SetErrorMode(0); | |
| 137 | - hModule = LoadLibraryEx(buffer,NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS|LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); | |
| 138 | - } | |
| 139 | - | |
| 140 | - rc = GetLastError(); | |
| 141 | - | |
| 142 | - trace("%s hModule=%p rc=%d",buffer,hModule,(int) rc); | |
| 143 | - } | |
| 144 | - else | |
| 145 | - { | |
| 146 | - hModule = LoadLibrary(dllname.c_str()); | |
| 147 | - rc = GetLastError(); | |
| 148 | - } | |
| 149 | - | |
| 150 | - SetErrorMode(errorMode); | |
| 151 | - | |
| 152 | - trace("%s hModule=%p rc=%d",dllname.c_str(),hModule,(int) rc); | |
| 153 | - | |
| 154 | - if(cookie && RemoveDllDirectory) | |
| 155 | - RemoveDllDirectory(cookie); | |
| 156 | - | |
| 157 | - if(kernel) | |
| 158 | - FreeLibrary(kernel); | |
| 159 | - | |
| 160 | - if(!hModule) | |
| 161 | - { | |
| 162 | - throw exception("%s: %s",dllname.c_str(),session::win32_strerror(rc).c_str()); | |
| 163 | - } | |
| 164 | - | |
| 165 | -#else | |
| 166 | - dllname += ".so"; | |
| 167 | - if(version) | |
| 168 | - { | |
| 169 | - dllname += "."; | |
| 170 | - dllname += version; | |
| 171 | - } | |
| 172 | - | |
| 173 | - dlerror(); | |
| 174 | - | |
| 175 | - hModule = dlopen(dllname.c_str(), RTLD_NOW); | |
| 176 | - if(!hModule) | |
| 177 | - throw exception("Can't load lib3270: %s",dllname.c_str()); | |
| 178 | - | |
| 179 | -#endif // WIN32 | |
| 180 | - | |
| 181 | - | |
| 182 | - } | |
| 183 | - | |
| 184 | - module::~module() | |
| 185 | - { | |
| 186 | -#ifdef WIN32 | |
| 187 | - FreeLibrary(hModule); | |
| 188 | -#else | |
| 189 | - dlclose(hModule); | |
| 190 | -#endif // WIN32 | |
| 191 | - } | |
| 192 | - | |
| 193 | - | |
| 194 | - void * module::get_symbol(const char *name) | |
| 195 | - { | |
| 196 | - void *symbol; | |
| 197 | - | |
| 198 | -#ifdef WIN32 | |
| 199 | - | |
| 200 | - symbol = (void *) GetProcAddress(hModule,name); | |
| 201 | - | |
| 202 | - if(!symbol) | |
| 203 | - throw exception("Can't load symbol %s",name); | |
| 204 | - | |
| 205 | -#else | |
| 206 | - symbol = dlsym(hModule,name); | |
| 207 | - | |
| 208 | - if(!symbol) | |
| 209 | - throw exception("Can't load symbol %s dlerror was \"%s\"",name,dlerror()); | |
| 210 | - | |
| 211 | -#endif // WIN32 | |
| 212 | - | |
| 213 | - return symbol; | |
| 214 | - } | |
| 215 | - | |
| 216 | -} | |
| 217 | - |
src/pw3270cpp/private.h
| ... | ... | @@ -1,113 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como private.h e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | -#ifndef PRIVATE_H_INCLUDED | |
| 31 | - | |
| 32 | - #define PRIVATE_H_INCLUDED | |
| 33 | - | |
| 34 | - #include <cstring> | |
| 35 | - #include <pw3270/class.h> | |
| 36 | - | |
| 37 | - #if defined(_WIN32) | |
| 38 | - | |
| 39 | - class recursive_mutex { | |
| 40 | - private: | |
| 41 | - HANDLE hMutex; | |
| 42 | - | |
| 43 | - public: | |
| 44 | - recursive_mutex() { | |
| 45 | - hMutex = CreateMutex(NULL,FALSE,NULL); | |
| 46 | - }; | |
| 47 | - | |
| 48 | - ~recursive_mutex() { | |
| 49 | - CloseHandle(hMutex); | |
| 50 | - }; | |
| 51 | - | |
| 52 | - void lock(void) { | |
| 53 | - WaitForSingleObject(hMutex,INFINITE); | |
| 54 | - }; | |
| 55 | - | |
| 56 | - void unlock(void) { | |
| 57 | - ReleaseMutex(hMutex); | |
| 58 | - }; | |
| 59 | - | |
| 60 | - bool try_lock(void) { | |
| 61 | - if(WaitForSingleObject(hMutex,1) == WAIT_OBJECT_0) | |
| 62 | - return true; | |
| 63 | - return false; | |
| 64 | - }; | |
| 65 | - }; | |
| 66 | - | |
| 67 | - #elif __cplusplus < 201103L | |
| 68 | - | |
| 69 | - #define nullptr NULL | |
| 70 | - | |
| 71 | - class recursive_mutex { | |
| 72 | - private: | |
| 73 | - pthread_mutex_t mtx; | |
| 74 | - pthread_mutexattr_t mtxAttr; | |
| 75 | - | |
| 76 | - public: | |
| 77 | - recursive_mutex() { | |
| 78 | - | |
| 79 | - memset(&mtx,0,sizeof(mtx)); | |
| 80 | - memset(&mtxAttr,0,sizeof(mtxAttr)); | |
| 81 | - | |
| 82 | - pthread_mutexattr_init(&mtxAttr); | |
| 83 | - pthread_mutexattr_settype(&mtxAttr, PTHREAD_MUTEX_RECURSIVE); | |
| 84 | - pthread_mutex_init(&mtx, &mtxAttr); | |
| 85 | - }; | |
| 86 | - | |
| 87 | - ~recursive_mutex() { | |
| 88 | - pthread_mutex_destroy(&mtx); | |
| 89 | - }; | |
| 90 | - | |
| 91 | - void lock(void) { | |
| 92 | - pthread_mutex_lock(&mtx); | |
| 93 | - }; | |
| 94 | - | |
| 95 | - void unlock(void) { | |
| 96 | - pthread_mutex_unlock(&mtx); | |
| 97 | - }; | |
| 98 | - | |
| 99 | - bool try_lock(void) { | |
| 100 | - return pthread_mutex_trylock(&mtx) == 0; | |
| 101 | - }; | |
| 102 | - }; | |
| 103 | - | |
| 104 | - #else | |
| 105 | - | |
| 106 | - #include <mutex> | |
| 107 | - | |
| 108 | - #endif // !c11 | |
| 109 | - | |
| 110 | - | |
| 111 | - | |
| 112 | - | |
| 113 | -#endif // PRIVATE_H_INCLUDED |
src/pw3270cpp/remote.cc
| ... | ... | @@ -1,1599 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como remote.cc e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | - #include <lib3270/config.h> | |
| 31 | - #include <iostream> | |
| 32 | - | |
| 33 | - #if defined(HAVE_DBUS) | |
| 34 | - #include <stdio.h> | |
| 35 | - #include <dbus/dbus.h> | |
| 36 | - #include <string.h> | |
| 37 | - #include <malloc.h> | |
| 38 | - #include <sys/types.h> | |
| 39 | - #include <unistd.h> | |
| 40 | - #include <limits.h> | |
| 41 | - | |
| 42 | - #ifndef DBUS_TIMEOUT_INFINITE | |
| 43 | - #define DBUS_TIMEOUT_INFINITE ((int) 0x7fffffff) | |
| 44 | - #endif // !DBUS_TIMEOUT_INFINITE | |
| 45 | - | |
| 46 | - #endif // HAVE_DBUS | |
| 47 | - | |
| 48 | - #if defined(WIN32) | |
| 49 | - #include <windows.h> | |
| 50 | - #include <pw3270/ipcpackets.h> | |
| 51 | - #include <process.h> | |
| 52 | - #else | |
| 53 | - #define HLLAPI_PACKET_IS_CONNECTED "isConnected" | |
| 54 | - #define HLLAPI_PACKET_GET_CSTATE "getConnectionState" | |
| 55 | - #define HLLAPI_PACKET_GET_PROGRAM_MESSAGE "getProgramMessage" | |
| 56 | - #define HLLAPI_PACKET_GET_SSL_STATE "getSecureState" | |
| 57 | - #define HLLAPI_PACKET_IS_READY "isReady" | |
| 58 | - #define HLLAPI_PACKET_DISCONNECT "disconnect" | |
| 59 | - #define HLLAPI_PACKET_GET_HOST "getURL" | |
| 60 | - #define HLLAPI_PACKET_SET_HOST "setURL" | |
| 61 | - #define HLLAPI_PACKET_GET_CURSOR "getCursorAddress" | |
| 62 | - #define HLLAPI_PACKET_GET_WIDTH "getScreenWidth" | |
| 63 | - #define HLLAPI_PACKET_GET_HEIGHT "getScreenHeight" | |
| 64 | - #define HLLAPI_PACKET_GET_LENGTH "getScreenLength" | |
| 65 | - #define HLLAPI_PACKET_ENTER "enter" | |
| 66 | - #define HLLAPI_PACKET_QUIT "quit" | |
| 67 | - #define HLLAPI_PACKET_ERASE "erase" | |
| 68 | - #define HLLAPI_PACKET_ERASE_EOF "eraseEOF" | |
| 69 | - #define HLLAPI_PACKET_ERASE_EOL "eraseEOL" | |
| 70 | - #define HLLAPI_PACKET_ERASE_INPUT "eraseInput" | |
| 71 | - #define HLLAPI_PACKET_PRINT "print" | |
| 72 | - #define HLLAPI_PACKET_ASC2EBC "asc2ebc" | |
| 73 | - #define HLLAPI_PACKET_EBC2ASC "ebc2asc" | |
| 74 | - #define HLLAPI_PACKET_SET_UNLOCK_DELAY "setUnlockDelay" | |
| 75 | - #endif // WIN32 | |
| 76 | - | |
| 77 | - #include <pw3270/class.h> | |
| 78 | - #include <lib3270/log.h> | |
| 79 | - | |
| 80 | -#if defined(HAVE_DBUS) | |
| 81 | - static const char * prefix_dest = "br.com.bb."; | |
| 82 | - static const char * prefix_path = "/br/com/bb/"; | |
| 83 | -#endif // HAVE_DBUS | |
| 84 | - | |
| 85 | -/*--[ Implement ]--------------------------------------------------------------------------------------------------*/ | |
| 86 | - | |
| 87 | - namespace PW3270_NAMESPACE | |
| 88 | - { | |
| 89 | - | |
| 90 | - class remote : public session | |
| 91 | - { | |
| 92 | - private: | |
| 93 | - | |
| 94 | -#if defined(WIN32) | |
| 95 | - | |
| 96 | - HANDLE hPipe; | |
| 97 | - | |
| 98 | - int query_intval(HLLAPI_PACKET id) | |
| 99 | - { | |
| 100 | - struct hllapi_packet_query query = { id }; | |
| 101 | - struct hllapi_packet_result response; | |
| 102 | - DWORD cbSize = sizeof(query); | |
| 103 | - if(TransactNamedPipe(hPipe,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL)) | |
| 104 | - return response.rc; | |
| 105 | - | |
| 106 | - throw exception(GetLastError(),"%s","Transaction error"); | |
| 107 | - } | |
| 108 | - | |
| 109 | - int query_strval(HLLAPI_PACKET id, unsigned char *buffer, size_t sz) | |
| 110 | - { | |
| 111 | - DWORD cbSize = sizeof(struct hllapi_packet_text)+sz; | |
| 112 | - struct hllapi_packet_text * query; | |
| 113 | - struct hllapi_packet_text * response; | |
| 114 | - int rc = -1; | |
| 115 | - | |
| 116 | - query = (struct hllapi_packet_text *) malloc(cbSize+2); | |
| 117 | - memset(query,0,cbSize+2); | |
| 118 | - query->packet_id = id; | |
| 119 | - memcpy(query->text,buffer,sz); | |
| 120 | - | |
| 121 | - response = (struct hllapi_packet_text *) malloc(cbSize+2); | |
| 122 | - memset(response,0,cbSize+2); | |
| 123 | - | |
| 124 | - if(TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, cbSize, &cbSize,NULL)) | |
| 125 | - { | |
| 126 | - if(response->packet_id) | |
| 127 | - { | |
| 128 | - rc = response->packet_id; | |
| 129 | - } | |
| 130 | - else | |
| 131 | - { | |
| 132 | - rc = 0; | |
| 133 | - strncpy((char *) buffer,response->text,sz); | |
| 134 | - } | |
| 135 | - } | |
| 136 | - | |
| 137 | - free(response); | |
| 138 | - free(query); | |
| 139 | - | |
| 140 | - return rc; | |
| 141 | - | |
| 142 | - } | |
| 143 | - | |
| 144 | - string query_string(void *query, size_t szQuery, size_t len) | |
| 145 | - { | |
| 146 | - struct hllapi_packet_text * response; | |
| 147 | - DWORD sz = sizeof(struct hllapi_packet_text)+len; | |
| 148 | - DWORD cbSize = (DWORD) sz; | |
| 149 | - string s; | |
| 150 | - char buffer[sz+2]; | |
| 151 | - | |
| 152 | - memset(buffer,0,sz+2); | |
| 153 | - | |
| 154 | - response = (struct hllapi_packet_text *) buffer; | |
| 155 | - | |
| 156 | - if(TransactNamedPipe(hPipe,(LPVOID) query, szQuery, response, sz, &cbSize,NULL)) | |
| 157 | - { | |
| 158 | - buffer[min(cbSize,sz)] = 0; | |
| 159 | - | |
| 160 | - trace("TransactNamedPipe call %d returns \"%s\"",(int) *( (unsigned char *) query), response->text); | |
| 161 | - | |
| 162 | - if(!response->packet_id) | |
| 163 | - s.assign(response->text); | |
| 164 | - } | |
| 165 | - else | |
| 166 | - { | |
| 167 | - trace("TransactNamedPipe error on call %d",(int) *( (unsigned char *) query)); | |
| 168 | - s.assign(""); | |
| 169 | - } | |
| 170 | - | |
| 171 | - return s; | |
| 172 | - } | |
| 173 | - | |
| 174 | - int query_intval(void *pkt, size_t szQuery, bool dynamic = false) | |
| 175 | - { | |
| 176 | - struct hllapi_packet_result response; | |
| 177 | - DWORD cbSize = (DWORD) szQuery; | |
| 178 | - BOOL status; | |
| 179 | - | |
| 180 | - status = TransactNamedPipe(hPipe,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL); | |
| 181 | - | |
| 182 | - if(dynamic) | |
| 183 | - free(pkt); | |
| 184 | - | |
| 185 | - if(status) | |
| 186 | - return response.rc; | |
| 187 | - | |
| 188 | - throw exception(GetLastError(),"%s","Transaction error"); | |
| 189 | - | |
| 190 | - } | |
| 191 | - | |
| 192 | - void set_intval(HLLAPI_PACKET id, int value) | |
| 193 | - { | |
| 194 | - struct hllapi_packet_set_int packet; | |
| 195 | - DWORD cbSize = (DWORD) sizeof(packet); | |
| 196 | - BOOL status; | |
| 197 | - | |
| 198 | - memset(&packet,0,sizeof(packet)); | |
| 199 | - packet.packet_id = id; | |
| 200 | - packet.value = value; | |
| 201 | - | |
| 202 | - status = TransactNamedPipe(hPipe,(LPVOID) &packet, cbSize, &packet, sizeof(packet), &cbSize,NULL); | |
| 203 | - | |
| 204 | - if(!status) | |
| 205 | - throw exception(GetLastError(),"%s","Transaction error"); | |
| 206 | - | |
| 207 | - } | |
| 208 | - | |
| 209 | - | |
| 210 | -#elif defined(HAVE_DBUS) | |
| 211 | - | |
| 212 | - DBusConnection * conn; | |
| 213 | - char * dest; | |
| 214 | - char * path; | |
| 215 | - char * intf; | |
| 216 | - int sequence; | |
| 217 | - | |
| 218 | - DBusMessage * create_message(const char *method) | |
| 219 | - { | |
| 220 | - DBusMessage * msg = dbus_message_new_method_call( this->dest, // Destination | |
| 221 | - this->path, // Path | |
| 222 | - this->intf, // Interface | |
| 223 | - method); // method | |
| 224 | - | |
| 225 | - if (!msg) | |
| 226 | - throw exception("Error creating DBUS message for method %s",method); | |
| 227 | - | |
| 228 | - return msg; | |
| 229 | - | |
| 230 | - } | |
| 231 | - | |
| 232 | - DBusMessage * call(DBusMessage *msg) | |
| 233 | - { | |
| 234 | - DBusMessage * reply; | |
| 235 | - DBusError error; | |
| 236 | - | |
| 237 | - dbus_error_init(&error); | |
| 238 | - reply = dbus_connection_send_with_reply_and_block(conn,msg,10000,&error); | |
| 239 | - dbus_message_unref(msg); | |
| 240 | - | |
| 241 | - if(!reply) | |
| 242 | - { | |
| 243 | - exception e = exception("%s",error.message); | |
| 244 | - dbus_error_free(&error); | |
| 245 | - throw e; | |
| 246 | - } | |
| 247 | - return reply; | |
| 248 | - } | |
| 249 | - | |
| 250 | - string get_string(DBusMessage * msg) | |
| 251 | - { | |
| 252 | - string rc; | |
| 253 | - | |
| 254 | - if(msg) | |
| 255 | - { | |
| 256 | - DBusMessageIter iter; | |
| 257 | - | |
| 258 | - if(dbus_message_iter_init(msg, &iter)) | |
| 259 | - { | |
| 260 | - if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) | |
| 261 | - { | |
| 262 | - const char * str; | |
| 263 | - dbus_message_iter_get_basic(&iter, &str); | |
| 264 | - trace("Response: [%s]",str); | |
| 265 | - rc.assign(str); | |
| 266 | - dbus_message_unref(msg); | |
| 267 | - return rc; | |
| 268 | - } | |
| 269 | - | |
| 270 | - exception e = exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | |
| 271 | - dbus_message_unref(msg); | |
| 272 | - | |
| 273 | - throw e; | |
| 274 | - | |
| 275 | - } | |
| 276 | - | |
| 277 | - } | |
| 278 | - | |
| 279 | - return rc; | |
| 280 | - } | |
| 281 | - | |
| 282 | - string query_string(const char *method) | |
| 283 | - { | |
| 284 | - return get_string(call(create_message(method))); | |
| 285 | - } | |
| 286 | - | |
| 287 | - int get_intval(DBusMessage * msg) | |
| 288 | - { | |
| 289 | - if(msg) | |
| 290 | - { | |
| 291 | - DBusMessageIter iter; | |
| 292 | - | |
| 293 | - if(dbus_message_iter_init(msg, &iter)) | |
| 294 | - { | |
| 295 | - if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32) | |
| 296 | - { | |
| 297 | - dbus_int32_t iSigned; | |
| 298 | - dbus_message_iter_get_basic(&iter, &iSigned); | |
| 299 | - dbus_message_unref(msg); | |
| 300 | - return (int) iSigned; | |
| 301 | - } | |
| 302 | - | |
| 303 | - exception e = exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | |
| 304 | - | |
| 305 | - dbus_message_unref(msg); | |
| 306 | - throw e; | |
| 307 | - return -1; | |
| 308 | - } | |
| 309 | - dbus_message_unref(msg); | |
| 310 | - } | |
| 311 | - return -1; | |
| 312 | - } | |
| 313 | - | |
| 314 | - int query_intval(const char *method) | |
| 315 | - { | |
| 316 | - return get_intval(call(create_message(method))); | |
| 317 | - } | |
| 318 | - | |
| 319 | - int query_intval(const char *method, int first_arg_type, ...) | |
| 320 | - { | |
| 321 | - va_list var_args; | |
| 322 | - DBusMessage * msg = dbus_message_new_method_call( this->dest, // Destination | |
| 323 | - this->path, // Path | |
| 324 | - this->intf, // Interface | |
| 325 | - method); // method | |
| 326 | - | |
| 327 | - if (!msg) | |
| 328 | - { | |
| 329 | - throw exception("Error creating DBUS message for method %s",method); | |
| 330 | - return -1; | |
| 331 | - } | |
| 332 | - | |
| 333 | - va_start(var_args, first_arg_type); | |
| 334 | - dbus_message_append_args_valist(msg,first_arg_type,var_args); | |
| 335 | - va_end(var_args); | |
| 336 | - | |
| 337 | - return get_intval(call(msg)); | |
| 338 | - } | |
| 339 | - | |
| 340 | - int query_strval(const char *method, unsigned char *buffer, size_t sz) | |
| 341 | - { | |
| 342 | - DBusMessage * outMsg = create_message(method); | |
| 343 | - | |
| 344 | - if(outMsg) | |
| 345 | - { | |
| 346 | - dbus_message_append_args(outMsg, DBUS_TYPE_STRING, &buffer, DBUS_TYPE_INVALID); | |
| 347 | - | |
| 348 | - DBusMessage * rspMsg = call(outMsg); | |
| 349 | - if(rspMsg) | |
| 350 | - { | |
| 351 | - DBusMessageIter iter; | |
| 352 | - | |
| 353 | - if(dbus_message_iter_init(rspMsg, &iter)) | |
| 354 | - { | |
| 355 | - if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) | |
| 356 | - { | |
| 357 | - const char * str; | |
| 358 | - dbus_message_iter_get_basic(&iter, &str); | |
| 359 | - trace("Response: [%s]",str); | |
| 360 | - strncpy((char *) buffer,str,sz); | |
| 361 | - dbus_message_unref(rspMsg); | |
| 362 | - return 0; | |
| 363 | - } | |
| 364 | - | |
| 365 | - exception e = exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); | |
| 366 | - dbus_message_unref(rspMsg); | |
| 367 | - | |
| 368 | - throw e; | |
| 369 | - | |
| 370 | - } | |
| 371 | - } | |
| 372 | - } | |
| 373 | - | |
| 374 | - return -1; | |
| 375 | - } | |
| 376 | - | |
| 377 | - void set_intval(const char *method, int value) | |
| 378 | - { | |
| 379 | - DBusMessage * outMsg = create_message(method); | |
| 380 | - | |
| 381 | - if(outMsg) | |
| 382 | - { | |
| 383 | - dbus_int32_t v = (dbus_int32_t) value; | |
| 384 | - | |
| 385 | - dbus_message_append_args(outMsg, DBUS_TYPE_INT32, &v, DBUS_TYPE_INVALID); | |
| 386 | - | |
| 387 | - DBusMessage * rspMsg = call(outMsg); | |
| 388 | - dbus_message_unref(rspMsg); | |
| 389 | - | |
| 390 | - } | |
| 391 | - } | |
| 392 | - | |
| 393 | -#else | |
| 394 | - | |
| 395 | - | |
| 396 | - int query_intval(const char *method) | |
| 397 | - { | |
| 398 | - throw exception("Call to unimplemented RPC method \"%s\"",method); | |
| 399 | - return -1; | |
| 400 | - } | |
| 401 | - | |
| 402 | - int query_strval(const char *method, unsigned char *buffer, size_t sz) | |
| 403 | - { | |
| 404 | - throw exception("Call to unimplemented RPC method \"%s\"",method); | |
| 405 | - return -1; | |
| 406 | - } | |
| 407 | - | |
| 408 | - | |
| 409 | -#endif | |
| 410 | - | |
| 411 | - public: | |
| 412 | - | |
| 413 | -#if defined(HAVE_DBUS) | |
| 414 | - const char * makeBusName(char *buffer, size_t sz) | |
| 415 | - { | |
| 416 | - size_t bytes = strlen(buffer); | |
| 417 | - char * ptr = buffer; | |
| 418 | - int val; | |
| 419 | - | |
| 420 | - sz -= 2; | |
| 421 | - | |
| 422 | - // First uses the object ID | |
| 423 | - val = this->sequence; | |
| 424 | - while(bytes < sz && val > 0) | |
| 425 | - { | |
| 426 | - *(ptr++) = 'a'+(val % 25); | |
| 427 | - val /= 25; | |
| 428 | - bytes++; | |
| 429 | - } | |
| 430 | - *(ptr++) = '.'; | |
| 431 | - | |
| 432 | - // Then the PID | |
| 433 | - val = (int) getpid(); | |
| 434 | - while(bytes < sz && val > 0) | |
| 435 | - { | |
| 436 | - *(ptr++) = 'a'+(val % 25); | |
| 437 | - val /= 25; | |
| 438 | - bytes++; | |
| 439 | - } | |
| 440 | - *(ptr++) = '.'; | |
| 441 | - | |
| 442 | - // And last, the project info | |
| 443 | - strncpy(ptr,intf,sz); | |
| 444 | - | |
| 445 | - trace("Busname=\"%s\" sequence=%d this=%p",buffer,sequence,this); | |
| 446 | - | |
| 447 | - return buffer; | |
| 448 | - | |
| 449 | - } | |
| 450 | -#endif // HAVE_DBUS | |
| 451 | - | |
| 452 | -#if defined(WIN32) | |
| 453 | - | |
| 454 | - static string getRegistryKey(const char *name) throw (std::exception) | |
| 455 | - { | |
| 456 | - char buffer[4096]; | |
| 457 | - HKEY hKey = 0; | |
| 458 | - unsigned long datalen = sizeof(buffer); | |
| 459 | - | |
| 460 | - debug("%s(%s)",__FUNCTION__,name); | |
| 461 | - | |
| 462 | - *buffer = 0; | |
| 463 | - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) != ERROR_SUCCESS) | |
| 464 | - { | |
| 465 | - throw exception("Can't open key %s","HKLM\\Software\\pw3270"); | |
| 466 | - } | |
| 467 | - else | |
| 468 | - { | |
| 469 | - unsigned long datatype; // #defined in winnt.h (predefined types 0-11) | |
| 470 | - | |
| 471 | - if(RegQueryValueExA(hKey,name,NULL,&datatype,(LPBYTE) buffer,&datalen) != ERROR_SUCCESS) | |
| 472 | - *buffer = 0; | |
| 473 | - RegCloseKey(hKey); | |
| 474 | - } | |
| 475 | - | |
| 476 | - return string(buffer); | |
| 477 | - | |
| 478 | - } | |
| 479 | - | |
| 480 | -#endif // defined | |
| 481 | - | |
| 482 | - remote(const char *session) throw (std::exception) | |
| 483 | - { | |
| 484 | -#if defined(WIN32) | |
| 485 | - static DWORD dwMode = PIPE_READMODE_MESSAGE; | |
| 486 | - char buffer[4096]; | |
| 487 | - char * str; | |
| 488 | - char * ptr; | |
| 489 | - time_t timer = time(0)+1; | |
| 490 | - | |
| 491 | - hPipe = INVALID_HANDLE_VALUE; | |
| 492 | - | |
| 493 | - trace("%s(%s)",__FUNCTION__,session); | |
| 494 | - | |
| 495 | - if(strcasecmp(session,"start") == 0 || strcasecmp(session,"new") == 0) | |
| 496 | - { | |
| 497 | - // Start a new session | |
| 498 | - string appName = getRegistryKey("appName"); | |
| 499 | - char buffer[80]; | |
| 500 | - STARTUPINFO si; | |
| 501 | - PROCESS_INFORMATION pi; | |
| 502 | - | |
| 503 | - // Get application path | |
| 504 | - | |
| 505 | - if(!appName.size()) | |
| 506 | - { | |
| 507 | - throw exception("key %s\\appName is invalid","HKLM\\Software\\pw3270"); | |
| 508 | - return; | |
| 509 | - } | |
| 510 | - | |
| 511 | - trace("%s appname=%s\n",__FUNCTION__,appName.c_str()); | |
| 512 | - | |
| 513 | - snprintf(buffer,79,"%s --session=\"H%06d\"",appName.c_str(),getpid()); | |
| 514 | - | |
| 515 | - ZeroMemory( &si, sizeof(si) ); | |
| 516 | - si.cb = sizeof(si); | |
| 517 | - ZeroMemory( &pi, sizeof(pi) ); | |
| 518 | - | |
| 519 | - // si.dwFlags = STARTF_PREVENTPINNING; | |
| 520 | - trace("App: %s",appName.c_str()); | |
| 521 | - trace("CmdLine: %s",buffer); | |
| 522 | - | |
| 523 | - if(CreateProcess(NULL,buffer,NULL,NULL,0,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi)) | |
| 524 | - { | |
| 525 | - CloseHandle( pi.hProcess ); | |
| 526 | - CloseHandle( pi.hThread ); | |
| 527 | - } | |
| 528 | - else | |
| 529 | - { | |
| 530 | - throw exception("Can't start %s",appName.c_str()); | |
| 531 | - return; | |
| 532 | - } | |
| 533 | - | |
| 534 | - snprintf(buffer,4095,"H%06d_a",getpid()); | |
| 535 | - str = strdup(buffer); | |
| 536 | - | |
| 537 | - // Até 20 segundos para o processo iniciar. | |
| 538 | - timer = time(0)+20; | |
| 539 | - | |
| 540 | - } | |
| 541 | - else | |
| 542 | - { | |
| 543 | - // Use an existing session | |
| 544 | - str = strdup(session); | |
| 545 | - | |
| 546 | - // Convert session name | |
| 547 | - for(ptr=str;*ptr;ptr++) | |
| 548 | - { | |
| 549 | - if(*ptr == ':') | |
| 550 | - *ptr = '_'; | |
| 551 | - else | |
| 552 | - *ptr = tolower(*ptr); | |
| 553 | - } | |
| 554 | - | |
| 555 | - // Wait? | |
| 556 | - int delay; | |
| 557 | - | |
| 558 | - try | |
| 559 | - { | |
| 560 | - delay = atoi(getRegistryKey("hllapiWait").c_str()); | |
| 561 | - } | |
| 562 | - catch(std::exception &e) | |
| 563 | - { | |
| 564 | - delay = 0; | |
| 565 | - } | |
| 566 | - | |
| 567 | - if(delay) { | |
| 568 | - timer = time(0) + delay; | |
| 569 | - } | |
| 570 | - | |
| 571 | - | |
| 572 | - } | |
| 573 | - | |
| 574 | - snprintf(buffer,4095,"\\\\.\\pipe\\%s",str); | |
| 575 | - | |
| 576 | - free(str); | |
| 577 | - | |
| 578 | - trace("Searching for \"%s\"",buffer); | |
| 579 | - | |
| 580 | - hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); | |
| 581 | - | |
| 582 | - if(hPipe == INVALID_HANDLE_VALUE) | |
| 583 | - { | |
| 584 | - // Cant get session, wait. | |
| 585 | - while(hPipe == INVALID_HANDLE_VALUE && time(0) < timer) | |
| 586 | - { | |
| 587 | - hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); | |
| 588 | - Sleep(1); | |
| 589 | - } | |
| 590 | - } | |
| 591 | - | |
| 592 | - if(hPipe == INVALID_HANDLE_VALUE) | |
| 593 | - { | |
| 594 | - throw exception("Can´t create service pipe %s",buffer); | |
| 595 | - } | |
| 596 | - else if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) | |
| 597 | - { | |
| 598 | - exception e = exception(GetLastError(),"%s","Can´t set pipe state"); | |
| 599 | - CloseHandle(hPipe); | |
| 600 | - hPipe = INVALID_HANDLE_VALUE; | |
| 601 | - throw e; | |
| 602 | - } | |
| 603 | - | |
| 604 | -#elif defined(HAVE_DBUS) | |
| 605 | - | |
| 606 | - static int sq = 0; | |
| 607 | - DBusError err; | |
| 608 | - int rc; | |
| 609 | - char * str = strdup(session); | |
| 610 | - char * ptr; | |
| 611 | - char busname[4096]; | |
| 612 | - | |
| 613 | - this->sequence = (++sq) + time(0); | |
| 614 | - | |
| 615 | - trace("%s str=%p sequence=%d",__FUNCTION__,str,sequence); | |
| 616 | - | |
| 617 | - for(ptr=str;*ptr;ptr++) | |
| 618 | - *ptr = tolower(*ptr); | |
| 619 | - | |
| 620 | - ptr = strchr(str,':'); | |
| 621 | - | |
| 622 | - if(ptr) | |
| 623 | - { | |
| 624 | - size_t sz; | |
| 625 | - | |
| 626 | - *(ptr++) = 0; | |
| 627 | - | |
| 628 | - // Build destination | |
| 629 | - sz = strlen(ptr)+strlen(str)+strlen(prefix_dest)+2; | |
| 630 | - dest = (char *) malloc(sz+1); | |
| 631 | - strncpy(dest,prefix_dest,sz); | |
| 632 | - strncat(dest,str,sz); | |
| 633 | - strncat(dest,".",sz); | |
| 634 | - strncat(dest,ptr,sz); | |
| 635 | - | |
| 636 | - // Build path | |
| 637 | - sz = strlen(str)+strlen(prefix_path); | |
| 638 | - path = (char *) malloc(sz+1); | |
| 639 | - strncpy(path,prefix_path,sz); | |
| 640 | - strncat(path,str,sz); | |
| 641 | - | |
| 642 | - // Build intf | |
| 643 | - sz = strlen(str)+strlen(prefix_dest)+1; | |
| 644 | - intf = (char *) malloc(sz+1); | |
| 645 | - strncpy(intf,prefix_dest,sz); | |
| 646 | - strncat(intf,str,sz); | |
| 647 | - | |
| 648 | - } | |
| 649 | - else | |
| 650 | - { | |
| 651 | - size_t sz; | |
| 652 | - | |
| 653 | - // Build destination | |
| 654 | - sz = strlen(str)+strlen(prefix_dest)+2; | |
| 655 | - dest = (char *) malloc(sz+1); | |
| 656 | - strncpy(dest,prefix_dest,sz); | |
| 657 | - strncat(dest,str,sz); | |
| 658 | - | |
| 659 | - // Build path | |
| 660 | - sz = strlen(str)+strlen(prefix_path); | |
| 661 | - path = (char *) malloc(sz+1); | |
| 662 | - strncpy(path,prefix_path,sz); | |
| 663 | - strncat(path,str,sz); | |
| 664 | - | |
| 665 | - // Build intf | |
| 666 | - sz = strlen(str)+strlen(prefix_dest)+1; | |
| 667 | - intf = (char *) malloc(sz+1); | |
| 668 | - strncpy(intf,prefix_dest,sz); | |
| 669 | - strncat(intf,str,sz); | |
| 670 | - | |
| 671 | - } | |
| 672 | - | |
| 673 | - trace("DBUS:\nDestination:\t[%s]\nPath:\t\t[%s]\nInterface:\t[%s]",dest,path,intf); | |
| 674 | - | |
| 675 | - free(str); | |
| 676 | - | |
| 677 | - dbus_error_init(&err); | |
| 678 | - | |
| 679 | - conn = dbus_bus_get(DBUS_BUS_SESSION, &err); | |
| 680 | - trace("dbus_bus_get conn=%p",conn); | |
| 681 | - | |
| 682 | - if (dbus_error_is_set(&err)) | |
| 683 | - { | |
| 684 | - exception e = exception("DBUS Connection Error (%s)", err.message); | |
| 685 | - dbus_error_free(&err); | |
| 686 | - throw e; | |
| 687 | - return; | |
| 688 | - } | |
| 689 | - | |
| 690 | - if(!conn) | |
| 691 | - { | |
| 692 | - throw exception("%s", "DBUS Connection failed"); | |
| 693 | - return; | |
| 694 | - } | |
| 695 | - | |
| 696 | - | |
| 697 | - rc = dbus_bus_request_name(conn, makeBusName(busname,4095), DBUS_NAME_FLAG_REPLACE_EXISTING , &err); | |
| 698 | - trace("dbus_bus_request_name(%s) rc=%d",busname,rc); | |
| 699 | - | |
| 700 | - if (dbus_error_is_set(&err)) | |
| 701 | - { | |
| 702 | - exception e = exception("Name Error (%s)", err.message); | |
| 703 | - dbus_error_free(&err); | |
| 704 | - throw e; | |
| 705 | - return; | |
| 706 | - } | |
| 707 | - | |
| 708 | - if(rc != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) | |
| 709 | - { | |
| 710 | - trace("%s: DBUS request for name %s failed",__FUNCTION__, busname); | |
| 711 | - throw exception("DBUS request for \"%s\" failed",session); | |
| 712 | - return; | |
| 713 | - } | |
| 714 | - | |
| 715 | - trace("%s: Using DBUS name %s",__FUNCTION__,busname); | |
| 716 | - | |
| 717 | - const char * id = "r"; | |
| 718 | - static const dbus_int32_t flag = 1; | |
| 719 | - query_intval("setScript", DBUS_TYPE_STRING, &id, DBUS_TYPE_INT32, &flag, DBUS_TYPE_INVALID); | |
| 720 | - | |
| 721 | - | |
| 722 | -#else | |
| 723 | - | |
| 724 | - throw exception("%s","RPC support is incomplete."); | |
| 725 | - | |
| 726 | -#endif | |
| 727 | - } | |
| 728 | - | |
| 729 | - virtual ~remote() | |
| 730 | - { | |
| 731 | -#if defined(WIN32) | |
| 732 | - | |
| 733 | - if(hPipe != INVALID_HANDLE_VALUE) | |
| 734 | - CloseHandle(hPipe); | |
| 735 | - | |
| 736 | -#elif defined(HAVE_DBUS) | |
| 737 | - | |
| 738 | - try | |
| 739 | - { | |
| 740 | - const char * id = "r"; | |
| 741 | - static const dbus_int32_t flag = 0; | |
| 742 | - query_intval("setScript", DBUS_TYPE_STRING, &id, DBUS_TYPE_INT32, &flag, DBUS_TYPE_INVALID); | |
| 743 | - } | |
| 744 | - catch(exception e) | |
| 745 | - { | |
| 746 | - std::cerr << e.what(); | |
| 747 | - } | |
| 748 | - | |
| 749 | - char busname[4096]; | |
| 750 | - makeBusName(busname,4096); | |
| 751 | - | |
| 752 | - free(dest); | |
| 753 | - free(path); | |
| 754 | - free(intf); | |
| 755 | - | |
| 756 | - DBusError err; | |
| 757 | - | |
| 758 | - dbus_error_init(&err); | |
| 759 | - dbus_bus_release_name(conn,busname,&err); | |
| 760 | - | |
| 761 | - if (dbus_error_is_set(&err)) | |
| 762 | - { | |
| 763 | - //exception e = exception("Error when releasing DBUS name (%s)", err.message); | |
| 764 | - std::cerr << err.message; | |
| 765 | - dbus_error_free(&err); | |
| 766 | - //throw e; | |
| 767 | - } | |
| 768 | - | |
| 769 | -#else | |
| 770 | - | |
| 771 | -#endif | |
| 772 | - } | |
| 773 | - | |
| 774 | - bool is_connected(void) | |
| 775 | - { | |
| 776 | - return query_intval(HLLAPI_PACKET_IS_CONNECTED) != 0; | |
| 777 | - } | |
| 778 | - | |
| 779 | - LIB3270_CSTATE get_cstate(void) | |
| 780 | - { | |
| 781 | - return (LIB3270_CSTATE) query_intval(HLLAPI_PACKET_GET_CSTATE); | |
| 782 | - } | |
| 783 | - | |
| 784 | - LIB3270_MESSAGE get_program_message(void) { | |
| 785 | - return (LIB3270_MESSAGE) query_intval(HLLAPI_PACKET_GET_PROGRAM_MESSAGE); | |
| 786 | - } | |
| 787 | - | |
| 788 | - LIB3270_SSL_STATE get_secure(void) { | |
| 789 | - return (LIB3270_SSL_STATE) query_intval(HLLAPI_PACKET_GET_SSL_STATE); | |
| 790 | - } | |
| 791 | - | |
| 792 | - | |
| 793 | - int connect(void) | |
| 794 | - { | |
| 795 | - int rc; | |
| 796 | - | |
| 797 | -#if defined(WIN32) | |
| 798 | - | |
| 799 | - size_t cbSize = sizeof(struct hllapi_packet_connect); | |
| 800 | - struct hllapi_packet_connect * pkt = (struct hllapi_packet_connect *) malloc(cbSize); | |
| 801 | - | |
| 802 | - memset(pkt,0,cbSize); | |
| 803 | - | |
| 804 | - pkt->packet_id = HLLAPI_PACKET_CONNECT; | |
| 805 | - pkt->wait = 0; | |
| 806 | - | |
| 807 | - rc = query_intval((void *) pkt,cbSize,true); | |
| 808 | - | |
| 809 | -#elif defined(HAVE_DBUS) | |
| 810 | - | |
| 811 | - static const char * str = ""; | |
| 812 | - | |
| 813 | - rc = query_intval("connect", DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); | |
| 814 | - | |
| 815 | -#else | |
| 816 | - rc = -1; | |
| 817 | - | |
| 818 | -#endif | |
| 819 | - return rc; | |
| 820 | - | |
| 821 | - } | |
| 822 | - | |
| 823 | - int set_url(const char *uri) | |
| 824 | - { | |
| 825 | - int rc; | |
| 826 | - | |
| 827 | -#if defined(WIN32) | |
| 828 | - | |
| 829 | - size_t cbSize = sizeof(struct hllapi_packet_text)+strlen(uri); | |
| 830 | - struct hllapi_packet_text * pkt = (struct hllapi_packet_text *) malloc(cbSize); | |
| 831 | - | |
| 832 | - pkt->packet_id = HLLAPI_PACKET_SET_HOST; | |
| 833 | - strcpy(pkt->text,uri); | |
| 834 | - | |
| 835 | - rc = query_intval((void *) pkt,cbSize,true); | |
| 836 | - | |
| 837 | -#elif defined(HAVE_DBUS) | |
| 838 | - | |
| 839 | - rc = query_intval(HLLAPI_PACKET_SET_HOST, DBUS_TYPE_STRING, &uri, DBUS_TYPE_INVALID); | |
| 840 | - | |
| 841 | -#else | |
| 842 | - | |
| 843 | - rc = -1; | |
| 844 | - | |
| 845 | -#endif | |
| 846 | - | |
| 847 | - return rc; | |
| 848 | - | |
| 849 | - } | |
| 850 | - | |
| 851 | - string get_url() | |
| 852 | - { | |
| 853 | -#if defined(WIN32) | |
| 854 | - | |
| 855 | - struct hllapi_packet_query query = { HLLAPI_PACKET_GET_HOST }; | |
| 856 | - return query_string(&query,sizeof(query),1024); | |
| 857 | - | |
| 858 | -#elif defined(HAVE_DBUS) | |
| 859 | - | |
| 860 | - return query_string(HLLAPI_PACKET_GET_HOST); | |
| 861 | - | |
| 862 | -#else | |
| 863 | - return string(); | |
| 864 | -#endif | |
| 865 | - } | |
| 866 | - | |
| 867 | - int wait_for_ready(int seconds) | |
| 868 | - { | |
| 869 | -#if defined(WIN32) | |
| 870 | - | |
| 871 | - time_t end = time(0)+seconds; | |
| 872 | - | |
| 873 | - while(time(0) < end) | |
| 874 | - { | |
| 875 | - if(!is_connected()) | |
| 876 | - return ENOTCONN; | |
| 877 | - | |
| 878 | - if(is_ready()) | |
| 879 | - return 0; | |
| 880 | - | |
| 881 | - Sleep(250); | |
| 882 | - } | |
| 883 | - | |
| 884 | - return ETIMEDOUT; | |
| 885 | - | |
| 886 | -#elif defined(HAVE_DBUS) | |
| 887 | - | |
| 888 | - time_t end = time(0)+seconds; | |
| 889 | - | |
| 890 | - while(time(0) < end) | |
| 891 | - { | |
| 892 | - static const dbus_int32_t delay = 2; | |
| 893 | - | |
| 894 | - int rc = query_intval("waitForReady", DBUS_TYPE_INT32, &delay, DBUS_TYPE_INVALID); | |
| 895 | - | |
| 896 | - trace("waitForReady exits with rc=%d",rc); | |
| 897 | - | |
| 898 | - if(rc != ETIMEDOUT) | |
| 899 | - return rc; | |
| 900 | - } | |
| 901 | - | |
| 902 | - return ETIMEDOUT; | |
| 903 | - | |
| 904 | -#else | |
| 905 | - | |
| 906 | - return -1; | |
| 907 | - | |
| 908 | -#endif | |
| 909 | - | |
| 910 | - } | |
| 911 | - | |
| 912 | - bool is_ready(void) | |
| 913 | - { | |
| 914 | - return query_intval(HLLAPI_PACKET_IS_READY) != 0; | |
| 915 | - } | |
| 916 | - | |
| 917 | - | |
| 918 | - int disconnect(void) | |
| 919 | - { | |
| 920 | - return query_intval(HLLAPI_PACKET_DISCONNECT); | |
| 921 | - } | |
| 922 | - | |
| 923 | - | |
| 924 | - int wait(int seconds) | |
| 925 | - { | |
| 926 | -#if defined(WIN32) | |
| 927 | - | |
| 928 | - time_t end = time(0)+seconds; | |
| 929 | - | |
| 930 | - while(time(0) < end) | |
| 931 | - { | |
| 932 | - if(!is_connected()) | |
| 933 | - return ENOTCONN; | |
| 934 | - Sleep(500); | |
| 935 | - } | |
| 936 | - | |
| 937 | - return 0; | |
| 938 | - | |
| 939 | -#elif defined(HAVE_DBUS) | |
| 940 | - | |
| 941 | - time_t end = time(0)+seconds; | |
| 942 | - | |
| 943 | - while(time(0) < end) | |
| 944 | - { | |
| 945 | - if(!is_connected()) | |
| 946 | - return ENOTCONN; | |
| 947 | - usleep(500); | |
| 948 | - } | |
| 949 | - | |
| 950 | - return 0; | |
| 951 | - | |
| 952 | -#else | |
| 953 | - | |
| 954 | - return -1; | |
| 955 | - | |
| 956 | -#endif | |
| 957 | - | |
| 958 | - } | |
| 959 | - | |
| 960 | - int iterate(bool wait) | |
| 961 | - { | |
| 962 | -#if defined(WIN32) | |
| 963 | - if(wait) | |
| 964 | - Sleep(250); | |
| 965 | - return 0; | |
| 966 | -#elif defined(HAVE_DBUS) | |
| 967 | - if(wait) | |
| 968 | - usleep(250); | |
| 969 | - return 0; | |
| 970 | -#else | |
| 971 | - return -1; | |
| 972 | -#endif | |
| 973 | - } | |
| 974 | - | |
| 975 | - string get_text_at(int row, int col, size_t sz) | |
| 976 | - { | |
| 977 | -#if defined(WIN32) | |
| 978 | - | |
| 979 | - struct hllapi_packet_query_at query = { HLLAPI_PACKET_GET_TEXT_AT, (unsigned short) row, (unsigned short) col, (unsigned short) sz }; | |
| 980 | - | |
| 981 | - return query_string(&query,sizeof(query),sz); | |
| 982 | - | |
| 983 | -#elif defined(HAVE_DBUS) | |
| 984 | - | |
| 985 | - dbus_int32_t r = (dbus_int32_t) row; | |
| 986 | - dbus_int32_t c = (dbus_int32_t) col; | |
| 987 | - dbus_int32_t l = (dbus_int32_t) sz; | |
| 988 | - | |
| 989 | - DBusMessage * msg = create_message("getTextAt"); | |
| 990 | - if(!msg) | |
| 991 | - return NULL; | |
| 992 | - | |
| 993 | - trace("%s(%d,%d,%d)",__FUNCTION__,r,c,l); | |
| 994 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INT32, &l, DBUS_TYPE_INVALID); | |
| 995 | - | |
| 996 | - return get_string(call(msg)); | |
| 997 | - | |
| 998 | -#else | |
| 999 | - | |
| 1000 | - return string(); | |
| 1001 | - | |
| 1002 | -#endif | |
| 1003 | - | |
| 1004 | - } | |
| 1005 | - | |
| 1006 | - int set_text_at(int row, int col, const char *str) | |
| 1007 | - { | |
| 1008 | -#if defined(WIN32) | |
| 1009 | - | |
| 1010 | - struct hllapi_packet_text_at * query; | |
| 1011 | - struct hllapi_packet_result response; | |
| 1012 | - DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen((const char *) str); | |
| 1013 | - | |
| 1014 | - query = (struct hllapi_packet_text_at *) malloc(cbSize); | |
| 1015 | - query->packet_id = HLLAPI_PACKET_SET_TEXT_AT; | |
| 1016 | - query->row = row; | |
| 1017 | - query->col = col; | |
| 1018 | - strcpy(query->text,(const char *) str); | |
| 1019 | - | |
| 1020 | - TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); | |
| 1021 | - | |
| 1022 | - free(query); | |
| 1023 | - | |
| 1024 | - return response.rc; | |
| 1025 | - | |
| 1026 | -#elif defined(HAVE_DBUS) | |
| 1027 | - | |
| 1028 | - dbus_int32_t r = (dbus_int32_t) row; | |
| 1029 | - dbus_int32_t c = (dbus_int32_t) col; | |
| 1030 | - | |
| 1031 | - return query_intval("setTextAt", DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); | |
| 1032 | - | |
| 1033 | -#else | |
| 1034 | - | |
| 1035 | - return -1; | |
| 1036 | - | |
| 1037 | -#endif | |
| 1038 | - | |
| 1039 | - } | |
| 1040 | - | |
| 1041 | - int cmp_text_at(int row, int col, const char *text) | |
| 1042 | - { | |
| 1043 | - debug("%s(%d,%d,\"%s\")",__FUNCTION__,row,col,text); | |
| 1044 | - | |
| 1045 | -#if defined(WIN32) | |
| 1046 | - | |
| 1047 | - struct hllapi_packet_text_at * query; | |
| 1048 | - size_t cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text); | |
| 1049 | - | |
| 1050 | - query = (struct hllapi_packet_text_at *) malloc(cbSize); | |
| 1051 | - query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT; | |
| 1052 | - query->row = row; | |
| 1053 | - query->col = col; | |
| 1054 | - strcpy(query->text,text); | |
| 1055 | - | |
| 1056 | - return query_intval((void *) query, cbSize, true); | |
| 1057 | - | |
| 1058 | -#elif defined(HAVE_DBUS) | |
| 1059 | - | |
| 1060 | - dbus_int32_t r = (dbus_int32_t) row; | |
| 1061 | - dbus_int32_t c = (dbus_int32_t) col; | |
| 1062 | - | |
| 1063 | - return query_intval("cmpTextAt", DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID); | |
| 1064 | - | |
| 1065 | -#endif | |
| 1066 | - | |
| 1067 | - return 0; | |
| 1068 | - } | |
| 1069 | - | |
| 1070 | - int wait_for_text_at(int row, int col, const char *key, int timeout) | |
| 1071 | - { | |
| 1072 | - time_t end = time(0)+timeout; | |
| 1073 | - | |
| 1074 | - while(time(0) < end) | |
| 1075 | - { | |
| 1076 | - if(!is_connected()) | |
| 1077 | - return ENOTCONN; | |
| 1078 | - | |
| 1079 | - if(!cmp_text_at(row,col,key)) | |
| 1080 | - return 0; | |
| 1081 | - | |
| 1082 | -#ifdef WIN32 | |
| 1083 | - Sleep(500); | |
| 1084 | -#else | |
| 1085 | - usleep(500); | |
| 1086 | -#endif | |
| 1087 | - } | |
| 1088 | - | |
| 1089 | - return ETIMEDOUT; | |
| 1090 | - } | |
| 1091 | - | |
| 1092 | - string get_text(int baddr, size_t len) | |
| 1093 | - { | |
| 1094 | -#if defined(WIN32) | |
| 1095 | - struct hllapi_packet_query_offset query = { HLLAPI_PACKET_GET_TEXT_AT_OFFSET, (unsigned short) baddr, (unsigned short) len }; | |
| 1096 | - return query_string(&query,sizeof(query),len); | |
| 1097 | - | |
| 1098 | -#elif defined(HAVE_DBUS) | |
| 1099 | - | |
| 1100 | - dbus_int32_t b = (dbus_int32_t) baddr; | |
| 1101 | - dbus_int32_t l = (dbus_int32_t) len; | |
| 1102 | - | |
| 1103 | - DBusMessage * msg = create_message("getText"); | |
| 1104 | - if(!msg) | |
| 1105 | - return NULL; | |
| 1106 | - | |
| 1107 | - trace("%s(%d,%d)",__FUNCTION__,b,l); | |
| 1108 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &b, DBUS_TYPE_INT32, &l, DBUS_TYPE_INVALID); | |
| 1109 | - | |
| 1110 | - return get_string(call(msg)); | |
| 1111 | -#else | |
| 1112 | - throw exception("%s","IPC support is unavailable"); | |
| 1113 | - return string(); | |
| 1114 | -#endif | |
| 1115 | - } | |
| 1116 | - | |
| 1117 | - | |
| 1118 | - int set_cursor_position(int row, int col) | |
| 1119 | - { | |
| 1120 | -#if defined(WIN32) | |
| 1121 | - | |
| 1122 | - struct hllapi_packet_cursor query = { HLLAPI_PACKET_SET_CURSOR_POSITION, (unsigned short) row, (unsigned short) col }; | |
| 1123 | - | |
| 1124 | - return query_intval((void *) &query, sizeof(query)); | |
| 1125 | - | |
| 1126 | -#elif defined(HAVE_DBUS) | |
| 1127 | - | |
| 1128 | - dbus_int32_t r = (dbus_int32_t) row; | |
| 1129 | - dbus_int32_t c = (dbus_int32_t) col; | |
| 1130 | - | |
| 1131 | - return query_intval("setCursorAt", DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INVALID); | |
| 1132 | - | |
| 1133 | -#endif | |
| 1134 | - | |
| 1135 | - return -1; | |
| 1136 | - } | |
| 1137 | - | |
| 1138 | - int set_cursor_addr(int addr) | |
| 1139 | - { | |
| 1140 | -#if defined(WIN32) | |
| 1141 | - | |
| 1142 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, (unsigned short) addr }; | |
| 1143 | - | |
| 1144 | - return query_intval((void *) &query, sizeof(query)); | |
| 1145 | - | |
| 1146 | -#elif defined(HAVE_DBUS) | |
| 1147 | - | |
| 1148 | - dbus_int32_t k = (dbus_int32_t) addr; | |
| 1149 | - | |
| 1150 | - return query_intval("setCursorAddress", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1151 | - | |
| 1152 | -#endif | |
| 1153 | - | |
| 1154 | - return -1; | |
| 1155 | - } | |
| 1156 | - | |
| 1157 | - int get_cursor_addr(void) | |
| 1158 | - { | |
| 1159 | - return query_intval(HLLAPI_PACKET_GET_CURSOR); | |
| 1160 | - } | |
| 1161 | - | |
| 1162 | - int get_width(void) { | |
| 1163 | - return query_intval(HLLAPI_PACKET_GET_WIDTH); | |
| 1164 | - } | |
| 1165 | - | |
| 1166 | - int get_height(void) { | |
| 1167 | - return query_intval(HLLAPI_PACKET_GET_HEIGHT); | |
| 1168 | - } | |
| 1169 | - | |
| 1170 | - int get_length(void) { | |
| 1171 | - return query_intval(HLLAPI_PACKET_GET_LENGTH); | |
| 1172 | - } | |
| 1173 | - | |
| 1174 | - int enter(void) | |
| 1175 | - { | |
| 1176 | - return query_intval(HLLAPI_PACKET_ENTER); | |
| 1177 | - } | |
| 1178 | - | |
| 1179 | - int pfkey(int key) | |
| 1180 | - { | |
| 1181 | -#if defined(WIN32) | |
| 1182 | - | |
| 1183 | - struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, (unsigned short) key }; | |
| 1184 | - | |
| 1185 | - return query_intval((void *) &query, sizeof(query)); | |
| 1186 | - | |
| 1187 | -#elif defined(HAVE_DBUS) | |
| 1188 | - | |
| 1189 | - dbus_int32_t k = (dbus_int32_t) key; | |
| 1190 | - | |
| 1191 | - return query_intval("pfKey", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1192 | - | |
| 1193 | -#else | |
| 1194 | - | |
| 1195 | - return -1; | |
| 1196 | - | |
| 1197 | -#endif | |
| 1198 | - | |
| 1199 | - } | |
| 1200 | - | |
| 1201 | - int pakey(int key) | |
| 1202 | - { | |
| 1203 | -#if defined(WIN32) | |
| 1204 | - | |
| 1205 | - struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, (unsigned short) key }; | |
| 1206 | - | |
| 1207 | - return query_intval((void *) &query, sizeof(query)); | |
| 1208 | - | |
| 1209 | -#elif defined(HAVE_DBUS) | |
| 1210 | - | |
| 1211 | - dbus_int32_t k = (dbus_int32_t) key; | |
| 1212 | - | |
| 1213 | - return query_intval("paKey", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1214 | - | |
| 1215 | -#else | |
| 1216 | - | |
| 1217 | - return -1; | |
| 1218 | - | |
| 1219 | -#endif | |
| 1220 | - | |
| 1221 | - } | |
| 1222 | - | |
| 1223 | - int quit(void) | |
| 1224 | - { | |
| 1225 | - return query_intval(HLLAPI_PACKET_QUIT); | |
| 1226 | - } | |
| 1227 | - | |
| 1228 | - int set_toggle(LIB3270_TOGGLE ix, bool value) | |
| 1229 | - { | |
| 1230 | -#if defined(WIN32) | |
| 1231 | - | |
| 1232 | - struct hllapi_packet_set query = { HLLAPI_PACKET_SET_TOGGLE, (unsigned short) ix, (unsigned short) value }; | |
| 1233 | - | |
| 1234 | - return query_intval((void *) &query, sizeof(query)); | |
| 1235 | - | |
| 1236 | -#elif defined(HAVE_DBUS) | |
| 1237 | - | |
| 1238 | - dbus_int32_t i = (dbus_int32_t) ix; | |
| 1239 | - dbus_int32_t v = (dbus_int32_t) value; | |
| 1240 | - | |
| 1241 | - return query_intval("setToggle", DBUS_TYPE_INT32, &i, DBUS_TYPE_INT32, &v, DBUS_TYPE_INVALID); | |
| 1242 | - | |
| 1243 | -#else | |
| 1244 | - return -1; | |
| 1245 | - | |
| 1246 | -#endif | |
| 1247 | - | |
| 1248 | - } | |
| 1249 | - | |
| 1250 | - int emulate_input(const char *str) | |
| 1251 | - { | |
| 1252 | -#if defined(WIN32) | |
| 1253 | - | |
| 1254 | - size_t len = strlen(str); | |
| 1255 | - struct hllapi_packet_emulate_input * query; | |
| 1256 | - size_t cbSize = sizeof(struct hllapi_packet_emulate_input)+len; | |
| 1257 | - | |
| 1258 | - query = (struct hllapi_packet_emulate_input *) malloc(cbSize); | |
| 1259 | - query->packet_id = HLLAPI_PACKET_EMULATE_INPUT; | |
| 1260 | - query->len = len; | |
| 1261 | - query->pasting = 1; | |
| 1262 | - strcpy(query->text,str); | |
| 1263 | - | |
| 1264 | - return query_intval((void *) query, cbSize, true); | |
| 1265 | - | |
| 1266 | -#elif defined(HAVE_DBUS) | |
| 1267 | - | |
| 1268 | - return query_intval("input", DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); | |
| 1269 | -#else | |
| 1270 | - | |
| 1271 | - return -1; | |
| 1272 | - | |
| 1273 | -#endif | |
| 1274 | - | |
| 1275 | - } | |
| 1276 | - | |
| 1277 | - int action(const char *str) | |
| 1278 | - { | |
| 1279 | - | |
| 1280 | -#if defined(WIN32) | |
| 1281 | - | |
| 1282 | - size_t len = strlen(str); | |
| 1283 | - struct hllapi_packet_text * query; | |
| 1284 | - size_t cbSize = sizeof(struct hllapi_packet_text)+len; | |
| 1285 | - | |
| 1286 | - query = (struct hllapi_packet_text *) malloc(cbSize); | |
| 1287 | - query->packet_id = HLLAPI_PACKET_ACTION; | |
| 1288 | - strcpy(query->text,str); | |
| 1289 | - | |
| 1290 | - return query_intval((void *) query, cbSize, true); | |
| 1291 | - | |
| 1292 | -#elif defined(HAVE_DBUS) | |
| 1293 | - | |
| 1294 | - return query_intval("action", DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); | |
| 1295 | -#else | |
| 1296 | - | |
| 1297 | - return -1; | |
| 1298 | - | |
| 1299 | -#endif | |
| 1300 | - | |
| 1301 | - } | |
| 1302 | - | |
| 1303 | - | |
| 1304 | - int get_field_start(int baddr) | |
| 1305 | - { | |
| 1306 | -#if defined(WIN32) | |
| 1307 | - | |
| 1308 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_FIELD_START, (unsigned short) baddr }; | |
| 1309 | - | |
| 1310 | - return query_intval((void *) &query, sizeof(query)); | |
| 1311 | - | |
| 1312 | -#elif defined(HAVE_DBUS) | |
| 1313 | - | |
| 1314 | - dbus_int32_t k = (dbus_int32_t) baddr; | |
| 1315 | - | |
| 1316 | - return query_intval("getFieldStart", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1317 | - | |
| 1318 | -#else | |
| 1319 | - | |
| 1320 | - return -1; | |
| 1321 | - | |
| 1322 | -#endif | |
| 1323 | - | |
| 1324 | - } | |
| 1325 | - | |
| 1326 | - int get_field_len(int baddr) | |
| 1327 | - { | |
| 1328 | -#if defined(WIN32) | |
| 1329 | - | |
| 1330 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_FIELD_LEN, (unsigned short) baddr }; | |
| 1331 | - | |
| 1332 | - return query_intval((void *) &query, sizeof(query)); | |
| 1333 | - | |
| 1334 | -#elif defined(HAVE_DBUS) | |
| 1335 | - | |
| 1336 | - dbus_int32_t k = (dbus_int32_t) baddr; | |
| 1337 | - | |
| 1338 | - return query_intval("getFieldLength", DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1339 | - | |
| 1340 | -#else | |
| 1341 | - | |
| 1342 | - return -1; | |
| 1343 | - | |
| 1344 | -#endif | |
| 1345 | - } | |
| 1346 | - | |
| 1347 | - int get_next_unprotected(int baddr) | |
| 1348 | - { | |
| 1349 | -#if defined(WIN32) | |
| 1350 | - | |
| 1351 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_NEXT_UNPROTECTED, (unsigned short) baddr }; | |
| 1352 | - | |
| 1353 | - return query_intval((void *) &query, sizeof(query)); | |
| 1354 | - | |
| 1355 | -#elif defined(HAVE_DBUS) | |
| 1356 | - | |
| 1357 | - dbus_int32_t k = (dbus_int32_t) baddr; | |
| 1358 | - | |
| 1359 | - DBusMessage * msg = create_message("getNextUnprotected"); | |
| 1360 | - if(msg) | |
| 1361 | - { | |
| 1362 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1363 | - return get_intval(call(msg)); | |
| 1364 | - } | |
| 1365 | - | |
| 1366 | - return -1; | |
| 1367 | - | |
| 1368 | -#else | |
| 1369 | - | |
| 1370 | - return -1; | |
| 1371 | - | |
| 1372 | -#endif | |
| 1373 | - | |
| 1374 | - } | |
| 1375 | - | |
| 1376 | - int get_is_protected(int baddr) | |
| 1377 | - { | |
| 1378 | -#if defined(WIN32) | |
| 1379 | - | |
| 1380 | - struct hllapi_packet_addr query = { HLLAPI_PACKET_IS_PROTECTED, (unsigned short) baddr }; | |
| 1381 | - | |
| 1382 | - return query_intval((void *) &query, sizeof(query)); | |
| 1383 | - | |
| 1384 | -#elif defined(HAVE_DBUS) | |
| 1385 | - | |
| 1386 | - dbus_int32_t k = (dbus_int32_t) baddr; | |
| 1387 | - | |
| 1388 | - DBusMessage * msg = create_message("getIsProtected"); | |
| 1389 | - if(msg) | |
| 1390 | - { | |
| 1391 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &k, DBUS_TYPE_INVALID); | |
| 1392 | - return get_intval(call(msg)); | |
| 1393 | - } | |
| 1394 | - | |
| 1395 | - return -1; | |
| 1396 | - | |
| 1397 | -#else | |
| 1398 | - | |
| 1399 | - return -1; | |
| 1400 | - | |
| 1401 | -#endif | |
| 1402 | - | |
| 1403 | - } | |
| 1404 | - | |
| 1405 | - int get_is_protected_at(int row,int col) | |
| 1406 | - { | |
| 1407 | -#if defined(WIN32) | |
| 1408 | - | |
| 1409 | - struct hllapi_packet_query_at query = { HLLAPI_PACKET_IS_PROTECTED_AT, (unsigned short) row, (unsigned short) col, 0 }; | |
| 1410 | - | |
| 1411 | - return query_intval((void *) &query, sizeof(query)); | |
| 1412 | - | |
| 1413 | -#elif defined(HAVE_DBUS) | |
| 1414 | - | |
| 1415 | - dbus_int32_t r = (dbus_int32_t) row; | |
| 1416 | - dbus_int32_t c = (dbus_int32_t) col; | |
| 1417 | - | |
| 1418 | - DBusMessage * msg = create_message("getIsProtectedAt"); | |
| 1419 | - if(msg) | |
| 1420 | - { | |
| 1421 | - dbus_message_append_args(msg, DBUS_TYPE_INT32, &r, DBUS_TYPE_INT32, &c, DBUS_TYPE_INVALID); | |
| 1422 | - return get_intval(call(msg)); | |
| 1423 | - } | |
| 1424 | - | |
| 1425 | - return -1; | |
| 1426 | - | |
| 1427 | -#else | |
| 1428 | - | |
| 1429 | - return -1; | |
| 1430 | - | |
| 1431 | -#endif | |
| 1432 | - | |
| 1433 | - } | |
| 1434 | - | |
| 1435 | - | |
| 1436 | - int set_host_charset(const char *charset) | |
| 1437 | - { | |
| 1438 | -#if defined(WIN32) | |
| 1439 | - | |
| 1440 | - size_t len = strlen(charset); | |
| 1441 | - struct hllapi_packet_set_text * query; | |
| 1442 | - size_t cbSize = sizeof(struct hllapi_packet_set_text)+len; | |
| 1443 | - | |
| 1444 | - query = (struct hllapi_packet_set_text *) malloc(cbSize); | |
| 1445 | - query->packet_id = HLLAPI_PACKET_SET_HOST_CHARSET; | |
| 1446 | - query->len = len; | |
| 1447 | - strcpy(query->text,charset); | |
| 1448 | - | |
| 1449 | - return query_intval((void *) query, cbSize, true); | |
| 1450 | - | |
| 1451 | -#elif defined(HAVE_DBUS) | |
| 1452 | - | |
| 1453 | - return query_intval("setHostCharset", DBUS_TYPE_STRING, &charset, DBUS_TYPE_INVALID); | |
| 1454 | - | |
| 1455 | -#else | |
| 1456 | - return -1; | |
| 1457 | -#endif | |
| 1458 | - } | |
| 1459 | - | |
| 1460 | - string get_host_charset(void) | |
| 1461 | - { | |
| 1462 | -#if defined(WIN32) | |
| 1463 | - | |
| 1464 | - struct hllapi_packet_query query = { HLLAPI_PACKET_GET_HOST_CHARSET }; | |
| 1465 | - return query_string(&query,sizeof(query),100); | |
| 1466 | - | |
| 1467 | -#elif defined(HAVE_DBUS) | |
| 1468 | - | |
| 1469 | - return query_string("getHostCharset"); | |
| 1470 | - | |
| 1471 | -#else | |
| 1472 | - | |
| 1473 | - return NULL; | |
| 1474 | - | |
| 1475 | -#endif | |
| 1476 | - } | |
| 1477 | - | |
| 1478 | - | |
| 1479 | -#if defined(HAVE_DBUS) | |
| 1480 | - string get_clipboard(void) | |
| 1481 | - { | |
| 1482 | - return query_string("getClipboard"); | |
| 1483 | - } | |
| 1484 | - | |
| 1485 | - int set_clipboard(const char *text) | |
| 1486 | - { | |
| 1487 | - return query_intval("setClipboard", DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID); | |
| 1488 | - } | |
| 1489 | - | |
| 1490 | - string get_display_charset(void) | |
| 1491 | - { | |
| 1492 | - return query_string("getDisplayCharset"); | |
| 1493 | - } | |
| 1494 | - | |
| 1495 | - int popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...) | |
| 1496 | - { | |
| 1497 | - DBusMessage * msg = dbus_message_new_method_call( this->dest, // Destination | |
| 1498 | - this->path, // Path | |
| 1499 | - this->intf, // Interface | |
| 1500 | - "showPopup"); // method | |
| 1501 | - | |
| 1502 | - if (!msg) | |
| 1503 | - { | |
| 1504 | - throw exception("%s","Error creating DBUS message for popup"); | |
| 1505 | - return -1; | |
| 1506 | - } | |
| 1507 | - else | |
| 1508 | - { | |
| 1509 | - char text[4096]; | |
| 1510 | - char * ptr = text; | |
| 1511 | - va_list arg_ptr; | |
| 1512 | - dbus_int32_t i = (dbus_int32_t) id; | |
| 1513 | - | |
| 1514 | - va_start(arg_ptr, fmt); | |
| 1515 | - vsnprintf(text,4095,fmt,arg_ptr); | |
| 1516 | - va_end(arg_ptr); | |
| 1517 | - | |
| 1518 | - if(!dbus_message_append_args(msg, DBUS_TYPE_INT32, &i, DBUS_TYPE_STRING, &title, DBUS_TYPE_STRING, &message, DBUS_TYPE_STRING, &ptr, DBUS_TYPE_INVALID)) | |
| 1519 | - { | |
| 1520 | - dbus_message_unref(msg); | |
| 1521 | - throw exception("%s","Cant append args for popup message"); | |
| 1522 | - } | |
| 1523 | - else | |
| 1524 | - { | |
| 1525 | - DBusMessage * reply; | |
| 1526 | - DBusError error; | |
| 1527 | - | |
| 1528 | - dbus_error_init(&error); | |
| 1529 | - reply = dbus_connection_send_with_reply_and_block(conn,msg,DBUS_TIMEOUT_INFINITE,&error); | |
| 1530 | - dbus_message_unref(msg); | |
| 1531 | - | |
| 1532 | - if(!reply) | |
| 1533 | - { | |
| 1534 | - exception e = exception("%s",error.message); | |
| 1535 | - dbus_error_free(&error); | |
| 1536 | - throw e; | |
| 1537 | - return -1; | |
| 1538 | - } | |
| 1539 | - | |
| 1540 | - return get_intval(reply); | |
| 1541 | - | |
| 1542 | - } | |
| 1543 | - } | |
| 1544 | - return 0; | |
| 1545 | - } | |
| 1546 | - | |
| 1547 | -#endif // HAVE_DBUS | |
| 1548 | - | |
| 1549 | - int erase(void) | |
| 1550 | - { | |
| 1551 | - return query_intval(HLLAPI_PACKET_ERASE); | |
| 1552 | - } | |
| 1553 | - | |
| 1554 | - int erase_eof(void) | |
| 1555 | - { | |
| 1556 | - return query_intval(HLLAPI_PACKET_ERASE_EOF); | |
| 1557 | - } | |
| 1558 | - | |
| 1559 | - int erase_eol(void) | |
| 1560 | - { | |
| 1561 | - return query_intval(HLLAPI_PACKET_ERASE_EOL); | |
| 1562 | - } | |
| 1563 | - | |
| 1564 | - int erase_input(void) | |
| 1565 | - { | |
| 1566 | - return query_intval(HLLAPI_PACKET_ERASE_INPUT); | |
| 1567 | - } | |
| 1568 | - | |
| 1569 | - int print(void) | |
| 1570 | - { | |
| 1571 | - return query_intval(HLLAPI_PACKET_PRINT); | |
| 1572 | - } | |
| 1573 | - | |
| 1574 | - const char * asc2ebc(unsigned char *text, int sz) | |
| 1575 | - { | |
| 1576 | - query_strval(HLLAPI_PACKET_ASC2EBC,text,sz); | |
| 1577 | - return (const char *) text; | |
| 1578 | - } | |
| 1579 | - | |
| 1580 | - const char * ebc2asc(unsigned char *text, int sz) | |
| 1581 | - { | |
| 1582 | - query_strval(HLLAPI_PACKET_EBC2ASC,text,sz); | |
| 1583 | - return (const char *) text; | |
| 1584 | - } | |
| 1585 | - | |
| 1586 | - void set_unlock_delay(unsigned short ms) | |
| 1587 | - { | |
| 1588 | - set_intval(HLLAPI_PACKET_SET_UNLOCK_DELAY,(int) ms); | |
| 1589 | - } | |
| 1590 | - | |
| 1591 | - }; | |
| 1592 | - | |
| 1593 | - session * session::create_remote(const char *session) throw (std::exception) | |
| 1594 | - { | |
| 1595 | - return new remote(session); | |
| 1596 | - } | |
| 1597 | - | |
| 1598 | - } | |
| 1599 | - |
src/pw3270cpp/session.cc
| ... | ... | @@ -1,698 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como session.cc e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | - #include <stdarg.h> | |
| 31 | - #include <stdio.h> | |
| 32 | - #include <string.h> | |
| 33 | - #include <malloc.h> | |
| 34 | - | |
| 35 | - #include "private.h" | |
| 36 | - | |
| 37 | -#ifndef WIN32 | |
| 38 | - #include <unistd.h> | |
| 39 | -#endif // !WIN32 | |
| 40 | - | |
| 41 | -#ifdef HAVE_SYSLOG | |
| 42 | - #include <syslog.h> | |
| 43 | -#endif // HAVE_SYSLOG | |
| 44 | - | |
| 45 | - | |
| 46 | -/*--[ Implement ]--------------------------------------------------------------------------------------------------*/ | |
| 47 | - | |
| 48 | - using namespace PW3270_NAMESPACE; | |
| 49 | - | |
| 50 | -#if defined(linux) | |
| 51 | - static void onLoad() __attribute__((constructor)); | |
| 52 | - static void onUnLoad() __attribute__((destructor)); | |
| 53 | - | |
| 54 | - static void onLoad() | |
| 55 | - { | |
| 56 | - session::init(); | |
| 57 | - } | |
| 58 | - | |
| 59 | - static void onUnLoad() | |
| 60 | - { | |
| 61 | - session::deinit(); | |
| 62 | - } | |
| 63 | - | |
| 64 | -#endif // linux | |
| 65 | - | |
| 66 | -#ifdef _WIN32 | |
| 67 | - | |
| 68 | - BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) | |
| 69 | - { | |
| 70 | - switch(fdwReason) | |
| 71 | - { | |
| 72 | - case DLL_PROCESS_ATTACH: | |
| 73 | - session::init(); | |
| 74 | - break; | |
| 75 | - | |
| 76 | - case DLL_PROCESS_DETACH: | |
| 77 | - session::deinit(); | |
| 78 | - break; | |
| 79 | - } | |
| 80 | - | |
| 81 | - return TRUE; | |
| 82 | - } | |
| 83 | - | |
| 84 | -#endif // _WIN32 | |
| 85 | - | |
| 86 | - | |
| 87 | - namespace PW3270_NAMESPACE { | |
| 88 | - | |
| 89 | - session * session::first = nullptr; | |
| 90 | - session * session::last = nullptr; | |
| 91 | - session * (*session::factory)(const char *name) = nullptr; | |
| 92 | - | |
| 93 | - static recursive_mutex mtx; | |
| 94 | - | |
| 95 | - inline void lock() | |
| 96 | - { | |
| 97 | - mtx.lock(); | |
| 98 | - } | |
| 99 | - | |
| 100 | - inline void unlock() | |
| 101 | - { | |
| 102 | - mtx.unlock(); | |
| 103 | - } | |
| 104 | - | |
| 105 | - void session::init() | |
| 106 | - { | |
| 107 | - trace("Loading %s objects",PACKAGE_NAME); | |
| 108 | - } | |
| 109 | - | |
| 110 | - void session::deinit() | |
| 111 | - { | |
| 112 | - trace("Unloading %s objects",PACKAGE_NAME); | |
| 113 | - while(first) | |
| 114 | - { | |
| 115 | - delete first; | |
| 116 | - } | |
| 117 | - | |
| 118 | - } | |
| 119 | - | |
| 120 | - session::session() | |
| 121 | - { | |
| 122 | - | |
| 123 | -#ifdef HAVE_ICONV | |
| 124 | - this->conv2Local = (iconv_t) (-1); | |
| 125 | - this->conv2Host = (iconv_t) (-1); | |
| 126 | -#endif | |
| 127 | - | |
| 128 | - if(first) | |
| 129 | - { | |
| 130 | - prev = last; | |
| 131 | - next = 0; | |
| 132 | - last->next = this; | |
| 133 | - last = this; | |
| 134 | - } | |
| 135 | - else | |
| 136 | - { | |
| 137 | - prev = next = 0; | |
| 138 | - first = last = this; | |
| 139 | - } | |
| 140 | - | |
| 141 | - } | |
| 142 | - | |
| 143 | - session::~session() | |
| 144 | - { | |
| 145 | -#ifdef HAVE_ICONV | |
| 146 | - | |
| 147 | - if(this->conv2Local != (iconv_t) (-1)) | |
| 148 | - iconv_close(this->conv2Local); | |
| 149 | - | |
| 150 | - if(this->conv2Host != (iconv_t) (-1)) | |
| 151 | - iconv_close(this->conv2Host); | |
| 152 | - | |
| 153 | -#endif | |
| 154 | - | |
| 155 | - if(prev) | |
| 156 | - prev->next = next; | |
| 157 | - else | |
| 158 | - first = next; | |
| 159 | - | |
| 160 | - if(next) | |
| 161 | - next->prev = prev; | |
| 162 | - else | |
| 163 | - last = prev; | |
| 164 | - } | |
| 165 | - | |
| 166 | - // Factory methods and settings | |
| 167 | - session * session::create(const char *name) throw (std::exception) | |
| 168 | - { | |
| 169 | - session *rc = nullptr; | |
| 170 | - | |
| 171 | - trace("%s(%s)",__FUNCTION__,name); | |
| 172 | - | |
| 173 | - lock(); | |
| 174 | - | |
| 175 | - try | |
| 176 | - { | |
| 177 | - if(factory) | |
| 178 | - rc = factory(name); | |
| 179 | - else if(name && *name) | |
| 180 | - rc = create_remote(name); | |
| 181 | - else | |
| 182 | - rc = create_local(); | |
| 183 | - | |
| 184 | - } | |
| 185 | - catch(std::exception &e) | |
| 186 | - { | |
| 187 | - unlock(); | |
| 188 | - throw e; | |
| 189 | - } | |
| 190 | - | |
| 191 | - unlock(); | |
| 192 | - | |
| 193 | - return rc; | |
| 194 | - } | |
| 195 | - | |
| 196 | - session * session::start(const char *name) | |
| 197 | - { | |
| 198 | - return create(name); | |
| 199 | - } | |
| 200 | - | |
| 201 | - bool session::has_default(void) | |
| 202 | - { | |
| 203 | - return first != nullptr; | |
| 204 | - } | |
| 205 | - | |
| 206 | - session * session::get_default(void) | |
| 207 | - { | |
| 208 | - if(first) | |
| 209 | - return first; | |
| 210 | - return create(NULL); | |
| 211 | - } | |
| 212 | - | |
| 213 | - void session::set_plugin(session * (*factory)(const char *name)) | |
| 214 | - { | |
| 215 | - trace("%s(%p)",__FUNCTION__,factory); | |
| 216 | - session::factory = factory; | |
| 217 | - } | |
| 218 | - | |
| 219 | - // Object settings | |
| 220 | - void session::set_display_charset(const char *remote, const char *local) | |
| 221 | - { | |
| 222 | - trace("%s(%s,%s)",__FUNCTION__,remote,local); | |
| 223 | - | |
| 224 | -#ifdef HAVE_ICONV | |
| 225 | - string display_charset = this->get_display_charset(); | |
| 226 | - | |
| 227 | - if(this->conv2Local != (iconv_t) (-1)) | |
| 228 | - iconv_close(this->conv2Local); | |
| 229 | - | |
| 230 | - if(this->conv2Host != (iconv_t) (-1)) | |
| 231 | - iconv_close(this->conv2Host); | |
| 232 | - | |
| 233 | - if(!remote) | |
| 234 | - remote = display_charset.c_str(); | |
| 235 | - | |
| 236 | - trace("%s remote=%s local=%s",__FUNCTION__,remote,local); | |
| 237 | - | |
| 238 | - if(strcmp(local,remote)) | |
| 239 | - { | |
| 240 | - // Local and remote charsets aren't the same, setup conversion | |
| 241 | - conv2Local = iconv_open(local, remote); | |
| 242 | - conv2Host = iconv_open(remote,local); | |
| 243 | - } | |
| 244 | - else | |
| 245 | - { | |
| 246 | - conv2Local = conv2Host = (iconv_t)(-1); | |
| 247 | - } | |
| 248 | - | |
| 249 | -#endif | |
| 250 | - | |
| 251 | - } | |
| 252 | - | |
| 253 | - string session::get_display_charset(void) | |
| 254 | - { | |
| 255 | - return string(get_encoding()); | |
| 256 | - } | |
| 257 | - | |
| 258 | - const char * session::get_encoding(void) | |
| 259 | - { | |
| 260 | - return "ISO-8859-1"; | |
| 261 | - } | |
| 262 | - | |
| 263 | - // 3270 methods | |
| 264 | - const string session::get_version(void) | |
| 265 | - { | |
| 266 | - return string(PACKAGE_VERSION); | |
| 267 | - } | |
| 268 | - | |
| 269 | - const string session::get_revision(void) | |
| 270 | - { | |
| 271 | - return string(PACKAGE_REVISION); | |
| 272 | - } | |
| 273 | - | |
| 274 | - void session::log(const char *fmt, ...) | |
| 275 | - { | |
| 276 | - va_list arg_ptr; | |
| 277 | - va_start(arg_ptr, fmt); | |
| 278 | - this->logva(fmt,arg_ptr); | |
| 279 | - va_end(arg_ptr); | |
| 280 | - } | |
| 281 | - | |
| 282 | - void session::logva(const char *fmt, va_list args) | |
| 283 | - { | |
| 284 | - #ifdef HAVE_SYSLOG | |
| 285 | - openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | |
| 286 | - vsyslog(LOG_INFO,fmt,args); | |
| 287 | - closelog(); | |
| 288 | - #else | |
| 289 | - vfprintf(stderr,fmt,args); | |
| 290 | - #endif | |
| 291 | - } | |
| 292 | - | |
| 293 | - int session::wait_for_text_at(int row, int col, const char *key, int timeout) | |
| 294 | - { | |
| 295 | - time_t end = time(0)+timeout; | |
| 296 | - | |
| 297 | - trace("%s(%d,%d,%s,%d)",__FUNCTION__,row,col,key,timeout); | |
| 298 | - | |
| 299 | - iterate(false); | |
| 300 | - while(time(0) < end) | |
| 301 | - { | |
| 302 | - trace("Aguardar %d segundos por \"%s\" @%d,%d (%s)",(int) (end - time(0)),key,row,col,get_text_at(row,col,strlen(key)).c_str()); | |
| 303 | - | |
| 304 | - int rc = wait_for_ready(end - time(0)); | |
| 305 | - if(rc) { | |
| 306 | - return rc; | |
| 307 | - } | |
| 308 | - | |
| 309 | - if(!cmp_text_at(row,col,key)) { | |
| 310 | - return 0; | |
| 311 | - } | |
| 312 | - | |
| 313 | - iterate(true); | |
| 314 | - | |
| 315 | - } | |
| 316 | - | |
| 317 | - trace("Tela:\n%s\n", ((string) *this).c_str()); | |
| 318 | - | |
| 319 | - return ETIMEDOUT; | |
| 320 | - } | |
| 321 | - | |
| 322 | - int session::set_copy(const char *text) | |
| 323 | - { | |
| 324 | - return EINVAL; | |
| 325 | - } | |
| 326 | - | |
| 327 | - string session::get_copy(void) | |
| 328 | - { | |
| 329 | - errno = EINVAL; | |
| 330 | - return string(); | |
| 331 | - } | |
| 332 | - | |
| 333 | - string session::get_clipboard(void) | |
| 334 | - { | |
| 335 | -#if defined(WIN32) | |
| 336 | - | |
| 337 | - if (! OpenClipboard(0)) | |
| 338 | - { | |
| 339 | - throw exception(GetLastError(),"%s","Can´t open system clipboard"); | |
| 340 | - return NULL; | |
| 341 | - } | |
| 342 | - | |
| 343 | - HANDLE hData = GetClipboardData(CF_TEXT); | |
| 344 | - if(!hData) | |
| 345 | - { | |
| 346 | - throw exception(GetLastError(),"%s","Can´t get clipboard data"); | |
| 347 | - return NULL; | |
| 348 | - } | |
| 349 | - | |
| 350 | - char * pszText = static_cast<char*>( GlobalLock(hData) ); | |
| 351 | - if(!pszText) | |
| 352 | - { | |
| 353 | - throw exception(GetLastError(),"%s","Can´t lock clipboard"); | |
| 354 | - return NULL; | |
| 355 | - } | |
| 356 | - | |
| 357 | - string text = string ( pszText ); | |
| 358 | - | |
| 359 | - GlobalUnlock( hData ); | |
| 360 | - | |
| 361 | - CloseClipboard(); | |
| 362 | - | |
| 363 | - return text; | |
| 364 | - | |
| 365 | -#else | |
| 366 | - errno = EINVAL; | |
| 367 | - return NULL; | |
| 368 | - | |
| 369 | -#endif // WIN32 | |
| 370 | - } | |
| 371 | - | |
| 372 | - int session::set_clipboard(const char *text) | |
| 373 | - { | |
| 374 | -#if defined(WIN32) | |
| 375 | - if (! OpenClipboard(0)) | |
| 376 | - { | |
| 377 | - throw exception(GetLastError(),"%s","Can´t open system clipboard"); | |
| 378 | - return -1; | |
| 379 | - } | |
| 380 | - | |
| 381 | - EmptyClipboard(); | |
| 382 | - | |
| 383 | - size_t size = strlen(text)+1; | |
| 384 | - HGLOBAL hClipboardData = GlobalAlloc(GMEM_MOVEABLE , size); | |
| 385 | - | |
| 386 | - strcpy((char *) GlobalLock(hClipboardData), text); | |
| 387 | - | |
| 388 | - if(!SetClipboardData(CF_TEXT, hClipboardData)) | |
| 389 | - { | |
| 390 | - GlobalUnlock(hClipboardData); | |
| 391 | - CloseClipboard(); | |
| 392 | - throw exception(GetLastError(),"%s","Can´t set system clipboard"); | |
| 393 | - } | |
| 394 | - | |
| 395 | - GlobalUnlock(hClipboardData); | |
| 396 | - CloseClipboard(); | |
| 397 | - | |
| 398 | - return 0; | |
| 399 | -#else | |
| 400 | - | |
| 401 | - return EINVAL; | |
| 402 | - | |
| 403 | -#endif // WIN32 | |
| 404 | - } | |
| 405 | - | |
| 406 | - | |
| 407 | - int session::popup_dialog(LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...) | |
| 408 | - { | |
| 409 | - return -1; | |
| 410 | - } | |
| 411 | - | |
| 412 | - string session::file_chooser_dialog(int action, const char *title, const char *extension, const char *filename) | |
| 413 | - { | |
| 414 | - return string(""); | |
| 415 | - } | |
| 416 | - | |
| 417 | - string session::get_3270_text(const char *str) | |
| 418 | - { | |
| 419 | - string rc; | |
| 420 | - | |
| 421 | -#ifdef HAVE_ICONV | |
| 422 | - size_t in = strlen(str); | |
| 423 | - | |
| 424 | - if(in && conv2Host != (iconv_t)(-1)) | |
| 425 | - { | |
| 426 | - size_t out = (in << 1); | |
| 427 | - char * ptr; | |
| 428 | - char * outBuffer = (char *) malloc(out); | |
| 429 | - ICONV_CONST char * inBuffer = (ICONV_CONST char *) str; | |
| 430 | - | |
| 431 | - memset(ptr=outBuffer,0,out); | |
| 432 | - | |
| 433 | - iconv(conv2Host,NULL,NULL,NULL,NULL); // Reset state | |
| 434 | - | |
| 435 | - if(iconv(conv2Host,&inBuffer,&in,&ptr,&out) == ((size_t) -1)) { | |
| 436 | - rc.assign(str); | |
| 437 | - } else { | |
| 438 | - rc.assign(outBuffer); | |
| 439 | - } | |
| 440 | - | |
| 441 | - free(outBuffer); | |
| 442 | - } else { | |
| 443 | - rc.assign(str); | |
| 444 | - } | |
| 445 | -#else | |
| 446 | - rc.assign(str); | |
| 447 | -#endif // HAVE_ICONV | |
| 448 | - | |
| 449 | - trace("%s(\"%s\")=\"%s\"",__FUNCTION__,str,rc.c_str()); | |
| 450 | - | |
| 451 | - return rc; | |
| 452 | - } | |
| 453 | - | |
| 454 | - string session::get_local_text(const char *str) | |
| 455 | - { | |
| 456 | - string rc; | |
| 457 | - | |
| 458 | -#ifdef HAVE_ICONV | |
| 459 | - size_t in = strlen(str); | |
| 460 | - | |
| 461 | - if(in && conv2Local != (iconv_t)(-1)) | |
| 462 | - { | |
| 463 | - size_t out = (in << 1); | |
| 464 | - char * ptr; | |
| 465 | - char * outBuffer = (char *) malloc(out); | |
| 466 | - ICONV_CONST char * inBuffer = (ICONV_CONST char *) str; | |
| 467 | - | |
| 468 | - memset(ptr=outBuffer,0,out); | |
| 469 | - | |
| 470 | - iconv(conv2Local,NULL,NULL,NULL,NULL); // Reset state | |
| 471 | - | |
| 472 | - if(iconv(conv2Local,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) | |
| 473 | - rc.assign(outBuffer); | |
| 474 | - | |
| 475 | - free(outBuffer); | |
| 476 | - } | |
| 477 | - else | |
| 478 | - { | |
| 479 | - char * text = strdup(str); | |
| 480 | - for(char *ptr = text;*ptr;ptr++) | |
| 481 | - { | |
| 482 | - if(*ptr < ' ' || *ptr > 128) | |
| 483 | - { | |
| 484 | - *ptr = '?'; | |
| 485 | - } | |
| 486 | - } | |
| 487 | - rc = text; | |
| 488 | - free(text); | |
| 489 | - } | |
| 490 | -#else | |
| 491 | - char * text = strdup(str); | |
| 492 | - for(char *ptr = text;*ptr;ptr++) | |
| 493 | - { | |
| 494 | - if(*ptr < ' ' || *ptr > 128) | |
| 495 | - { | |
| 496 | - *ptr = '?'; | |
| 497 | - } | |
| 498 | - } | |
| 499 | - rc = text; | |
| 500 | - free(text); | |
| 501 | -#endif // HAVE_ICONV | |
| 502 | - | |
| 503 | - return rc; | |
| 504 | - } | |
| 505 | - | |
| 506 | - string session::get_string_at(int row, int col, size_t sz) | |
| 507 | - { | |
| 508 | - return this->get_local_text(this->get_text_at(row,col,sz).c_str()); | |
| 509 | - } | |
| 510 | - | |
| 511 | - int session::set_string_at(int row, int col, const char *str) | |
| 512 | - { | |
| 513 | - if(!str) | |
| 514 | - return -1; | |
| 515 | - | |
| 516 | -#ifdef HAVE_ICONV | |
| 517 | - if(conv2Host != (iconv_t)(-1)) | |
| 518 | - { | |
| 519 | - size_t in = strlen(str); | |
| 520 | - size_t out = (in << 1); | |
| 521 | - char * ptr; | |
| 522 | - char * outBuffer = (char *) malloc(out); | |
| 523 | - ICONV_CONST char * inBuffer = (ICONV_CONST char *) str; | |
| 524 | - | |
| 525 | - memset(ptr=outBuffer,0,out); | |
| 526 | - | |
| 527 | - iconv(conv2Host,NULL,NULL,NULL,NULL); // Reset state | |
| 528 | - | |
| 529 | - if(iconv(conv2Host,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) | |
| 530 | - { | |
| 531 | - int rc = this->set_text_at(row,col,outBuffer); | |
| 532 | - free(outBuffer); | |
| 533 | - return rc; | |
| 534 | - } | |
| 535 | - | |
| 536 | - free(outBuffer); | |
| 537 | - } | |
| 538 | -#endif // HAVE_ICONV | |
| 539 | - | |
| 540 | - return this->set_text_at(row,col,str); | |
| 541 | - | |
| 542 | - } | |
| 543 | - | |
| 544 | - int session::input_string(const char *str) | |
| 545 | - { | |
| 546 | - if(!str) | |
| 547 | - return -1; | |
| 548 | - | |
| 549 | -#ifdef HAVE_ICONV | |
| 550 | - if(conv2Host != (iconv_t)(-1)) | |
| 551 | - { | |
| 552 | - size_t in = strlen(str); | |
| 553 | - size_t out = (in << 1); | |
| 554 | - char * ptr; | |
| 555 | - char * outBuffer = (char *) malloc(out); | |
| 556 | - ICONV_CONST char * inBuffer = (ICONV_CONST char *) str; | |
| 557 | - | |
| 558 | - memset(ptr=outBuffer,0,out); | |
| 559 | - | |
| 560 | - iconv(conv2Host,NULL,NULL,NULL,NULL); // Reset state | |
| 561 | - | |
| 562 | - if(iconv(conv2Host,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) | |
| 563 | - { | |
| 564 | - int rc = this->emulate_input(outBuffer); | |
| 565 | - free(outBuffer); | |
| 566 | - return rc; | |
| 567 | - } | |
| 568 | - | |
| 569 | - free(outBuffer); | |
| 570 | - } | |
| 571 | -#endif // HAVE_ICONV | |
| 572 | - | |
| 573 | - return this->emulate_input(str); | |
| 574 | - | |
| 575 | - } | |
| 576 | - | |
| 577 | - int session::cmp_string_at(int row, int col, const char *text) | |
| 578 | - { | |
| 579 | - return cmp_text_at(row,col,get_3270_text(text).c_str()); | |
| 580 | - } | |
| 581 | - | |
| 582 | - int session::wait_for_string_at(int row, int col, const char *key, int timeout) | |
| 583 | - { | |
| 584 | - return wait_for_text_at(row,col,get_3270_text(key).c_str(),timeout); | |
| 585 | - } | |
| 586 | - | |
| 587 | - string session::get_string(int baddr, size_t len) | |
| 588 | - { | |
| 589 | - return get_local_text(get_text(baddr,len).c_str()); | |
| 590 | - } | |
| 591 | - | |
| 592 | - string session::asc2ebc(string &str) | |
| 593 | - { | |
| 594 | - size_t sz = str.size(); | |
| 595 | - unsigned char buffer[sz+1]; | |
| 596 | - | |
| 597 | - memcpy(buffer,str.c_str(),sz); | |
| 598 | - return string(asc2ebc(buffer,sz)); | |
| 599 | - } | |
| 600 | - | |
| 601 | - string session::ebc2asc(string &str) | |
| 602 | - { | |
| 603 | - size_t sz = str.size(); | |
| 604 | - unsigned char buffer[sz+1]; | |
| 605 | - memcpy(buffer,str.c_str(),sz); | |
| 606 | - return string(ebc2asc(buffer,sz)); | |
| 607 | - } | |
| 608 | - | |
| 609 | - int session::file_transfer(LIB3270_FT_OPTION options, const char *local, const char *remote, int lrecl, int blksize, int primspace, int secspace, int dft) | |
| 610 | - { | |
| 611 | - log("Can't transfer %s: File transfer is unavailable", local ? local : "file"); | |
| 612 | - return EINVAL; | |
| 613 | - } | |
| 614 | - | |
| 615 | - int session::set_host(const char *host) | |
| 616 | - { | |
| 617 | - return set_url(host); | |
| 618 | - } | |
| 619 | - | |
| 620 | - int session::connect(const char *host, time_t wait) | |
| 621 | - { | |
| 622 | - int rc = 0; | |
| 623 | - | |
| 624 | - if(host && *host) | |
| 625 | - { | |
| 626 | - rc = set_url(host); | |
| 627 | - trace("%s: set_url(%s) = %d",__FUNCTION__,host,rc); | |
| 628 | - } | |
| 629 | - | |
| 630 | - rc = connect(); | |
| 631 | - trace("%s: connect=%d",__FUNCTION__,rc); | |
| 632 | - | |
| 633 | - if(!rc && wait) | |
| 634 | - { | |
| 635 | - time_t timeout = time(0)+wait; | |
| 636 | - rc = ETIMEDOUT; | |
| 637 | - | |
| 638 | - while(time(0) < timeout && rc == ETIMEDOUT) | |
| 639 | - { | |
| 640 | - trace("%s: Waiting",__FUNCTION__); | |
| 641 | - if(is_connected()) | |
| 642 | - rc = 0; | |
| 643 | - iterate(true); | |
| 644 | - } | |
| 645 | - } | |
| 646 | - | |
| 647 | - return rc; | |
| 648 | - } | |
| 649 | - | |
| 650 | -#ifdef WIN32 | |
| 651 | - string session::win32_strerror(int e) | |
| 652 | - { | |
| 653 | - static char buffer[4096]; | |
| 654 | - | |
| 655 | - memset(buffer,0,sizeof(buffer)); | |
| 656 | - | |
| 657 | - if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,e,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),buffer,sizeof(buffer),NULL) == 0) | |
| 658 | - { | |
| 659 | - snprintf(buffer,4095,"Windows error %d", e); | |
| 660 | - } | |
| 661 | - | |
| 662 | - for(size_t f=0;f<sizeof(buffer);f++) | |
| 663 | - { | |
| 664 | - if(buffer[f] < ' ') | |
| 665 | - { | |
| 666 | - buffer[f] = 0; | |
| 667 | - break; | |
| 668 | - } | |
| 669 | - } | |
| 670 | - | |
| 671 | - return string(buffer); | |
| 672 | - } | |
| 673 | -#endif // WIN32 | |
| 674 | - | |
| 675 | - int session::erase(int mode) { | |
| 676 | - | |
| 677 | - switch(mode) { | |
| 678 | - case 0: | |
| 679 | - return erase(); | |
| 680 | - | |
| 681 | - case 1: | |
| 682 | - return erase_eof(); | |
| 683 | - | |
| 684 | - case 2: | |
| 685 | - return erase_eol(); | |
| 686 | - | |
| 687 | - case 3: | |
| 688 | - return erase_input(); | |
| 689 | - | |
| 690 | - } | |
| 691 | - | |
| 692 | - return -1; | |
| 693 | - } | |
| 694 | - | |
| 695 | - | |
| 696 | - } | |
| 697 | - | |
| 698 | - |
src/pw3270cpp/testprogram.cc
| ... | ... | @@ -1,92 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como testprogram.cc e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | - #include <pw3270/class.h> | |
| 31 | - #include <unistd.h> | |
| 32 | - #include <iostream> | |
| 33 | - | |
| 34 | - using namespace std; | |
| 35 | - using namespace PW3270_NAMESPACE; | |
| 36 | - | |
| 37 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 38 | - | |
| 39 | - int main(int numpar, char *param[]) | |
| 40 | - { | |
| 41 | - | |
| 42 | - { | |
| 43 | - string s; | |
| 44 | - session *session = session::start(""); | |
| 45 | - // session *session = session::start("new"); | |
| 46 | - | |
| 47 | - cout << "pw3270 version: " << session->get_version() << endl; | |
| 48 | - cout << "pw3270 revision: " << session->get_revision() << endl << endl; | |
| 49 | - | |
| 50 | - if(session->is_connected()) | |
| 51 | - cout << "\tConnected to host" << endl; | |
| 52 | - else | |
| 53 | - cout << "\tDisconnected" << endl; | |
| 54 | - | |
| 55 | - cout << "\tSession state: " << session->get_cstate() << endl; | |
| 56 | - | |
| 57 | - s = session->get_display_charset(); | |
| 58 | - cout << "\tDisplay charset: " << s.c_str() << endl; | |
| 59 | - | |
| 60 | - s = session->get_host_charset(); | |
| 61 | - cout << "\tHost charset: " << s.c_str() << endl; | |
| 62 | - | |
| 63 | - cout << "Connect: " << session->connect("fandezhi.efglobe.com:23",60) << endl << endl; | |
| 64 | - | |
| 65 | - cout << "\tWaitForReady: " << session->wait_for_ready(10) << endl; | |
| 66 | - | |
| 67 | - cout << "\tIsConnected: " << session->is_connected() << endl; | |
| 68 | - cout << "\tIsReady: " << session->is_ready() << endl; | |
| 69 | - cout << "\tString(3,2,14) " << session->get_string_at(3,2,14) << endl; | |
| 70 | - | |
| 71 | - delete session; | |
| 72 | - } | |
| 73 | - | |
| 74 | - // Waits | |
| 75 | - sleep(2); | |
| 76 | - | |
| 77 | - // Create another session | |
| 78 | - /* | |
| 79 | - { | |
| 80 | - session *session = session::start("pw3270:a"); | |
| 81 | - | |
| 82 | - session->disconnect(); | |
| 83 | - delete session; | |
| 84 | - | |
| 85 | - } | |
| 86 | - */ | |
| 87 | - | |
| 88 | - | |
| 89 | - return 0; | |
| 90 | - } | |
| 91 | - | |
| 92 | - |