RegStore::AoR* RegStore::Connector::get_aor_data(const std::string& aor_id, SAS::TrailId trail) { LOG_DEBUG("Get AoR data for %s", aor_id.c_str()); AoR* aor_data = NULL; std::string data; uint64_t cas; Store::Status status = _data_store->get_data("reg", aor_id, data, cas, trail); if (status == Store::Status::OK) { // Retrieved the data, so deserialize it. aor_data = deserialize_aor(data); aor_data->_cas = cas; LOG_DEBUG("Data store returned a record, CAS = %ld", aor_data->_cas); SAS::Event event(trail, SASEvent::REGSTORE_GET_FOUND, 0); event.add_var_param(aor_id); SAS::report_event(event); } else if (status == Store::Status::NOT_FOUND) { // Data store didn't find the record, so create a new blank record. aor_data = new AoR(); SAS::Event event(trail, SASEvent::REGSTORE_GET_NEW, 0); event.add_var_param(aor_id); SAS::report_event(event); LOG_DEBUG("Data store returned not found, so create new record, CAS = %ld", aor_data->_cas); } else { // LCOV_EXCL_START SAS::Event event(trail, SASEvent::REGSTORE_GET_FAILURE, 0); event.add_var_param(aor_id); SAS::report_event(event); // LCOV_EXCL_STOP } return aor_data; }
/// Retrieve the AoR data for a given SIP URI, creating it if there isn't /// any already, and returning NULL if we can't get a connection. AoR* MemcachedStore::get_aor_data(const std::string& aor_id) ///< the SIP URI { memcached_return_t rc; MemcachedAoR* aor_data = NULL; // Try to get a connection struct timespec wait_time; wait_time.tv_sec = 0; wait_time.tv_nsec = 100 * 1000 * 1000; memcached_st* st = memcached_pool_fetch(_pool, &wait_time, &rc); if (st != NULL) { // Got one: use it. const char* key_ptr = aor_id.data(); const size_t key_len = aor_id.length(); rc = memcached_mget(st, &key_ptr, &key_len, 1); if (memcached_success(rc)) { memcached_result_st result; memcached_result_create(st, &result); memcached_fetch_result(st, &result, &rc); if (memcached_success(rc)) { aor_data = deserialize_aor(std::string(memcached_result_value(&result), memcached_result_length(&result))); aor_data->set_cas(memcached_result_cas(&result)); int now = time(NULL); expire_bindings(aor_data, now); } else { // AoR does not exist, so create it. aor_data = new MemcachedAoR(); } } memcached_pool_release(_pool, st); } return (AoR*)aor_data; }