/// Called when the expiry timer pops. void Flow::expiry_timer() { // Scan through all the identities deleting any that have passed their // expiry time. This is done as a simple scan because we don't expect // a single flow to have a large number of identities. This may not be // a valid assumption if a downstream SBC or AGCF muxes a large number of // clients over a single flow. pthread_mutex_lock(&_flow_lock); int now = time(NULL); int min_expires = 0; for (auth_id_map::const_iterator i = _authorized_ids.begin(); i != _authorized_ids.end(); ) { if (i->second.expires <= now) { LOG_DEBUG("Expiring identity %s", i->first.c_str()); // Check to see whether this was the current default identity we are // using for this flow. We could do the string comparision in all cases // but it is only necessary if the identity is marked as a default // candidate. if ((i->second.default_id) && (i->first == _default_id)) { // This was our default ID, so remove it. _default_id = ""; } _authorized_ids.erase(i++); } else { // This entry hasn't expired yet, so use to to work out when we next // need the expiry timer to pop. if ((min_expires == 0) || (i->second.expires < min_expires)) { min_expires = i->second.expires; } ++i; } } if (_default_id == "") { // We've lost our default identity, so scan the list to see if there is // another one we can use. select_default_identity(); } if ((_authorized_ids.size() == 0) && (!PJSIP_TRANSPORT_IS_RELIABLE(_transport))) { // No active registrations on a non-reliable transport, so restart the // timer as an idle timer. restart_timer(IDLE_TIMER, IDLE_TIMEOUT); LOG_DEBUG("Started idle timer for flow %p", this); } else if (min_expires > now) { // Restart the timer to pop when the next identity(s) will expire. restart_timer(EXPIRY_TIMER, min_expires - now); } pthread_mutex_unlock(&_flow_lock); }
/* * Start Bios Keyboard. */ void xtk_init(void) { enable_irq(1); /* enable BIOS Keyboard interrupts */ restart_timer(); }
/// Sets the specified identities as authorized for this flow. void Flow::set_identity(const pjsip_uri* uri, const std::string& service_route, bool is_default, int expires) { int now = time(NULL); // Render the URI to an AoR suitable to look up in the map. std::string aor = PJUtils::public_id_from_uri((pjsip_uri*)pjsip_uri_get_uri(uri)); LOG_DEBUG("Setting identity %s on flow %p, expires = %d", aor.c_str(), this, expires); pthread_mutex_lock(&_flow_lock); // Convert the expiry time to an absolute time. expires += now; if (expires > now) { // Add a constant "grace" period to the expiry time to give clients so // leeway if they are late refreshing bindings, to avoid extra authentication // challenges. expires += EXPIRY_GRACE_INTERVAL; // Find or create the entry for this aor. AuthId& aid = _authorized_ids[aor]; // Store the name_addr rendered from the received URI. aid.name_addr = PJUtils::uri_to_string(PJSIP_URI_IN_FROMTO_HDR, uri); // Store the service route for this identity. aid.service_route = service_route; // Update the expiry time. aid.expires = expires; // Set the default_id flag aid.default_id = is_default; if ((aid.default_id) && (_default_id == "")) { // This is the first default_id to be set. _default_id = aor; } // May need to (re)start the timer if either it's not running, or it's // running as an idle timer, or the expires time for these identities is // earlier than the timer will next pop. if ((_timer.id != EXPIRY_TIMER) || (_timer._timer_value.sec > expires)) { restart_timer(EXPIRY_TIMER, expires - time(NULL)); } } else { LOG_DEBUG("Deleting identity %s", aor.c_str()); auth_id_map::iterator i = _authorized_ids.find(aor); if (i != _authorized_ids.end()) { // Check to see whether this was the current default identity we are // using for this flow. We could do the string comparision in all cases // but it is only necessary if the identity is marked as a default // candidate. if ((i->second.default_id) && (i->first == _default_id)) { // This was our default ID, so remove it. _default_id = ""; } _authorized_ids.erase(i); } if (_default_id == "") { // We've lost our default identity, so scan the list to see if there is // another one we can use. select_default_identity(); } // No need to restart the timer here. It may pop earlier than necessary // next time (if the entry we just deleted was the first to expire) but // that won't cause any problems. Restarting it here would require // a scan through all the entries looking for the next one to expire, // so would be no more efficient. } pthread_mutex_unlock(&_flow_lock); }
/// Start timing when a test starts void test_unit_start( boost::unit_test::test_unit const& unit) { restart_timer(); }