Browse Source

[3213] ignore the 'source' param for the istream version of masterLoad.

it was actually unused in the revised code.  as a result we can easily
consolidate the two versions, so did it too with a helper template function.
also explained the API change in the doc.
JINMEI Tatuya 11 years ago
parent
commit
d57c3ae58c
2 changed files with 22 additions and 24 deletions
  1. 17 21
      src/lib/dns/masterload.cc
  2. 5 3
      src/lib/dns/masterload.h

+ 17 - 21
src/lib/dns/masterload.cc

@@ -64,18 +64,14 @@ callbackWrapper(const RRsetPtr& rrset, MasterLoadCallback callback,
 
 
     callback(rrset);
     callback(rrset);
 }
 }
-}
 
 
+template <typename InputType>
 void
 void
-masterLoad(const char* const filename, const Name& origin,
+loadHelper(InputType input, const Name& origin,
            const RRClass& zone_class, MasterLoadCallback callback)
            const RRClass& zone_class, MasterLoadCallback callback)
 {
 {
-    if ((filename == NULL) || (*filename == '\0')) {
-        isc_throw(MasterLoadError, "Name of master file must not be null");
-    }
-
     RRCollator rr_collator(boost::bind(callbackWrapper, _1, callback, &origin));
     RRCollator rr_collator(boost::bind(callbackWrapper, _1, callback, &origin));
-    MasterLoader loader(filename, origin, zone_class,
+    MasterLoader loader(input, origin, zone_class,
                         MasterLoaderCallbacks::getNullCallbacks(),
                         MasterLoaderCallbacks::getNullCallbacks(),
                         rr_collator.getCallback());
                         rr_collator.getCallback());
     try {
     try {
@@ -85,24 +81,24 @@ masterLoad(const char* const filename, const Name& origin,
     }
     }
     rr_collator.flush();
     rr_collator.flush();
 }
 }
+}
 
 
 void
 void
-masterLoad(istream& input, const Name& origin, const RRClass& zone_class,
-           MasterLoadCallback callback, const char* source)
+masterLoad(const char* const filename, const Name& origin,
+           const RRClass& zone_class, MasterLoadCallback callback)
 {
 {
-    RRCollator rr_collator(boost::bind(callbackWrapper, _1, callback, &origin));
-    MasterLoader loader(input, origin, zone_class,
-                        MasterLoaderCallbacks::getNullCallbacks(),
-                        rr_collator.getCallback());
-    if (source == NULL) {
-        source = "<unknown>";
-    }
-    try {
-        loader.load();
-    } catch (const MasterLoaderError& ex) {
-        isc_throw(MasterLoadError, ex.what());
+    if ((filename == NULL) || (*filename == '\0')) {
+        isc_throw(MasterLoadError, "Name of master file must not be null");
     }
     }
-    rr_collator.flush();
+
+    loadHelper<const char*>(filename, origin, zone_class, callback);
+}
+
+void
+masterLoad(istream& input, const Name& origin, const RRClass& zone_class,
+           MasterLoadCallback callback, const char*)
+{
+    loadHelper<istream&>(input, origin, zone_class, callback);
 }
 }
 
 
 } // namespace dns
 } // namespace dns

+ 5 - 3
src/lib/dns/masterload.h

@@ -159,14 +159,16 @@ void masterLoad(const char* const filename, const Name& origin,
 /// All descriptions of the other version apply to this version except those
 /// All descriptions of the other version apply to this version except those
 /// specific to file I/O.
 /// specific to file I/O.
 ///
 ///
+/// Note: The 'source' parameter is now ignored, but it was only used in
+/// exception messages on some error.  So the compatibility effect should be
+/// minimal.
+///
 /// \param input An input stream object that is to emit zone's RRs.
 /// \param input An input stream object that is to emit zone's RRs.
 /// \param origin The origin name of the zone.
 /// \param origin The origin name of the zone.
 /// \param zone_class The RR class of the zone.
 /// \param zone_class The RR class of the zone.
 /// \param callback A callback functor or function that is to be called for
 /// \param callback A callback functor or function that is to be called for
 /// each RRset.
 /// each RRset.
-/// \param source A string to use in error messages if zone content is bad
-/// (e.g. the file name when reading from a file). If this value is NULL,
-/// or left out, the error will use the string '<unknown>'
+/// \param source This parameter is now ignored but left for compatibility.
 void masterLoad(std::istream& input, const Name& origin,
 void masterLoad(std::istream& input, const Name& origin,
                 const RRClass& zone_class, MasterLoadCallback callback,
                 const RRClass& zone_class, MasterLoadCallback callback,
                 const char* source = NULL);
                 const char* source = NULL);