Commit 8deeb7f38bbaa1fddefd6571957f6560d64dc010

Authored by perry.werneck@gmail.com
1 parent 5408e656

Implementando conversão ebcdic<->ascii no objeto remoto

src/classlib/local.cc
... ... @@ -307,8 +307,8 @@
307 307 const char * (*_get_host_charset)(H3270 *hSession);
308 308 int (*_print)(H3270 *hSession);
309 309 int (*_erase_eof)(H3270 *hSession);
310   - const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, size_t sz);
311   - const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, size_t sz);
  310 + const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, int sz);
  311 + const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, int sz);
312 312  
313 313 public:
314 314  
... ... @@ -580,12 +580,12 @@
580 580 }
581 581  
582 582  
583   - const char * asc2ebc(unsigned char *str, size_t sz)
  583 + const char * asc2ebc(unsigned char *str, int sz)
584 584 {
585 585 return _asc2ebc(hSession,str,sz);
586 586 }
587 587  
588   - const char * ebc2asc(unsigned char *str, size_t sz)
  588 + const char * ebc2asc(unsigned char *str, int sz)
589 589 {
590 590 return _ebc2asc(hSession,str,sz);
591 591 }
... ...
src/classlib/remote.cc
... ... @@ -57,6 +57,8 @@
57 57 #define HLLAPI_PACKET_QUIT "quit"
58 58 #define HLLAPI_PACKET_ERASE_EOF "eraseEOF"
59 59 #define HLLAPI_PACKET_PRINT "print"
  60 + #define HLLAPI_PACKET_ASC2EBC "asc2ebc"
  61 + #define HLLAPI_PACKET_EBC2ASC "ebc2asc"
60 62 #endif // WIN32
61 63  
62 64 #include <pw3270/class.h>
... ... @@ -91,6 +93,41 @@
91 93 throw exception(GetLastError(),"%s","Transaction error");
92 94 }
93 95  
  96 + int query_strval(HLLAPI_PACKET id, unsigned char *buffer, size_t sz)
  97 + {
  98 + DWORD cbSize = sizeof(struct hllapi_packet_text)+sz;
  99 + struct hllapi_packet_text * query;
  100 + struct hllapi_packet_text * response;
  101 + int rc = -1;
  102 +
  103 + query = (struct hllapi_packet_text *) malloc(cbSize+2);
  104 + memset(query,0,cbSize+2);
  105 + query->packet_id = id;
  106 + memcpy(query->text,buffer,sz);
  107 +
  108 + response = (struct hllapi_packet_text *) malloc(cbSize+2);
  109 + memset(response,0,cbSize+2);
  110 +
  111 + if(TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, cbSize, &cbSize,NULL))
  112 + {
  113 + if(response->packet_id)
  114 + {
  115 + rc = response->packet_id;
  116 + }
  117 + else
  118 + {
  119 + rc = 0;
  120 + strncpy((char *) buffer,response->text,sz);
  121 + }
  122 + }
  123 +
  124 + free(response);
  125 + free(query);
  126 +
  127 + return rc;
  128 +
  129 + }
  130 +
94 131 string * query_string(void *query, size_t szQuery, size_t len)
95 132 {
96 133 struct hllapi_packet_text * response;
... ... @@ -264,6 +301,41 @@
264 301 return get_intval(call(msg));
265 302 }
266 303  
  304 + int query_strval(const char *method, unsigned char *buffer, size_t sz)
  305 + {
  306 + DBusMessage * outMsg = create_message(const char *method);
  307 +
  308 + if(outMsg)
  309 + {
  310 + dbus_message_append_args(outMsg, DBUS_TYPE_STRING, &buffer, DBUS_TYPE_INVALID);
  311 +
  312 + DBusMessage * rspMsg = call(outMsg);
  313 + if(rspMsg)
  314 + {
  315 + if(dbus_message_iter_init(rspMsg, &iter))
  316 + {
  317 + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING)
  318 + {
  319 + const char * str;
  320 + dbus_message_iter_get_basic(&iter, &str);
  321 + trace("Response: [%s]",str);
  322 + strncpy(buffer,str,sz);
  323 + dbus_message_unref(msg);
  324 + return 0;
  325 + }
  326 +
  327 + exception e = exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32);
  328 + dbus_message_unref(msg);
  329 +
  330 + throw e;
  331 +
  332 + }
  333 + }
  334 + }
  335 +
  336 + return -1;
  337 + }
  338 +
