diff --git a/PjsuaCommunicator.cpp b/PjsuaCommunicator.cpp index a4c3cd4..5bbd78a 100644 --- a/PjsuaCommunicator.cpp +++ b/PjsuaCommunicator.cpp @@ -144,7 +144,16 @@ namespace sip { communicator.logger.notice(msgText); communicator.onStateChange(msgText); - communicator.onMuteDeafChange(0); + + communicator.got_dtmf = ""; + + /* + * if no pin is set, go ahead and turn off mute/deaf + * otherwise, wait for pin to be entered + */ + if ( communicator.pin.length() == 0 ) { + communicator.onMuteDeafChange(0); + } } else if (ci.state == PJSIP_INV_STATE_DISCONNECTED) { auto &acc = dynamic_cast<_Account &>(account); @@ -183,7 +192,31 @@ namespace sip { } void _Call::onDtmfDigit(pj::OnDtmfDigitParam &prm) { - communicator.logger.notice("DTMF digit '%s' (call %d).", prm.digit.c_str(), getId()); + communicator.logger.notice("DTMF digit '%s' (call %d).", + prm.digit.c_str(), getId()); + pj::CallOpParam param; + + if ( communicator.pin.length() > 0 ) { + if ( prm.digit == "#" ) { + communicator.logger.notice("DTMF got string command %s", + communicator.got_dtmf.c_str()); + if ( communicator.got_dtmf == communicator.pin ) { + communicator.logger.notice("Caller entered correct PIN"); + communicator.onMuteDeafChange(0); + } else { + communicator.logger.notice("Caller entered wrong PIN"); + param.statusCode = PJSIP_SC_SERVICE_UNAVAILABLE; + this->hangup(param); + } + communicator.got_dtmf = ""; + } else { + communicator.logger.notice("DTMF append %s to %s", + prm.digit.c_str(), communicator.got_dtmf.c_str()); + communicator.got_dtmf = communicator.got_dtmf + prm.digit; + } + } else { + communicator.logger.notice("DTMF ignoring %s", prm.digit.c_str()); + } } void _Account::onRegState(pj::OnRegStateParam &prm) { @@ -324,3 +357,4 @@ void sip::PjsuaCommunicator::registerAccount(string host, string user, string pa account.reset(new _Account(*this)); account->create(accountConfig); } + diff --git a/PjsuaCommunicator.hpp b/PjsuaCommunicator.hpp index 83b3dc0..8bb8aa3 100644 --- a/PjsuaCommunicator.hpp +++ b/PjsuaCommunicator.hpp @@ -76,6 +76,9 @@ namespace sip { int16_t *samples, unsigned int length); + std::string pin; + std::string got_dtmf; + std::function onIncomingPcmSamples; std::function onStateChange; diff --git a/config.ini.example b/config.ini.example index d5a635c..2b735f6 100644 --- a/config.ini.example +++ b/config.ini.example @@ -28,6 +28,11 @@ channelNameExpression = # in the same group autodeaf = 0 +# Caller PIN needed to authenticate the phone call itself. The caller presses +# the PIN, followed by the hash '#' key. On success, the caller is +# unmuted/undeafened. On failure, the SIP call is hung up. +pin = 4321 + # Bitrate of Opus encoder in B/s # Adjust it if you need to meet the specific bandwidth requirements of Murmur server opusEncoderBitrate = 16000 diff --git a/main.cpp b/main.cpp index d2ce848..83d5078 100644 --- a/main.cpp +++ b/main.cpp @@ -96,6 +96,13 @@ int main(int argc, char *argv[]) { mumbleConf.autodeaf = false; } + /* default to */ + try { + pjsuaCommunicator.pin = conf.getString("mumble.pin"); + } catch (...) { + pjsuaCommunicator.pin = ""; + } + mumbleCommunicator.connect(mumbleConf); pjsuaCommunicator.connect(