2 * Copyright 2007, OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
16 #include "SaslInteractionHandler.h"
17 #include "SaslInteraction.h"
20 void DefaultSaslInteractionHandler::handleInteractions(
21 const std::list<SaslInteraction*> &cb )
23 DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::handleCallbacks()"
25 std::list<SaslInteraction*>::const_iterator i;
27 for (i = cb.begin(); i != cb.end(); i++ ) {
30 cleanupList.push_back(*i);
32 std::cout << (*i)->getPrompt();
33 if (! (*i)->getDefaultResult().empty() ) {
34 std::cout << "(" << (*i)->getDefaultResult() << ")" ;
38 switch ( (*i)->getId() ) {
40 case SASL_CB_ECHOPROMPT:
49 /* turn off terminal echo if needed */
50 struct termios old_attr;
53 if (tcgetattr(STDIN_FILENO, &attr) < 0) {
57 /* save terminal attributes */
58 memcpy(&old_attr, &attr, sizeof(attr));
61 attr.c_lflag &= ~(ECHO);
63 /* write attributes to terminal */
64 if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) < 0) {
68 #endif /* HAVE_TERMIOS_H */
70 std::cin >> std::noskipws >> input;
71 std::cin >> std::skipws;
72 (*i)->setResult(input);
73 if( std::cin.fail() ) {
76 /* ignore the rest of the input line */
77 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
80 /* restore terminal settings */
82 tcsetattr(STDIN_FILENO, TCSANOW, &old_attr);
83 std::cout << std::endl;
85 #endif /* HAVE_TERMIOS_H */
89 DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler()
91 DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler()"
94 std::list<SaslInteraction*>::const_iterator i;
95 for (i = cleanupList.begin(); i != cleanupList.end(); i++ ) {