#include #include #include #include #include #include #include #include #include #include #include isc_log_t *logc = NULL; static void output(void *closure, const char *text, int textlen) { UNUSED(closure); if (fwrite(text, 1, textlen, stdout) != (size_t)textlen) { perror("fwrite"); exit(1); } } /* * This needs to match the list in bin/named/log.c. */ static isc_logcategory_t categories[] = { { "", 0 }, { "client", 0 }, { "network", 0 }, { "update", 0 }, { "queries", 0 }, { "unmatched", 0 }, { "update-security", 0 }, { "query-errors", 0 }, { NULL, 0 } }; isc_result_t setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) { isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; isc_log_t *log = NULL; RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS); isc_log_registercategories(log, categories); isc_log_setcontext(log); dns_log_init(log); dns_log_setcontext(log); cfg_log_init(log); destination.file.stream = errout; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; RUNTIME_CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, 0) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) == ISC_R_SUCCESS); *logp = log; return (ISC_R_SUCCESS); } int main(int argc, char **argv) { int c; cfg_parser_t *parser = NULL; isc_buffer_t inbuffer; const cfg_type_t *type = NULL; cfg_obj_t *config = NULL; isc_mem_t *mctx = NULL; isc_result_t result; const char cfg_text[] = " " "/* xxx */" "ldap xxxxxx;" ""; static cfg_clausedef_t dyndb_ldap_conf_clauses[] = { { "ldap", &cfg_type_sstring, 0 }, { NULL, NULL, 0 } }; static cfg_clausedef_t * dyndb_ldap_clausulesets[] = { dyndb_ldap_conf_clauses, NULL }; cfg_type_t cfg_type_namedconf = { "dyndb_ldap_conf", cfg_parse_mapbody, cfg_print_mapbody, cfg_doc_mapbody, &cfg_rep_map, dyndb_ldap_clausulesets }; isc_buffer_constinit(&inbuffer, cfg_text, sizeof(cfg_text)); isc_buffer_add(&inbuffer, sizeof(cfg_text) - 1); RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); RUNTIME_CHECK(setup_logging(mctx, stdout, &logc) == ISC_R_SUCCESS); RUNTIME_CHECK(cfg_parser_create(mctx, logc, &parser) == ISC_R_SUCCESS); // I had to open biffer explicitly to make parser->lexer->sources list is non-empty RUNTIME_CHECK(isc_lex_openbuffer(parser->lexer, &inbuffer) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_lex_setsourcename(parser->lexer, "test.c") == ISC_R_SUCCESS); RUNTIME_CHECK(isc_lex_setsourceline(parser->lexer, 324) == ISC_R_SUCCESS); // this blows up for reasons which are unclear to me result = cfg_parse_buffer2(parser, &inbuffer, "built-in", &cfg_type_namedconf, &config); if (result == ISC_R_SUCCESS) { cfg_printx(config, CFG_PRINTER_XKEY, output, NULL); printf("file = %s\n", cfg_obj_file(config)); printf("line = %d\n", cfg_obj_line(config)); cfg_obj_log(config, logc, ISC_LOG_ERROR, "blabla"); cfg_obj_destroy(parser, &config); } }