Commit 7a43c610e3635d29e4dd638bfe08390ce8acbd4b

Authored by Perry Werneck
1 parent 2a69db4a

Adding "wait for string" methods

Standardizing API Calls
src/core/html.c
@@ -282,7 +282,7 @@ @@ -282,7 +282,7 @@
282 } 282 }
283 else if(session->text[baddr+col+1].chr == 'F') 283 else if(session->text[baddr+col+1].chr == 'F')
284 { 284 {
285 - char *text = lib3270_get_field_text_at(session,baddr+col+1); 285 + char *text = lib3270_get_field_string_at(session,baddr+col+1);
286 286
287 if(text) 287 if(text)
288 { 288 {
src/core/wait.c
@@ -67,6 +67,42 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) @@ -67,6 +67,42 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds)
67 return errno = ETIMEDOUT; 67 return errno = ETIMEDOUT;
68 } 68 }
69 69
  70 +int lib3270_wait_for_text(H3270 *hSession, const char *key, int seconds)
  71 +{
  72 + time_t end = time(0)+seconds;
  73 +
  74 + FAIL_IF_NOT_ONLINE(hSession);
  75 +
  76 + lib3270_main_iterate(hSession,0);
  77 +
  78 + do
  79 + {
  80 + // Keyboard is locked by operator error, fails!
  81 + if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession))
  82 + return errno = EPERM;
  83 +
  84 + if(!lib3270_connected(hSession))
  85 + return errno = ENOTCONN;
  86 +
  87 + char * contents = lib3270_get_string_at_address(hSession, 0, -1, 0);
  88 + if(!contents)
  89 + return errno;
  90 +
  91 + if(strstr(contents,key)) {
  92 + lib3270_free(contents);
  93 + return 0;
  94 + }
  95 +
  96 + lib3270_free(contents);
  97 +
  98 + lib3270_main_iterate(hSession,1);
  99 +
  100 + }
  101 + while(time(0) < end);
  102 +
  103 + return errno = ETIMEDOUT;
  104 +}
  105 +
