diff --git a/src/core/host.c b/src/core/host.c index ab51d29..edd4f2f 100644 --- a/src/core/host.c +++ b/src/core/host.c @@ -261,13 +261,6 @@ static void update_url(H3270 *hSession) } -LIB3270_EXPORT int lib3270_set_luname(H3270 *hSession, const char *luname) -{ - FAIL_IF_ONLINE(hSession); - strncpy(hSession->lu.names,luname,LIB3270_LUNAME_LENGTH); - return 0; -} - LIB3270_EXPORT const char * lib3270_get_associated_luname(const H3270 *hSession) { if(check_online_session(hSession)) diff --git a/src/core/properties/string.c b/src/core/properties/string.c index 2b750e2..7c96f3a 100644 --- a/src/core/properties/string.c +++ b/src/core/properties/string.c @@ -33,6 +33,7 @@ #include #include #include + #include static const char * get_version(const H3270 GNUC_UNUSED(*hSession)) { @@ -289,3 +290,73 @@ int lib3270_set_string_property(H3270 *hSession, const char *name, const char * } +/* +LIB3270_EXPORT int lib3270_set_luname(H3270 *hSession, const char *luname) +{ + FAIL_IF_ONLINE(hSession); + strncpy(hSession->lu.names,luname,LIB3270_LUNAME_LENGTH); + return 0; +} +*/ + +LIB3270_EXPORT int lib3270_set_lunames(H3270 *hSession, const char *lunames) +{ + FAIL_IF_ONLINE(hSession); + + if(hSession->lu.names) + { + lib3270_free(hSession->lu.names); + hSession->lu.names = NULL; + } + + // Do I have lunames to set? If not just return. + if(!lunames) + return 0; + + // + // Count the commas in the LU names. That plus one is the + // number of LUs to try. + // + char *comma; + char *lu; + int n_lus = 1; + + lu = (char *) lunames; + while ((comma = strchr(lu, ',')) != CN) + { + n_lus++; + lu++; + } + + // + // Allocate enough memory to construct an argv[] array for + // the LUs. + // + Replace(hSession->lu.names,(char **)lib3270_malloc((n_lus+1) * sizeof(char *) + strlen(lunames) + 1)); + + // Copy each LU into the array. + lu = (char *)(hSession->lu.names + n_lus + 1); + (void) strcpy(lu, lunames); + + size_t i = 0; + do + { + hSession->lu.names[i++] = lu; + comma = strchr(lu, ','); + if (comma != CN) + { + *comma = '\0'; + lu = comma + 1; + } + } while (comma != CN); + + hSession->lu.names[i] = CN; + + return 0; +} + +LIB3270_EXPORT const char ** lib3270_get_lunames(H3270 *hSession) +{ + return (const char **) hSession->lu.names; +} + diff --git a/src/core/session.c b/src/core/session.c index b3bd956..306d5aa 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -99,6 +99,14 @@ void lib3270_session_free(H3270 *h) for(f=0;flisteners.actions[f]); + // Release Lu names + if(h->lu.names) + { + lib3270_free(h->lu.names); + h->lu.names = NULL; + } + + // Release memory #define release_pointer(x) lib3270_free(x); x = NULL; diff --git a/src/core/telnet.c b/src/core/telnet.c index 54e904d..8cf6960 100644 --- a/src/core/telnet.c +++ b/src/core/telnet.c @@ -369,13 +369,26 @@ void popup_a_sockerr(H3270 *hSession, char *fmt, ...) // Set up the LU list. static void setup_lus(H3270 *hSession) { + hSession->lu.associated = CN; + hSession->connected_type = CN; + + if(hSession->lu.names) + { + hSession->lu.curr = hSession->lu.names; + hSession->lu.try = * hSession->lu.curr; + } + else + { + hSession->lu.curr = (char **)NULL; + hSession->lu.try = CN; + } + + /* char *lu; char *comma; int n_lus = 1; int i; - hSession->lu.associated = CN; - hSession->connected_type = CN; if (!hSession->lu.names[0]) { @@ -419,8 +432,8 @@ static void setup_lus(H3270 *hSession) } while (comma != CN); hSession->lus[i] = CN; - hSession->curr_lu = hSession->lus; - hSession->try_lu = *hSession->curr_lu; + */ + } static int net_connected(H3270 *hSession) @@ -775,11 +788,13 @@ static void send_naws(H3270 *hSession) -/* Advance 'try_lu' to the next desired LU name. */ +/// +/// @brief Advance 'try_lu' to the next desired LU name. +/// static void next_lu(H3270 *hSession) { - if (hSession->curr_lu != (char **)NULL && (hSession->try_lu = *++hSession->curr_lu) == CN) - hSession->curr_lu = (char **)NULL; + if (hSession->lu.curr != (char **)NULL && (hSession->lu.try = *++hSession->lu.curr) == CN) + hSession->lu.curr = (char **)NULL; } /* @@ -1087,7 +1102,7 @@ static int telnet_fsm(H3270 *hSession, unsigned char c) trace_dsn(hSession,"%s %s\n", opt(hSession->sbbuf[0]),telquals[hSession->sbbuf[1]]); - if (hSession->lus != (char **)NULL && hSession->try_lu == CN) + if (hSession->lu.names != (char **)NULL && hSession->lu.try == CN) { // None of the LUs worked. popup_an_error(hSession, _( "Cannot connect to specified LU" ) ); @@ -1095,10 +1110,10 @@ static int telnet_fsm(H3270 *hSession, unsigned char c) } tt_len = strlen(hSession->termtype); - if (hSession->try_lu != CN && *hSession->try_lu) + if (hSession->lu.try != CN && *hSession->lu.try) { - tt_len += strlen(hSession->try_lu) + 1; - hSession->lu.associated = hSession->try_lu; + tt_len += strlen(hSession->lu.try) + 1; + hSession->lu.associated = hSession->lu.try; } else { @@ -1112,8 +1127,8 @@ static int telnet_fsm(H3270 *hSession, unsigned char c) (void) sprintf(tt_out, "%c%c%c%c%s%s%s%c%c", IAC, SB, TELOPT_TTYPE, TELQUAL_IS, hSession->termtype, - (hSession->try_lu != CN && *hSession->try_lu) ? "@" : "", - (hSession->try_lu != CN && *hSession->try_lu) ? hSession->try_lu : "", + (hSession->lu.try != CN && *hSession->lu.try) ? "@" : "", + (hSession->lu.try != CN && *hSession->lu.try) ? hSession->lu.try : "", IAC, SE); net_rawout(hSession, (unsigned char *)tt_out, tb_len); @@ -1175,7 +1190,7 @@ static void continue_tls(H3270 *hSession, unsigned char *sbbuf, int len) #endif // HAVE_LIBSSL #if defined(X3270_TN3270E) /*[*/ -/* Send a TN3270E terminal type request. */ +/// @brief Send a TN3270E terminal type request. static void tn3270e_request(H3270 *hSession) { int tt_len, tb_len; @@ -1183,8 +1198,8 @@ static void tn3270e_request(H3270 *hSession) char *t; tt_len = strlen(hSession->termtype); - if (hSession->try_lu != CN && *hSession->try_lu) - tt_len += strlen(hSession->try_lu) + 1; + if (hSession->lu.try != CN && *hSession->lu.try) + tt_len += strlen(hSession->lu.try) + 1; tb_len = 5 + tt_len + 2; tt_out = lib3270_malloc(tb_len + 1); @@ -1197,8 +1212,8 @@ static void tn3270e_request(H3270 *hSession) if (tt_out[12] == '9') tt_out[12] = '8'; - if (hSession->try_lu != CN && *hSession->try_lu) - t += sprintf(t, "%c%s", TN3270E_OP_CONNECT, hSession->try_lu); + if (hSession->lu.try != CN && *hSession->lu.try) + t += sprintf(t, "%c%s", TN3270E_OP_CONNECT, hSession->lu.try); (void) sprintf(t, "%c%c", IAC, SE); @@ -1210,8 +1225,8 @@ static void tn3270e_request(H3270 *hSession) opt(TELOPT_TN3270E), (int) strlen(hSession->termtype), tt_out + 5, - (hSession->try_lu != CN && *hSession->try_lu) ? " CONNECT " : "", - (hSession->try_lu != CN && *hSession->try_lu) ? hSession->try_lu : "", + (hSession->lu.try != CN && *hSession->lu.try) ? " CONNECT " : "", + (hSession->lu.try != CN && *hSession->lu.try) ? hSession->lu.try : "", cmd(SE) ); @@ -1332,14 +1347,14 @@ static int tn3270e_negotiate(H3270 *hSession) } next_lu(hSession); - if (hSession->try_lu != CN) + if (hSession->lu.try != CN) { - /* Try the next LU. */ + // Try the next LU. tn3270e_request(hSession); } - else if (hSession->lus != (char **)NULL) + else if (hSession->lu.names != (char **)NULL) { - /* No more LUs to try. Give up. */ + // No more LUs to try. Give up. backoff_tn3270e(hSession,_("Host rejected resource(s)")); } else @@ -2096,9 +2111,9 @@ static void check_in3270(H3270 *hSession) // TN3270E mode, reset the LU list so we can try again // in the new mode. // - if (hSession->lus != (char **)NULL && was_in_e != IN_E) { - hSession->curr_lu = hSession->lus; - hSession->try_lu = *hSession->curr_lu; + if (hSession->lu.names != (char **)NULL && was_in_e != IN_E) { + hSession->lu.curr = hSession->lu.names; + hSession->lu.try = *hSession->lu.curr; } #endif diff --git a/src/core/toggles/table.c b/src/core/toggles/table.c index 080085b..51caaf2 100644 --- a/src/core/toggles/table.c +++ b/src/core/toggles/table.c @@ -239,8 +239,8 @@ const LIB3270_TOGGLE toggle_descriptor[LIB3270_TOGGLE_COUNT+1] = .def = False, .key = NULL, // Default keycode .icon = NULL, // Icon name - .label = N_( "Auto connect" ), - .summary = N_( "Connect on startup" ), + .label = N_( "Connect on startup" ), + .summary = N_( "Automatically connect to host on startup" ), .description = "" }, { diff --git a/src/include/internals.h b/src/include/internals.h index 9fd5e83..dfe2b48 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -508,14 +508,13 @@ struct _h3270 */ /// @brief LU - char **curr_lu; - char * try_lu; - char **lus; ///< @brief Array with the LU names to try. struct { - char reported[LIB3270_LU_MAX+1]; - char * associated; ///< @brief The LU name associated with the session. - char names[LIB3270_LUNAME_LENGTH+1]; ///< @brief The LU names to try. + char reported[LIB3270_LU_MAX+1]; + const char * associated; ///< @brief The LU name associated with the session. + char **names; ///< @brief Array with the LU names to try. + char **curr; + const char * try; } lu; diff --git a/src/include/lib3270.h b/src/include/lib3270.h index dfefc71..d47f5cf 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -964,7 +964,7 @@ LIB3270_EXPORT void lib3270_register_fd_handlers(void * (*add)(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata), void (*rm)(H3270 *, void *id)); /** - * Get program message. + * @brief Get program message. * * @see LIB3270_MESSAGE * @@ -976,7 +976,7 @@ LIB3270_EXPORT LIB3270_MESSAGE lib3270_get_program_message(const H3270 *h); /** - * Get the LU name associated with the session, if there is one. + * @brief Get the LU name associated with the session, if there is one. * * Get the name LU associated with the session; the value is * internal to lib3270 and should not be changed ou freed. @@ -988,7 +988,21 @@ */ LIB3270_EXPORT const char * lib3270_get_associated_luname(const H3270 *hSession); - LIB3270_EXPORT int lib3270_set_luname(H3270 *hSession, const char *luname); + /** + * @brief Set the LU names. + * + * @param hSession Session handle. + * @param lunames Comma separated list of the LU names to set. + * + * @return 0 if the list was set, non zero if not (sets errno) + * + * @retval EISCONN The session is online. + * @retval EINVAL Invalid session handle. + * + */ + LIB3270_EXPORT int lib3270_set_lunames(H3270 *hSession, const char *luname); + + LIB3270_EXPORT const char ** lib3270_get_lunames(H3270 *hSession); LIB3270_EXPORT int lib3270_is_connected(const H3270 *h); LIB3270_EXPORT int lib3270_is_disconnected(const H3270 *h); diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index cd20dc1..a7e1666 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -9,6 +9,7 @@ #include #include #include +#include #define MAX_ARGS 10 @@ -19,7 +20,7 @@ static void write_trace(H3270 GNUC_UNUSED(*session), void GNUC_UNUSED(*userdata) FILE *out = fopen(trace_file,"a"); if(out) { - + vfprintf(out,fmt,args); fclose(out); } @@ -149,6 +150,21 @@ int main(int argc, char *argv[]) lib3270_unregister_action_group_listener(h,LIB3270_ACTION_GROUP_ONLINE,online_listener); + lib3270_disconnect(h); + + { + lib3270_set_lunames(h,"a,b,c,d,e"); + + const char ** names = lib3270_get_lunames(h); + + size_t i; + for(i=0;names[i];i++) + { + debug("[%s]",names[i]); + } + + } + lib3270_session_free(h); return 0; -- libgit2 0.21.2