Harald Welte | 3e5ab69 | 2018-06-04 04:26:20 +0200 | [diff] [blame^] | 1 | /* Simple command-line client against the Osmocom CTRL interface */ |
| 2 | |
| 3 | /* (C) 2018 by Harald Welte <laforge@gnumonks.org> |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 21 | * MA 02110-1301, USA. |
| 22 | */ |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | |
| 28 | #include "simple_ctrl.h" |
| 29 | |
| 30 | #include <osmocom/core/logging.h> |
| 31 | #include <osmocom/core/application.h> |
| 32 | |
| 33 | static struct log_info log_info = {}; |
| 34 | |
| 35 | static void exit_help(void) |
| 36 | { |
| 37 | printf("help!\n"); |
| 38 | exit(2); |
| 39 | } |
| 40 | |
| 41 | int main(int argc, char **argv) |
| 42 | { |
| 43 | struct simple_ctrl_handle *sch; |
| 44 | const char *host; |
| 45 | uint16_t port; |
| 46 | int rc; |
| 47 | |
| 48 | if (argc < 4) |
| 49 | exit_help(); |
| 50 | |
| 51 | host = argv[1]; |
| 52 | port = atoi(argv[2]); |
| 53 | |
| 54 | osmo_init_logging2(NULL, &log_info); |
| 55 | |
| 56 | sch = simple_ctrl_open(NULL, host, port); |
| 57 | if (!sch) |
| 58 | exit(1); |
| 59 | |
| 60 | if (!strcmp(argv[3], "get")) { |
| 61 | char *val; |
| 62 | if (argc < 5) |
| 63 | exit_help(); |
| 64 | val = simple_ctrl_get(sch, argv[4]); |
| 65 | if (!val) |
| 66 | exit(2); |
| 67 | printf("%s\n", val); |
| 68 | } else if (!strcmp(argv[3], "set")) { |
| 69 | if (argc < 6) |
| 70 | exit_help(); |
| 71 | rc = simple_ctrl_set(sch, argv[4], argv[5]); |
| 72 | if (rc < 0) |
| 73 | exit(1); |
| 74 | } |
| 75 | |
| 76 | exit(0); |
| 77 | } |