Commit 163dd8d38c5ac769073cb8155354f45762717f89
1 parent
4d76b644
Exists in
master
and in
5 other branches
Atualizando Makefiles
Showing
23 changed files
with
3729 additions
and
4066 deletions
Show diff stats
Makefile.in
... | ... | @@ -22,8 +22,6 @@ |
22 | 22 | # |
23 | 23 | # perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) |
24 | 24 | # erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) |
25 | -# licinio@bb.com.br (Licínio Luis Branco) | |
26 | -# kraucer@bb.com.br (Kraucer Fernandes Mazuco) | |
27 | 25 | # |
28 | 26 | |
29 | 27 | #---[ Configuration values ]--------------------------------------------------- |
... | ... | @@ -31,12 +29,8 @@ |
31 | 29 | PACKAGE_NAME=@PACKAGE_NAME@ |
32 | 30 | PACKAGE_VERSION=@PACKAGE_VERSION@ |
33 | 31 | PACKAGE_LEVEL=@PACKAGE_LEVEL@ |
34 | -PACKAGE_REVISION=@PACKAGE_REVISION@ | |
35 | 32 | PACKAGE_TARNAME=@PACKAGE_TARNAME@ |
36 | 33 | |
37 | -PLUGINS=@PLUGINS@ | |
38 | -EXTENSIONS=@EXTENSIONS@ | |
39 | - | |
40 | 34 | #---[ Paths ]------------------------------------------------------------------ |
41 | 35 | |
42 | 36 | prefix=@prefix@ |
... | ... | @@ -51,413 +45,82 @@ docdir=@docdir@ |
51 | 45 | sysconfdir=@sysconfdir@ |
52 | 46 | mandir=@mandir@ |
53 | 47 | |
54 | -BINDIR=.bin | |
55 | -EXEEXT=@EXEEXT@ | |
56 | -DBGLIB=-L../../$(BINDIR)/Debug@DLLDIR@ -l3270 | |
57 | -RLSLIB=-L../../$(BINDIR)/Release@DLLDIR@ -l3270 | |
58 | -TMPDIR = .tmp | |
59 | -GLOBAL_DEPS=$(PWD)/include/*.h $(PWD)/include/lib3270/*.h | |
60 | -LANG_FILES=$(wildcard po/*.po) | |
48 | +BASEDIR=@BASEDIR@ | |
49 | + | |
50 | +BINDIR=$(BASEDIR)/.bin | |
51 | +BINDBG=$(BINDIR)/Debug | |
52 | +BINRLS=$(BINDIR)/Release | |
61 | 53 | |
62 | 54 | #---[ Tools ]------------------------------------------------------------------ |
63 | 55 | |
64 | -VALGRIND=@VALGRIND@ | |
65 | -MKDIR=@MKDIR_P@ | |
66 | -INSTALL=@INSTALL@ | |
67 | -INSTALL_PROGRAM=@INSTALL_PROGRAM@ | |
68 | -INSTALL_DATA=@INSTALL_DATA@ | |
69 | -RPMBUILD=@RPMBUILD@ | |
70 | -DPKGBUILD=@DPKGBUILD@ | |
71 | -MACBUNDLER=@MACBUNDLER@ | |
72 | -CONVERT=@CONVERT@ | |
73 | -MSGCAT=@MSGCAT@ | |
74 | -MSGINIT=@MSGINIT@ | |
75 | -MSGMERGE=@MSGMERGE@ | |
76 | -MSGFMT=@MSGFMT@ | |
77 | -XML2POT=src/tools/xml2pot@EXEEXT@ | |
78 | -SHELL=@SHELL@ | |
79 | -AMTAR=@AMTAR@ | |
80 | -DBGCMDPREFIX=@DBGCMDPREFIX@ | |
81 | -MAKENSIS=@MAKENSIS@ | |
82 | - | |
83 | -PLUGIN_RELEASE_ARGS=BINDIR="../../../$(BINDIR)" LIB3270_MODE=Release | |
84 | -PLUGIN_DEBUG_ARGS=BINDIR="../../../$(BINDIR)" LIB3270_MODE=Debug | |
85 | 56 | |
86 | 57 | #---[ Rules ]------------------------------------------------------------------ |
87 | 58 | |
88 | -%.tar.bz2: %.tar | |
89 | - @echo " GEN `basename $@`" | |
90 | - @bzip2 --compress -9 --stdout $< > $@ | |
91 | - @chmod 0644 $@ | |
92 | - | |
93 | -%.tar.gz: %.tar | |
94 | - @echo " GEN `basename $@`" | |
95 | - @gzip -9 --stdout $< > $@ | |
96 | - @chmod 0644 $@ | |
97 | - | |
98 | - | |
99 | -src/pw3270/%.png: src/pw3270/pixmaps/%.svg | |
100 | -ifneq ($(CONVERT),no) | |
101 | - @echo " GEN `basename $@`" | |
102 | - @$(MKDIR) `dirname $@` | |
103 | - @$(CONVERT) --format=png --output=$@ $< | |
104 | -endif | |
105 | - | |
106 | -%.png: src/pw3270/pixmaps/%.svg | |
107 | -ifneq ($(CONVERT),no) | |
108 | - @echo " GEN `basename $@`" | |
109 | - @$(MKDIR) `dirname $@` | |
110 | - @$(CONVERT) --format=png --output=$@ $< | |
111 | -endif | |
59 | +DEPENDS=$(BASEDIR)/src/include/*.h $(BASEDIR)/src/include/lib3270/*.h $(BASEDIR)/src/include/pw3270/*.h Makefile | |
112 | 60 | |
113 | -$(BINDIR)/pot/%.pot: src/%/Makefile | |
114 | - @$(MAKE) BINDIR=../../$(BINDIR) -C $(dir $^) ../../$@ | |
61 | +$(BINDBG)/%@DLLEXT@: \ | |
62 | + $(DEPENDS) \ | |
63 | + ./src/%/* | |
64 | + | |
65 | + @$(MAKE) -C src/$(basename $(notdir $@)) $@ | |
115 | 66 | |
116 | -po/%.po: $(PACKAGE_NAME).po | |
117 | - @echo " GEN `basename $@`" | |
118 | - @$(MKDIR) `dirname $@` | |
119 | - @$(MKDIR) $(TMPDIR)/po | |
120 | - @cp $@ $(TMPDIR)/$@ 2> $(TMPDIR)/cp.err > $(TMPDIR)/cp.out || true | |
121 | - @touch $(TMPDIR)/$@ | |
122 | - @$(MSGMERGE) $(TMPDIR)/$@ $(PACKAGE_NAME).po --output-file=$@ | |
123 | - @rm -fr $(TMPDIR)/po | |
67 | +$(BINDBG)/%@EXEEXT@: \ | |
68 | + $(DEPENDS) \ | |
69 | + ./src/%/* | |
70 | + | |
71 | + @$(MAKE) -C src/$(basename $(notdir $@)) $@ | |
124 | 72 | |
125 | -$(BINDIR)/Release/$(localedir)/%/LC_MESSAGES/$(PACKAGE_NAME).mo: po/%.po | |
126 | - @echo " FMT `basename $@`" | |
127 | - @$(MKDIR) `dirname $@` | |
128 | - @$(MSGFMT) -c -v -o $@ $^ | |
73 | +$(BINRLS)/%@DLLEXT@: \ | |
74 | + $(DEPENDS) \ | |
75 | + ./src/%/* | |
76 | + | |
77 | + @$(MAKE) -C src/$(basename $(notdir $@)) $@ | |
129 | 78 | |
130 | -src/tools/%@EXEEXT@: src/tools/%.c | |
131 | - @make -C src/tools $(notdir $@) | |
79 | +$(BINRLS)/%@EXEEXT@: \ | |
80 | + $(DEPENDS) \ | |
81 | + ./src/%/* | |
82 | + | |
83 | + @$(MAKE) -C src/$(basename $(notdir $@)) $@ | |
132 | 84 | |
133 | -$(BINDIR)/Debug/plugins/%@DLLEXT@: src/plugins/%/* $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) | |
134 | - @make BINDIR="../../../$(BINDIR)" PW3270_LIBS="-L../../../$(BINDIR)/Debug@DLLDIR@ -l3270 -lpw3270" PW3270_CFLAGS="-I../../../src/include" -C $(dir $<) Debug | |
135 | - | |
136 | -$(BINDIR)/Release/plugins/%@DLLEXT@: src/plugins/%/* $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) | |
137 | - @make $(PLUGIN_RELEASE_ARGS) -C $(dir $<) Release | |
138 | - | |
139 | -$(BINDIR)/Debug/plugins/j3270@DLLEXT@: src/java/* $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) | |
140 | - @make BINDIR="../../$(BINDIR)" PW3270_LIBS="-L../../$(BINDIR)/Debug@DLLDIR@ -l3270 -lpw3270" PW3270_CFLAGS="-I../include" -C $(dir $<) Debug | |
141 | - | |
142 | -$(BINDIR)/Release/plugins/j3270@DLLEXT@: src/java/* $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) | |
143 | - make BINDIR="../../$(BINDIR)" PW3270_LIBS="-L../../$(BINDIR)/Release@DLLDIR@ -l3270 -lpw3270" PW3270_CFLAGS="-I../include" -C $(dir $<) Release | |
144 | - | |
145 | -$(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins/%@DLLEXT@: $(BINDIR)/Release/plugins/%@DLLEXT@ | |
146 | - @$(MKDIR) `dirname $@` | |
147 | - @$(INSTALL_PROGRAM) "$^" "$@" | |
148 | 85 | |
149 | 86 | #---[ Release targets ]-------------------------------------------------------- |
150 | 87 | |
151 | -all: \ | |
152 | - $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) \ | |
153 | - $(foreach EXT, $(EXTENSIONS), $(EXT)) \ | |
154 | - $(foreach PLUGIN, $(PLUGINS), $(BINDIR)/Release/plugins/$(PLUGIN)@DLLEXT@) \ | |
155 | - locale pixmaps | |
156 | - | |
157 | 88 | Release: \ |
158 | - $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) \ | |
159 | - $(foreach EXT, $(EXTENSIONS), $(EXT)) \ | |
160 | - $(foreach PLUGIN, $(PLUGINS), $(BINDIR)/Release/plugins/$(PLUGIN)@DLLEXT@) \ | |
161 | - locale pixmaps | |
89 | + $(BINRLS)/lib3270@DLLEXT@ \ | |
90 | + $(BINRLS)/$(PACKAGE_TARNAME)@EXEEXT@ | |
162 | 91 | |
163 | -$(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT): src/pw3270/* $(BINDIR)/Release@DLLDIR@/lib3270@DLLEXT@ $(DEPENDS) | |
164 | - @$(MAKE) BINDIR="../../$(BINDIR)" LIB3270_LIBS="$(RLSLIB)" LIB3270_CFLAGS="-I../../src/include" -C src/pw3270 ../../$(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) | |
165 | - | |
166 | -$(BINDIR)/Release@DLLDIR@/lib3270@DLLEXT@: src/lib3270/* src/include/lib3270/* src/include/* Makefile | |
167 | - @$(MAKE) BINRLS=../../.bin/Release@DLLDIR@ -C src/lib3270 ../../.bin/Release@DLLDIR@/lib3270@DLLEXT@ | |
168 | - | |
169 | -oxt: $(BINDIR)/Release/$(PACKAGE_NAME).oxt | |
170 | - | |
171 | -$(BINDIR)/Release/$(PACKAGE_NAME).oxt: | |
172 | - @$(MAKE) -C src/loffice Release | |
173 | - @$(MKDIR) `dirname $@` | |
174 | - @cp src/loffice/.bin/Release/$(PACKAGE_NAME).oxt $@ | |
175 | - | |
176 | -php: $(BINDIR)/Release/tn3270@DLLEXT@ | |
177 | - | |
178 | -$(BINDIR)/Release/tn3270.so: src/php/* | |
179 | - @$(MAKE) -C src/php Release | |
180 | - @$(MKDIR) `dirname $@` | |
181 | - @cp src/php/.bin/Release/php3270.so $@ | |
182 | - | |
183 | -java: $(BINDIR)/Release/@DLLPREFIX@jni3270@DLLEXT@ | |
184 | - | |
185 | -$(BINDIR)/Release/@DLLPREFIX@jni3270@DLLEXT@: src/java/* | |
186 | - @$(MKDIR) `dirname $@` | |
187 | - @$(MAKE) BINDIR="../../$(BINDIR)" LIB3270_LIBS="$(RLSLIB)" LIB3270_CFLAGS="-I../../src/include" -C src/java Release | |
188 | - | |
189 | -python: $(BINDIR)/Release/py3270@DLLEXT@ | |
190 | - | |
191 | -$(BINDIR)/Release/py3270@DLLEXT@: src/python/* | |
192 | - @$(MAKE) -C src/python Release | |
193 | - @$(MKDIR) `dirname $@` | |
194 | - @cp src/python/.bin/Release/py3270@DLLEXT@ $@ | |
92 | +#---[ Debug targets ]---------------------------------------------------------- | |
195 | 93 | |
196 | -rexx: $(BINDIR)/Debug/plugins/rx3270@DLLEXT@ | |
94 | +Debug: \ | |
95 | + $(BINDBG)/lib3270@DLLEXT@ \ | |
96 | + $(BINDBG)/$(PACKAGE_TARNAME)@EXEEXT@ | |
197 | 97 | |
198 | -#---[ Debug targets ]---------------------------------------------------------- | |
98 | +run: \ | |
99 | + $(BINDBG)/lib3270@DLLEXT@ \ | |
100 | + $(BINDBG)/$(PACKAGE_TARNAME)@EXEEXT@ | |
199 | 101 | |
200 | -Debug: $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) \ | |
201 | - $(foreach PLUGIN, $(PLUGINS), $(BINDIR)/Debug/plugins/$(PLUGIN)@DLLEXT@) | |
202 | - | |
203 | -$(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT): src/pw3270/* $(BINDIR)/Debug@DLLDIR@/lib3270@DLLEXT@ $(DEPENDS) | |
204 | - @$(MAKE) BINDIR="../../$(BINDIR)" LIB3270_LIBS="$(DBGLIB)" LIB3270_CFLAGS="-I../../src/include" -C src/pw3270 ../../$(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) | |
205 | - | |
206 | -$(BINDIR)/Debug@DLLDIR@/lib3270@DLLEXT@: src/lib3270/* src/include/lib3270/* src/include/* Makefile | |
207 | - @$(MAKE) BINDBG=../../.bin/Debug@DLLDIR@ -C src/lib3270 ../../.bin/Debug@DLLDIR@/lib3270@DLLEXT@ | |
208 | - | |
209 | -run: $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) $(PACKAGE_NAME).png $(PACKAGE_NAME)-logo.png \ | |
210 | - $(foreach PLUGIN, $(PLUGINS), $(BINDIR)/Debug/plugins/$(PLUGIN)@DLLEXT@) | |
211 | - @$(DBGCMDPREFIX) "$(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT)" | |
212 | - | |
213 | -memchk: $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) | |
214 | - @$(MKDIR) $(PWD)/$(TMPDIR) | |
215 | -ifeq ($(VALGRIND),no) | |
216 | - @PATH="$(BINDIR)/Debug@DLLDIR@:$(PATH)" "$(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT)" | |
217 | -else | |
218 | - @PATH="$(BINDIR)/Debug@DLLDIR@:$(PATH)" G_DEBUG=gc-friendly G_SLICE=always-malloc \$(VALGRIND) --leak-check=full --suppressions=src/pw3270/valgrind.suppression --gen-suppressions=all $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) | |
219 | -endif | |
220 | - | |
221 | -#---[ Targets ]---------------------------------------------------------------- | |
222 | - | |
223 | -tgz: $(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.gz | |
224 | - | |
225 | -bz2: $(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.bz2 | |
226 | - | |
227 | -rpm: $(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.bz2 | |
228 | -ifneq ($(RPMBUILD),no) | |
229 | - @$(MKDIR) $(PWD)/$(TMPDIR)/rpmbuild | |
230 | - @TMPDIR=$(PWD)/$(TMPDIR)/rpmbuild $(RPMBUILD) --define="_sourcedir $(PWD)" -ba --clean $(PACKAGE_TARNAME).spec | |
231 | - @rm -fr $(PWD)/$(TMPDIR)/rpmbuild | |
232 | -endif | |
102 | + @LD_LIBRARY_PATH=$(BINDBG) $(BINDBG)/$(PACKAGE_TARNAME)@EXEEXT@ | |
233 | 103 | |
234 | -srpm: $(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.bz2 | |
235 | -ifneq ($(RPMBUILD),no) | |
236 | - @$(RPMBUILD) --define="_srcrpmdir $(PWD)" -bs $(PACKAGE_TARNAME).spec | |
237 | -endif | |
238 | - | |
239 | -package: Release | |
240 | -ifneq ($(MAKENSIS),no) | |
241 | - @chmod +x makegtkruntime.sh | |
242 | - @echo " GEN GTK Runtime" | |
243 | - @./makegtkruntime.sh | |
244 | - @echo " GEN Windows installer" | |
245 | - @cp -rv $(BINDIR)/Release/$(localedir) $(BINDIR)/Release | |
246 | - @make -C nsi package-no-gtk | |
247 | - @make -C nsi package | |
248 | -endif | |
104 | +#---[ Install Targets ]-------------------------------------------------------- | |
249 | 105 | |
250 | -ifneq ($(DPKGBUILD),no) | |
251 | - @rm -fr debian | |
252 | - @mkdir debian | |
253 | 106 | |
254 | - @echo 7 > debian/compat | |
255 | - @cp debian.control debian/control | |
256 | - @cp debian.rules debian/rules | |
257 | - @chmod +x debian/rules | |
107 | +#---[ Clean Targets ]---------------------------------------------------------- | |
258 | 108 | |
259 | - @EDITOR=true dch --preserve -v $(PACKAGE_VERSION)-$(PACKAGE_LEVEL) -u low --create --package $(PACKAGE_NAME) | |
260 | - @sed -i "s@UNRELEASED@unstable@;s@Initial release. (Closes: #XXXXXX)@SVN Revision $(PACKAGE_REVISION)@g" debian/changelog | |
109 | +cleanDebug: | |
110 | + | |
111 | + @$(MAKE) -C src/lib3270 cleanDebug | |
112 | + @$(MAKE) -C src/pw3270 cleanDebug | |
261 | 113 | |
262 | - @$(DPKGBUILD) -rfakeroot -uc -us | |
263 | -endif | |
114 | +cleanRelease: | |
264 | 115 | |
265 | -ifneq ($(MACBUNDLER),no) | |
266 | - @rm -fr .bin/pw3270.app | |
267 | - @$(MACBUNDLER) mac/pw3270.bundle | |
268 | -endif | |
116 | + @$(MAKE) -C src/lib3270 cleanRelease | |
117 | + @$(MAKE) -C src/pw3270 cleanRelease | |
269 | 118 | |
270 | 119 | |
271 | -$(PACKAGE_NAME).po: $(TMPDIR)/$(PACKAGE_NAME).pot | |
272 | - @echo " INIT `basename $@`" | |
273 | - @$(MSGINIT) --no-translator -o $@ --locale=en_US -i $^ | |
274 | - | |
275 | -$(BINDIR)/pot/ui.pot: $(XML2POT) $(wildcard ui/*.xml) | |
276 | - @echo " TEXT `basename $@`" | |
277 | - @$(MKDIR) `dirname $@` | |
278 | - @$(XML2POT) $(wildcard ui/*.xml) > $@ | |
279 | - | |
280 | -$(TMPDIR)/$(PACKAGE_NAME).pot: \ | |
281 | - $(BINDIR)/pot/pw3270.pot \ | |
282 | - $(BINDIR)/pot/lib3270.pot \ | |
283 | - $(BINDIR)/pot/ui.pot | |
284 | - | |
285 | - @echo " TEXT `basename $@`" | |
286 | - @$(MKDIR) `dirname $@` | |
287 | - @$(MSGCAT) --sort-output $^ | sed "s&VERSION&$(PACKAGE_VERSION)&;s&CHARSET&UTF-8&;s&PACKAGE&$(PACKAGE_NAME)&g" > $@ | |
288 | - | |
289 | -pixmaps: src/pw3270/$(PACKAGE_NAME).png src/pw3270/$(PACKAGE_NAME)-logo.png | |
290 | - | |
291 | -$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar: clean pixmaps | |
292 | - @rm -fr $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
293 | - @$(MKDIR) $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
294 | - @NOCONFIGURE=1 ./autogen.sh $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
295 | - @cp *.m4 $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
296 | - @cp revision $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
297 | - @cp ChangeLog $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
298 | - @cp colors.conf $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
299 | - @cp autogen.sh $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
300 | - @cp configure.ac $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
301 | -# @cp configure $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
302 | - @cp *.in $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
303 | - @cp AUTHORS LICENSE $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
304 | - @cp -r src $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
305 | - @cp -r scripts $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
306 | - @cp -r nsi $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
307 | - @cp $(PACKAGE_TARNAME).spec $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
308 | - | |
309 | - @cp debian.* $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
310 | - @cp makedeb.sh $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
311 | - | |
312 | - @$(MKDIR) $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/ui | |
313 | - @cp ui/* $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/ui | |
314 | - | |
315 | - @$(MKDIR) $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/debian | |
316 | - | |
317 | - @$(MKDIR) $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/po | |
318 | - @cp po/*.po $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/po | |
319 | - | |
320 | - @$(MKDIR) $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/man | |
321 | - @cp -r man/* $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/man | |
322 | - | |
323 | - @$(MKDIR) $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/mac | |
324 | - @cp -r mac/* $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/mac | |
325 | - | |
326 | - @$(AMTAR) --format=ustar --verbose --exclude-backups --exclude="*.bak" --create --directory $(TMPDIR) --exclude-vcs --owner=root --group=root --file=$@ $(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
327 | - | |
328 | - @rm -fr $(TMPDIR)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | |
329 | - @echo $@ | |
330 | - | |
331 | -install: $(foreach EXT, sdk lib app man plugins $(EXTENSIONS), install-$(EXT)) | |
332 | - | |
333 | -install-app: \ | |
334 | - $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) \ | |
335 | - install-locale | |
336 | - | |
337 | - @$(MAKE) BINDIR="../../$(BINDIR)" LIB3270_LIBS="$(RLSLIB)" LIB3270_CFLAGS="-I../../src/include" -C src/pw3270 install | |
338 | - @$(MKDIR) $(DESTDIR)$(datarootdir)/$(PACKAGE_NAME)/ui | |
339 | - @$(INSTALL_DATA) colors.conf $(DESTDIR)$(datarootdir)/$(PACKAGE_NAME) | |
340 | - @$(INSTALL_DATA) ui/*.xml $(DESTDIR)$(datarootdir)/$(PACKAGE_NAME)/ui | |
341 | - | |
342 | -install-plugins: \ | |
343 | - $(foreach PLUGIN, $(PLUGINS), $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins/$(PLUGIN)@DLLEXT@) | |
344 | - | |
345 | -install-lib: $(BINDIR)/Release@DLLDIR@/lib3270@DLLEXT@ | |
346 | - @$(MAKE) BINRLS="../../.bin/Release@DLLDIR@" -C src/lib3270 install | |
347 | - | |
348 | -install-classlib: | |
349 | - @$(MAKE) BINRLS="../../.bin/Release" -C src/classlib install | |
350 | - | |
351 | -locale: $(foreach MO, $(basename $(LANG_FILES)), $(BINDIR)/Release/$(localedir)/$(notdir $(MO))/LC_MESSAGES/$(PACKAGE_NAME).mo) | |
352 | - | |
353 | -install-locale: $(foreach MO, $(basename $(LANG_FILES)), $(BINDIR)/Release/$(localedir)/$(notdir $(MO))/LC_MESSAGES/$(PACKAGE_NAME).mo) | |
354 | - @echo -e $(foreach MO, $(notdir $(basename $(LANG_FILES))), mkdir -p $(DESTDIR)/$(localedir)/$(MO)/LC_MESSAGES\\n$(INSTALL_DATA) $(BINDIR)/Release/$(localedir)/$(MO)/LC_MESSAGES/$(PACKAGE_NAME).mo $(DESTDIR)/$(localedir)/$(MO)/LC_MESSAGES/$(PACKAGE_NAME).mo \\n ) | $(SHELL) | |
355 | - | |
356 | -install-man: | |
357 | - @$(MKDIR) $(DESTDIR)$(mandir)/man1 | |
358 | - @$(INSTALL_DATA) man/man1/pw3270.1 $(DESTDIR)/$(mandir)/man1/pw3270.1 | |
359 | - @$(MKDIR) $(DESTDIR)$(mandir)/man5 | |
360 | - @$(INSTALL_DATA) man/man5/pw3270.5 $(DESTDIR)/$(mandir)/man5/pw3270.5 | |
361 | - | |
362 | -install-sdk: | |
363 | - | |
364 | - @$(MKDIR) $(DESTDIR)$(includedir)/lib3270 | |
365 | - @$(INSTALL_DATA) src/include/lib3270.h $(DESTDIR)/$(includedir) | |
366 | - @$(INSTALL_DATA) src/include/lib3270/config.h $(DESTDIR)/$(includedir)/lib3270 | |
367 | - @$(INSTALL_DATA) src/include/lib3270/selection.h $(DESTDIR)/$(includedir)/lib3270 | |
368 | - @$(INSTALL_DATA) src/include/lib3270/popup.h $(DESTDIR)/$(includedir)/lib3270 | |
369 | - @$(INSTALL_DATA) src/include/lib3270/actions.h $(DESTDIR)/$(includedir)/lib3270 | |
370 | - @$(INSTALL_DATA) src/include/lib3270/action_table.h $(DESTDIR)/$(includedir)/lib3270 | |
371 | - @$(INSTALL_DATA) src/include/lib3270/trace.h $(DESTDIR)/$(includedir)/lib3270 | |
372 | - @$(INSTALL_DATA) src/include/lib3270/charset.h $(DESTDIR)/$(includedir)/lib3270 | |
373 | - @$(INSTALL_DATA) src/include/lib3270/filetransfer.h $(DESTDIR)/$(includedir)/lib3270 | |
374 | - @$(INSTALL_DATA) src/include/lib3270/log.h $(DESTDIR)/$(includedir)/lib3270 | |
375 | - @$(INSTALL_DATA) src/include/lib3270/session.h $(DESTDIR)/$(includedir)/lib3270 | |
376 | - | |
377 | - @$(MKDIR) $(DESTDIR)$(includedir)/pw3270 | |
378 | - @$(INSTALL_DATA) src/pw3270/include/*.h $(DESTDIR)/$(includedir)/pw3270 | |
379 | - | |
380 | - @$(INSTALL_DATA) src/include/pw3270/trace.h $(DESTDIR)/$(includedir)/pw3270 | |
381 | - @$(INSTALL_DATA) src/include/pw3270/plugin.h $(DESTDIR)/$(includedir)/pw3270 | |
382 | - @$(INSTALL_DATA) src/include/pw3270.h $(DESTDIR)/$(includedir) | |
383 | - | |
384 | - @$(MKDIR) $(DESTDIR)/$(libdir)/pkgconfig | |
385 | - @$(INSTALL_DATA) lib3270.pc $(DESTDIR)/$(libdir)/pkgconfig | |
386 | - @$(INSTALL_DATA) pw3270.pc $(DESTDIR)/$(libdir)/pkgconfig | |
387 | - | |
388 | - @$(MKDIR) $(DESTDIR)$(datarootdir)/$(PACKAGE_NAME)/sample | |
389 | - @$(INSTALL_DATA) src/sample/Makefile $(DESTDIR)$(datarootdir)/$(PACKAGE_NAME)/sample | |
390 | - @$(INSTALL_DATA) src/sample/sample.cbp $(DESTDIR)$(datarootdir)/$(PACKAGE_NAME)/sample | |
391 | - @$(INSTALL_DATA) src/sample/*.c $(DESTDIR)$(datarootdir)/$(PACKAGE_NAME)/sample | |
392 | - | |
393 | - @$(MAKE) -C src/classlib install-sdk | |
394 | - | |
395 | -install-oxt: | |
396 | - @$(MAKE) BINDIR=../../.bin LIB3270_CFLAGS="-I../../src/include" -C src/loffice install | |
397 | - | |
398 | -install-php: | |
399 | - @$(MAKE) -C src/php install | |
400 | - | |
401 | -install-python: | |
402 | - @$(MAKE) -C src/python install | |
403 | - | |
404 | -install-java: | |
405 | - @$(MAKE) BINDIR=../../.bin LIB3270_CFLAGS="-I../../src/include" -C src/java install | |
120 | +clean: \ | |
121 | + cleanDebug \ | |
122 | + cleanRelease | |
406 | 123 | |
407 | -install-rexx: | |
408 | - @$(MAKE) BINDIR=../../../.bin LIB3270_CFLAGS="-I../../src/include" -C src/plugins/rx3270 install | |
124 | + @rm -fr $(BINDIR) | |
409 | 125 | |
410 | -clean: | |
411 | - @rm -fr .obj | |
412 | - @rm -fr .bin | |
413 | - @rm -fr .tmp | |
414 | - @find . -type d -name .obj -exec echo rm -fr {} \; | sh | |
415 | - @find . -type d -name .bin -exec echo rm -fr {} \; | sh | |
416 | - @rm -f $(PACKAGE_NAME).po | |
417 | - @make -C src/lib3270 clean | |
418 | - @make -C src/pw3270 clean | |
419 | - @make -C src/tools clean | |
420 | - @make -C src/classlib clean | |
421 | - @rm -f $(PACKAGE_NAME).png | |
422 | - @rm -f $(PACKAGE_NAME)-logo.png | |
423 | - @rm -f *.log | |
424 | - @echo "$@" | |
425 | 126 | |
426 | -cleanDebug: clean | |
427 | - @echo "$@" | |
428 | - | |
429 | -distclean: clean | |
430 | - @make -C src/pw3270 distclean | |
431 | - @rm -f src/pw3270/Makefile | |
432 | - @rm -f config.status | |
433 | - @rm -f src/lib3270/mkversion.sh | |
434 | - @rm -f src/lib3270/Makefile | |
435 | - @rm -f src/include/lib3270/config.h | |
436 | - @rm -f src/pw3270/uiparser/Makefile | |
437 | - @rm -fr autom4te.cache | |
438 | - @rm -f *.pc | |
439 | - @rm -f $(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar* | |
440 | - @find ./src -name "Makefile" -exec rm -f {} \; | |
441 | - | |
442 | - @rm -f Makefile | |
443 | - @echo "$@" | |
444 | - | |
445 | -#---[ Plugins ]---------------------------------------------------------------- | |
446 | - | |
447 | -$(BINDIR)/Debug/plugins/hllapi@DLLEXT@: src/plugins/hllapi/* $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) | |
448 | - @make $(PLUGIN_DEBUG_ARGS) -C $(dir $<) Debug | |
449 | - | |
450 | -$(BINDIR)/Release/plugins/hllapi@DLLEXT@: src/plugins/hllapi/* $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) | |
451 | - @make $(PLUGIN_RELEASE_ARGS) -C $(dir $<) Release | |
452 | - | |
453 | -$(BINDIR)/Debug/plugins/rx3270@DLLEXT@: src/plugins/rx3270/* $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) | |
454 | - @make $(PLUGIN_DEBUG_ARGS) -C $(dir $<) Debug | |
455 | - | |
456 | -$(BINDIR)/Release/plugins/rx3270@DLLEXT@: src/plugins/rx3270/* $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) | |
457 | - @make $(PLUGIN_RELEASE_ARGS) -C $(dir $<) Release | |
458 | - | |
459 | -$(BINDIR)/Debug/plugins/dbus3270@DLLEXT@: src/plugins/dbus3270/* $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) | |
460 | - @make $(PLUGIN_DEBUG_ARGS) -C $(dir $<) Debug | |
461 | - | |
462 | -$(BINDIR)/Release/plugins/dbus3270@DLLEXT@: src/plugins/dbus3270/* $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) | |
463 | - @make $(PLUGIN_RELEASE_ARGS) -C $(dir $<) Release | ... | ... |
configure.ac
... | ... | @@ -330,7 +330,7 @@ AC_CONFIG_FILES(src/pw3270/v3270ft/Makefile) |
330 | 330 | AC_CONFIG_FILES(src/pw3270/uiparser/Makefile) |
331 | 331 | AC_CONFIG_FILES(src/pw3270/common/Makefile) |
332 | 332 | |
333 | -dnl AC_CONFIG_FILES(Makefile) | |
333 | +AC_CONFIG_FILES(Makefile) | |
334 | 334 | |
335 | 335 | dnl --------------------------------------------------------------------------- |
336 | 336 | dnl Output the generated config.status script. | ... | ... |
src/classlib/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/classlib/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/classlib/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/classlib/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/classlib/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/classlib/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/classlib/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/classlib/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/classlib/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/classlib/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 | - |
src/pw3270/Makefile.in
... | ... | @@ -0,0 +1,161 @@ |
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 | + | ... | ... |
... | ... | @@ -0,0 +1,50 @@ |
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 | + | ... | ... |
... | ... | @@ -0,0 +1,49 @@ |
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> | ... | ... |
... | ... | @@ -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 <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 | ... | ... |
... | ... | @@ -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,698 @@ |
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 | + | ... | ... |
... | ... | @@ -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 | + | ... | ... |