diff utils/themwi-update-numdb2.c @ 231:abb3f415b9dd

themwi-update-numdb2: check secondary numbers
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 11:45:41 -0800
parents 803829e6244f
children
line wrap: on
line diff
--- a/utils/themwi-update-numdb2.c	Mon Aug 14 11:09:35 2023 -0800
+++ b/utils/themwi-update-numdb2.c	Mon Aug 14 11:45:41 2023 -0800
@@ -446,6 +446,64 @@
 }
 
 static void
+check_secondnum_mapto(src)
+	struct owned_number_rec *src;
+{
+	struct owned_number_rec *dest;
+
+	dest = bsearch(src->remap, owned_number_buf, owned_number_count,
+			sizeof(struct owned_number_rec), compare_owned_num);
+	if (!dest) {
+		fprintf(stderr,
+	"error: NANP %03u-%03u-%04u map-to target is not in the database\n",
+			src->number[0], src->number[1], src->number[2]);
+		exit(1);
+	}
+	if ((dest->usage & NUMBER_USAGE_MASK) != NUMBER_USAGE_TYPE_GSM_SUB) {
+		fprintf(stderr,
+	"error: NANP %03u-%03u-%04u map-to target is not a gsm-sub number\n",
+			src->number[0], src->number[1], src->number[2]);
+		exit(1);
+	}
+}
+
+static void
+check_secondnum_e911via(src)
+	struct owned_number_rec *src;
+{
+	struct owned_number_rec *dest;
+
+	dest = bsearch(src->remap, owned_number_buf, owned_number_count,
+			sizeof(struct owned_number_rec), compare_owned_num);
+	if (!dest) {
+		fprintf(stderr,
+	"error: NANP %03u-%03u-%04u e911-via target is not in the database\n",
+			src->number[0], src->number[1], src->number[2]);
+		exit(1);
+	}
+	if (!(dest->number_flags & NUMBER_FLAG_E911PROV)) {
+		fprintf(stderr,
+	"error: NANP %03u-%03u-%04u e911-via target is not an E911 number\n",
+			src->number[0], src->number[1], src->number[2]);
+		exit(1);
+	}
+}
+
+static void
+check_secondary_numbers()
+{
+	struct owned_number_rec *p, *endp;
+
+	endp = owned_number_buf + owned_number_count;
+	for (p = owned_number_buf; p < endp; p++) {
+		if ((p->usage & NUMBER_USAGE_MASK) == NUMBER_USAGE_TYPE_ALIAS)
+			check_secondnum_mapto(p);
+		if (p->usage & NUMBER_USAGE_FLAG_E911_VIA)
+			check_secondnum_e911via(p);
+	}
+}
+
+static void
 emit_output()
 {
 	FILE *outf;
@@ -499,6 +557,7 @@
 			sizeof(owned_number_buf[0]), compare_owned_num);
 		owned_num_check_dup();
 	}
+	check_secondary_numbers();
 	if (short_number_count >= 2) {
 		qsort(short_number_buf, short_number_count,
 			sizeof(short_number_buf[0]), compare_short_num);