Commit 2b9270e084eff780e2f4bc6046c0480954ed08e5

Authored by perry.werneck@gmail.com
1 parent 4b3b4481

Consulta HLLAPI comeca a funcionar

pw3270.cbp
... ... @@ -225,6 +225,9 @@
225 225 <Option compilerVar="CC" />
226 226 </Unit>
227 227 <Unit filename="src\plugins\remotectl\remotectl.h" />
  228 + <Unit filename="src\plugins\remotectl\testprogram.c">
  229 + <Option compilerVar="CC" />
  230 + </Unit>
228 231 <Unit filename="src\pw3270\Makefile.in" />
229 232 <Unit filename="src\pw3270\actions.c">
230 233 <Option compilerVar="CC" />
... ...
src/include/pw3270/hllapi.h
... ... @@ -29,6 +29,11 @@
29 29 *
30 30 */
31 31  
  32 +#ifndef HLLAPI_H_INCLUDED
  33 +
  34 + #define HLLAPI_H_INCLUDED 1
  35 + #include <lib3270.h>
  36 +
32 37 #ifdef __cplusplus
33 38 extern "C" {
34 39 #endif
... ... @@ -53,9 +58,10 @@ extern &quot;C&quot; {
53 58 } HLLAPI_DATA;
54 59 #pragma pack()
55 60  
56   - LIB3270_EXPORT int hllapi(unsigned long function, const char *string, unsigned short length, unsigned short *rc);
  61 + LIB3270_EXPORT int hllapi(unsigned long function, char *string, unsigned short length, unsigned short *rc);
57 62  
58 63 #ifdef __cplusplus
59 64 } /* end of extern "C" */
60 65 #endif
61 66  
  67 +#endif // HLLAPI_H_INCLUDED
