diff --git a/Makefile.in b/Makefile.in index 70bedba..076b5cd 100644 --- a/Makefile.in +++ b/Makefile.in @@ -326,7 +326,7 @@ clean: @make -C src/lib3270 clean @make -C src/pw3270 clean @make -C src/tools clean - @make -C src/plugins/remotectl clean + @make -C src/plugins/hllapi clean @make -C src/plugins/rx3270 clean @make -C src/plugins/dbus3270 clean @make -C src/oxt clean @@ -356,10 +356,10 @@ distclean: clean #---[ Plugins ]---------------------------------------------------------------- -$(BINDIR)/Debug/plugins/remotectl@DLLEXT@: src/plugins/remotectl/* $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) +$(BINDIR)/Debug/plugins/hllapi@DLLEXT@: src/plugins/hllapi/* $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) @make $(PLUGIN_DEBUG_ARGS) -C $(dir $<) Debug -$(BINDIR)/Release/plugins/remotectl@DLLEXT@: src/plugins/remotectl/* $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) +$(BINDIR)/Release/plugins/hllapi@DLLEXT@: src/plugins/hllapi/* $(BINDIR)/Release/$(PACKAGE_TARNAME)$(EXEEXT) @make $(PLUGIN_RELEASE_ARGS) -C $(dir $<) Release $(BINDIR)/Debug/plugins/rx3270@DLLEXT@: src/plugins/rx3270/* $(BINDIR)/Debug/$(PACKAGE_TARNAME)$(EXEEXT) diff --git a/configure.ac b/configure.ac index 55f0e28..28f91de 100644 --- a/configure.ac +++ b/configure.ac @@ -128,7 +128,7 @@ case "$host" in DLLDIR="" DBGCMDPREFIX="" LDARCH="" - PLUGINS="remotectl" + PLUGINS="hllapi" APP_GUI_SRC="resources.rc" ;; @@ -433,7 +433,7 @@ AC_CONFIG_FILES([ src/oxt/Makefile src/pw3270/uiparser/Makefile src/tools/Makefile - src/plugins/remotectl/Makefile + src/plugins/hllapi/Makefile src/plugins/rx3270/Makefile src/plugins/dbus3270/Makefile man/Makefile diff --git a/po/pt_BR.po b/po/pt_BR.po index 7ea36d7..0b447ac 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: pw3270 5.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-03-04 18:26-0300\n" +"POT-Creation-Date: 2013-03-06 09:33-0300\n" "PO-Revision-Date: 2013-02-25 14:46-0300\n" "Last-Translator: Perry Werneck \n" "Language-Team: Português <>\n" @@ -91,11 +91,11 @@ msgstr "- Emulador 3270 para GTK" msgid "16 colors" msgstr "16 cores" -#: screen.c:653 screen.c:683 screen.c:697 screen.c:816 +#: screen.c:655 screen.c:685 screen.c:699 screen.c:818 msgid "3270 Error" msgstr "Erro 3270" -#: screen.c:668 +#: screen.c:670 msgid "3270 Warning" msgstr "Alerta 3270" @@ -200,7 +200,7 @@ msgstr "Sobre a segurança" msgid "Action failed" msgstr "Ação falhou" -#: ui/00default.xml:64 +#: ui/00default.xml:286 msgid "Add to copy" msgstr "Adicionar à cópia" @@ -208,7 +208,7 @@ msgstr "Adicionar à cópia" msgid "Add/Remove _CR at end of line" msgstr "Adicionar/Remover _CR no final da linha" -#: ui/00default.xml:132 +#: ui/00default.xml:354 msgid "Alert sound" msgstr "Aviso sonoro" @@ -221,7 +221,7 @@ msgstr "" msgid "Application name" msgstr "Nome da aplicação" -#: ui/10keypad.xml:467 +#: ui/10keypad.xml:155 msgid "Attn" msgstr "Attn" @@ -238,7 +238,7 @@ msgstr "Authority and issuer serial number mismatch" msgid "Authority and subject key identifier mismatch" msgstr "Authority and subject key identifier mismatch" -#: ui/00default.xml:127 +#: ui/00default.xml:349 msgid "Auto-Reconnect" msgstr "Reconectar automaticamente" @@ -262,11 +262,11 @@ msgstr "Versão winsock inválida" msgid "Black" msgstr "Preto" -#: ui/00default.xml:125 +#: ui/00default.xml:347 msgid "Blank Fill" msgstr "Completar com espaços" -#: ui/00default.xml:118 +#: ui/00default.xml:340 msgid "Blinking Cursor" msgstr "Cursor piscante" @@ -274,7 +274,7 @@ msgstr "Cursor piscante" msgid "Blue" msgstr "Azul" -#: ui/00default.xml:128 +#: ui/00default.xml:350 msgid "Bold" msgstr "Negrito" @@ -282,7 +282,7 @@ msgstr "Negrito" msgid "Brazilian Public Software Portal" msgstr "Portal do Software Público Brasileiro" -#: ui/10keypad.xml:468 +#: ui/10keypad.xml:156 msgid "Break" msgstr "Break" @@ -474,7 +474,7 @@ msgstr "Tabela de tradução tem %d entradas, precisa de 256" msgid "Charset has more than 256 entries" msgstr "Tabela de tradução tem mais de 256 caracteres" -#: ui/00default.xml:79 +#: ui/10keypad.xml:147 msgid "Clear" msgstr "Limpar" @@ -486,7 +486,7 @@ msgstr "Tema de cores:" msgid "Color setup" msgstr "Configuração de cores" -#: ui/00default.xml:107 +#: ui/00default.xml:329 msgid "Colors" msgstr "Cores" @@ -494,7 +494,7 @@ msgstr "Cores" msgid "Complete" msgstr "Completo" -#: ui/00default.xml:117 +#: ui/00default.xml:339 msgid "Connect on startup" msgstr "Conectar ao iniciar" @@ -502,19 +502,19 @@ msgstr "Conectar ao iniciar" msgid "Connection reset by peer" msgstr "Conexão foi cancelada pelo servidor" -#: ui/00default.xml:61 +#: ui/00default.xml:283 msgid "Copy" msgstr "Copiar" -#: ui/99debug.xml:566 +#: ui/99debug.xml:200 msgid "Copy as HTML" msgstr "Copiar como HTML" -#: ui/00default.xml:62 +#: ui/00default.xml:284 msgid "Copy as table" msgstr "Copiar como tabela" -#: colors.c:418 ui/00default.xml:124 +#: colors.c:418 ui/00default.xml:346 msgid "Cross hair cursor" msgstr "Cursor mira" @@ -527,7 +527,7 @@ msgstr "Atual (%s)" msgid "Custom colors" msgstr "Cores personalizadas" -#: ui/00default.xml:65 +#: ui/00default.xml:287 msgid "Cut" msgstr "Recortar" @@ -539,7 +539,7 @@ msgstr "Cilindros" msgid "DFT B_uffer size:" msgstr "Tamanho do b_uffer DFT:" -#: ui/99debug.xml:571 +#: ui/99debug.xml:205 msgid "DS Trace" msgstr "DS Trace" @@ -555,11 +555,11 @@ msgstr "Verde Escuro" msgid "Data conversion error" msgstr "Erro na conversão de dados" -#: ui/99debug.xml:579 +#: ui/99debug.xml:213 msgid "Debug" msgstr "Depuração" -#: ui/99debug.xml:581 +#: ui/99debug.xml:215 msgid "Debug window updates" msgstr "Mostrar atualizações de janela" @@ -567,7 +567,7 @@ msgstr "Mostrar atualizações de janela" msgid "Default" msgstr "Padrão" -#: ui/00default.xml:81 +#: ui/00default.xml:303 msgid "Delete field" msgstr "Apagar campo" @@ -599,7 +599,7 @@ msgstr "Nome do servidor em branco" msgid "Empty port name" msgstr "Porta em branco" -#: ui/10keypad.xml:463 +#: ui/10keypad.xml:151 msgid "" "Erase\n" "EOF" @@ -607,7 +607,7 @@ msgstr "" "Apagar\n" "Campo" -#: ui/10keypad.xml:464 +#: ui/10keypad.xml:152 msgid "" "Erase\n" "Input" @@ -615,15 +615,15 @@ msgstr "" "Apagar\n" "Campos" -#: ui/00default.xml:80 +#: ui/00default.xml:302 msgid "Erase input" msgstr "Apagar campos" -#: ui/00default.xml:82 +#: ui/00default.xml:304 msgid "Erase to end of field" msgstr "Apagar até o final do campo" -#: ui/00default.xml:83 +#: ui/00default.xml:305 msgid "Erase to end of line" msgstr "Apagar até o final da linha" @@ -666,7 +666,7 @@ msgstr "Erro lendo %s" msgid "Error resolving %s: %s" msgstr "Erro ao resolver %s: %s" -#: ui/99debug.xml:573 +#: ui/99debug.xml:207 msgid "Event Trace" msgstr "Trace de eventos" @@ -714,11 +714,11 @@ msgstr "Format error in certificate's notAfter field" msgid "Format error in certificate's notBefore field" msgstr "Format error in certificate's notBefore field" -#: ui/00default.xml:121 +#: ui/00default.xml:343 msgid "Full Screen" msgstr "Tela cheia" -#: ui/10functions.xml:347 +#: ui/10functions.xml:35 msgid "Function bar" msgstr "Barra de funções" @@ -763,7 +763,7 @@ msgstr "HTTP Proxy: EOF inesperado" msgid "HTTP Proxy: unrecognized reply" msgstr "HTTP Proxy: Resposta desconhecida" -#: ui/00default.xml:142 +#: ui/00default.xml:364 msgid "Help" msgstr "Ajuda" @@ -824,7 +824,7 @@ msgstr "Comprimento de frame inválido" msgid "Informations" msgstr "Informações" -#: ui/00default.xml:137 +#: ui/00default.xml:359 msgid "Input method" msgstr "Método de entrada" @@ -871,7 +871,7 @@ msgstr "Sintaxe de proxy inválida" msgid "Invalid proxy type '%.*s'" msgstr "Tipo de proxy invalido '%.*s'" -#: ui/00default.xml:130 +#: ui/00default.xml:352 msgid "Keep selected" msgstr "Manter selecionado" @@ -887,7 +887,7 @@ msgstr "Teclado está bloqueado" msgid "LRECL:" msgstr "LRECL:" -#: ui/10keypad.xml:413 +#: ui/10keypad.xml:101 msgid "Lateral keypad" msgstr "Barra lateral" @@ -904,7 +904,7 @@ msgstr "Faltando ']'" msgid "Model %d (%s)" msgstr "Modelo %d (%s)" -#: ui/00default.xml:119 +#: ui/00default.xml:341 msgid "Monocase" msgstr "Só Maiúsculas" @@ -940,7 +940,7 @@ msgstr "Erro de rede" msgid "Network startup error" msgstr "Erro ao iniciar a rede" -#: ui/00default.xml:189 +#: ui/00default.xml:411 msgid "Next field" msgstr "Próximo campo" @@ -1017,111 +1017,111 @@ msgstr "Other (VM/CMS)" msgid "Out of memory" msgstr "Out of memory" -#: ui/10keypad.xml:450 +#: ui/10keypad.xml:138 msgid "PA1" msgstr "PA1" -#: ui/10keypad.xml:451 +#: ui/10keypad.xml:139 msgid "PA2" msgstr "PA2" -#: ui/10keypad.xml:452 +#: ui/10keypad.xml:140 msgid "PA3" msgstr "PA3" -#: ui/10functions.xml:348 +#: ui/10functions.xml:36 msgid "PF1" msgstr "PF1" -#: ui/10functions.xml:357 +#: ui/10functions.xml:45 msgid "PF10" msgstr "PF10" -#: ui/10functions.xml:358 +#: ui/10functions.xml:46 msgid "PF11" msgstr "PF11" -#: ui/10functions.xml:359 +#: ui/10functions.xml:47 msgid "PF12" msgstr "PF12" -#: ui/10functions.xml:362 +#: ui/10functions.xml:50 msgid "PF13" msgstr "PF13" -#: ui/10functions.xml:363 +#: ui/10functions.xml:51 msgid "PF14" msgstr "PF14" -#: ui/10functions.xml:364 +#: ui/10functions.xml:52 msgid "PF15" msgstr "PF15" -#: ui/10functions.xml:365 +#: ui/10functions.xml:53 msgid "PF16" msgstr "PF16" -#: ui/10functions.xml:366 +#: ui/10functions.xml:54 msgid "PF17" msgstr "PF17" -#: ui/10functions.xml:367 +#: ui/10functions.xml:55 msgid "PF18" msgstr "PF18" -#: ui/10functions.xml:368 +#: ui/10functions.xml:56 msgid "PF19" msgstr "PF19" -#: ui/10functions.xml:349 +#: ui/10functions.xml:37 msgid "PF2" msgstr "PF2" -#: ui/10functions.xml:369 +#: ui/10functions.xml:57 msgid "PF20" msgstr "PF20" -#: ui/10functions.xml:370 +#: ui/10functions.xml:58 msgid "PF21" msgstr "PF21" -#: ui/10functions.xml:371 +#: ui/10functions.xml:59 msgid "PF22" msgstr "PF22" -#: ui/10functions.xml:372 +#: ui/10functions.xml:60 msgid "PF23" msgstr "PF23" -#: ui/10functions.xml:373 +#: ui/10functions.xml:61 msgid "PF24" msgstr "PF24" -#: ui/10functions.xml:350 +#: ui/10functions.xml:38 msgid "PF3" msgstr "PF3" -#: ui/10functions.xml:351 +#: ui/10functions.xml:39 msgid "PF4" msgstr "PF4" -#: ui/10functions.xml:352 +#: ui/10functions.xml:40 msgid "PF5" msgstr "PF5" -#: ui/10functions.xml:353 +#: ui/10functions.xml:41 msgid "PF6" msgstr "PF6" -#: ui/10functions.xml:354 +#: ui/10functions.xml:42 msgid "PF7" msgstr "PF7" -#: ui/10functions.xml:355 +#: ui/10functions.xml:43 msgid "PF8" msgstr "PF8" -#: ui/10functions.xml:356 +#: ui/10functions.xml:44 msgid "PF9" msgstr "PF9" @@ -1138,15 +1138,15 @@ msgstr "Erro de interpretação em %s" msgid "Passthru Proxy: send error" msgstr "Passthru Proxy: Erro ao enviar" -#: ui/00default.xml:66 +#: ui/00default.xml:288 msgid "Paste" msgstr "Colar" -#: ui/00default.xml:67 +#: ui/00default.xml:289 msgid "Paste next" msgstr "Colar próximo" -#: ui/00default.xml:70 +#: ui/00default.xml:292 msgid "Paste text file" msgstr "Colar arquivo texto" @@ -1154,7 +1154,7 @@ msgstr "Colar arquivo texto" msgid "Paste text file contents" msgstr "Colar conteúdo de arquivo texto" -#: ui/00default.xml:123 +#: ui/00default.xml:345 msgid "Paste with left margin" msgstr "Colar com margem esquerda" @@ -1170,7 +1170,7 @@ msgstr "Path to application data files" msgid "Pink" msgstr "Rosa" -#: ui/00default.xml:188 +#: ui/00default.xml:410 msgid "Previous field" msgstr "Campo anterior" @@ -1178,11 +1178,11 @@ msgstr "Campo anterior" msgid "Primary space:" msgstr "Primary space:" -#: ui/00default.xml:49 +#: ui/00default.xml:271 msgid "Print" msgstr "Imprimir" -#: ui/00default.xml:51 +#: ui/00default.xml:273 msgid "Print copy" msgstr "Imprimir cópia" @@ -1190,7 +1190,7 @@ msgstr "Imprimir cópia" msgid "Print operation failed" msgstr "Operação de impressão falhou" -#: ui/00default.xml:50 +#: ui/00default.xml:272 msgid "Print selected" msgstr "Imprimir seleção" @@ -1198,7 +1198,7 @@ msgstr "Imprimir seleção" msgid "Print selection box" msgstr "Imprimir marca de seleção" -#: print.c:743 ui/00default.xml:108 +#: print.c:743 ui/00default.xml:330 msgid "Print settings" msgstr "Configurações de impressão" @@ -1286,7 +1286,7 @@ msgstr "RPQ: can't resolve '%s': %s" msgid "RPQ: gethostbyname error" msgstr "RPQ: Erro em gethostbyname" -#: ui/00default.xml:54 +#: ui/00default.xml:276 msgid "Receive file" msgstr "Receber arquivo" @@ -1302,27 +1302,27 @@ msgstr "Formato de registro" msgid "Red" msgstr "Vermelho" -#: ui/99debug.xml:580 +#: ui/99debug.xml:214 msgid "Reload buffer contents" msgstr "Recarregar conteúdo do buffer" -#: ui/00default.xml:75 +#: ui/00default.xml:297 msgid "Remove selection" msgstr "Remover seleção" -#: ui/00default.xml:76 +#: ui/00default.xml:298 msgid "Reselect" msgstr "Reselecionar" -#: ui/10keypad.xml:460 +#: ui/10keypad.xml:148 msgid "Reset" msgstr "Reset" -#: ui/00default.xml:122 +#: ui/00default.xml:344 msgid "Resize on alternate screen" msgstr "Mudar tamanho do terminal em tela alternativa" -#: ui/00default.xml:190 +#: ui/00default.xml:412 msgid "Return" msgstr "Return" @@ -1483,7 +1483,7 @@ msgstr "" "SSL_write:\n" "%s" -#: ui/00default.xml:46 +#: ui/00default.xml:268 msgid "Save copy" msgstr "Salvar cópia" @@ -1491,7 +1491,7 @@ msgstr "Salvar cópia" msgid "Save copy to file" msgstr "Salvar cópia para arquivo" -#: ui/00default.xml:44 +#: ui/00default.xml:266 msgid "Save screen" msgstr "Salvar tela" @@ -1499,7 +1499,7 @@ msgstr "Salvar tela" msgid "Save screen to file" msgstr "Salvar tela para arquivo" -#: ui/00default.xml:45 +#: ui/00default.xml:267 msgid "Save selected" msgstr "Salvar seleção" @@ -1507,20 +1507,15 @@ msgstr "Salvar seleção" msgid "Save selection to file" msgstr "Salvar seleção para arquivo" -#: ui/99debug.xml:572 +#: ui/99debug.xml:206 msgid "Screen Trace" msgstr "Trace de tela" -#: ui/00default.xml:114 +#: ui/00default.xml:336 msgid "Screen size" msgstr "Tamanho da tela" -#: ui/09scripts.xml:297 -#, fuzzy -msgid "Script" -msgstr "Scripts" - -#: ui/00default.xml:89 +#: ui/00default.xml:311 msgid "Scripts" msgstr "Scripts" @@ -1532,15 +1527,15 @@ msgstr "Secondary space:" msgid "Secure connection was successful." msgstr "Conexão segura efetuada com sucesso." -#: ui/00default.xml:74 +#: ui/00default.xml:296 msgid "Select Field" msgstr "Selecionar campo" -#: ui/00default.xml:73 +#: ui/00default.xml:295 msgid "Select all" msgstr "Selecionar tudo" -#: ui/00default.xml:126 +#: ui/00default.xml:348 msgid "Select by rectangles" msgstr "Seleção retangular" @@ -1552,7 +1547,7 @@ msgstr "Selecione arquivo a receber" msgid "Select file to send" msgstr "Selecione arquivo a enviar" -#: ui/00default.xml:111 +#: ui/00default.xml:333 msgid "Select font" msgstr "Selecione fonte" @@ -1576,7 +1571,7 @@ msgstr "Self signed certificate" msgid "Self signed certificate in certificate chain" msgstr "Self signed certificate in certificate chain" -#: ui/00default.xml:55 +#: ui/00default.xml:277 msgid "Send file" msgstr "Enviar arquivo" @@ -1588,7 +1583,7 @@ msgstr "Enviar arquivo para o servidor" msgid "Send messages to syslog" msgstr "Send messages to syslog" -#: ui/00default.xml:54 +#: ui/00default.xml:276 msgid "Send/Receive" msgstr "Enviar/Receber" @@ -1596,7 +1591,7 @@ msgstr "Enviar/Receber" msgid "Session name" msgstr "Nome da sessão" -#: ui/00default.xml:92 +#: ui/00default.xml:314 msgid "Set hostname" msgstr "Selecione servidor" @@ -1604,19 +1599,19 @@ msgstr "Selecione servidor" msgid "Set reported colors (8/16)" msgstr "Define número de cores informadas (8/16)" -#: ui/00default.xml:107 +#: ui/00default.xml:329 msgid "Settings" msgstr "Configurações" -#: ui/00default.xml:129 +#: ui/00default.xml:351 msgid "Show Underline" msgstr "Mostrar sublinhado" -#: ui/99debug.xml:579 +#: ui/99debug.xml:213 msgid "Show test pattern" msgstr "Mostrar padrão de teste" -#: ui/00default.xml:131 +#: ui/00default.xml:353 msgid "Smart paste" msgstr "Colar inteligente" @@ -1664,18 +1659,6 @@ msgstr "T_otal" msgid "Terminal colors" msgstr "Cores do terminal" -#: ui/09scripts.xml:298 -msgid "Teste01" -msgstr "Teste01" - -#: ui/09scripts.xml:302 -msgid "Teste02" -msgstr "Teste02" - -#: ui/09scripts.xml:306 -msgid "Teste03" -msgstr "Teste03" - #: host.c:216 msgid "Text before '['" msgstr "Texto antes de '['" @@ -1902,15 +1885,15 @@ msgid "" "This version of %s was built without support for secure sockets layer (SSL)." msgstr "Esta versão do %s foi gerada sem suporte para conexões seguras (SSL)." -#: ui/00default.xml:148 +#: ui/00default.xml:370 msgid "Toolbar" msgstr "Barra de ferramentas" -#: ui/99debug.xml:571 +#: ui/99debug.xml:205 msgid "Trace" msgstr "Trace" -#: ui/00default.xml:120 +#: ui/00default.xml:342 msgid "Track Cursor" msgstr "Mostrar posição do cursor" @@ -2117,7 +2100,7 @@ msgstr "Unsupported passthru host session" msgid "Unsupported socks 4 proxy" msgstr "Unsupported socks 4 proxy" -#: ui/00default.xml:133 +#: ui/00default.xml:355 msgid "Use +/- for field navigation" msgstr "Usar teclas +/- para navegar por campos" @@ -2130,7 +2113,7 @@ msgstr "Variável" msgid "Version %s - Revision %s" msgstr "Versão %s - Revisão %s" -#: ui/99debug.xml:574 +#: ui/99debug.xml:208 msgid "View Field Delimiters" msgstr "Mostrar delimitadores de campo" @@ -2158,7 +2141,7 @@ msgstr "Europa ocidental (ISO 8859-1)" msgid "White" msgstr "Branco" -#: ui/00default.xml:159 +#: ui/00default.xml:381 msgid "Window" msgstr "Janela" @@ -2226,19 +2209,19 @@ msgstr "_Procurar" msgid "_Color table:" msgstr "Tabela de cores:" -#: ui/00default.xml:102 +#: ui/00default.xml:324 msgid "_Connect" msgstr "_Conectar" -#: ui/00default.xml:103 +#: ui/00default.xml:325 msgid "_Disconnect" msgstr "_Desconectar" -#: ui/00default.xml:61 +#: ui/99debug.xml:200 msgid "_Edit" msgstr "_Editar" -#: ui/00default.xml:36 +#: ui/00default.xml:258 msgid "_File" msgstr "_Arquivo" @@ -2266,11 +2249,11 @@ msgstr "Nome do _Host:" msgid "_Local file name:" msgstr "Arquivo _local:" -#: ui/00default.xml:92 +#: ui/00default.xml:314 msgid "_Network" msgstr "_Rede" -#: ui/00default.xml:117 +#: ui/00default.xml:339 msgid "_Options" msgstr "_Opções" @@ -2298,7 +2281,7 @@ msgstr "Arquivo _texto" msgid "_To" msgstr "_Para" -#: ui/00default.xml:87 +#: ui/00default.xml:309 msgid "_View" msgstr "_Exibir" @@ -2345,6 +2328,19 @@ msgid "unknown error" msgstr "Erro desconhecido" #, fuzzy +#~ msgid "Script" +#~ msgstr "Scripts" + +#~ msgid "Teste01" +#~ msgstr "Teste01" + +#~ msgid "Teste02" +#~ msgstr "Teste02" + +#~ msgid "Teste03" +#~ msgstr "Teste03" + +#, fuzzy #~ msgid "Cross hair Cursor" #~ msgstr "Cursor mira" diff --git a/pw3270.cbp b/pw3270.cbp index a3092fd..79327ca 100644 --- a/pw3270.cbp +++ b/pw3270.cbp @@ -243,29 +243,34 @@ - - + + - - + + - - + + - + - + - - - + + + + + + + + diff --git a/pw3270.nsi.in b/pw3270.nsi.in index d5eca42..e81745b 100644 --- a/pw3270.nsi.in +++ b/pw3270.nsi.in @@ -117,7 +117,7 @@ SubSection "@PACKAGE@" SecMain setOutPath $INSTDIR CreateDirectory "$INSTDIR\plugins" - file "/oname=$INSTDIR\plugins\remotectl.dll" ".bin\Release\plugins\remotectl.dll" + file "/oname=$INSTDIR\plugins\hllapi.dll" ".bin\Release\plugins\hllapi.dll" file "/oname=$SYSDIR\libhllapi.dll" ".bin\Release\libhllapi.dll" sectionEnd diff --git a/src/include/pw3270/hllapi.h b/src/include/pw3270/hllapi.h index f93f9b3..efd55e1 100644 --- a/src/include/pw3270/hllapi.h +++ b/src/include/pw3270/hllapi.h @@ -81,13 +81,16 @@ extern "C" { __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD pos, LPSTR buffer, WORD len); __declspec (dllexport) DWORD __stdcall hllapi_enter(void); __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text); - __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text); + __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text); + __declspec (dllexport) DWORD __stdcall hllapi_emulate_input(LPSTR buffer, WORD len, WORD pasting); __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds); __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds); __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key); __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key); __declspec (dllexport) DWORD __stdcall hllapi_setcursor(WORD key); __declspec (dllexport) DWORD __stdcall hllapi_getcursor(); + __declspec (dllexport) DWORD __stdcall hllapi_erase_eof(void); + __declspec (dllexport) DWORD __stdcall hllapi_print(void); #else diff --git a/src/plugins/hllapi/Makefile.in b/src/plugins/hllapi/Makefile.in new file mode 100644 index 0000000..0f0c00b --- /dev/null +++ b/src/plugins/hllapi/Makefile.in @@ -0,0 +1,152 @@ +# +# "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 +# (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a +# aplicativos mainframe. Registro no INPI sob o nome G3270. +# +# Copyright (C) <2008> +# +# Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob +# os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela +# Free Software Foundation. +# +# Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER +# GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO +# A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para +# obter mais detalhes. +# +# Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este +# programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple +# Place, Suite 330, Boston, MA, 02111-1307, USA +# +# Contatos: +# +# perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) +# erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) +# licinio@bb.com.br (Licínio Luis Branco) +# kraucer@bb.com.br (Kraucer Fernandes Mazuco) +# + +#---[ Sources ]---------------------------------------------------------------- + +MODULE_NAME=hllapi +DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile +PLUGIN_SRC=pluginmain.c +HLLAPI_SRC=hllapi.c calls.c remote.c + +#---[ Paths ]------------------------------------------------------------------ + +ROOTDIR ?= . +OBJDIR ?= $(ROOTDIR)/.obj +BINDIR ?= $(ROOTDIR)/.bin +BINDBG ?= $(BINDIR)/Debug +BINRLS ?= $(BINDIR)/Release + +OBJDBG = $(OBJDIR)/Debug +OBJRLS = $(OBJDIR)/Release +OBJEXT = o + +#---[ Tools ]------------------------------------------------------------------ + +MKDIR=@MKDIR_P@ +CC=@CC@ +LD=@CC@ +MSGCAT=@MSGCAT@ +XGETTEXT=@XGETTEXT@ + +#---[ Rules ]------------------------------------------------------------------ + +DLL_FLAGS=@DLL_FLAGS@ +DEBUG_CFLAGS=-DDEBUG=1 -g -Wall + +LIB3270_MODE ?= Default + +ifeq ($(LIB3270_MODE),Debug) + PW3270_LIBS=-L../../../.bin/Debug@DLLDIR@ -lpw3270 -l3270 + PW3270_CFLAGS=-I../../../src/include + LIB3270_LIBS=-L../../../.bin/Debug@DLLDIR@ -l3270 + LIB3270_CFLAGS=-I../../../src/include +endif + +ifeq ($(LIB3270_MODE),Release) + PW3270_LIBS=-L../../../.bin/Release@DLLDIR@ -lpw3270 -l3270 + PW3270_CFLAGS=-I../../../src/include + LIB3270_LIBS=-L../../../.bin/Release@DLLDIR@ -l3270 + LIB3270_CFLAGS=-I../../../src/include +endif + +ifeq ($(LIB3270_MODE),Default) + LIB3270_LIBS ?= `pkg-config --libs lib3270` + LIB3270_CFLAGS ?= `pkg-config --cflags lib3270` + PW3270_LIBS ?= `pkg-config --libs pw3270 lib3270` + PW3270_CFLAGS ?= `pkg-config --cflags pw3270 lib3270` +endif + + +GTK_CFLAGS ?= @GTK_CFLAGS@ @GTKMAC_CFLAGS@ +GTK_LIBS ?= @GTK_LIBS@ @GTKMAC_LIBS@ + +$(OBJDBG)/%.o: %.c $(DEPENDS) + @echo " CC `basename $@`" + @$(MKDIR) `dirname $@` + @$(CC) $(CFLAGS) $(DEBUG_CFLAGS) $(LIB3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< + +$(OBJRLS)/%.o: %.c $(DEPENDS) + @echo " CC `basename $@`" + @$(MKDIR) `dirname $@` + @$(CC) $(CFLAGS) $(LIB3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< + + +#---[ Release targets ]-------------------------------------------------------- + +Release: $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ $(BINRLS)/libhllapi@DLLEXT@ + +$(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@: $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJRLS)/$(SRC).o) + @echo " CCLD `basename $@`" + @$(MKDIR) `dirname $@` + @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) -o $@ $^ $(LIBS) $(PW3270_LIBS) $(GTK_LIBS) + +$(BINRLS)/libhllapi@DLLEXT@: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJRLS)/$(SRC).o) + @echo " CCLD `basename $@`" + @$(MKDIR) `dirname $@` + @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) @LDLIBFLAGS@ -o $@ $^ $(LIBS) + +#---[ Debug targets ]---------------------------------------------------------- + +Debug: $(BINDBG)/plugins/$(MODULE_NAME)@DLLEXT@ $(BINDBG)/libhllapi@DLLEXT@ + +$(BINDBG)/plugins/$(MODULE_NAME)@DLLEXT@: $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJDBG)/$(SRC).o) + @echo " CCLD `basename $@`" + @$(MKDIR) `dirname $@` + @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) -o $@ $^ $(LIBS) $(PW3270_LIBS) $(GTK_LIBS) + +$(BINDBG)/libhllapi@DLLEXT@: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJDBG)/$(SRC).o) + @echo " CCLD `basename $@`" + @$(MKDIR) `dirname $@` + @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) @LDLIBFLAGS@ -o $@ $^ $(LIBS) + +#---[ Misc targets ]----------------------------------------------------------- + +$(BINDBG)/testprogram@EXEEXT@: testprogram.c $(BINDBG)/libhllapi@DLLEXT@ + @echo " CCLD `basename $@`" + @$(MKDIR) `dirname $@` + @$(CC) $(CFLAGS) $(PW3270_CFLAGS) -L$(BINDBG) $(DEBUG_CFLAGS) -lhllapi -o $@ testprogram.c + +test: $(BINDBG)/testprogram@EXEEXT@ + +run: $(BINDBG)/testprogram@EXEEXT@ + @cd $(BINDBG) ; ./testprogram@EXEEXT@ + +install: $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ + @$(MKDIR) $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins + @$(INSTALL_PROGRAM) $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins + +$(DEBDIR)/$(MODULE_NAME).install: Makefile + @$(MKDIR) `dirname $@` + @rm -f $@ + @echo $(libdir)/$(PACKAGE_NAME)-plugins/$(MODULE_NAME)@DLLEXT@ > $@ + +clean: + @rm -fr $(OBJDIR) + @rm -fr $(BINDIR) + @rm -f testprogram@EXEEXT@ + @find . -name "*~" -exec rm -f {} \; diff --git a/src/plugins/hllapi/calls.c b/src/plugins/hllapi/calls.c new file mode 100644 index 0000000..342b570 --- /dev/null +++ b/src/plugins/hllapi/calls.c @@ -0,0 +1,463 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como calls.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include + #include + #include + #include + #include + #include + #include + #include "client.h" + + #undef trace + #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } } + +/*--[ Globals ]--------------------------------------------------------------------------------------*/ + + HMODULE hModule = NULL; + void * hSession = NULL; + + static void * (*session_new)(const char *model) = NULL; + static void (*session_free)(void *h) = NULL; + static const char * (*get_revision)(void) = NULL; + static int (*host_connect)(void *h,const char *n, int wait) = NULL; + static int (*host_is_connected)(void *h) = NULL; + static int (*wait_for_ready)(void *h, int seconds) = NULL; + static void (*host_disconnect)(void *h) = NULL; + static int (*script_sleep)(void *h, int seconds) = NULL; + static LIB3270_MESSAGE (*get_message)(void *h) = NULL; + static char * (*get_text)(void *h, int row, int col, int len) = NULL; + static char * (*get_text_at_offset)(void *h, int offset, int len) = NULL; + + static void * (*release_memory)(void *p) = NULL; + static int (*action_enter)(void *h) = NULL; + static int (*set_text_at)(void *h, int row, int col, const unsigned char *str) = NULL; + static int (*cmp_text_at)(void *h, int row, int col, const char *text) = NULL; + static int (*pfkey)(void *hSession, int key) = NULL; + static int (*pakey)(void *hSession, int key) = NULL; + static int (*getcursor)(void *hSession) = NULL; + static int (*setcursor)(void *hSession, int baddr) = NULL; + static int (*emulate_input)(void *hSession, const char *s, int len, int pasting) = NULL; + static int (*erase_eof)(void *hSession) = NULL; + + static const struct _entry_point + { + void **call; + void * pipe; + const char * name; + } entry_point[] = + { + { (void **) &session_new, (void *) hllapi_pipe_init, "lib3270_session_new" }, + { (void **) &session_free, (void *) hllapi_pipe_deinit, "lib3270_session_free" }, + { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, + { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, + { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" }, + { (void **) &host_is_connected, (void *) hllapi_pipe_is_connected, "lib3270_in_tn3270e" }, + { (void **) &wait_for_ready, (void *) hllapi_pipe_wait_for_ready, "lib3270_wait_for_ready" }, + { (void **) &script_sleep, (void *) hllapi_pipe_sleep, "lib3270_wait" }, + { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, + { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, + { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, + { (void **) &action_enter, (void *) hllapi_pipe_enter, "lib3270_enter" }, + { (void **) &set_text_at, (void *) hllapi_pipe_set_text_at, "lib3270_set_string_at" }, + { (void **) &cmp_text_at, (void *) hllapi_pipe_cmp_text_at, "lib3270_cmp_text_at" }, + { (void **) &pfkey, (void *) hllapi_pipe_pfkey, "lib3270_pfkey" }, + { (void **) &pakey, (void *) hllapi_pipe_pakey, "lib3270_pakey" }, + { (void **) &setcursor, (void *) hllapi_pipe_setcursor, "lib3270_set_cursor_address" }, + { (void **) &getcursor, (void *) hllapi_pipe_getcursor, "lib3270_get_cursor_address" }, + { (void **) &get_text_at_offset, (void *) hllapi_pipe_get_text, "lib3270_get_text" }, + { (void **) &emulate_input, (void *) hllapi_pipe_emulate_input, "lib3270_emulate_input" }, + { (void **) &erase_eof, (void *) hllapi_pipe_erase_eof, "lib3270_eraseeof" }, + { NULL, NULL, NULL } + }; + +// http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx +#ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS + #define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000 +#endif // LOAD_LIBRARY_SEARCH_DEFAULT_DIRS + +#ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR + #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100 +#endif // LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode) + { + if(!mode) + return EINVAL; + + trace("%s(%s)",__FUNCTION__,(char *) mode); + + if(mode && *mode) + { + // Get pointers to the pipe based calls + int f; + + trace("%s: Loading pipe based calls",__FUNCTION__); + for(f=0;entry_point[f].name;f++) + *entry_point[f].call = entry_point[f].pipe; + + } + else + { + // Direct mode, load lib3270.dll, get pointers to the calls + static const char *dllname = "lib3270.dll." PACKAGE_VERSION; + + int f; + HMODULE kernel; + HANDLE cookie = NULL; + DWORD rc; + HANDLE (*AddDllDirectory)(PCWSTR NewDirectory); + BOOL (*RemoveDllDirectory)(HANDLE Cookie); + UINT errorMode; + char datadir[4096]; + + trace("hModule=%p",hModule); + if(hModule) + return EBUSY; + + kernel = LoadLibrary("kernel32.dll"); + AddDllDirectory = (HANDLE (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory"); + RemoveDllDirectory = (BOOL (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory"); + + // Notify user in case of error loading protocol DLL + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v=vs.85).aspx + errorMode = SetErrorMode(1); + + memset(datadir,' ',4095); + datadir[4095] = 0; + + if(hllapi_get_datadir(datadir)) + { + char buffer[4096]; + wchar_t path[4096]; + + mbstowcs(path, datadir, 4095); + trace("Datadir=[%s] AddDllDirectory=%p RemoveDllDirectory=%p\n",datadir,AddDllDirectory,RemoveDllDirectory); + if(AddDllDirectory) + cookie = AddDllDirectory(path); + +#ifdef DEBUG + snprintf(buffer,4096,"%s\\.bin\\Debug\\%s",datadir,dllname); +#else + snprintf(buffer,4096,"%s\\%s",datadir,dllname); +#endif // DEBUG + + hModule = LoadLibrary(buffer); + + trace("%s hModule=%p rc=%d",buffer,hModule,(int) GetLastError()); + + if(hModule == NULL) + { + // Enable DLL error popup and try again with full path + SetErrorMode(0); + hModule = LoadLibraryEx(buffer,NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS|LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); + } + + rc = GetLastError(); + + trace("%s hModule=%p rc=%d",buffer,hModule,(int) rc); + } + else + { + hModule = LoadLibrary(dllname); + rc = GetLastError(); + } + + SetErrorMode(errorMode); + + trace("%s hModule=%p rc=%d",dllname,hModule,(int) rc); + + if(cookie && RemoveDllDirectory) + RemoveDllDirectory(cookie); + + if(kernel) + FreeLibrary(kernel); + + if(!hModule) + return rc; + + // Get library entry pointers + for(f=0;entry_point[f].name;f++) + { + void *ptr = (void *) GetProcAddress(hModule,entry_point[f].name); + + trace("%d %s=%p\n",f,entry_point[f].name,ptr); + + if(!ptr) + { + fprintf(stderr,"Can´t load \"%s\"\n",entry_point[f].name); + hllapi_deinit(); + return ENOENT; + } + *entry_point[f].call = ptr; + } + + } + // Get session handle + hSession = session_new((const char *) mode); + trace("%s ok hSession=%p\n",__FUNCTION__,hSession); + + return hSession ? 0 : -1; + } + + __declspec (dllexport) DWORD __stdcall hllapi_deinit(void) + { + int f; + + // Release session + if(hSession && session_free) + session_free(hSession); + + for(f=0;entry_point[f].name;f++) + *entry_point[f].call = NULL; + + if(hModule != NULL) + { + FreeLibrary(hModule); + hModule = NULL; + } + + return 0; + } + + __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void) + { + if(!get_revision) + return 0; + return (DWORD) atoi(get_revision()); + } + + __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait) + { + if(!(host_connect && hSession && uri)) + return EINVAL; + + return host_connect(hSession,uri,wait); + } + + __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void) + { + if(!(host_is_connected && hSession)) + return EINVAL; + + return host_is_connected(hSession); + } + + __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void) + { + if(!(host_disconnect && hSession)) + return EINVAL; + + host_disconnect(hSession); + + return 0; + } + + __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds) + { + if(!(wait_for_ready && hSession)) + return EINVAL; + + trace("%s seconds=%d\n", __FUNCTION__, (int) seconds); + + return (DWORD) wait_for_ready(hSession,(int) seconds); + } + + __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds) + { + if(!(script_sleep && hSession)) + return EINVAL; + + return (DWORD) script_sleep(hSession,(int) seconds); + } + + __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void) + { + if(!(get_message && hSession)) + return EINVAL; + return (DWORD) get_message(hSession); + } + + __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer) + { + char * text; + int len; + + if(!(get_text && release_memory && hSession)) + return EINVAL; + + trace("%s row=%d col=%d buffer=%p",__FUNCTION__,row,col,buffer); + len = strlen(buffer); + + trace(" len=%d",len); + + text = get_text(hSession,row,col,len); + + trace(" text=%p errno=%d %s\n",text,errno,strerror(errno)); + + if(!text) + return EINVAL; + + strncpy(buffer,text,len); + release_memory(text); + + trace("text:\n%s\n",buffer); + + return 0; + } + + __declspec (dllexport) DWORD __stdcall hllapi_enter(void) + { + if(!(action_enter && hSession)) + return EINVAL; + + return (DWORD) action_enter(hSession); + } + + __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text) + { + if(!(set_text_at && hSession)) + return EINVAL; + + return (DWORD) set_text_at(hSession,row,col,(const unsigned char *) text); + } + + __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text) + { + if(!(cmp_text_at && hSession)) + return EINVAL; + + return (DWORD) cmp_text_at(hSession,row,col,(const char *) text); + } + + __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key) + { + if(!(pfkey && hSession)) + return EINVAL; + + return (DWORD) pfkey(hSession,key); + } + + __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key) + { + if(!(pfkey && hSession)) + return EINVAL; + + return (DWORD) pakey(hSession,key); + } + + __declspec (dllexport) DWORD __stdcall hllapi_get_datadir(LPSTR datadir) + { + HKEY hKey = 0; + unsigned long datalen = strlen(datadir); + + *datadir = 0; + + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) + { + unsigned long datatype; // #defined in winnt.h (predefined types 0-11) + if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) != ERROR_SUCCESS) + *datadir = 0; + RegCloseKey(hKey); + } + + return *datadir; + } + + __declspec (dllexport) DWORD __stdcall hllapi_setcursor(WORD pos) + { + if(!(setcursor && hSession)) + return EINVAL; + trace("%s(%d)",__FUNCTION__,pos); + return setcursor(hSession,pos-1); + } + + __declspec (dllexport) DWORD __stdcall hllapi_getcursor() + { + if(!(getcursor && hSession)) + return -EINVAL; + return getcursor(hSession)+1; + } + + __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD pos, LPSTR buffer, WORD len) + { + char *text; + + trace("%s(%d,%d)",__FUNCTION__,pos,len); + + if(len < 0) + len = strlen(buffer); + + if(!(get_text_at_offset && hSession)) + return EINVAL; + + if(len > strlen(buffer)) + len = strlen(buffer); + + trace("len=%d",len); + text = get_text_at_offset(hSession,pos-1,len); + + trace("text=\n%s\n",text); + + if(!text) + return -1; + + memcpy(buffer,text,len); + + release_memory(text); + + return 0; + } + + __declspec (dllexport) DWORD __stdcall hllapi_emulate_input(LPSTR buffer, WORD len, WORD pasting) + { + + if(!(emulate_input && hSession)) + return EINVAL; + trace("%s",__FUNCTION__); + return emulate_input(hSession, buffer, len, pasting); + } + + __declspec (dllexport) DWORD __stdcall hllapi_erase_eof(void) + { + if(!erase_eof && hSession) + return EINVAL; + trace("%s",__FUNCTION__); + return erase_eof(hSession); + } + + __declspec (dllexport) DWORD __stdcall hllapi_print(void) + { + #warning Implementar + return -1; + } diff --git a/src/plugins/hllapi/client.h b/src/plugins/hllapi/client.h new file mode 100644 index 0000000..709d26f --- /dev/null +++ b/src/plugins/hllapi/client.h @@ -0,0 +1,63 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como private.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include + + #ifndef ETIMEDOUT + #define ETIMEDOUT 1238 + #endif // ETIMEDOUT + + #define PIPE_BUFFER_LENGTH 8192 + + #define set_active(x) /* x */ + + void * hllapi_pipe_init(const char *id); + void hllapi_pipe_deinit(void *h); + const char * hllapi_pipe_get_revision(void); + void hllapi_pipe_release_memory(void *p); + int hllapi_pipe_connect(void *h, const char *n, int wait); + void hllapi_pipe_disconnect(void *h); + LIB3270_MESSAGE hllapi_pipe_get_message(void *h); + char * hllapi_pipe_get_text_at(void *h, int row, int col, int len); + char * hllapi_pipe_get_text(void *h, int offset, int len); + int hllapi_pipe_enter(void *h); + int hllapi_pipe_erase_eof(void *h); + int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str); + int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text); + int hllapi_pipe_pfkey(void *h, int key); + int hllapi_pipe_pakey(void *h, int key); + int hllapi_pipe_wait_for_ready(void *h, int seconds); + int hllapi_pipe_sleep(void *h, int seconds); + int hllapi_pipe_is_connected(void *h); + int hllapi_pipe_getcursor(void *h); + int hllapi_pipe_setcursor(void *h, int baddr); + int hllapi_pipe_emulate_input(void *hSession, const char *s, int len, int pasting); + + diff --git a/src/plugins/hllapi/hllapi.c b/src/plugins/hllapi/hllapi.c new file mode 100644 index 0000000..1aa9ebd --- /dev/null +++ b/src/plugins/hllapi/hllapi.c @@ -0,0 +1,291 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como hllapi.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include + #include + #include + #include + #include + #include + + #undef trace + #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } } + +/*--[ Prototipes ]-----------------------------------------------------------------------------------*/ + + static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc); + static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc); + static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc); + static int copy_ps_to_str(char *buffer, unsigned short *length, unsigned short *rc); + + static int get_cursor_position(char *buffer, unsigned short *length, unsigned short *rc); + static int set_cursor_position(char *buffer, unsigned short *length, unsigned short *rc); + static int input_string(char *buffer, unsigned short *length, unsigned short *rc); + + static int invalid_request(char *buffer, unsigned short *length, unsigned short *rc); + +/*--[ Globals ]--------------------------------------------------------------------------------------*/ + + static const struct _hllapi_call + { + unsigned long func; + int (*exec)(char *buffer, unsigned short *length, unsigned short *rc); + } hllapi_call[] = + { + { HLLAPI_CMD_CONNECTPS, connect_ps }, + { HLLAPI_CMD_DISCONNECTPS, disconnect_ps }, + { HLLAPI_CMD_GETREVISION, get_library_revision }, + { HLLAPI_CMD_QUERYCURSOR, get_cursor_position }, + { HLLAPI_CMD_SETCURSOR, set_cursor_position }, + { HLLAPI_CMD_COPYPSTOSTR, copy_ps_to_str }, + { HLLAPI_CMD_INPUTSTRING, input_string }, + { HLLAPI_CMD_WAIT, invalid_request }, + { HLLAPI_CMD_COPYPS, invalid_request }, + { HLLAPI_CMD_SEARCHPS, invalid_request }, + { HLLAPI_CMD_COPYSTRTOPS, invalid_request }, + { HLLAPI_CMD_SENDFILE, invalid_request }, + { HLLAPI_CMD_RECEIVEFILE, invalid_request }, + + }; + + static const char control_char = '@'; + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + +#ifdef _WIN32 + __declspec (dllexport) int __stdcall hllapi(LPWORD func, LPSTR buffer, LPWORD length, LPWORD rc) +#else + LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc) +#endif // _WIN32 +{ + int f; + + trace("%s(%d)",__FUNCTION__,*func); + + for(f=0;f< (sizeof (hllapi_call) / sizeof ((hllapi_call)[0]));f++) + { + if(hllapi_call[f].func == *func) + return hllapi_call[f].exec(buffer,length,rc); + } + + return invalid_request(buffer, length, rc); +} + +static int invalid_request(char *buffer, unsigned short *length, unsigned short *rc) +{ + *rc = HLLAPI_STATUS_BAD_PARAMETER; + return *rc; +} + +static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc) +{ + char *tempbuffer = NULL; + + trace("%s: len=%d buflen=%d",__FUNCTION__,*length,strlen(buffer)); + + if(strlen(buffer) > *length) + buffer[*length] = 0; + + if(!strrchr(buffer,':')) + { + int sz = strlen(buffer); + + tempbuffer = malloc(sz+2); + strcpy(tempbuffer,buffer); + tempbuffer[sz-1] = ':'; + tempbuffer[sz] = buffer[sz-1]; + tempbuffer[sz+1] = 0; + buffer = tempbuffer; + } + + if(hllapi_init(buffer) == 0) + *rc = HLLAPI_STATUS_SUCESS; + else + *rc = HLLAPI_STATUS_UNAVAILABLE; + + if(tempbuffer) + free(tempbuffer); + + return 0; +} + +static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc) +{ + *rc = hllapi_deinit(); + return 0; +} + +static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc) +{ + *rc = hllapi_get_revision(); + return 0; +} + +static int get_cursor_position(char *buffer, unsigned short *length, unsigned short *rc) +{ + int pos = hllapi_getcursor(); + + trace("%s(%d)",__FUNCTION__,pos); + + if(pos < 0) + return -1; + + *rc = pos; + return 0; +} + +static int set_cursor_position(char *buffer, unsigned short *length, unsigned short *rc) +{ + trace("%s(%d)",__FUNCTION__,*rc); + *rc = hllapi_setcursor(*rc); + return 0; +} + +static int copy_ps_to_str(char *buffer, unsigned short *length, unsigned short *rc) +{ + // Length Length of the target data string. + // PS Position Position within the host presentation space of the first byte in your target data string. + return hllapi_get_screen(*rc,buffer,*length); +} + +static int input_string(char *input, unsigned short *length, unsigned short *rc) +{ + size_t szText; + char * text; + + if(!input) + { + *rc = HLLAPI_STATUS_BAD_PARAMETER; + return HLLAPI_STATUS_BAD_PARAMETER; + } + + szText = strlen(input); + + if(*length > 0 && *length < szText) + szText = *length; + + text = malloc(szText+2); + memcpy(text,input,szText); + text[szText] = 0; + + *rc = 0; + + if(strchr(text,control_char)) + { + // Convert control char + char * buffer = text; + char * ptr; + + for(ptr = strchr(text,control_char);ptr;ptr = strchr(buffer,control_char)) + { + *(ptr++) = 0; + + hllapi_emulate_input(buffer,-1,0); + + switch(*(ptr++)) + { + case 'P': // Print + *rc = hllapi_print(); + break; + + case 'E': // Enter + hllapi_enter(); + break; + + case 'F': // Erase EOF + hllapi_erase_eof(); + break; + + case '1': // PF1 + hllapi_pfkey(1); + break; + + case '2': // PF2 + hllapi_pfkey(2); + break; + + case '3': // PF3 + hllapi_pfkey(3); + break; + + case '4': // PF4 + hllapi_pfkey(4); + break; + + case '5': // PF5 + hllapi_pfkey(5); + break; + + case '6': // PF6 + hllapi_pfkey(6); + break; + + case '7': // PF7 + hllapi_pfkey(7); + break; + + case '8': // PF8 + hllapi_pfkey(8); + break; + + case '9': // PF9 + hllapi_pfkey(9); + break; + + case 'a': // PF10 + hllapi_pfkey(10); + break; + + case 'b': // PF11 + hllapi_pfkey(11); + break; + + case 'c': // PF12 + hllapi_pfkey(12); + break; + } + + buffer = ptr; + + } + + hllapi_emulate_input(buffer,-1,0); + + } + else + { + hllapi_emulate_input(text,szText,0); + } + + free(text); + + return 0; +} + diff --git a/src/plugins/hllapi/hllapi.cbp b/src/plugins/hllapi/hllapi.cbp new file mode 100644 index 0000000..89cfc8e --- /dev/null +++ b/src/plugins/hllapi/hllapi.cbp @@ -0,0 +1,84 @@ + + + + + + diff --git a/src/plugins/hllapi/packets.h b/src/plugins/hllapi/packets.h new file mode 100644 index 0000000..2d12ab6 --- /dev/null +++ b/src/plugins/hllapi/packets.h @@ -0,0 +1,152 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como packets.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + typedef enum _hllapi_packet + { + HLLAPI_PACKET_CONNECT, + HLLAPI_PACKET_DISCONNECT, + HLLAPI_PACKET_GET_PROGRAM_MESSAGE, + HLLAPI_PACKET_GET_TEXT_AT_OFFSET, + HLLAPI_PACKET_GET_TEXT_AT, + HLLAPI_PACKET_SET_TEXT_AT, + HLLAPI_PACKET_CMP_TEXT_AT, + HLLAPI_PACKET_ENTER, + HLLAPI_PACKET_PFKEY, + HLLAPI_PACKET_PAKEY, + HLLAPI_PACKET_SET_CURSOR_POSITION, + HLLAPI_PACKET_GET_CURSOR_POSITION, + HLLAPI_PACKET_INPUT_STRING, + HLLAPI_PACKET_IS_CONNECTED, + HLLAPI_PACKET_SET_CURSOR, + HLLAPI_PACKET_GET_CURSOR, + HLLAPI_PACKET_EMULATE_INPUT, + HLLAPI_PACKET_ERASE_EOF, + + HLLAPI_PACKET_INVALID + + } HLLAPI_PACKET; + +#pragma pack(1) + +struct hllapi_packet_result +{ + int rc; +}; + +struct hllapi_packet_text_result +{ + int rc; + char text[1]; +}; + +struct hllapi_packet_query +{ + unsigned char packet_id; +}; + +struct hllapi_packet_connect +{ + unsigned char packet_id; + unsigned char wait; + char hostname[1]; +}; + +struct hllapi_packet_keycode +{ + unsigned char packet_id; + unsigned short keycode; +}; + +struct hllapi_packet_cursor +{ + unsigned char packet_id; + unsigned short row; + unsigned short col; +}; + +struct hllapi_packet_text +{ + unsigned char packet_id; + char text[1]; +}; + +struct hllapi_packet_at +{ + unsigned char packet_id; + unsigned short row; + unsigned short col; + unsigned short len; +}; + +struct hllapi_packet_text_at +{ + unsigned char packet_id; + unsigned short row; + unsigned short col; + char text[1]; +}; + +struct hllapi_packet_query_at +{ + unsigned char packet_id; + unsigned short row; + unsigned short col; + unsigned short len; +}; + +struct hllapi_packet_wait +{ + unsigned char packet_id; + int timeout; +}; + +struct hllapi_packet_addr +{ + unsigned char packet_id; + unsigned short addr; +}; + +struct hllapi_packet_query_offset +{ + unsigned char packet_id; + unsigned short addr; + unsigned short len; +}; + +struct hllapi_packet_emulate_input +{ + unsigned char packet_id; + unsigned short len; + unsigned char pasting; + char text[1]; +}; + + +#pragma pack() + diff --git a/src/plugins/hllapi/pipesource.c b/src/plugins/hllapi/pipesource.c new file mode 100644 index 0000000..b72c56b --- /dev/null +++ b/src/plugins/hllapi/pipesource.c @@ -0,0 +1,385 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como pipesource.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + */ + + #include + #include + + #include + #include + #include "remotectl.h" + +/*---[ Defines ]----------------------------------------------------------------------------*/ + + #pragma pack(1) + + typedef struct _pipe_source + { + GSource gsrc; + HANDLE hPipe; + + enum _PIPE_STATE + { + PIPE_STATE_WAITING, + PIPE_STATE_READ, + PIPE_STATE_PENDING_READ, + + PIPE_STATE_UNDEFINED, + } state; + + OVERLAPPED overlap; + unsigned char buffer[PIPE_BUFFER_LENGTH+1]; + } pipe_source; + + #pragma pack() + +/*---[ GSource ]----------------------------------------------------------------------------*/ + +static void wait_for_client(pipe_source *source) +{ + set_active(FALSE); + if(ConnectNamedPipe(source->hPipe,&source->overlap)) + { + popup_lasterror("%s",_( "Error in ConnectNamedPipe" )); + return; + } + + switch(GetLastError()) + { + // The overlapped connection in progress. + case ERROR_IO_PENDING: + // trace("%s: ERROR_IO_PENDING",__FUNCTION__); + source->state = PIPE_STATE_WAITING; + break; + + // Client is already connected, so signal an event. + case ERROR_PIPE_CONNECTED: + trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__); + set_active(TRUE); + if(SetEvent(source->overlap.hEvent)) + break; + + // If an error occurs during the connect operation... + default: + popup_lasterror("%s", _( "ConnectNamedPipe failed" )); + } + + } + + static gboolean IO_prepare(GSource *source, gint *timeout) + { + /* + * Called before all the file descriptors are polled. + * If the source can determine that it is ready here + * (without waiting for the results of the poll() call) + * it should return TRUE. + * + * It can also return a timeout_ value which should be the maximum + * timeout (in milliseconds) which should be passed to the poll() call. + * The actual timeout used will be -1 if all sources returned -1, + * or it will be the minimum of all the timeout_ values + * returned which were >= 0. + * + */ + if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) + { + // trace("%s: source=%p",__FUNCTION__,source); + return TRUE; + } + + *timeout = 10; + return FALSE; + } + + static gboolean IO_check(GSource *source) + { + /* + * Called after all the file descriptors are polled. + * The source should return TRUE if it is ready to be dispatched. + * Note that some time may have passed since the previous prepare + * function was called, so the source should be checked again here. + * + */ + if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) + return TRUE; + + return FALSE; + } + + static void process_input(pipe_source *source, DWORD cbRead) + { + HLLAPI_DATA * data = (HLLAPI_DATA *) source->buffer; + QUERY * qry = g_malloc0(sizeof(QUERY)+cbRead+1); + + qry->hPipe = source->hPipe; + qry->text = (const gchar *) (qry+1); + + if(data->id == HLLAPI_REQUEST_QUERY) + { + // HLLAPI query + qry->cmd = (int) data->func; + qry->pos = (int) data->rc; + qry->length = data->value; + memcpy((gchar *)(qry->text),data->string,qry->length); + } + else + { + qry->cmd = -1; + } + + enqueue_request(qry); + } + + void request_complete(QUERY *qry, int rc, const gchar *text) + { + request_buffer(qry,rc,strlen(text),(const gpointer) text); + } + + void request_status(QUERY *qry, int rc) + { + if(rc) + { + const gchar *msg = strerror(rc); + request_buffer(qry, rc, strlen(msg), (const gpointer) msg); + } + else + { + request_buffer(qry, rc, 0, NULL); + } + } + + void request_value(QUERY *qry, int rc, unsigned int value) + { + HLLAPI_DATA data; + + memset(&data,0,sizeof(data)); + data.id = HLLAPI_RESPONSE_VALUE; + data.func = qry->cmd; + data.rc = rc; + data.value = value; + +#ifdef WIN32 + { + DWORD wrote = sizeof(data); + WriteFile(qry->hPipe,&data,wrote,&wrote,NULL); + trace("Wrote=%d len=%d",(int) wrote, sizeof(data)); + } +#endif // WIN32 + + g_free(qry); + + + } + + void request_buffer(QUERY *qry, int rc, size_t szBuffer, const gpointer buffer) + { + size_t sz; + HLLAPI_DATA *data; + + if(buffer) + { + sz = sizeof(HLLAPI_DATA)+szBuffer; + data = g_malloc0(sz); + data->id = HLLAPI_RESPONSE_TEXT; + memcpy(data->string,buffer,szBuffer); + } + else + { + sz = sizeof(HLLAPI_DATA); + data = g_malloc0(sz); + data->id = HLLAPI_RESPONSE_VALUE; + } + + data->func = qry->cmd; + data->rc = rc; + data->value = szBuffer; + + trace("rc=%d data->len=%d",rc,(int) szBuffer); + +#ifdef WIN32 + { + DWORD wrote = sz; + WriteFile(qry->hPipe,data,wrote,&wrote,NULL); + trace("Wrote=%d len=%d",(int) wrote, (int) sz); + } +#endif // WIN32 + + g_free(data); + g_free(qry); + + } + + static void read_input_pipe(pipe_source *source) + { + DWORD cbRead = 0; + + if(ReadFile(source->hPipe,source->buffer,PIPE_BUFFER_LENGTH,&cbRead,&source->overlap) && cbRead > 0) + process_input(source,cbRead); + + // The read operation is still pending. + switch(GetLastError()) + { + case 0: + break; + + case ERROR_IO_PENDING: + // trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__); + source->state = PIPE_STATE_PENDING_READ; + break; + + case ERROR_PIPE_LISTENING: + // trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__); + source->state = PIPE_STATE_READ; + break; + + case ERROR_BROKEN_PIPE: + trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__); + + if(!DisconnectNamedPipe(source->hPipe)) + { + set_active(FALSE); + popup_lasterror("%s",_( "Error in DisconnectNamedPipe" )); + } + else + { + wait_for_client(source); + } + break; + + case ERROR_PIPE_NOT_CONNECTED: + trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__); + set_active(FALSE); + break; + + default: + if(source->hPipe != INVALID_HANDLE_VALUE) + popup_lasterror("%s",_( "Error receiving message from pipe" ) ); + } + + } + + static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer data) + { + /* + * Called to dispatch the event source, + * after it has returned TRUE in either its prepare or its check function. + * The dispatch function is passed in a callback function and data. + * The callback function may be NULL if the source was never connected + * to a callback using g_source_set_callback(). The dispatch function + * should call the callback function with user_data and whatever additional + * parameters are needed for this type of event source. + */ + BOOL fSuccess; + DWORD cbRead = 0; +// DWORD dwErr = 0; + + fSuccess = GetOverlappedResult(((pipe_source *) source)->hPipe,&((pipe_source *) source)->overlap,&cbRead,FALSE ); + + // trace("%s: source=%p data=%p Result=%s cbRead=%d",__FUNCTION__,source,data,fSuccess ? "Success" : "Unsuccess",(int) cbRead); + + switch(((pipe_source *) source)->state) + { + case PIPE_STATE_WAITING: + if(fSuccess) + { + trace("Pipe connected (cbRet=%d)",(int) cbRead); + set_active(TRUE); + ((pipe_source *) source)->state = PIPE_STATE_READ; + } + else + { + popup_lasterror("%s", _( "Pipe connection failed" )); + } + break; + + case PIPE_STATE_READ: + // trace("Reading pipe (cbRead=%d)",(int) cbRead); + read_input_pipe( (pipe_source *) source); + break; + + case PIPE_STATE_PENDING_READ: + if(fSuccess && cbRead > 0) + process_input((pipe_source *) source,cbRead); + ((pipe_source *) source)->state = PIPE_STATE_READ; + break; + +//#ifdef DEBUG +// default: +// trace("%s: source=%p data=%p Unexpected mode %d",__FUNCTION__,source,data,((pipe_source *) source)->state); +//#endif + } + + return TRUE; + } + + static void IO_finalize(GSource *source) + { +// trace("%s: source=%p",__FUNCTION__,source); + + if( ((pipe_source *) source)->hPipe != INVALID_HANDLE_VALUE) + { + CloseHandle(((pipe_source *) source)->hPipe); + ((pipe_source *) source)->hPipe = INVALID_HANDLE_VALUE; + } + + } + + static gboolean IO_closure(gpointer data) + { +// trace("%s: data=%p",__FUNCTION__,data); + return 0; + } + + + void init_source_pipe(HANDLE hPipe) + { + static GSourceFuncs pipe_source_funcs = + { + IO_prepare, + IO_check, + IO_dispatch, + IO_finalize, + IO_closure, + NULL + }; + + pipe_source *source = (pipe_source *) g_source_new(&pipe_source_funcs,sizeof(pipe_source)); + + source->hPipe = hPipe; + source->state = PIPE_STATE_WAITING; + source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL); + + g_source_attach((GSource *) source,NULL); + + wait_for_client(source); + + return; + } + diff --git a/src/plugins/hllapi/pluginmain.c b/src/plugins/hllapi/pluginmain.c new file mode 100644 index 0000000..186c170 --- /dev/null +++ b/src/plugins/hllapi/pluginmain.c @@ -0,0 +1,818 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como pluginmain.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + * Agradecimento: + * + * Hélio Passos + * + */ + + #include "server.h" + #include "packets.h" + #include + +/*--[ Defines ]--------------------------------------------------------------------------------------*/ + + #pragma pack(1) + + typedef struct _pipe_source + { + GSource gsrc; + HANDLE hPipe; + + enum _PIPE_STATE + { + PIPE_STATE_WAITING, + PIPE_STATE_READ, + PIPE_STATE_PENDING_READ, + PIPE_STATE_UNDEFINED, + } state; + + OVERLAPPED overlap; + unsigned char buffer[PIPE_BUFFER_LENGTH+1]; + } pipe_source; + + #pragma pack() + + +/*--[ Globals ]--------------------------------------------------------------------------------------*/ + + static const gchar control_char = '@'; + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + static void IO_accept(pipe_source *source) + { + set_active(FALSE); + + if(ConnectNamedPipe(source->hPipe,&source->overlap)) + { + popup_lasterror("%s",_( "Error in ConnectNamedPipe" )); + return; + } + + switch(GetLastError()) + { + // The overlapped connection in progress. + case ERROR_IO_PENDING: + // trace("%s: ERROR_IO_PENDING",__FUNCTION__); + source->state = PIPE_STATE_WAITING; + break; + + // Client is already connected, so signal an event. + case ERROR_PIPE_CONNECTED: + trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__); + set_active(TRUE); + if(SetEvent(source->overlap.hEvent)) + break; + + // If an error occurs during the connect operation... + default: + popup_lasterror("%s", _( "ConnectNamedPipe failed" )); + } + + } + + static gboolean IO_prepare(GSource *source, gint *timeout) + { + /* + * Called before all the file descriptors are polled. + * If the source can determine that it is ready here + * (without waiting for the results of the poll() call) + * it should return TRUE. + * + * It can also return a timeout_ value which should be the maximum + * timeout (in milliseconds) which should be passed to the poll() call. + * The actual timeout used will be -1 if all sources returned -1, + * or it will be the minimum of all the timeout_ values + * returned which were >= 0. + * + */ + if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) + return TRUE; + + *timeout = 10; + return FALSE; + } + + static gboolean IO_check(GSource *source) + { + /* + * Called after all the file descriptors are polled. + * The source should return TRUE if it is ready to be dispatched. + * Note that some time may have passed since the previous prepare + * function was called, so the source should be checked again here. + * + */ + if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) + return TRUE; + + return FALSE; + } + + static void send_text(pipe_source *source, char *text) + { + struct hllapi_packet_text *pkt; + DWORD szBlock; + + if(text) + { + szBlock = sizeof(struct hllapi_packet_text)+strlen(text); + pkt = g_malloc0(szBlock); + pkt->packet_id = 0; + strcpy(pkt->text,text); + lib3270_free(text); + } + else + { + szBlock = sizeof(struct hllapi_packet_text); + pkt = g_malloc0(szBlock); + pkt->packet_id = errno ? errno : -1; + } + + WriteFile(source->hPipe,pkt,szBlock,&szBlock,NULL); + + g_free(pkt); + } + + static void send_result(pipe_source *source, int rc) + { + struct hllapi_packet_result pkt = { rc }; + DWORD wrote = sizeof(pkt); + WriteFile(source->hPipe,&pkt,wrote,&wrote,NULL); + } + + static void process_input(pipe_source *source, DWORD cbRead) + { + + trace("%s id=%d",__FUNCTION__,((struct hllapi_packet_query *) source->buffer)->packet_id); + + switch(((struct hllapi_packet_query *) source->buffer)->packet_id) + { + case HLLAPI_PACKET_CONNECT: + send_result(source,lib3270_connect( lib3270_get_default_session_handle(), + ((struct hllapi_packet_connect *) source->buffer)->hostname, + ((struct hllapi_packet_connect *) source->buffer)->wait)); + break; + + case HLLAPI_PACKET_DISCONNECT: + send_result(source,lib3270_disconnect(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_GET_PROGRAM_MESSAGE: + send_result(source,lib3270_get_program_message(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_IS_CONNECTED: + send_result(source,lib3270_in_tn3270e(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_ENTER: + send_result(source,lib3270_enter(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_ERASE_EOF: + send_result(source,lib3270_eraseeof(lib3270_get_default_session_handle())); + break; + + case HLLAPI_PACKET_PFKEY: + send_result(source,lib3270_pfkey( lib3270_get_default_session_handle(), + ((struct hllapi_packet_keycode *) source->buffer)->keycode)); + break; + + case HLLAPI_PACKET_PAKEY: + send_result(source,lib3270_pakey( lib3270_get_default_session_handle(), + ((struct hllapi_packet_keycode *) source->buffer)->keycode)); + break; + + case HLLAPI_PACKET_SET_CURSOR_POSITION: + send_result(source,lib3270_set_cursor_position( lib3270_get_default_session_handle(), + ((struct hllapi_packet_cursor *) source->buffer)->row, + ((struct hllapi_packet_cursor *) source->buffer)->col)); + break; + + case HLLAPI_PACKET_SET_TEXT_AT: + send_result(source,lib3270_set_text_at( lib3270_get_default_session_handle(), + ((struct hllapi_packet_text_at *) source->buffer)->row, + ((struct hllapi_packet_text_at *) source->buffer)->col, + (unsigned char *) ((struct hllapi_packet_text_at *) source->buffer)->text)); + break; + + case HLLAPI_PACKET_GET_TEXT_AT: + send_text(source,lib3270_get_text_at( lib3270_get_default_session_handle(), + ((struct hllapi_packet_at *) source->buffer)->row, + ((struct hllapi_packet_at *) source->buffer)->col, + ((struct hllapi_packet_at *) source->buffer)->len)); + break; + + case HLLAPI_PACKET_GET_TEXT_AT_OFFSET: + send_text(source,lib3270_get_text( lib3270_get_default_session_handle(), + ((struct hllapi_packet_query_offset *) source->buffer)->addr, + ((struct hllapi_packet_query_offset *) source->buffer)->len)); + break; + + case HLLAPI_PACKET_CMP_TEXT_AT: + send_result(source,lib3270_cmp_text_at( lib3270_get_default_session_handle(), + ((struct hllapi_packet_text_at *) source->buffer)->row, + ((struct hllapi_packet_text_at *) source->buffer)->col, + ((struct hllapi_packet_text_at *) source->buffer)->text)); + break; + + case HLLAPI_PACKET_INPUT_STRING: + send_result(source,lib3270_input_string(lib3270_get_default_session_handle(), + (unsigned char *) ((struct hllapi_packet_text *) source->buffer)->text)); + break; + + case HLLAPI_PACKET_EMULATE_INPUT: + send_result(source,lib3270_emulate_input(lib3270_get_default_session_handle(), + (const char *) ((struct hllapi_packet_emulate_input *) source->buffer)->text, + (int) ((struct hllapi_packet_emulate_input *) source->buffer)->len, + (int) ((struct hllapi_packet_emulate_input *) source->buffer)->pasting)); + break; + + case HLLAPI_PACKET_SET_CURSOR: + send_result(source,lib3270_set_cursor_address(lib3270_get_default_session_handle(), + ((struct hllapi_packet_addr *) source->buffer)->addr)); + break; + + case HLLAPI_PACKET_GET_CURSOR: + send_result(source,lib3270_get_cursor_address(lib3270_get_default_session_handle())); + break; + + + default: + send_result(source, EINVAL); + g_message("Invalid remote request (id=%d)",source->buffer[0]); + } + + } + + static void read_input_pipe(pipe_source *source) + { + DWORD cbRead = 0; + + if(ReadFile(source->hPipe,source->buffer,PIPE_BUFFER_LENGTH,&cbRead,&source->overlap) && cbRead > 0) + process_input(source,cbRead); + + // The read operation is still pending. + switch(GetLastError()) + { + case 0: + break; + + case ERROR_IO_PENDING: + // trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__); + source->state = PIPE_STATE_PENDING_READ; + break; + + case ERROR_PIPE_LISTENING: + // trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__); + source->state = PIPE_STATE_READ; + break; + + case ERROR_BROKEN_PIPE: + trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__); + + if(!DisconnectNamedPipe(source->hPipe)) + { + set_active(FALSE); + popup_lasterror("%s",_( "Error in DisconnectNamedPipe" )); + } + else + { + IO_accept(source); + } + break; + + case ERROR_PIPE_NOT_CONNECTED: + trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__); + set_active(FALSE); + break; + + default: + if(source->hPipe != INVALID_HANDLE_VALUE) + popup_lasterror("%s",_( "Error receiving message from pipe" ) ); + } + + } + + static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer data) + { + /* + * Called to dispatch the event source, + * after it has returned TRUE in either its prepare or its check function. + * The dispatch function is passed in a callback function and data. + * The callback function may be NULL if the source was never connected + * to a callback using g_source_set_callback(). The dispatch function + * should call the callback function with user_data and whatever additional + * parameters are needed for this type of event source. + */ + BOOL fSuccess; + DWORD cbRead = 0; +// DWORD dwErr = 0; + + fSuccess = GetOverlappedResult(((pipe_source *) source)->hPipe,&((pipe_source *) source)->overlap,&cbRead,FALSE ); + + // trace("%s: source=%p data=%p Result=%s cbRead=%d",__FUNCTION__,source,data,fSuccess ? "Success" : "Unsuccess",(int) cbRead); + + switch(((pipe_source *) source)->state) + { + case PIPE_STATE_WAITING: + if(fSuccess) + { + trace("Pipe connected (cbRet=%d)",(int) cbRead); + set_active(TRUE); + ((pipe_source *) source)->state = PIPE_STATE_READ; + } + else + { + popup_lasterror("%s", _( "Pipe connection failed" )); + } + break; + + case PIPE_STATE_READ: + // trace("Reading pipe (cbRead=%d)",(int) cbRead); + read_input_pipe( (pipe_source *) source); + break; + + case PIPE_STATE_PENDING_READ: + if(fSuccess && cbRead > 0) + process_input((pipe_source *) source,cbRead); + ((pipe_source *) source)->state = PIPE_STATE_READ; + break; + + case PIPE_STATE_UNDEFINED: + break; + +//#ifdef DEBUG +// default: +// trace("%s: source=%p data=%p Unexpected mode %d",__FUNCTION__,source,data,((pipe_source *) source)->state); +//#endif + } + + return TRUE; + } + + static void IO_finalize(GSource *source) + { +// trace("%s: source=%p",__FUNCTION__,source); + + if( ((pipe_source *) source)->hPipe != INVALID_HANDLE_VALUE) + { + CloseHandle(((pipe_source *) source)->hPipe); + ((pipe_source *) source)->hPipe = INVALID_HANDLE_VALUE; + } + + } + + static gboolean IO_closure(gpointer data) + { +// trace("%s: data=%p",__FUNCTION__,data); + return 0; + } + + void popup_lasterror(const gchar *fmt, ...) + { + char buffer[4096]; + va_list arg_ptr; + int sz; + DWORD errcode = GetLastError(); + char *ptr; + LPVOID lpMsgBuf = 0; + + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); + + for(ptr=lpMsgBuf;*ptr && *ptr != '\n';ptr++); + *ptr = 0; + + va_start(arg_ptr, fmt); + vsnprintf(buffer,4095,fmt,arg_ptr); + va_end(arg_ptr); + + sz = strlen(buffer); + snprintf(buffer+sz,4096-sz,": %s\n(rc=%d)",lpMsgBuf,(int) errcode); + + printf("%s\n",buffer); + +#ifdef DEBUG + fprintf(stderr,"%s\n",buffer); + fflush(stderr); +#endif + + LocalFree(lpMsgBuf); + } + + LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window) + { + char id; + + for(id='A';id < 'Z';id++) + { + gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s_%c",pw3270_get_session_name(window),id); + gchar * ptr; + HANDLE hPipe; + + for(ptr=pipename;*ptr;ptr++) + *ptr = g_ascii_tolower(*ptr); + + hPipe = CreateNamedPipe( TEXT(pipename), // pipe name + PIPE_ACCESS_DUPLEX | // read/write access + FILE_FLAG_OVERLAPPED, // overlapped mode + PIPE_TYPE_MESSAGE | // pipe type + PIPE_READMODE_MESSAGE | // pipe mode + PIPE_WAIT, // blocking mode + 1, // number of instances + PIPE_BUFFER_LENGTH, // output buffer size + PIPE_BUFFER_LENGTH, // input buffer size + NMPWAIT_USE_DEFAULT_WAIT, // client time-out + NULL); // default security attributes + + trace("%s = %p",pipename,hPipe); + g_free(pipename); + + if(hPipe != INVALID_HANDLE_VALUE) + { + static GSourceFuncs pipe_source_funcs = + { + IO_prepare, + IO_check, + IO_dispatch, + IO_finalize, + IO_closure, + NULL + }; + pipe_source * source; + gchar * session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),id); + + pw3270_set_session_name(window,session); + g_free(session); + + source = (pipe_source *) g_source_new(&pipe_source_funcs,sizeof(pipe_source)); + + source->hPipe = hPipe; + source->state = PIPE_STATE_WAITING; + source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL); + + g_source_attach((GSource *) source,NULL); + IO_accept(source); + + return 0; + } + + } + + popup_lasterror( "%s", _( "Can´t create remote control pipe" )); + + return -1; + } + + LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window) + { + + return 0; + } + +/* + static void cmd_connectps(QUERY *qry) + { + g_message("%s","HLLAPI ConnectPS request received"); + request_status(qry,v3270_set_script(pw3270_get_terminal_widget(NULL),'H',TRUE)); + } + + static void cmd_disconnectps(QUERY *qry) + { + g_message("%s","HLLAPI DisconnectPS request received"); + request_status(qry,0); + } + + static void cmd_getrevision(QUERY *qry) + { + request_complete(qry,0,lib3270_get_revision()); + } + + static void cmd_setcursor(QUERY *qry) + { + int rc = ENOTCONN; + + if(lib3270_connected(qry->hSession)) + { + trace("%s: pos=%d row=%d col=%d",__FUNCTION__,rc,rc/80,rc%80); + lib3270_set_cursor_address(qry->hSession,qry->pos -1); + rc = 0; + } + + request_status(qry,rc); + } + + static void cmd_sendstring(QUERY *qry) + { + gchar * text; + GError * error = NULL; + gsize bytes_read; + gsize bytes_written; + const gchar * charset; + + if(!lib3270_connected(qry->hSession)) + { + request_status(qry,ENOTCONN); + return; + } + + g_get_charset(&charset); + + text = g_convert(qry->text,qry->length,lib3270_get_charset(qry->hSession),charset,&bytes_read,&bytes_written,&error); + if(text) + { + int rc = 0; + + if(strchr(text,control_char)) + { + // Convert control char + gchar * buffer = text; + char * ptr; + + for(ptr = strchr(text,control_char);ptr;ptr = strchr(buffer,control_char)) + { + *(ptr++) = 0; + + lib3270_emulate_input(qry->hSession,buffer,-1,0); + + switch(*(ptr++)) + { + case 'P': // Print + rc = pw3270_print(pw3270_get_terminal_widget(NULL), NULL, GTK_PRINT_OPERATION_ACTION_PRINT, PW3270_SRC_ALL); + break; + + case 'E': // Enter + lib3270_enter(qry->hSession); + break; + + case 'F': // Erase EOF + lib3270_eraseeof(qry->hSession); + break; + + case '1': // PF1 + lib3270_pfkey(qry->hSession,1); + break; + + case '2': // PF2 + lib3270_pfkey(qry->hSession,2); + break; + + case '3': // PF3 + lib3270_pfkey(qry->hSession,3); + break; + + case '4': // PF4 + lib3270_pfkey(qry->hSession,4); + break; + + case '5': // PF5 + lib3270_pfkey(qry->hSession,5); + break; + + case '6': // PF6 + lib3270_pfkey(qry->hSession,6); + break; + + case '7': // PF7 + lib3270_pfkey(qry->hSession,7); + break; + + case '8': // PF8 + lib3270_pfkey(qry->hSession,8); + break; + + case '9': // PF9 + lib3270_pfkey(qry->hSession,9); + break; + + case 'a': // PF10 + lib3270_pfkey(qry->hSession,10); + break; + + case 'b': // PF11 + lib3270_pfkey(qry->hSession,11); + break; + + case 'c': // PF12 + lib3270_pfkey(qry->hSession,12); + break; + } + + } + + lib3270_emulate_input(qry->hSession,buffer,-1,0); + + } + else + { + lib3270_emulate_input(qry->hSession,text,strlen(text),0); + } + g_free(text); + + request_status(qry,rc); + + return; + } + + request_complete(qry, error->code, error->message); + g_error_free(error); + + } + + struct wait + { + QUERY * qry; + time_t end; + }; + + static gboolean do_wait(struct wait *w) + { + if(lib3270_get_program_message(w->qry->hSession) == LIB3270_MESSAGE_NONE) + { + request_status(w->qry,0); + return FALSE; + } + + if(time(0) > w->end) + { + trace("%s: TIMEOUT",__FUNCTION__); + request_status(w->qry,ETIMEDOUT); + return FALSE; + } + + return TRUE; + } + + static void cmd_wait(QUERY *qry) + { + struct wait *w; + + if(lib3270_get_program_message(qry->hSession) == LIB3270_MESSAGE_NONE) + { + request_status(qry,0); + return; + } + + w = g_malloc0(sizeof(struct wait)); + w->qry = qry; + w->end = time(0)+pw3270_get_integer(pw3270_get_toplevel(),"hllapi","wait",2); + + g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) 300, (GSourceFunc) do_wait, w, g_free); + } + + static void cmd_copypstostr(QUERY *qry) + { + int rows; + int cols; + unsigned short * attr; + unsigned char * text; + int rc; + unsigned char * buffer; + size_t length; + + if(!lib3270_connected(qry->hSession)) + { + request_status(qry,ENOTCONN); + return; + } + + lib3270_get_screen_size(qry->hSession,&rows,&cols); + + if(qry->pos < 1 || (qry->pos+qry->length) >= (rows*cols)) + { + request_status(qry,EINVAL); + return; + } + + qry->pos--; + + length = (qry->length * sizeof(unsigned short)) + qry->length + 2; + text = buffer = g_malloc0(length+1); + attr = (unsigned short *) (text+qry->length+1); + + trace("%s: pos=%d length=%d",__FUNCTION__,qry->pos,qry->length); + rc = lib3270_get_contents(qry->hSession,qry->pos,qry->pos+(qry->length-1),text,attr); + + if(rc) + { + request_status(qry,rc); + } + else + { + const gchar * charset; + gchar * local; + gsize bytes_read; + gsize bytes_written; + GError * error = NULL; + + trace("Text: [%s]",text); + + g_get_charset(&charset); + + local = g_convert((const gchar *) text,-1,charset,lib3270_get_charset(qry->hSession),&bytes_read,&bytes_written,&error); + + if(!local) + { + request_complete(qry,error->code,error->message); + g_error_free(error); + } + else + { + strncpy((char *) text,(const char *) local,qry->length); + + trace("response: [%s] len=%d",buffer,length); + request_buffer(qry,0,length,buffer); + g_free(local); + } + } + + g_free(buffer); + } + + static void cmd_querycursor(QUERY *qry) + { + request_value(qry,0,lib3270_get_cursor_address(qry->hSession)); + } + + void enqueue_request(QUERY *qry) + { + static const struct _cmd + { + int cmd; + void (*exec)(QUERY *qry); + } cmd[] = + { + { HLLAPI_CMD_CONNECTPS, cmd_connectps }, // 1 + { HLLAPI_CMD_DISCONNECTPS, cmd_disconnectps }, // 2 + { HLLAPI_CMD_INPUTSTRING, cmd_sendstring }, // 3 + { HLLAPI_CMD_WAIT, cmd_wait }, // 4 +// { HLLAPI_CMD_COPYPS, }, // 5 +// { HLLAPI_CMD_SEARCHPS, }, // 6 + { HLLAPI_CMD_QUERYCURSOR, cmd_querycursor }, // 7 + + { HLLAPI_CMD_COPYPSTOSTR, cmd_copypstostr }, // 8 + +// { HLLAPI_CMD_COPYSTRTOPS }, // 15 + + { HLLAPI_CMD_SETCURSOR, cmd_setcursor }, // 40 + +// { HLLAPI_CMD_SENDFILE }, // 90 +// { HLLAPI_CMD_RECEIVEFILE }, + + + { HLLAPI_CMD_GETREVISION, cmd_getrevision }, + }; + + + + int f; + + trace("HLLAPI function %d",(int) qry->cmd); + + qry->hSession = lib3270_get_default_session_handle(); + + for(f=0;fcmd) + { + cmd[f].exec(qry); + return; + } + } + + g_warning("Unexpected HLLAPI function %d",(int) qry->cmd); + request_status(qry,EINVAL); + } + + G_GNUC_INTERNAL void set_active(gboolean on) + { + v3270_set_script(pw3270_get_terminal_widget(NULL),'H',on); + } + +*/ diff --git a/src/plugins/hllapi/remote.c b/src/plugins/hllapi/remote.c new file mode 100644 index 0000000..87b39fa --- /dev/null +++ b/src/plugins/hllapi/remote.c @@ -0,0 +1,363 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como calls.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include + #include + #include + #include + #include + #include + + #include "client.h" + #include "packets.h" + +/*--[ Globals ]--------------------------------------------------------------------------------------*/ + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + void * hllapi_pipe_init(const char *id) + { + HANDLE hPipe = INVALID_HANDLE_VALUE; + static DWORD dwMode = PIPE_READMODE_MESSAGE; + char buffer[4096]; + char * name = strdup(id); + char * ptr; + + trace("%s(%s)",__FUNCTION__,id); + + for(ptr=name;*ptr;ptr++) + { + if(*ptr == ':') + *ptr = '_'; + } + + snprintf(buffer,4095,"\\\\.\\pipe\\%s",name); + + free(name); + + trace("Opening \"%s\"",buffer); + + if(!WaitNamedPipe(buffer,NMPWAIT_USE_DEFAULT_WAIT)) + { + trace("%s: Pipe not found",__FUNCTION__); + errno = ENOENT; + return NULL; + } + + hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); + + if(hPipe == INVALID_HANDLE_VALUE) + { + errno = GetLastError(); + return NULL; + } + + if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) + { + errno = GetLastError(); + return NULL; + } + + trace("hPipe=%p",(void *) hPipe); + return hPipe; + } + + void hllapi_pipe_deinit(void *h) + { + trace("%s(%p)",__FUNCTION__,h); + + if(!h) + return; + + CloseHandle((HANDLE) h); + } + + const char * hllapi_pipe_get_revision(void) + { + return PACKAGE_REVISION; + } + + int hllapi_pipe_connect(void *h, const char *n, int wait) + { + struct hllapi_packet_connect * pkt; + struct hllapi_packet_result response; + DWORD cbSize; + + if(!n) + n = ""; + + cbSize = sizeof(struct hllapi_packet_connect)+strlen(n); + pkt = malloc(cbSize); + + pkt->packet_id = HLLAPI_PACKET_CONNECT; + pkt->wait = (unsigned char) wait; + strcpy(pkt->hostname,n); + + trace("Sending %s",pkt->hostname); + + if(!TransactNamedPipe((HANDLE) h,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL)) + { + errno = GetLastError(); + response.rc = -1; + } + + free(pkt); + + return response.rc; + } + + void hllapi_pipe_disconnect(void *h) + { + static const struct hllapi_packet_query query = { HLLAPI_PACKET_DISCONNECT }; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(query); + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); + } + + LIB3270_MESSAGE hllapi_pipe_get_message(void *h) + { + static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_PROGRAM_MESSAGE }; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(query); + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); + return (LIB3270_MESSAGE) response.rc; + } + + char * hllapi_pipe_get_text_at(void *h, int row, int col, int len) + { + struct hllapi_packet_query_at query = { HLLAPI_PACKET_GET_TEXT_AT, }; + struct hllapi_packet_text * response; + DWORD cbSize = sizeof(struct hllapi_packet_text)+len; + char * text = NULL; + + response = malloc(cbSize+2); + memset(response,0,cbSize+2); + + if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(struct hllapi_packet_query_at), &response, cbSize, &cbSize,NULL)) + return NULL; + + if(response->packet_id) + errno = response->packet_id; + else + text = strdup(response->text); + + free(response); + return text; + } + + int hllapi_pipe_enter(void *h) + { + static const struct hllapi_packet_query query = { HLLAPI_PACKET_ENTER }; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(query); + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); + return response.rc; + } + + int hllapi_pipe_erase_eof(void *h) + { + static const struct hllapi_packet_query query = { HLLAPI_PACKET_ERASE_EOF }; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(query); + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); + return response.rc; + } + + + int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str) + { + struct hllapi_packet_text_at * query; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen((const char *) str); + + query = malloc(cbSize); + query->packet_id = HLLAPI_PACKET_SET_TEXT_AT; + query->row = row; + query->col = col; + strcpy(query->text,(const char *) str); + + TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); + + free(query); + + return response.rc; + } + + int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text) + { + struct hllapi_packet_text_at * query; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text); + + query = malloc(cbSize); + query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT; + query->row = row; + query->col = col; + strcpy(query->text,text); + + TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); + + free(query); + + return response.rc; + } + + int hllapi_pipe_pfkey(void *h, int key) + { + struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, key }; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(query); + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); + return response.rc; + } + + int hllapi_pipe_pakey(void *h, int key) + { + struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, key }; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(query); + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); + return response.rc; + } + + void hllapi_pipe_release_memory(void *p) + { + free(p); + } + + int hllapi_pipe_wait_for_ready(void *h, int seconds) + { + time_t end = time(0)+seconds; + + while(time(0) < end) + { + if(!hllapi_pipe_is_connected(h)) + return ENOTCONN; + + if(hllapi_pipe_get_message(h) == 0) + return 0; + Sleep(250); + } + + return ETIMEDOUT; + } + + int hllapi_pipe_is_connected(void *h) + { + static const struct hllapi_packet_query query = { HLLAPI_PACKET_IS_CONNECTED }; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(query); + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); + return (LIB3270_MESSAGE) response.rc; + } + + int hllapi_pipe_sleep(void *h, int seconds) + { + time_t end = time(0)+seconds; + + while(time(0) < end) + { + if(!hllapi_pipe_is_connected(h)) + return ENOTCONN; + Sleep(500); + } + + return 0; + } + + int hllapi_pipe_getcursor(void *h) + { + static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_CURSOR }; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(query); + + trace("%s",__FUNCTION__); + + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); + return (LIB3270_MESSAGE) response.rc; + + } + + int hllapi_pipe_setcursor(void *h, int baddr) + { + struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, baddr }; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(query); + + trace("%s(%d)",__FUNCTION__,query.addr); + + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); + return response.rc; + } + + char * hllapi_pipe_get_text(void *h, int offset, int len) + { + struct hllapi_packet_query_offset query = { HLLAPI_PACKET_GET_TEXT_AT_OFFSET, offset, len }; + struct hllapi_packet_text * response; + DWORD cbSize = sizeof(struct hllapi_packet_text)+len; + char * text = NULL; + + trace("cbSize=%d",(int) cbSize); + + response = malloc(cbSize+2); + memset(response,0,cbSize+2); + + if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(query), response, cbSize, &cbSize,NULL)) + return NULL; + + trace("rc=%d",response->packet_id); + + if(response->packet_id) + errno = response->packet_id; + else + text = strdup(response->text); + + free(response); + return text; + } + + int hllapi_pipe_emulate_input(void *h, const char *text, int len, int pasting) + { + struct hllapi_packet_emulate_input * query; + struct hllapi_packet_result response; + DWORD cbSize = sizeof(struct hllapi_packet_emulate_input)+strlen(text); + + query = malloc(cbSize); + query->packet_id = HLLAPI_PACKET_EMULATE_INPUT; + query->len = len; + query->pasting = pasting; + strcpy(query->text,text); + + TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); + + free(query); + + return response.rc; + } diff --git a/src/plugins/hllapi/remotectl.h b/src/plugins/hllapi/remotectl.h new file mode 100644 index 0000000..5912d82 --- /dev/null +++ b/src/plugins/hllapi/remotectl.h @@ -0,0 +1,85 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como remotectl.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + * Agradecimento: + * + * Hélio Passos + * + */ + + #define ENABLE_NLS + #define GETTEXT_PACKAGE PACKAGE_NAME + + #include + #include + #include + + #include + #include + #include + + typedef struct _remotequery + { +#ifdef WIN32 + HANDLE hPipe; /**< Pipe handle (for response) */ +#endif // WIN32 + + H3270 * hSession; /**< 3270 Session */ + int cmd; /**< Command */ + int rc; /**< Response status */ + + int pos; + unsigned short length; /**< Query string length */ + const gchar * text; /**< Query string */ + + } QUERY; + + G_GNUC_INTERNAL void set_active(gboolean on); + G_GNUC_INTERNAL void enqueue_request(QUERY *qry); + G_GNUC_INTERNAL void request_complete(QUERY *qry, int rc, const gchar *text); + + G_GNUC_INTERNAL void request_status(QUERY *qry, int rc); + G_GNUC_INTERNAL void request_value(QUERY *qry, int rc, unsigned int value); + G_GNUC_INTERNAL void request_buffer(QUERY *qry, int rc, size_t sz, const gpointer buffer); + +// int run_hllapi(unsigned long function, char *string, unsigned short length, unsigned short rc); + + +#ifdef WIN32 + + #define PIPE_BUFFER_LENGTH 8192 + + void init_source_pipe(HANDLE hPipe); + void popup_lasterror(const gchar *fmt, ...); + +#endif // WIN32 + + + + + + diff --git a/src/plugins/hllapi/server.h b/src/plugins/hllapi/server.h new file mode 100644 index 0000000..65e70df --- /dev/null +++ b/src/plugins/hllapi/server.h @@ -0,0 +1,51 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como server.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #define ENABLE_NLS + #define GETTEXT_PACKAGE PACKAGE_NAME + + #include + #include + #include + + #include + #include + #include + #include + + #include + + #define PIPE_BUFFER_LENGTH HLLAPI_MAXLENGTH+30 + + #define set_active(x) /* x */ + + + G_GNUC_INTERNAL void popup_lasterror(const gchar *fmt, ...); + diff --git a/src/plugins/hllapi/testprogram.c b/src/plugins/hllapi/testprogram.c new file mode 100644 index 0000000..4afcc63 --- /dev/null +++ b/src/plugins/hllapi/testprogram.c @@ -0,0 +1,139 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como testprogram.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include + #include + #include + + #define BUFFER_LENGTH 8000 + +/*---[ Implement ]--------------------------------------------------------------------------------*/ + + int main(int numpar, char *param[]) + { + const char *session = "pw3270:a"; + + printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session)); + printf("revision=%d\n",(int) hllapi_get_revision()); + printf("connect=%d\n",(int) hllapi_connect("fandezhi.efglobe.com:23",0)); + printf("wait=%d\n",(int) hllapi_wait(3)); + printf("connected=%s\n",(int) hllapi_is_connected() ? "Yes" : "No"); + +// printf("disconnect=%d\n",(int) hllapi_disconnect("fandezhi.efglobe.com:23",1)); + + + printf("deinit=%d\n",(int) hllapi_deinit()); + +/* + DWORD revision; + int rc; + + rc = hllapi_init(""); + if(rc) + { + printf("Init exits with rc=%d\n",rc); + return rc; + } + + if(!hllapi_get_revision(&revision)) + printf("Library revision is %d\n",(int) revision); + + + printf("Deinit exits with rc=%d\n",rc); + rc = hllapi_deinit(); +*/ + return 0; + } + +/* + int main(int numpar, char *param[]) + { + char buffer[BUFFER_LENGTH]; + unsigned short rc; + unsigned short len; + unsigned long fn; + + static const struct _cmd + { + const char * name; + unsigned short fn; + const char * arg; + } cmd[] = + { + { "GetRevision", HLLAPI_CMD_GETREVISION, " " }, + { "ConnectPS", HLLAPI_CMD_CONNECTPS, "pw3270A" }, + { "InputString", HLLAPI_CMD_INPUTSTRING, "test" }, + + }; + + int f; + + + for(f=0;f< (sizeof(cmd)/sizeof(struct _cmd)); f++) + { + len = strlen(cmd[f].arg); + memcpy(buffer,cmd[f].arg,len); + hllapi((LPWORD) &cmd[f].fn,buffer,&len,&rc); + printf("%s exits with rc=%d\n[%s]\n",cmd[f].name,rc,buffer); + } + + len = 80; + rc = 1040; + fn = HLLAPI_CMD_COPYPSTOSTR; + hllapi((LPWORD) &fn,buffer,&len,&rc); + printf("%s exits with rc=%d\n%s\n","HLLAPI_CMD_COPYPSTOSTR",rc,buffer); + + // Performance + len = strlen(cmd[0].arg); + memcpy(buffer,cmd[0].arg,len); + if(hllapi((LPWORD) &cmd[0].fn,buffer,&len,&rc) == 0 && rc == 0) + { + time_t end = time(0) + 5; + int qtd = 0; + do + { + qtd++; + } while(hllapi((LPWORD) &cmd[0].fn,buffer,&len,&rc) == 0 && rc == 0 && time(0) -# -# Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob -# os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela -# Free Software Foundation. -# -# Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER -# GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO -# A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para -# obter mais detalhes. -# -# Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este -# programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple -# Place, Suite 330, Boston, MA, 02111-1307, USA -# -# Contatos: -# -# perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) -# erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) -# licinio@bb.com.br (Licínio Luis Branco) -# kraucer@bb.com.br (Kraucer Fernandes Mazuco) -# - -#---[ Sources ]---------------------------------------------------------------- - -MODULE_NAME=remotectl -DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile -PLUGIN_SRC=pluginmain.c -HLLAPI_SRC=hllapi.c calls.c remote.c - -#---[ Paths ]------------------------------------------------------------------ - -ROOTDIR ?= . -OBJDIR ?= $(ROOTDIR)/.obj -BINDIR ?= $(ROOTDIR)/.bin -BINDBG ?= $(BINDIR)/Debug -BINRLS ?= $(BINDIR)/Release - -OBJDBG = $(OBJDIR)/Debug -OBJRLS = $(OBJDIR)/Release -OBJEXT = o - -#---[ Tools ]------------------------------------------------------------------ - -MKDIR=@MKDIR_P@ -CC=@CC@ -LD=@CC@ -MSGCAT=@MSGCAT@ -XGETTEXT=@XGETTEXT@ - -#---[ Rules ]------------------------------------------------------------------ - -DLL_FLAGS=@DLL_FLAGS@ -DEBUG_CFLAGS=-DDEBUG=1 -g -Wall - -LIB3270_MODE ?= Default - -ifeq ($(LIB3270_MODE),Debug) - PW3270_LIBS=-L../../../.bin/Debug@DLLDIR@ -lpw3270 -l3270 - PW3270_CFLAGS=-I../../../src/include - LIB3270_LIBS=-L../../../.bin/Debug@DLLDIR@ -l3270 - LIB3270_CFLAGS=-I../../../src/include -endif - -ifeq ($(LIB3270_MODE),Release) - PW3270_LIBS=-L../../../.bin/Release@DLLDIR@ -lpw3270 -l3270 - PW3270_CFLAGS=-I../../../src/include - LIB3270_LIBS=-L../../../.bin/Release@DLLDIR@ -l3270 - LIB3270_CFLAGS=-I../../../src/include -endif - -ifeq ($(LIB3270_MODE),Default) - LIB3270_LIBS ?= `pkg-config --libs lib3270` - LIB3270_CFLAGS ?= `pkg-config --cflags lib3270` - PW3270_LIBS ?= `pkg-config --libs pw3270 lib3270` - PW3270_CFLAGS ?= `pkg-config --cflags pw3270 lib3270` -endif - - -GTK_CFLAGS ?= @GTK_CFLAGS@ @GTKMAC_CFLAGS@ -GTK_LIBS ?= @GTK_LIBS@ @GTKMAC_LIBS@ - -$(OBJDBG)/%.o: %.c $(DEPENDS) - @echo " CC `basename $@`" - @$(MKDIR) `dirname $@` - @$(CC) $(CFLAGS) $(DEBUG_CFLAGS) $(LIB3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< - -$(OBJRLS)/%.o: %.c $(DEPENDS) - @echo " CC `basename $@`" - @$(MKDIR) `dirname $@` - @$(CC) $(CFLAGS) $(LIB3270_CFLAGS) $(GTK_CFLAGS) -o $@ -c $< - - -#---[ Release targets ]-------------------------------------------------------- - -Release: $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ $(BINRLS)/libhllapi@DLLEXT@ - -$(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@: $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJRLS)/$(SRC).o) - @echo " CCLD `basename $@`" - @$(MKDIR) `dirname $@` - @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) -o $@ $^ $(LIBS) $(PW3270_LIBS) $(GTK_LIBS) - -$(BINRLS)/libhllapi@DLLEXT@: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJRLS)/$(SRC).o) - @echo " CCLD `basename $@`" - @$(MKDIR) `dirname $@` - @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) @LDLIBFLAGS@ -o $@ $^ $(LIBS) - -#---[ Debug targets ]---------------------------------------------------------- - -Debug: $(BINDBG)/plugins/$(MODULE_NAME)@DLLEXT@ $(BINDBG)/libhllapi@DLLEXT@ - -$(BINDBG)/plugins/$(MODULE_NAME)@DLLEXT@: $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJDBG)/$(SRC).o) - @echo " CCLD `basename $@`" - @$(MKDIR) `dirname $@` - @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) -o $@ $^ $(LIBS) $(PW3270_LIBS) $(GTK_LIBS) - -$(BINDBG)/libhllapi@DLLEXT@: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJDBG)/$(SRC).o) - @echo " CCLD `basename $@`" - @$(MKDIR) `dirname $@` - @$(LD) $(DLL_FLAGS) @LDSOFLAGS@ $(LDFLAGS) @LDLIBFLAGS@ -o $@ $^ $(LIBS) - -#---[ Misc targets ]----------------------------------------------------------- - -$(BINDBG)/testprogram@EXEEXT@: testprogram.c $(BINDBG)/libhllapi@DLLEXT@ - @echo " CCLD `basename $@`" - @$(MKDIR) `dirname $@` - @$(CC) $(CFLAGS) $(PW3270_CFLAGS) -L$(BINDBG) $(DEBUG_CFLAGS) -lhllapi -o $@ testprogram.c - -test: $(BINDBG)/testprogram@EXEEXT@ - -run: $(BINDBG)/testprogram@EXEEXT@ - @cd $(BINDBG) ; ./testprogram@EXEEXT@ - -install: $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ - @$(MKDIR) $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins - @$(INSTALL_PROGRAM) $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ $(DESTDIR)$(libdir)/$(PACKAGE_NAME)-plugins - -$(DEBDIR)/$(MODULE_NAME).install: Makefile - @$(MKDIR) `dirname $@` - @rm -f $@ - @echo $(libdir)/$(PACKAGE_NAME)-plugins/$(MODULE_NAME)@DLLEXT@ > $@ - -clean: - @rm -fr $(OBJDIR) - @rm -fr $(BINDIR) - @rm -f testprogram@EXEEXT@ - @find . -name "*~" -exec rm -f {} \; diff --git a/src/plugins/remotectl/calls.c b/src/plugins/remotectl/calls.c deleted file mode 100644 index 2b276fb..0000000 --- a/src/plugins/remotectl/calls.c +++ /dev/null @@ -1,436 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA, 02111-1307, USA - * - * Este programa está nomeado como calls.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - - #include - #include - #include - #include - #include - #include - #include - #include - #include "client.h" - - #undef trace - #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } } - -/*--[ Globals ]--------------------------------------------------------------------------------------*/ - - HMODULE hModule = NULL; - void * hSession = NULL; - - static void * (*session_new)(const char *model) = NULL; - static void (*session_free)(void *h) = NULL; - static const char * (*get_revision)(void) = NULL; - static int (*host_connect)(void *h,const char *n, int wait) = NULL; - static int (*host_is_connected)(void *h) = NULL; - static int (*wait_for_ready)(void *h, int seconds) = NULL; - static void (*host_disconnect)(void *h) = NULL; - static int (*script_sleep)(void *h, int seconds) = NULL; - static LIB3270_MESSAGE (*get_message)(void *h) = NULL; - static char * (*get_text)(void *h, int row, int col, int len) = NULL; - static char * (*get_text_at_offset)(void *h, int offset, int len) = NULL; - - static void * (*release_memory)(void *p) = NULL; - static int (*action_enter)(void *h) = NULL; - static int (*set_text_at)(void *h, int row, int col, const unsigned char *str) = NULL; - static int (*cmp_text_at)(void *h, int row, int col, const char *text) = NULL; - static int (*pfkey)(void *hSession, int key) = NULL; - static int (*pakey)(void *hSession, int key) = NULL; - static int (*getcursor)(void *hSession) = NULL; - static int (*setcursor)(void *hSession, int baddr) = NULL; - - static const struct _entry_point - { - void **call; - void * pipe; - const char * name; - } entry_point[] = - { - { (void **) &session_new, (void *) hllapi_pipe_init, "lib3270_session_new" }, - { (void **) &session_free, (void *) hllapi_pipe_deinit, "lib3270_session_free" }, - { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, - { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, - { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" }, - { (void **) &host_is_connected, (void *) hllapi_pipe_is_connected, "lib3270_in_tn3270e" }, - { (void **) &wait_for_ready, (void *) hllapi_pipe_wait_for_ready, "lib3270_wait_for_ready" }, - { (void **) &script_sleep, (void *) hllapi_pipe_sleep, "lib3270_wait" }, - { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, - { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, - { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, - { (void **) &action_enter, (void *) hllapi_pipe_enter, "lib3270_enter" }, - { (void **) &set_text_at, (void *) hllapi_pipe_set_text_at, "lib3270_set_string_at" }, - { (void **) &cmp_text_at, (void *) hllapi_pipe_cmp_text_at, "lib3270_cmp_text_at" }, - { (void **) &pfkey, (void *) hllapi_pipe_pfkey, "lib3270_pfkey" }, - { (void **) &pakey, (void *) hllapi_pipe_pakey, "lib3270_pakey" }, - { (void **) &setcursor, (void *) hllapi_pipe_setcursor, "lib3270_set_cursor_address" }, - { (void **) &getcursor, (void *) hllapi_pipe_getcursor, "lib3270_get_cursor_address" }, - { (void **) &get_text_at_offset, (void *) hllapi_pipe_get_text, "lib3270_get_text" }, - { NULL, NULL } - }; - -// http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx -#ifndef LOAD_LIBRARY_SEARCH_DEFAULT_DIRS - #define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000 -#endif // LOAD_LIBRARY_SEARCH_DEFAULT_DIRS - -#ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR - #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100 -#endif // LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR - -/*--[ Implement ]------------------------------------------------------------------------------------*/ - - __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode) - { - if(!mode) - return EINVAL; - - trace("%s(%s)",__FUNCTION__,(char *) mode); - - if(mode && *mode) - { - // Get pointers to the pipe based calls - int f; - - trace("%s: Loading pipe based calls",__FUNCTION__); - for(f=0;entry_point[f].name;f++) - *entry_point[f].call = entry_point[f].pipe; - - } - else - { - // Direct mode, load lib3270.dll, get pointers to the calls - static const char *dllname = "lib3270.dll." PACKAGE_VERSION; - - int f; - HMODULE kernel; - HANDLE cookie = NULL; - DWORD rc; - HANDLE (*AddDllDirectory)(PCWSTR NewDirectory); - BOOL (*RemoveDllDirectory)(HANDLE Cookie); - UINT errorMode; - char datadir[4096]; - - trace("hModule=%p",hModule); - if(hModule) - return EBUSY; - - kernel = LoadLibrary("kernel32.dll"); - AddDllDirectory = (HANDLE (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory"); - RemoveDllDirectory = (BOOL (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory"); - - // Notify user in case of error loading protocol DLL - // http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v=vs.85).aspx - errorMode = SetErrorMode(1); - - memset(datadir,' ',4095); - datadir[4095] = 0; - - if(hllapi_get_datadir(datadir)) - { - char buffer[4096]; - wchar_t path[4096]; - - mbstowcs(path, datadir, 4095); - trace("Datadir=[%s] AddDllDirectory=%p RemoveDllDirectory=%p\n",datadir,AddDllDirectory,RemoveDllDirectory); - if(AddDllDirectory) - cookie = AddDllDirectory(path); - -#ifdef DEBUG - snprintf(buffer,4096,"%s\\.bin\\Debug\\%s",datadir,dllname); -#else - snprintf(buffer,4096,"%s\\%s",datadir,dllname); -#endif // DEBUG - - hModule = LoadLibrary(buffer); - - trace("%s hModule=%p rc=%d",buffer,hModule,(int) GetLastError()); - - if(hModule == NULL) - { - // Enable DLL error popup and try again with full path - SetErrorMode(0); - hModule = LoadLibraryEx(buffer,NULL,LOAD_LIBRARY_SEARCH_DEFAULT_DIRS|LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); - } - - rc = GetLastError(); - - trace("%s hModule=%p rc=%d",buffer,hModule,(int) rc); - } - else - { - hModule = LoadLibrary(dllname); - rc = GetLastError(); - } - - SetErrorMode(errorMode); - - trace("%s hModule=%p rc=%d",dllname,hModule,(int) rc); - - if(cookie && RemoveDllDirectory) - RemoveDllDirectory(cookie); - - if(kernel) - FreeLibrary(kernel); - - if(!hModule) - return rc; - - // Get library entry pointers - for(f=0;entry_point[f].name;f++) - { - void *ptr = (void *) GetProcAddress(hModule,entry_point[f].name); - - trace("%d %s=%p\n",f,entry_point[f].name,ptr); - - if(!ptr) - { - fprintf(stderr,"Can´t load \"%s\"\n",entry_point[f].name); - hllapi_deinit(); - return ENOENT; - } - *entry_point[f].call = ptr; - } - - } - // Get session handle - hSession = session_new((const char *) mode); - trace("%s ok hSession=%p\n",__FUNCTION__,hSession); - - return hSession ? 0 : -1; - } - - __declspec (dllexport) DWORD __stdcall hllapi_deinit(void) - { - int f; - - // Release session - if(hSession && session_free) - session_free(hSession); - - for(f=0;entry_point[f].name;f++) - *entry_point[f].call = NULL; - - if(hModule != NULL) - { - FreeLibrary(hModule); - hModule = NULL; - } - - return 0; - } - - __declspec (dllexport) DWORD __stdcall hllapi_get_revision(void) - { - if(!get_revision) - return 0; - return (DWORD) atoi(get_revision()); - } - - __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait) - { - if(!(host_connect && hSession && uri)) - return EINVAL; - - return host_connect(hSession,uri,wait); - } - - __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void) - { - if(!(host_is_connected && hSession)) - return EINVAL; - - return host_is_connected(hSession); - } - - __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void) - { - if(!(host_disconnect && hSession)) - return EINVAL; - - host_disconnect(hSession); - - return 0; - } - - __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds) - { - if(!(wait_for_ready && hSession)) - return EINVAL; - - trace("%s seconds=%d\n", __FUNCTION__, (int) seconds); - - return (DWORD) wait_for_ready(hSession,(int) seconds); - } - - __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds) - { - if(!(script_sleep && hSession)) - return EINVAL; - - return (DWORD) script_sleep(hSession,(int) seconds); - } - - __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void) - { - if(!(get_message && hSession)) - return EINVAL; - return (DWORD) get_message(hSession); - } - - __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer) - { - char * text; - int len; - - if(!(get_text && release_memory && hSession)) - return EINVAL; - - trace("%s row=%d col=%d buffer=%p",__FUNCTION__,row,col,buffer); - len = strlen(buffer); - - trace(" len=%d",len); - - text = get_text(hSession,row,col,len); - - trace(" text=%p errno=%d %s\n",text,errno,strerror(errno)); - - if(!text) - return EINVAL; - - strncpy(buffer,text,len); - release_memory(text); - - trace("text:\n%s\n",buffer); - - return 0; - } - - __declspec (dllexport) DWORD __stdcall hllapi_enter(void) - { - if(!(action_enter && hSession)) - return EINVAL; - - return (DWORD) action_enter(hSession); - } - - __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text) - { - if(!(set_text_at && hSession)) - return EINVAL; - - return (DWORD) set_text_at(hSession,row,col,(const unsigned char *) text); - } - - __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text) - { - if(!(cmp_text_at && hSession)) - return EINVAL; - - return (DWORD) cmp_text_at(hSession,row,col,(const char *) text); - } - - __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key) - { - if(!(pfkey && hSession)) - return EINVAL; - - return (DWORD) pfkey(hSession,key); - } - - __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key) - { - if(!(pfkey && hSession)) - return EINVAL; - - return (DWORD) pakey(hSession,key); - } - - __declspec (dllexport) DWORD __stdcall hllapi_get_datadir(LPSTR datadir) - { - HKEY hKey = 0; - unsigned long datalen = strlen(datadir); - - *datadir = 0; - - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) - { - unsigned long datatype; // #defined in winnt.h (predefined types 0-11) - if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) != ERROR_SUCCESS) - *datadir = 0; - RegCloseKey(hKey); - } - - return *datadir; - } - - __declspec (dllexport) DWORD __stdcall hllapi_setcursor(WORD pos) - { - if(!(setcursor && hSession)) - return EINVAL; - trace("%s(%d)",__FUNCTION__,pos); - return setcursor(hSession,pos-1); - } - - __declspec (dllexport) DWORD __stdcall hllapi_getcursor() - { - if(!(getcursor && hSession)) - return -EINVAL; - return getcursor(hSession)+1; - } - - __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD pos, LPSTR buffer, WORD len) - { - char *text; - - trace("%s(%d,%d)",__FUNCTION__,pos,len); - - if(len < 0) - len = strlen(buffer); - - if(!(get_text_at_offset && hSession)) - return EINVAL; - - if(len > strlen(buffer)) - len = strlen(buffer); - - trace("len=%d",len); - text = get_text_at_offset(hSession,pos-1,len); - - trace("text=\n%s\n",text); - - if(!text) - return -1; - - memcpy(buffer,text,len); - - release_memory(text); - - return 0; - } diff --git a/src/plugins/remotectl/client.h b/src/plugins/remotectl/client.h deleted file mode 100644 index 489503a..0000000 --- a/src/plugins/remotectl/client.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA, 02111-1307, USA - * - * Este programa está nomeado como private.h e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - - #include - #include - - #ifndef ETIMEDOUT - #define ETIMEDOUT 1238 - #endif // ETIMEDOUT - - #define PIPE_BUFFER_LENGTH 8192 - - #define set_active(x) /* x */ - - void * hllapi_pipe_init(const char *id); - void hllapi_pipe_deinit(void *h); - const char * hllapi_pipe_get_revision(void); - void hllapi_pipe_release_memory(void *p); - int hllapi_pipe_connect(void *h, const char *n, int wait); - void hllapi_pipe_disconnect(void *h); - LIB3270_MESSAGE hllapi_pipe_get_message(void *h); - char * hllapi_pipe_get_text_at(void *h, int row, int col, int len); - char * hllapi_pipe_get_text(void *h, int offset, int len); - int hllapi_pipe_enter(void *h); - int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str); - int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text); - int hllapi_pipe_pfkey(void *h, int key); - int hllapi_pipe_pakey(void *h, int key); - int hllapi_pipe_wait_for_ready(void *h, int seconds); - int hllapi_pipe_sleep(void *h, int seconds); - int hllapi_pipe_is_connected(void *h); - int hllapi_pipe_getcursor(void *h); - int hllapi_pipe_setcursor(void *h, int baddr); - - diff --git a/src/plugins/remotectl/hllapi.c b/src/plugins/remotectl/hllapi.c deleted file mode 100644 index 647964a..0000000 --- a/src/plugins/remotectl/hllapi.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA, 02111-1307, USA - * - * Este programa está nomeado como hllapi.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - - #include - #include - #include - #include - #include - #include - #include - - #undef trace - #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } } - -/*--[ Prototipes ]-----------------------------------------------------------------------------------*/ - - static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc); - static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc); - static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc); - static int copy_ps_to_str(char *buffer, unsigned short *length, unsigned short *rc); - - static int get_cursor_position(char *buffer, unsigned short *length, unsigned short *rc); - static int set_cursor_position(char *buffer, unsigned short *length, unsigned short *rc); - -/*--[ Globals ]--------------------------------------------------------------------------------------*/ - - static const struct _hllapi_call - { - unsigned long func; - int (*exec)(char *buffer, unsigned short *length, unsigned short *rc); - } hllapi_call[] = - { - { HLLAPI_CMD_CONNECTPS, connect_ps }, - { HLLAPI_CMD_DISCONNECTPS, disconnect_ps }, - { HLLAPI_CMD_GETREVISION, get_library_revision }, - { HLLAPI_CMD_QUERYCURSOR, get_cursor_position }, - { HLLAPI_CMD_SETCURSOR, set_cursor_position }, - { HLLAPI_CMD_COPYPSTOSTR, copy_ps_to_str }, - }; - -/*--[ Implement ]------------------------------------------------------------------------------------*/ - -#ifdef _WIN32 - __declspec (dllexport) int __stdcall hllapi(LPWORD func, LPSTR buffer, LPWORD length, LPWORD rc) -#else - LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc) -#endif // _WIN32 -{ - int f; - - trace("%s(%d)",__FUNCTION__,*func); - - for(f=0;f< (sizeof (hllapi_call) / sizeof ((hllapi_call)[0]));f++) - { - if(hllapi_call[f].func == *func) - return hllapi_call[f].exec(buffer,length,rc); - } - - *rc = HLLAPI_STATUS_BAD_PARAMETER; - - return *rc; -} - -static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc) -{ - char *tempbuffer = NULL; - - trace("%s: len=%d buflen=%d",__FUNCTION__,*length,strlen(buffer)); - - if(strlen(buffer) > *length) - buffer[*length] = 0; - - if(!strrchr(buffer,':')) - { - int sz = strlen(buffer); - - tempbuffer = malloc(sz+2); - strcpy(tempbuffer,buffer); - tempbuffer[sz-1] = ':'; - tempbuffer[sz] = buffer[sz-1]; - tempbuffer[sz+1] = 0; - buffer = tempbuffer; - } - - if(hllapi_init(buffer) == 0) - *rc = HLLAPI_STATUS_SUCESS; - else - *rc = HLLAPI_STATUS_UNAVAILABLE; - - if(tempbuffer) - free(tempbuffer); - - return 0; -} - -static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc) -{ - *rc = hllapi_deinit(); - return 0; -} - -static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc) -{ - *rc = hllapi_get_revision(); - return 0; -} - -static int get_cursor_position(char *buffer, unsigned short *length, unsigned short *rc) -{ - int pos = hllapi_getcursor(); - - trace("%s(%d)",__FUNCTION__,pos); - - if(pos < 0) - return -1; - - *rc = pos; - return 0; -} - -static int set_cursor_position(char *buffer, unsigned short *length, unsigned short *rc) -{ - trace("%s(%d)",__FUNCTION__,*rc); - *rc = hllapi_setcursor(*rc); - return 0; -} - -static int copy_ps_to_str(char *buffer, unsigned short *length, unsigned short *rc) -{ - // Length Length of the target data string. - // PS Position Position within the host presentation space of the first byte in your target data string. - return hllapi_get_screen(*rc,buffer,*length); -} - -/* - static int cmd_connect_ps(const char *name) - { -#ifdef WIN32 - - static DWORD dwMode = PIPE_READMODE_MESSAGE; - char PipeName[4096]; - - if(hPipe != INVALID_HANDLE_VALUE) - return 0; - - snprintf(PipeName,4095,"\\\\.\\pipe\\%s",name); - - if(!WaitNamedPipe(PipeName,NMPWAIT_USE_DEFAULT_WAIT)) - return ENOENT; - - hPipe = CreateFile(PipeName,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); - - if(hPipe == INVALID_HANDLE_VALUE) - return GetLastError(); - - if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) - return GetLastError(); - - trace("Pipe %ld open",(unsigned long) hPipe); -#else - - #error Not implemented - -#endif // WIN32 - - return 0; - } - - - static char * run_query(unsigned long func, const char *arg, size_t *length, unsigned short *rc) - { - char *outBuffer = NULL; - -#ifdef WIN32 - - if(hPipe == INVALID_HANDLE_VALUE) - { - trace("%s: Invalid pipe handle",__FUNCTION__); - *rc = EPERM; - } - else - { - HLLAPI_DATA *buffer = malloc(HLLAPI_MAXLENGTH+1); - DWORD cbSize = sizeof(HLLAPI_DATA) + *length; - HLLAPI_DATA *data = malloc(cbSize+1); - - memset(buffer,0,HLLAPI_MAXLENGTH); - - data->id = HLLAPI_REQUEST_QUERY; - data->func = func; - data->rc = *rc; - data->value = *length; - - if(arg && *length > 0) - memcpy(data->string,arg,*length); - - memset(buffer,0,HLLAPI_MAXLENGTH); - - if(!TransactNamedPipe(hPipe,(LPVOID) data,cbSize,buffer,HLLAPI_MAXLENGTH,&cbSize,NULL)) - { - trace("Error %d in TransactNamedPipe",(int) GetLastError()); - *rc = GetLastError(); - } - else - { - *rc = buffer->rc; - *length = buffer->value; - - trace("buffer->id=%d buffer->value=%d rc=%d",buffer->id,buffer->value,buffer->rc); - - if(buffer->value > 0 && buffer->id == HLLAPI_RESPONSE_TEXT) - { - outBuffer = malloc(buffer->value+1); - memcpy(outBuffer,buffer->string,buffer->value); - outBuffer[buffer->value] = 0; - - trace("outBuffer=[%s]",outBuffer); - } - } - - free(data); - free(buffer); - } - -#else - - #error NOT IMPLEMENTED - -#endif // WIN32 - - return outBuffer; - } - - static void copyString(char *str, unsigned short *length, const char *msg) - { - size_t len = strlen(msg); - - if(len > *length) - len = *length; - else - *length = len; - - memcpy(str,msg,*length); - } - -#ifdef _WIN32 - __declspec (dllexport) int __stdcall hllapi(LPWORD func, LPSTR buffer, LPWORD length, LPWORD rc) -#else - LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc) -#endif // _WIN32 - { - char * inBuffer = NULL; - char * outBuffer = NULL; - size_t szOutBuffer; - - if(*length < 0 || *length > HLLAPI_MAXLENGTH) - { - *rc = EINVAL; - return 0; - } - - szOutBuffer = (size_t) *length; - - // Copy input argument - if(*length) - { - inBuffer = malloc(*length+1); - memcpy(inBuffer,buffer,*length); - inBuffer[*length] = 0; - } - - // Clear output buffer - memset(buffer,' ',*length); - buffer[*length] = 0; - - switch(*func) - { - case HLLAPI_CMD_CONNECTPS: - *rc = cmd_connect_ps(inBuffer); - if(!*rc) - { - outBuffer = run_query(*func, inBuffer, &szOutBuffer, rc); - if(*rc) - { - trace("Closing pipe rc=%d",*rc); - CloseHandle(hPipe); - hPipe = INVALID_HANDLE_VALUE; - } - } - break; - - case HLLAPI_CMD_DISCONNECTPS: -#ifdef WIN32 - if(hPipe == INVALID_HANDLE_VALUE) - { - *rc = EINVAL; - } - else - { - outBuffer = run_query(*func, inBuffer, &szOutBuffer, rc); - CloseHandle(hPipe); - hPipe = INVALID_HANDLE_VALUE; - } -#endif // WIN32 - break; - - default: - trace("Calling function %d",(int) *func); - outBuffer = run_query(*func, inBuffer, &szOutBuffer, rc); - } - - if(*rc) - copyString(buffer,length,strerror(*rc)); - else if(outBuffer) - { - if(szOutBuffer < *length) - *length = szOutBuffer; - - copyString(buffer,length,outBuffer); - } - if(outBuffer) - free(outBuffer); - - free(inBuffer); - return 0; - } - -*/ diff --git a/src/plugins/remotectl/hllapi.cbp b/src/plugins/remotectl/hllapi.cbp deleted file mode 100644 index 89cfc8e..0000000 --- a/src/plugins/remotectl/hllapi.cbp +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - diff --git a/src/plugins/remotectl/packets.h b/src/plugins/remotectl/packets.h deleted file mode 100644 index ae6f0da..0000000 --- a/src/plugins/remotectl/packets.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA, 02111-1307, USA - * - * Este programa está nomeado como packets.h e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - - typedef enum _hllapi_packet - { - HLLAPI_PACKET_CONNECT, - HLLAPI_PACKET_DISCONNECT, - HLLAPI_PACKET_GET_PROGRAM_MESSAGE, - HLLAPI_PACKET_GET_TEXT_AT_OFFSET, - HLLAPI_PACKET_GET_TEXT_AT, - HLLAPI_PACKET_SET_TEXT_AT, - HLLAPI_PACKET_CMP_TEXT_AT, - HLLAPI_PACKET_ENTER, - HLLAPI_PACKET_PFKEY, - HLLAPI_PACKET_PAKEY, - HLLAPI_PACKET_SET_CURSOR_POSITION, - HLLAPI_PACKET_GET_CURSOR_POSITION, - HLLAPI_PACKET_INPUT_STRING, - HLLAPI_PACKET_IS_CONNECTED, - HLLAPI_PACKET_SET_CURSOR, - HLLAPI_PACKET_GET_CURSOR, - - HLLAPI_PACKET_INVALID - - } HLLAPI_PACKET; - -#pragma pack(1) - -struct hllapi_packet_result -{ - int rc; -}; - -struct hllapi_packet_text_result -{ - int rc; - char text[1]; -}; - -struct hllapi_packet_query -{ - unsigned char packet_id; -}; - -struct hllapi_packet_connect -{ - unsigned char packet_id; - unsigned char wait; - char hostname[1]; -}; - -struct hllapi_packet_keycode -{ - unsigned char packet_id; - unsigned short keycode; -}; - -struct hllapi_packet_cursor -{ - unsigned char packet_id; - unsigned short row; - unsigned short col; -}; - -struct hllapi_packet_text -{ - unsigned char packet_id; - char text[1]; -}; - -struct hllapi_packet_at -{ - unsigned char packet_id; - unsigned short row; - unsigned short col; - unsigned short len; -}; - -struct hllapi_packet_text_at -{ - unsigned char packet_id; - unsigned short row; - unsigned short col; - char text[1]; -}; - -struct hllapi_packet_query_at -{ - unsigned char packet_id; - unsigned short row; - unsigned short col; - unsigned short len; -}; - -struct hllapi_packet_wait -{ - unsigned char packet_id; - int timeout; -}; - -struct hllapi_packet_addr -{ - unsigned char packet_id; - unsigned short addr; -}; - -struct hllapi_packet_query_offset -{ - unsigned char packet_id; - unsigned short addr; - unsigned short len; -}; - - - -#pragma pack() - diff --git a/src/plugins/remotectl/pipesource.c b/src/plugins/remotectl/pipesource.c deleted file mode 100644 index b72c56b..0000000 --- a/src/plugins/remotectl/pipesource.c +++ /dev/null @@ -1,385 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA, 02111-1307, USA - * - * Este programa está nomeado como pipesource.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - */ - - #include - #include - - #include - #include - #include "remotectl.h" - -/*---[ Defines ]----------------------------------------------------------------------------*/ - - #pragma pack(1) - - typedef struct _pipe_source - { - GSource gsrc; - HANDLE hPipe; - - enum _PIPE_STATE - { - PIPE_STATE_WAITING, - PIPE_STATE_READ, - PIPE_STATE_PENDING_READ, - - PIPE_STATE_UNDEFINED, - } state; - - OVERLAPPED overlap; - unsigned char buffer[PIPE_BUFFER_LENGTH+1]; - } pipe_source; - - #pragma pack() - -/*---[ GSource ]----------------------------------------------------------------------------*/ - -static void wait_for_client(pipe_source *source) -{ - set_active(FALSE); - if(ConnectNamedPipe(source->hPipe,&source->overlap)) - { - popup_lasterror("%s",_( "Error in ConnectNamedPipe" )); - return; - } - - switch(GetLastError()) - { - // The overlapped connection in progress. - case ERROR_IO_PENDING: - // trace("%s: ERROR_IO_PENDING",__FUNCTION__); - source->state = PIPE_STATE_WAITING; - break; - - // Client is already connected, so signal an event. - case ERROR_PIPE_CONNECTED: - trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__); - set_active(TRUE); - if(SetEvent(source->overlap.hEvent)) - break; - - // If an error occurs during the connect operation... - default: - popup_lasterror("%s", _( "ConnectNamedPipe failed" )); - } - - } - - static gboolean IO_prepare(GSource *source, gint *timeout) - { - /* - * Called before all the file descriptors are polled. - * If the source can determine that it is ready here - * (without waiting for the results of the poll() call) - * it should return TRUE. - * - * It can also return a timeout_ value which should be the maximum - * timeout (in milliseconds) which should be passed to the poll() call. - * The actual timeout used will be -1 if all sources returned -1, - * or it will be the minimum of all the timeout_ values - * returned which were >= 0. - * - */ - if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) - { - // trace("%s: source=%p",__FUNCTION__,source); - return TRUE; - } - - *timeout = 10; - return FALSE; - } - - static gboolean IO_check(GSource *source) - { - /* - * Called after all the file descriptors are polled. - * The source should return TRUE if it is ready to be dispatched. - * Note that some time may have passed since the previous prepare - * function was called, so the source should be checked again here. - * - */ - if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) - return TRUE; - - return FALSE; - } - - static void process_input(pipe_source *source, DWORD cbRead) - { - HLLAPI_DATA * data = (HLLAPI_DATA *) source->buffer; - QUERY * qry = g_malloc0(sizeof(QUERY)+cbRead+1); - - qry->hPipe = source->hPipe; - qry->text = (const gchar *) (qry+1); - - if(data->id == HLLAPI_REQUEST_QUERY) - { - // HLLAPI query - qry->cmd = (int) data->func; - qry->pos = (int) data->rc; - qry->length = data->value; - memcpy((gchar *)(qry->text),data->string,qry->length); - } - else - { - qry->cmd = -1; - } - - enqueue_request(qry); - } - - void request_complete(QUERY *qry, int rc, const gchar *text) - { - request_buffer(qry,rc,strlen(text),(const gpointer) text); - } - - void request_status(QUERY *qry, int rc) - { - if(rc) - { - const gchar *msg = strerror(rc); - request_buffer(qry, rc, strlen(msg), (const gpointer) msg); - } - else - { - request_buffer(qry, rc, 0, NULL); - } - } - - void request_value(QUERY *qry, int rc, unsigned int value) - { - HLLAPI_DATA data; - - memset(&data,0,sizeof(data)); - data.id = HLLAPI_RESPONSE_VALUE; - data.func = qry->cmd; - data.rc = rc; - data.value = value; - -#ifdef WIN32 - { - DWORD wrote = sizeof(data); - WriteFile(qry->hPipe,&data,wrote,&wrote,NULL); - trace("Wrote=%d len=%d",(int) wrote, sizeof(data)); - } -#endif // WIN32 - - g_free(qry); - - - } - - void request_buffer(QUERY *qry, int rc, size_t szBuffer, const gpointer buffer) - { - size_t sz; - HLLAPI_DATA *data; - - if(buffer) - { - sz = sizeof(HLLAPI_DATA)+szBuffer; - data = g_malloc0(sz); - data->id = HLLAPI_RESPONSE_TEXT; - memcpy(data->string,buffer,szBuffer); - } - else - { - sz = sizeof(HLLAPI_DATA); - data = g_malloc0(sz); - data->id = HLLAPI_RESPONSE_VALUE; - } - - data->func = qry->cmd; - data->rc = rc; - data->value = szBuffer; - - trace("rc=%d data->len=%d",rc,(int) szBuffer); - -#ifdef WIN32 - { - DWORD wrote = sz; - WriteFile(qry->hPipe,data,wrote,&wrote,NULL); - trace("Wrote=%d len=%d",(int) wrote, (int) sz); - } -#endif // WIN32 - - g_free(data); - g_free(qry); - - } - - static void read_input_pipe(pipe_source *source) - { - DWORD cbRead = 0; - - if(ReadFile(source->hPipe,source->buffer,PIPE_BUFFER_LENGTH,&cbRead,&source->overlap) && cbRead > 0) - process_input(source,cbRead); - - // The read operation is still pending. - switch(GetLastError()) - { - case 0: - break; - - case ERROR_IO_PENDING: - // trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__); - source->state = PIPE_STATE_PENDING_READ; - break; - - case ERROR_PIPE_LISTENING: - // trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__); - source->state = PIPE_STATE_READ; - break; - - case ERROR_BROKEN_PIPE: - trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__); - - if(!DisconnectNamedPipe(source->hPipe)) - { - set_active(FALSE); - popup_lasterror("%s",_( "Error in DisconnectNamedPipe" )); - } - else - { - wait_for_client(source); - } - break; - - case ERROR_PIPE_NOT_CONNECTED: - trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__); - set_active(FALSE); - break; - - default: - if(source->hPipe != INVALID_HANDLE_VALUE) - popup_lasterror("%s",_( "Error receiving message from pipe" ) ); - } - - } - - static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer data) - { - /* - * Called to dispatch the event source, - * after it has returned TRUE in either its prepare or its check function. - * The dispatch function is passed in a callback function and data. - * The callback function may be NULL if the source was never connected - * to a callback using g_source_set_callback(). The dispatch function - * should call the callback function with user_data and whatever additional - * parameters are needed for this type of event source. - */ - BOOL fSuccess; - DWORD cbRead = 0; -// DWORD dwErr = 0; - - fSuccess = GetOverlappedResult(((pipe_source *) source)->hPipe,&((pipe_source *) source)->overlap,&cbRead,FALSE ); - - // trace("%s: source=%p data=%p Result=%s cbRead=%d",__FUNCTION__,source,data,fSuccess ? "Success" : "Unsuccess",(int) cbRead); - - switch(((pipe_source *) source)->state) - { - case PIPE_STATE_WAITING: - if(fSuccess) - { - trace("Pipe connected (cbRet=%d)",(int) cbRead); - set_active(TRUE); - ((pipe_source *) source)->state = PIPE_STATE_READ; - } - else - { - popup_lasterror("%s", _( "Pipe connection failed" )); - } - break; - - case PIPE_STATE_READ: - // trace("Reading pipe (cbRead=%d)",(int) cbRead); - read_input_pipe( (pipe_source *) source); - break; - - case PIPE_STATE_PENDING_READ: - if(fSuccess && cbRead > 0) - process_input((pipe_source *) source,cbRead); - ((pipe_source *) source)->state = PIPE_STATE_READ; - break; - -//#ifdef DEBUG -// default: -// trace("%s: source=%p data=%p Unexpected mode %d",__FUNCTION__,source,data,((pipe_source *) source)->state); -//#endif - } - - return TRUE; - } - - static void IO_finalize(GSource *source) - { -// trace("%s: source=%p",__FUNCTION__,source); - - if( ((pipe_source *) source)->hPipe != INVALID_HANDLE_VALUE) - { - CloseHandle(((pipe_source *) source)->hPipe); - ((pipe_source *) source)->hPipe = INVALID_HANDLE_VALUE; - } - - } - - static gboolean IO_closure(gpointer data) - { -// trace("%s: data=%p",__FUNCTION__,data); - return 0; - } - - - void init_source_pipe(HANDLE hPipe) - { - static GSourceFuncs pipe_source_funcs = - { - IO_prepare, - IO_check, - IO_dispatch, - IO_finalize, - IO_closure, - NULL - }; - - pipe_source *source = (pipe_source *) g_source_new(&pipe_source_funcs,sizeof(pipe_source)); - - source->hPipe = hPipe; - source->state = PIPE_STATE_WAITING; - source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL); - - g_source_attach((GSource *) source,NULL); - - wait_for_client(source); - - return; - } - diff --git a/src/plugins/remotectl/pluginmain.c b/src/plugins/remotectl/pluginmain.c deleted file mode 100644 index 9e16f0c..0000000 --- a/src/plugins/remotectl/pluginmain.c +++ /dev/null @@ -1,807 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como pluginmain.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - * Agradecimento: - * - * Hélio Passos - * - */ - - #include "server.h" - #include "packets.h" - #include - -/*--[ Defines ]--------------------------------------------------------------------------------------*/ - - #pragma pack(1) - - typedef struct _pipe_source - { - GSource gsrc; - HANDLE hPipe; - - enum _PIPE_STATE - { - PIPE_STATE_WAITING, - PIPE_STATE_READ, - PIPE_STATE_PENDING_READ, - PIPE_STATE_UNDEFINED, - } state; - - OVERLAPPED overlap; - unsigned char buffer[PIPE_BUFFER_LENGTH+1]; - } pipe_source; - - #pragma pack() - - -/*--[ Globals ]--------------------------------------------------------------------------------------*/ - - static const gchar control_char = '@'; - -/*--[ Implement ]------------------------------------------------------------------------------------*/ - - static void IO_accept(pipe_source *source) - { - set_active(FALSE); - - if(ConnectNamedPipe(source->hPipe,&source->overlap)) - { - popup_lasterror("%s",_( "Error in ConnectNamedPipe" )); - return; - } - - switch(GetLastError()) - { - // The overlapped connection in progress. - case ERROR_IO_PENDING: - // trace("%s: ERROR_IO_PENDING",__FUNCTION__); - source->state = PIPE_STATE_WAITING; - break; - - // Client is already connected, so signal an event. - case ERROR_PIPE_CONNECTED: - trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__); - set_active(TRUE); - if(SetEvent(source->overlap.hEvent)) - break; - - // If an error occurs during the connect operation... - default: - popup_lasterror("%s", _( "ConnectNamedPipe failed" )); - } - - } - - static gboolean IO_prepare(GSource *source, gint *timeout) - { - /* - * Called before all the file descriptors are polled. - * If the source can determine that it is ready here - * (without waiting for the results of the poll() call) - * it should return TRUE. - * - * It can also return a timeout_ value which should be the maximum - * timeout (in milliseconds) which should be passed to the poll() call. - * The actual timeout used will be -1 if all sources returned -1, - * or it will be the minimum of all the timeout_ values - * returned which were >= 0. - * - */ - if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) - return TRUE; - - *timeout = 10; - return FALSE; - } - - static gboolean IO_check(GSource *source) - { - /* - * Called after all the file descriptors are polled. - * The source should return TRUE if it is ready to be dispatched. - * Note that some time may have passed since the previous prepare - * function was called, so the source should be checked again here. - * - */ - if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) - return TRUE; - - return FALSE; - } - - static void send_text(pipe_source *source, char *text) - { - struct hllapi_packet_text *pkt; - DWORD szBlock; - - if(text) - { - szBlock = sizeof(struct hllapi_packet_text)+strlen(text); - pkt = g_malloc0(szBlock); - pkt->packet_id = 0; - strcpy(pkt->text,text); - lib3270_free(text); - } - else - { - szBlock = sizeof(struct hllapi_packet_text); - pkt = g_malloc0(szBlock); - pkt->packet_id = errno ? errno : -1; - } - - WriteFile(source->hPipe,pkt,szBlock,&szBlock,NULL); - - g_free(pkt); - } - - static void send_result(pipe_source *source, int rc) - { - struct hllapi_packet_result pkt = { rc }; - DWORD wrote = sizeof(pkt); - WriteFile(source->hPipe,&pkt,wrote,&wrote,NULL); - } - - static void process_input(pipe_source *source, DWORD cbRead) - { - - trace("%s id=%d",__FUNCTION__,((struct hllapi_packet_query *) source->buffer)->packet_id); - - switch(((struct hllapi_packet_query *) source->buffer)->packet_id) - { - case HLLAPI_PACKET_CONNECT: - send_result(source,lib3270_connect( lib3270_get_default_session_handle(), - ((struct hllapi_packet_connect *) source->buffer)->hostname, - ((struct hllapi_packet_connect *) source->buffer)->wait)); - break; - - case HLLAPI_PACKET_DISCONNECT: - send_result(source,lib3270_disconnect(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_GET_PROGRAM_MESSAGE: - send_result(source,lib3270_get_program_message(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_IS_CONNECTED: - send_result(source,lib3270_in_tn3270e(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_ENTER: - send_result(source,lib3270_enter(lib3270_get_default_session_handle())); - break; - - case HLLAPI_PACKET_PFKEY: - send_result(source,lib3270_pfkey( lib3270_get_default_session_handle(), - ((struct hllapi_packet_keycode *) source->buffer)->keycode)); - break; - - case HLLAPI_PACKET_PAKEY: - send_result(source,lib3270_pakey( lib3270_get_default_session_handle(), - ((struct hllapi_packet_keycode *) source->buffer)->keycode)); - break; - - case HLLAPI_PACKET_SET_CURSOR_POSITION: - send_result(source,lib3270_set_cursor_position( lib3270_get_default_session_handle(), - ((struct hllapi_packet_cursor *) source->buffer)->row, - ((struct hllapi_packet_cursor *) source->buffer)->col)); - break; - - case HLLAPI_PACKET_SET_TEXT_AT: - send_result(source,lib3270_set_text_at( lib3270_get_default_session_handle(), - ((struct hllapi_packet_text_at *) source->buffer)->row, - ((struct hllapi_packet_text_at *) source->buffer)->col, - (unsigned char *) ((struct hllapi_packet_text_at *) source->buffer)->text)); - break; - - case HLLAPI_PACKET_GET_TEXT_AT: - send_text(source,lib3270_get_text_at( lib3270_get_default_session_handle(), - ((struct hllapi_packet_at *) source->buffer)->row, - ((struct hllapi_packet_at *) source->buffer)->col, - ((struct hllapi_packet_at *) source->buffer)->len)); - break; - - case HLLAPI_PACKET_GET_TEXT_AT_OFFSET: - send_text(source,lib3270_get_text( lib3270_get_default_session_handle(), - ((struct hllapi_packet_query_offset *) source->buffer)->addr, - ((struct hllapi_packet_query_offset *) source->buffer)->len)); - break; - - case HLLAPI_PACKET_CMP_TEXT_AT: - send_result(source,lib3270_cmp_text_at( lib3270_get_default_session_handle(), - ((struct hllapi_packet_text_at *) source->buffer)->row, - ((struct hllapi_packet_text_at *) source->buffer)->col, - ((struct hllapi_packet_text_at *) source->buffer)->text)); - break; - - case HLLAPI_PACKET_INPUT_STRING: - send_result(source,lib3270_input_string(lib3270_get_default_session_handle(), - (unsigned char *) ((struct hllapi_packet_text *) source->buffer)->text)); - break; - - case HLLAPI_PACKET_SET_CURSOR: - send_result(source,lib3270_set_cursor_address(lib3270_get_default_session_handle(), - ((struct hllapi_packet_addr *) source->buffer)->addr)); - break; - - case HLLAPI_PACKET_GET_CURSOR: - send_result(source,lib3270_get_cursor_address(lib3270_get_default_session_handle())); - break; - - - default: - send_result(source, EINVAL); - g_message("Invalid remote request (id=%d)",source->buffer[0]); - } - - } - - static void read_input_pipe(pipe_source *source) - { - DWORD cbRead = 0; - - if(ReadFile(source->hPipe,source->buffer,PIPE_BUFFER_LENGTH,&cbRead,&source->overlap) && cbRead > 0) - process_input(source,cbRead); - - // The read operation is still pending. - switch(GetLastError()) - { - case 0: - break; - - case ERROR_IO_PENDING: - // trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__); - source->state = PIPE_STATE_PENDING_READ; - break; - - case ERROR_PIPE_LISTENING: - // trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__); - source->state = PIPE_STATE_READ; - break; - - case ERROR_BROKEN_PIPE: - trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__); - - if(!DisconnectNamedPipe(source->hPipe)) - { - set_active(FALSE); - popup_lasterror("%s",_( "Error in DisconnectNamedPipe" )); - } - else - { - IO_accept(source); - } - break; - - case ERROR_PIPE_NOT_CONNECTED: - trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__); - set_active(FALSE); - break; - - default: - if(source->hPipe != INVALID_HANDLE_VALUE) - popup_lasterror("%s",_( "Error receiving message from pipe" ) ); - } - - } - - static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer data) - { - /* - * Called to dispatch the event source, - * after it has returned TRUE in either its prepare or its check function. - * The dispatch function is passed in a callback function and data. - * The callback function may be NULL if the source was never connected - * to a callback using g_source_set_callback(). The dispatch function - * should call the callback function with user_data and whatever additional - * parameters are needed for this type of event source. - */ - BOOL fSuccess; - DWORD cbRead = 0; -// DWORD dwErr = 0; - - fSuccess = GetOverlappedResult(((pipe_source *) source)->hPipe,&((pipe_source *) source)->overlap,&cbRead,FALSE ); - - // trace("%s: source=%p data=%p Result=%s cbRead=%d",__FUNCTION__,source,data,fSuccess ? "Success" : "Unsuccess",(int) cbRead); - - switch(((pipe_source *) source)->state) - { - case PIPE_STATE_WAITING: - if(fSuccess) - { - trace("Pipe connected (cbRet=%d)",(int) cbRead); - set_active(TRUE); - ((pipe_source *) source)->state = PIPE_STATE_READ; - } - else - { - popup_lasterror("%s", _( "Pipe connection failed" )); - } - break; - - case PIPE_STATE_READ: - // trace("Reading pipe (cbRead=%d)",(int) cbRead); - read_input_pipe( (pipe_source *) source); - break; - - case PIPE_STATE_PENDING_READ: - if(fSuccess && cbRead > 0) - process_input((pipe_source *) source,cbRead); - ((pipe_source *) source)->state = PIPE_STATE_READ; - break; - - case PIPE_STATE_UNDEFINED: - break; - -//#ifdef DEBUG -// default: -// trace("%s: source=%p data=%p Unexpected mode %d",__FUNCTION__,source,data,((pipe_source *) source)->state); -//#endif - } - - return TRUE; - } - - static void IO_finalize(GSource *source) - { -// trace("%s: source=%p",__FUNCTION__,source); - - if( ((pipe_source *) source)->hPipe != INVALID_HANDLE_VALUE) - { - CloseHandle(((pipe_source *) source)->hPipe); - ((pipe_source *) source)->hPipe = INVALID_HANDLE_VALUE; - } - - } - - static gboolean IO_closure(gpointer data) - { -// trace("%s: data=%p",__FUNCTION__,data); - return 0; - } - - void popup_lasterror(const gchar *fmt, ...) - { - char buffer[4096]; - va_list arg_ptr; - int sz; - DWORD errcode = GetLastError(); - char *ptr; - LPVOID lpMsgBuf = 0; - - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); - - for(ptr=lpMsgBuf;*ptr && *ptr != '\n';ptr++); - *ptr = 0; - - va_start(arg_ptr, fmt); - vsnprintf(buffer,4095,fmt,arg_ptr); - va_end(arg_ptr); - - sz = strlen(buffer); - snprintf(buffer+sz,4096-sz,": %s\n(rc=%d)",lpMsgBuf,(int) errcode); - - printf("%s\n",buffer); - -#ifdef DEBUG - fprintf(stderr,"%s\n",buffer); - fflush(stderr); -#endif - - LocalFree(lpMsgBuf); - } - - LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window) - { - char id; - - for(id='A';id < 'Z';id++) - { - gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s_%c",pw3270_get_session_name(window),id); - gchar * ptr; - HANDLE hPipe; - - for(ptr=pipename;*ptr;ptr++) - *ptr = g_ascii_tolower(*ptr); - - hPipe = CreateNamedPipe( TEXT(pipename), // pipe name - PIPE_ACCESS_DUPLEX | // read/write access - FILE_FLAG_OVERLAPPED, // overlapped mode - PIPE_TYPE_MESSAGE | // pipe type - PIPE_READMODE_MESSAGE | // pipe mode - PIPE_WAIT, // blocking mode - 1, // number of instances - PIPE_BUFFER_LENGTH, // output buffer size - PIPE_BUFFER_LENGTH, // input buffer size - NMPWAIT_USE_DEFAULT_WAIT, // client time-out - NULL); // default security attributes - - trace("%s = %p",pipename,hPipe); - g_free(pipename); - - if(hPipe != INVALID_HANDLE_VALUE) - { - static GSourceFuncs pipe_source_funcs = - { - IO_prepare, - IO_check, - IO_dispatch, - IO_finalize, - IO_closure, - NULL - }; - pipe_source * source; - gchar * session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),id); - - pw3270_set_session_name(window,session); - g_free(session); - - source = (pipe_source *) g_source_new(&pipe_source_funcs,sizeof(pipe_source)); - - source->hPipe = hPipe; - source->state = PIPE_STATE_WAITING; - source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL); - - g_source_attach((GSource *) source,NULL); - IO_accept(source); - - return 0; - } - - } - - popup_lasterror( "%s", _( "Can´t create remote control pipe" )); - - return -1; - } - - LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window) - { - - return 0; - } - -/* - static void cmd_connectps(QUERY *qry) - { - g_message("%s","HLLAPI ConnectPS request received"); - request_status(qry,v3270_set_script(pw3270_get_terminal_widget(NULL),'H',TRUE)); - } - - static void cmd_disconnectps(QUERY *qry) - { - g_message("%s","HLLAPI DisconnectPS request received"); - request_status(qry,0); - } - - static void cmd_getrevision(QUERY *qry) - { - request_complete(qry,0,lib3270_get_revision()); - } - - static void cmd_setcursor(QUERY *qry) - { - int rc = ENOTCONN; - - if(lib3270_connected(qry->hSession)) - { - trace("%s: pos=%d row=%d col=%d",__FUNCTION__,rc,rc/80,rc%80); - lib3270_set_cursor_address(qry->hSession,qry->pos -1); - rc = 0; - } - - request_status(qry,rc); - } - - static void cmd_sendstring(QUERY *qry) - { - gchar * text; - GError * error = NULL; - gsize bytes_read; - gsize bytes_written; - const gchar * charset; - - if(!lib3270_connected(qry->hSession)) - { - request_status(qry,ENOTCONN); - return; - } - - g_get_charset(&charset); - - text = g_convert(qry->text,qry->length,lib3270_get_charset(qry->hSession),charset,&bytes_read,&bytes_written,&error); - if(text) - { - int rc = 0; - - if(strchr(text,control_char)) - { - // Convert control char - gchar * buffer = text; - char * ptr; - - for(ptr = strchr(text,control_char);ptr;ptr = strchr(buffer,control_char)) - { - *(ptr++) = 0; - - lib3270_emulate_input(qry->hSession,buffer,-1,0); - - switch(*(ptr++)) - { - case 'P': // Print - rc = pw3270_print(pw3270_get_terminal_widget(NULL), NULL, GTK_PRINT_OPERATION_ACTION_PRINT, PW3270_SRC_ALL); - break; - - case 'E': // Enter - lib3270_enter(qry->hSession); - break; - - case 'F': // Erase EOF - lib3270_eraseeof(qry->hSession); - break; - - case '1': // PF1 - lib3270_pfkey(qry->hSession,1); - break; - - case '2': // PF2 - lib3270_pfkey(qry->hSession,2); - break; - - case '3': // PF3 - lib3270_pfkey(qry->hSession,3); - break; - - case '4': // PF4 - lib3270_pfkey(qry->hSession,4); - break; - - case '5': // PF5 - lib3270_pfkey(qry->hSession,5); - break; - - case '6': // PF6 - lib3270_pfkey(qry->hSession,6); - break; - - case '7': // PF7 - lib3270_pfkey(qry->hSession,7); - break; - - case '8': // PF8 - lib3270_pfkey(qry->hSession,8); - break; - - case '9': // PF9 - lib3270_pfkey(qry->hSession,9); - break; - - case 'a': // PF10 - lib3270_pfkey(qry->hSession,10); - break; - - case 'b': // PF11 - lib3270_pfkey(qry->hSession,11); - break; - - case 'c': // PF12 - lib3270_pfkey(qry->hSession,12); - break; - } - - } - - lib3270_emulate_input(qry->hSession,buffer,-1,0); - - } - else - { - lib3270_emulate_input(qry->hSession,text,strlen(text),0); - } - g_free(text); - - request_status(qry,rc); - - return; - } - - request_complete(qry, error->code, error->message); - g_error_free(error); - - } - - struct wait - { - QUERY * qry; - time_t end; - }; - - static gboolean do_wait(struct wait *w) - { - if(lib3270_get_program_message(w->qry->hSession) == LIB3270_MESSAGE_NONE) - { - request_status(w->qry,0); - return FALSE; - } - - if(time(0) > w->end) - { - trace("%s: TIMEOUT",__FUNCTION__); - request_status(w->qry,ETIMEDOUT); - return FALSE; - } - - return TRUE; - } - - static void cmd_wait(QUERY *qry) - { - struct wait *w; - - if(lib3270_get_program_message(qry->hSession) == LIB3270_MESSAGE_NONE) - { - request_status(qry,0); - return; - } - - w = g_malloc0(sizeof(struct wait)); - w->qry = qry; - w->end = time(0)+pw3270_get_integer(pw3270_get_toplevel(),"hllapi","wait",2); - - g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) 300, (GSourceFunc) do_wait, w, g_free); - } - - static void cmd_copypstostr(QUERY *qry) - { - int rows; - int cols; - unsigned short * attr; - unsigned char * text; - int rc; - unsigned char * buffer; - size_t length; - - if(!lib3270_connected(qry->hSession)) - { - request_status(qry,ENOTCONN); - return; - } - - lib3270_get_screen_size(qry->hSession,&rows,&cols); - - if(qry->pos < 1 || (qry->pos+qry->length) >= (rows*cols)) - { - request_status(qry,EINVAL); - return; - } - - qry->pos--; - - length = (qry->length * sizeof(unsigned short)) + qry->length + 2; - text = buffer = g_malloc0(length+1); - attr = (unsigned short *) (text+qry->length+1); - - trace("%s: pos=%d length=%d",__FUNCTION__,qry->pos,qry->length); - rc = lib3270_get_contents(qry->hSession,qry->pos,qry->pos+(qry->length-1),text,attr); - - if(rc) - { - request_status(qry,rc); - } - else - { - const gchar * charset; - gchar * local; - gsize bytes_read; - gsize bytes_written; - GError * error = NULL; - - trace("Text: [%s]",text); - - g_get_charset(&charset); - - local = g_convert((const gchar *) text,-1,charset,lib3270_get_charset(qry->hSession),&bytes_read,&bytes_written,&error); - - if(!local) - { - request_complete(qry,error->code,error->message); - g_error_free(error); - } - else - { - strncpy((char *) text,(const char *) local,qry->length); - - trace("response: [%s] len=%d",buffer,length); - request_buffer(qry,0,length,buffer); - g_free(local); - } - } - - g_free(buffer); - } - - static void cmd_querycursor(QUERY *qry) - { - request_value(qry,0,lib3270_get_cursor_address(qry->hSession)); - } - - void enqueue_request(QUERY *qry) - { - static const struct _cmd - { - int cmd; - void (*exec)(QUERY *qry); - } cmd[] = - { - { HLLAPI_CMD_CONNECTPS, cmd_connectps }, // 1 - { HLLAPI_CMD_DISCONNECTPS, cmd_disconnectps }, // 2 - { HLLAPI_CMD_INPUTSTRING, cmd_sendstring }, // 3 - { HLLAPI_CMD_WAIT, cmd_wait }, // 4 -// { HLLAPI_CMD_COPYPS, }, // 5 -// { HLLAPI_CMD_SEARCHPS, }, // 6 - { HLLAPI_CMD_QUERYCURSOR, cmd_querycursor }, // 7 - - { HLLAPI_CMD_COPYPSTOSTR, cmd_copypstostr }, // 8 - -// { HLLAPI_CMD_COPYSTRTOPS }, // 15 - - { HLLAPI_CMD_SETCURSOR, cmd_setcursor }, // 40 - -// { HLLAPI_CMD_SENDFILE }, // 90 -// { HLLAPI_CMD_RECEIVEFILE }, - - - { HLLAPI_CMD_GETREVISION, cmd_getrevision }, - }; - - - - int f; - - trace("HLLAPI function %d",(int) qry->cmd); - - qry->hSession = lib3270_get_default_session_handle(); - - for(f=0;fcmd) - { - cmd[f].exec(qry); - return; - } - } - - g_warning("Unexpected HLLAPI function %d",(int) qry->cmd); - request_status(qry,EINVAL); - } - - G_GNUC_INTERNAL void set_active(gboolean on) - { - v3270_set_script(pw3270_get_terminal_widget(NULL),'H',on); - } - -*/ diff --git a/src/plugins/remotectl/remote.c b/src/plugins/remotectl/remote.c deleted file mode 100644 index 4cac7cf..0000000 --- a/src/plugins/remotectl/remote.c +++ /dev/null @@ -1,334 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA, 02111-1307, USA - * - * Este programa está nomeado como calls.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - - #include - #include - #include - #include - #include - #include - #include - - #include "client.h" - #include "packets.h" - -/*--[ Globals ]--------------------------------------------------------------------------------------*/ - -/*--[ Implement ]------------------------------------------------------------------------------------*/ - - void * hllapi_pipe_init(const char *id) - { - HANDLE hPipe = INVALID_HANDLE_VALUE; - static DWORD dwMode = PIPE_READMODE_MESSAGE; - char buffer[4096]; - char * name = strdup(id); - char * ptr; - - trace("%s(%s)",__FUNCTION__,id); - - for(ptr=name;*ptr;ptr++) - { - if(*ptr == ':') - *ptr = '_'; - } - - snprintf(buffer,4095,"\\\\.\\pipe\\%s",name); - - free(name); - - trace("Opening \"%s\"",buffer); - - if(!WaitNamedPipe(buffer,NMPWAIT_USE_DEFAULT_WAIT)) - { - trace("%s: Pipe not found",__FUNCTION__); - errno = ENOENT; - return NULL; - } - - hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); - - if(hPipe == INVALID_HANDLE_VALUE) - { - errno = GetLastError(); - return NULL; - } - - if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) - { - errno = GetLastError(); - return NULL; - } - - trace("hPipe=%p",(void *) hPipe); - return hPipe; - } - - void hllapi_pipe_deinit(void *h) - { - trace("%s(%p)",__FUNCTION__,h); - - if(!h) - return; - - CloseHandle((HANDLE) h); - } - - const char * hllapi_pipe_get_revision(void) - { - return PACKAGE_REVISION; - } - - int hllapi_pipe_connect(void *h, const char *n, int wait) - { - struct hllapi_packet_connect * pkt; - struct hllapi_packet_result response; - DWORD cbSize; - - if(!n) - n = ""; - - cbSize = sizeof(struct hllapi_packet_connect)+strlen(n); - pkt = malloc(cbSize); - - pkt->packet_id = HLLAPI_PACKET_CONNECT; - pkt->wait = (unsigned char) wait; - strcpy(pkt->hostname,n); - - trace("Sending %s",pkt->hostname); - - if(!TransactNamedPipe((HANDLE) h,(LPVOID) pkt, cbSize, &response, sizeof(response), &cbSize,NULL)) - { - errno = GetLastError(); - response.rc = -1; - } - - free(pkt); - - return response.rc; - } - - void hllapi_pipe_disconnect(void *h) - { - static const struct hllapi_packet_query query = { HLLAPI_PACKET_DISCONNECT }; - struct hllapi_packet_result response; - DWORD cbSize = sizeof(query); - TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); - } - - LIB3270_MESSAGE hllapi_pipe_get_message(void *h) - { - static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_PROGRAM_MESSAGE }; - struct hllapi_packet_result response; - DWORD cbSize = sizeof(query); - TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); - return (LIB3270_MESSAGE) response.rc; - } - - char * hllapi_pipe_get_text_at(void *h, int row, int col, int len) - { - struct hllapi_packet_query_at query = { HLLAPI_PACKET_GET_TEXT_AT, }; - struct hllapi_packet_text * response; - DWORD cbSize = sizeof(struct hllapi_packet_text)+len; - char * text = NULL; - - response = malloc(cbSize+2); - memset(response,0,cbSize+2); - - if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(struct hllapi_packet_query_at), &response, cbSize, &cbSize,NULL)) - return NULL; - - if(response->packet_id) - errno = response->packet_id; - else - text = strdup(response->text); - - free(response); - return text; - } - - int hllapi_pipe_enter(void *h) - { - static const struct hllapi_packet_query query = { HLLAPI_PACKET_ENTER }; - struct hllapi_packet_result response; - DWORD cbSize = sizeof(query); - TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); - return response.rc; - } - - int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str) - { - struct hllapi_packet_text_at * query; - struct hllapi_packet_result response; - DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen((const char *) str); - - query = malloc(cbSize); - query->packet_id = HLLAPI_PACKET_SET_TEXT_AT; - query->row = row; - query->col = col; - strcpy(query->text,(const char *) str); - - TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); - - free(query); - - return response.rc; - } - - int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text) - { - struct hllapi_packet_text_at * query; - struct hllapi_packet_result response; - DWORD cbSize = sizeof(struct hllapi_packet_text_at)+strlen(text); - - query = malloc(cbSize); - query->packet_id = HLLAPI_PACKET_CMP_TEXT_AT; - query->row = row; - query->col = col; - strcpy(query->text,text); - - TransactNamedPipe((HANDLE) h,(LPVOID) query, cbSize, &response, sizeof(response), &cbSize,NULL); - - free(query); - - return response.rc; - } - - int hllapi_pipe_pfkey(void *h, int key) - { - struct hllapi_packet_keycode query = { HLLAPI_PACKET_PFKEY, key }; - struct hllapi_packet_result response; - DWORD cbSize = sizeof(query); - TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); - return response.rc; - } - - int hllapi_pipe_pakey(void *h, int key) - { - struct hllapi_packet_keycode query = { HLLAPI_PACKET_PAKEY, key }; - struct hllapi_packet_result response; - DWORD cbSize = sizeof(query); - TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); - return response.rc; - } - - void hllapi_pipe_release_memory(void *p) - { - free(p); - } - - int hllapi_pipe_wait_for_ready(void *h, int seconds) - { - time_t end = time(0)+seconds; - - while(time(0) < end) - { - if(!hllapi_pipe_is_connected(h)) - return ENOTCONN; - - if(hllapi_pipe_get_message(h) == 0) - return 0; - Sleep(250); - } - - return ETIMEDOUT; - } - - int hllapi_pipe_is_connected(void *h) - { - static const struct hllapi_packet_query query = { HLLAPI_PACKET_IS_CONNECTED }; - struct hllapi_packet_result response; - DWORD cbSize = sizeof(query); - TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); - return (LIB3270_MESSAGE) response.rc; - } - - int hllapi_pipe_sleep(void *h, int seconds) - { - time_t end = time(0)+seconds; - - while(time(0) < end) - { - if(!hllapi_pipe_is_connected(h)) - return ENOTCONN; - Sleep(500); - } - - return 0; - } - - int hllapi_pipe_getcursor(void *h) - { - static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_CURSOR }; - struct hllapi_packet_result response; - DWORD cbSize = sizeof(query); - - trace("%s",__FUNCTION__); - - TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); - return (LIB3270_MESSAGE) response.rc; - - } - - int hllapi_pipe_setcursor(void *h, int baddr) - { - struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, baddr }; - struct hllapi_packet_result response; - DWORD cbSize = sizeof(query); - - trace("%s(%d)",__FUNCTION__,query.addr); - - TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); - return response.rc; - } - - char * hllapi_pipe_get_text(void *h, int offset, int len) - { - struct hllapi_packet_query_offset query = { HLLAPI_PACKET_GET_TEXT_AT_OFFSET, offset, len }; - struct hllapi_packet_text * response; - DWORD cbSize = sizeof(struct hllapi_packet_text)+len; - char * text = NULL; - - trace("cbSize=%d",(int) cbSize); - - response = malloc(cbSize+2); - memset(response,0,cbSize+2); - - if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(query), response, cbSize, &cbSize,NULL)) - return NULL; - - trace("rc=%d",response->packet_id); - - if(response->packet_id) - errno = response->packet_id; - else - text = strdup(response->text); - - free(response); - return text; - } diff --git a/src/plugins/remotectl/remotectl.h b/src/plugins/remotectl/remotectl.h deleted file mode 100644 index 5912d82..0000000 --- a/src/plugins/remotectl/remotectl.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como remotectl.h e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - * Agradecimento: - * - * Hélio Passos - * - */ - - #define ENABLE_NLS - #define GETTEXT_PACKAGE PACKAGE_NAME - - #include - #include - #include - - #include - #include - #include - - typedef struct _remotequery - { -#ifdef WIN32 - HANDLE hPipe; /**< Pipe handle (for response) */ -#endif // WIN32 - - H3270 * hSession; /**< 3270 Session */ - int cmd; /**< Command */ - int rc; /**< Response status */ - - int pos; - unsigned short length; /**< Query string length */ - const gchar * text; /**< Query string */ - - } QUERY; - - G_GNUC_INTERNAL void set_active(gboolean on); - G_GNUC_INTERNAL void enqueue_request(QUERY *qry); - G_GNUC_INTERNAL void request_complete(QUERY *qry, int rc, const gchar *text); - - G_GNUC_INTERNAL void request_status(QUERY *qry, int rc); - G_GNUC_INTERNAL void request_value(QUERY *qry, int rc, unsigned int value); - G_GNUC_INTERNAL void request_buffer(QUERY *qry, int rc, size_t sz, const gpointer buffer); - -// int run_hllapi(unsigned long function, char *string, unsigned short length, unsigned short rc); - - -#ifdef WIN32 - - #define PIPE_BUFFER_LENGTH 8192 - - void init_source_pipe(HANDLE hPipe); - void popup_lasterror(const gchar *fmt, ...); - -#endif // WIN32 - - - - - - diff --git a/src/plugins/remotectl/server.h b/src/plugins/remotectl/server.h deleted file mode 100644 index 65e70df..0000000 --- a/src/plugins/remotectl/server.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA, 02111-1307, USA - * - * Este programa está nomeado como server.h e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - - #include - #define ENABLE_NLS - #define GETTEXT_PACKAGE PACKAGE_NAME - - #include - #include - #include - - #include - #include - #include - #include - - #include - - #define PIPE_BUFFER_LENGTH HLLAPI_MAXLENGTH+30 - - #define set_active(x) /* x */ - - - G_GNUC_INTERNAL void popup_lasterror(const gchar *fmt, ...); - diff --git a/src/plugins/remotectl/testprogram.c b/src/plugins/remotectl/testprogram.c deleted file mode 100644 index 4afcc63..0000000 --- a/src/plugins/remotectl/testprogram.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA, 02111-1307, USA - * - * Este programa está nomeado como testprogram.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - - #include - #include - #include - #include - - #define BUFFER_LENGTH 8000 - -/*---[ Implement ]--------------------------------------------------------------------------------*/ - - int main(int numpar, char *param[]) - { - const char *session = "pw3270:a"; - - printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session)); - printf("revision=%d\n",(int) hllapi_get_revision()); - printf("connect=%d\n",(int) hllapi_connect("fandezhi.efglobe.com:23",0)); - printf("wait=%d\n",(int) hllapi_wait(3)); - printf("connected=%s\n",(int) hllapi_is_connected() ? "Yes" : "No"); - -// printf("disconnect=%d\n",(int) hllapi_disconnect("fandezhi.efglobe.com:23",1)); - - - printf("deinit=%d\n",(int) hllapi_deinit()); - -/* - DWORD revision; - int rc; - - rc = hllapi_init(""); - if(rc) - { - printf("Init exits with rc=%d\n",rc); - return rc; - } - - if(!hllapi_get_revision(&revision)) - printf("Library revision is %d\n",(int) revision); - - - printf("Deinit exits with rc=%d\n",rc); - rc = hllapi_deinit(); -*/ - return 0; - } - -/* - int main(int numpar, char *param[]) - { - char buffer[BUFFER_LENGTH]; - unsigned short rc; - unsigned short len; - unsigned long fn; - - static const struct _cmd - { - const char * name; - unsigned short fn; - const char * arg; - } cmd[] = - { - { "GetRevision", HLLAPI_CMD_GETREVISION, " " }, - { "ConnectPS", HLLAPI_CMD_CONNECTPS, "pw3270A" }, - { "InputString", HLLAPI_CMD_INPUTSTRING, "test" }, - - }; - - int f; - - - for(f=0;f< (sizeof(cmd)/sizeof(struct _cmd)); f++) - { - len = strlen(cmd[f].arg); - memcpy(buffer,cmd[f].arg,len); - hllapi((LPWORD) &cmd[f].fn,buffer,&len,&rc); - printf("%s exits with rc=%d\n[%s]\n",cmd[f].name,rc,buffer); - } - - len = 80; - rc = 1040; - fn = HLLAPI_CMD_COPYPSTOSTR; - hllapi((LPWORD) &fn,buffer,&len,&rc); - printf("%s exits with rc=%d\n%s\n","HLLAPI_CMD_COPYPSTOSTR",rc,buffer); - - // Performance - len = strlen(cmd[0].arg); - memcpy(buffer,cmd[0].arg,len); - if(hllapi((LPWORD) &cmd[0].fn,buffer,&len,&rc) == 0 && rc == 0) - { - time_t end = time(0) + 5; - int qtd = 0; - do - { - qtd++; - } while(hllapi((LPWORD) &cmd[0].fn,buffer,&len,&rc) == 0 && rc == 0 && time(0)