34 #include "commands.h" |
34 #include "commands.h" |
35 |
35 |
36 #define JABBERPORT 5222 |
36 #define JABBERPORT 5222 |
37 #define JABBERSSLPORT 5223 |
37 #define JABBERSSLPORT 5223 |
38 |
38 |
|
39 #define RECONNECTION_TIMEOUT 60L |
|
40 |
39 jconn jc; |
41 jconn jc; |
40 enum enum_jstate jstate; |
42 enum enum_jstate jstate; |
41 |
43 |
42 char imstatus2char[imstatus_size+1] = { |
44 char imstatus2char[imstatus_size+1] = { |
43 '_', 'o', 'i', 'f', 'd', 'n', 'a', '\0' |
45 '_', 'o', 'i', 'f', 'd', 'n', 'a', '\0' |
44 }; |
46 }; |
45 |
47 |
|
48 static bool AutoConnection; |
46 static time_t LastPingTime; |
49 static time_t LastPingTime; |
47 static unsigned int KeepaliveDelay; |
50 static unsigned int KeepaliveDelay; |
48 static enum imstatus mystatus = offline; |
51 static enum imstatus mystatus = offline; |
49 static gchar *mystatusmsg; |
52 static gchar *mystatusmsg; |
50 static unsigned char online; |
53 static unsigned char online; |
162 } |
169 } |
163 |
170 |
164 void jb_set_keepalive_delay(unsigned int delay) |
171 void jb_set_keepalive_delay(unsigned int delay) |
165 { |
172 { |
166 KeepaliveDelay = delay; |
173 KeepaliveDelay = delay; |
|
174 } |
|
175 |
|
176 // check_connection() |
|
177 // Check if we've been disconnected for a while (predefined timeout), |
|
178 // and if so try to reconnect. |
|
179 static void check_connection(void) |
|
180 { |
|
181 static time_t disconnection_timestamp = 0L; |
|
182 time_t now; |
|
183 |
|
184 // Are we totally disconnected? |
|
185 if (jc && jc->state != JCONN_STATE_OFF) { |
|
186 disconnection_timestamp = 0L; |
|
187 return; |
|
188 } |
|
189 |
|
190 // Maybe we're voluntarily offline... |
|
191 if (!AutoConnection) |
|
192 return; |
|
193 |
|
194 time(&now); |
|
195 if (!disconnection_timestamp) { |
|
196 disconnection_timestamp = now; |
|
197 return; |
|
198 } |
|
199 |
|
200 // If the reconnection_timeout is reached, try to reconnect. |
|
201 if (now > disconnection_timestamp + RECONNECTION_TIMEOUT) { |
|
202 mcabber_connect(); |
|
203 disconnection_timestamp = 0L; |
|
204 } |
167 } |
205 } |
168 |
206 |
169 void jb_main() |
207 void jb_main() |
170 { |
208 { |
171 time_t now; |
209 time_t now; |
172 fd_set fds; |
210 fd_set fds; |
173 long timeout; |
211 long timeout; |
174 struct timeval tv; |
212 struct timeval tv; |
175 static time_t last_eviqs_check = 0; |
213 static time_t last_eviqs_check = 0L; |
176 |
214 |
177 if (!online) { |
215 if (!online) { |
178 safe_usleep(10000); |
216 safe_usleep(10000); |
|
217 check_connection(); |
179 return; |
218 return; |
180 } |
219 } |
181 |
220 |
182 if (jc && jc->state == JCONN_STATE_CONNECTING) { |
221 if (jc && jc->state == JCONN_STATE_CONNECTING) { |
183 safe_usleep(75000); |
222 safe_usleep(75000); |