... ...
src/plugins/remotectl/Makefile.in
... ... @@ -104,7 +104,16 @@ $(BINDBG)/libhllapi.dll: $(foreach SRC, $(basename $(HLLAPI_SRC)), $(OBJDBG)/$(S
104 104  
105 105 #---[ Misc targets ]-----------------------------------------------------------
106 106  
  107 +testprogram@EXEEXT@: testprogram.c
  108 + @echo " CCLD `basename $@`"
  109 + @$(MKDIR) `dirname $@`
  110 + @$(CC) $(CFLAGS) -I../../../src/include -L../../../$(BINDIR)/Debug $(DEBUG_CFLAGS) -lhllapi -o $@ -c $<
  111 +
  112 +test: testprogram@EXEEXT@
  113 + @PATH="../../../$(BINDIR)/Debug:$(PATH)" ./testprogram@EXEEXT@
  114 +
107 115 clean:
108 116 @rm -fr $(OBJDIR)
109 117 @rm -fr $(BINDIR)
  118 + @rm -f testprogram@EXEEXT@
110 119 @find . -name "*~" -exec rm -f {} \;
... ...
src/plugins/remotectl/hllapi.c
... ... @@ -32,10 +32,12 @@
32 32 #include <string.h>
33 33 #include <errno.h>
34 34 #include <pw3270/hllapi.h>
  35 + #include <stdio.h>
  36 + #include <lib3270/log.h>
35 37  
36 38 /*--[ Implement ]------------------------------------------------------------------------------------*/
37 39  
38   - LIB3270_EXPORT int hllapi(unsigned long func, const char *string, unsigned short length, unsigned short *rc)
  40 + LIB3270_EXPORT int hllapi(unsigned long func, char *string, unsigned short length, unsigned short *rc)
39 41 {
40 42 int result = -1;
41 43  
... ... @@ -69,8 +71,8 @@
69 71 else
70 72 {
71 73 HLLAPI_DATA *buffer = malloc(HLLAPI_MAXLENGTH+1);
72   - DWORD cbSize = 0;
73   - HLLAPI_DATA *data = malloc(sizeof(HLLAPI_DATA) + length);
  74 + DWORD cbSize = sizeof(HLLAPI_DATA) + length;
  75 + HLLAPI_DATA *data = malloc(cbSize+1);
74 76  
75 77 data->id = HLLAPI_REQUEST_ID;
76 78 data->func = func;
... ... @@ -80,7 +82,9 @@
80 82 if(string && length > 0)
81 83 memcpy(data->string,string,length);
82 84  
83   - if(!TransactNamedPipe(hPipe,(LPVOID) data,sizeof(HLLAPI_DATA) + length,buffer,HLLAPI_MAXLENGTH,&cbSize,NULL))
  85 + trace("Sending %d bytes",(int) cbSize);
  86 +
  87 + if(!TransactNamedPipe(hPipe,(LPVOID) data,cbSize,buffer,HLLAPI_MAXLENGTH,&cbSize,NULL))
84 88 {
85 89 result = -1;
86 90 }
... ...
src/plugins/remotectl/pipesource.c
... ... @@ -34,7 +34,6 @@
34 34  
35 35 #include <windows.h>
36 36 #include <stdarg.h>
37   - #include <lib3270.h>
38 37 #include "remotectl.h"
39 38  
40 39 /*---[ Defines ]----------------------------------------------------------------------------*/
... ... @@ -134,13 +133,18 @@ static void wait_for_client(pipe_source *source)
134 133  
135 134 static void process_input(pipe_source *source, DWORD cbRead)
136 135 {
137   - gint argc = 0;
138   - gchar **argv;
139   - GError * error = NULL;
140   - gchar * cmd;
  136 + HLLAPI_DATA *data = (HLLAPI_DATA *) source->buffer;
141 137  
142 138 source->buffer[cbRead] = 0;
143 139  
  140 + if(data->id == 0x01)
  141 + {
  142 + DWORD wrote;
  143 + data->rc = run_hllapi(data->func,data->string,data->len,data->rc);
  144 + wrote = sizeof(HLLAPI_DATA)+data->len;
  145 + WriteFile(source->hPipe,data,wrote,&wrote,NULL);
  146 + }
  147 +
144 148 }
145 149  
146 150 static void read_input_pipe(pipe_source *source)
... ... @@ -195,7 +199,7 @@ static void wait_for_client(pipe_source *source)
195 199 */
196 200 BOOL fSuccess;
197 201 DWORD cbRead = 0;
198   - DWORD dwErr = 0;
  202 +// DWORD dwErr = 0;
199 203  
200 204 fSuccess = GetOverlappedResult(((pipe_source *) source)->hPipe,&((pipe_source *) source)->overlap,&cbRead,FALSE );
201 205  
... ...
src/plugins/remotectl/remotectl.c
... ... @@ -33,6 +33,8 @@
33 33  
34 34 #include "remotectl.h"
35 35 #include <pw3270/plugin.h>
  36 + #include <errno.h>
  37 + #include <string.h>
36 38  
37 39 /*--[ Implement ]------------------------------------------------------------------------------------*/
38 40  
... ... @@ -121,4 +123,30 @@
121 123 return 0;
122 124 }
123 125  
  126 + static int cmd_getrevision(unsigned short rc, char *string, unsigned short length)
  127 + {
  128 + strncpy(string,lib3270_get_revision(),length);
  129 + return 0;
  130 + }
  131 +
  132 + int run_hllapi(unsigned long function, char *string, unsigned short length, unsigned short rc)
  133 + {
  134 + static const struct _cmd
  135 + {
  136 + unsigned long function;
  137 + int (*exec)(unsigned short rc, char *string, unsigned short length);
  138 + } cmd[] =
  139 + {
  140 + { HLLAPI_CMD_GETREVISION, cmd_getrevision }
  141 + };
  142 + int f;
  143 +
  144 + for(f=0;f<G_N_ELEMENTS(cmd);f++)
  145 + {
  146 + if(cmd[f].function == function)
  147 + return cmd[f].exec(rc,string,length);
  148 + }
  149 +
  150 + return EINVAL;
  151 + }
124 152  
... ...
src/plugins/remotectl/remotectl.h
... ... @@ -42,6 +42,8 @@
42 42 #include <lib3270/log.h>
43 43 #include <pw3270/hllapi.h>
44 44  
  45 + int run_hllapi(unsigned long function, char *string, unsigned short length, unsigned short rc);
  46 +
45 47 #ifdef WIN32
46 48  
47 49 #define PIPE_BUFFER_LENGTH 4096
... ...
src/plugins/remotectl/testprogram.c 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como testprogram.c e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include <windows.h>
  31 + #include <stdio.h>
  32 + #include <pw3270/hllapi.h>
  33 +
  34 +/*---[ Implement ]--------------------------------------------------------------------------------*/
  35 +
  36 + int main(int numpar, char *param[])
  37 + {
  38 + char buffer[1024];
  39 + unsigned short rc;
  40 +
  41 + // Test for GetRevision call
  42 + *buffer = 0;
  43 + printf("GetRevision exits with %d\n[%s]\n",hllapi(HLLAPI_CMD_GETREVISION,buffer,1024,&rc),buffer);
  44 +
  45 + return 0;
  46 + }
... ...