2 * Copyright 2007, OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
14 #include "SaslInteractionHandler.h"
15 #include "SaslInteraction.h"
18 void DefaultSaslInteractionHandler::handleInteractions(
19 const std::list<SaslInteraction*> &cb )
21 DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::handleCallbacks()"
23 std::list<SaslInteraction*>::const_iterator i;
25 for (i = cb.begin(); i != cb.end(); i++ ) {
28 cleanupList.push_back(*i);
30 std::cout << (*i)->getPrompt();
31 if (! (*i)->getDefaultResult().empty() ) {
32 std::cout << "(" << (*i)->getDefaultResult() << ")" ;
36 switch ( (*i)->getId() ) {
38 case SASL_CB_ECHOPROMPT:
47 /* turn off terminal echo if needed */
48 struct termios old_attr;
51 if (tcgetattr(STDIN_FILENO, &attr) < 0) {
55 /* save terminal attributes */
56 memcpy(&old_attr, &attr, sizeof(attr));
59 attr.c_lflag &= ~(ECHO);
61 /* write attributes to terminal */
62 if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) < 0) {
66 #endif /* HAVE_TERMIOS_H */
68 std::cin >> std::noskipws >> input;
69 std::cin >> std::skipws;
70 (*i)->setResult(input);
71 if( std::cin.fail() ) {
74 /* ignore the rest of the input line */
75 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
78 /* restore terminal settings */
80 tcsetattr(STDIN_FILENO, TCSANOW, &old_attr);
81 std::cout << std::endl;
83 #endif /* HAVE_TERMIOS_H */
87 DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler()
89 DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler()"
92 std::list<SaslInteraction*>::const_iterator i;
93 for (i = cleanupList.begin(); i != cleanupList.end(); i++ ) {