70 int lib3270_wait_for_string_at_address(H3270 *hSession, int baddr, const char *key, int seconds) 106 int lib3270_wait_for_string_at_address(H3270 *hSession, int baddr, const char *key, int seconds)
71 { 107 {
72 time_t end = time(0)+seconds; 108 time_t end = time(0)+seconds;
@@ -87,7 +123,7 @@ int lib3270_wait_for_string_at_address(H3270 *hSession, int baddr, const char *k @@ -87,7 +123,7 @@ int lib3270_wait_for_string_at_address(H3270 *hSession, int baddr, const char *k
87 if(!lib3270_connected(hSession)) 123 if(!lib3270_connected(hSession))
88 return errno = ENOTCONN; 124 return errno = ENOTCONN;
89 125
90 - if(lib3270_cmp_text_at_address(hSession, baddr, key, 0) == 0) 126 + if(lib3270_cmp_string_at_address(hSession, baddr, key, 0) == 0)
91 return 0; 127 return 0;
92 128
93 lib3270_main_iterate(hSession,1); 129 lib3270_main_iterate(hSession,1);
src/include/lib3270.h
@@ -705,9 +705,7 @@ @@ -705,9 +705,7 @@
705 * @return Negative if error (sets errno) or number of processed characters. 705 * @return Negative if error (sets errno) or number of processed characters.
706 * 706 *
707 */ 707 */
708 - LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *text, int length);  
709 -  
710 - #define lib3270_set_text_at(h,r,c,t) lib3270_set_string_at(h,r,c,t,-1) 708 + LIB3270_EXPORT int lib3270_set_text(H3270 *h, const unsigned char *text, int length);
711 709
712 /** 710 /**
713 * @brief Set string at defined row/column. 711 * @brief Set string at defined row/column.
@@ -1135,9 +1133,9 @@ @@ -1135,9 +1133,9 @@
1135 * @return Test result from strcmp 1133 * @return Test result from strcmp
1136 * 1134 *
1137 */ 1135 */
1138 - LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, unsigned int row, unsigned int col, const char *text, char lf); 1136 + LIB3270_EXPORT int lib3270_cmp_string_at(H3270 *h, unsigned int row, unsigned int col, const char *text, char lf);
1139 1137
1140 - LIB3270_EXPORT int lib3270_cmp_text_at_address(H3270 *h, int baddr, const char *text, char lf); 1138 + LIB3270_EXPORT int lib3270_cmp_string_at_address(H3270 *h, int baddr, const char *text, char lf);
1141 1139
1142 /** 1140 /**
1143 * @brief Get contents of the field at position. 1141 * @brief Get contents of the field at position.
@@ -1151,7 +1149,7 @@ @@ -1151,7 +1149,7 @@
1151 * @exception EOVERFLOW Invalid position. 1149 * @exception EOVERFLOW Invalid position.
1152 * 1150 *
1153 */ 1151 */
1154 - LIB3270_EXPORT char * lib3270_get_field_text_at(H3270 *h, int baddr); 1152 + LIB3270_EXPORT char * lib3270_get_field_string_at(H3270 *h, int baddr);
1155 1153
1156 /** 1154 /**
1157 * @brief Find the next unprotected field. 1155 * @brief Find the next unprotected field.
@@ -1481,6 +1479,22 @@ @@ -1481,6 +1479,22 @@
1481 LIB3270_EXPORT char lib3270_get_session_id(H3270 *hSession); 1479 LIB3270_EXPORT char lib3270_get_session_id(H3270 *hSession);
1482 1480
1483 /** 1481 /**
  1482 + * @brief Wait for string at screen.
  1483 + *
  1484 + * @param hSession TN3270 Session.
  1485 + * @param key The string to wait for.
  1486 + * @param seconds Maximum wait time.
  1487 + *
  1488 + * @return 0 if the string was found, error code if not (sets errno).
  1489 + *
  1490 + * @retval ENOTCONN Not connected to host.
  1491 + * @retval ETIMEDOUT Timeout.
  1492 + * @retval EPERM The keyboard is locked.
  1493 + *
  1494 + */
  1495 + LIB3270_EXPORT int lib3270_wait_for_string(H3270 *hSession, const char *key, int seconds);
  1496 +
  1497 + /**
1484 * @brief Wait for string at position. 1498 * @brief Wait for string at position.
1485 * 1499 *
1486 * @param hSession TN3270 Session. 1500 * @param hSession TN3270 Session.
src/selection/selection.c
@@ -345,16 +345,16 @@ LIB3270_EXPORT char * lib3270_get_string_at(H3270 *h, unsigned int row, unsigned @@ -345,16 +345,16 @@ LIB3270_EXPORT char * lib3270_get_string_at(H3270 *h, unsigned int row, unsigned
345 return lib3270_get_string_at_address(h, baddr, len, lf); 345 return lib3270_get_string_at_address(h, baddr, len, lf);
346 } 346 }
347 347
348 -LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, unsigned int row, unsigned int col, const char *text, char lf) 348 +LIB3270_EXPORT int lib3270_cmp_string_at(H3270 *h, unsigned int row, unsigned int col, const char *text, char lf)
349 { 349 {
350 int baddr = lib3270_translate_to_address(h,row,col); 350 int baddr = lib3270_translate_to_address(h,row,col);
351 if(baddr < 0) 351 if(baddr < 0)
352 return -1; 352 return -1;
353 353
354 - return lib3270_cmp_text_at_address(h,baddr,text,lf); 354 + return lib3270_cmp_string_at_address(h,baddr,text,lf);
355 } 355 }
356 356
357 - LIB3270_EXPORT int lib3270_cmp_text_at_address(H3270 *h, int baddr, const char *text, char lf) 357 + LIB3270_EXPORT int lib3270_cmp_string_at_address(H3270 *h, int baddr, const char *text, char lf)
358 { 358 {
359 int rc; 359 int rc;
360 size_t sz = strlen(text); 360 size_t sz = strlen(text);
@@ -380,7 +380,7 @@ LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, unsigned int row, unsigned int @@ -380,7 +380,7 @@ LIB3270_EXPORT int lib3270_cmp_text_at(H3270 *h, unsigned int row, unsigned int
380 * 380 *
381 * @return String with the field contents (release it with lib3270_free() 381 * @return String with the field contents (release it with lib3270_free()
382 */ 382 */
383 -LIB3270_EXPORT char * lib3270_get_field_text_at(H3270 *session, int baddr) 383 +LIB3270_EXPORT char * lib3270_get_field_string_at(H3270 *session, int baddr)
384 { 384 {
385 int first = lib3270_field_addr(session,baddr); 385 int first = lib3270_field_addr(session,baddr);
386 386
src/ssl/negotiate.c
@@ -434,7 +434,7 @@ void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) @@ -434,7 +434,7 @@ void ssl_info_callback(INFO_CONST SSL *s, int where, int ret)
434 434
435 #endif /*]*/ 435 #endif /*]*/
436 436
437 -int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const char *title, const char *summary, const char *body) 437 +int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const char GNUC_UNUSED(*title), const char *summary, const char *body)
438 { 438 {
439 #ifdef _WIN32 439 #ifdef _WIN32
440 440