Commit 713a618b4c0508d3f4e4cf1f4f57c87fcfdcef81
1 parent
2be8012a
Exists in
master
and in
3 other branches
+ Adding string properties.
Showing
6 changed files
with
335 additions
and
142 deletions
Show diff stats
src/include/lib3270.h
... | ... | @@ -1217,6 +1217,8 @@ |
1217 | 1217 | LIB3270_EXPORT int lib3270_get_color_type(H3270 *hSession); |
1218 | 1218 | |
1219 | 1219 | LIB3270_EXPORT int lib3270_set_host_type(H3270 *hSession, const char *name); |
1220 | + LIB3270_EXPORT const char * lib3270_get_host_type(H3270 *hSession); | |
1221 | + | |
1220 | 1222 | LIB3270_EXPORT LIB3270_OPTION lib3270_parse_host_type(const char *name); |
1221 | 1223 | |
1222 | 1224 | LIB3270_EXPORT const LIB3270_OPTION_ENTRY * lib3270_get_option_list(void); | ... | ... |
src/include/lib3270/properties.h
... | ... | @@ -51,6 +51,16 @@ |
51 | 51 | |
52 | 52 | } LIB3270_INT_PROPERTY; |
53 | 53 | |
54 | + typedef struct _lib3270_string_property | |
55 | + { | |
56 | + const char * name; ///< @brief Property name. | |
57 | + const char * description; ///< @brief Property description. | |
58 | + const char * (*get)(H3270 *hSession); ///< @brief Get value. | |
59 | + int (*set)(H3270 *hSession, const char * value); ///< @brief Set value. | |
60 | + | |
61 | + } LIB3270_STRING_PROPERTY; | |
62 | + | |
63 | + | |
54 | 64 | /** |
55 | 65 | * @brief Get lib3270 integer properties table. |
56 | 66 | * |
... | ... | @@ -60,7 +70,16 @@ |
60 | 70 | LIB3270_EXPORT const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void); |
61 | 71 | |
62 | 72 | /** |
63 | - * @brief Get lib3270 property by name. | |
73 | + * @brief Get lib3270 string properties table. | |
74 | + * | |
75 | + * @return The properties table. | |
76 | + * | |
77 | + */ | |
78 | + LIB3270_EXPORT const LIB3270_STRING_PROPERTY * lib3270_get_string_properties_list(void); | |
79 | + | |
80 | + | |
81 | + /** | |
82 | + * @brief Get lib3270 integer property by name. | |
64 | 83 | * |
65 | 84 | * @param name Nome of the property. |
66 | 85 | * @param seconds Time (in seconds) whe should wait for "ready" state (0 = none). |
... | ... | @@ -68,10 +87,22 @@ |
68 | 87 | * @return Property value or -1 in case of error (sets errno). |
69 | 88 | * |
70 | 89 | */ |
71 | - LIB3270_EXPORT int lib3270_get_property(H3270 * hSession, const char *name, int seconds); | |
90 | + LIB3270_EXPORT int lib3270_get_int_property(H3270 * hSession, const char *name, int seconds); | |
91 | + | |
92 | + /** | |
93 | + * @brief Set lib3270 integer property by name. | |
94 | + * | |
95 | + * @param name Nome of the property. | |
96 | + * @param value New property value. | |
97 | + * @param seconds Time (in seconds) whe should wait for "ready" state (0 = none). | |
98 | + * | |
99 | + * @return 0 if ok, -1 in case of error (sets errno). | |
100 | + * | |
101 | + */ | |
102 | + LIB3270_EXPORT int lib3270_set_int_property(H3270 * hSession, const char *name, int value, int seconds); | |
72 | 103 | |
73 | 104 | /** |
74 | - * @brief Set lib3270 property by name. | |
105 | + * @brief Set lib3270 integer property by name. | |
75 | 106 | * |
76 | 107 | * @param name Nome of the property. |
77 | 108 | * @param value New property value. |
... | ... | @@ -80,7 +111,7 @@ |
80 | 111 | * @return 0 if ok, -1 in case of error (sets errno). |
81 | 112 | * |
82 | 113 | */ |
83 | - LIB3270_EXPORT int lib3270_set_property(H3270 * hSession, const char *name, int value, int seconds); | |
114 | + LIB3270_EXPORT int lib3270_set_string_property(H3270 * hSession, const char *name, const char * value, int seconds); | |
84 | 115 | |
85 | 116 | #ifdef __cplusplus |
86 | 117 | } | ... | ... |
src/lib3270/ctlr.c
... | ... | @@ -253,7 +253,7 @@ int lib3270_set_model(H3270 *hSession, const char *model) |
253 | 253 | int model_number; |
254 | 254 | |
255 | 255 | if(hSession->cstate != LIB3270_NOT_CONNECTED) |
256 | - return EBUSY; | |
256 | + return errno = EBUSY; | |
257 | 257 | |
258 | 258 | strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); |
259 | 259 | hSession->model_name = &hSession->full_model_name[4]; | ... | ... |
src/lib3270/host.c
... | ... | @@ -331,6 +331,12 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) |
331 | 331 | { |
332 | 332 | *(val++) = 0; |
333 | 333 | |
334 | + if(lib3270_set_string_property(h, var, val, 0)) | |
335 | + { | |
336 | + continue; | |
337 | + } | |
338 | + | |
339 | + /* | |
334 | 340 | if(!(strcasecmp(var,"lu") && strcasecmp(var,"luname"))) |
335 | 341 | { |
336 | 342 | lib3270_set_luname(h, val); |
... | ... | @@ -340,6 +346,9 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) |
340 | 346 | { |
341 | 347 | lib3270_write_log(h,"","Ignoring invalid URL attribute \"%s\"",var); |
342 | 348 | } |
349 | + */ | |
350 | + | |
351 | + lib3270_write_log(h,"","Can't set attribute \"%s\": %s",var,strerror(errno)); | |
343 | 352 | |
344 | 353 | } |
345 | 354 | ... | ... |
src/lib3270/options.c
... | ... | @@ -176,6 +176,22 @@ LIB3270_EXPORT int lib3270_set_host_type(H3270 *hSession, const char *name) |
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | - return EINVAL; | |
179 | + return errno = EINVAL; | |
180 | 180 | } |
181 | 181 | |
182 | +LIB3270_EXPORT const char * lib3270_get_host_type(H3270 *hSession) | |
183 | +{ | |
184 | + size_t f; | |
185 | + | |
186 | + for(f=0;f<(sizeof(host_type)/sizeof(host_type[0]));f++) | |
187 | + { | |
188 | + if(hSession->options & host_type[f].option) | |
189 | + { | |
190 | + return host_type[f].name; | |
191 | + } | |
192 | + } | |
193 | + | |
194 | + errno = EINVAL; | |
195 | + return ""; | |
196 | + | |
197 | +} | ... | ... |
src/lib3270/properties.c
... | ... | @@ -37,136 +37,242 @@ |
37 | 37 | #include <lib3270.h> |
38 | 38 | #include <lib3270/properties.h> |
39 | 39 | |
40 | - static const LIB3270_INT_PROPERTY properties[] = { | |
41 | - | |
42 | - { | |
43 | - "ready", // Property name. | |
44 | - N_( "" ), // Property description. | |
45 | - lib3270_is_ready, // Get value. | |
46 | - NULL // Set value. | |
47 | - }, | |
48 | - | |
49 | - { | |
50 | - "connected", // Property name. | |
51 | - N_( "" ), // Property description. | |
52 | - lib3270_is_connected, // Get value. | |
53 | - lib3270_set_connected // Set value. | |
54 | - }, | |
55 | - | |
56 | - { | |
57 | - "secure", // Property name. | |
58 | - N_( "" ), // Property description. | |
59 | - lib3270_is_secure, // Get value. | |
60 | - NULL // Set value. | |
61 | - }, | |
62 | - | |
63 | - { | |
64 | - "tso", // Property name. | |
65 | - N_( "Non zero if the host is TSO." ), // Property description. | |
66 | - lib3270_is_tso, // Get value. | |
67 | - NULL // Set value. | |
68 | - }, | |
69 | - | |
70 | - { | |
71 | - "pconnected", // Property name. | |
72 | - N_( "" ), // Property description. | |
73 | - lib3270_pconnected, // Get value. | |
74 | - NULL // Set value. | |
75 | - }, | |
76 | - | |
77 | - { | |
78 | - "half_connected", // Property name. | |
79 | - N_( "" ), // Property description. | |
80 | - lib3270_half_connected, // Get value. | |
81 | - NULL // Set value. | |
82 | - }, | |
83 | - | |
84 | - { | |
85 | - "neither", // Property name. | |
86 | - N_( "" ), // Property description. | |
87 | - lib3270_in_neither, // Get value. | |
88 | - NULL // Set value. | |
89 | - }, | |
90 | - | |
91 | - { | |
92 | - "ansi", // Property name. | |
93 | - N_( "" ), // Property description. | |
94 | - lib3270_in_ansi, // Get value. | |
95 | - NULL // Set value. | |
96 | - }, | |
97 | - | |
98 | - { | |
99 | - "3270", // Property name. | |
100 | - N_( "" ), // Property description. | |
101 | - lib3270_in_3270, // Get value. | |
102 | - NULL // Set value. | |
103 | - }, | |
104 | - | |
105 | - { | |
106 | - "sscp", // Property name. | |
107 | - N_( "" ), // Property description. | |
108 | - lib3270_in_sscp, // Get value. | |
109 | - NULL // Set value. | |
110 | - }, | |
111 | - | |
112 | - { | |
113 | - "tn3270e", // Property name. | |
114 | - N_( "" ), // Property description. | |
115 | - lib3270_in_tn3270e, // Get value. | |
116 | - NULL // Set value. | |
117 | - }, | |
118 | - | |
119 | - { | |
120 | - "e", // Property name. | |
121 | - N_( "" ), // Property description. | |
122 | - lib3270_in_e, // Get value. | |
123 | - NULL // Set value. | |
124 | - }, | |
125 | - | |
126 | - { | |
127 | - "cursor_address", // Property name. | |
128 | - N_( "Cursor address" ), // Property description. | |
129 | - lib3270_get_cursor_address, // Get value. | |
130 | - lib3270_set_cursor_address // Set value. | |
131 | - }, | |
132 | - | |
133 | - { | |
134 | - "has_selection", // Property name. | |
135 | - N_( "Has selected aread" ), // Property description. | |
136 | - lib3270_has_selection, // Get value. | |
137 | - NULL // Set value. | |
138 | - }, | |
139 | - | |
140 | - { | |
141 | - "model_number", // Property name. | |
142 | - N_( "The model number" ), // Property description. | |
143 | - lib3270_get_model_number, // Get value. | |
144 | - NULL // Set value. | |
145 | - }, | |
146 | - | |
147 | - { | |
148 | - "color_type", // Property name. | |
149 | - N_( "The color type" ), // Property description. | |
150 | - lib3270_get_color_type, // Get value. | |
151 | - lib3270_set_color_type // Set value. | |
152 | - }, | |
153 | - | |
154 | - /* | |
155 | - { | |
156 | - "", // Property name. | |
157 | - N_( "" ), // Property description. | |
158 | - NULL, // Get value. | |
159 | - NULL // Set value. | |
160 | - }, | |
161 | - */ | |
162 | 40 | |
163 | - { | |
164 | - NULL, | |
165 | - NULL, | |
166 | - NULL, | |
167 | - NULL | |
168 | - } | |
169 | - }; | |
41 | + static int lib3270_get_connection_state_as_int(H3270 *hSession) | |
42 | + { | |
43 | + return (int) lib3270_get_connection_state(hSession); | |
44 | + } | |
45 | + | |
46 | + static int lib3270_get_program_message_as_int(H3270 *hSession) | |
47 | + { | |
48 | + return (int) lib3270_get_program_message(hSession); | |
49 | + } | |
50 | + | |
51 | + const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void) { | |
52 | + | |
53 | + static const LIB3270_INT_PROPERTY properties[] = { | |
54 | + | |
55 | + { | |
56 | + "ready", // Property name. | |
57 | + N_( "" ), // Property description. | |
58 | + lib3270_is_ready, // Get value. | |
59 | + NULL // Set value. | |
60 | + }, | |
61 | + | |
62 | + { | |
63 | + "connected", // Property name. | |
64 | + N_( "" ), // Property description. | |
65 | + lib3270_is_connected, // Get value. | |
66 | + lib3270_set_connected // Set value. | |
67 | + }, | |
68 | + | |
69 | + { | |
70 | + "secure", // Property name. | |
71 | + N_( "" ), // Property description. | |
72 | + lib3270_is_secure, // Get value. | |
73 | + NULL // Set value. | |
74 | + }, | |
75 | + | |
76 | + { | |
77 | + "tso", // Property name. | |
78 | + N_( "Non zero if the host is TSO." ), // Property description. | |
79 | + lib3270_is_tso, // Get value. | |
80 | + NULL // Set value. | |
81 | + }, | |
82 | + | |
83 | + { | |
84 | + "pconnected", // Property name. | |
85 | + N_( "" ), // Property description. | |
86 | + lib3270_pconnected, // Get value. | |
87 | + NULL // Set value. | |
88 | + }, | |
89 | + | |
90 | + { | |
91 | + "half_connected", // Property name. | |
92 | + N_( "" ), // Property description. | |
93 | + lib3270_half_connected, // Get value. | |
94 | + NULL // Set value. | |
95 | + }, | |
96 | + | |
97 | + { | |
98 | + "neither", // Property name. | |
99 | + N_( "" ), // Property description. | |
100 | + lib3270_in_neither, // Get value. | |
101 | + NULL // Set value. | |
102 | + }, | |
103 | + | |
104 | + { | |
105 | + "ansi", // Property name. | |
106 | + N_( "" ), // Property description. | |
107 | + lib3270_in_ansi, // Get value. | |
108 | + NULL // Set value. | |
109 | + }, | |
110 | + | |
111 | + { | |
112 | + "3270", // Property name. | |
113 | + N_( "" ), // Property description. | |
114 | + lib3270_in_3270, // Get value. | |
115 | + NULL // Set value. | |
116 | + }, | |
117 | + | |
118 | + { | |
119 | + "sscp", // Property name. | |
120 | + N_( "" ), // Property description. | |
121 | + lib3270_in_sscp, // Get value. | |
122 | + NULL // Set value. | |
123 | + }, | |
124 | + | |
125 | + { | |
126 | + "tn3270e", // Property name. | |
127 | + N_( "" ), // Property description. | |
128 | + lib3270_in_tn3270e, // Get value. | |
129 | + NULL // Set value. | |
130 | + }, | |
131 | + | |
132 | + { | |
133 | + "e", // Property name. | |
134 | + N_( "" ), // Property description. | |
135 | + lib3270_in_e, // Get value. | |
136 | + NULL // Set value. | |
137 | + }, | |
138 | + | |
139 | + { | |
140 | + "cursor_address", // Property name. | |
141 | + N_( "Cursor address" ), // Property description. | |
142 | + lib3270_get_cursor_address, // Get value. | |
143 | + lib3270_set_cursor_address // Set value. | |
144 | + }, | |
145 | + | |
146 | + { | |
147 | + "has_selection", // Property name. | |
148 | + N_( "Has selected aread" ), // Property description. | |
149 | + lib3270_has_selection, // Get value. | |
150 | + NULL // Set value. | |
151 | + }, | |
152 | + | |
153 | + { | |
154 | + "model_number", // Property name. | |
155 | + N_( "The model number" ), // Property description. | |
156 | + lib3270_get_model_number, // Get value. | |
157 | + NULL // Set value. | |
158 | + }, | |
159 | + | |
160 | + { | |
161 | + "color_type", // Property name. | |
162 | + N_( "The color type" ), // Property description. | |
163 | + lib3270_get_color_type, // Get value. | |
164 | + lib3270_set_color_type // Set value. | |
165 | + }, | |
166 | + | |
167 | + { | |
168 | + "width",// Property name. | |
169 | + N_( "Current screen width in columns" ), // Property description. | |
170 | + lib3270_get_width, // Get value. | |
171 | + NULL // Set value. | |
172 | + }, | |
173 | + | |
174 | + { | |
175 | + "height", // Property name. | |
176 | + N_( "Current screen width in rows" ), // Property description. | |
177 | + lib3270_get_height, // Get value. | |
178 | + NULL // Set value. | |
179 | + }, | |
180 | + | |
181 | + { | |
182 | + "length", // Property name. | |
183 | + N_( "Screen buffer length in bytes" ), // Property description. | |
184 | + lib3270_get_length, // Get value. | |
185 | + NULL // Set value. | |
186 | + }, | |
187 | + | |
188 | + { | |
189 | + "cstate", // Property name. | |
190 | + N_( "Connection state" ), // Property description. | |
191 | + lib3270_get_connection_state_as_int, // Get value. | |
192 | + NULL // Set value. | |
193 | + }, | |
194 | + | |
195 | + { | |
196 | + "program_message", // Property name. | |
197 | + N_( "Latest program message" ), // Property description. | |
198 | + lib3270_get_program_message_as_int, // Get value. | |
199 | + NULL // Set value. | |
200 | + }, | |
201 | + | |
202 | + | |
203 | + /* | |
204 | + { | |
205 | + "", // Property name. | |
206 | + N_( "" ), // Property description. | |
207 | + NULL, // Get value. | |
208 | + NULL // Set value. | |
209 | + }, | |
210 | + */ | |
211 | + | |
212 | + { | |
213 | + NULL, | |
214 | + NULL, | |
215 | + NULL, | |
216 | + NULL | |
217 | + } | |
218 | + }; | |
219 | + | |
220 | + return properties; | |
221 | + } | |
222 | + | |
223 | + LIB3270_EXPORT const LIB3270_STRING_PROPERTY * lib3270_get_string_properties_list(void) | |
224 | + { | |
225 | + static const LIB3270_STRING_PROPERTY properties[] = { | |
226 | + | |
227 | + { | |
228 | + "luname", // Property name. | |
229 | + N_( "" ), // Property description. | |
230 | + lib3270_get_luname, // Get value. | |
231 | + lib3270_set_luname // Set value. | |
232 | + }, | |
233 | + | |
234 | + { | |
235 | + "url", // Property name. | |
236 | + N_( "" ), // Property description. | |
237 | + lib3270_get_url, // Get value. | |
238 | + lib3270_set_url // Set value. | |
239 | + }, | |
240 | + | |
241 | + { | |
242 | + "model", // Property name. | |
243 | + N_( "" ), // Property description. | |
244 | + lib3270_get_model, // Get value. | |
245 | + lib3270_set_model // Set value. | |
246 | + }, | |
247 | + | |
248 | + { | |
249 | + "host_type", // Property name. | |
250 | + N_( "" ), // Property description. | |
251 | + lib3270_get_host_type, // Get value. | |
252 | + lib3270_set_host_type // Set value. | |
253 | + }, | |
254 | + | |
255 | + /* | |
256 | + { | |
257 | + "", // Property name. | |
258 | + N_( "" ), // Property description. | |
259 | + , // Get value. | |
260 | + NULL // Set value. | |
261 | + }, | |
262 | + */ | |
263 | + | |
264 | + { | |
265 | + NULL, | |
266 | + NULL, | |
267 | + NULL, | |
268 | + NULL | |
269 | + } | |
270 | + | |
271 | + }; | |
272 | + | |
273 | + return properties; | |
274 | + | |
275 | + } | |
170 | 276 | |
171 | 277 | int lib3270_set_connected(H3270 *hSession, int state) { |
172 | 278 | |
... | ... | @@ -183,11 +289,7 @@ |
183 | 289 | return 0; |
184 | 290 | } |
185 | 291 | |
186 | - const LIB3270_INT_PROPERTY * lib3270_get_int_properties_list(void) { | |
187 | - return properties; | |
188 | - } | |
189 | - | |
190 | -int lib3270_get_property(H3270 *hSession, const char *name, int seconds) | |
292 | +int lib3270_get_int_property(H3270 *hSession, const char *name, int seconds) | |
191 | 293 | { |
192 | 294 | size_t ix; |
193 | 295 | |
... | ... | @@ -196,6 +298,7 @@ int lib3270_get_property(H3270 *hSession, const char *name, int seconds) |
196 | 298 | lib3270_wait_for_ready(hSession, seconds); |
197 | 299 | } |
198 | 300 | |
301 | + const LIB3270_INT_PROPERTY * properties = lib3270_get_int_properties_list(); | |
199 | 302 | for(ix = 0; ix < (sizeof(properties)/sizeof(properties[0])); ix++) |
200 | 303 | { |
201 | 304 | if(!strcasecmp(name,properties[ix].name)) |
... | ... | @@ -218,7 +321,7 @@ int lib3270_get_property(H3270 *hSession, const char *name, int seconds) |
218 | 321 | return -1; |
219 | 322 | } |
220 | 323 | |
221 | -int lib3270_set_property(H3270 *hSession, const char *name, int value, int seconds) | |
324 | +int lib3270_set_int_property(H3270 *hSession, const char *name, int value, int seconds) | |
222 | 325 | { |
223 | 326 | size_t ix; |
224 | 327 | |
... | ... | @@ -227,7 +330,8 @@ int lib3270_set_property(H3270 *hSession, const char *name, int value, int secon |
227 | 330 | lib3270_wait_for_ready(hSession, seconds); |
228 | 331 | } |
229 | 332 | |
230 | - for(ix = 0; ix < (sizeof(properties)/sizeof(properties[0])); ix++) | |
333 | + const LIB3270_INT_PROPERTY * properties = lib3270_get_int_properties_list(); | |
334 | + for(ix = 0; properties[ix].name; ix++) | |
231 | 335 | { |
232 | 336 | if(!strcasecmp(name,properties[ix].name)) |
233 | 337 | { |
... | ... | @@ -249,3 +353,34 @@ int lib3270_set_property(H3270 *hSession, const char *name, int value, int secon |
249 | 353 | |
250 | 354 | } |
251 | 355 | |
356 | +int lib3270_set_string_property(H3270 *hSession, const char *name, const char * value, int seconds) | |
357 | +{ | |
358 | + size_t ix; | |
359 | + | |
360 | + if(seconds) | |
361 | + { | |
362 | + lib3270_wait_for_ready(hSession, seconds); | |
363 | + } | |
364 | + | |
365 | + const LIB3270_STRING_PROPERTY * properties = lib3270_get_string_properties_list(); | |
366 | + for(ix = 0; properties[ix].name; ix++) | |
367 | + { | |
368 | + if(!strcasecmp(name,properties[ix].name)) | |
369 | + { | |
370 | + if(properties[ix].set) | |
371 | + { | |
372 | + return properties[ix].set(hSession, value); | |
373 | + } | |
374 | + else | |
375 | + { | |
376 | + errno = EPERM; | |
377 | + return -1; | |
378 | + } | |
379 | + } | |
380 | + | |
381 | + } | |
382 | + | |
383 | + errno = ENOENT; | |
384 | + return -1; | |
385 | + | |
386 | +} | ... | ... |