Discussion:
mgetty patch for caller-id functionality
(too old to reply)
Gert Doering
2008-03-31 06:16:01 UTC
Permalink
Hi,
I am resending this as I fear my email may have been filtered
since I got no reply. I've sent this 4-5 times so far ...
Your mail did arrive. Sorry for not responding so far, I have been a bit
busy with other things and haven't had much time for working on mgetty.

It is still sitting in my inbox, and waiting for me to think about it
and comment and/or integrate it. (Of course readers of the list are
free to use it "as is" - you have the source :) ).

gert
--
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany ***@greenie.muc.de
fax: +49-89-35655025 ***@net.informatik.tu-muenchen.de

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Alexandros Manoussakis
2008-03-31 08:12:25 UTC
Permalink
Gert,
Thanks for your response. Wasn't sure if you were alive :-)
This functionality is very useful. For example all my callers go to a
logfile. grep / less beats fumbling with my stupid telephone, that loses
everything when it runs out of battery anyway.

Also I can tell wether an incoming call is coming from a known fax number,
so I let mgetty pick up, otherwise I pick up the phone.
If your mother-in-law calls, you can let vgetty pick up the phone :-)
There are various ideas / applications!

Usage of cid-program does not affect cnd-program.
The latter is run as usual, when mgety picks up the phone.

Having separate cid-program and cnd-program may seem overkill if you only
have "rings 1" but it's essential in cases where you have many "rings".


The only thing in my patch I'm worried about is this:
+ if ( rings == 1 && c_isset(cid_program) )
+ cnd_call( c_string(cid_program), Device, dist_ring );

In my area, I get caller-id info immediately after the 1st ring, which is
why I have "rings == 1".
It may be the case that in other areas, caller-id info comes after the 2nd
or 3rd ring... I should probably be checking for the 1st time that
cndfind() was able to get the all the info, but I'm not sure
what's the best way to determine that.

Alex
Post by Gert Doering
Hi,
I am resending this as I fear my email may have been filtered
since I got no reply. I've sent this 4-5 times so far ...
Your mail did arrive. Sorry for not responding so far, I have been a bit
busy with other things and haven't had much time for working on mgetty.
It is still sitting in my inbox, and waiting for me to think about it
and comment and/or integrate it. (Of course readers of the list are
free to use it "as is" - you have the source :) ).
gert
--
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
kernel panic ()
2008-04-04 19:30:42 UTC
Permalink
Sounds like you guys are on the same track as I am. I use my version
of cid program to query a mysql database to perform an action
according to the caller record such as telling cnd-program which
greeting to use according to caller id. Works great for blowing off
the telespammers.


--
--------------------------------- --- -- -
Posted with NewsLeecher v3.8 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -
Kernel Panic
2008-04-05 20:15:36 UTC
Permalink
Post by Alexandros Manoussakis
Gert,
Thanks for your response. Wasn't sure if you were alive :-)
This functionality is very useful. For example all my callers go to a
logfile. grep / less beats fumbling with my stupid telephone, that loses
everything when it runs out of battery anyway.
Also I can tell wether an incoming call is coming from a known fax number,
so I let mgetty pick up, otherwise I pick up the phone.
If your mother-in-law calls, you can let vgetty pick up the phone :-)
There are various ideas / applications!
Usage of cid-program does not affect cnd-program.
The latter is run as usual, when mgety picks up the phone.
Having separate cid-program and cnd-program may seem overkill if you only
have "rings 1" but it's essential in cases where you have many "rings".
+ if ( rings == 1 && c_isset(cid_program) )
+ cnd_call( c_string(cid_program), Device, dist_ring );
In my area, I get caller-id info immediately after the 1st ring, which is
why I have "rings == 1".
It may be the case that in other areas, caller-id info comes after the 2nd
or 3rd ring... I should probably be checking for the 1st time that
cndfind() was able to get the all the info, but I'm not sure
what's the best way to determine that.
Alex
Post by Gert Doering
Hi,
I am resending this as I fear my email may have been filtered
since I got no reply. I've sent this 4-5 times so far ...
Your mail did arrive. Sorry for not responding so far, I have been a bit
busy with other things and haven't had much time for working on mgetty.
It is still sitting in my inbox, and waiting for me to think about it
and comment and/or integrate it. (Of course readers of the list are
free to use it "as is" - you have the source :) ).
gert
--
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany
fax: +49-89-35655025
I missed the beginning of this thread so forgive me if I've missed the point
but here's what I did.
This should work for cases when caller id is available after a different
number of rings.
cid_available is a global flag set in mgetty.c.

