diff --git a/src/classlib/local.cc b/src/classlib/local.cc index 76ee9c5..ff6a03a 100644 --- a/src/classlib/local.cc +++ b/src/classlib/local.cc @@ -307,8 +307,8 @@ const char * (*_get_host_charset)(H3270 *hSession); int (*_print)(H3270 *hSession); int (*_erase_eof)(H3270 *hSession); - const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, size_t sz); - const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, size_t sz); + const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, int sz); + const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, int sz); public: @@ -580,12 +580,12 @@ } - const char * asc2ebc(unsigned char *str, size_t sz) + const char * asc2ebc(unsigned char *str, int sz) { return _asc2ebc(hSession,str,sz); } - const char * ebc2asc(unsigned char *str, size_t sz) + const char * ebc2asc(unsigned char *str, int sz) { return _ebc2asc(hSession,str,sz); } diff --git a/src/classlib/remote.cc b/src/classlib/remote.cc index 8ec461f..36484ff 100644 --- a/src/classlib/remote.cc +++ b/src/classlib/remote.cc @@ -57,6 +57,8 @@ #define HLLAPI_PACKET_QUIT "quit" #define HLLAPI_PACKET_ERASE_EOF "eraseEOF" #define HLLAPI_PACKET_PRINT "print" + #define HLLAPI_PACKET_ASC2EBC "asc2ebc" + #define HLLAPI_PACKET_EBC2ASC "ebc2asc" #endif // WIN32 #include @@ -91,6 +93,41 @@ throw exception(GetLastError(),"%s","Transaction error"); } + int query_strval(HLLAPI_PACKET id, unsigned char *buffer, size_t sz) + { + DWORD cbSize = sizeof(struct hllapi_packet_text)+sz; + struct hllapi_packet_text * query; + struct hllapi_packet_text * response; + int rc = -1; + + query = (struct hllapi_packet_text *) malloc(cbSize+2); + memset(query,0,cbSize+2); + query->packet_id = id; + memcpy(query->text,buffer,sz); + + response = (struct hllapi_packet_text *) malloc(cbSize+2); + memset(response,0,cbSize+2); + + if(TransactNamedPipe(hPipe,(LPVOID) query, cbSize, &response, cbSize, &cbSize,NULL)) + { + if(response->packet_id) + { + rc = response->packet_id; + } + else + { + rc = 0; + strncpy((char *) buffer,response->text,sz); + } + } + + free(response); + free(query); + + return rc; + + } + string * query_string(void *query, size_t szQuery, size_t len) { struct hllapi_packet_text * response; @@ -264,6 +301,41 @@ return get_intval(call(msg)); } + int query_strval(const char *method, unsigned char *buffer, size_t sz) + { + DBusMessage * outMsg = create_message(const char *method); + + if(outMsg) + { + dbus_message_append_args(outMsg, DBUS_TYPE_STRING, &buffer, DBUS_TYPE_INVALID); + + DBusMessage * rspMsg = call(outMsg); + if(rspMsg) + { + if(dbus_message_iter_init(rspMsg, &iter)) + { + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) + { + const char * str; + dbus_message_iter_get_basic(&iter, &str); + trace("Response: [%s]",str); + strncpy(buffer,str,sz); + dbus_message_unref(msg); + return 0; + } + + exception e = exception("DBUS Return type was %c, expecting %c",dbus_message_iter_get_arg_type(&iter),DBUS_TYPE_INT32); + dbus_message_unref(msg); + + throw e; + + } + } + } + + return -1; + } + #else @@ -1188,19 +1260,18 @@ return query_intval(HLLAPI_PACKET_PRINT); } - const char * asc2ebc(unsigned char *str, size_t sz) + const char * asc2ebc(unsigned char *text, int sz) { - #warning Incomplete - return (const char *) str; + query_strval(HLLAPI_PACKET_ASC2EBC,text,sz); + return (const char *) text; } - const char * ebc2asc(unsigned char *str, size_t sz) + const char * ebc2asc(unsigned char *text, int sz) { - #warning Incomplete - return (const char *) str; + query_strval(HLLAPI_PACKET_EBC2ASC,text,sz); + return (const char *) text; } - }; session * session::create_remote(const char *session) diff --git a/src/include/lib3270/charset.h b/src/include/lib3270/charset.h index 26b5182..8d940e6 100644 --- a/src/include/lib3270/charset.h +++ b/src/include/lib3270/charset.h @@ -64,8 +64,8 @@ LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name); LIB3270_EXPORT const char * lib3270_get_host_charset(H3270 *hSession); LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way); - LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, size_t sz); - LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, size_t sz); + LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, int sz); + LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, int sz); #ifdef __cplusplus diff --git a/src/include/pw3270/class.h b/src/include/pw3270/class.h index 0745ba8..454c194 100644 --- a/src/include/pw3270/class.h +++ b/src/include/pw3270/class.h @@ -141,8 +141,8 @@ virtual int emulate_input(const char *str) = 0; // Ascii<->EBCDIC translation - virtual const char * asc2ebc(unsigned char *str, size_t sz = -1) = 0; - virtual const char * ebc2asc(unsigned char *str, size_t sz = -1) = 0; + virtual const char * asc2ebc(unsigned char *str, int sz = -1) = 0; + virtual const char * ebc2asc(unsigned char *str, int sz = -1) = 0; string asc2ebc(string &str); string ebc2asc(string &str); diff --git a/src/include/pw3270/ipcpackets.h b/src/include/pw3270/ipcpackets.h index f06ab4b..6a5fa29 100644 --- a/src/include/pw3270/ipcpackets.h +++ b/src/include/pw3270/ipcpackets.h @@ -59,6 +59,9 @@ HLLAPI_PACKET_SET_HOST_CHARSET, HLLAPI_PACKET_GET_HOST_CHARSET, + HLLAPI_PACKET_ASC2EBC, + HLLAPI_PACKET_EBC2ASC, + HLLAPI_PACKET_INVALID } HLLAPI_PACKET; diff --git a/src/lib3270/charset.c b/src/lib3270/charset.c index d455e51..ee3dd0f 100644 --- a/src/lib3270/charset.c +++ b/src/lib3270/charset.c @@ -406,7 +406,7 @@ LIB3270_ACTION( charsettable ) return 0; } -LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, size_t sz) +LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, int sz) { int f; if(sz < 0) @@ -421,7 +421,7 @@ LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buff return (const char *) buffer; } -LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, size_t sz) +LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, int sz) { int f; if(sz < 0) diff --git a/src/plugins/dbus3270/gobject.c b/src/plugins/dbus3270/gobject.c index c195909..26639ca 100644 --- a/src/plugins/dbus3270/gobject.c +++ b/src/plugins/dbus3270/gobject.c @@ -479,3 +479,35 @@ void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context) { dbus_g_method_return(context,lib3270_print(pw3270_dbus_get_session_handle(object))); } + +void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context) +{ + int sz = strlen(from); + + if(sz > 0) + { + unsigned char buffer[sz+1]; + memcpy(buffer,from,sz); + dbus_g_method_return(context,lib3270_ebc2asc(pw3270_dbus_get_session_handle(object),buffer,sz)); + return; + } + + dbus_g_method_return(context,""); + +} + +void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context) +{ + int sz = strlen(from); + + if(sz > 0) + { + unsigned char buffer[sz+1]; + memcpy(buffer,from,sz); + dbus_g_method_return(context,lib3270_asc2ebc(pw3270_dbus_get_session_handle(object),buffer,sz)); + return; + } + + dbus_g_method_return(context,""); + +} diff --git a/src/plugins/dbus3270/pw3270dbus.xml b/src/plugins/dbus3270/pw3270dbus.xml index 524cee6..6e39ecd 100644 --- a/src/plugins/dbus3270/pw3270dbus.xml +++ b/src/plugins/dbus3270/pw3270dbus.xml @@ -170,6 +170,16 @@ + + + + + + + + + + diff --git a/src/plugins/dbus3270/service.h b/src/plugins/dbus3270/service.h index 7aece11..3bbb0cc 100644 --- a/src/plugins/dbus3270/service.h +++ b/src/plugins/dbus3270/service.h @@ -112,6 +112,9 @@ void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context); void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context); + void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context); + G_END_DECLS #endif // _PW3270_DBUS_SERVICE_H diff --git a/src/plugins/hllapi/pluginmain.c b/src/plugins/hllapi/pluginmain.c index ddc41a6..a493513 100644 --- a/src/plugins/hllapi/pluginmain.c +++ b/src/plugins/hllapi/pluginmain.c @@ -313,6 +313,20 @@ (const char *) ((struct hllapi_packet_set_text *) source->buffer)->text)); break; + case HLLAPI_PACKET_ASC2EBC: + send_text(source,(char *) lib3270_asc2ebc( + lib3270_get_default_session_handle(), + (unsigned char *) ((struct hllapi_packet_set_text *) source->buffer)->text,-1 + )); + break; + + case HLLAPI_PACKET_EBC2ASC: + send_text(source,(char *) lib3270_ebc2asc( + lib3270_get_default_session_handle(), + (unsigned char *) ((struct hllapi_packet_set_text *) source->buffer)->text,-1 + )); + break; + case HLLAPI_PACKET_GET_HOST_CHARSET: send_text(source,(char *) lib3270_get_host_charset(lib3270_get_default_session_handle())); break; diff --git a/src/plugins/rx3270/pluginmain.cc b/src/plugins/rx3270/pluginmain.cc index 102ae05..05a91f4 100644 --- a/src/plugins/rx3270/pluginmain.cc +++ b/src/plugins/rx3270/pluginmain.cc @@ -135,8 +135,8 @@ string * get_host_charset(void); string * get_display_charset(void); - const char * asc2ebc(unsigned char *str, size_t sz = -1); - const char * ebc2asc(unsigned char *str, size_t sz = -1); + const char * asc2ebc(unsigned char *str, int sz = -1); + const char * ebc2asc(unsigned char *str, int sz = -1); int quit(void); @@ -761,12 +761,12 @@ int plugin::print(void) return lib3270_print(hSession); } -const char * plugin::asc2ebc(unsigned char *str, size_t sz) +const char * plugin::asc2ebc(unsigned char *str, int sz) { return lib3270_asc2ebc(hSession,str,sz); } -const char * plugin::ebc2asc(unsigned char *str, size_t sz) +const char * plugin::ebc2asc(unsigned char *str, int sz) { return lib3270_ebc2asc(hSession,str,sz); } -- libgit2 0.21.2