void SubscribeDB::updateNotifyUnexpiredSubscription( const UtlString& component, const UtlString& to, const UtlString& from, const UtlString& callid, const UtlString& eventTypeKey, const UtlString& id, int timeNow, int updatedNotifyCseq, int version) const { mongo::BSONObj query = BSON( Subscription::toUri_fld() << to.str() << Subscription::callId_fld() << callid.str() << Subscription::eventTypeKey_fld() << eventTypeKey.str() << Subscription::id_fld() << id.str() ); mongo::BSONObj update = BSON("$set" << BSON( Subscription::notifyCseq_fld() << updatedNotifyCseq << Subscription::version_fld() << version)); MongoDB::ScopedDbConnectionPtr conn(mongo::ScopedDbConnection::getScopedDbConnection(_info.getConnectionString().toString())); mongo::DBClientBase* client = conn->get(); client->update(_info.getNS(), query, update); client->ensureIndex("node.subscription", BSON( "expires" << 1 )); client->ensureIndex("node.subscription", BSON( "key" << 1 )); client->ensureIndex("node.subscription", BSON( "toUri" << 1 )); conn->done(); }
void SubscribeDB::getUnexpiredSubscriptionsAndIncrementCSeq ( const UtlString& component, const UtlString& key, const UtlString& eventTypeKey, const int& timeNow, Subscriptions& subscriptions) { removeExpired(component, timeNow); //query="key=",key,"and eventtypekey=",eventTypeKey; mongo::BSONObj query = BSON("$findAndModify" << BSON("query" << BSON( Subscription::key_fld() << key.str() << Subscription::eventTypeKey_fld() << eventTypeKey.str())) << "," << BSON("update" << BSON_INC(Subscription::notifyCseq_fld() << "1") ) ); mongo::ScopedDbConnection conn(_info.getConnectionString()); mongo::BSONObj result; if (conn->runCommand(_info.getNS(), query, result)) { for (mongo::BSONObjIterator iter = result.begin(); iter.more();) { subscriptions.push_back(Subscription(iter.next().embeddedObject())); } } //while (pCursor.get() && pCursor->more()) //{ // subscriptions.push_back(Subscription(pCursor->next())); //} conn.done(); }
void SubscribeDB::updateNotifyUnexpiredSubscription( const UtlString& component, const UtlString& to, const UtlString& from, const UtlString& callid, const UtlString& eventTypeKey, const UtlString& id, int timeNow, int updatedNotifyCseq, int version) const { mongo::BSONObj query = BSON( Subscription::toUri_fld() << to.str() << Subscription::callId_fld() << callid.str() << Subscription::eventTypeKey_fld() << eventTypeKey.str() << Subscription::id_fld() << id.str() ); mongo::BSONObj update = BSON("$set" << BSON( Subscription::notifyCseq_fld() << updatedNotifyCseq << Subscription::version_fld() << version)); mongo::ScopedDbConnection conn(_info.getConnectionString()); conn->update(_info.getNS(), query, update); conn.done(); }
void SubscribeDB::removeError ( const UtlString& component, const UtlString& to, const UtlString& from, const UtlString& callid ) { mongo::BSONObj query = BSON( Subscription::toUri_fld() << to.str() << Subscription::fromUri_fld() << from.str() << Subscription::callId_fld() << callid.str()); mongo::ScopedDbConnection conn(_info.getConnectionString()); conn->remove(_info.getNS(), query); conn.done(); }
//delete methods - delete a subscription session void SubscribeDB::remove ( const UtlString& component, const UtlString& to, const UtlString& from, const UtlString& callid, const int& subscribeCseq) { mongo::BSONObj query = BSON( Subscription::toUri_fld() << to.str() << Subscription::fromUri_fld() << from.str() << Subscription::callId_fld() << callid.str() << Subscription::subscribeCseq_fld() << BSON_LESS_THAN(subscribeCseq)); MongoDB::ScopedDbConnectionPtr conn(mongo::ScopedDbConnection::getScopedDbConnection(_info.getConnectionString().toString())); conn->get()->remove(_info.getNS(), query); conn->done(); }
void SubscribeDB::removeExpired( const UtlString& component, const int timeNow ) { mongo::BSONObj query = BSON( Subscription::component_fld() << component.str() << Subscription::expires_fld() << BSON_LESS_THAN(timeNow)); mongo::ScopedDbConnection conn(_info.getConnectionString()); conn->remove(_info.getNS(), query); conn.done(); }
OsStatus SipRedirectorFallback::determineCallerLocationFromProvisionedUserLocation( const SipMessage& message, UtlString& callerLocation ) { OsStatus result = OS_FAILED; callerLocation.remove( 0 ); // First, determine the identity of the caller. This is done by looking for // a properly signed P-Asserted identity in the request message. // If the request contains a P-Asserted-Identity header and is not signed, // we will not trust it the returned location will be blank. UtlString matchedIdentityHeader; SipXauthIdentity sipxIdentity; Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "SipRedirectorFallback:: unbound entities allowing: %s", mAllowUnbound ? "TRUE" : "FALSE"); if (!mAllowUnbound) { SipXauthIdentity sipxIdentity( message, matchedIdentityHeader, false ); } else { SipXauthIdentity sipxIdentity( message, matchedIdentityHeader, false, SipXauthIdentity::allowUnbound); } if( !matchedIdentityHeader.isNull() ) { UtlString authenticatedUserIdentity; bool bRequestIsAuthenticated; bRequestIsAuthenticated = sipxIdentity.getIdentity( authenticatedUserIdentity ); if( bRequestIsAuthenticated ) { // we now have the autheticated identity of the caller. Look up the user location // database to find out the location that is mapped to it. //ResultSet userLocationsResult; // Check in User Location database if user has locations //mpUserLocationDbInstance->getLocations( authenticatedUserIdentity, userLocationsResult ); // Get the caller's site location. Only the first returned location is used. // This is not a problem given that a user should only belong to one location. EntityRecord entity; EntityDB* entityDb = SipRegistrar::getInstance(NULL)->getEntityDB(); if (entityDb->findByIdentity(authenticatedUserIdentity.str(), entity)) { callerLocation = entity.location().c_str(); result = OS_SUCCESS; Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "%s::determineCallerLocationFromProvisionedUserLocation mapped user '%s' taken from header '%s' to location '%s' based on its provisioned location", mLogName.data(), authenticatedUserIdentity.data(), authenticatedUserIdentity.data(), entity.location().c_str() ); } } } return result; }
void SubscribeDB::updateToTag( const UtlString& callid, const UtlString& fromtag, const UtlString& totag) const { mongo::BSONObj query = BSON(Subscription::callId_fld() << callid.str()); MongoDB::ScopedDbConnectionPtr conn(mongo::ScopedDbConnection::getScopedDbConnection(_info.getConnectionString().toString())); mongo::DBClientBase* client = conn->get(); auto_ptr<mongo::DBClientCursor> pCursor = client->query(_info.getNS(), query); while (pCursor.get() && pCursor->more()) { mongo::BSONObj bsonObj = pCursor->next(); if (bsonObj.hasField(Subscription::fromUri_fld())) { string fromUri = bsonObj.getStringField(Subscription::fromUri_fld()); Url from_uri(fromUri.c_str(), FALSE); UtlString seen_tag; if (from_uri.getFieldParameter("tag", seen_tag) && seen_tag.compareTo(fromtag) == 0) { if (bsonObj.hasField(Subscription::toUri_fld())) { string toUri = bsonObj.getStringField(Subscription::toUri_fld()); Url to_uri(toUri.c_str(), FALSE); UtlString dummy; if (!to_uri.getFieldParameter("tag", dummy)) { to_uri.setFieldParameter("tag", totag); to_uri.toString(dummy); // un-parse as name-addr mongo::BSONElement _id_field; if (true == bsonObj.getObjectID(_id_field)) { mongo::OID oid; _id_field.Val(oid); mongo::BSONObj query = BSON("_id" << oid); mongo::BSONObj update = BSON("$set" << BSON(Subscription::toUri_fld() << dummy.data())); client->update(_info.getNS(), query, update); client->ensureIndex("node.subscription", BSON( "expires" << 1 )); client->ensureIndex("node.subscription", BSON( "key" << 1 )); client->ensureIndex("node.subscription", BSON( "toUri" << 1 )); } else { // could not retrieve object id so update will fail OS_LOG_INFO(FAC_ODBC, "SubscribeDB::updateToTag get object id failed"); } } } } } } conn->done(); }
void SubscribeDB::getUnexpiredSubscriptions ( const UtlString& component, const UtlString& key, const UtlString& eventTypeKey, const int& timeNow, Subscriptions& subscriptions) { removeExpired(component, timeNow); //query="key=",key,"and eventtypekey=",eventTypeKey; mongo::BSONObj query = BSON( Subscription::key_fld() << key.str() << Subscription::eventTypeKey_fld() << eventTypeKey.str()); mongo::ScopedDbConnection conn(_info.getConnectionString()); auto_ptr<mongo::DBClientCursor> pCursor = conn->query(_info.getNS(), query); while (pCursor.get() && pCursor->more()) { subscriptions.push_back(Subscription(pCursor->next())); } conn.done(); }
bool SubscribeDB::subscriptionExists ( const UtlString& /*component*/, const UtlString& toUri, const UtlString& fromUri, const UtlString& callId, const int timeNow) { mongo::BSONObj query = BSON( Subscription::toUri_fld() << toUri.str() << Subscription::fromUri_fld() << fromUri.str() << Subscription::callId_fld() << callId.str() << Subscription::expires_fld() << BSON_GREATER_THAN_EQUAL(timeNow)); MongoDB::ScopedDbConnectionPtr conn(mongo::ScopedDbConnection::getScopedDbConnection(_info.getConnectionString().toString())); auto_ptr<mongo::DBClientCursor> pCursor = conn->get()->query(_info.getNS(), query); if (pCursor.get() && pCursor->more()) { conn->done(); return pCursor->itcount() > 0; } conn->done(); return false; }
int SubscribeDB::getMaxVersion(const UtlString& uri) const { mongo::BSONObj query = BSON(Subscription::uri_fld() << uri.str()); mongo::ScopedDbConnection conn(_info.getConnectionString()); auto_ptr<mongo::DBClientCursor> pCursor = conn->query(_info.getNS(), query); unsigned int value = 0; while (pCursor.get() && pCursor->more()) { Subscription row = pCursor->next(); if (value < row.version()) value = row.version(); } conn.done(); return value; }
void SubscribeDB::getUnexpiredContactsFieldsContaining( UtlString& substringToMatch, const int& timeNow, std::vector<string>& matchingContactFields ) const { mongo::BSONObj query = BSON(Subscription::expires_fld() << BSON_LESS_THAN(timeNow)); mongo::ScopedDbConnection conn(_info.getConnectionString()); auto_ptr<mongo::DBClientCursor> pCursor = conn->query(_info.getNS(), query); while (pCursor.get() && pCursor->more()) { string contact; mongo::BSONObj bsonObj = pCursor->next(); if (bsonObj.hasField(Subscription::contact_fld())) contact = bsonObj.getStringField(Subscription::contact_fld()); if (contact.find(substringToMatch.str()) != string::npos) matchingContactFields.push_back(contact); } conn.done(); }
bool SubscribeDB::findFromAndTo( const UtlString& callid, const UtlString& fromtag, const UtlString& totag, UtlString& from, UtlString& to) const { mongo::BSONObj query = BSON(Subscription::callId_fld() << callid.str()); mongo::ScopedDbConnection conn(_info.getConnectionString()); auto_ptr<mongo::DBClientCursor> pCursor = conn->query(_info.getNS(), query); while (pCursor.get() && pCursor->more()) { Subscription row = pCursor->next(); UtlBoolean r; UtlString seen_tag; // Get the tag on the URI in the "from" column. Url fromUri(row.fromUri().c_str(), FALSE); r = fromUri.getFieldParameter("tag", seen_tag); // If it matches... if (r && seen_tag.compareTo(fromtag) == 0) { // Get the tag on the URI in the "to" column. Url toUri(row.toUri().c_str(), FALSE); r = toUri.getFieldParameter("tag", seen_tag); // If it matches... if (r && seen_tag.compareTo(totag) == 0) { // We have found a match. Record the full URIs. from = row.fromUri().c_str(); to = row.toUri().c_str(); conn.done(); return true; } } } conn.done(); return false; }
void NatMaintainer::sendKeepAliveToRegContactList(const UtlString& identityToMatch) { int timeNow = OsDateTime::getSecsSinceEpoch(); RegDB::Bindings bindings; mpRegDb->getUnexpiredContactsUserContaining( identityToMatch.str(), timeNow, bindings); for (RegDB::Bindings::iterator iter = bindings.begin(); iter != bindings.end(); iter++) { Url url(iter->getContact().c_str()); PublicTransportData publicTransport( url ); if( publicTransport.isInitialized() && publicTransport.getTransportProtocol().compareTo( "udp", UtlString::ignoreCase ) == 0 ) { sendKeepAliveToEndpoint( publicTransport.getAddress(), publicTransport.getPort() ); } } }
void SubscribeDB::updateToTag( const UtlString& callid, const UtlString& fromtag, const UtlString& totag) const { mongo::BSONObj query = BSON(Subscription::callId_fld() << callid.str()); mongo::ScopedDbConnection conn(_info.getConnectionString()); auto_ptr<mongo::DBClientCursor> pCursor = conn->query(_info.getNS(), query); while (pCursor.get() && pCursor->more()) { mongo::BSONObj bsonObj = pCursor->next(); if (bsonObj.hasField(Subscription::fromUri_fld())) { string fromUri = bsonObj.getStringField(Subscription::fromUri_fld()); Url from_uri(fromUri.c_str(), FALSE); UtlString seen_tag; if (from_uri.getFieldParameter("tag", seen_tag) && seen_tag.compareTo(fromtag) == 0) { if (bsonObj.hasField(Subscription::toUri_fld())) { string toUri = bsonObj.getStringField(Subscription::toUri_fld()); Url to_uri(toUri.c_str(), FALSE); UtlString dummy; if (!to_uri.getFieldParameter("tag", dummy)) { to_uri.setFieldParameter("tag", totag); to_uri.toString(dummy); // un-parse as name-addr string oid = bsonObj.getStringField(Subscription::oid_fld()); mongo::BSONObj query = BSON(Subscription::oid_fld() << oid); mongo::BSONObj update = BSON("$set" << BSON(Subscription::toUri_fld() << dummy.data())); conn->update(_info.getNS(), query, update); } } } } } conn.done(); }
void SubscribeDB::upsert ( const UtlString& component, const UtlString& uri, const UtlString& callId, const UtlString& contact, unsigned int expires, unsigned int subscribeCseq, const UtlString& eventTypeKey, const UtlString& eventType, const UtlString& id, const UtlString& toUri, const UtlString& fromUri, const UtlString& key, const UtlString& recordRoute, unsigned int notifyCseq, const UtlString& accept, unsigned int version) { mongo::BSONObj query = BSON( "key" << key.str() << "contact" << contact.str()); mongo::BSONObj update = BSON("$set" << BSON( Subscription::component_fld() << component.str() << Subscription::uri_fld() << uri.str() << Subscription::callId_fld() << callId.str() << Subscription::contact_fld() << contact.str() << Subscription::expires_fld() << expires << Subscription::subscribeCseq_fld() << subscribeCseq << Subscription::eventTypeKey_fld() << eventTypeKey.str() << Subscription::eventType_fld() << eventType.str() << Subscription::id_fld() << id.str() << Subscription::toUri_fld() << toUri.str() << Subscription::fromUri_fld() << fromUri.str() << Subscription::key_fld() << key.str() << Subscription::recordRoute_fld() << recordRoute.str() << Subscription::notifyCseq_fld() << notifyCseq << Subscription::accept_fld() << accept.str() << Subscription::version_fld() << version)); mongo::ScopedDbConnection conn(_info.getConnectionString()); conn->update(_info.getNS(), query, update, true, false); conn.done(); }
bool CallerAlias::getCallerAlias ( const UtlString& identity, const UtlString& domain, UtlString& callerAlias_ ) const { if (!_pEntities) return false; EntityRecord userEntity; EntityRecord gatewayEntity; bool hasUserEntity = false; bool hasGatewayEntity = false; std::string callerAlias; OS_LOG_INFO(FAC_SIP, "CallerAlias::getCallerAlias - EntityDB::findByIdentity for identity=" << identity.str() << " domain=" << domain.str()); hasUserEntity = _pEntities->collection().findByIdentity(identity.str(), userEntity); hasGatewayEntity = _pEntities->collection().findByIdentity(domain.str(), gatewayEntity); if (hasGatewayEntity && gatewayEntity.callerId().transformExtension) { size_t loc = identity.str().find("@"); if (loc != std::string::npos) { std::string userId = identity.str().substr(0, loc); // // Check if we need to truncate the userId to a certain length // if (gatewayEntity.callerId().extensionLength > 0 && userId.length() > (size_t)gatewayEntity.callerId().extensionLength) userId = string_right(userId, gatewayEntity.callerId().extensionLength); // // Now check if a prefix is specified // if (!gatewayEntity.callerId().extensionPrefix.empty()) { std::string buff = gatewayEntity.callerId().extensionPrefix; buff += userId; userId = userId = buff; } callerAlias = "<sip:"; callerAlias += userId; callerAlias += identity.str().substr(loc); callerAlias += ">"; } } else { if (hasUserEntity && !userEntity.callerId().id.empty()) callerAlias = userEntity.callerId().id; else if (hasGatewayEntity) gatewayEntity.callerId().ignoreUserCalleId = true; if (hasGatewayEntity && gatewayEntity.callerId().ignoreUserCalleId) { if (gatewayEntity.callerId().enforcePrivacy) { callerAlias = "sip:[email protected]"; } else if (!gatewayEntity.callerId().id.empty()) { callerAlias = gatewayEntity.callerId().id; } } } if (!callerAlias.empty()) callerAlias_ = callerAlias.c_str(); else OS_LOG_WARNING(FAC_SIP, "CallerAlias::getCallerAlias - No caller alias configured for identity=" << identity.str() << " domain=" << domain.str()); return !callerAlias.empty(); }
RedirectPlugin::LookUpStatus SipRedirectorRegDB::lookUp( const SipMessage& message, const UtlString& requestString, const Url& requestUri, const UtlString& method, ContactList& contactList, RequestSeqNo requestSeqNo, int redirectorNo, SipRedirectorPrivateStorage*& privateStorage, ErrorDescriptor& errorDescriptor) { unsigned long timeNow = OsDateTime::getSecsSinceEpoch(); // Local copy of requestUri Url requestUriCopy = requestUri; // Look for any grid parameter and remove it. UtlString gridParameter; UtlBoolean gridPresent = requestUriCopy.getUrlParameter("grid", gridParameter, 0); if (gridPresent) { requestUriCopy.removeUrlParameter("grid"); } if (Os::Logger::instance().willLog(FAC_SIP, PRI_DEBUG)) { UtlString temp; requestUriCopy.getUri(temp); Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "%s::lookUp gridPresent = %d, gridParameter = '%s', " "requestUriCopy after removing grid = '%s'", mLogName.data(), gridPresent, gridParameter.data(), temp.data()); } RegDB::Bindings registrations; // Give the ~~in~ URIs separate processing. UtlString user; requestUriCopy.getUserId(user); if (user.index(URI_IN_PREFIX) == 0) { // This is a ~~in~ URI. // Check for an '&' separator. ssize_t s = user.last('&'); if (s != UTL_NOT_FOUND) { // This is a ~~in~[user]&[instrument] URI. const char* instrumentp = user.data() + s + 1; UtlString u; u.append(user, sizeof (URI_IN_PREFIX) - 1, s - (sizeof (URI_IN_PREFIX) - 1)); requestUriCopy.setUserId(u); //regDB-> // getUnexpiredContactsUserInstrument(requestUriCopy, instrumentp, timeNow, registrations); UtlString identity; requestUriCopy.getIdentity(identity); _dataStore.regDB().getUnexpiredContactsUserInstrument(identity.str(), instrumentp, timeNow, registrations); } else { // This is a ~~in~[instrument] URI. const char* instrumentp = user.data() + sizeof (URI_IN_PREFIX) - 1; _dataStore.regDB().getUnexpiredContactsInstrument(instrumentp, timeNow, registrations); } } else { // Note that getUnexpiredContactsUser will reduce the requestUri to its // identity (user/host/port) part before searching in the // database. The requestUri identity is matched against the // "identity" column of the database, which is the identity part of // the "uri" column which is stored in registration.xml. UtlString identity; requestUriCopy.getIdentity(identity); _dataStore.regDB().getUnexpiredContactsUser(identity.str(), timeNow, registrations); } int numUnexpiredContacts = registrations.size(); Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "%s::lookUp got %d unexpired contacts", mLogName.data(), numUnexpiredContacts); // Check for a per-user call forward timer. // Don't set timer if we're not going to forward to voicemail. std::ostringstream userCfwdTimer; bool foundUserCfwdTimer = false; if (method.compareTo(SIP_INVITE_METHOD) == 0) { UtlString noRoute; requestUriCopy.getUrlParameter("sipx-noroute", noRoute); if ((!noRoute.isNull()) && (noRoute.compareTo("Voicemail") == 0)) { // This is not a call scenerio controlled by this users "forward to voicemail" timer } else { UtlString identity; requestUriCopy.getIdentity(identity); EntityRecord entity; foundUserCfwdTimer = _dataStore.entityDB().findByIdentity(identity.str(), entity); if (foundUserCfwdTimer) userCfwdTimer << entity.callForwardTime(); } } for (RegDB::Bindings::const_iterator iter = registrations.begin(); iter != registrations.end(); iter++) { // Query the Registration DB for the contact, expires and qvalue columns. Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "%s::lookUp contact = '%s', qvalue = '%s', path = '%s'", mLogName.data(), iter->getContact().c_str(), iter->getQvalue().c_str(), iter->getPath().c_str() ); Url contactUri(iter->getContact().c_str()); // If available set the per-user call forward timer. if (foundUserCfwdTimer) { contactUri.setHeaderParameter("expires", userCfwdTimer.str().c_str()); } // If the contact URI is the same as the request URI, ignore it. if (!contactUri.isUserHostPortEqual(requestUriCopy)) { // Check if the q-value from the database is valid, and if so, // add it into contactUri. if (!iter->getQvalue().empty()) { // :TODO: (XPL-3) need a RegEx copy constructor here // Check if q value is numeric and between the range 0.0 and 1.0. static RegEx qValueValid("^(0(\\.\\d{0,3})?|1(\\.0{0,3})?)$"); if (qValueValid.Search(iter->getQvalue().c_str())) { contactUri.setFieldParameter(SIP_Q_FIELD, iter->getQvalue().c_str()); } } // Re-apply any grid parameter. if (gridPresent) { contactUri.setUrlParameter("grid", gridParameter); } contactUri.setUrlParameter(SIP_SIPX_CALL_DEST_FIELD, "INT"); // Check if database contained a Path value. If so, add a Route // header parameter to the contact with the Path vector taken from // the registration data. if (!iter->getPath().empty()) { UtlString existingRouteValue; std::string pathVector = iter->getPath(); if ( contactUri.getHeaderParameter(SIP_ROUTE_FIELD, existingRouteValue)) { // there is already a Route header parameter in the contact; append it to the // Route derived from the Path vector. pathVector += SIP_MULTIFIELD_SEPARATOR; pathVector += existingRouteValue.str(); } contactUri.setHeaderParameter(SIP_ROUTE_FIELD, pathVector.c_str()); } // Add the contact. contactList.add( contactUri, *this ); } } return RedirectPlugin::SUCCESS; }
void SubscribeDB::upsert ( const UtlString& component, const UtlString& uri, const UtlString& callId, const UtlString& contact, unsigned int expires, unsigned int subscribeCseq, const UtlString& eventTypeKey, const UtlString& eventType, const UtlString& id, const UtlString& toUri, const UtlString& fromUri, const UtlString& key, const UtlString& recordRoute, unsigned int notifyCseq, const UtlString& accept, unsigned int version) { mongo::BSONObj query = BSON( "toUri" << toUri.str() << "fromUri" << fromUri.str() << "callId" << callId.str() << "eventTypeKey" << eventTypeKey.str()); mongo::BSONObjBuilder objBuilder; objBuilder.append(Subscription::component_fld(), component.str()); objBuilder.append(Subscription::uri_fld(), uri.str()); objBuilder.append(Subscription::callId_fld(), callId.str()); objBuilder.append(Subscription::contact_fld(), contact.str()); objBuilder.append(Subscription::expires_fld(), expires); objBuilder.append(Subscription::subscribeCseq_fld(), subscribeCseq); objBuilder.append(Subscription::eventTypeKey_fld(), eventTypeKey.str()); objBuilder.append(Subscription::eventType_fld(), eventType.str()); objBuilder.append(Subscription::id_fld(), id.str()); objBuilder.append(Subscription::toUri_fld(), toUri.str()); objBuilder.append(Subscription::fromUri_fld(), fromUri.str()); objBuilder.append(Subscription::key_fld(), key.str()); //do not include RecordRoute if was not provided, because it will delete existing entry if (!recordRoute.isNull()) { objBuilder.append(Subscription::recordRoute_fld(), recordRoute.str()); } // do not include the notifysequence in the update if it is zero if (notifyCseq) { objBuilder.append(Subscription::notifyCseq_fld(), notifyCseq); } objBuilder.append(Subscription::accept_fld(), accept.str()); objBuilder.append(Subscription::version_fld(),version); mongo::BSONObjBuilder opBuilder; opBuilder.append("$set", objBuilder.obj()); mongo::BSONObj update = opBuilder.obj(); MongoDB::ScopedDbConnectionPtr conn(mongo::ScopedDbConnection::getScopedDbConnection(_info.getConnectionString().toString())); mongo::DBClientBase* client = conn->get(); client->update(_info.getNS(), query, update, true, false); client->ensureIndex("node.subscription", BSON( "expires" << 1 )); client->ensureIndex("node.subscription", BSON( "key" << 1 )); client->ensureIndex("node.subscription", BSON( "toUri" << 1 )); conn->done(); removeAllExpired(); }