📄 sipimpliedsubscriptions.cpp
字号:
// // // Copyright (C) 2004 SIPfoundry Inc.// Licensed by SIPfoundry under the LGPL license.// // Copyright (C) 2004 Pingtel Corp.// Licensed to SIPfoundry under a Contributor Agreement.// // $$///////////////////////////////////////////////////////////////////////////////** * SIP Registrar Implied Subscriptions * * The SipImpliedSubscriptions::doImpliedSubscriptions method is invoked by * the Registrar whenever a REGISTER request succeeds. This object determines * whether or not the register needs to generate any SUBSCRIBE requests on behalf * of the originator of the REGISTER, and if so, creates and sends those SUBSCRIBE * requests. * * Configuration is in the registrar-config file. Directives that begin with the * ConfigPrefix (const below) specify a regular expression to be checked against * the User-Agent value in the REGISTER request. When it matches, this module * generates a SUBSCRIBE for message waiting indication on behalf of the phone. */// SYSTEM INCLUDES// :TODO: #include <stdlib.h>// APPLICATION INCLUDES#include "os/OsLock.h"#include "os/OsDateTime.h"#include "os/OsSysLog.h"#include "os/OsConfigDb.h"#include "utl/UtlString.h"#include "utl/UtlRegex.h"#include "net/NetMd5Codec.h"#include "sipdb/CredentialDB.h"#include "SipImpliedSubscriptions.h"// DEFINES// MACROS// EXTERNAL FUNCTIONS// EXTERNAL VARIABLES// CONSTANTS// STRUCTS// TYPEDEFS// FORWARD DECLARATIONS// GLOBAL VARIABLESextern "C" RegisterPlugin* getRegisterPlugin(const UtlString& name){ OsLock lock(*SipImpliedSubscriptions::mpSingletonLock); RegisterPlugin* thePlugin; if (!SipImpliedSubscriptions::mpSingleton) { SipImpliedSubscriptions::mpSingleton = new SipImpliedSubscriptions(name); thePlugin = dynamic_cast<RegisterPlugin*>(SipImpliedSubscriptions::mpSingleton); } else { OsSysLog::add(FAC_SIP, PRI_ERR, "SipImpliedSubscriptions plugin may not be configured twice.\n" " First configured instance is %s.\n" " Second instance [%s] not created.", SipImpliedSubscriptions::mpSingleton->mLogName.data(), name.data() ); thePlugin = NULL; } return thePlugin;}OsBSem* SipImpliedSubscriptions::mpSingletonLock = new OsBSem( OsBSem::Q_PRIORITY ,OsBSem::FULL );SipImpliedSubscriptions* SipImpliedSubscriptions::mpSingleton;// ImpliedSubscriptionUserAgent - private configuration class// Each of these records one implied subscription directive// from the registrar configuration file.// The parent UtlString value is the UA identifier from the configuration directive// These are created as members of the configuredUserAgents list, below.class ImpliedSubscriptionUserAgent : public UtlString{public: ImpliedSubscriptionUserAgent( const UtlString& name ,const UtlString& recognizer ,const UtlString& logName ) : UtlString(name) { mUserAgentRegEx = NULL; try { mUserAgentRegEx = new RegEx(recognizer.data()); } catch(const char* compileError) { OsSysLog::add( FAC_SIP, PRI_ERR ,"%s: Invalid recognizer expression '%s' for '%s%s': %s" ,logName.data() ,recognizer.data() ,SipImpliedSubscriptions::ConfigPrefix ,data() ,compileError ); } } ~ImpliedSubscriptionUserAgent() { if (mUserAgentRegEx) { delete mUserAgentRegEx; } } UtlBoolean matchesRecognizer(const UtlString& rcvdUA, const UtlString& logName) const { UtlBoolean matched = FALSE; if (mUserAgentRegEx) // NULL if recognizer did not compile {# if 1 // :TODO: DEBUG OsSysLog::add( FAC_SIP, PRI_DEBUG ,"%s checking %s: %s" ,logName.data(), data(), rcvdUA.data() );# endif matched = mUserAgentRegEx->Search(rcvdUA); } return matched; }private: RegEx* mUserAgentRegEx;};// ConfiguredUserAgents - private class// This is the list of ImpliedSubscriptionUserAgent objects;// one per configuration directive.class ConfiguredUserAgents{public: ConfiguredUserAgents() { } ~ConfiguredUserAgents() { reset(); } void add( const UtlString& name ,const UtlString& recognizer ,const UtlString& logName ) { mConfiguredUserAgents.append(new ImpliedSubscriptionUserAgent( name, recognizer, logName )); } void reset() { mConfiguredUserAgents.destroyAll(); } ImpliedSubscriptionUserAgent* configurationName( const UtlString& name ,const UtlString& logName ) { ImpliedSubscriptionUserAgent* foundAgent = NULL; ImpliedSubscriptionUserAgent* agent; UtlSListIterator nextAgent(mConfiguredUserAgents) ; for (agent = dynamic_cast<ImpliedSubscriptionUserAgent*>(nextAgent()); !foundAgent && agent; agent = dynamic_cast<ImpliedSubscriptionUserAgent*>(nextAgent()) ) { if (agent->matchesRecognizer(name, logName)) { foundAgent = agent; } } return foundAgent ; }private: UtlSList mConfiguredUserAgents ;};// the only instance of ConfiguredUserAgentsstatic ConfiguredUserAgents configuredUserAgents;// the 'SIP_REGISTRAR.<instancename>.' has been stripped by the time we see it...const char SipImpliedSubscriptions::ConfigPrefix[] = "UA.";SipImpliedSubscriptions::SipImpliedSubscriptions(const UtlString& name) : RegisterPlugin(name){ mLogName.append("["); mLogName.append(name); mLogName.append("] SipImpliedSubscriptions");}SipImpliedSubscriptions::~SipImpliedSubscriptions(){}void SipImpliedSubscriptions::readConfig( OsConfigDb& configDb ){ OsConfigDb impliedSubscriptionConfig; OsStatus found; UtlString key; UtlString name; UtlString recognizer; configuredUserAgents.reset(); // extract the database of implied message waiting subscriptions configDb.getSubHash( ConfigPrefix ,impliedSubscriptionConfig ); for ( key = "", found = impliedSubscriptionConfig.getNext( key ,name ,recognizer ); found == OS_SUCCESS; key = name, found = impliedSubscriptionConfig.getNext( key ,name ,recognizer ) ) { OsSysLog::add( FAC_SIP, PRI_INFO
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -