2/2: fixup: add osmo_gsup_peer_id with type enum and union

During code review it was requested to insert an ability to handle different
kinds of peer id, in order to be able to add a Global Title in the future.

Add this, but only in the publicly visible API. For osmo-hlr internal code, I
intend to push implementing this into the future, when a different peer
identification actually gets introduced.

This way we don't need to implement it now in all osmo-hlr code paths (save
time now), but still make all API users aware that this type may be extended in
the future.

Change-Id: Ide9dcdca283ab989240cfc6e53e9211862a199c5
diff --git a/include/Makefile.am b/include/Makefile.am
index aeeb03f..cf95854 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,7 +1,7 @@
 SUBDIRS = osmocom
 
 nobase_include_HEADERS = \
-	osmocom/gsupclient/ipa_name.h \
+	osmocom/gsupclient/gsup_peer_id.h \
 	osmocom/gsupclient/gsup_client.h \
 	osmocom/gsupclient/gsup_req.h \
 	osmocom/mslookup/mdns.h \
diff --git a/include/osmocom/gsupclient/gsup_peer_id.h b/include/osmocom/gsupclient/gsup_peer_id.h
new file mode 100644
index 0000000..f67671b
--- /dev/null
+++ b/include/osmocom/gsupclient/gsup_peer_id.h
@@ -0,0 +1,64 @@
+/* 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 General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+#include <unistd.h>
+#include <stdint.h>
+#include <osmocom/core/utils.h>
+
+/*! IPA Name: Arbitrary length blob, not necessarily zero-terminated.
+ * In osmo-hlr, struct hlr_subscriber is mostly used as static reference and cannot serve as talloc context, which is
+ * why this is also implemented as a fixed-maximum-size buffer instead of a talloc'd arbitrary sized buffer.
+ * NOTE: The length of val may be extended in the future if it becomes necessary.
+ * At the time of writing, this holds IPA unit name strings of very limited length.
+ */
+struct osmo_ipa_name {
+	size_t len;
+	uint8_t val[128];
+};
+
+bool osmo_ipa_name_is_empty(struct osmo_ipa_name *ipa_name);
+int osmo_ipa_name_set(struct osmo_ipa_name *ipa_name, const uint8_t *val, size_t len);
+int osmo_ipa_name_set_str(struct osmo_ipa_name *ipa_name, const char *str_fmt, ...);
+int osmo_ipa_name_cmp(const struct osmo_ipa_name *a, const struct osmo_ipa_name *b);
+const char *osmo_ipa_name_to_str(const struct osmo_ipa_name *ipa_name);
+
+enum osmo_gsup_peer_id_type {
+	OSMO_GSUP_PEER_ID_EMPTY=0,
+	OSMO_GSUP_PEER_ID_IPA_NAME,
+	/* OSMO_GSUP_PEER_ID_GLOBAL_TITLE, <-- currently not implemented, but likely future possibility */
+};
+
+extern const struct value_string osmo_gsup_peer_id_type_names[];
+static inline const char *osmo_gsup_peer_id_type_name(enum osmo_gsup_peer_id_type val)
+{ return get_value_string(osmo_gsup_peer_id_type_names, val); }
+
+struct osmo_gsup_peer_id {
+	enum osmo_gsup_peer_id_type type;
+	union {
+		struct osmo_ipa_name ipa_name;
+	};
+};
+
+bool osmo_gsup_peer_id_is_empty(struct osmo_gsup_peer_id *gsup_peer_id);
+int osmo_gsup_peer_id_set(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
+			  const uint8_t *val, size_t len);
+int osmo_gsup_peer_id_set_str(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
+			      const char *str_fmt, ...);
+int osmo_gsup_peer_id_cmp(const struct osmo_gsup_peer_id *a, const struct osmo_gsup_peer_id *b);
+const char *osmo_gsup_peer_id_to_str(const struct osmo_gsup_peer_id *gsup_peer_id);
diff --git a/include/osmocom/gsupclient/gsup_req.h b/include/osmocom/gsupclient/gsup_req.h
index 09959f0..a8d74f5 100644
--- a/include/osmocom/gsupclient/gsup_req.h
+++ b/include/osmocom/gsupclient/gsup_req.h
@@ -19,14 +19,14 @@
 #pragma once
 
 #include <osmocom/gsm/gsup.h>
