Holger Hans Peter Freyther | f8c4219 | 2013-01-09 17:03:27 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * (C) 2013 by Holger Hans Peter Freyther |
| 3 | * (C) 2013 by sysmocom s.f.m.c. GmbH |
| 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 | #include <openbsc/control_cmd.h> |
| 23 | #include <openbsc/gsm_data.h> |
| 24 | |
| 25 | #define CTRL_CMD_VTY_STRING(cmdname, cmdstr, dtype, element) \ |
| 26 | CTRL_HELPER_GET_STRING(cmdname, dtype, element) \ |
| 27 | CTRL_HELPER_SET_STRING(cmdname, dtype, element) \ |
| 28 | static struct ctrl_cmd_element cmd_##cmdname = { \ |
| 29 | .name = cmdstr, \ |
| 30 | .param = NULL, \ |
| 31 | .get = get_##cmdname, \ |
| 32 | .set = set_##cmdname, \ |
| 33 | .verify = verify_vty_description_string, \ |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Check that there are no newlines or comments or other things |
| 38 | * that could make the VTY configuration unparsable. |
| 39 | */ |
| 40 | static int verify_vty_description_string(struct ctrl_cmd *cmd, |
| 41 | const char *value, void *data) |
| 42 | { |
| 43 | int i; |
| 44 | const size_t len = strlen(value); |
| 45 | |
| 46 | for (i = 0; i < len; ++i) { |
| 47 | switch(value[i]) { |
| 48 | case '#': |
| 49 | case '\n': |
| 50 | case '\r': |
| 51 | cmd->reply = "String includes illegal character"; |
| 52 | return -1; |
| 53 | default: |
| 54 | break; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | CTRL_CMD_DEFINE_RANGE(net_mnc, "mnc", struct gsm_network, network_code, 0, 999); |
| 62 | CTRL_CMD_DEFINE_RANGE(net_mcc, "mcc", struct gsm_network, country_code, 1, 999); |
| 63 | CTRL_CMD_VTY_STRING(net_short_name, "short-name", struct gsm_network, name_short); |
| 64 | CTRL_CMD_VTY_STRING(net_long_name, "long-name", struct gsm_network, name_long); |
| 65 | |
| 66 | int bsc_base_ctrl_cmds_install(void) |
| 67 | { |
| 68 | int rc = 0; |
| 69 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mnc); |
| 70 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mcc); |
| 71 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_short_name); |
| 72 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_long_name); |
| 73 | |
| 74 | return rc; |
| 75 | } |