From 00e98f6ee3f76b8b894d779aeed2eab59aeb989d Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Tue, 5 Mar 2013 22:29:52 +0000 Subject: [PATCH] Reimplementando HLLAPI no novo formato --- src/include/pw3270/hllapi.h | 1 + src/plugins/remotectl/calls.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++------------------- src/plugins/remotectl/client.h | 1 + src/plugins/remotectl/hllapi.c | 10 +++++++++- src/plugins/remotectl/packets.h | 15 +++++++++++++++ src/plugins/remotectl/pluginmain.c | 10 +++++++++- src/plugins/remotectl/remote.c | 26 ++++++++++++++++++++++++++ 7 files changed, 112 insertions(+), 21 deletions(-) diff --git a/src/include/pw3270/hllapi.h b/src/include/pw3270/hllapi.h index be0cfdd..f93f9b3 100644 --- a/src/include/pw3270/hllapi.h +++ b/src/include/pw3270/hllapi.h @@ -78,6 +78,7 @@ extern "C" { __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void); __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void); __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer); + __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD pos, LPSTR buffer, WORD len); __declspec (dllexport) DWORD __stdcall hllapi_enter(void); __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text); __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text); diff --git a/src/plugins/remotectl/calls.c b/src/plugins/remotectl/calls.c index a0b9e81..2b276fb 100644 --- a/src/plugins/remotectl/calls.c +++ b/src/plugins/remotectl/calls.c @@ -55,6 +55,8 @@ static int (*script_sleep)(void *h, int seconds) = NULL; static LIB3270_MESSAGE (*get_message)(void *h) = NULL; static char * (*get_text)(void *h, int row, int col, int len) = NULL; + static char * (*get_text_at_offset)(void *h, int offset, int len) = NULL; + static void * (*release_memory)(void *p) = NULL; static int (*action_enter)(void *h) = NULL; static int (*set_text_at)(void *h, int row, int col, const unsigned char *str) = NULL; @@ -71,25 +73,25 @@ const char * name; } entry_point[] = { - { (void **) &session_new, (void *) hllapi_pipe_init, "lib3270_session_new" }, - { (void **) &session_free, (void *) hllapi_pipe_deinit, "lib3270_session_free" }, - { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, - { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, - { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" }, - { (void **) &host_is_connected, (void *) hllapi_pipe_is_connected, "lib3270_in_tn3270e" }, - { (void **) &wait_for_ready, (void *) hllapi_pipe_wait_for_ready, "lib3270_wait_for_ready" }, - { (void **) &script_sleep, (void *) hllapi_pipe_sleep, "lib3270_wait" }, - { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, - { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, - { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, - { (void **) &action_enter, (void *) hllapi_pipe_enter, "lib3270_enter" }, - { (void **) &set_text_at, (void *) hllapi_pipe_set_text_at, "lib3270_set_string_at" }, - { (void **) &cmp_text_at, (void *) hllapi_pipe_cmp_text_at, "lib3270_cmp_text_at" }, - { (void **) &pfkey, (void *) hllapi_pipe_pfkey, "lib3270_pfkey" }, - { (void **) &pakey, (void *) hllapi_pipe_pakey, "lib3270_pakey" }, - { (void **) &setcursor, (void *) hllapi_pipe_setcursor, "lib3270_set_cursor_address" }, - { (void **) &getcursor, (void *) hllapi_pipe_getcursor, "lib3270_get_cursor_address" }, - + { (void **) &session_new, (void *) hllapi_pipe_init, "lib3270_session_new" }, + { (void **) &session_free, (void *) hllapi_pipe_deinit, "lib3270_session_free" }, + { (void **) &get_revision, (void *) hllapi_pipe_get_revision, "lib3270_get_revision" }, + { (void **) &host_connect, (void *) hllapi_pipe_connect, "lib3270_connect" }, + { (void **) &host_disconnect, (void *) hllapi_pipe_disconnect, "lib3270_disconnect" }, + { (void **) &host_is_connected, (void *) hllapi_pipe_is_connected, "lib3270_in_tn3270e" }, + { (void **) &wait_for_ready, (void *) hllapi_pipe_wait_for_ready, "lib3270_wait_for_ready" }, + { (void **) &script_sleep, (void *) hllapi_pipe_sleep, "lib3270_wait" }, + { (void **) &get_message, (void *) hllapi_pipe_get_message, "lib3270_get_program_message" }, + { (void **) &get_text, (void *) hllapi_pipe_get_text_at, "lib3270_get_text_at" }, + { (void **) &release_memory, (void *) hllapi_pipe_release_memory, "lib3270_free" }, + { (void **) &action_enter, (void *) hllapi_pipe_enter, "lib3270_enter" }, + { (void **) &set_text_at, (void *) hllapi_pipe_set_text_at, "lib3270_set_string_at" }, + { (void **) &cmp_text_at, (void *) hllapi_pipe_cmp_text_at, "lib3270_cmp_text_at" }, + { (void **) &pfkey, (void *) hllapi_pipe_pfkey, "lib3270_pfkey" }, + { (void **) &pakey, (void *) hllapi_pipe_pakey, "lib3270_pakey" }, + { (void **) &setcursor, (void *) hllapi_pipe_setcursor, "lib3270_set_cursor_address" }, + { (void **) &getcursor, (void *) hllapi_pipe_getcursor, "lib3270_get_cursor_address" }, + { (void **) &get_text_at_offset, (void *) hllapi_pipe_get_text, "lib3270_get_text" }, { NULL, NULL } }; @@ -402,3 +404,33 @@ return -EINVAL; return getcursor(hSession)+1; } + + __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD pos, LPSTR buffer, WORD len) + { + char *text; + + trace("%s(%d,%d)",__FUNCTION__,pos,len); + + if(len < 0) + len = strlen(buffer); + + if(!(get_text_at_offset && hSession)) + return EINVAL; + + if(len > strlen(buffer)) + len = strlen(buffer); + + trace("len=%d",len); + text = get_text_at_offset(hSession,pos-1,len); + + trace("text=\n%s\n",text); + + if(!text) + return -1; + + memcpy(buffer,text,len); + + release_memory(text); + + return 0; + } diff --git a/src/plugins/remotectl/client.h b/src/plugins/remotectl/client.h index 4bf0e05..489503a 100644 --- a/src/plugins/remotectl/client.h +++ b/src/plugins/remotectl/client.h @@ -46,6 +46,7 @@ void hllapi_pipe_disconnect(void *h); LIB3270_MESSAGE hllapi_pipe_get_message(void *h); char * hllapi_pipe_get_text_at(void *h, int row, int col, int len); + char * hllapi_pipe_get_text(void *h, int offset, int len); int hllapi_pipe_enter(void *h); int hllapi_pipe_set_text_at(void *h, int row, int col, const unsigned char *str); int hllapi_pipe_cmp_text_at(void *h, int row, int col, const char *text); diff --git a/src/plugins/remotectl/hllapi.c b/src/plugins/remotectl/hllapi.c index 1b29ee5..647964a 100644 --- a/src/plugins/remotectl/hllapi.c +++ b/src/plugins/remotectl/hllapi.c @@ -43,6 +43,7 @@ static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc); static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc); static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc); + static int copy_ps_to_str(char *buffer, unsigned short *length, unsigned short *rc); static int get_cursor_position(char *buffer, unsigned short *length, unsigned short *rc); static int set_cursor_position(char *buffer, unsigned short *length, unsigned short *rc); @@ -59,7 +60,8 @@ { HLLAPI_CMD_DISCONNECTPS, disconnect_ps }, { HLLAPI_CMD_GETREVISION, get_library_revision }, { HLLAPI_CMD_QUERYCURSOR, get_cursor_position }, - { HLLAPI_CMD_SETCURSOR, set_cursor_position }, + { HLLAPI_CMD_SETCURSOR, set_cursor_position }, + { HLLAPI_CMD_COPYPSTOSTR, copy_ps_to_str }, }; /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -149,6 +151,12 @@ static int set_cursor_position(char *buffer, unsigned short *length, unsigned sh return 0; } +static int copy_ps_to_str(char *buffer, unsigned short *length, unsigned short *rc) +{ + // Length Length of the target data string. + // PS Position Position within the host presentation space of the first byte in your target data string. + return hllapi_get_screen(*rc,buffer,*length); +} /* static int cmd_connect_ps(const char *name) diff --git a/src/plugins/remotectl/packets.h b/src/plugins/remotectl/packets.h index 755e798..ae6f0da 100644 --- a/src/plugins/remotectl/packets.h +++ b/src/plugins/remotectl/packets.h @@ -32,6 +32,7 @@ HLLAPI_PACKET_CONNECT, HLLAPI_PACKET_DISCONNECT, HLLAPI_PACKET_GET_PROGRAM_MESSAGE, + HLLAPI_PACKET_GET_TEXT_AT_OFFSET, HLLAPI_PACKET_GET_TEXT_AT, HLLAPI_PACKET_SET_TEXT_AT, HLLAPI_PACKET_CMP_TEXT_AT, @@ -56,6 +57,12 @@ struct hllapi_packet_result int rc; }; +struct hllapi_packet_text_result +{ + int rc; + char text[1]; +}; + struct hllapi_packet_query { unsigned char packet_id; @@ -123,6 +130,14 @@ struct hllapi_packet_addr unsigned short addr; }; +struct hllapi_packet_query_offset +{ + unsigned char packet_id; + unsigned short addr; + unsigned short len; +}; + + #pragma pack() diff --git a/src/plugins/remotectl/pluginmain.c b/src/plugins/remotectl/pluginmain.c index 0b98344..9e16f0c 100644 --- a/src/plugins/remotectl/pluginmain.c +++ b/src/plugins/remotectl/pluginmain.c @@ -154,7 +154,9 @@ pkt->packet_id = errno ? errno : -1; } - WriteFile(source->hPipe,&pkt,szBlock,&szBlock,NULL); + WriteFile(source->hPipe,pkt,szBlock,&szBlock,NULL); + + g_free(pkt); } static void send_result(pipe_source *source, int rc) @@ -223,6 +225,12 @@ ((struct hllapi_packet_at *) source->buffer)->len)); break; + case HLLAPI_PACKET_GET_TEXT_AT_OFFSET: + send_text(source,lib3270_get_text( lib3270_get_default_session_handle(), + ((struct hllapi_packet_query_offset *) source->buffer)->addr, + ((struct hllapi_packet_query_offset *) source->buffer)->len)); + break; + case HLLAPI_PACKET_CMP_TEXT_AT: send_result(source,lib3270_cmp_text_at( lib3270_get_default_session_handle(), ((struct hllapi_packet_text_at *) source->buffer)->row, diff --git a/src/plugins/remotectl/remote.c b/src/plugins/remotectl/remote.c index 89e2e53..4cac7cf 100644 --- a/src/plugins/remotectl/remote.c +++ b/src/plugins/remotectl/remote.c @@ -306,3 +306,29 @@ TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); return response.rc; } + + char * hllapi_pipe_get_text(void *h, int offset, int len) + { + struct hllapi_packet_query_offset query = { HLLAPI_PACKET_GET_TEXT_AT_OFFSET, offset, len }; + struct hllapi_packet_text * response; + DWORD cbSize = sizeof(struct hllapi_packet_text)+len; + char * text = NULL; + + trace("cbSize=%d",(int) cbSize); + + response = malloc(cbSize+2); + memset(response,0,cbSize+2); + + if(!TransactNamedPipe((HANDLE) h,(LPVOID) &query, sizeof(query), response, cbSize, &cbSize,NULL)) + return NULL; + + trace("rc=%d",response->packet_id); + + if(response->packet_id) + errno = response->packet_id; + else + text = strdup(response->text); + + free(response); + return text; + } -- libgit2 0.21.2