Browse Source

[trac551] Method for changing name of rrset

Michal 'vorner' Vaner 14 years ago
parent
commit
406ff425ec
1 changed files with 25 additions and 0 deletions
  1. 25 0
      src/lib/datasrc/memory_datasrc.cc

+ 25 - 0
src/lib/datasrc/memory_datasrc.cc

@@ -351,6 +351,31 @@ struct MemoryZone::MemoryZoneImpl {
         return (false);
     }
 
+    /*
+     * Prepares a rrset to be return as a result.
+     *
+     * If rename is false, it returns the one provided. If it is true, it
+     * creates a new rrset with the same data but with provided name.
+     * It is designed for wildcard case, where we create the rrsets
+     * dynamically.
+     */
+    static ConstRRsetPtr prepareRRset(const Name& name, const ConstRRsetPtr&
+        rrset, bool rename)
+    {
+        if (rename) {
+            // TODO What about signatures? If we change the name, it would be
+            // wrong anyway...
+            RRsetPtr result(new RRset(name, rrset->getClass(),
+                rrset->getType(), rrset->getTTL()));
+            for (RdataIteratorPtr i(rrset->getRdataIterator()); !i->isLast();
+                i->next()) {
+                result->addRdata(i->getCurrent());
+            }
+            return (result);
+        } else {
+            return (rrset);
+        }
+    }
 
     // Implementation of MemoryZone::find
     FindResult find(const Name& name, RRType type,