From 4ea0d6c5857064187cf28dad83e3e1e46b0e0a17 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Tue, 5 Mar 2013 21:41:20 +0000 Subject: [PATCH] Ajustando chamadas hllapi --- src/lib3270/screen.c | 2 ++ src/plugins/remotectl/calls.c | 5 +++-- src/plugins/remotectl/hllapi.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- src/plugins/remotectl/packets.h | 22 +++++++++++----------- src/plugins/remotectl/pluginmain.c | 6 +++--- src/plugins/remotectl/remote.c | 6 ++++++ 6 files changed, 68 insertions(+), 23 deletions(-) diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c index 03536f7..5368676 100644 --- a/src/lib3270/screen.c +++ b/src/lib3270/screen.c @@ -388,6 +388,8 @@ LIB3270_EXPORT int lib3270_get_cursor_address(H3270 *h) LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *h, int baddr) { CHECK_SESSION_HANDLE(h); + + trace("%s(%d)",__FUNCTION__,baddr); if(h->selected && !lib3270_get_toggle(h,LIB3270_TOGGLE_KEEP_SELECTED)) lib3270_unselect(h); diff --git a/src/plugins/remotectl/calls.c b/src/plugins/remotectl/calls.c index edca890..a85c8ca 100644 --- a/src/plugins/remotectl/calls.c +++ b/src/plugins/remotectl/calls.c @@ -392,12 +392,13 @@ { if(!(setcursor && hSession)) return EINVAL; - return setcursor(hSession,pos+1); + trace("%s(%d)",__FUNCTION__,pos); + return setcursor(hSession,pos-1); } __declspec (dllexport) DWORD __stdcall hllapi_getcursor() { if(!(getcursor && hSession)) return -EINVAL; - return getcursor(hSession)-1; + return getcursor(hSession); } diff --git a/src/plugins/remotectl/hllapi.c b/src/plugins/remotectl/hllapi.c index c003ef7..1b29ee5 100644 --- a/src/plugins/remotectl/hllapi.c +++ b/src/plugins/remotectl/hllapi.c @@ -34,6 +34,9 @@ #include #include #include + + #undef trace + #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } } /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ @@ -68,7 +71,9 @@ #endif // _WIN32 { int f; - + + trace("%s(%d)",__FUNCTION__,*func); + for(f=0;f< (sizeof (hllapi_call) / sizeof ((hllapi_call)[0]));f++) { if(hllapi_call[f].func == *func) @@ -81,11 +86,34 @@ } static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc) -{ +{ + char *tempbuffer = NULL; + + trace("%s: len=%d buflen=%d",__FUNCTION__,*length,strlen(buffer)); + + if(strlen(buffer) > *length) + buffer[*length] = 0; + + if(!strrchr(buffer,':')) + { + int sz = strlen(buffer); + + tempbuffer = malloc(sz+2); + strcpy(tempbuffer,buffer); + tempbuffer[sz-1] = ':'; + tempbuffer[sz] = buffer[sz-1]; + tempbuffer[sz+1] = 0; + buffer = tempbuffer; + } + if(hllapi_init(buffer) == 0) *rc = HLLAPI_STATUS_SUCESS; else - *rc = HLLAPI_STATUS_UNAVAILABLE; + *rc = HLLAPI_STATUS_UNAVAILABLE; + + if(tempbuffer) + free(tempbuffer); + return 0; } @@ -102,14 +130,22 @@ static int get_library_revision(char *buffer, unsigned short *length, unsigned s } static int get_cursor_position(char *buffer, unsigned short *length, unsigned short *rc) -{ - *rc = hllapi_getcursor()-1; +{ + int pos = hllapi_getcursor(); + + trace("%s(%d)",__FUNCTION__,pos); + + if(pos < 0) + return -1; + + *rc = pos; return 0; } static int set_cursor_position(char *buffer, unsigned short *length, unsigned short *rc) -{ - *rc = hllapi_setcursor(*rc+1); +{ + trace("%s(%d)",__FUNCTION__,*rc); + *rc = hllapi_setcursor(*rc); return 0; } diff --git a/src/plugins/remotectl/packets.h b/src/plugins/remotectl/packets.h index c82e599..755e798 100644 --- a/src/plugins/remotectl/packets.h +++ b/src/plugins/remotectl/packets.h @@ -58,38 +58,38 @@ struct hllapi_packet_result struct hllapi_packet_query { - int packet_id; + unsigned char packet_id; }; struct hllapi_packet_connect { - int packet_id; + unsigned char packet_id; unsigned char wait; char hostname[1]; }; struct hllapi_packet_keycode { - int packet_id; + unsigned char packet_id; unsigned short keycode; }; struct hllapi_packet_cursor { - int packet_id; + unsigned char packet_id; unsigned short row; unsigned short col; }; struct hllapi_packet_text { - int packet_id; + unsigned char packet_id; char text[1]; }; struct hllapi_packet_at { - int packet_id; + unsigned char packet_id; unsigned short row; unsigned short col; unsigned short len; @@ -97,7 +97,7 @@ struct hllapi_packet_at struct hllapi_packet_text_at { - int packet_id; + unsigned char packet_id; unsigned short row; unsigned short col; char text[1]; @@ -105,7 +105,7 @@ struct hllapi_packet_text_at struct hllapi_packet_query_at { - int packet_id; + unsigned char packet_id; unsigned short row; unsigned short col; unsigned short len; @@ -113,14 +113,14 @@ struct hllapi_packet_query_at struct hllapi_packet_wait { - int packet_id; + unsigned char packet_id; int timeout; }; struct hllapi_packet_addr { - int packet_id; - int addr; + unsigned char packet_id; + unsigned short addr; }; diff --git a/src/plugins/remotectl/pluginmain.c b/src/plugins/remotectl/pluginmain.c index b18e566..0b98344 100644 --- a/src/plugins/remotectl/pluginmain.c +++ b/src/plugins/remotectl/pluginmain.c @@ -167,9 +167,9 @@ static void process_input(pipe_source *source, DWORD cbRead) { - trace("%s id=%d",__FUNCTION__,source->buffer[0]); + trace("%s id=%d",__FUNCTION__,((struct hllapi_packet_query *) source->buffer)->packet_id); - switch(source->buffer[0]) + switch(((struct hllapi_packet_query *) source->buffer)->packet_id) { case HLLAPI_PACKET_CONNECT: send_result(source,lib3270_connect( lib3270_get_default_session_handle(), @@ -235,7 +235,7 @@ (unsigned char *) ((struct hllapi_packet_text *) source->buffer)->text)); break; - case HLLAPI_PACKET_SET_CURSOR: + case HLLAPI_PACKET_SET_CURSOR: send_result(source,lib3270_set_cursor_address(lib3270_get_default_session_handle(), ((struct hllapi_packet_addr *) source->buffer)->addr)); break; diff --git a/src/plugins/remotectl/remote.c b/src/plugins/remotectl/remote.c index d927a34..89e2e53 100644 --- a/src/plugins/remotectl/remote.c +++ b/src/plugins/remotectl/remote.c @@ -287,6 +287,9 @@ static const struct hllapi_packet_query query = { HLLAPI_PACKET_GET_CURSOR }; struct hllapi_packet_result response; DWORD cbSize = sizeof(query); + + trace("%s",__FUNCTION__); + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); return (LIB3270_MESSAGE) response.rc; @@ -297,6 +300,9 @@ struct hllapi_packet_addr query = { HLLAPI_PACKET_SET_CURSOR, baddr }; struct hllapi_packet_result response; DWORD cbSize = sizeof(query); + + trace("%s(%d)",__FUNCTION__,query.addr); + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL); return response.rc; } -- libgit2 0.21.2