Mychaela N. Falconia | ff7c7ea | 2023-09-21 01:55:51 +0000 | [diff] [blame^] | 1 | /* OsmoHLR SMS-over-GSUP routing implementation */ |
| 2 | |
| 3 | /* Author: Mychaela N. Falconia <falcon@freecalypso.org>, 2023 - however, |
| 4 | * Mother Mychaela's contributions are NOT subject to copyright. |
| 5 | * No rights reserved, all rights relinquished. |
| 6 | * |
| 7 | * Based on earlier unmerged work by Vadim Yanitskiy, 2019. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU Affero General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
| 22 | |
| 23 | #include <stdint.h> |
| 24 | #include <string.h> |
| 25 | #include <errno.h> |
| 26 | |
| 27 | #include <osmocom/core/talloc.h> |
| 28 | #include <osmocom/gsm/gsup.h> |
| 29 | |
| 30 | #include <osmocom/hlr/hlr.h> |
| 31 | #include <osmocom/hlr/hlr_sms.h> |
| 32 | #include <osmocom/hlr/gsup_server.h> |
| 33 | #include <osmocom/hlr/gsup_router.h> |
| 34 | #include <osmocom/hlr/logging.h> |
| 35 | #include <osmocom/hlr/db.h> |
| 36 | |
| 37 | /*********************************************************************** |
| 38 | * core data structures expressing config from VTY |
| 39 | ***********************************************************************/ |
| 40 | |
| 41 | struct hlr_smsc *smsc_find(struct hlr *hlr, const char *name) |
| 42 | { |
| 43 | struct hlr_smsc *smsc; |
| 44 | |
| 45 | llist_for_each_entry(smsc, &hlr->smsc_list, list) { |
| 46 | if (!strcmp(smsc->name, name)) |
| 47 | return smsc; |
| 48 | } |
| 49 | return NULL; |
| 50 | } |
| 51 | |
| 52 | struct hlr_smsc *smsc_alloc(struct hlr *hlr, const char *name) |
| 53 | { |
| 54 | struct hlr_smsc *smsc = smsc_find(hlr, name); |
| 55 | if (smsc) |
| 56 | return NULL; |
| 57 | |
| 58 | smsc = talloc_zero(hlr, struct hlr_smsc); |
| 59 | smsc->name = talloc_strdup(smsc, name); |
| 60 | smsc->hlr = hlr; |
| 61 | llist_add_tail(&smsc->list, &hlr->smsc_list); |
| 62 | |
| 63 | return smsc; |
| 64 | } |
| 65 | |
| 66 | void smsc_free(struct hlr_smsc *smsc) |
| 67 | { |
| 68 | llist_del(&smsc->list); |
| 69 | talloc_free(smsc); |
| 70 | } |
| 71 | |
| 72 | struct hlr_smsc_route *smsc_route_find(struct hlr *hlr, const char *num_addr) |
| 73 | { |
| 74 | struct hlr_smsc_route *rt; |
| 75 | |
| 76 | llist_for_each_entry(rt, &hlr->smsc_routes, list) { |
| 77 | if (!strcmp(rt->num_addr, num_addr)) |
| 78 | return rt; |
| 79 | } |
| 80 | return NULL; |
| 81 | } |
| 82 | |
| 83 | struct hlr_smsc_route *smsc_route_alloc(struct hlr *hlr, const char *num_addr, |
| 84 | struct hlr_smsc *smsc) |
| 85 | { |
| 86 | struct hlr_smsc_route *rt; |
| 87 | |
| 88 | if (smsc_route_find(hlr, num_addr)) |
| 89 | return NULL; |
| 90 | |
| 91 | rt = talloc_zero(hlr, struct hlr_smsc_route); |
| 92 | rt->num_addr = talloc_strdup(rt, num_addr); |
| 93 | rt->smsc = smsc; |
| 94 | llist_add_tail(&rt->list, &hlr->smsc_routes); |
| 95 | |
| 96 | return rt; |
| 97 | } |
| 98 | |
| 99 | void smsc_route_free(struct hlr_smsc_route *rt) |
| 100 | { |
| 101 | llist_del(&rt->list); |
| 102 | talloc_free(rt); |
| 103 | } |