From 62ed4ef47e17366a751263500ea6d3855f859c7e Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 21 Sep 2020 16:31:42 -0300 Subject: [PATCH] Implementing hllapi_set_session_property(const LPSTR property, const LPSTR value) method. --- src/core/controller.cc | 5 +++++ src/core/hllapi.cc | 33 ++++++++++++++++++++++++++++++++- src/core/set.cc | 17 +++++++++++++++++ src/include/lib3270/hllapi.h | 1 + src/testprogram/testprogram.cc | 6 ++++++ 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/core/controller.cc b/src/core/controller.cc index 062b19b..141ee25 100644 --- a/src/core/controller.cc +++ b/src/core/controller.cc @@ -70,6 +70,11 @@ debug("Will set timeout to %d",120); +#ifdef DEBUG + // Hack to speed up the tests. + hllapi_host->setProperty("crl_download",false); +#endif // DEBUG + hllapi_host->setTimeout(120); } catch(const std::exception &e) { diff --git a/src/core/hllapi.cc b/src/core/hllapi.cc index ebf47e3..6ca1188 100644 --- a/src/core/hllapi.cc +++ b/src/core/hllapi.cc @@ -470,7 +470,38 @@ HLLAPI_API_CALL hllapi_set_session_parameter(LPSTR param, WORD len, WORD value) } else { - return HLLAPI_STATUS_BAD_PARAMETER; + int rc = HLLAPI_STATUS_BAD_PARAMETER; + + char * buffer = NULL; + asprintf(&buffer,"%u",(unsigned int) value); + + if(!buffer) + return HLLAPI_STATUS_SYSTEM_ERROR; + + try { + + getSession().setProperty(param,buffer); + + } catch(const std::system_error &e) { + + rc = hllapi_translate_error(e); + + } catch(const std::exception &e) { + + // Error getting session or lock state + hllapi_lasterror = e.what(); + rc = HLLAPI_STATUS_SYSTEM_ERROR; + + } catch(...) { + + // Unexpected error getting session or lock state + hllapi_lasterror = _( "Unexpected error" ); + rc = HLLAPI_STATUS_SYSTEM_ERROR; + + } + + free(buffer); + return rc; } diff --git a/src/core/set.cc b/src/core/set.cc index 0338ff8..3dac5d2 100644 --- a/src/core/set.cc +++ b/src/core/set.cc @@ -117,3 +117,20 @@ }); } + + HLLAPI_API_CALL hllapi_set_session_property(const LPSTR property, const LPSTR value) { + + if(!(property && *property)) { + hllapi_lasterror = _( "Invalid property name" ); + return HLLAPI_STATUS_BAD_PARAMETER; + + } + + return set([property,value](TN3270::Host &host) { + + host.setProperty(property,value); + + }); + + } + diff --git a/src/include/lib3270/hllapi.h b/src/include/lib3270/hllapi.h index b988c57..1e7d274 100644 --- a/src/include/lib3270/hllapi.h +++ b/src/include/lib3270/hllapi.h @@ -330,6 +330,7 @@ HLLAPI_API_CALL hllapi_pakey(WORD key); HLLAPI_API_CALL hllapi_set_session_parameter(LPSTR param, WORD len, WORD value); + HLLAPI_API_CALL hllapi_set_session_property(const LPSTR property, const LPSTR value); HLLAPI_API_CALL hllapi_enter(void); HLLAPI_API_CALL hllapi_erase(void); diff --git a/src/testprogram/testprogram.cc b/src/testprogram/testprogram.cc index ec3e599..0c3e3b4 100644 --- a/src/testprogram/testprogram.cc +++ b/src/testprogram/testprogram.cc @@ -89,6 +89,9 @@ #endif // ! defined(_MSC_VER) + cout << "Host: \"" << host << "\"" << endl + << "Session: \"" << session << "\"" << endl; + try { rc = hllapi_init((char *) session); @@ -101,6 +104,9 @@ hllapi_set_timeout(10); + // Hack to speed up connection. + hllapi_set_session_property("crl_download","0"); + } catch(const std::exception &e) { cerr << e.what() << endl; -- libgit2 0.21.2