267 339 #else
268 340  
269 341  
... ... @@ -1188,19 +1260,18 @@
1188 1260 return query_intval(HLLAPI_PACKET_PRINT);
1189 1261 }
1190 1262  
1191   - const char * asc2ebc(unsigned char *str, size_t sz)
  1263 + const char * asc2ebc(unsigned char *text, int sz)
1192 1264 {
1193   - #warning Incomplete
1194   - return (const char *) str;
  1265 + query_strval(HLLAPI_PACKET_ASC2EBC,text,sz);
  1266 + return (const char *) text;
1195 1267 }
1196 1268  
1197   - const char * ebc2asc(unsigned char *str, size_t sz)
  1269 + const char * ebc2asc(unsigned char *text, int sz)
1198 1270 {
1199   - #warning Incomplete
1200   - return (const char *) str;
  1271 + query_strval(HLLAPI_PACKET_EBC2ASC,text,sz);
  1272 + return (const char *) text;
1201 1273 }
1202 1274  
1203   -
1204 1275 };
1205 1276  
1206 1277 session * session::create_remote(const char *session)
... ...
src/include/lib3270/charset.h
... ... @@ -64,8 +64,8 @@
64 64 LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name);
65 65 LIB3270_EXPORT const char * lib3270_get_host_charset(H3270 *hSession);
66 66 LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way);
67   - LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, size_t sz);
68   - LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, size_t sz);
  67 + LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, int sz);
  68 + LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, int sz);
69 69  
70 70  
71 71 #ifdef __cplusplus
... ...
src/include/pw3270/class.h
... ... @@ -141,8 +141,8 @@
141 141 virtual int emulate_input(const char *str) = 0;
142 142  
143 143 // Ascii<->EBCDIC translation
144   - virtual const char * asc2ebc(unsigned char *str, size_t sz = -1) = 0;
145   - virtual const char * ebc2asc(unsigned char *str, size_t sz = -1) = 0;
  144 + virtual const char * asc2ebc(unsigned char *str, int sz = -1) = 0;
  145 + virtual const char * ebc2asc(unsigned char *str, int sz = -1) = 0;
146 146 string asc2ebc(string &str);
147 147 string ebc2asc(string &str);
148 148  
... ...
src/include/pw3270/ipcpackets.h
... ... @@ -59,6 +59,9 @@
59 59 HLLAPI_PACKET_SET_HOST_CHARSET,
60 60 HLLAPI_PACKET_GET_HOST_CHARSET,
61 61  
  62 + HLLAPI_PACKET_ASC2EBC,
  63 + HLLAPI_PACKET_EBC2ASC,
  64 +
62 65 HLLAPI_PACKET_INVALID
63 66  
64 67 } HLLAPI_PACKET;
... ...
src/lib3270/charset.c
... ... @@ -406,7 +406,7 @@ LIB3270_ACTION( charsettable )
406 406 return 0;
407 407 }
408 408  
409   -LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, size_t sz)
  409 +LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, int sz)
410 410 {
411 411 int f;
412 412 if(sz < 0)
... ... @@ -421,7 +421,7 @@ LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buff
421 421 return (const char *) buffer;
422 422 }
423 423  
424   -LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, size_t sz)
  424 +LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, int sz)
