3 * Copyright 2007, OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
17 #include "SaslInteractionHandler.h"
18 #include "SaslInteraction.h"
21 void DefaultSaslInteractionHandler::handleInteractions(
22 const std::list<SaslInteraction*> &cb )
24 DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::handleCallbacks()"
26 std::list<SaslInteraction*>::const_iterator i;
28 for (i = cb.begin(); i != cb.end(); i++ ) {
31 cleanupList.push_back(*i);
33 std::cout << (*i)->getPrompt();
34 if (! (*i)->getDefaultResult().empty() ) {
35 std::cout << "(" << (*i)->getDefaultResult() << ")" ;
39 switch ( (*i)->getId() ) {
41 case SASL_CB_ECHOPROMPT:
50 /* turn off terminal echo if needed */
51 struct termios old_attr;
54 if (tcgetattr(STDIN_FILENO, &attr) < 0) {
58 /* save terminal attributes */
59 memcpy(&old_attr, &attr, sizeof(attr));
62 attr.c_lflag &= ~(ECHO);
64 /* write attributes to terminal */
65 if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) < 0) {
69 #endif /* HAVE_TERMIOS_H */
71 std::cin >> std::noskipws >> input;
72 std::cin >> std::skipws;
73 (*i)->setResult(input);
74 if( std::cin.fail() ) {
77 /* ignore the rest of the input line */
78 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
81 /* restore terminal settings */
83 tcsetattr(STDIN_FILENO, TCSANOW, &old_attr);
84 std::cout << std::endl;
86 #endif /* HAVE_TERMIOS_H */
90 DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler()
92 DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler()"
95 std::list<SaslInteraction*>::const_iterator i;
96 for (i = cleanupList.begin(); i != cleanupList.end(); i++ ) {