Sending caller-id patch (against mgetty-1.1.37) with updates so that
the test suite works properly. Gert, if you can merge it into the
mainline it would be really great ! It's pretty much complete,
with documentation, changelog, etc.
Changelog:
The purpose of this patch is to allow mgetty to function as a caller-id box
and report caller-id information by invoking a user-specified program, as
soon as the callerid information becomes available. The invoked program is
specified by the new cid-program option, which is similar to the cnd-program
that already exists (used to invoke a program only when mgetty actually picks
up the phone).
* cnd.c:
(cndfind) (process_rockwell_mesg): Upgraded message reporting caller
to L_NOISE, since it's a rather noteworthy event.
(cnd_call): Call the setup_environment function, so that CID information
will be available to the cnd-program/cid-program scripts as environment
variables.
(set_env_var): Moved this function here from logname.c as it makes
sense to have set_env_var and setup_environment in the same file
and allows cnd.o to be linked by the test suite.
(setup_environment): Moved this function here from login.c
and added new environment variables CALL_DATE and CALL_TIME,
useful to pass to programs run by cnd-program/cid-program.
* conf_mg.c (conf_mg.c): Added the new cid-program configuration option, which
is used to execute a program as soon as caller id information comes in.
* conf_mg.h: Added cid_program member to the conf_data_mgetty struct.
* mgetty.texi-in: Added documentation about the new cid-program option, and
added information about the new CALL_DATE and CALL_TIME environment
variables, and about the existing CALL_DEVICE environment variable.
* login.c (setup_environment): Added new environment variables CALL_DATE and
CALL_TIME, useful to pass to programs run by cnd-program/cid-program.
* logname.c (set_env_var): Moved this function to cnd.c
* mgetty.c (main): Added logic to run cid-program as soon as caller-id
information comes in (and only run it once per call).
* mgetty.h: Added extern reference to the CallDate pointer, since it is now
used by more than one file.
* t/t_ring.c: Initialize Device to a dummy value for cnd.c to use for the test.
diff -upr mgetty-1.1.37-orig/cnd.c mgetty-1.1.37/cnd.c
--- mgetty-1.1.37-orig/cnd.c 2005-04-17 04:55:43.000000000 -0700
+++ mgetty-1.1.37/cnd.c 2010-09-01 21:52:05.000000000 -0700
@@ -11,6 +11,8 @@
#include "mgetty.h"
#include "config.h"
+extern char * Device; /* mgetty.c */
+
char *Connect = "";
char *CallerId = "none";
char *CallTime = "";
@@ -170,7 +172,7 @@ cndfind _P1((str), char *str)
p++;
}
}
- lprintf(L_JUNK, "CND: found: %s", *(cp->variable));
+ lprintf(L_NOISE, "CND: found: %s", *(cp->variable));
return;
}
}
@@ -221,7 +223,7 @@ void process_rockwell_mesg _P0 (void)
}
*p = 0;
- lprintf(L_JUNK, "CND: caller ID: %s", CallerId);
+ lprintf(L_NOISE, "CND: caller ID: %s", CallerId);
}
/* lookup Caller ID in CNDFILE, decide upon answering or not */
@@ -287,6 +289,7 @@ int cnd_call _P3((name, tty, dist_ring),
tty, CallerId, CallName, dist_ring, CalledNr, CONSOLE );
lprintf( L_NOISE, "CND: program \"%s\"", program );
+ setup_environment();
rc = system(program);
if ( rc < 0 )
@@ -297,3 +300,38 @@ int cnd_call _P3((name, tty, dist_ring),
return rc>>8;
}
+
+/* set_env_var( var, string )
+ *
+ * create an environment entry "VAR=string"
+ */
+void set_env_var _P2( (var,string), char * var, char * string )
+{
+ char * v;
+ v = malloc( strlen(var) + strlen(string) + 2 );
+ if ( v == NULL )
+ lprintf( L_ERROR, "set_env_var: cannot malloc" );
+ else
+ {
+ sprintf( v, "%s=%s", var, string );
+ lprintf( L_NOISE, "setenv: '%s'", v );
+ if ( putenv( v ) != 0 )
+ lprintf( L_ERROR, "putenv failed" );
+ }
+}
+
+void setup_environment _P0(void)
+{
+ if ( *CallerId )
+ set_env_var( "CALLER_ID", CallerId );
+ if ( *CallDate )
+ set_env_var( "CALL_DATE", CallDate );
+ if ( *CallTime )
+ set_env_var( "CALL_TIME", CallTime );
+ if ( *CallName )
+ set_env_var( "CALLER_NAME", CallName );
+ if ( *CalledNr )
+ set_env_var( "CALLED_ID", CalledNr );
+ set_env_var( "CONNECT", Connect );
+ set_env_var( "DEVICE", Device );
+}
diff -upr mgetty-1.1.37-orig/conf_mg.c mgetty-1.1.37/conf_mg.c
--- mgetty-1.1.37-orig/conf_mg.c 2009-03-19 08:13:53.000000000 -0700
+++ mgetty-1.1.37/conf_mg.c 2010-09-01 21:45:14.000000000 -0700
@@ -85,6 +85,7 @@ struct conf_data_mgetty c = {
{ "rings", {1}, CT_INT, C_PRESET },
{ "msn-list", {(p_int) NULL}, CT_CHAT, C_EMPTY },
{ "get-cnd-chat", {0}, CT_CHAT, C_EMPTY },
+ { "cid-program", {(p_int) NULL}, CT_STRING, C_EMPTY },
{ "cnd-program", {(p_int) NULL}, CT_STRING, C_EMPTY },
{ "answer-chat", {0}, CT_CHAT, C_EMPTY },
{ "answer-chat-timeout", {80}, CT_INT, C_PRESET },
diff -upr mgetty-1.1.37-orig/conf_mg.h mgetty-1.1.37/conf_mg.h
--- mgetty-1.1.37-orig/conf_mg.h 2005-11-24 08:57:58.000000000 -0800
+++ mgetty-1.1.37/conf_mg.h 2010-09-01 21:45:14.000000000 -0700
@@ -33,6 +33,7 @@ extern struct conf_data_mgetty {
rings_wanted, /* number of RINGs */
msn_list, /* ISDN MSNs (dist.ring) */
getcnd_chat, /* get caller ID (for ELINK)*/
+ cid_program, /* notify about caller ID */
cnd_program, /* accept caller? */
answer_chat, /* ATA...CONNECT...""...\n */
answer_chat_timeout, /* longer as S7! */
diff -upr mgetty-1.1.37-orig/doc/mgetty.texi-in mgetty-1.1.37/doc/mgetty.texi-in
--- mgetty-1.1.37-orig/doc/mgetty.texi-in 2008-01-31 08:30:12.000000000 -0800
+++ mgetty-1.1.37/doc/mgetty.texi-in 2010-09-01 21:45:14.000000000 -0700
@@ -638,12 +638,20 @@ Some telephone companies provide a servi
your phone is ringing. Not all providers support it, and you'll have to
ask for it.
-If your modem is able to retrieve callerid information, and @code{mgetty}
+Right now, Caller ID in @code{mgetty} works for most modem variants out there,
+ZyXEL, Rockwell, ELSA and isdn4linux among them.
+
+If your modem is able to retrieve callerid information, @code{mgetty} can
+report that information by passing it as arguments to the @code{cid-program}
+statement in @file{mgetty.config}. You may point @code{cid-program} to a
+script that writes to a logfile, displays a popup on your terminal, etc.
+@code{cid-program} takes the same arguments as @code{cnd-program} (see below)
+but its exit code is ignored.
+
+In addition to the ability of reporting callerid information, if @code{mgetty}
is compiled with @code{CNDFILE} defined in @file{policy.h}, @code{mgetty}
-can check the caller's number before answering the phone. (Right now, it
-works for most variants out there, ZyXEL, Rockwell, ELSA and isdn4linux
-among them). If @code{CNDFILE} is undefined, or if the
-file specified does not exist, all calls will be allowed.
+can check the caller's number before answering the phone. If @code{CNDFILE} is
+undefined, or if the file specified does not exist, all calls will be allowed.
One important thing: for most analog modems, you @strong{must} set the
number of RINGs to wait for to two (2) or higher (set @samp{rings 2} in
@@ -1042,6 +1050,13 @@ if the static Caller ID selection in CND
or if you want to use the Caller ID data for other purposes (displaying,
for example). @xref{Caller-ID}.
+@item @code{cid-program} @var{pathname}
+
+Specify a program to be run as soon as Caller ID information comes in
+(typically between 1st and 2nd ring). If Caller ID info is not available by
+the 3rd ring, still run the program (to report the time that the phone rang).
+This allows mgetty to behave like a caller-id box. @xref{Caller-ID}.
+
@item @code{answer-chat} @var{chat sequence}
This is the command sequence that is used to answer a phone call. Usually
@@ -1489,11 +1504,11 @@ A sample command line might look like th
@BINDIR@/new_fax 0 "+49 89 3243328" 1 @FAX_SPOOL@/ff-01.a123
@end example
-In addition, some environment variables are provide: @code{CALLER_ID},
+In addition, some environment variables are provided: @code{CALLER_ID},
@code{CALLER_NAME}, @code{CALLED_ID} (Caller ID and destination ISDN MSN,
-if available and supported by your modem), and @code{DEVICE} (the full
-name of the tty device, if you want to process faxes differently
-depending on the line they came in).
+if available and supported by your modem), @code{CALL_DATE}, @code{CALL_TIME},
+and @code{DEVICE} (the full name of the tty device, if you want to process
+faxes differently depending on the line they came in).
Such a ``notify program'' could print out the fax, convert it into a MIME
metamail and send it away, display it in an X window (this a little bit
diff -upr mgetty-1.1.37-orig/login.c mgetty-1.1.37/login.c
--- mgetty-1.1.37-orig/login.c 2003-12-05 14:28:58.000000000 -0800
+++ mgetty-1.1.37/login.c 2010-09-01 21:48:16.000000000 -0700
@@ -369,14 +369,3 @@ fallthrough:
exit(FAIL);
}
-void setup_environment _P0(void)
-{
- if ( *CallerId )
- set_env_var( "CALLER_ID", CallerId );
- if ( *CallName )
- set_env_var( "CALLER_NAME", CallName );
- if ( *CalledNr )
- set_env_var( "CALLED_ID", CalledNr );
- set_env_var( "CONNECT", Connect );
- set_env_var( "DEVICE", Device );
-}
diff -upr mgetty-1.1.37-orig/logname.c mgetty-1.1.37/logname.c
--- mgetty-1.1.37-orig/logname.c 2005-11-24 08:58:32.000000000 -0800
+++ mgetty-1.1.37/logname.c 2010-09-01 21:51:57.000000000 -0700
@@ -230,25 +230,6 @@ boolean ln_all_upper _P1( (string), char
#endif
-/* set_env_var( var, string )
- *
- * create an environment entry "VAR=string"
- */
-void set_env_var _P2( (var,string), char * var, char * string )
-{
- char * v;
- v = malloc( strlen(var) + strlen(string) + 2 );
- if ( v == NULL )
- lprintf( L_ERROR, "set_env_var: cannot malloc" );
- else
- {
- sprintf( v, "%s=%s", var, string );
- lprintf( L_NOISE, "setenv: '%s'", v );
- if ( putenv( v ) != 0 )
- lprintf( L_ERROR, "putenv failed" );
- }
-}
-
static int timeouts = 0;
static RETSIGTYPE getlog_timeout(SIG_HDLR_ARGS)
{
diff -upr mgetty-1.1.37-orig/mgetty.c mgetty-1.1.37/mgetty.c
--- mgetty-1.1.37-orig/mgetty.c 2009-03-19 08:14:28.000000000 -0700
+++ mgetty-1.1.37/mgetty.c 2010-09-01 21:45:14.000000000 -0700
@@ -279,6 +279,7 @@ int main _P2((argc, argv), int argc, cha
int rings_wanted;
int rings = 0;
int dist_ring = 0; /* type of RING detected */
+ boolean cid_program_ran = FALSE;/* Only run cid_program once per call */
#if defined(_3B1_) || defined(MEIBE) || defined(sysV68)
extern struct passwd *getpwuid(), *getpwnam();
@@ -548,6 +549,7 @@ int main _P2((argc, argv), int argc, cha
*/
CallTime = CallName = CalledNr = ""; /* dirty */
CallerId = "none";
+ cid_program_ran = FALSE;
clean_line( STDIN, 3); /* let line settle */
rmlocks();
mgetty_state = St_waiting;
@@ -738,14 +740,26 @@ int main _P2((argc, argv), int argc, cha
while ( rings < rings_wanted )
{
- if ( wait_for_ring( STDIN, c_chat(msn_list),
- ( c_bool(ringback) && rings == 0 )
- ? c_int(ringback_time) : ring_chat_timeout,
- ring_chat_actions, &what_action,
- &dist_ring ) == FAIL)
+ int w;
+
+ w = wait_for_ring( STDIN, c_chat(msn_list),
+ ( c_bool(ringback) && rings == 0 )
+ ? c_int(ringback_time) : ring_chat_timeout,
+ ring_chat_actions, &what_action,
+ &dist_ring );
+
+ /* Inform about Caller ID. If we haven't gotten the info by 3rd
+ * ring, it's hopeless; just report that the phone rang. */
+ if ( c_isset(cid_program) && !cid_program_ran
+ && (rings >= 2 || *CallName || strcmp(CallerId, "none")) )
{
- break; /* ringing stopped, or "action" */
+ cnd_call( c_string(cid_program), Device, dist_ring );
+ cid_program_ran = TRUE;
}
+
+ if ( w == FAIL )
+ break; /* ringing stopped, or "action" */
+
rings++;
}
diff -upr mgetty-1.1.37-orig/mgetty.h mgetty-1.1.37/mgetty.h
--- mgetty-1.1.37-orig/mgetty.h 2006-01-01 09:13:18.000000000 -0800
+++ mgetty-1.1.37/mgetty.h 2010-09-01 21:45:14.000000000 -0700
@@ -296,6 +296,7 @@ void setup_environment _PROTO(( void ));
extern char *Connect;
extern char *CallerId;
+extern char *CallDate;
extern char *CallTime;
extern char *CallName;
extern char *CalledNr;
diff -upr mgetty-1.1.37-orig/t/t_ring.c mgetty-1.1.37/t/t_ring.c
--- mgetty-1.1.37-orig/t/t_ring.c 2005-03-23 01:56:21.000000000 -0800
+++ mgetty-1.1.37/t/t_ring.c 2010-09-01 21:53:16.000000000 -0700
@@ -30,6 +30,8 @@
# include <stdarg.h>
#endif
+
+char *Device = "/dev/null"; /* device to use */
char *msnlist[] = {"9999", "35655023", "35655024", "35655025", "4023", NULL};
struct t_ring_tests { char * input;
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de