VTY: pass program name, version and copyright to vty_init()

This enables us to make the VTY completely independent of any
compile-time program-specific information, i.e. one step closer
to using VTY as a shared library from multiple programs.
This commit is contained in:
Harald Welte 2010-05-16 19:20:24 +02:00
parent 3071d6aa7d
commit 1353f961ef
13 changed files with 47 additions and 67 deletions

View File

@ -57,6 +57,10 @@ struct host {
/* Banner configuration. */
const char *motd;
char *motdfile;
const char *prog_name;
const char *prog_version;
const char *prog_copyright;
};
/* There are some command levels which called from command node. */
@ -377,7 +381,8 @@ extern struct cmd_element config_list_cmd;
char *host_config_file();
void host_config_set(const char *);
void print_version(const char *);
/* This is called from main when a daemon is invoked with -v or --version. */
void print_version(int print_copyright);
extern void *tall_vty_cmd_ctx;

View File

@ -128,7 +128,7 @@ static inline char *vty_newline(struct vty *vty)
}
/* Prototypes. */
void vty_init (void);
void vty_init(const char *name, const char *version, const char *copyright);
int vty_read_config_file(const char *file_name);
void vty_init_vtysh (void);
void vty_reset (void);

View File

@ -7,7 +7,6 @@ SUBDIRS = . ipaccess gprs
sbin_PROGRAMS = bsc_hack bs11_config isdnsync bsc_mgcp
noinst_LIBRARIES = libbsc.a libmsc.a libvty.a libsccp.a
noinst_HEADERS = vty/cardshell.h
bscdir = $(libdir)
bsc_LIBRARIES = libsccp.a

View File

