VTY: decouple telnet_interface from 'struct gsmnet'
We want the VTY and telnet code to be independent from the BSC
application(s). As a side note, we also like to eliminate static
global variables for 'struct gsm_network' all over the code.
As such, telnet_init() is now passed along a "private" pointer,
which getst stored in telnet_connection.priv. This telnet_connection
is then stored in vty->priv, which in turn gets dereferenced if
anyone needs a reference to 'struct gsm_network' from the BSC vty
code.
Also:
* vty_init() now calls cmd_init()
* the ugliness that telnet_init() calls back into the application by means of
bsc_vty_init() function has been removed.
* telnet_init() now returns any errors, so the main program can exit
e.g. if the port is already in use.
diff --git a/openbsc/src/vty/vty.c b/openbsc/src/vty/vty.c
index 821c08c..438b6c3 100644
--- a/openbsc/src/vty/vty.c
+++ b/openbsc/src/vty/vty.c
@@ -1354,7 +1354,7 @@
/* Read up configuration file */
static int
-vty_read_file(FILE *confp)
+vty_read_file(FILE *confp, void *priv)
{
int ret;
struct vty *vty;
@@ -1363,6 +1363,7 @@
vty->fd = 0;
vty->type = VTY_FILE;
vty->node = CONFIG_NODE;
+ vty->priv = priv;
ret = config_from_file(vty, confp);
@@ -1634,14 +1635,16 @@
/* Install vty's own commands like `who' command. */
void vty_init(const char *name, const char *version, const char *copyright)
{
- host.prog_name = name;
- host.prog_version = version;
- host.prog_copyright = copyright;
-
tall_vty_ctx = talloc_named_const(NULL, 0, "vty");
tall_vty_vec_ctx = talloc_named_const(tall_vty_ctx, 0, "vty_vector");
tall_vty_cmd_ctx = talloc_named_const(tall_vty_ctx, 0, "vty_command");
+ cmd_init(1);
+
+ host.prog_name = name;
+ host.prog_version = version;
+ host.prog_copyright = copyright;
+
/* For further configuration read, preserve current directory. */
vty_save_cwd();
@@ -1664,7 +1667,7 @@
install_element(VTY_NODE, &no_vty_login_cmd);
}
-int vty_read_config_file(const char *file_name)
+int vty_read_config_file(const char *file_name, void *priv)
{
FILE *cfile;
int rc;
@@ -1673,7 +1676,7 @@
if (!cfile)
return -ENOENT;
- rc = vty_read_file(cfile);
+ rc = vty_read_file(cfile, priv);
fclose(cfile);
host_config_set(file_name);