added the command "isdnctrl name ifdefaults": the named device is reset

to some reasonable defaults.

Internally, isdnctrl.c contains a list of functions (defs_fcns []), which
are called one after the other with the interface-name as a patameter.
Each function returns a char* to a string containing iscnctrl-commands
to be executed. Example:

char *
defs_budget(char *id) {
	static char	r [1024];
	char	*p = r;

	p += sprintf(p, "budget %s dial 10 1min\n", id);
	p += sprintf(p, "budget %s charge 100 1day\n", id);
	p += sprintf(p, "budget %s online 8hour 1day\n", id);

	return(r);
}

The advantage of this approach is, that even complex commands can be executed.

PS: The function defs_basic() in isdnctrl.c is not complete.
This commit is contained in:
cal 1998-06-09 18:11:29 +00:00
parent 2856594657
commit a05c712d86
5 changed files with 206 additions and 8 deletions

View File

@ -331,7 +331,6 @@ write_icmp_type(char *s, __u8 from, __u8 to) {
} else { \
++args_used; \
} \
fprintf(stderr, "looking for <%s>: argp = %d/%d (%s)\n", msg, argp, argc, argv [argp]); \
}
@ -822,6 +821,17 @@ set_default_timeout(int fd, char *id, int firstarg, int argc, char *argv []) {
}
char *
defs_timru(char *id) {
static char r [1024];
char *p = r;
p += sprintf(p, "addrule %s keepup in 0 ppp/lcp\n", id);
return(r);
}
/* Budget-Erweiterung */
/*
??.07.97:cal:DAY: (60 * HOUR) --> (24 * HOUR)
@ -842,10 +852,10 @@ char *output_time(time_t *);
int
hdl_budget(int fd, char *id, int cmd, int firstarg, int argc, char *argv []) {
hdl_budget(int fd, char *id, int cmd, int argc, char *argv []) {
isdn_ioctl_budget budget;
int ioret, n,
argp = firstarg,
argp = 0,
args_used = 0;
time_t t;
@ -1124,4 +1134,17 @@ output_budgets(int fd, char *id, int cmd, int firstarg, int argc, char *argv [])
return(0);
}
char *
defs_budget(char *id) {
static char r [1024];
char *p = r;
p += sprintf(p, "budget %s dial 10 1min\n", id);
p += sprintf(p, "budget %s charge 100 1day\n", id);
p += sprintf(p, "budget %s online 8hour 1day\n", id);
return(r);
}
#endif

25
isdnctrl/ctrltimru.h Normal file
View File

@ -0,0 +1,25 @@
/*
* ISDN TimRu-Control
*
* Copyright 1998 by Christian A. Lademann (cal@zls.de)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
int hdl_timeout_rule(int fd, char *id, int cmd, int argc, char *argv []);
char * defs_timru(char *id);
int hdl_budget(int fd, char *id, int cmd, int argc, char *argv []);
char * defs_budget(char *id);

View File

@ -1,4 +1,4 @@
/* $Id: isdnctrl.c,v 1.21 1998/06/02 12:17:15 detabc Exp $
/* $Id: isdnctrl.c,v 1.22 1998/06/09 18:11:31 cal Exp $
* ISDN driver for Linux. (Control-Utility)
*
* Copyright 1994,95 by Fritz Elfert (fritz@wuemaus.franken.de)
@ -21,6 +21,31 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: isdnctrl.c,v $
* Revision 1.22 1998/06/09 18:11:31 cal
* added the command "isdnctrl name ifdefaults": the named device is reset
* to some reasonable defaults.
*
* Internally, isdnctrl.c contains a list of functions (defs_fcns []), which
* are called one after the other with the interface-name as a patameter.
* Each function returns a char* to a string containing iscnctrl-commands
* to be executed. Example:
*
* char *
* defs_budget(char *id) {
* static char r [1024];
* char *p = r;
*
* p += sprintf(p, "budget %s dial 10 1min\n", id);
* p += sprintf(p, "budget %s charge 100 1day\n", id);
* p += sprintf(p, "budget %s online 8hour 1day\n", id);
*
* return(r);
* }
*
* The advantage of this approach is, that even complex commands can be executed.
*
* PS: The function defs_basic() in isdnctrl.c is not complete.
*
* Revision 1.21 1998/06/02 12:17:15 detabc
* wegen einer einstweiliger verfuegung gegen DW ist zur zeit
* die abc-extension bis zur klaerung der rechtslage nicht verfuegbar
@ -175,9 +200,29 @@
# include "ctrlconf.h"
#endif /* I4L_CTRL_CONF */
#ifdef I4L_CTRL_TIMRU
# include "ctrltimru.h"
#endif /* I4L_CTRL_TIMRU */
#define CMD_IFCONFIG "ifconfig"
#define CMD_OPT_IFCONFIG "down"
/* list of functions to obtain default-configuration of interface */
typedef char *(*defs_fcn_t)();
defs_fcn_t defs_fcns [] = {
defs_basic,
#ifdef I4L_CTRL_TIMRU
defs_timru,
defs_budget,
#endif
NULL
};
char nextlistif[10];
int exec_args(int fd, int argc, char **argv);
@ -1393,6 +1438,66 @@ int exec_args(int fd, int argc, char **argv)
printf("ISDN Configuration read from %s.\n", id);
break;
#endif /* I4L_CTRL_CONF */
case IFDEFAULTS: {
#define MAX_DEFS_ARGS 64
int defs_argc;
char *defs_argv [MAX_DEFS_ARGS + 1];
defs_fcn_t defs_fcn_p;
int i;
char *s, *s0, *t, *u;
i = 0;
while((defs_fcn_p = defs_fcns [i++]) != NULL) {
s = (*defs_fcn_p)(id);
if(!s || !*s)
continue;
s0 = s = strdup(s);
while(s && *s) {
t = strdup(strtok(s, "\n"));
s += strlen(t) + 1;
if(!t || !*t)
continue;
defs_argc = 0;
defs_argv [defs_argc] = NULL;
u = strtok(t, " \t");
while(u && *u) {
if(++defs_argc >= MAX_DEFS_ARGS) {
fprintf(stderr, "default-values overflow.");
exit(1);
}
defs_argv [defs_argc - 1] = strdup(u);
defs_argv [defs_argc] = NULL;
u = strtok(NULL, " \t");
}
if(defs_argc) {
exec_args(fd, defs_argc, defs_argv);
while(defs_argc--)
free(defs_argv [defs_argc]);
}
free(t);
}
free(s0);
}
}
break;
}
#if DEBUG
@ -1405,6 +1510,17 @@ int exec_args(int fd, int argc, char **argv)
return 0;
}
char *defs_basic(char *id) {
static char r [1024];
char *p = r;
p += sprintf(p, "status %s off\n", id);
p += sprintf(p, "huptimeout %s 60\n", id);
return(r);
}
void check_version() {
int fd;

View File

@ -1,4 +1,4 @@
/* $Id: isdnctrl.h,v 1.10 1998/03/16 09:40:56 cal Exp $
/* $Id: isdnctrl.h,v 1.11 1998/06/09 18:11:33 cal Exp $
* ISDN driver for Linux. (Control-Utility)
*
* Copyright 1994,95 by Fritz Elfert (fritz@wuemaus.franken.de)
@ -21,6 +21,31 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: isdnctrl.h,v $
* Revision 1.11 1998/06/09 18:11:33 cal
* added the command "isdnctrl name ifdefaults": the named device is reset
* to some reasonable defaults.
*
* Internally, isdnctrl.c contains a list of functions (defs_fcns []), which
* are called one after the other with the interface-name as a patameter.
* Each function returns a char* to a string containing iscnctrl-commands
* to be executed. Example:
*
* char *
* defs_budget(char *id) {
* static char r [1024];
* char *p = r;
*
* p += sprintf(p, "budget %s dial 10 1min\n", id);
* p += sprintf(p, "budget %s charge 100 1day\n", id);
* p += sprintf(p, "budget %s online 8hour 1day\n", id);
*
* return(r);
* }
*
* The advantage of this approach is, that even complex commands can be executed.
*
* PS: The function defs_basic() in isdnctrl.c is not complete.
*
* Revision 1.10 1998/03/16 09:40:56 cal
* fixed a problem parsing TimRu-Commands
* started with TimRu-man-page
@ -80,8 +105,9 @@ enum {
SAVEBUDGETS, RESTOREBUDGETS,
#endif
#ifdef I4L_CTRL_CONF
WRITECONF, READCONF
WRITECONF, READCONF,
#endif /* I4L_CTRL_CONF */
IFDEFAULTS
};
typedef struct {
@ -150,6 +176,7 @@ cmd_struct cmds[] =
{"writeconf", "01"},
{"readconf", "01"},
#endif /* I4L_CTRL_CONF */
{"ifdefaults", "01"},
{NULL,}
};
@ -236,6 +263,8 @@ _EXTERN int key2num(char *key, char **keytable, int *numtable);
_EXTERN char * num2key(int num, char **keytable, int *numtable);
_EXTERN int exec_args(int fd, int argc, char **argv);
_EXTERN char * defs_basic(char *id);
#undef _EXTERN
/*****************************************************************************/

View File

@ -1,6 +1,6 @@
.\" $Id: isdnctrl.man.in,v 1.9 1998/05/14 17:32:20 paul Exp $
.\" $Id: isdnctrl.man.in,v 1.10 1998/06/09 18:11:36 cal Exp $
.\"
.\" CHECKIN $Date: 1998/05/14 17:32:20 $
.\" CHECKIN $Date: 1998/06/09 18:11:36 $
.\"
.\" Process this file with
.\" groff -man -Tascii isdnctrl.8 for ASCII output, or
@ -73,6 +73,11 @@ is appended,
.BI ifconfig " name " down
before removing an interface.
.TP
.BI ifdefaults " name "
resets the interface
.IR name
to some reasonable defaults.
.TP
.BI addphone " name " out " num"
Adds the phone number
.I num