blob: f67671b3d32e312288833d16d31a49d326e166cb [file] [log] [blame]
Neels Hofmeyr008ce4b2019-12-04 01:04:32 +01001/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
2 *
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20#include <unistd.h>
21#include <stdint.h>
22#include <osmocom/core/utils.h>
23
24/*! IPA Name: Arbitrary length blob, not necessarily zero-terminated.
25 * In osmo-hlr, struct hlr_subscriber is mostly used as static reference and cannot serve as talloc context, which is
26 * why this is also implemented as a fixed-maximum-size buffer instead of a talloc'd arbitrary sized buffer.
27 * NOTE: The length of val may be extended in the future if it becomes necessary.
28 * At the time of writing, this holds IPA unit name strings of very limited length.
29 */
30struct osmo_ipa_name {
31 size_t len;
32 uint8_t val[128];
33};
34
35bool osmo_ipa_name_is_empty(struct osmo_ipa_name *ipa_name);
36int osmo_ipa_name_set(struct osmo_ipa_name *ipa_name, const uint8_t *val, size_t len);
37int osmo_ipa_name_set_str(struct osmo_ipa_name *ipa_name, const char *str_fmt, ...);
38int osmo_ipa_name_cmp(const struct osmo_ipa_name *a, const struct osmo_ipa_name *b);
39const char *osmo_ipa_name_to_str(const struct osmo_ipa_name *ipa_name);
40
41enum osmo_gsup_peer_id_type {
42 OSMO_GSUP_PEER_ID_EMPTY=0,
43 OSMO_GSUP_PEER_ID_IPA_NAME,
44 /* OSMO_GSUP_PEER_ID_GLOBAL_TITLE, <-- currently not implemented, but likely future possibility */
45};
46
47extern const struct value_string osmo_gsup_peer_id_type_names[];
48static inline const char *osmo_gsup_peer_id_type_name(enum osmo_gsup_peer_id_type val)
49{ return get_value_string(osmo_gsup_peer_id_type_names, val); }
50
51struct osmo_gsup_peer_id {
52 enum osmo_gsup_peer_id_type type;
53 union {
54 struct osmo_ipa_name ipa_name;
55 };
56};
57
58bool osmo_gsup_peer_id_is_empty(struct osmo_gsup_peer_id *gsup_peer_id);
59int osmo_gsup_peer_id_set(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
60 const uint8_t *val, size_t len);
61int osmo_gsup_peer_id_set_str(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type,
62 const char *str_fmt, ...);
63int osmo_gsup_peer_id_cmp(const struct osmo_gsup_peer_id *a, const struct osmo_gsup_peer_id *b);
64const char *osmo_gsup_peer_id_to_str(const struct osmo_gsup_peer_id *gsup_peer_id);