aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo_client_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/osmo_client_main.c')
-rw-r--r--src/osmo_client_main.c64
1 files changed, 52 insertions, 12 deletions
diff --git a/src/osmo_client_main.c b/src/osmo_client_main.c
index c7d68d4..818a2f1 100644
--- a/src/osmo_client_main.c
+++ b/src/osmo_client_main.c
@@ -33,6 +33,7 @@
#include <osmocom/vty/logging.h>
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/stats.h>
+#include <osmocom/vty/misc.h>
#include <pcap.h>
#include <signal.h>
@@ -50,8 +51,6 @@ static int daemonize = 0;
void *tall_cli_ctx;
struct osmo_pcap_client *pcap_client;
-extern void *tall_msgb_ctx;
-extern void *tall_ctr_ctx;
static const struct rate_ctr_desc pcap_client_ctr_desc[] = {
@@ -80,7 +79,6 @@ static struct vty_app_info vty_info = {
.name = "OsmoPCAPClient",
.version = PACKAGE_VERSION,
.go_parent_cb = osmopcap_go_parent,
- .is_config_node = osmopcap_is_config_node,
};
static void print_usage()
@@ -93,25 +91,58 @@ static void print_help()
printf(" Some useful help...\n");
printf(" -h --help this text\n");
printf(" -D --daemonize Fork the process into a background daemon\n");
+ printf(" -V --version Print the version number\n");
printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
printf(" -s --disable-color\n");
printf(" -T --timestamp. Print a timestamp in the debug output.\n");
printf(" -e --log-level number. Set a global loglevel.\n");
printf(" -c --config-file filename The config file to use.\n");
+
+ printf("\nVTY reference generation:\n");
+ printf(" --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n");
+ printf(" --vty-ref-xml Generate the VTY reference XML output and exit.\n");
+}
+
+static void handle_long_options(const char *prog_name, const int long_option)
+{
+ static int vty_ref_mode = VTY_REF_GEN_MODE_DEFAULT;
+ switch (long_option) {
+ case 1:
+ vty_ref_mode = get_string_value(vty_ref_gen_mode_names, optarg);
+ if (vty_ref_mode < 0) {
+ fprintf(stderr, "%s: Unknown VTY reference generation "
+ "mode '%s'\n", prog_name, optarg);
+ exit(2);
+ }
+ break;
+ case 2:
+ fprintf(stderr, "Generating the VTY reference in mode '%s' (%s)\n",
+ get_value_string(vty_ref_gen_mode_names, vty_ref_mode),
+ get_value_string(vty_ref_gen_mode_desc, vty_ref_mode));
+ vty_dump_xml_ref_mode(stdout, (enum vty_ref_gen_mode) vty_ref_mode);
+ exit(0);
+ default:
+ fprintf(stderr, "%s: error parsing cmdline options\n", prog_name);
+ exit(2);
+ }
}
static void handle_options(int argc, char **argv)
{
while (1) {
int option_index = 0, c;
+ static int long_option = 0;
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"daemonize", 0, 0, 'D'},
{"debug", 1, 0, 'd'},
+ {"version", 0, 0, 'V'},
{"disable-color", 0, 0, 's'},
{"timestamp", 0, 0, 'T'},
{"log-level", 1, 0, 'e'},
{"config-file", 1, 0, 'c'},
+ {"vty-ref-mode", 1, &long_option, 1},
+ {"vty-ref-xml", 0, &long_option, 2},
{0, 0, 0, 0}
};
@@ -125,12 +156,19 @@ static void handle_options(int argc, char **argv)
print_usage();
print_help();
exit(0);
+ case 0:
+ handle_long_options(argv[0], long_option);
+ break;
case 'D':
daemonize = 1;
break;
case 'd':
log_parse_category_mask(osmo_stderr_target, optarg);
break;
+ case 'V':
+ print_version(1);
+ exit(0);
+ break;
case 's':
log_set_use_color(osmo_stderr_target, 0);
break;
@@ -182,8 +220,7 @@ static void signal_handler(int signum)
static void talloc_init_ctx()
{
tall_cli_ctx = talloc_named_const(NULL, 0, "client");
- tall_msgb_ctx = talloc_named_const(tall_cli_ctx, 0, "msgb");
- tall_ctr_ctx = talloc_named_const(tall_cli_ctx, 0, "counter");
+ msgb_talloc_ctx_init(tall_cli_ctx, 0);
}
int main(int argc, char **argv)
@@ -194,9 +231,12 @@ int main(int argc, char **argv)
osmo_init_logging2(tall_cli_ctx, &log_info);
vty_info.copyright = osmopcap_copyright;
+ vty_info.tall_ctx = tall_cli_ctx;
vty_init(&vty_info);
logging_vty_add_cmds();
osmo_stats_vty_add_cmds();
+ osmo_talloc_vty_add_cmds();
+ vty_client_init();
/* parse options */
handle_options(argc, argv);
@@ -215,18 +255,11 @@ int main(int argc, char **argv)
osmo_tls_init();
- rc = telnet_init(tall_cli_ctx, NULL, OSMO_VTY_PORT_PCAP_CLIENT);
- if (rc < 0) {
- LOGP(DCLIENT, LOGL_ERROR, "Failed to bind telnet interface\n");
- exit(1);
- }
-
pcap_client = osmo_pcap_client_alloc(tall_cli_ctx);
if (!pcap_client) {
LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate osmo_pcap_client.\n");
exit(1);
}
- vty_client_init(pcap_client);
/* initialize the queue */
INIT_LLIST_HEAD(&pcap_client->conns);
@@ -246,6 +279,13 @@ int main(int argc, char **argv)
exit(1);
}
+ rc = telnet_init_default(tall_cli_ctx, NULL, OSMO_VTY_PORT_PCAP_CLIENT);
+ if (rc < 0) {
+ LOGP(DCLIENT, LOGL_ERROR, "Failed to bind telnet interface\n");
+ exit(1);
+ }
+
+
/* attempt to connect to the remote */
if (pcap_client->conn.srv_ip && pcap_client->conn.srv_port > 0)
osmo_client_connect(&pcap_client->conn);