2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2005 Net Integration Technologies, Inc.
5 * Standalone WvDial program, for testing the WvDialer class.
7 * Created: Sept 30 1997 D. Coombs
15 #include "wvlogfile.h"
23 volatile bool want_to_die
= false;
26 // use no prefix string for app "Modem", and an arrow for everything else.
27 // This makes the output of the wvdial application look nicer.
28 class WvDialLogger
: public WvLogConsole
29 /**************************************/
32 WvDialLogger() : WvLogConsole(dup(2)) // log to stderr (fd 2)
36 virtual void _make_prefix();
40 void WvDialLogger::_make_prefix()
41 /*******************************/
43 WvString name
= last_source
;
44 if(name
== "WvDial Modem")
56 static void signalhandler(int sig
)
57 /***********************************/
59 fprintf(stderr
, "Caught signal %d: Attempting to exit gracefully...\n", sig
);
65 bool haveconfig
= false;
66 static bool config_cb(WvStringParm value
, void *userdata
)
68 WvConf
*cfg
= reinterpret_cast<WvConf
*>(userdata
);
69 if (!access(value
, F_OK
))
71 cfg
->load_file(value
);
75 fprintf(stderr
, "Cannot read `%s'\n", value
.cstr());
80 int main(int argc
, char **argv
)
81 /********************************/
84 free( malloc( 1 ) ); // for electric fence
88 WvSyslog
*syslog
= NULL
;
89 WvLogFile
*filelog
= NULL
;
90 UniConfRoot
uniconf("temp:");
92 WvStringList sections
;
93 WvStringList cmdlineopts
;
94 WvLog
log( "WvDial", WvLog::Debug
);
95 WvString homedir
= getenv("HOME");
97 bool chat_mode
= false;
98 bool write_syslog
= true;
100 signal(SIGTERM
, signalhandler
);
101 signal(SIGINT
, signalhandler
);
102 signal(SIGHUP
, signalhandler
);
105 args
.set_version("WvDial " WVDIAL_VER_STRING
"\n"
106 "Copyright (c) 1997-2005 Net Integration Technologies, "
108 args
.set_help_header("An intelligent PPP dialer.");
109 args
.set_help_footer("Optional SECTION arguments refer to sections in "
110 "configuration file (usually)\n"
111 "/etc/wvdial.conf, $HOME/.wvdialrc or the file "
112 "specified by --config.\n"
113 "Specified sections are all read, with later ones "
114 "overriding previous ones.\n"
115 "Any options not in the listed sections are taken "
116 "from [Dialer Defaults].\n"
118 "Also, optional OPTION=value parameters allow you "
119 "to override options within\n"
120 "the configuration files.\n");
121 args
.set_email("<wvdial-list@lists.nit.ca>");
123 args
.add_option('C', "config",
124 "use configfile instead of /etc/wvdial.conf",
125 "configfile", WvArgs::ArgCallback(&config_cb
), &cfg
);
126 args
.add_set_bool_option('c', "chat",
127 "used when running wvdial from pppd", chat_mode
);
128 args
.add_reset_bool_option('n', "no-syslog",
129 "don't send output to SYSLOG", chat_mode
);
130 args
.add_optional_arg("SECTION", true);
131 args
.add_optional_arg("OPTION=value", true);
133 WvStringList remaining_args
;
134 args
.process(argc
, argv
, &remaining_args
);
137 WvStringList::Iter
i(remaining_args
);
138 for (i
.rewind(); i
.next(); )
140 if (strchr(i(), '=' ))
141 cmdlineopts
.append(new WvString(i()),true);
143 sections
.append(new WvString("Dialer %s", i()), true);
147 if (sections
.isempty())
148 sections
.append(new WvString("Dialer Defaults"), true);
152 // Load the system file first...
153 WvString
stdconfig("/etc/wvdial.conf");
155 if (!access(stdconfig
, F_OK
))
156 cfg
.load_file(stdconfig
);
158 // Then the user specific one...
161 WvString
rcfile("%s/.wvdialrc", homedir
);
163 if (!access(rcfile
, F_OK
))
164 cfg
.load_file(rcfile
);
168 // Inject all of the command line options on into the cfg file in a new
169 // section called Command-Line if there are command line options.
170 if (!cmdlineopts
.isempty())
172 WvStringList::Iter
i(cmdlineopts
);
173 for (i
.rewind();i
.next();)
175 char *name
= i().edit();
176 char *value
= strchr(name
,'=');
178 // Value should never be null since it can't get into the list
179 // if it doesn't have an = in i()
183 name
= trim_string(name
);
184 value
= trim_string(value
);
185 cfg
.set("Command-Line", name
, value
);
187 sections
.prepend(new WvString("Command-Line"), true);
199 WvString
buf("wvdial[%s]", getpid());
200 syslog
= new WvSyslog( buf
, false, WvLog::Debug2
,
205 // Direct logging to /dev/null as otherwise WvLog hasn't any
206 // receivers and thus will use WvLogConsole to log to stderr.
207 // That can disturb the communication with the modem on
208 // stdin/stdout. - Fixes a bug reported by SUSE on 04/05/04
209 filelog
= new WvLogFile( "/dev/null", WvLog::Debug2
);
213 WvDialer
dialer(cfg
, §ions
, chat_mode
);
216 if (dialer
.isok() && dialer
.options
.ask_password
)
217 dialer
.ask_password();
219 if (dialer
.dial() == false)
222 while (!want_to_die
&& dialer
.isok()
223 && dialer
.status() != WvDialer::Idle
)
233 // Probably dieing from a user signal
237 if ((dialer
.status() != WvDialer::Idle
) || !dialer
.isok())