2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2003 Net Integration Technologies, Inc.
5 * Standalone WvDial program, for testing the WvDialer class.
7 * Created: Sept 30 1997 D. Coombs
14 #include "wvlogfile.h"
22 volatile bool want_to_die
= false;
25 // use no prefix string for app "Modem", and an arrow for everything else.
26 // This makes the output of the wvdial application look nicer.
27 class WvDialLogger
: public WvLogConsole
28 /**************************************/
31 WvDialLogger() : WvLogConsole(dup(2)) // log to stderr (fd 2)
35 virtual void _make_prefix();
39 void WvDialLogger::_make_prefix()
40 /*******************************/
42 WvString name
= appname(last_source
);
43 if(name
== "WvDial Modem")
55 static void print_version()
56 /*************************/
58 printf( "%s", wvdial_version_text
);
61 static void print_help()
62 /**********************/
65 printf( "\n%s", wvdial_help_text
);
68 static void signalhandler(int sig
)
69 /***********************************/
71 fprintf(stderr
, "Caught signal %d: Attempting to exit gracefully...\n", sig
);
77 int main(int argc
, char **argv
)
78 /********************************/
81 free( malloc( 1 ) ); // for electric fence
85 WvSyslog
*syslog
= NULL
;
86 WvLogFile
*filelog
= NULL
;
87 UniConfRoot
uniconf("temp:");
89 WvStringList sections
;
90 WvStringList cmdlineopts
;
91 WvLog
log( "WvDial", WvLog::Debug
);
92 WvString homedir
= getenv("HOME");
94 int havecmdlineopts
= 0;
96 bool chat_mode
= false;
97 bool write_syslog
= true;
99 signal(SIGTERM
, signalhandler
);
100 signal(SIGINT
, signalhandler
);
101 signal(SIGHUP
, signalhandler
);
105 for(int i
=1; i
< argc
; i
++)
107 if(!strcmp(argv
[i
], "--config" ))
109 if (!access(argv
[++i
< argc
? i
: i
- 1], F_OK
))
112 cfg
.load_file(WvString(argv
[i
]));
117 log("Error: --config requires a valid argument\n");
122 if(strchr(argv
[i
], '=' ))
125 cmdlineopts
.append(new WvString(argv
[i
]),true);
128 if(!strcmp(argv
[i
], "--chat" ))
133 if(!strcmp( argv
[i
], "--no-syslog" ))
135 write_syslog
= false;
138 if( !strcmp(argv
[i
], "--help"))
143 else if(!strcmp(argv
[i
], "--version"))
148 else if(argv
[i
][0] == '-')
153 sections
.append(new WvString("Dialer %s", argv
[i
]), true);
158 sections
.append(new WvString("Dialer Defaults"), true);
163 // Load the system file first...
164 WvString
stdconfig("/etc/wvdial.conf");
166 if (!access(stdconfig
, F_OK
))
167 cfg
.load_file(stdconfig
);
169 // Then the user specific one...
172 WvString
rcfile("%s/.wvdialrc", homedir
);
174 if (!access(rcfile
, F_OK
))
175 cfg
.load_file(rcfile
);
179 // Inject all of the command line options on into the cfg file in a new
180 // section called Command-Line if there are command line options.
181 if (havecmdlineopts
== 1)
183 WvStringList::Iter
i(cmdlineopts
);
184 for (i
.rewind();i
.next();)
186 char *name
= i().edit();
187 char *value
= strchr(name
,'=');
189 // Value should never be null since it can't get into the list
190 // if it doesn't have an = in i()
194 name
= trim_string(name
);
195 value
= trim_string(value
);
196 cfg
.set("Command-Line", name
, value
);
198 sections
.append(new WvString("Command-Line"), true);
210 WvString
buf("wvdial[%s]", getpid());
211 syslog
= new WvSyslog( buf
, false, WvLog::Debug2
,
216 // Direct logging to /dev/null as otherwise WvLog hasn't any
217 // receivers and thus will use WvLogConsole to log to stderr.
218 // That can disturb the communication with the modem on
219 // stdin/stdout. - Fixes a bug reported by SUSE on 04/05/04
220 filelog
= new WvLogFile( "/dev/null", WvLog::Debug2
);
224 WvDialer
dialer(cfg
, §ions
, chat_mode
);
227 if (dialer
.isok() && dialer
.options
.ask_password
)
228 dialer
.ask_password();
230 if (dialer
.dial() == false)
233 while (!want_to_die
&& dialer
.isok()
234 && dialer
.status() != WvDialer::Idle
)
244 // Probably dieing from a user signal
248 if ((dialer
.status() != WvDialer::Idle
) || !dialer
.isok())