]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
dns_master_loadlexer[inc], to load master files from existing lexers
authorBrian Wellington <source@isc.org>
Thu, 21 Feb 2002 00:45:11 +0000 (00:45 +0000)
committerBrian Wellington <source@isc.org>
Thu, 21 Feb 2002 00:45:11 +0000 (00:45 +0000)
lib/dns/include/dns/master.h
lib/dns/master.c

index d52ea9c4ab25d425d5a93b4c8d4e128fc3d0b9c8..c026502b00391c1d5b99061ca497d7ce51ddc859 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: master.h,v 1.34 2001/12/11 20:52:41 marka Exp $ */
+/* $Id: master.h,v 1.35 2002/02/21 00:45:11 bwelling Exp $ */
 
 #ifndef DNS_MASTER_H
 #define DNS_MASTER_H 1
@@ -73,6 +73,15 @@ dns_master_loadbuffer(isc_buffer_t *buffer,
                      dns_rdatacallbacks_t *callbacks,
                      isc_mem_t *mctx);
 
+isc_result_t
+dns_master_loadlexer(isc_lex_t *lex,
+                    dns_name_t *top,
+                    dns_name_t *origin,
+                    dns_rdataclass_t zclass,
+                    unsigned int options,
+                    dns_rdatacallbacks_t *callbacks,
+                    isc_mem_t *mctx);
+
 isc_result_t
 dns_master_loadfileinc(const char *master_file,
                       dns_name_t *top,
@@ -106,12 +115,23 @@ dns_master_loadbufferinc(isc_buffer_t *buffer,
                         dns_loaddonefunc_t done, void *done_arg,
                         dns_loadctx_t **ctxp, isc_mem_t *mctx);
 
+isc_result_t
+dns_master_loadlexerinc(isc_lex_t *lex,
+                       dns_name_t *top,
+                       dns_name_t *origin,
+                       dns_rdataclass_t zclass,
+                       unsigned int options,
+                       dns_rdatacallbacks_t *callbacks,
+                       isc_task_t *task,
+                       dns_loaddonefunc_t done, void *done_arg,
+                       dns_loadctx_t **ctxp, isc_mem_t *mctx);
+
 /*
- * Loads a RFC 1305 master file from a file, stream, or buffer into rdatasets
- * and then calls 'callbacks->commit' to commit the rdatasets.  Rdata memory
- * belongs to dns_master_load and will be reused / released when the callback
- * completes.  dns_load_master will abort if callbacks->commit returns
- * any value other than ISC_R_SUCCESS.
+ * Loads a RFC 1305 master file from a file, stream, buffer, or existing
+ * lexer into rdatasets and then calls 'callbacks->commit' to commit the
+ * rdatasets.  Rdata memory belongs to dns_master_load and will be
+ * reused / released when the callback completes.  dns_load_master will
+ * abort if callbacks->commit returns any value other than ISC_R_SUCCESS.
  *
  * If 'DNS_MASTER_AGETTL' is set and the master file contains one or more
  * $DATE directives, the TTLs of the data will be aged accordingly.
@@ -125,6 +145,7 @@ dns_master_loadbufferinc(isc_buffer_t *buffer,
  *
  * Requires:
  *     'master_file' points to a valid string.
+ *     'lexer' points to a valid lexer.
  *     'top' points to a valid name.
  *     'origin' points to a valid name.
  *     'callbacks->commit' points to a valid function.
index 036ea167688bc8208fae47c0b7e7054b0d0ce616..710754d0fc7a743710c25432941d3cea586176da 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: master.c,v 1.135 2002/02/20 03:34:12 marka Exp $ */
+/* $Id: master.c,v 1.136 2002/02/21 00:45:09 bwelling Exp $ */
 
 #include <config.h>
 
@@ -94,6 +94,7 @@ struct dns_loadctx {
        unsigned int            magic;
        isc_mem_t               *mctx;
        isc_lex_t               *lex;
+       isc_boolean_t           keep_lex;
        dns_rdatacallbacks_t    *callbacks;
        isc_task_t              *task;
        dns_loaddonefunc_t      done;
@@ -372,7 +373,7 @@ loadctx_destroy(dns_loadctx_t *lctx) {
                incctx_destroy(lctx->mctx, lctx->inc);
 
        /* isc_lex_destroy() will close all open streams */
-       if (lctx->lex != NULL)
+       if (lctx->lex != NULL && !lctx->keep_lex)
                isc_lex_destroy(&lctx->lex);
 
        if (lctx->task != NULL)
@@ -423,7 +424,7 @@ static isc_result_t
 loadctx_create(isc_mem_t *mctx, unsigned int options, dns_name_t *top,
               dns_rdataclass_t zclass, dns_name_t *origin,
               dns_rdatacallbacks_t *callbacks, isc_task_t *task,
-              dns_loaddonefunc_t done, void *done_arg,
+              dns_loaddonefunc_t done, void *done_arg, isc_lex_t *lex,
               dns_loadctx_t **lctxp)
 {
        dns_loadctx_t *lctx;
@@ -459,16 +460,20 @@ loadctx_create(isc_mem_t *mctx, unsigned int options, dns_name_t *top,
        if (result != ISC_R_SUCCESS) 
                goto cleanup_ctx;
 
-       lctx->lex = NULL;
-       result = isc_lex_create(mctx, TOKENSIZ, &lctx->lex);
-       if (result != ISC_R_SUCCESS)
-               goto cleanup_inc;
-       memset(specials, 0, sizeof(specials));
-       specials['('] = 1;
-       specials[')'] = 1;
-       specials['"'] = 1;
-       isc_lex_setspecials(lctx->lex, specials);
-       isc_lex_setcomments(lctx->lex, ISC_LEXCOMMENT_DNSMASTERFILE);
+       if (lex != NULL)
+               lctx->lex = lex;
+       else {
+               lctx->lex = NULL;
+               result = isc_lex_create(mctx, TOKENSIZ, &lctx->lex);
+               if (result != ISC_R_SUCCESS)
+                       goto cleanup_inc;
+               memset(specials, 0, sizeof(specials));
+               specials['('] = 1;
+               specials[')'] = 1;
+               specials['"'] = 1;
+               isc_lex_setspecials(lctx->lex, specials);
+               isc_lex_setcomments(lctx->lex, ISC_LEXCOMMENT_DNSMASTERFILE);
+       }
 
        lctx->ttl_known = ISC_FALSE;
        lctx->ttl = 0;
@@ -1706,7 +1711,7 @@ dns_master_loadfile(const char *master_file, dns_name_t *top,
        isc_result_t result;
 
        result = loadctx_create(mctx, options, top, zclass, origin,
-                               callbacks, NULL, NULL, NULL, &lctx);
+                               callbacks, NULL, NULL, NULL, NULL, &lctx);
        if (result != ISC_R_SUCCESS)
                return (result);
 
@@ -1737,7 +1742,7 @@ dns_master_loadfileinc(const char *master_file, dns_name_t *top,
        REQUIRE(done != NULL);
 
        result = loadctx_create(mctx, options, top, zclass, origin,
-                               callbacks, task, done, done_arg, &lctx);
+                               callbacks, task, done, done_arg, NULL, &lctx);
        if (result != ISC_R_SUCCESS)
                return (result);
 
@@ -1768,7 +1773,7 @@ dns_master_loadstream(FILE *stream, dns_name_t *top, dns_name_t *origin,
        REQUIRE(stream != NULL);
 
        result = loadctx_create(mctx, options, top, zclass, origin,
-                               callbacks, NULL, NULL, NULL, &lctx);
+                               callbacks, NULL, NULL, NULL, NULL, &lctx);
        if (result != ISC_R_SUCCESS)
                goto cleanup;
 
@@ -1800,7 +1805,7 @@ dns_master_loadstreaminc(FILE *stream, dns_name_t *top, dns_name_t *origin,
        REQUIRE(done != NULL);
 
        result = loadctx_create(mctx, options, top, zclass, origin,
-                               callbacks, task, done, done_arg, &lctx);
+                               callbacks, task, done, done_arg, NULL, &lctx);
        if (result != ISC_R_SUCCESS)
                goto cleanup;
 
@@ -1832,7 +1837,7 @@ dns_master_loadbuffer(isc_buffer_t *buffer, dns_name_t *top,
        REQUIRE(buffer != NULL);
 
        result = loadctx_create(mctx, options, top, zclass, origin,
-                               callbacks, NULL, NULL, NULL, &lctx);
+                               callbacks, NULL, NULL, NULL, NULL, &lctx);
        if (result != ISC_R_SUCCESS)
                return (result);
 
@@ -1865,7 +1870,7 @@ dns_master_loadbufferinc(isc_buffer_t *buffer, dns_name_t *top,
        REQUIRE(done != NULL);
 
        result = loadctx_create(mctx, options, top, zclass, origin,
-                               callbacks, task, done, done_arg, &lctx);
+                               callbacks, task, done, done_arg, NULL, &lctx);
        if (result != ISC_R_SUCCESS)
                return (result);
 
@@ -1885,6 +1890,59 @@ dns_master_loadbufferinc(isc_buffer_t *buffer, dns_name_t *top,
        return (result);
 }
 
+isc_result_t
+dns_master_loadlexer(isc_lex_t *lex, dns_name_t *top,
+                    dns_name_t *origin, dns_rdataclass_t zclass,
+                    unsigned int options,
+                    dns_rdatacallbacks_t *callbacks, isc_mem_t *mctx)
+{
+       isc_result_t result;
+       dns_loadctx_t *lctx = NULL;
+
+       REQUIRE(lex != NULL);
+
+       result = loadctx_create(mctx, options, top, zclass, origin,
+                               callbacks, NULL, NULL, NULL, lex, &lctx);
+       if (result != ISC_R_SUCCESS)
+               return (result);
+
+       result = load(lctx);
+       INSIST(result != DNS_R_CONTINUE);
+
+       dns_loadctx_detach(&lctx);
+       return (result);
+}
+
+isc_result_t
+dns_master_loadlexerinc(isc_lex_t *lex, dns_name_t *top,
+                       dns_name_t *origin, dns_rdataclass_t zclass,
+                       unsigned int options,
+                       dns_rdatacallbacks_t *callbacks, isc_task_t *task,
+                       dns_loaddonefunc_t done, void *done_arg,
+                       dns_loadctx_t **lctxp, isc_mem_t *mctx)
+{
+       isc_result_t result;
+       dns_loadctx_t *lctx = NULL;
+
+       REQUIRE(lex != NULL);
+       REQUIRE(task != NULL);
+       REQUIRE(done != NULL);
+
+       result = loadctx_create(mctx, options, top, zclass, origin,
+                               callbacks, task, done, done_arg, lex, &lctx);
+       if (result != ISC_R_SUCCESS)
+               return (result);
+
+       result = task_send(lctx);
+       if (result == ISC_R_SUCCESS) {
+               dns_loadctx_attach(lctx, lctxp);
+               return (DNS_R_CONTINUE);
+       }
+
+       dns_loadctx_detach(&lctx);
+       return (result);
+}
+
 /*
  * Grow the slab of dns_rdatalist_t structures.
  * Re-link glue and current list.