@ -42,8 +42,6 @@ static struct log_target *stderr_target;
struct gsm_network *bsc_gsmnet = 0;
static const char *database_name = "hlr.sqlite3";
static const char *config_file = "openbsc.cfg";
extern const char *openbsc_version;
extern const char *openbsc_copyright;
/* timer to store statistics */
#define DB_SYNC_INTERVAL 60, 0
@ -87,16 +85,6 @@ static void print_help()
printf(" -e --log-level number. Set a global loglevel.\n");
}
static void print_version()
{
printf("%s\n", openbsc_version);
}
static void print_copyright()
{
puts(openbsc_copyright);
}
static void handle_options(int argc, char** argv)
{
while (1) {
@ -151,9 +139,7 @@ static void handle_options(int argc, char** argv)
log_set_log_level(stderr_target, atoi(optarg));
break;
case 'V':
print_version();
printf("\n");
print_copyright();
print_version(1);
exit(0);
break;
default:
@ -227,6 +213,11 @@ int main(int argc, char **argv)
/* enable filters */
log_set_all_filter(stderr_target, 1);
/* This needs to precede handle_options() as it calls vty_init() */
rc = bsc_bootstrap_network(mncc_recv, config_file);
if (rc < 0)
exit(1);
/* parse options */
handle_options(argc, argv);
@ -250,10 +241,6 @@ int main(int argc, char **argv)
db_sync_timer.data = NULL;
bsc_schedule_timer(&db_sync_timer, DB_SYNC_INTERVAL);
rc = bsc_bootstrap_network(mncc_recv, config_file);
if (rc < 0)
exit(1);
signal(SIGINT, &signal_handler);
signal(SIGABRT, &signal_handler);
signal(SIGUSR1, &signal_handler);

View File

@ -20,7 +20,6 @@
#include "bscconfig.h"
const char *openbsc_version = "OpenBSC " PACKAGE_VERSION;
const char *openbsc_copyright =
"Copyright (C) 2008-2010 Harald Welte, Holger Freyther\n"
"Contributions by Daniel Willmann, Jan Lübbe,Stefan Schmidt\n"

View File

@ -46,6 +46,8 @@
#include <openbsc/vty.h>
#include <openbsc/gb_proxy.h>
#include <vty/command.h>
#include "../../bscconfig.h"
/* this is here for the vty... it will never be called */
@ -56,11 +58,8 @@ void subscr_put() { abort(); }
void *tall_bsc_ctx;
const char *openbsc_version = "Osmocom NSIP Proxy " PACKAGE_VERSION;
const char *openbsc_copyright =
"Copyright (C) 2010 Harald Welte and On-Waves\n"
"Contributions by Daniel Willmann, Jan Lübbe, Stefan Schmidt\n"
"Dieter Spaar, Andreas Eversberg, Holger Freyther\n\n"
"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n";
@ -175,9 +174,7 @@ static void handle_options(int argc, char **argv)
log_set_log_level(stderr_target, atoi(optarg));
break;
case 'V':
printf("%s\n", openbsc_version);
printf("\n");
puts(openbsc_copyright);
print_version(1);
exit(0);
break;
default:
@ -208,10 +205,11 @@ int main(int argc, char **argv)
log_add_target(stderr_target);
log_set_all_filter(stderr_target, 1);
telnet_init(&dummy_network, 4246);
handle_options(argc, argv);
rate_ctr_init(tall_bsc_ctx);
telnet_init(&dummy_network, 4246);
bssgp_nsi = gprs_ns_instantiate(&proxy_ns_cb);
if (!bssgp_nsi) {
@ -254,7 +252,7 @@ struct gsm_network;
int bsc_vty_init(struct gsm_network *dummy)
{
cmd_init(1);
vty_init();
vty_init("Osmocom Gb Proxy", PACKAGE_VERSION, openbsc_copyright);
openbsc_vty_add_cmds();
gbproxy_vty_init();

View File

@ -58,11 +58,8 @@ void *tall_bsc_ctx;
struct gprs_ns_inst *sgsn_nsi;
const char *openbsc_version = "Osmocom NSIP Proxy " PACKAGE_VERSION;
const char *openbsc_copyright =
"Copyright (C) 2010 Harald Welte and On-Waves\n"
"Contributions by Daniel Willmann, Jan Lübbe, Stefan Schmidt\n"
"Dieter Spaar, Andreas Eversberg, Holger Freyther\n\n"
"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n";
@ -174,7 +171,7 @@ struct gsm_network;
int bsc_vty_init(struct gsm_network *dummy)
{
cmd_init(1);
vty_init();
vty_init("Osmocom SGSN", PACKAGE_VERSION, openbsc_copyright);
openbsc_vty_add_cmds();
sgsn_vty_init();

View File

@ -58,7 +58,6 @@ static struct bsc_fd bfd;
static struct mgcp_config *cfg;
static int reset_endpoints = 0;
const char *openbsc_version = "OpenBSC MGCP " PACKAGE_VERSION;
const char *openbsc_copyright =
"Copyright (C) 2009-2010 Holger Freyther and On-Waves\n"
"Contributions by Daniel Willmann, Jan Lübbe,Stefan Schmidt\n"
@ -79,12 +78,6 @@ static void print_help()
printf(" -c --config-file filename The config file to use.\n");
}
static void print_mgcp_version()
{
printf("%s\n\n", openbsc_version);
printf("%s", openbsc_copyright);
}
static void handle_options(int argc, char** argv)
{
while (1) {
@ -110,7 +103,7 @@ static void handle_options(int argc, char** argv)
config_file = talloc_strdup(tall_bsc_ctx, optarg);
break;
case 'V':
print_mgcp_version();
print_version(1);
exit(0);
break;
default:
@ -200,9 +193,10 @@ int main(int argc, char** argv)
if (!cfg)
return -1;
telnet_init(&dummy_network, 4243);
handle_options(argc, argv);
telnet_init(&dummy_network, 4243);
rc = mgcp_parse_config(config_file, cfg);
if (rc < 0)
return rc;
@ -264,7 +258,7 @@ struct gsm_network;
int bsc_vty_init(struct gsm_network *dummy)
{
cmd_init(1);
vty_init();
vty_init("OpenBSC MGCP", PACKAGE_VERSION, openbsc_copyright);
openbsc_vty_add_cmds();
mgcp_vty_init();

View File

@ -99,7 +99,6 @@ void telnet_init(struct gsm_network *network, int port) {
}
extern const char *openbsc_copyright;
extern const char *openbsc_version;
static void print_welcome(int fd) {
int ret;

View File

@ -1,6 +0,0 @@
#include "../../bscconfig.h"
#define QUAGGA_PROGNAME PACKAGE_NAME
#define QUAGGA_VERSION PACKAGE_VERSION
#define QUAGGA_COPYRIGHT "Harald Welte <laforge@gnumonks.org>"
#define CONFIGFILE_MASK 022
#define SYSCONFDIR "/usr/local/etc"

View File

@ -21,8 +21,6 @@ along with GNU Zebra; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "cardshell.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -44,6 +42,8 @@ Boston, MA 02111-1307, USA. */
#include <openbsc/gsm_subscriber.h>
#include <osmocore/talloc.h>
#define CONFIGFILE_MASK 022
void *tall_vty_cmd_ctx;
/* Command vector which includes some level of command lists. Normally
@ -81,16 +81,14 @@ struct cmd_node config_node = {
};
/* Default motd string. */
const char *default_motd = "\r\n\
Hello, this is " QUAGGA_PROGNAME " (version " QUAGGA_VERSION ").\r\n\
" QUAGGA_COPYRIGHT "\r\n\
\r\n";
const char *default_motd = "";
/* This is called from main when a daemon is invoked with -v or --version. */
void print_version(const char *progname)
void print_version(int print_copyright)
{
printf("%s version %s\n", progname, QUAGGA_VERSION);
printf("%s\n", QUAGGA_COPYRIGHT);
printf("%s version %s\n", host.prog_name, host.prog_version);
if (print_copyright)
printf("\n%s\n", host.prog_copyright);
}
/* Utility function to concatenate argv argument into a single string
@ -2199,9 +2197,9 @@ gDEFUN(config_exit,
DEFUN(show_version,
show_version_cmd, "show version", SHOW_STR "Displays program version\n")
{
vty_out(vty, "%s %s (%s).%s", QUAGGA_PROGNAME, QUAGGA_VERSION,
vty_out(vty, "%s %s (%s).%s", host.prog_name, host.prog_version,
host.name ? host.name : "", VTY_NEWLINE);
vty_out(vty, "%s%s", QUAGGA_COPYRIGHT, VTY_NEWLINE);
vty_out(vty, "%s%s", host.prog_copyright, VTY_NEWLINE);
return CMD_SUCCESS;
}
@ -2294,7 +2292,8 @@ DEFUN(config_write_file,
file_vty->type = VTY_FILE;
/* Config file header print. */
vty_out(file_vty, "!\n! OpenBSC configuration saved from vty\n! ");
vty_out(file_vty, "!\n! %s (%s) configuration saved from vty\n!",
host.prog_name, host.prog_version);
//vty_time_print (file_vty, 1);
vty_out(file_vty, "!\n");

View File

@ -13,12 +13,13 @@
#include <arpa/telnet.h>
#include "cardshell.h"
#include <vty/vty.h>
#include <vty/command.h>
#include <vty/buffer.h>
#include <osmocore/talloc.h>
#define SYSCONFDIR "/usr/local/etc"
/* our callback, located in telnet_interface.c */
void vty_event(enum event event, int sock, struct vty *vty);
@ -468,6 +469,7 @@ static void vty_hist_add(struct vty *vty)
vty->hp = vty->hindex;
}
#define TELNET_OPTION_DEBUG
/* Get telnet window size. */
static int
vty_telnet_option (struct vty *vty, unsigned char *buf, int nbytes)
@ -1631,8 +1633,12 @@ void vty_init_vtysh()
extern void *tall_bsc_ctx;
/* Install vty's own commands like `who' command. */
void vty_init()
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");

View File

@ -41,6 +41,8 @@
#include <openbsc/vty.h>
#include <openbsc/gprs_ns.h>
#include "../bscconfig.h"
static struct gsm_network *gsmnet;
/* FIXME: this should go to some common file */
@ -1942,13 +1944,14 @@ DEFUN(cfg_ts_e1_subslot,
}
extern int bsc_vty_init_extra(struct gsm_network *net);
extern const char *openbsc_copyright;
int bsc_vty_init(struct gsm_network *net)
{
gsmnet = net;
cmd_init(1);
vty_init();
vty_init("OpenBSC", PACKAGE_VERSION, openbsc_copyright);
install_element_ve(&show_net_cmd);
install_element_ve(&show_bts_cmd);