3 * Copyright 2007-2011 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
18 #include "SaslInteractionHandler.h"
19 #include "SaslInteraction.h"
22 void DefaultSaslInteractionHandler::handleInteractions(
23 const std::list<SaslInteraction*> &cb )
25 DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::handleCallbacks()"
27 std::list<SaslInteraction*>::const_iterator i;
29 for (i = cb.begin(); i != cb.end(); i++ ) {
32 cleanupList.push_back(*i);
34 std::cout << (*i)->getPrompt();
35 if (! (*i)->getDefaultResult().empty() ) {
36 std::cout << "(" << (*i)->getDefaultResult() << ")" ;
40 switch ( (*i)->getId() ) {
42 case SASL_CB_ECHOPROMPT:
51 /* turn off terminal echo if needed */
52 struct termios old_attr;
55 if (tcgetattr(STDIN_FILENO, &attr) < 0) {
59 /* save terminal attributes */
60 memcpy(&old_attr, &attr, sizeof(attr));
63 attr.c_lflag &= ~(ECHO);
65 /* write attributes to terminal */
66 if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) < 0) {
70 #endif /* HAVE_TERMIOS_H */
72 std::cin >> std::noskipws >> input;
73 std::cin >> std::skipws;
74 (*i)->setResult(input);
75 if( std::cin.fail() ) {
78 /* ignore the rest of the input line */
79 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
82 /* restore terminal settings */
84 tcsetattr(STDIN_FILENO, TCSANOW, &old_attr);
85 std::cout << std::endl;
87 #endif /* HAVE_TERMIOS_H */
91 DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler()
93 DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler()"
96 std::list<SaslInteraction*>::const_iterator i;
97 for (i = cleanupList.begin(); i != cleanupList.end(); i++ ) {