--- ring.c 2008-04-05 08:25:56.000000000 -0700
+++ ../mgetty-1.1.35-orig/ring.c 2007-12-12 08:47:51.000000000 -0800
@@ -27,12 +27,6 @@
#include "policy.h"
#include "tio.h"
#include "fax_lib.h"
-#include "config.h"
-#include "conf_mg.h"
-extern char *Device;
-extern int dist_ring;
-extern int cid_result;
-extern int cid_available;

/* strdup variant that returns "<null>" in case of out-of-memory */
static char * safedup( char * in )
@@ -318,12 +312,7 @@
if ( w == 0 ) { continue; } /* ignore empty lines */
buf[w] = '\0';
cndfind( buf ); /* grab caller ID */
- if (!cid_available && strcmp(CallerId,"none") && *CallName) {
- cid_result = cnd_call(c_string(cid_program), Device, dist_ring);
- cid_available = TRUE;
- if (cid_result == 2) { break; }
- /* else { continue; } */
- }
+
Paul Fox
2008-03-31 12:56:43 UTC
Permalink
Post by Gert Doering
Hi,
I am resending this as I fear my email may have been filtered
since I got no reply. I've sent this 4-5 times so far ...
Your mail did arrive. Sorry for not responding so far, I have been a bit
busy with other things and haven't had much time for working on mgetty.
It is still sitting in my inbox, and waiting for me to think about it
and comment and/or integrate it. (Of course readers of the list are
free to use it "as is" - you have the source :) ).
is it possible that you received it and no one else did? (i did
not.) my caller-id is working fine with mgetty, but i'm always
interested in reasons that it might break. :-)

paul
=---------------------
paul fox, ***@foxharp.boston.ma.us (arlington, ma, where it's 31.8 degrees)

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Johannes Beekhuizen
2008-03-31 13:44:33 UTC
Permalink
Hallo Paul,

Op maandag 31 maart 2008 schreef Paul Fox aan All:

PF> is it possible that you received it and no one else did? (i did
PF> not.)

Anything is possible :)
But I also saw it for the first time this morning.

Groeten,

Hans.

jdh punt beekhuizen bij duinheks punt nl
Alexandros Manoussakis
2008-04-13 07:42:51 UTC
Permalink
Post by Kernel Panic
This should work for cases when caller id is available after a different
number of rings.
cid_available is a global flag set in mgetty.c.
...
Hi, the code you posted is probably overkill (I don't believe we need
to touch ring.c at all), but you gave me the solution; I just need to
check that CallerId is not "none" and/or *CallName != '\0', instead of
checking that rings==1.
Thank you!

Sending revised patch (works great), including documentation.
Gert, you should now have no excuse to not include this functionality
in mgetty 1.1.37 :-)

Vielen Dank,
Alexandros

Patch begins here (also attaching it in gzipped format to preserve
whitespace etc)

diff -upr mgetty-1.1.36-orig/cnd.c mgetty-1.1.36/cnd.c
--- mgetty-1.1.36-orig/cnd.c 2005-04-17 04:55:43.000000000 -0700
+++ mgetty-1.1.36/cnd.c 2008-03-29 09:55:32.000000000 -0700
@@ -170,7 +170,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 +221,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 */
diff -upr mgetty-1.1.36-orig/conf_mg.c mgetty-1.1.36/conf_mg.c
--- mgetty-1.1.36-orig/conf_mg.c 2006-01-01 09:13:18.000000000 -0800
+++ mgetty-1.1.36/conf_mg.c 2008-03-29 09:55:32.000000000 -0700
@@ -84,6 +84,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.36-orig/conf_mg.h mgetty-1.1.36/conf_mg.h
--- mgetty-1.1.36-orig/conf_mg.h 2005-11-24 08:57:58.000000000 -0800
+++ mgetty-1.1.36/conf_mg.h 2008-03-29 09:55:32.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.36-orig/doc/mgetty.texi-in mgetty-1.1.36/doc/mgetty.texi-in
--- mgetty-1.1.36-orig/doc/mgetty.texi-in 2005-12-30 13:43:49.000000000 -0800
+++ mgetty-1.1.36/doc/mgetty.texi-in 2008-04-13 00:28:29.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
diff -upr mgetty-1.1.36-orig/mgetty.c mgetty-1.1.36/mgetty.c
--- mgetty-1.1.36-orig/mgetty.c 2006-01-01 09:13:18.000000000 -0800
+++ mgetty-1.1.36/mgetty.c 2008-04-13 00:30: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++;
}

