Browse Source

[2497] Add a new RdataFactory class which includes the new create() impl

Also code to gen-rdatacode.py to optionally use the new RdataFactory
for some types if configured to do so.
Mukund Sivaraman 12 years ago
parent
commit
331d377c8f
2 changed files with 25 additions and 2 deletions
  1. 12 2
      src/lib/dns/gen-rdatacode.py.in
  2. 13 0
      src/lib/dns/rrparamregistry-placeholder.cc

+ 12 - 2
src/lib/dns/gen-rdatacode.py.in

@@ -28,6 +28,7 @@ re_typecode = re.compile('([\da-z]+)_(\d+)')
 classcode2txt = {}
 typecode2txt = {}
 typeandclass = []
+new_rdatafactory_users = []
 generic_code = 65536            # something larger than any code value
 rdata_declarations = ''
 class_definitions = ''
@@ -271,15 +272,24 @@ def generate_rrparam(fileprefix, basemtime):
         class_utxt = class_tuple[1].upper()
         indent = ' ' * 8
         typeandclassparams += indent
+
+        # By default, we use OldRdataFactory (see bug #2497). If you
+        # want to pick RdataFactory for a particular type, add it to
+        # new_rdatafactory_users.
+        if type_txt in new_rdatafactory_users:
+            rdf_class = 'RdataFactory'
+        else:
+            rdf_class = 'OldRdataFactory'
+
         if class_tuple[1] != 'generic':
             typeandclassparams += 'add("' + type_utxt + '", '
             typeandclassparams += str(type_code) + ', "' + class_utxt
             typeandclassparams += '", ' + str(class_code)
-            typeandclassparams += ', RdataFactoryPtr(new OldRdataFactory<'
+            typeandclassparams += ', RdataFactoryPtr(new ' + rdf_class + '<'
             typeandclassparams += class_txt + '::' + type_utxt + '>()));\n'
         else:
             typeandclassparams += 'add("' + type_utxt + '", ' + str(type_code)
-            typeandclassparams += ', RdataFactoryPtr(new OldRdataFactory<'
+            typeandclassparams += ', RdataFactoryPtr(new ' + rdf_class + '<'
             typeandclassparams += class_txt + '::' + type_utxt + '>()));\n'
 
     rrparam_temp = open(placeholder, 'r')

+ 13 - 0
src/lib/dns/rrparamregistry-placeholder.cc

@@ -181,6 +181,19 @@ public:
     }
 };
 
+template <typename T>
+class RdataFactory : public OldRdataFactory<T> {
+public:
+    using OldRdataFactory<T>::create;
+
+    virtual RdataPtr create(MasterLexer& lexer, const Name* origin,
+                            MasterLoader::Options options,
+                            MasterLoaderCallbacks& callbacks) const {
+        return (RdataPtr(new T(dynamic_cast<const T&>(lexer, origin, options,
+                                                      callbacks))));
+    }
+};
+
 ///
 /// \brief The \c RRParamRegistryImpl class is the actual implementation of
 /// \c RRParamRegistry.