📄 dialogusagemanager.cxx
字号:
} case CANCEL: { // find the appropropriate ServerInvSession CancelMap::iterator i = mCancelMap.find(request.getTransactionId()); if (i != mCancelMap.end()) { i->second->dispatch(request); } else { InfoLog (<< "Received a CANCEL on a non-existent transaction "); SipMessage failure; makeResponse(failure, request, 481); sendResponse(failure); } break; } case PUBLISH: assert(false); case SUBSCRIBE: if (!checkEventPackage(request)) { InfoLog (<< "Rejecting request (unsupported package) " << request.brief()); return; } case NOTIFY : // handle unsolicited (illegal) NOTIFYs case INVITE: // new INVITE case REFER: // out-of-dialog REFER //case INFO : // handle non-dialog (illegal) INFOs case OPTIONS : // handle non-dialog OPTIONS case MESSAGE : case REGISTER: { { DialogSetId id(request); //cryptographically dangerous if(mDialogSetMap.find(id) != mDialogSetMap.end()) { // this can only happen if someone sends us a request with the same callid and from tag as one // that is in the process of destroying - since this is bad endpoint behaviour - we will // reject the request with a 400 response SipMessage badrequest; makeResponse(badrequest, request, 400); badrequest.header(h_AcceptLanguages) = getMasterProfile()->getSupportedLanguages(); sendResponse(badrequest); return; } } if (mDumShutdownHandler) { SipMessage forbidden; makeResponse(forbidden, request, 480); forbidden.header(h_AcceptLanguages) = getMasterProfile()->getSupportedLanguages(); sendResponse(forbidden); return; } try { DialogSet* dset = new DialogSet(request, *this); StackLog ( << "*********** Calling AppDialogSetFactory *************" ); AppDialogSet* appDs = mAppDialogSetFactory->createAppDialogSet(*this, request); appDs->mDialogSet = dset; dset->setUserProfile(appDs->selectUASUserProfile(request)); dset->mAppDialogSet = appDs; StackLog ( << "************* Adding DialogSet ***************" ); StackLog ( << "Before: " << Inserter(mDialogSetMap) ); mDialogSetMap[dset->getId()] = dset; StackLog ( << "After: Req" << Inserter(mDialogSetMap) ); dset->dispatch(request); } catch (BaseException& e) { SipMessage failure; makeResponse(failure, request, 400, e.getMessage()); failure.header(h_AcceptLanguages) = getMasterProfile()->getSupportedLanguages(); sendResponse(failure); } break; } case RESPONSE: case SERVICE: assert(false); break; case UNKNOWN: case MAX_METHODS: assert(false); break; } }}voidDialogUsageManager::processResponse(const SipMessage& response){ if (response.header(h_CSeq).method() != CANCEL) { DialogSet* ds = findDialogSet(DialogSetId(response)); if (ds) { DebugLog ( << "DialogUsageManager::processResponse: " << std::endl << std::endl << response.brief()); ds->dispatch(response); } else { InfoLog (<< "Throwing away stray response: " << std::endl << std::endl << response.brief()); } }}voidDialogUsageManager::processPublish(const SipMessage& request){ if (!checkEventPackage(request)) { InfoLog(<< "Rejecting request (unsupported package) " << request.brief()); return; } if (request.exists(h_SIPIfMatch)) { ServerPublications::iterator i = mServerPublications.find(request.header(h_SIPIfMatch).value()); if (i != mServerPublications.end()) { i->second->dispatch(request); } else { SharedPtr<SipMessage> response(new SipMessage); makeResponse(*response, request, 412); send(response); } } else { Data etag = Random::getCryptoRandomHex(8); while (mServerPublications.find(etag) != mServerPublications.end()) { etag = Random::getCryptoRandomHex(8); } if (request.getContents()) { ServerPublication* sp = new ServerPublication(*this, etag, request); mServerPublications[etag] = sp; sp->dispatch(request); } else { // per 3903 (sec 6.5), a PUB w/ no SIPIfMatch must have contents. .mjf. SharedPtr<SipMessage> response(new SipMessage); makeResponse(*response, request, 400); send(response); } }}boolDialogUsageManager::checkEventPackage(const SipMessage& request){ int failureCode = 0; MethodTypes method = request.header(h_RequestLine).method();// || (method == NOTIFY && !request.exists(h_SubscriptionState))) if (!request.exists(h_Event)) { InfoLog (<< "No Event header in " << request.header(h_RequestLine).unknownMethodName()); failureCode = 400; } else { switch(method) { case SUBSCRIBE: if (!getServerSubscriptionHandler(request.header(h_Event).value())) { InfoLog (<< "No handler for event package for SUBSCRIBE: " << request.header(h_Event).value()); failureCode = 489; } break; case NOTIFY: if (!getClientSubscriptionHandler(request.header(h_Event).value())) { InfoLog (<< "No handler for event package for NOTIFY: " << request.header(h_Event).value()); failureCode = 489; } break; case PUBLISH: if (!getServerPublicationHandler(request.header(h_Event).value())) { InfoLog (<< "No handler for event package for PUBLISH: " << request.header(h_Event).value()); failureCode = 489; } break; default: assert(0); } } if (failureCode > 0) { SharedPtr<SipMessage> response(new SipMessage); makeResponse(*response, request, failureCode); send(response); return false; } return true;}DialogSet*DialogUsageManager::findDialogSet(const DialogSetId& id){ StackLog ( << "Looking for dialogSet: " << id << " in map:" ); StackLog ( << Inserter(mDialogSetMap) ); DialogSetMap::const_iterator it = mDialogSetMap.find(id); if (it == mDialogSetMap.end()) { return 0; } else { if(it->second->isDestroying()) { return 0; } else { return it->second; } }}BaseCreator*DialogUsageManager::findCreator(const DialogId& id){ DialogSet* ds = findDialogSet(id.getDialogSetId()); if (ds) { return ds->getCreator(); } else { return 0; }}voidDialogUsageManager::removeDialogSet(const DialogSetId& dsId){ StackLog ( << "************* Removing DialogSet ***************" ); StackLog ( << "Before: " << Inserter(mDialogSetMap) ); mDialogSetMap.erase(dsId); StackLog ( << "After: " << Inserter(mDialogSetMap) ); if (mRedirectManager.get()) { mRedirectManager->removeDialogSet(dsId); }}ClientSubscriptionHandler*DialogUsageManager::getClientSubscriptionHandler(const Data& eventType){ map<Data, ClientSubscriptionHandler*>::iterator res = mClientSubscriptionHandlers.find(eventType); if (res != mClientSubscriptionHandlers.end()) { return res->second; } else { return 0; }}ServerSubscriptionHandler*DialogUsageManager::getServerSubscriptionHandler(const Data& eventType){ map<Data, ServerSubscriptionHandler*>::iterator res = mServerSubscriptionHandlers.find(eventType); if (res != mServerSubscriptionHandlers.end()) { return res->second; } else { return 0; }}ClientPublicationHandler*DialogUsageManager::getClientPublicationHandler(const Data& eventType){ map<Data, ClientPublicationHandler*>::iterator res = mClientPublicationHandlers.find(eventType); if (res != mClientPublicationHandlers.end()) { return res->second; } else { return 0; }}ServerPublicationHandler*DialogUsageManager::getServerPublicationHandler(const Data& eventType){ map<Data, ServerPublicationHandler*>::iterator res = mServerPublicationHandlers.find(eventType); if (res != mServerPublicationHandlers.end()) { return res->second; } else { return 0; }}OutOfDialogHandler*DialogUsageManager::getOutOfDialogHandler(const MethodTypes type){ map<MethodTypes, OutOfDialogHandler*>::iterator res = mOutOfDialogHandlers.find(type); if (res != mOutOfDialogHandlers.end()) { return res->second; } else { return 0; }}void DialogUsageManager::addIncomingFeature(resip::SharedPtr<DumFeature> feat){ mIncomingFeatureList.push_back(feat);}voidDialogUsageManager::addOutgoingFeature(resip::SharedPtr<DumFeature> feat){ // make sure EncryptionManager is the last feature in the list. mOutgoingFeatureList.insert(mOutgoingFeatureList.begin(), feat);}voidDialogUsageManager::setOutgoingMessageInterceptor(SharedPtr<DumFeature> feat){ mOutgoingMessageInterceptor = feat;}voidDialogUsageManager::applyToAllServerSubscriptions(ServerSubscriptionFunctor* functor){ assert(functor); for (DialogSetMap::iterator it = mDialogSetMap.begin(); it != mDialogSetMap.end(); ++it) { for (DialogSet::DialogMap::iterator i = it->second->mDialogs.begin(); i != it->second->mDialogs.end(); ++i) { std::vector<ServerSubscriptionHandle> serverSubs = i->second->getServerSubscriptions(); for (std::vector<ServerSubscriptionHandle>::iterator iss = serverSubs.begin(); iss != serverSubs.end(); ++iss) { functor->apply(*iss); } } }}voidDialogUsageManager::applyToAllClientSubscriptions(ClientSubscriptionFunctor* functor){ assert(functor); for (DialogSetMap::iterator it = mDialogSetMap.begin(); it != mDialogSetMap.end(); ++it) { for (DialogSet::DialogMap::iterator i = it->second->mDialogs.begin(); i != it->second->mDialogs.end(); ++i) { std::vector<ClientSubscriptionHandle> clientSubs = i->second->getClientSubscriptions(); for (std::vector<ClientSubscriptionHandle>::iterator ics = clientSubs.begin(); ics != clientSubs.end(); ++ics) { functor->apply(*ics); } } }}voidDialogUsageManager::registerForConnectionTermination(Postable* listener){ mConnectionTerminatedEventDispatcher.addListener(listener);}voidDialogUsageManager::unRegisterForConnectionTermination(Postable* listener){ mConnectionTerminatedEventDispatcher.removeListener(listener);}voidDialogUsageManager::requestMergedRequestRemoval(const MergedRequestKey& key){ DebugLog(<< "Got merged request removal request"); MergedRequestRemovalCommand command(*this, key); mStack.postMS(command, Timer::TF, this);}voidDialogUsageManager::removeMergedRequest(const MergedRequestKey& key){ DebugLog(<< "Merged request removed"); mMergedRequests.erase(key);}TargetCommand::Target& DialogUsageM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -