modilp, ilp - show duration, bugfix
s. isdnlog/ilp/README for more information isdnlog 4.48
This commit is contained in:
parent
3c2c67567f
commit
50ab54c896
|
@ -1,4 +1,4 @@
|
|||
## $Id: Makefile.in,v 1.188 2000/12/15 14:36:04 leo Exp $
|
||||
## $Id: Makefile.in,v 1.189 2000/12/21 09:56:46 leo Exp $
|
||||
##
|
||||
## ISDN accounting for isdn4linux.
|
||||
##
|
||||
|
@ -19,6 +19,10 @@
|
|||
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
##
|
||||
## $Log: Makefile.in,v $
|
||||
## Revision 1.189 2000/12/21 09:56:46 leo
|
||||
## modilp, ilp - show duration, bugfix
|
||||
## s. isdnlog/ilp/README for more information isdnlog 4.48
|
||||
##
|
||||
## Revision 1.188 2000/12/15 14:36:04 leo
|
||||
## modilp, ilp - B-chan usage in /proc/isdnlog
|
||||
## s. isdnlog/ilp/README for more information
|
||||
|
@ -1420,7 +1424,7 @@ SERVICEFILE = /etc/services
|
|||
# DON'T EDIT BELOW THIS LINE
|
||||
######################################################################
|
||||
|
||||
VERSION = 4.47
|
||||
VERSION = 4.48
|
||||
|
||||
MANPAGES = isdnlog/callerid.conf.5 isdnlog/isdn.conf.5 \
|
||||
isdnlog/isdnformat.5 isdnlog/isdnlog.5 isdnlog/isdnlog.8 \
|
||||
|
|
|
@ -8,8 +8,11 @@ FLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX -O2
|
|||
modilp.o: modilp.c /usr/include/linux/version.h Makefile
|
||||
$(CC) $(FLAGS) -c modilp.c
|
||||
|
||||
ilp: ilp.c
|
||||
$(CC) -Wall -g -DSTANDALONE ilp.c -o ilp
|
||||
|
||||
clean:
|
||||
rm *.o *~
|
||||
rm *.o *~ ilp
|
||||
|
||||
distlean:
|
||||
clean
|
||||
|
|
|
@ -19,9 +19,47 @@
|
|||
* Changes:
|
||||
*
|
||||
* 0.10 15.12.2000 lt Initial Version
|
||||
* 0.11 21.12.2000 lt STANDALONE test mode, bug fixes
|
||||
*/
|
||||
|
||||
#ifdef STANDALONE
|
||||
#define print_msg(l,f,x,y) printf(f,x,y)
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
struct callt {
|
||||
char num[2][30];
|
||||
char area[2][30];
|
||||
char alias[2][30];
|
||||
char vorwahl[2][30];
|
||||
int dialin;
|
||||
double pay;
|
||||
time_t connect;
|
||||
} call;
|
||||
|
||||
typedef struct callt CALL;
|
||||
|
||||
#define _ME(call) (call->dialin ? 1 : 0)
|
||||
#define _OTHER(call) (call->dialin ? 0 : 1)
|
||||
#define CONNECT 7
|
||||
#define RELEASE 0x77
|
||||
|
||||
time_t cur_time;
|
||||
|
||||
char *double2clock(double d) {
|
||||
return " 0:01:23";
|
||||
}
|
||||
|
||||
#else
|
||||
#include "isdnlog.h"
|
||||
#endif
|
||||
|
||||
#define PROC_ISDNLOG "/proc/isdnlog"
|
||||
|
||||
|
@ -29,14 +67,14 @@
|
|||
|
||||
void procinfo(int chan, CALL *call, int state)
|
||||
{
|
||||
static FILE *fp = NULL;
|
||||
static int fd = -1;
|
||||
static int errcount = 0;
|
||||
int c;
|
||||
char s[80];
|
||||
char s[82];
|
||||
char *msn;
|
||||
char *alias;
|
||||
char *st;
|
||||
char *p;
|
||||
size_t len;
|
||||
|
||||
print_msg(PRT_INFO, "procinfo: chan %d, state %d\n", chan, state);
|
||||
|
||||
|
@ -46,16 +84,16 @@ void procinfo(int chan, CALL *call, int state)
|
|||
|
||||
/* special state to clean up */
|
||||
if (state == -1) {
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
fp = NULL;
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
fd = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
/* open /proc/isdnlog for writing */
|
||||
if (fp == NULL) {
|
||||
fp = fopen(PROC_ISDNLOG, "w");
|
||||
if (fp == NULL) {
|
||||
if (fd == -1) {
|
||||
fd = open(PROC_ISDNLOG, O_WRONLY|O_NONBLOCK, O_FSYNC);
|
||||
if (fd == -1) {
|
||||
print_msg(PRT_ERR, "Failed to open '%s' for writing: %s\n",
|
||||
PROC_ISDNLOG, strerror(errno));
|
||||
errcount++;
|
||||
|
@ -69,9 +107,8 @@ void procinfo(int chan, CALL *call, int state)
|
|||
msn = call->num[_ME(call)] + strlen(call->num[_ME(call)]) - 3;
|
||||
|
||||
/* alias is alias | area | country */
|
||||
c = call->confentry[_OTHER(call)];
|
||||
alias = c >= 0 ? known[c]->who :
|
||||
call->area[_OTHER(call)] ? call->area[_OTHER(call)] :
|
||||
alias = *call->alias[_OTHER(call)] ? call->alias[_OTHER(call)] :
|
||||
*call->area[_OTHER(call)] ? call->area[_OTHER(call)] :
|
||||
call->vorwahl[_OTHER(call)]; /* FIXME no country in call? */
|
||||
|
||||
/* format message for channel */
|
||||
|
@ -97,8 +134,32 @@ void procinfo(int chan, CALL *call, int state)
|
|||
double2clock((double) (cur_time - call->connect)));
|
||||
if (!call->dialin)
|
||||
p += sprintf(p, " %7.3f", call->pay);
|
||||
strcpy(p, "\n");
|
||||
fputs(s, fp);
|
||||
fflush(fp);
|
||||
strcpy(p, "\n");
|
||||
len = strlen(s);
|
||||
if (write(fd, s, len) != len) {
|
||||
print_msg(PRT_ERR, "Write error '%s': %s\n",
|
||||
PROC_ISDNLOG, strerror(errno));
|
||||
errcount++;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef STANDALONE
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
time_t now;
|
||||
call.dialin = 1;
|
||||
strcpy(call.num[0], "41");
|
||||
strcpy(call.num[1], argc > 1 ? argv[1] : "1234567");
|
||||
strcpy(call.alias[0], "");
|
||||
strcpy(call.alias[1], "");
|
||||
strcpy(call.area[0], "Hbgtn");
|
||||
strcpy(call.area[1], "Wien");
|
||||
time(&now);
|
||||
call.connect = now;
|
||||
call.pay = 1.23;
|
||||
procinfo(2, &call, CONNECT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
* Changes:
|
||||
*
|
||||
* 0.10 15.12.2000 lt Initial Version
|
||||
* 0.11 21.12.2000 lt calculate duration
|
||||
*/
|
||||
|
||||
/* based on code found in lkmpg/node17.html, which is: */
|
||||
|
@ -39,6 +40,7 @@
|
|||
|
||||
/* Necessary because we use proc fs */
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/time.h> /* get time */
|
||||
|
||||
|
||||
/* In 2.2.3 /usr/include/linux/version.h includes a
|
||||
|
@ -72,21 +74,46 @@ copy_to_user (void *to, const void *from, unsigned long n)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#define get_fast_time do_gettimeofday
|
||||
#endif
|
||||
|
||||
/* The module's file functions ********************** */
|
||||
|
||||
|
||||
/* Here we keep the last message received */
|
||||
|
||||
#define MESSAGE_LENGTH 80
|
||||
#define N_CHANS 2
|
||||
static char Message[N_CHANS][MESSAGE_LENGTH];
|
||||
|
||||
static struct mes_t {
|
||||
char text[MESSAGE_LENGTH];
|
||||
time_t start;
|
||||
} message[N_CHANS];
|
||||
|
||||
/* string in Connect-messages */
|
||||
#define Connect "CON"
|
||||
|
||||
/* store duration d as text at p */
|
||||
|
||||
static void calc_diff(ulong d, char *p) {
|
||||
int h,m;
|
||||
char s[10];
|
||||
|
||||
h = d / 3600;
|
||||
d %= 3600;
|
||||
m = d / 60;
|
||||
d %= 60;
|
||||
if (h > 99) /* forgotten connection ? */
|
||||
h = 99;
|
||||
sprintf(s, "%02d:%02d:%02d", h, m, (int)d);
|
||||
memcpy(p, s, 8);
|
||||
}
|
||||
|
||||
/* The module's file functions ********************** */
|
||||
|
||||
|
||||
/* Since we use the file operations struct, we can't
|
||||
* use the special proc output provisions - we have to
|
||||
* use a standard read function, which is this function */
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
|
||||
static ssize_t
|
||||
module_output (
|
||||
|
@ -107,8 +134,9 @@ module_output (
|
|||
{
|
||||
static int finished = 0;
|
||||
int i;
|
||||
char message[MESSAGE_LENGTH * (N_CHANS + 1)];
|
||||
char output[MESSAGE_LENGTH * (N_CHANS + 1)];
|
||||
char *p;
|
||||
struct timeval tv;
|
||||
|
||||
/* We return 0 to indicate end of file, that we have
|
||||
* no more information. Otherwise, processes will
|
||||
|
@ -118,15 +146,22 @@ module_output (
|
|||
finished = 0;
|
||||
return 0;
|
||||
}
|
||||
get_fast_time(&tv);
|
||||
for (i=0 ; i<N_CHANS; i++)
|
||||
if (message[i].text &&
|
||||
strlen(message[i].text) >= 70 &&
|
||||
strstr(message[i].text, Connect))
|
||||
calc_diff(tv.tv_sec-message[i].start, message[i].text+62);
|
||||
|
||||
sprintf (message,
|
||||
sprintf (output,
|
||||
/*2345678901234567890123456789012345678901234567890123456789012345678901234567890 */
|
||||
/* 1 2 3 4 5 6 7 */
|
||||
"Ch State Msn - Number Alias Time Cost\n%s%s",
|
||||
Message[0], Message[1]);
|
||||
for (p = message, i = 1; *p && i < len; p++, i++)
|
||||
"Ch State Msn - Number Alias Duration Cost\n%s%s",
|
||||
message[0].text, message[1].text);
|
||||
for (p = output, i = 1; *p && i < len; p++, i++)
|
||||
;
|
||||
copy_to_user (buf, message, i);
|
||||
len = i;
|
||||
copy_to_user (buf, output, len);
|
||||
|
||||
/* Notice, we assume here that the size of the message
|
||||
* is below len, or it will be received cut. In a real
|
||||
|
@ -136,7 +171,7 @@ module_output (
|
|||
* the message. */
|
||||
finished = 1;
|
||||
|
||||
return i; /* Return the number of bytes "read" */
|
||||
return len; /* Return the number of bytes "read" */
|
||||
}
|
||||
|
||||
|
||||
|
@ -160,7 +195,8 @@ module_input (
|
|||
{
|
||||
int n;
|
||||
char c;
|
||||
|
||||
struct timeval tv;
|
||||
|
||||
/* get prefix "1" or "2" */
|
||||
copy_from_user (&c, buf, 1);
|
||||
length--;
|
||||
|
@ -171,8 +207,13 @@ module_input (
|
|||
* will later be able to use it */
|
||||
if (length > MESSAGE_LENGTH - 1)
|
||||
length = MESSAGE_LENGTH - 1;
|
||||
copy_from_user (Message[n], buf+1, length);
|
||||
Message[n][length] = '\0';
|
||||
copy_from_user (message[n].text, buf+1, length);
|
||||
message[n].text[length] = '\0';
|
||||
/* remember connect time */
|
||||
if (strstr(message[n].text, Connect)) {
|
||||
get_fast_time(&tv);
|
||||
message[n].start = tv.tv_sec;
|
||||
}
|
||||
return length + 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: processor.c,v 1.119 2000/12/15 14:36:05 leo Exp $
|
||||
/* $Id: processor.c,v 1.120 2000/12/21 09:56:47 leo Exp $
|
||||
*
|
||||
* ISDN accounting for isdn4linux. (log-module)
|
||||
*
|
||||
|
@ -19,6 +19,10 @@
|
|||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Log: processor.c,v $
|
||||
* Revision 1.120 2000/12/21 09:56:47 leo
|
||||
* modilp, ilp - show duration, bugfix
|
||||
* s. isdnlog/ilp/README for more information isdnlog 4.48
|
||||
*
|
||||
* Revision 1.119 2000/12/15 14:36:05 leo
|
||||
* modilp, ilp - B-chan usage in /proc/isdnlog
|
||||
* s. isdnlog/ilp/README for more information
|
||||
|
@ -4279,7 +4283,11 @@ static void LCR(int chan, char *s)
|
|||
} /* LCR */
|
||||
#endif
|
||||
|
||||
#ifdef ILP
|
||||
extern void procinfo(int channel, CALL * cp, int state);
|
||||
#else
|
||||
void procinfo(int channel, CALL * cp, int state) {}
|
||||
#endif
|
||||
|
||||
static void processctrl(int card, char *s)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue