add libosmo-mslookup abstract client

mslookup is a key concept in Distributed GSM, which allows querying the current
location of a subscriber in a number of cooperating but independent core
network sites, by arbitrary service names and by MSISDN/IMSI.

Add the abstract mslookup client library. An actual lookup method (besides
mslookup_client_fake.c) is added in a subsequent patch.

For a detailed overview of this and upcoming patches, please see the elaborate
comment at the top of mslookup.c.

Add as separate library, libosmo-mslookup, to allow adding D-GSM capability to
arbitrary client programs.

osmo-hlr will be the only mslookup server implementation, added in a subsequent
patch.

osmo-hlr itself will also use this library and act as an mslookup client, when
requesting the home HLR for locally unknown IMSIs.

Related: OS#4237
Patch-by: osmith, nhofmeyr
Change-Id: I83487ab8aad1611eb02e997dafbcb8344da13df1
diff --git a/tests/mslookup/mslookup_test.c b/tests/mslookup/mslookup_test.c
new file mode 100644
index 0000000..1672bd0
--- /dev/null
+++ b/tests/mslookup/mslookup_test.c
@@ -0,0 +1,88 @@
+/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <string.h>
+#include <osmocom/core/application.h>
+#include <osmocom/core/select.h>
+#include <osmocom/hlr/logging.h>
+#include <osmocom/mslookup/mslookup_client.h>
+
+void *ctx;
+
+const char *domains[] = {
+	"gsup.hlr.123456789012345.imsi",
+	"gsup.hlr.1.imsi",
+	"sip.voice.1.msisdn",
+	"a.b.c.imsi",
+	"",
+	".",
+	"...",
+	".....",
+	".....1.msisdn",
+	"fofdndsf. d.ads ofdsf. ads.kj.1243455132.msisdn",
+	"foo.12345678901234567890.imsi",
+	"gsup.hlr.123456789012345.what",
+	NULL,
+	"blarg",
+	"blarg.",
+	"blarg.1.",
+	"blarg.1.msisdn",
+	"blarg.1.msisdn.",
+	".1.msisdn",
+	"1.msisdn",
+	"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmm.1.msisdn",
+	"qwerty.1.qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmm",
+};
+
+void test_osmo_mslookup_query_init_from_domain_str()
+{
+	int i;
+	for (i = 0; i < ARRAY_SIZE(domains); i++) {
+		const char *d = domains[i];
+		struct osmo_mslookup_query q;
+
+		int rc = osmo_mslookup_query_init_from_domain_str(&q, d);
+		if (rc)
+			fprintf(stderr, "%s -> rc = %d\n", osmo_quote_str(d, -1), rc);
+		else
+			fprintf(stderr, "%s -> %s %s %s\n", osmo_quote_str(d, -1),
+			       osmo_quote_str_c(ctx, q.service, -1),
+			       osmo_quote_str_c(ctx, q.id.imsi, -1),
+			       osmo_mslookup_id_type_name(q.id.type));
+	}
+}
+
+int main()
+{
+	ctx = talloc_named_const(NULL, 0, "main");
+	osmo_init_logging2(ctx, NULL);
+
+	log_set_print_filename(osmo_stderr_target, 0);
+	log_set_print_level(osmo_stderr_target, 0);
+	log_set_print_category(osmo_stderr_target, 0);
+	log_set_print_category_hex(osmo_stderr_target, 0);
+	log_set_use_color(osmo_stderr_target, 0);
+	log_set_category_filter(osmo_stderr_target, DMSLOOKUP, true, LOGL_DEBUG);
+
+	test_osmo_mslookup_query_init_from_domain_str();
+
+	talloc_free(ctx);
+
+	return 0;
+}