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(time_t now
);
40 void WvDialLogger::_make_prefix(time_t now
)
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");
122 args
.add_option('C', "config",
123 "use configfile instead of /etc/wvdial.conf",
124 "configfile", WvArgs::ArgCallback(&config_cb
), &cfg
);
125 args
.add_set_bool_option('c', "chat",
126 "used when running wvdial from pppd", chat_mode
);
127 args
.add_reset_bool_option('n', "no-syslog",
128 "don't send output to SYSLOG", chat_mode
);
129 args
.add_optional_arg("SECTION", true);
130 args
.add_optional_arg("OPTION=value", true);
132 WvStringList remaining_args
;
133 args
.process(argc
, argv
, &remaining_args
);
136 WvStringList::Iter
i(remaining_args
);
137 for (i
.rewind(); i
.next(); )
139 if (strchr(i(), '=' ))
140 cmdlineopts
.append(new WvString(i()),true);
142 sections
.append(new WvString("Dialer %s", i()), true);
146 if (sections
.isempty())
147 sections
.append(new WvString("Dialer Defaults"), true);
151 // Load the system file first...
152 WvString
stdconfig("/etc/wvdial.conf");
154 if (!access(stdconfig
, F_OK
))
155 cfg
.load_file(stdconfig
);
157 // Then the user specific one...
160 WvString
rcfile("%s/.wvdialrc", homedir
);
162 if (!access(rcfile
, F_OK
))
163 cfg
.load_file(rcfile
);
167 // Inject all of the command line options on into the cfg file in a new
168 // section called Command-Line if there are command line options.
169 if (!cmdlineopts
.isempty())
171 WvStringList::Iter
i(cmdlineopts
);
172 for (i
.rewind();i
.next();)
174 char *name
= i().edit();
175 char *value
= strchr(name
,'=');
177 // Value should never be null since it can't get into the list
178 // if it doesn't have an = in i()
182 name
= trim_string(name
);
183 value
= trim_string(value
);
184 cfg
.set("Command-Line", name
, value
);
186 sections
.prepend(new WvString("Command-Line"), true);
198 WvString
buf("wvdial[%s]", getpid());
199 syslog
= new WvSyslog( buf
, false, WvLog::Debug2
,
204 // Direct logging to /dev/null as otherwise WvLog hasn't any
205 // receivers and thus will use WvLogConsole to log to stderr.
206 // That can disturb the communication with the modem on
207 // stdin/stdout. - Fixes a bug reported by SUSE on 04/05/04
208 filelog
= new WvLogFile( "/dev/null", WvLog::Debug2
);
212 WvDialer
dialer(cfg
, §ions
, chat_mode
);
215 if (dialer
.isok() && dialer
.options
.ask_password
)
216 dialer
.ask_password();
218 if (dialer
.dial() == false)
221 while (!want_to_die
&& dialer
.isok()
222 && dialer
.status() != WvDialer::Idle
)
232 // Probably dieing from a user signal
236 if ((dialer
.status() != WvDialer::Idle
) || !dialer
.isok())