-- end of message --
Kernel Panic
2008-04-14 18:19:35 UTC
Permalink
Post by Alexandros Manoussakis
Post by Kernel Panic
This should work for cases when caller id is available after a different
number of rings.
cid_available is a global flag set in mgetty.c.
...
Hi, the code you posted is probably overkill (I don't believe we need
to touch ring.c at all), but you gave me the solution; I just need to
check that CallerId is not "none" and/or *CallName != '\0', instead of
checking that rings==1.
Thank you!
Glad to be of help. The reason I put the code in ring .c is so thad
cid_program is called immediatly after the caller id is made available
instead of waiting for the second ring. cid_program can then optionally
return a result code to mgetty.c whether to pick up the call right away.
Then you don't have to hear the second ring for known telespammers. If only
I could get rid of the first ring!!!

luding documentation.
Post by Alexandros Manoussakis
Gert, you should now have no excuse to not include this functionality
in mgetty 1.1.37 :-)
Vielen Dank,
Alexandros
Patch begins here (also attaching it in gzipped format to preserve
whitespace etc)
diff -upr mgetty-1.1.36-orig/cnd.c mgetty-1.1.36/cnd.c
--- mgetty-1.1.36-orig/cnd.c 2005-04-17 04:55:43.000000000 -0700
+++ mgetty-1.1.36/cnd.c 2008-03-29 09:55:32.000000000 -0700
@@ -170,7 +170,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 +221,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 */
diff -upr mgetty-1.1.36-orig/conf_mg.c mgetty-1.1.36/conf_mg.c
--- mgetty-1.1.36-orig/conf_mg.c 2006-01-01 09:13:18.000000000 -0800
+++ mgetty-1.1.36/conf_mg.c 2008-03-29 09:55:32.000000000 -0700
@@ -84,6 +84,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.36-orig/conf_mg.h mgetty-1.1.36/conf_mg.h
--- mgetty-1.1.36-orig/conf_mg.h 2005-11-24 08:57:58.000000000 -0800
+++ mgetty-1.1.36/conf_mg.h 2008-03-29 09:55:32.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.36-orig/doc/mgetty.texi-in
mgetty-1.1.36/doc/mgetty.texi-in
--- mgetty-1.1.36-orig/doc/mgetty.texi-in 2005-12-30
13:43:49.000000000 -0800
+++ mgetty-1.1.36/doc/mgetty.texi-in 2008-04-13 00:28:29.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.
+ZyXEL, Rockwell, ELSA and isdn4linux among them.
+
+report that information by passing it as arguments to the
@code{cid-program}
+script that writes to a logfile, displays a popup on your terminal, etc.
+but its exit code is ignored.
+
-can check the caller's number before answering the phone. (Right now, it
-works for most variants out there, ZyXEL, Rockwell, ELSA and isdn4linux
-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.
@@ -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,
+
+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).
+
@item @code{answer-chat} @var{chat sequence}
This is the command sequence that is used to answer a phone call. Usually
diff -upr mgetty-1.1.36-orig/mgetty.c mgetty-1.1.36/mgetty.c
--- mgetty-1.1.36-orig/mgetty.c 2006-01-01 09:13:18.000000000 -0800
+++ mgetty-1.1.36/mgetty.c 2008-04-13 00:30: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++;
}
-- end of message --
Alexandros Manoussakis
2008-04-21 18:16:34 UTC
Permalink
Resending, my updated patch did not post to the newsgroup it seems.
Post by Kernel Panic
Glad to be of help.
Very much so!
Post by Kernel Panic
The reason I put the code in ring .c is so thad cid_program is called
immediatly after the caller id is made available
instead of waiting for the second ring.
Hmm, not sure if an extra ring is worth adding several global variables.
I'll leave that decision up to Gert; he may have a way to optimize this
anyway. There's already a TODO item #226 / #226a about call cnd-program
after "min-rings" RINGs, and have the cnd-program decide whether to
"answer NOW" or later. So I think what you are requesting makes more sense
to the existing cnd-program option, not the new cid-program I'm proposing.

