diff --git a/RasTbl.cxx b/RasTbl.cxx index ae2e3e14..9c24055c 100644 --- a/RasTbl.cxx +++ b/RasTbl.cxx @@ -1020,7 +1020,7 @@ bool EndpointRec::SendURQ(H225_UnregRequestReason::Choices reason, int preemptio && !UsesH46017()) return false; // no valid RAS address - RasServer *RasSrv = RasServer::Instance(); + RasServer * RasSrv = RasServer::Instance(); H225_RasMessage ras_msg; ras_msg.SetTag(H225_RasMessage::e_unregistrationRequest); H225_UnregistrationRequest & urq = ras_msg; @@ -1031,6 +1031,13 @@ bool EndpointRec::SendURQ(H225_UnregRequestReason::Choices reason, int preemptio urq.m_endpointIdentifier = GetEndpointIdentifier(); urq.m_callSignalAddress.SetSize(1); urq.m_callSignalAddress[0] = GetCallSignalAddress(); + if (Toolkit::Instance()->IsMaintenanceMode()) { + H225_ArrayOf_AlternateGK alternates = Toolkit::Instance()->GetMaintenanceAlternate(); + if (alternates.GetSize() > 0) { + urq.IncludeOptionalField(H225_UnregistrationRequest::e_alternateGatekeeper); + urq.m_alternateGatekeeper = alternates; + } + } SetUsesH460P(false); #ifdef HAS_H46017 @@ -1822,12 +1829,14 @@ void RegistrationTable::RemoveByEndptr(const endptr & eptr) { RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctUnregister, eptr); EndpointRec *ep = eptr.operator->(); // evil - if (RasServer::Instance()->IsPassThroughRegistrant()) - RasServer::Instance()->RemoveAdditiveRegistration(ep->GetAliases()); - ep->SetUsesH460P(false); - ep->RemoveNATSocket(); - WriteLock lock(listLock); - InternalRemove(find(EndpointList.begin(), EndpointList.end(), ep)); + if (ep) { + if (RasServer::Instance()->IsPassThroughRegistrant()) + RasServer::Instance()->RemoveAdditiveRegistration(ep->GetAliases()); + ep->SetUsesH460P(false); + ep->RemoveNATSocket(); + WriteLock lock(listLock); + InternalRemove(find(EndpointList.begin(), EndpointList.end(), ep)); + } } void RegistrationTable::InternalRemove(iterator Iter) @@ -2439,6 +2448,25 @@ void RegistrationTable::OnNATSocketClosed(CallSignalSocket * s) } } +void RegistrationTable::UnregisterAllEndpointsNotInCall() +{ + WriteLock lock(listLock); + + iterator Iter = EndpointList.begin(); + while (Iter != EndpointList.end()) { + EndpointRec *ep = *Iter; + callptr call = CallTable::Instance()->FindCallRec(endptr(ep)); + if (!call) { + ep->Unregister(); + RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctUnregister, endptr(ep)); + RemovedList.push_back(ep); + Iter = EndpointList.erase(Iter); + --regSize; + } + else ++Iter; + } +} + #ifdef HAS_H46017 void RegistrationTable::UnregisterAllH46017Endpoints() { diff --git a/RasTbl.h b/RasTbl.h index c1d247ac..b0ac0f3f 100644 --- a/RasTbl.h +++ b/RasTbl.h @@ -599,6 +599,7 @@ class RegistrationTable : public Singleton { #ifdef HAS_H46017 void UnregisterAllH46017Endpoints(); #endif + void UnregisterAllEndpointsNotInCall(); void PrintAllRegistrations(USocket *client, bool verbose=FALSE); void PrintAllCached(USocket *client, bool verbose=FALSE); diff --git a/SoftPBX.cxx b/SoftPBX.cxx index 12515076..78eac424 100644 --- a/SoftPBX.cxx +++ b/SoftPBX.cxx @@ -581,6 +581,9 @@ void SoftPBX::MaintenanceMode(bool on, const PString & alternate) } else { Toolkit::Instance()->SetMaintenanceAlternate(""); } + if (on) { + RegistrationTable::Instance()->UnregisterAllEndpointsNotInCall(); + } GkStatus::Instance()->SignalStatus(PString("MaintenanceMode ") + (on ? "ON" : "OFF") + " " + alternate + "\r\n"); }