]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
move geoip to parser.c
authorMark Andrews <marka@isc.org>
Fri, 7 Dec 2018 01:50:03 +0000 (12:50 +1100)
committerMark Andrews <marka@isc.org>
Fri, 7 Dec 2018 01:50:03 +0000 (12:50 +1100)
lib/isccfg/namedconf.c
lib/isccfg/parser.c

index e94b0178e3221df593b078058d5117fc257a6823..bb306f98c933e434cfcc447a2b625d1fda74932a 100644 (file)
@@ -74,17 +74,6 @@ doc_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type);
 static void
 doc_optional_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type);
 
-#ifdef HAVE_GEOIP
-static isc_result_t
-parse_geoip(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
-
-static void
-print_geoip(cfg_printer_t *pctx, const cfg_obj_t *obj);
-
-static void
-doc_geoip(cfg_printer_t *pctx, const cfg_type_t *type);
-#endif /* HAVE_GEOIP */
-
 static cfg_type_t cfg_type_acl;
 static cfg_type_t cfg_type_bracketed_dscpsockaddrlist;
 static cfg_type_t cfg_type_bracketed_namesockaddrkeylist;
@@ -2919,102 +2908,6 @@ static cfg_type_t cfg_type_qminmethod = {
        &cfg_rep_string, qminmethod_enums
 };
 
-#ifdef HAVE_GEOIP
-/*
- * "geoip" ACL element:
- * geoip [ db <database> ] search-type <string>
- */
-static const char *geoiptype_enums[] = {
-       "area", "areacode", "asnum", "city", "continent", "country",
-       "country3", "countryname", "domain", "isp", "metro", "metrocode",
-       "netspeed", "org", "postal", "postalcode", "region", "regionname",
-       "timezone", "tz", NULL
-};
-static cfg_type_t cfg_type_geoiptype = {
-       "geoiptype", cfg_parse_enum, cfg_print_ustring,
-       cfg_doc_enum, &cfg_rep_string, &geoiptype_enums
-};
-
-static const char *geoipdb_enums[] = {
-       "asnum", "city", "country", "domain", "isp", "netspeed",
-       "org", "region", NULL
-};
-static cfg_type_t cfg_type_geoipdb = {
-       "geoipdb", cfg_parse_enum, cfg_print_ustring,
-       cfg_doc_enum, &cfg_rep_string, &geoipdb_enums
-};
-
-static cfg_tuplefielddef_t geoip_fields[] = {
-       { "negated", &cfg_type_void, 0 },
-       { "db", &cfg_type_geoipdb, 0 },
-       { "subtype", &cfg_type_geoiptype, 0 },
-       { "search", &cfg_type_astring, 0 },
-       { NULL, NULL, 0 }
-};
-
-static cfg_type_t cfg_type_geoip = {
-       "geoip", parse_geoip, print_geoip, doc_geoip,
-       &cfg_rep_tuple, geoip_fields
-};
-
-static isc_result_t
-parse_geoip(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
-       isc_result_t result;
-       cfg_obj_t *obj = NULL;
-       const cfg_tuplefielddef_t *fields = type->of;
-
-       CHECK(cfg_create_tuple(pctx, type, &obj));
-       CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[0]));
-
-       /* Parse the optional "db" field. */
-       CHECK(cfg_peektoken(pctx, 0));
-       if (pctx->token.type == isc_tokentype_string) {
-               CHECK(cfg_gettoken(pctx, 0));
-               if (strcasecmp(TOKEN_STRING(pctx), "db") == 0 &&
-                   obj->value.tuple[1] == NULL) {
-                       CHECK(cfg_parse_obj(pctx, fields[1].type,
-                                   &obj->value.tuple[1]));
-               } else {
-                       CHECK(cfg_parse_void(pctx, NULL,
-                                            &obj->value.tuple[1]));
-                       cfg_ungettoken(pctx);
-               }
-       }
-
-       CHECK(cfg_parse_obj(pctx, fields[2].type, &obj->value.tuple[2]));
-       CHECK(cfg_parse_obj(pctx, fields[3].type, &obj->value.tuple[3]));
-
-       *ret = obj;
-       return (ISC_R_SUCCESS);
-
- cleanup:
-       CLEANUP_OBJ(obj);
-       return (result);
-}
-
-static void
-print_geoip(cfg_printer_t *pctx, const cfg_obj_t *obj) {
-       if (obj->value.tuple[1]->type->print != cfg_print_void) {
-               cfg_print_cstr(pctx, " db ");
-               cfg_print_obj(pctx, obj->value.tuple[1]);
-       }
-       cfg_print_obj(pctx, obj->value.tuple[2]);
-       cfg_print_obj(pctx, obj->value.tuple[3]);
-}
-
-static void
-doc_geoip(cfg_printer_t *pctx, const cfg_type_t *type) {
-       UNUSED(type);
-       cfg_print_cstr(pctx, "[ db ");
-       cfg_doc_enum(pctx, &cfg_type_geoipdb);
-       cfg_print_cstr(pctx, " ]");
-       cfg_print_cstr(pctx, " ");
-       cfg_doc_enum(pctx, &cfg_type_geoiptype);
-       cfg_print_cstr(pctx, " ");
-       cfg_print_cstr(pctx, "<quoted_string>");
-}
-#endif /* HAVE_GEOIP */
-
 /*%
  * A "controls" statement is represented as a map with the multivalued
  * "inet" and "unix" clauses.
index 07341bf725fee5f4c05994ffe1aa61075be315d6..431a49288f5d686ce7af49fc4f5cdb188909359a 100644 (file)
@@ -102,6 +102,17 @@ static void
 parser_complain(cfg_parser_t *pctx, bool is_warning,
                unsigned int flags, const char *format, va_list args);
 
+#ifdef HAVE_GEOIP
+static isc_result_t
+parse_geoip(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
+
+static void
+print_geoip(cfg_printer_t *pctx, const cfg_obj_t *obj);
+
+static void
+doc_geoip(cfg_printer_t *pctx, const cfg_type_t *type);
+#endif /* HAVE_GEOIP */
+
 /*
  * Data representations.  These correspond to members of the
  * "value" union in struct cfg_obj (except "void", which does
@@ -1326,6 +1337,102 @@ LIBISCCFG_EXTERNAL_DATA cfg_type_t cfg_type_bracketed_text = {
        &cfg_rep_string, NULL
 };
 
+#ifdef HAVE_GEOIP
+/*
+ * "geoip" ACL element:
+ * geoip [ db <database> ] search-type <string>
+ */
+static const char *geoiptype_enums[] = {
+       "area", "areacode", "asnum", "city", "continent", "country",
+       "country3", "countryname", "domain", "isp", "metro", "metrocode",
+       "netspeed", "org", "postal", "postalcode", "region", "regionname",
+       "timezone", "tz", NULL
+};
+static cfg_type_t cfg_type_geoiptype = {
+       "geoiptype", cfg_parse_enum, cfg_print_ustring,
+       cfg_doc_enum, &cfg_rep_string, &geoiptype_enums
+};
+
+static const char *geoipdb_enums[] = {
+       "asnum", "city", "country", "domain", "isp", "netspeed",
+       "org", "region", NULL
+};
+static cfg_type_t cfg_type_geoipdb = {
+       "geoipdb", cfg_parse_enum, cfg_print_ustring,
+       cfg_doc_enum, &cfg_rep_string, &geoipdb_enums
+};
+
+static cfg_tuplefielddef_t geoip_fields[] = {
+       { "negated", &cfg_type_void, 0 },
+       { "db", &cfg_type_geoipdb, 0 },
+       { "subtype", &cfg_type_geoiptype, 0 },
+       { "search", &cfg_type_astring, 0 },
+       { NULL, NULL, 0 }
+};
+
+static cfg_type_t cfg_type_geoip = {
+       "geoip", parse_geoip, print_geoip, doc_geoip,
+       &cfg_rep_tuple, geoip_fields
+};
+
+static isc_result_t
+parse_geoip(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
+       isc_result_t result;
+       cfg_obj_t *obj = NULL;
+       const cfg_tuplefielddef_t *fields = type->of;
+
+       CHECK(cfg_create_tuple(pctx, type, &obj));
+       CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[0]));
+
+       /* Parse the optional "db" field. */
+       CHECK(cfg_peektoken(pctx, 0));
+       if (pctx->token.type == isc_tokentype_string) {
+               CHECK(cfg_gettoken(pctx, 0));
+               if (strcasecmp(TOKEN_STRING(pctx), "db") == 0 &&
+                   obj->value.tuple[1] == NULL) {
+                       CHECK(cfg_parse_obj(pctx, fields[1].type,
+                                   &obj->value.tuple[1]));
+               } else {
+                       CHECK(cfg_parse_void(pctx, NULL,
+                                            &obj->value.tuple[1]));
+                       cfg_ungettoken(pctx);
+               }
+       }
+
+       CHECK(cfg_parse_obj(pctx, fields[2].type, &obj->value.tuple[2]));
+       CHECK(cfg_parse_obj(pctx, fields[3].type, &obj->value.tuple[3]));
+
+       *ret = obj;
+       return (ISC_R_SUCCESS);
+
+ cleanup:
+       CLEANUP_OBJ(obj);
+       return (result);
+}
+
+static void
+print_geoip(cfg_printer_t *pctx, const cfg_obj_t *obj) {
+       if (obj->value.tuple[1]->type->print != cfg_print_void) {
+               cfg_print_cstr(pctx, " db ");
+               cfg_print_obj(pctx, obj->value.tuple[1]);
+       }
+       cfg_print_obj(pctx, obj->value.tuple[2]);
+       cfg_print_obj(pctx, obj->value.tuple[3]);
+}
+
+static void
+doc_geoip(cfg_printer_t *pctx, const cfg_type_t *type) {
+       UNUSED(type);
+       cfg_print_cstr(pctx, "[ db ");
+       cfg_doc_enum(pctx, &cfg_type_geoipdb);
+       cfg_print_cstr(pctx, " ]");
+       cfg_print_cstr(pctx, " ");
+       cfg_doc_enum(pctx, &cfg_type_geoiptype);
+       cfg_print_cstr(pctx, " ");
+       cfg_print_cstr(pctx, "<quoted_string>");
+}
+#endif /* HAVE_GEOIP */
+
 static cfg_type_t cfg_type_addrmatchelt;
 static cfg_type_t cfg_type_negated;