In any case, I really want to see my patch into mgetty soon, since apart
from the caller-id box functionality, it will help with those TODO items.
(You can point cid-program to the same executable that cnd-program points to.
Also, we could add checking of the cid-program exit-code, and use that to
decide wether cnd-program will be called sooner or later)

I'm resending my patch (has one small whitespace fix over the last one).
Including both in the email body, and as a gzipped attachment.

Gert, I want to remind you this is complete, tested, and includes
documentation, so please review and merge it in the official sources.

Vielen Dank,
Alex


diff -upr mgetty-1.1.36-orig/cnd.c mgetty-1.1.36/cnd.c
--- mgetty-1.1.36-orig/cnd.c 2005-04-17 04:55:43.000000000 -0700
+++ mgetty-1.1.36/cnd.c 2008-03-29 09:55:32.000000000 -0700
@@ -170,7 +170,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 +221,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 */
diff -upr mgetty-1.1.36-orig/conf_mg.c mgetty-1.1.36/conf_mg.c
--- mgetty-1.1.36-orig/conf_mg.c 2006-01-01 09:13:18.000000000 -0800
+++ mgetty-1.1.36/conf_mg.c 2008-03-29 09:55:32.000000000 -0700
@@ -84,6 +84,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.36-orig/conf_mg.h mgetty-1.1.36/conf_mg.h
--- mgetty-1.1.36-orig/conf_mg.h 2005-11-24 08:57:58.000000000 -0800
+++ mgetty-1.1.36/conf_mg.h 2008-03-29 09:55:32.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.36-orig/doc/mgetty.texi-in mgetty-1.1.36/doc/mgetty.texi-in
--- mgetty-1.1.36-orig/doc/mgetty.texi-in 2005-12-30 13:43:49.000000000 -0800
+++ mgetty-1.1.36/doc/mgetty.texi-in 2008-04-13 00:28:29.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
diff -upr mgetty-1.1.36-orig/mgetty.c mgetty-1.1.36/mgetty.c
--- mgetty-1.1.36-orig/mgetty.c 2006-01-01 09:13:18.000000000 -0800
+++ mgetty-1.1.36/mgetty.c 2008-04-13 00:30: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++;
}

-- end of message --
Paul Fox
2008-04-21 20:06:23 UTC
Permalink
Post by Alexandros Manoussakis
Post by Kernel Panic
The reason I put the code in ring .c is so thad cid_program is called
immediatly after the caller id is made available
instead of waiting for the second ring.
Hmm, not sure if an extra ring is worth adding several global variables.
I'll leave that decision up to Gert; he may have a way to optimize this
anyway. There's already a TODO item #226 / #226a about call cnd-program
after "min-rings" RINGs, and have the cnd-program decide whether to
"answer NOW" or later. So I think what you are requesting makes more sense
to the existing cnd-program option, not the new cid-program I'm proposing.
In any case, I really want to see my patch into mgetty soon, since apart
be patient. :-)

some of us have been waiting for years (really!) for gert
to apply very similar patches. the mailing list archives seem to be
terribly broken -- so i'm afraid i can't point you at other versions of
this fix. however, i will say that i've been running code almost identical
to your patch (by visual comparison) for many years now, and it works fine.

since i wanted the caller-id information as soon as possible, my patch
(which looks like yours in mgetty.c) also includs a change to ring.c
which a) causes "NMBR" to be counted just like "RING", and b) if "NMBR"
was seen, then sets a 1 second timeout to let NAME and MESG arrive, in
case them come after. when that timeout expires, wait_for_ring() will
return.

