Commit 68b91b26e14366bb9bca6e61e78eecbeb78a6645

Authored by perry.werneck@gmail.com
1 parent 63b4fa60

Implementando captura HLLAPI

Showing 1 changed file with 43 additions and 20 deletions   Show diff stats
src/plugins/remotectl/remotectl.c
... ... @@ -278,36 +278,59 @@
278 278 return lib3270_wait_for_ready(hSession,60);
279 279 }
280 280  
281   - static int cmd_copypstostr(H3270 *hSession, unsigned short pos, char *buffer, unsigned short length)
  281 + static int cmd_copypstostr(H3270 *hSession, unsigned short pos, char *outBuff, unsigned short length)
282 282 {
283   - char * text = lib3270_get_text(hSession, (int) pos, (int) length);
284   - gchar * local;
285   - GError * error = NULL;
286   - gsize bytes_read;
287   - gsize bytes_written;
288   - int rc = 0;
289   - const gchar * charset;
  283 + int rows;
  284 + int cols;
  285 + unsigned short * attr;
  286 + unsigned char * text;
  287 + int rc;
290 288  
291   - if(!text)
292   - return -1;
  289 + lib3270_get_screen_size(hSession,&rows,&cols);
293 290  
294   - g_get_charset(&charset);
  291 + if(pos < 1 || (pos+length) >= (rows*cols))
  292 + return EINVAL;
  293 +
  294 + pos--;
295 295  
296   - local = g_convert((const gchar *) text,-1,charset,lib3270_get_charset(hSession),&bytes_read,&bytes_written,&error);
  296 + attr = g_new0(unsigned short, length+0);
  297 + text = g_new0(unsigned char, length+1);
297 298  
298   - if(local)
  299 + rc = lib3270_get_contents(hSession,pos,pos+(length-1),text,attr);
  300 +
  301 + if(rc)
299 302 {
300   - strncpy(buffer,local,length);
301   - g_free(local);
  303 + strncpy(outBuff,strerror(rc),length);
302 304 }
303 305 else
304 306 {
305   - strncpy(buffer,error->message,length);
306   - rc = error->code;
307   - g_error_free(error);
308   - }
  307 + const gchar * charset;
  308 + gchar * local;
  309 + gsize bytes_read;
  310 + gsize bytes_written;
  311 + GError * error = NULL;
309 312  
310   - lib3270_free(text);
  313 + trace("Text: [%s]",text);
  314 +
  315 + g_get_charset(&charset);
  316 +
  317 + local = g_convert((const gchar *) text,length,charset,lib3270_get_charset(hSession),&bytes_read,&bytes_written,&error);
  318 +
  319 + g_free(attr);
  320 + g_free(text);
  321 +
  322 + if(!local)
  323 + {
  324 + rc = error->code;
  325 + strncpy(outBuff,error->message,length);
  326 + g_error_free(error);
  327 + }
  328 + else
  329 + {
  330 + strncpy(outBuff,(const char *) local,length);
  331 + g_free(local);
  332 + }
  333 + }
311 334 return rc;
312 335 }
313 336  
... ...