Harald Welte | 2c8bfe7 | 2018-06-15 22:04:28 +0200 | [diff] [blame^] | 1 | /* OsmoHLR VTY implementation */ |
| 2 | |
| 3 | /* (C) 2018 Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | #include <osmocom/core/talloc.h> |
| 24 | #include <stdint.h> |
| 25 | #include <string.h> |
| 26 | |
| 27 | #include "hlr.h" |
| 28 | #include "hlr_ussd.h" |
| 29 | |
| 30 | struct hlr_euse *euse_find(struct hlr *hlr, const char *name) |
| 31 | { |
| 32 | struct hlr_euse *euse; |
| 33 | |
| 34 | llist_for_each_entry(euse, &hlr->euse_list, list) { |
| 35 | if (!strcmp(euse->name, name)) |
| 36 | return euse; |
| 37 | } |
| 38 | return NULL; |
| 39 | } |
| 40 | |
| 41 | struct hlr_euse *euse_alloc(struct hlr *hlr, const char *name) |
| 42 | { |
| 43 | struct hlr_euse *euse = euse_find(hlr, name); |
| 44 | if (euse) |
| 45 | return NULL; |
| 46 | |
| 47 | euse = talloc_zero(hlr, struct hlr_euse); |
| 48 | euse->name = talloc_strdup(euse, name); |
| 49 | euse->hlr = hlr; |
| 50 | INIT_LLIST_HEAD(&euse->routes); |
| 51 | llist_add_tail(&euse->list, &hlr->euse_list); |
| 52 | |
| 53 | return euse; |
| 54 | } |
| 55 | |
| 56 | void euse_del(struct hlr_euse *euse) |
| 57 | { |
| 58 | llist_del(&euse->list); |
| 59 | talloc_free(euse); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | struct hlr_euse_route *euse_route_find(struct hlr_euse *euse, const char *prefix) |
| 64 | { |
| 65 | struct hlr_euse_route *rt; |
| 66 | |
| 67 | llist_for_each_entry(rt, &euse->routes, list) { |
| 68 | if (!strcmp(rt->prefix, prefix)) |
| 69 | return rt; |
| 70 | } |
| 71 | return NULL; |
| 72 | } |
| 73 | |
| 74 | struct hlr_euse_route *euse_route_prefix_alloc(struct hlr_euse *euse, const char *prefix) |
| 75 | { |
| 76 | struct hlr_euse_route *rt; |
| 77 | |
| 78 | if (euse_route_find(euse, prefix)) |
| 79 | return NULL; |
| 80 | |
| 81 | rt = talloc_zero(euse, struct hlr_euse_route); |
| 82 | rt->prefix = talloc_strdup(rt, prefix); |
| 83 | rt->euse = euse; |
| 84 | llist_add_tail(&rt->list, &euse->routes); |
| 85 | |
| 86 | return rt; |
| 87 | } |
| 88 | |
| 89 | void euse_route_del(struct hlr_euse_route *rt) |
| 90 | { |
| 91 | llist_del(&rt->list); |
| 92 | talloc_free(rt); |
| 93 | } |