local_zone_data.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. // $Id$
  15. #include <dns/rrset.h>
  16. #include "local_zone_data.h"
  17. #include "cache_entry_key.h"
  18. #include "rrset_copy.h"
  19. using namespace std;
  20. using namespace isc::dns;
  21. namespace isc {
  22. namespace cache {
  23. typedef pair<std::string, RRsetPtr> RRsetMapPair;
  24. typedef map<std::string, RRsetPtr>::iterator RRsetMapIterator;
  25. isc::dns::RRsetPtr
  26. LocalZoneData::lookup(const isc::dns::Name& name,
  27. const isc::dns::RRType& type)
  28. {
  29. string key = genCacheEntryName(name, type);
  30. RRsetMapIterator iter = rrsets_map_.find(key);
  31. if (iter == rrsets_map_.end()) {
  32. return (RRsetPtr());
  33. } else {
  34. return (iter->second);
  35. }
  36. }
  37. void
  38. LocalZoneData::update(const isc::dns::RRset& rrset) {
  39. //TODO Do we really need to recreate the rrset again?
  40. string key = genCacheEntryName(rrset.getName(), rrset.getType());
  41. RRset* rrset_copy = new RRset(rrset.getName(), rrset.getClass(),
  42. rrset.getType(), rrset.getTTL());
  43. rrsetCopy(rrset, *rrset_copy);
  44. RRsetPtr rrset_ptr(rrset_copy);
  45. pair<RRsetMapIterator, bool> result = rrsets_map_.insert(RRsetMapPair(key, rrset_ptr));
  46. if (!result.second) {
  47. // Insert failed, we should remove the existed rrset first,
  48. // then insert again.
  49. rrsets_map_.erase(result.first);
  50. rrsets_map_.insert(RRsetMapPair(key, rrset_ptr));
  51. }
  52. }
  53. } // namespace cache
  54. } // namespace isc