aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/vty/vty.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-05-16 20:52:23 +0200
committerHarald Welte <laforge@gnumonks.org>2010-05-16 20:52:23 +0200
commitdcccb1818da12041d08469ce2ab2ccd191187100 (patch)
treef2bb70dd3b130e8afa4c8c4c2a8e7689867843ec /openbsc/src/vty/vty.c
parent88907a2f92523c56bf5250c3c75230601eb2f604 (diff)
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.
Diffstat (limited to 'openbsc/src/vty/vty.c')
-rw-r--r--openbsc/src/vty/vty.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/openbsc/src/vty/vty.c b/openbsc/src/vty/vty.c
index 821c08c5d..438b6c36e 100644
--- a/openbsc/src/vty/vty.c
+++ b/openbsc/src/vty/vty.c
@@ -1354,7 +1354,7 @@ int vty_read(struct vty *vty)
/* 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_read_file(FILE *confp)
vty->fd = 0;
vty->type = VTY_FILE;
vty->node = CONFIG_NODE;
+ vty->priv = priv;
ret = config_from_file(vty, confp);
@@ -1634,14 +1635,16 @@ extern void *tall_bsc_ctx;
/* 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 @@ void vty_init(const char *name, const char *version, const char *copyright)
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 @@ int vty_read_config_file(const char *file_name)
if (!cfile)
return -ENOENT;
- rc = vty_read_file(cfile);
+ rc = vty_read_file(cfile, priv);
fclose(cfile);
host_config_set(file_name);