diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 3c8617c..41b7a2c 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -1217,6 +1217,8 @@ LIB3270_EXPORT int lib3270_get_color_type(H3270 *hSession); LIB3270_EXPORT int lib3270_set_host_type(H3270 *hSession, const char *name); + LIB3270_EXPORT const char * lib3270_get_host_type(H3270 *hSession); + LIB3270_EXPORT LIB3270_OPTION lib3270_parse_host_type(const char *name); LIB3270_EXPORT const LIB3270_OPTION_ENTRY * lib3270_get_option_list(void); diff --git a/src/include/lib3270/properties.h b/src/include/lib3270/properties.h index 324f2f5..a706bde 100644 --- a/src/include/lib3270/properties.h +++ b/src/include/lib3270/properties.h @@ -51,6 +51,16 @@ } LIB3270_INT_PROPERTY; + typedef struct _lib3270_string_property + { + const char * name; ///< @brief Property name. + const char * description; ///< @brief Property description. + const char * (*get)(H3270 *hSession); ///< @brief Get value. + int (*set)(H3270 *hSession, const char * value); ///< @brief Set value. + + } LIB3270_STRING_PROPERTY; + + /** * @brief Get lib3270 integer properties table. * @@ -60,7 +70,16 @@ LIB3270_EXPORT const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void); /** - * @brief Get lib3270 property by name. + * @brief Get lib3270 string properties table. + * + * @return The properties table. + * + */ + LIB3270_EXPORT const LIB3270_STRING_PROPERTY * lib3270_get_string_properties_list(void); + + + /** + * @brief Get lib3270 integer property by name. * * @param name Nome of the property. * @param seconds Time (in seconds) whe should wait for "ready" state (0 = none). @@ -68,10 +87,22 @@ * @return Property value or -1 in case of error (sets errno). * */ - LIB3270_EXPORT int lib3270_get_property(H3270 * hSession, const char *name, int seconds); + LIB3270_EXPORT int lib3270_get_int_property(H3270 * hSession, const char *name, int seconds); + + /** + * @brief Set lib3270 integer property by name. + * + * @param name Nome of the property. + * @param value New property value. + * @param seconds Time (in seconds) whe should wait for "ready" state (0 = none). + * + * @return 0 if ok, -1 in case of error (sets errno). + * + */ + LIB3270_EXPORT int lib3270_set_int_property(H3270 * hSession, const char *name, int value, int seconds); /** - * @brief Set lib3270 property by name. + * @brief Set lib3270 integer property by name. * * @param name Nome of the property. * @param value New property value. @@ -80,7 +111,7 @@ * @return 0 if ok, -1 in case of error (sets errno). * */ - LIB3270_EXPORT int lib3270_set_property(H3270 * hSession, const char *name, int value, int seconds); + LIB3270_EXPORT int lib3270_set_string_property(H3270 * hSession, const char *name, const char * value, int seconds); #ifdef __cplusplus } diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index e7b1ac5..8d91aab 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -253,7 +253,7 @@ int lib3270_set_model(H3270 *hSession, const char *model) int model_number; if(hSession->cstate != LIB3270_NOT_CONNECTED) - return EBUSY; + return errno = EBUSY; strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); hSession->model_name = &hSession->full_model_name[4]; diff --git a/src/lib3270/host.c b/src/lib3270/host.c index 29d3b06..8b94c24 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -331,6 +331,12 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) { *(val++) = 0; + if(lib3270_set_string_property(h, var, val, 0)) + { + continue; + } + + /* if(!(strcasecmp(var,"lu") && strcasecmp(var,"luname"))) { lib3270_set_luname(h, val); @@ -340,6 +346,9 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) { lib3270_write_log(h,"","Ignoring invalid URL attribute \"%s\"",var); } + */ + + lib3270_write_log(h,"","Can't set attribute \"%s\": %s",var,strerror(errno)); } diff --git a/src/lib3270/options.c b/src/lib3270/options.c index daf749c..0cb951b 100644 --- a/src/lib3270/options.c +++ b/src/lib3270/options.c @@ -176,6 +176,22 @@ LIB3270_EXPORT int lib3270_set_host_type(H3270 *hSession, const char *name) } } - return EINVAL; + return errno = EINVAL; } +LIB3270_EXPORT const char * lib3270_get_host_type(H3270 *hSession) +{ + size_t f; + + for(f=0;f<(sizeof(host_type)/sizeof(host_type[0]));f++) + { + if(hSession->options & host_type[f].option) + { + return host_type[f].name; + } + } + + errno = EINVAL; + return ""; + +} diff --git a/src/lib3270/properties.c b/src/lib3270/properties.c index 6187929..cfb837f 100644 --- a/src/lib3270/properties.c +++ b/src/lib3270/properties.c @@ -37,136 +37,242 @@ #include #include - static const LIB3270_INT_PROPERTY properties[] = { - - { - "ready", // Property name. - N_( "" ), // Property description. - lib3270_is_ready, // Get value. - NULL // Set value. - }, - - { - "connected", // Property name. - N_( "" ), // Property description. - lib3270_is_connected, // Get value. - lib3270_set_connected // Set value. - }, - - { - "secure", // Property name. - N_( "" ), // Property description. - lib3270_is_secure, // Get value. - NULL // Set value. - }, - - { - "tso", // Property name. - N_( "Non zero if the host is TSO." ), // Property description. - lib3270_is_tso, // Get value. - NULL // Set value. - }, - - { - "pconnected", // Property name. - N_( "" ), // Property description. - lib3270_pconnected, // Get value. - NULL // Set value. - }, - - { - "half_connected", // Property name. - N_( "" ), // Property description. - lib3270_half_connected, // Get value. - NULL // Set value. - }, - - { - "neither", // Property name. - N_( "" ), // Property description. - lib3270_in_neither, // Get value. - NULL // Set value. - }, - - { - "ansi", // Property name. - N_( "" ), // Property description. - lib3270_in_ansi, // Get value. - NULL // Set value. - }, - - { - "3270", // Property name. - N_( "" ), // Property description. - lib3270_in_3270, // Get value. - NULL // Set value. - }, - - { - "sscp", // Property name. - N_( "" ), // Property description. - lib3270_in_sscp, // Get value. - NULL // Set value. - }, - - { - "tn3270e", // Property name. - N_( "" ), // Property description. - lib3270_in_tn3270e, // Get value. - NULL // Set value. - }, - - { - "e", // Property name. - N_( "" ), // Property description. - lib3270_in_e, // Get value. - NULL // Set value. - }, - - { - "cursor_address", // Property name. - N_( "Cursor address" ), // Property description. - lib3270_get_cursor_address, // Get value. - lib3270_set_cursor_address // Set value. - }, - - { - "has_selection", // Property name. - N_( "Has selected aread" ), // Property description. - lib3270_has_selection, // Get value. - NULL // Set value. - }, - - { - "model_number", // Property name. - N_( "The model number" ), // Property description. - lib3270_get_model_number, // Get value. - NULL // Set value. - }, - - { - "color_type", // Property name. - N_( "The color type" ), // Property description. - lib3270_get_color_type, // Get value. - lib3270_set_color_type // Set value. - }, - - /* - { - "", // Property name. - N_( "" ), // Property description. - NULL, // Get value. - NULL // Set value. - }, - */ - { - NULL, - NULL, - NULL, - NULL - } - }; + static int lib3270_get_connection_state_as_int(H3270 *hSession) + { + return (int) lib3270_get_connection_state(hSession); + } + + static int lib3270_get_program_message_as_int(H3270 *hSession) + { + return (int) lib3270_get_program_message(hSession); + } + + const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void) { + + static const LIB3270_INT_PROPERTY properties[] = { + + { + "ready", // Property name. + N_( "" ), // Property description. + lib3270_is_ready, // Get value. + NULL // Set value. + }, + + { + "connected", // Property name. + N_( "" ), // Property description. + lib3270_is_connected, // Get value. + lib3270_set_connected // Set value. + }, + + { + "secure", // Property name. + N_( "" ), // Property description. + lib3270_is_secure, // Get value. + NULL // Set value. + }, + + { + "tso", // Property name. + N_( "Non zero if the host is TSO." ), // Property description. + lib3270_is_tso, // Get value. + NULL // Set value. + }, + + { + "pconnected", // Property name. + N_( "" ), // Property description. + lib3270_pconnected, // Get value. + NULL // Set value. + }, + + { + "half_connected", // Property name. + N_( "" ), // Property description. + lib3270_half_connected, // Get value. + NULL // Set value. + }, + + { + "neither", // Property name. + N_( "" ), // Property description. + lib3270_in_neither, // Get value. + NULL // Set value. + }, + + { + "ansi", // Property name. + N_( "" ), // Property description. + lib3270_in_ansi, // Get value. + NULL // Set value. + }, + + { + "3270", // Property name. + N_( "" ), // Property description. + lib3270_in_3270, // Get value. + NULL // Set value. + }, + + { + "sscp", // Property name. + N_( "" ), // Property description. + lib3270_in_sscp, // Get value. + NULL // Set value. + }, + + { + "tn3270e", // Property name. + N_( "" ), // Property description. + lib3270_in_tn3270e, // Get value. + NULL // Set value. + }, + + { + "e", // Property name. + N_( "" ), // Property description. + lib3270_in_e, // Get value. + NULL // Set value. + }, + + { + "cursor_address", // Property name. + N_( "Cursor address" ), // Property description. + lib3270_get_cursor_address, // Get value. + lib3270_set_cursor_address // Set value. + }, + + { + "has_selection", // Property name. + N_( "Has selected aread" ), // Property description. + lib3270_has_selection, // Get value. + NULL // Set value. + }, + + { + "model_number", // Property name. + N_( "The model number" ), // Property description. + lib3270_get_model_number, // Get value. + NULL // Set value. + }, + + { + "color_type", // Property name. + N_( "The color type" ), // Property description. + lib3270_get_color_type, // Get value. + lib3270_set_color_type // Set value. + }, + + { + "width",// Property name. + N_( "Current screen width in columns" ), // Property description. + lib3270_get_width, // Get value. + NULL // Set value. + }, + + { + "height", // Property name. + N_( "Current screen width in rows" ), // Property description. + lib3270_get_height, // Get value. + NULL // Set value. + }, + + { + "length", // Property name. + N_( "Screen buffer length in bytes" ), // Property description. + lib3270_get_length, // Get value. + NULL // Set value. + }, + + { + "cstate", // Property name. + N_( "Connection state" ), // Property description. + lib3270_get_connection_state_as_int, // Get value. + NULL // Set value. + }, + + { + "program_message", // Property name. + N_( "Latest program message" ), // Property description. + lib3270_get_program_message_as_int, // Get value. + NULL // Set value. + }, + + + /* + { + "", // Property name. + N_( "" ), // Property description. + NULL, // Get value. + NULL // Set value. + }, + */ + + { + NULL, + NULL, + NULL, + NULL + } + }; + + return properties; + } + + LIB3270_EXPORT const LIB3270_STRING_PROPERTY * lib3270_get_string_properties_list(void) + { + static const LIB3270_STRING_PROPERTY properties[] = { + + { + "luname", // Property name. + N_( "" ), // Property description. + lib3270_get_luname, // Get value. + lib3270_set_luname // Set value. + }, + + { + "url", // Property name. + N_( "" ), // Property description. + lib3270_get_url, // Get value. + lib3270_set_url // Set value. + }, + + { + "model", // Property name. + N_( "" ), // Property description. + lib3270_get_model, // Get value. + lib3270_set_model // Set value. + }, + + { + "host_type", // Property name. + N_( "" ), // Property description. + lib3270_get_host_type, // Get value. + lib3270_set_host_type // Set value. + }, + + /* + { + "", // Property name. + N_( "" ), // Property description. + , // Get value. + NULL // Set value. + }, + */ + + { + NULL, + NULL, + NULL, + NULL + } + + }; + + return properties; + + } int lib3270_set_connected(H3270 *hSession, int state) { @@ -183,11 +289,7 @@ return 0; } - const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void) { - return properties; - } - -int lib3270_get_property(H3270 *hSession, const char *name, int seconds) +int lib3270_get_int_property(H3270 *hSession, const char *name, int seconds) { size_t ix; @@ -196,6 +298,7 @@ int lib3270_get_property(H3270 *hSession, const char *name, int seconds) lib3270_wait_for_ready(hSession, seconds); } + const LIB3270_INT_PROPERTY * properties = lib3270_get_int_properties_list(); for(ix = 0; ix < (sizeof(properties)/sizeof(properties[0])); ix++) { if(!strcasecmp(name,properties[ix].name)) @@ -218,7 +321,7 @@ int lib3270_get_property(H3270 *hSession, const char *name, int seconds) return -1; } -int lib3270_set_property(H3270 *hSession, const char *name, int value, int seconds) +int lib3270_set_int_property(H3270 *hSession, const char *name, int value, int seconds) { size_t ix; @@ -227,7 +330,8 @@ int lib3270_set_property(H3270 *hSession, const char *name, int value, int secon lib3270_wait_for_ready(hSession, seconds); } - for(ix = 0; ix < (sizeof(properties)/sizeof(properties[0])); ix++) + const LIB3270_INT_PROPERTY * properties = lib3270_get_int_properties_list(); + for(ix = 0; properties[ix].name; ix++) { if(!strcasecmp(name,properties[ix].name)) { @@ -249,3 +353,34 @@ int lib3270_set_property(H3270 *hSession, const char *name, int value, int secon } +int lib3270_set_string_property(H3270 *hSession, const char *name, const char * value, int seconds) +{ + size_t ix; + + if(seconds) + { + lib3270_wait_for_ready(hSession, seconds); + } + + const LIB3270_STRING_PROPERTY * properties = lib3270_get_string_properties_list(); + for(ix = 0; properties[ix].name; ix++) + { + if(!strcasecmp(name,properties[ix].name)) + { + if(properties[ix].set) + { + return properties[ix].set(hSession, value); + } + else + { + errno = EPERM; + return -1; + } + } + + } + + errno = ENOENT; + return -1; + +} -- libgit2 0.21.2