-#include <osmocom/gsupclient/ipa_name.h>
+#include <osmocom/gsupclient/gsup_peer_id.h>
 
 struct osmo_gsup_req;
 
 #define LOG_GSUP_REQ_CAT_SRC(req, subsys, level, file, line, fmt, args...) \
 	LOGPSRC(subsys, level, file, line, "GSUP %u: %s: IMSI-%s %s: " fmt, \
 		(req) ? (req)->nr : 0, \
-		(req) ? osmo_ipa_name_to_str(&(req)->source_name) : "NULL", \
+		(req) ? osmo_gsup_peer_id_to_str(&(req)->source_name) : "NULL", \
 		(req) ? (req)->gsup.imsi : "NULL", \
 		(req) ? osmo_gsup_message_type_name((req)->gsup.message_type) : "NULL", \
 		##args)
@@ -56,11 +56,11 @@
 	/* The ultimate source of this message: the source_name form the GSUP message, or, if not present, then the
 	 * immediate GSUP peer. GSUP messages going via a proxy reflect the initial source in the source_name.
 	 * This source_name is implicitly added to the routes for the conn the message was received on. */
-	struct osmo_ipa_name source_name;
+	struct osmo_gsup_peer_id source_name;
 
 	/* If the source_name is not an immediate GSUP peer, this is set to the closest intermediate peer between here
 	 * and source_name. */
-	struct osmo_ipa_name via_proxy;
+	struct osmo_gsup_peer_id via_proxy;
 
 	/* Identify this request by number, for logging. */
 	unsigned int nr;
@@ -82,7 +82,7 @@
 	struct msgb *msg;
 };
 
-struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_ipa_name *from_peer, struct msgb *msg,
+struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_gsup_peer_id *from_peer, struct msgb *msg,
 					osmo_gsup_req_send_response_t send_response_cb, void *cb_data,
 					struct llist_head *add_to_list);
 void osmo_gsup_req_free(struct osmo_gsup_req *req);
diff --git a/include/osmocom/gsupclient/ipa_name.h b/include/osmocom/gsupclient/ipa_name.h
deleted file mode 100644
index 5016f48..0000000
--- a/include/osmocom/gsupclient/ipa_name.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* 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 General Public License as published by
- * the Free Software Foundation; either version 2 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-#include <unistd.h>
-#include <stdint.h>
-
-/*! IPA Name: Arbitrary length blob, not necessarily zero-terminated.
- * In osmo-hlr, struct hlr_subscriber is mostly used as static reference and cannot serve as talloc context, which is
- * why this is also implemented as a fixed-maximum-size buffer instead of a talloc'd arbitrary sized buffer.
- * NOTE: The length of val may be extended in the future if it becomes necessary.
- * At the time of writing, this holds IPA unit name strings of very limited length.
- */
-struct osmo_ipa_name {
-	size_t len;
-	uint8_t val[128];
-};
-
-int osmo_ipa_name_set(struct osmo_ipa_name *ipa_name, const uint8_t *val, size_t len);
-int osmo_ipa_name_set_str(struct osmo_ipa_name *ipa_name, const char *str_fmt, ...);
-int osmo_ipa_name_cmp(const struct osmo_ipa_name *a, const struct osmo_ipa_name *b);
-const char *osmo_ipa_name_to_str(const struct osmo_ipa_name *ipa_name);
diff --git a/include/osmocom/hlr/db.h b/include/osmocom/hlr/db.h
index 5c627be..02ab7e2 100644
--- a/include/osmocom/hlr/db.h
+++ b/include/osmocom/hlr/db.h
@@ -3,7 +3,7 @@
 #include <stdbool.h>
 #include <sqlite3.h>
 
-#include <osmocom/gsupclient/ipa_name.h>
+#include <osmocom/gsupclient/gsup_peer_id.h>
 
 struct hlr;
 
diff --git a/include/osmocom/hlr/gsup_server.h b/include/osmocom/hlr/gsup_server.h
index 149971a..0ecf42c 100644
--- a/include/osmocom/hlr/gsup_server.h
+++ b/include/osmocom/hlr/gsup_server.h
@@ -5,7 +5,7 @@
 #include <osmocom/abis/ipa.h>
 #include <osmocom/abis/ipaccess.h>
 #include <osmocom/gsm/gsup.h>
-#include <osmocom/gsupclient/ipa_name.h>
+#include <osmocom/gsupclient/gsup_peer_id.h>
 #include <osmocom/gsupclient/gsup_req.h>
 
 #ifndef OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN