Neels Hofmeyr | 0d28d85 | 2019-12-04 01:04:32 +0100 | [diff] [blame] | 1 | /* 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 | */ |
| 30 | struct osmo_ipa_name { |
| 31 | size_t len; |
| 32 | uint8_t val[128]; |
| 33 | }; |
| 34 | |
| 35 | bool osmo_ipa_name_is_empty(struct osmo_ipa_name *ipa_name); |
| 36 | int osmo_ipa_name_set(struct osmo_ipa_name *ipa_name, const uint8_t *val, size_t len); |
| 37 | int osmo_ipa_name_set_str(struct osmo_ipa_name *ipa_name, const char *str_fmt, ...); |
| 38 | int osmo_ipa_name_cmp(const struct osmo_ipa_name *a, const struct osmo_ipa_name *b); |
| 39 | const char *osmo_ipa_name_to_str_c(void *ctx, const struct osmo_ipa_name *ipa_name); |
| 40 | const char *osmo_ipa_name_to_str(const struct osmo_ipa_name *ipa_name); |
| 41 | |
| 42 | enum osmo_gsup_peer_id_type { |
| 43 | OSMO_GSUP_PEER_ID_EMPTY=0, |
| 44 | OSMO_GSUP_PEER_ID_IPA_NAME, |
| 45 | /* OSMO_GSUP_PEER_ID_GLOBAL_TITLE, <-- currently not implemented, but likely future possibility */ |
| 46 | }; |
| 47 | |
| 48 | extern const struct value_string osmo_gsup_peer_id_type_names[]; |
| 49 | static inline const char *osmo_gsup_peer_id_type_name(enum osmo_gsup_peer_id_type val) |
| 50 | { return get_value_string(osmo_gsup_peer_id_type_names, val); } |
| 51 | |
| 52 | struct osmo_gsup_peer_id { |
| 53 | enum osmo_gsup_peer_id_type type; |
| 54 | union { |
| 55 | struct osmo_ipa_name ipa_name; |
| 56 | }; |
| 57 | }; |
| 58 | |
| 59 | bool osmo_gsup_peer_id_is_empty(struct osmo_gsup_peer_id *gsup_peer_id); |
| 60 | int osmo_gsup_peer_id_set(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type, |
| 61 | const uint8_t *val, size_t len); |
| 62 | int osmo_gsup_peer_id_set_str(struct osmo_gsup_peer_id *gsup_peer_id, enum osmo_gsup_peer_id_type type, |
| 63 | const char *str_fmt, ...); |
| 64 | int osmo_gsup_peer_id_cmp(const struct osmo_gsup_peer_id *a, const struct osmo_gsup_peer_id *b); |
| 65 | const char *osmo_gsup_peer_id_to_str(const struct osmo_gsup_peer_id *gsup_peer_id); |
| 66 | const char *osmo_gsup_peer_id_to_str_c(void *ctx, const struct osmo_gsup_peer_id *gsup_peer_id); |