Commit b88b5d23a6c7acd755a0901adbabb82645b0e1be
1 parent
d2eea719
Exists in
master
and in
3 other branches
Adjustments on session structure.
Showing
6 changed files
with
100 additions
and
38 deletions
Show diff stats
src/include/lib3270.h
... | ... | @@ -454,13 +454,26 @@ |
454 | 454 | /** |
455 | 455 | * @brief Register a function interested in a state change. |
456 | 456 | * |
457 | - * @param h Session handle. | |
458 | - * @param tx State ID | |
459 | - * @param func Callback | |
460 | - * @param data Data | |
457 | + * @param hSession Session handle. | |
458 | + * @param tx State ID | |
459 | + * @param func Callback | |
460 | + * @param data Data | |
461 | + * | |
462 | + * @return State change identifier. | |
463 | + * | |
464 | + */ | |
465 | + LIB3270_EXPORT const void * lib3270_register_schange(H3270 *hSession, LIB3270_STATE tx, void (*func)(H3270 *, int, void *),void *data); | |
466 | + | |
467 | + /** | |
468 | + * @brief Unregister a function interested in a state change. | |
469 | + * | |
470 | + * @param hSession Session handle. | |
471 | + * @param id State change identifier. | |
472 | + * | |
473 | + * @return 0 if suceeds, non zero if fails (sets errno). | |
461 | 474 | * |
462 | 475 | */ |
463 | - LIB3270_EXPORT void lib3270_register_schange(H3270 *h,LIB3270_STATE tx, void (*func)(H3270 *, int, void *),void *data); | |
476 | + LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx, void * id); | |
464 | 477 | |
465 | 478 | LIB3270_EXPORT void lib3270_reset_callbacks(H3270 *hSession); |
466 | 479 | ... | ... |
src/lib3270/host.c
... | ... | @@ -167,26 +167,66 @@ void lib3270_set_disconnected(H3270 *hSession) |
167 | 167 | |
168 | 168 | /** |
169 | 169 | * @brief Register a function interested in a state change. |
170 | + * | |
171 | + * @param hSession Session handle. | |
172 | + * @param tx State ID | |
173 | + * @param func Callback | |
174 | + * @param data Data | |
175 | + * | |
176 | + * @return State change identifier. | |
177 | + * | |
170 | 178 | */ |
171 | -LIB3270_EXPORT void lib3270_register_schange(H3270 *h, LIB3270_STATE tx, void (*func)(H3270 *, int, void *),void *data) | |
179 | +LIB3270_EXPORT const void * lib3270_register_schange(H3270 *hSession, LIB3270_STATE tx, void (*func)(H3270 *, int, void *),void *data) | |
172 | 180 | { |
173 | 181 | struct lib3270_state_callback *st; |
174 | 182 | |
175 | - CHECK_SESSION_HANDLE(h); | |
183 | + CHECK_SESSION_HANDLE(hSession); | |
176 | 184 | |
177 | 185 | st = (struct lib3270_state_callback *) lib3270_malloc(sizeof(struct lib3270_state_callback)); |
178 | 186 | st->func = func; |
179 | 187 | st->data = data; |
180 | 188 | |
181 | - if (h->st_last[tx]) | |
182 | - h->st_last[tx]->next = st; | |
189 | + if (hSession->st.last[tx]) | |
190 | + hSession->st.last[tx]->next = st; | |
183 | 191 | else |
184 | - h->st_callbacks[tx] = st; | |
192 | + hSession->st.callbacks[tx] = st; | |
193 | + | |
194 | + hSession->st.last[tx] = st; | |
185 | 195 | |
186 | - h->st_last[tx] = st; | |
196 | + return (void *) st; | |
187 | 197 | |
188 | 198 | } |
189 | 199 | |
200 | +LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx, void * id) | |
201 | +{ | |
202 | + struct lib3270_state_callback *st; | |
203 | + struct lib3270_state_callback *prev = (struct lib3270_state_callback *) NULL; | |
204 | + | |
205 | + for (st = hSession->st.callbacks[tx]; st != (struct lib3270_state_callback *) NULL; st = (struct lib3270_state_callback *) st->next) | |
206 | + { | |
207 | + if (st == (struct lib3270_state_callback *)id) | |
208 | + break; | |
209 | + | |
210 | + prev = st; | |
211 | + } | |
212 | + | |
213 | + if (st == (struct lib3270_state_callback *)NULL) | |
214 | + { | |
215 | + lib3270_write_log(hSession,"lib3270","Invalid call to (%s): %p wasnt found in the list",__FUNCTION__,id); | |
216 | + return errno = ENOENT; | |
217 | + } | |
218 | + | |
219 | + if (prev != (struct lib3270_state_callback *) NULL) | |
220 | + prev->next = st->next; | |
221 | + else | |
222 | + hSession->st.callbacks[tx] = (struct lib3270_state_callback *) st->next; | |
223 | + | |
224 | + lib3270_free(id); | |
225 | + | |
226 | + return 0; | |
227 | +} | |
228 | + | |
229 | + | |
190 | 230 | /** |
191 | 231 | * @brief Signal a state change. |
192 | 232 | */ |
... | ... | @@ -214,7 +254,7 @@ void lib3270_st_changed(H3270 *h, LIB3270_STATE tx, int mode) |
214 | 254 | |
215 | 255 | trace("%s is %d on session %p",state_name[tx],mode,h); |
216 | 256 | |
217 | - for (st = h->st_callbacks[tx];st;st = st->next) | |
257 | + for(st = h->st.callbacks[tx];st;st = st->next) | |
218 | 258 | { |
219 | 259 | st->func(h,mode,st->data); |
220 | 260 | } |
... | ... | @@ -449,23 +489,23 @@ LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h) |
449 | 489 | LIB3270_EXPORT int lib3270_has_active_script(H3270 *h) |
450 | 490 | { |
451 | 491 | CHECK_SESSION_HANDLE(h); |
452 | - return (h->oia_flag[LIB3270_FLAG_SCRIPT] != 0); | |
492 | + return (h->oia.flag[LIB3270_FLAG_SCRIPT] != 0); | |
453 | 493 | } |
454 | 494 | |
455 | 495 | LIB3270_EXPORT int lib3270_get_typeahead(H3270 *h) |
456 | 496 | { |
457 | 497 | CHECK_SESSION_HANDLE(h); |
458 | - return (h->oia_flag[LIB3270_FLAG_TYPEAHEAD] != 0); | |
498 | + return (h->oia.flag[LIB3270_FLAG_TYPEAHEAD] != 0); | |
459 | 499 | } |
460 | 500 | |
461 | 501 | LIB3270_EXPORT int lib3270_get_undera(H3270 *h) |
462 | 502 | { |
463 | 503 | CHECK_SESSION_HANDLE(h); |
464 | - return (h->oia_flag[LIB3270_FLAG_UNDERA] != 0); | |
504 | + return (h->oia.flag[LIB3270_FLAG_UNDERA] != 0); | |
465 | 505 | } |
466 | 506 | |
467 | 507 | LIB3270_EXPORT int lib3270_get_oia_box_solid(H3270 *h) |
468 | 508 | { |
469 | 509 | CHECK_SESSION_HANDLE(h); |
470 | - return (h->oia_flag[LIB3270_FLAG_BOXSOLID] != 0); | |
510 | + return (h->oia.flag[LIB3270_FLAG_BOXSOLID] != 0); | |
471 | 511 | } | ... | ... |
src/lib3270/private.h
... | ... | @@ -366,14 +366,16 @@ struct _h3270 |
366 | 366 | char * qualified; |
367 | 367 | } host; |
368 | 368 | |
369 | - char * proxy; /**< Proxy server (type:host[:port]) */ | |
369 | + // char * proxy; /**< Proxy server (type:host[:port]) */ | |
370 | 370 | char * termname; |
371 | 371 | |
372 | 372 | struct lib3270_charset charset; |
373 | 373 | |
374 | - LIB3270_MESSAGE oia_status; | |
375 | - | |
376 | - unsigned char oia_flag[LIB3270_FLAG_COUNT]; | |
374 | + struct | |
375 | + { | |
376 | + LIB3270_MESSAGE status; | |
377 | + unsigned char flag[LIB3270_FLAG_COUNT]; | |
378 | + } oia; | |
377 | 379 | |
378 | 380 | unsigned short current_port; |
379 | 381 | |
... | ... | @@ -630,9 +632,11 @@ struct _h3270 |
630 | 632 | void *userdata; |
631 | 633 | } trace; |
632 | 634 | |
633 | - // Callbacks. | |
634 | - struct lib3270_state_callback * st_callbacks[LIB3270_STATE_USER]; | |
635 | - struct lib3270_state_callback * st_last[LIB3270_STATE_USER]; | |
635 | + // State change listeners. | |
636 | + struct { | |
637 | + struct lib3270_state_callback * callbacks[LIB3270_STATE_USER]; | |
638 | + struct lib3270_state_callback * last[LIB3270_STATE_USER]; | |
639 | + } st; | |
636 | 640 | |
637 | 641 | }; |
638 | 642 | ... | ... |
src/lib3270/properties.c
... | ... | @@ -641,9 +641,9 @@ LIB3270_EXPORT int lib3270_get_secure_host(H3270 *hSession) |
641 | 641 | |
642 | 642 | } |
643 | 643 | |
644 | +#ifdef SSL_ENABLE_CRL_CHECK | |
644 | 645 | LIB3270_EXPORT char * lib3270_get_ssl_crl_text(H3270 *hSession) |
645 | 646 | { |
646 | -#ifdef SSL_ENABLE_CRL_CHECK | |
647 | 647 | |
648 | 648 | if(hSession->ssl.crl.cert) |
649 | 649 | { |
... | ... | @@ -666,11 +666,16 @@ LIB3270_EXPORT char * lib3270_get_ssl_crl_text(H3270 *hSession) |
666 | 666 | |
667 | 667 | } |
668 | 668 | |
669 | + return NULL; | |
669 | 670 | |
670 | -#endif // SSL_ENABLE_CRL_CHECK | |
671 | - | |
671 | +} | |
672 | +#else | |
673 | +LIB3270_EXPORT char * lib3270_get_ssl_crl_text(H3270 *hSession unused) | |
674 | +{ | |
672 | 675 | return NULL; |
673 | 676 | } |
677 | +#endif // SSL_ENABLE_CRL_CHECK | |
678 | + | |
674 | 679 | |
675 | 680 | LIB3270_EXPORT char * lib3270_get_ssl_peer_certificate_text(H3270 *hSession) |
676 | 681 | { | ... | ... |
src/lib3270/screen.c
... | ... | @@ -545,8 +545,8 @@ void set_status(H3270 *session, LIB3270_FLAG id, Boolean on) |
545 | 545 | { |
546 | 546 | CHECK_SESSION_HANDLE(session); |
547 | 547 | |
548 | - session->oia_flag[id] = (on != 0); | |
549 | - session->cbk.update_oia(session,id,session->oia_flag[id]); | |
548 | + session->oia.flag[id] = (on != 0); | |
549 | + session->cbk.update_oia(session,id,session->oia.flag[id]); | |
550 | 550 | |
551 | 551 | } |
552 | 552 | |
... | ... | @@ -640,7 +640,7 @@ void status_reset(H3270 *session) |
640 | 640 | LIB3270_EXPORT LIB3270_MESSAGE lib3270_get_program_message(H3270 *session) |
641 | 641 | { |
642 | 642 | CHECK_SESSION_HANDLE(session); |
643 | - return session->oia_status; | |
643 | + return session->oia.status; | |
644 | 644 | } |
645 | 645 | |
646 | 646 | /** |
... | ... | @@ -655,8 +655,8 @@ LIB3270_EXPORT LIB3270_MESSAGE lib3270_lock_status(H3270 *hSession) |
655 | 655 | { |
656 | 656 | CHECK_SESSION_HANDLE(hSession); |
657 | 657 | |
658 | - if(hSession->oia_status) | |
659 | - return hSession->oia_status; | |
658 | + if(hSession->oia.status) | |
659 | + return hSession->oia.status; | |
660 | 660 | |
661 | 661 | if(hSession->kybdlock) |
662 | 662 | return LIB3270_MESSAGE_KYBDLOCK; |
... | ... | @@ -683,10 +683,10 @@ void status_changed(H3270 *session, LIB3270_MESSAGE id) |
683 | 683 | { |
684 | 684 | CHECK_SESSION_HANDLE(session); |
685 | 685 | |
686 | - if(id == session->oia_status || id < 0) | |
686 | + if(id == session->oia.status || id < 0) | |
687 | 687 | return; |
688 | 688 | |
689 | - session->oia_status = id; | |
689 | + session->oia.status = id; | |
690 | 690 | |
691 | 691 | session->cbk.update_status(session,id); |
692 | 692 | } | ... | ... |
src/lib3270/session.c
... | ... | @@ -91,11 +91,11 @@ void lib3270_session_free(H3270 *h) |
91 | 91 | // Release state change callbacks |
92 | 92 | for(f=0;f<LIB3270_STATE_USER;f++) |
93 | 93 | { |
94 | - while(h->st_callbacks[f]) | |
94 | + while(h->st.callbacks[f]) | |
95 | 95 | { |
96 | - struct lib3270_state_callback *next = h->st_callbacks[f]->next; | |
97 | - lib3270_free(h->st_callbacks[f]); | |
98 | - h->st_callbacks[f] = next; | |
96 | + struct lib3270_state_callback *next = h->st.callbacks[f]->next; | |
97 | + lib3270_free(h->st.callbacks[f]); | |
98 | + h->st.callbacks[f] = next; | |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
... | ... | @@ -321,7 +321,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char |
321 | 321 | hSession->sock = -1; |
322 | 322 | hSession->model_num = -1; |
323 | 323 | hSession->cstate = LIB3270_NOT_CONNECTED; |
324 | - hSession->oia_status = -1; | |
324 | + hSession->oia.status = -1; | |
325 | 325 | hSession->kybdlock = KL_NOT_CONNECTED; |
326 | 326 | hSession->aid = AID_NO; |
327 | 327 | hSession->reply_mode = SF_SRM_FIELD; | ... | ... |