Merged revisions 11610-11649 via svnmerge from
[wvapps.git] / wvdial / wvdialer.h
blob0b3300e8456278c63b72d90681b85236882542d4
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2003 Net Integration Technologies, Inc.
5 * Definition of the WvDialer smart-dialer class.
7 */
9 #ifndef __DIALER_H
10 #define __DIALER_H
12 #include <termios.h>
14 #include "strutils.h"
15 #include "wvconfemu.h"
16 #include "wvlog.h"
17 #include "wvmodem.h"
18 #include "wvpapchap.h"
19 #include "wvdialbrain.h"
20 #include "wvpipe.h"
21 #include "wvstreamclone.h"
22 #include "wvdialmon.h"
24 #define INBUF_SIZE 1024
25 #define DEFAULT_BAUD 57600U
27 extern const char wvdial_help_text[];
28 extern const char wvdial_version_text[];
30 struct OptInfo
31 /************/
33 char * name;
34 WvString * str_member;
35 int * int_member;
36 char * str_default;
37 int int_default;
40 class WvConf;
42 class WvDialer : public WvStreamClone
43 /***********************************/
45 public:
46 WvDialer( WvConf &_cfg, WvStringList *_sect_list, bool _chat_mode = false );
47 virtual ~WvDialer();
49 bool dial();
50 void hangup();
51 void execute();
53 bool check_attempts_exceeded(int connect_attempts);
55 void pppd_watch( int w );
57 int ask_password();
59 enum Status {
60 Idle,
61 ModemError,
62 OtherError,
63 Online,
64 Dial,
65 PreDial1,
66 PreDial2,
67 WaitDial,
68 WaitAnything,
69 WaitPrompt,
70 AutoReconnectDelay
73 Status status() const
74 { return stat; }
76 time_t auto_reconnect_time() const
77 { return (auto_reconnect_at - time(NULL)); }
79 virtual void pre_select(SelectInfo &si);
80 virtual bool post_select(SelectInfo &si);
81 virtual bool isok() const;
83 int connect_attempts;
84 int dial_stat;
85 char *connect_status() const;
86 bool init_modem();
87 void del_modem();
88 WvModemBase *take_modem();
89 void give_modem(WvModemBase *_modem);
91 friend class WvDialBrain;
93 struct {
94 WvString modem;
95 int baud;
96 WvString init1;
97 WvString init2;
98 WvString init3;
99 WvString init4;
100 WvString init5;
101 WvString init6;
102 WvString init7;
103 WvString init8;
104 WvString init9;
105 WvString phnum;
106 WvString phnum1;
107 WvString phnum2;
108 WvString phnum3;
109 WvString phnum4;
110 WvString dial_prefix;
111 WvString areacode;
112 WvString dial_cmd;
113 WvString login;
114 WvString login_prompt;
115 WvString password;
116 WvString pass_prompt;
117 WvString where_pppd;
118 WvString pppd_option;
119 WvString force_addr;
120 WvString remote;
121 WvString default_reply;
122 WvString country;
123 WvString provider;
124 WvString product;
125 WvString homepage;
126 WvString dialmessage1;
127 WvString dialmessage2;
128 WvString dnstest1, dnstest2;
129 int carrier_check;
130 int stupid_mode;
131 int new_pppd;
132 int auto_reconnect;
133 int abort_on_busy;
134 int abort_on_no_dialtone;
135 int dial_attempts;
136 int compuserve;
137 int tonline;
138 int auto_dns;
139 int check_dns;
140 int check_dfr;
141 int idle_seconds;
142 int isdn;
143 int ask_password;
145 } options;
148 WvDialMon pppd_mon; // class to analyse messages of pppd
151 private:
152 WvDialBrain *brain;
153 WvConf &cfg;
154 WvStringList *sect_list;
155 WvModemBase *modem;
157 bool chat_mode;
159 bool been_online;
160 time_t connected_at;
161 time_t auto_reconnect_delay;
162 time_t auto_reconnect_at;
163 WvPipe *ppp_pipe;
165 int phnum_count;
166 int phnum_max;
168 WvLog log;
169 WvLog err;
170 WvLog modemrx;
172 Status stat;
174 time_t last_rx;
175 time_t last_execute;
176 int prompt_tries;
177 WvString prompt_response;
179 void load_options();
181 void async_dial();
182 void async_waitprompt();
184 void start_ppp();
186 // The following members are for the wait_for_modem() function.
187 int wait_for_modem( char *strs[], int timeout, bool neednewline,
188 bool verbose = true);
189 int async_wait_for_modem( char * strs[], bool neednewline,
190 bool verbose = true);
191 char buffer[ INBUF_SIZE + 1 ];
192 off_t offset;
193 void reset_offset();
195 // Called from WvDialBrain::guess_menu()
196 bool is_pending() { return( modem->select( 1000 ) ); }
198 // These are used to read the messages of pppd
199 int pppd_msgfd[2]; // two fd of the pipe
200 WvFDStream *pppd_log; // to read messages of pppd
202 // These are used to pipe the password to pppd
203 int pppd_passwdfd[2]; // two fd of the pipe
206 #endif // __DIALER_H