425 425 {
426 426 int f;
427 427 if(sz < 0)
... ...
src/plugins/dbus3270/gobject.c
... ... @@ -479,3 +479,35 @@ void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context)
479 479 {
480 480 dbus_g_method_return(context,lib3270_print(pw3270_dbus_get_session_handle(object)));
481 481 }
  482 +
  483 +void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context)
  484 +{
  485 + int sz = strlen(from);
  486 +
  487 + if(sz > 0)
  488 + {
  489 + unsigned char buffer[sz+1];
  490 + memcpy(buffer,from,sz);
  491 + dbus_g_method_return(context,lib3270_ebc2asc(pw3270_dbus_get_session_handle(object),buffer,sz));
  492 + return;
  493 + }
  494 +
  495 + dbus_g_method_return(context,"");
  496 +
  497 +}
  498 +
  499 +void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context)
  500 +{
  501 + int sz = strlen(from);
  502 +
  503 + if(sz > 0)
  504 + {
  505 + unsigned char buffer[sz+1];
  506 + memcpy(buffer,from,sz);
  507 + dbus_g_method_return(context,lib3270_asc2ebc(pw3270_dbus_get_session_handle(object),buffer,sz));
  508 + return;
  509 + }
  510 +
  511 + dbus_g_method_return(context,"");
  512 +
  513 +}
... ...
src/plugins/dbus3270/pw3270dbus.xml
... ... @@ -170,6 +170,16 @@
170 170 <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
171 171 <arg type="i" name="result" direction="out" />
172 172 </method>
  173 + <method name="ebc2asc">
  174 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  175 + <arg type="s" name="from" direction="in" />
  176 + <arg type="s" name="to" direction="out" />
  177 + </method>
  178 + <method name="asc2ebc">
  179 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  180 + <arg type="s" name="from" direction="in" />
  181 + <arg type="s" name="to" direction="out" />
  182 + </method>
173 183  
174 184 </interface>
175 185  
... ...
src/plugins/dbus3270/service.h
... ... @@ -112,6 +112,9 @@
112 112 void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context);
113 113 void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context);
114 114  
  115 + void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context);
  116 + void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context);
  117 +
115 118 G_END_DECLS
116 119  
117 120 #endif // _PW3270_DBUS_SERVICE_H
... ...
src/plugins/hllapi/pluginmain.c
... ... @@ -313,6 +313,20 @@
313 313 (const char *) ((struct hllapi_packet_set_text *) source->buffer)->text));
314 314 break;
315 315  
  316 + case HLLAPI_PACKET_ASC2EBC:
  317 + send_text(source,(char *) lib3270_asc2ebc(
  318 + lib3270_get_default_session_handle(),
  319 + (unsigned char *) ((struct hllapi_packet_set_text *) source->buffer)->text,-1
  320 + ));
  321 + break;
  322 +
  323 + case HLLAPI_PACKET_EBC2ASC:
  324 + send_text(source,(char *) lib3270_ebc2asc(
  325 + lib3270_get_default_session_handle(),
  326 + (unsigned char *) ((struct hllapi_packet_set_text *) source->buffer)->text,-1
  327 + ));
  328 + break;
  329 +
316 330 case HLLAPI_PACKET_GET_HOST_CHARSET:
317 331 send_text(source,(char *) lib3270_get_host_charset(lib3270_get_default_session_handle()));
318 332 break;
... ...
src/plugins/rx3270/pluginmain.cc
... ... @@ -135,8 +135,8 @@
135 135 string * get_host_charset(void);
136 136 string * get_display_charset(void);
137 137  
138   - const char * asc2ebc(unsigned char *str, size_t sz = -1);
139   - const char * ebc2asc(unsigned char *str, size_t sz = -1);
  138 + const char * asc2ebc(unsigned char *str, int sz = -1);
  139 + const char * ebc2asc(unsigned char *str, int sz = -1);
140 140  
141 141 int quit(void);
142 142  
... ... @@ -761,12 +761,12 @@ int plugin::print(void)
761 761 return lib3270_print(hSession);
762 762 }
763 763  
764   -const char * plugin::asc2ebc(unsigned char *str, size_t sz)
  764 +const char * plugin::asc2ebc(unsigned char *str, int sz)
765 765 {
766 766 return lib3270_asc2ebc(hSession,str,sz);
767 767 }
768 768  
769   -const char * plugin::ebc2asc(unsigned char *str, size_t sz)
  769 +const char * plugin::ebc2asc(unsigned char *str, int sz)
770 770 {
771 771 return lib3270_ebc2asc(hSession,str,sz);
772 772 }
... ...