there was another patch submitted for this, and various other fixes,
sometime after mine. the submitter was rad darius. i have his patches
too, if you'd like to see them. among other things, he added a program
to be called on every ring.

(for the record, my patches were in a message on june 1 2004, rad's were
on sept 1, 2004.)

in any case, the only thing i see missing from your patch is that
setup_environment() should be called from cnd_call() -- otherwise
(unless i've missed another change somewhere) the CID information
won't be available to the new script as environment variables. i
would also add two new variables to setup_environment:
if ( *CallDate )
set_env_var( "CALL_DATE", CallDate );
if ( *CallTime )
set_env_var( "CALL_TIME", CallTime );
just for completeness, since mgetty already collects the information.

i, too, would like to see this in the mgetty base code. i'd like to
see my timeout code in there too (for earlier reporting of CID), but
you've done a better job with naming the new script, and documentation,
so i'd rather propose a second patch after yours is accepted.

(as i'm sure it will be -- right gert?? :-)

paul
=---------------------
paul fox, ***@foxharp.boston.ma.us (arlington, ma, where it's 57.7 degrees)

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Alexandros Manoussakis
2008-04-22 00:38:45 UTC
Permalink
Post by Paul Fox
Post by Alexandros Manoussakis
In any case, I really want to see my patch into mgetty soon,
be patient. :-)
...
for the record, my patches were in a message on june 1 2004, rad's were
on sept 1, 2004.)
I hope I won't have to wait 4 years.
I'm picking up German just to get some better traction with Gert:
Gert, bitte finden sie die Zeit mein Patch zu benutzen !
Viele Leute werden dich danken! Open-source Projekts wollen activ und
lebend sein :-)

Updated patch follows to include your environmental suggestions,
(in code as well as in documentation). They worked nice for me.

Alex


diff -upr mgetty-1.1.36-orig/cnd.c mgetty-1.1.36/cnd.c
--- mgetty-1.1.36-orig/cnd.c 2005-04-17 04:55:43.000000000 -0700
+++ mgetty-1.1.36/cnd.c 2008-04-21 17:15:59.000000000 -0700
@@ -170,7 +170,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 +221,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 +287,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 )
diff -upr mgetty-1.1.36-orig/conf_mg.c mgetty-1.1.36/conf_mg.c
--- mgetty-1.1.36-orig/conf_mg.c 2006-01-01 09:13:18.000000000 -0800
+++ mgetty-1.1.36/conf_mg.c 2008-03-29 09:55:32.000000000 -0700
@@ -84,6 +84,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.36-orig/conf_mg.h mgetty-1.1.36/conf_mg.h
--- mgetty-1.1.36-orig/conf_mg.h 2005-11-24 08:57:58.000000000 -0800
+++ mgetty-1.1.36/conf_mg.h 2008-03-29 09:55:32.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.36-orig/doc/mgetty.texi-in mgetty-1.1.36/doc/mgetty.texi-in
--- mgetty-1.1.36-orig/doc/mgetty.texi-in 2005-12-30 13:43:49.000000000 -0800
+++ mgetty-1.1.36/doc/mgetty.texi-in 2008-04-21 17:19:40.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.36-orig/login.c mgetty-1.1.36/login.c
--- mgetty-1.1.36-orig/login.c 2003-12-05 14:28:58.000000000 -0800
+++ mgetty-1.1.36/login.c 2008-04-21 17:23:42.000000000 -0700
@@ -373,6 +373,10 @@ 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 )
diff -upr mgetty-1.1.36-orig/mgetty.c mgetty-1.1.36/mgetty.c
--- mgetty-1.1.36-orig/mgetty.c 2006-01-01 09:13:18.000000000 -0800
+++ mgetty-1.1.36/mgetty.c 2008-04-13 00:48:10.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.36-orig/mgetty.h mgetty-1.1.36/mgetty.h
--- mgetty-1.1.36-orig/mgetty.h 2006-01-01 09:13:18.000000000 -0800
+++ mgetty-1.1.36/mgetty.h 2008-04-21 17:12:27.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;
-- end of message --

Loading...