Commit 1fdad013c2f68c3336295b2f1df2ee3751745cca
1 parent
70442604
Exists in
master
and in
5 other branches
HLLAPI passa a converter o charset do terminal, funcao lib3270_get_text estava a…
…ceitando gets maiores que o tamanho do terminal, implementacao da funcao HLLAPI para obter o buffer do terminal, HLLAPI estava fechando a pipe de comunicacao logo apos a conexao
Showing
5 changed files
with
89 additions
and
16 deletions
Show diff stats
src/lib3270/selection.c
@@ -464,11 +464,9 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) | @@ -464,11 +464,9 @@ LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) | ||
464 | if(!lib3270_connected(h)) | 464 | if(!lib3270_connected(h)) |
465 | return NULL; | 465 | return NULL; |
466 | 466 | ||
467 | - maxlen = h->rows * (h->cols+1); | 467 | + maxlen = (h->rows * (h->cols+1)) - offset; |
468 | 468 | ||
469 | - if(len < 0) | ||
470 | - len = (maxlen - offset); | ||
471 | - else if(len > maxlen) | 469 | + if(len < 0 || len > maxlen) |
472 | len = maxlen; | 470 | len = maxlen; |
473 | 471 | ||
474 | buffer = lib3270_malloc(len+1); | 472 | buffer = lib3270_malloc(len+1); |
src/plugins/remotectl/hllapi.c
@@ -68,6 +68,7 @@ | @@ -68,6 +68,7 @@ | ||
68 | if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) | 68 | if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) |
69 | return GetLastError(); | 69 | return GetLastError(); |
70 | 70 | ||
71 | + trace("Pipe %ld open",(unsigned long) hPipe); | ||
71 | #else | 72 | #else |
72 | 73 | ||
73 | #error Not implemented | 74 | #error Not implemented |
@@ -89,6 +90,7 @@ | @@ -89,6 +90,7 @@ | ||
89 | 90 | ||
90 | if(hPipe == INVALID_HANDLE_VALUE) | 91 | if(hPipe == INVALID_HANDLE_VALUE) |
91 | { | 92 | { |
93 | + trace("Invalid pipe handle %ld",(unsigned long) hPipe); | ||
92 | result = EPERM; | 94 | result = EPERM; |
93 | } | 95 | } |
94 | else | 96 | else |
@@ -180,8 +182,9 @@ | @@ -180,8 +182,9 @@ | ||
180 | if(!result) | 182 | if(!result) |
181 | { | 183 | { |
182 | result = run_query(*func, arg, str, *length, rc); | 184 | result = run_query(*func, arg, str, *length, rc); |
183 | - if(result || rc) | 185 | + if(result || *rc) |
184 | { | 186 | { |
187 | + trace("Closing pipe rc=%d result=%d ",*rc,result); | ||
185 | CloseHandle(hPipe); | 188 | CloseHandle(hPipe); |
186 | hPipe = INVALID_HANDLE_VALUE; | 189 | hPipe = INVALID_HANDLE_VALUE; |
187 | } | 190 | } |
src/plugins/remotectl/remotectl.c
@@ -162,15 +162,36 @@ | @@ -162,15 +162,36 @@ | ||
162 | return 0; | 162 | return 0; |
163 | } | 163 | } |
164 | 164 | ||
165 | - static int cmd_sendstring(H3270 *hSession, unsigned short rc, char *text, unsigned short length) | 165 | + static int cmd_sendstring(H3270 *hSession, unsigned short dunno, char *buffer, unsigned short length) |
166 | { | 166 | { |
167 | + gchar * text; | ||
168 | + GError * error = NULL; | ||
169 | + gsize bytes_read; | ||
170 | + gsize bytes_written; | ||
171 | + const gchar * charset; | ||
172 | + int rc = -1; | ||
173 | + | ||
167 | if(!lib3270_connected(hSession)) | 174 | if(!lib3270_connected(hSession)) |
168 | return ENOTCONN; | 175 | return ENOTCONN; |
169 | 176 | ||
170 | - #warning Converter formato da string | ||
171 | - lib3270_emulate_input(hSession,text,strlen(text),0); | 177 | + g_get_charset(&charset); |
172 | 178 | ||
173 | - return 0; | 179 | + text = g_convert(buffer,-1,lib3270_get_charset(hSession),charset,&bytes_read,&bytes_written,&error); |
180 | + if(text) | ||
181 | + { | ||
182 | + #warning Converter "@" em "\\" | ||
183 | + lib3270_emulate_input(hSession,text,strlen(text),0); | ||
184 | + g_free(text); | ||
185 | + rc = 0; | ||
186 | + } | ||
187 | + else | ||
188 | + { | ||
189 | + strncpy(buffer,error->message,length); | ||
190 | + rc = error->code; | ||
191 | + g_error_free(error); | ||
192 | + } | ||
193 | + | ||
194 | + return rc; | ||
174 | } | 195 | } |
175 | 196 | ||
176 | static int cmd_wait(H3270 *hSession, unsigned short rc, char *text, unsigned short length) | 197 | static int cmd_wait(H3270 *hSession, unsigned short rc, char *text, unsigned short length) |
@@ -178,6 +199,39 @@ | @@ -178,6 +199,39 @@ | ||
178 | return lib3270_wait_for_ready(hSession,60); | 199 | return lib3270_wait_for_ready(hSession,60); |
179 | } | 200 | } |
180 | 201 | ||
202 | + static int cmd_copypstostr(H3270 *hSession, unsigned short pos, char *buffer, unsigned short length) | ||
203 | + { | ||
204 | + char * text = lib3270_get_text(hSession, (int) pos, (int) length); | ||
205 | + gchar * local; | ||
206 | + GError * error = NULL; | ||
207 | + gsize bytes_read; | ||
208 | + gsize bytes_written; | ||
209 | + int rc = 0; | ||
210 | + const gchar * charset; | ||
211 | + | ||
212 | + if(!text) | ||
213 | + return -1; | ||
214 | + | ||
215 | + g_get_charset(&charset); | ||
216 | + | ||
217 | + local = g_convert((const gchar *) text,-1,charset,lib3270_get_charset(hSession),&bytes_read,&bytes_written,&error); | ||
218 | + | ||
219 | + if(local) | ||
220 | + { | ||
221 | + strncpy(buffer,local,length); | ||
222 | + g_free(local); | ||
223 | + } | ||
224 | + else | ||
225 | + { | ||
226 | + strncpy(buffer,error->message,length); | ||
227 | + rc = error->code; | ||
228 | + g_error_free(error); | ||
229 | + } | ||
230 | + | ||
231 | + lib3270_free(text); | ||
232 | + return rc; | ||
233 | + } | ||
234 | + | ||
181 | int run_hllapi(unsigned long function, char *string, unsigned short length, unsigned short rc) | 235 | int run_hllapi(unsigned long function, char *string, unsigned short length, unsigned short rc) |
182 | { | 236 | { |
183 | static const struct _cmd | 237 | static const struct _cmd |
@@ -191,7 +245,8 @@ | @@ -191,7 +245,8 @@ | ||
191 | { HLLAPI_CMD_INPUTSTRING, cmd_sendstring }, | 245 | { HLLAPI_CMD_INPUTSTRING, cmd_sendstring }, |
192 | { HLLAPI_CMD_WAIT, cmd_wait }, | 246 | { HLLAPI_CMD_WAIT, cmd_wait }, |
193 | { HLLAPI_CMD_SETCURSOR, cmd_setcursor }, | 247 | { HLLAPI_CMD_SETCURSOR, cmd_setcursor }, |
194 | - { HLLAPI_CMD_GETREVISION, cmd_getrevision } | 248 | + { HLLAPI_CMD_GETREVISION, cmd_getrevision }, |
249 | + { HLLAPI_CMD_COPYPSTOSTR, cmd_copypstostr } | ||
195 | }; | 250 | }; |
196 | int f; | 251 | int f; |
197 | 252 |
src/plugins/remotectl/remotectl.h
@@ -46,7 +46,7 @@ | @@ -46,7 +46,7 @@ | ||
46 | 46 | ||
47 | #ifdef WIN32 | 47 | #ifdef WIN32 |
48 | 48 | ||
49 | - #define PIPE_BUFFER_LENGTH 4096 | 49 | + #define PIPE_BUFFER_LENGTH 8192 |
50 | 50 | ||
51 | void init_source_pipe(HANDLE hPipe); | 51 | void init_source_pipe(HANDLE hPipe); |
52 | void popup_lasterror(const gchar *fmt, ...); | 52 | void popup_lasterror(const gchar *fmt, ...); |
src/plugins/remotectl/testprogram.c
@@ -31,12 +31,17 @@ | @@ -31,12 +31,17 @@ | ||
31 | #include <stdio.h> | 31 | #include <stdio.h> |
32 | #include <pw3270/hllapi.h> | 32 | #include <pw3270/hllapi.h> |
33 | 33 | ||
34 | + #define BUFFER_LENGTH 4096 | ||
35 | + | ||
34 | /*---[ Implement ]--------------------------------------------------------------------------------*/ | 36 | /*---[ Implement ]--------------------------------------------------------------------------------*/ |
35 | 37 | ||
36 | int main(int numpar, char *param[]) | 38 | int main(int numpar, char *param[]) |
37 | { | 39 | { |
38 | - char buffer[1024]; | 40 | + char buffer[BUFFER_LENGTH]; |
39 | unsigned short rc; | 41 | unsigned short rc; |
42 | + unsigned short len; | ||
43 | + int result; | ||
44 | + unsigned long fn; | ||
40 | 45 | ||
41 | static const struct _cmd | 46 | static const struct _cmd |
42 | { | 47 | { |
@@ -49,7 +54,6 @@ | @@ -49,7 +54,6 @@ | ||
49 | { "GetRevision", HLLAPI_CMD_GETREVISION, "" }, | 54 | { "GetRevision", HLLAPI_CMD_GETREVISION, "" }, |
50 | { "InputString", HLLAPI_CMD_INPUTSTRING, "test" }, | 55 | { "InputString", HLLAPI_CMD_INPUTSTRING, "test" }, |
51 | 56 | ||
52 | - { "DisconnectPS", HLLAPI_CMD_DISCONNECTPS, "" }, | ||
53 | }; | 57 | }; |
54 | 58 | ||
55 | int f; | 59 | int f; |
@@ -57,14 +61,27 @@ | @@ -57,14 +61,27 @@ | ||
57 | 61 | ||
58 | for(f=0;f< (sizeof(cmd)/sizeof(struct _cmd)); f++) | 62 | for(f=0;f< (sizeof(cmd)/sizeof(struct _cmd)); f++) |
59 | { | 63 | { |
60 | - unsigned short len = 1024; | ||
61 | - int result; | ||
62 | - | 64 | + len = BUFFER_LENGTH; |
63 | strcpy(buffer,cmd[f].arg); | 65 | strcpy(buffer,cmd[f].arg); |
64 | result = hllapi(&cmd[f].fn,buffer,&len,&rc); | 66 | result = hllapi(&cmd[f].fn,buffer,&len,&rc); |
65 | printf("%s exits with %d\n[%s]\n",cmd[f].name,result,buffer); | 67 | printf("%s exits with %d\n[%s]\n",cmd[f].name,result,buffer); |
66 | 68 | ||
67 | } | 69 | } |
68 | 70 | ||
71 | + len = BUFFER_LENGTH; | ||
72 | + rc = 1; | ||
73 | + fn = HLLAPI_CMD_COPYPSTOSTR; | ||
74 | + result = hllapi(&fn,buffer,&len,&rc); | ||
75 | + printf("%s exits with %d\n%s\n","HLLAPI_CMD_COPYPSTOSTR",result,buffer); | ||
76 | + | ||
77 | + | ||
78 | + // Disconnect | ||
79 | + len = BUFFER_LENGTH; | ||
80 | + rc = 1; | ||
81 | + fn = HLLAPI_CMD_DISCONNECTPS; | ||
82 | + *buffer = 0; | ||
83 | + result = hllapi(&fn,buffer,&len,&rc); | ||
84 | + printf("%s exits with %d [%s]\n","HLLAPI_CMD_DISCONNECTPS",result,buffer); | ||
85 | + | ||
69 | return 0; | 86 | return 0; |
70 | } | 87 | } |