3 * Copyright 2007-2015 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
19 #include "SaslInteractionHandler.h"
20 #include "SaslInteraction.h"
23 void DefaultSaslInteractionHandler::handleInteractions(
24 const std::list<SaslInteraction*> &cb )
26 DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::handleCallbacks()"
28 std::list<SaslInteraction*>::const_iterator i;
30 for (i = cb.begin(); i != cb.end(); i++ ) {
33 cleanupList.push_back(*i);
35 std::cout << (*i)->getPrompt();
36 if (! (*i)->getDefaultResult().empty() ) {
37 std::cout << "(" << (*i)->getDefaultResult() << ")" ;
41 switch ( (*i)->getId() ) {
43 case SASL_CB_ECHOPROMPT:
52 /* turn off terminal echo if needed */
53 struct termios old_attr;
56 if (tcgetattr(STDIN_FILENO, &attr) < 0) {
60 /* save terminal attributes */
61 memcpy(&old_attr, &attr, sizeof(attr));
64 attr.c_lflag &= ~(ECHO);
66 /* write attributes to terminal */
67 if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) < 0) {
71 #endif /* HAVE_TERMIOS_H */
73 std::cin >> std::noskipws >> input;
74 std::cin >> std::skipws;
75 (*i)->setResult(input);
76 if( std::cin.fail() ) {
79 /* ignore the rest of the input line */
80 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
83 /* restore terminal settings */
85 tcsetattr(STDIN_FILENO, TCSANOW, &old_attr);
86 std::cout << std::endl;
88 #endif /* HAVE_TERMIOS_H */
92 DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler()
94 DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler()"
97 std::list<SaslInteraction*>::const_iterator i;
98 for (i = cleanupList.begin(); i != cleanupList.end(); i++ ) {