28
28
static void read_cb(gpointer data, gint source, PurpleInputCondition cond);
29
static void servconn_timeout_renew(MsnServConn *servconn);
30
31
/**************************************************************************
82
85
purple_circ_buffer_destroy(servconn->tx_buf);
83
86
if (servconn->tx_handler > 0)
84
87
purple_input_remove(servconn->tx_handler);
88
if (servconn->timeout_handle > 0)
89
purple_input_remove(servconn->timeout_handle);
86
91
msn_cmdproc_destroy(servconn->cmdproc);
118
123
**************************************************************************/
121
msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error)
126
msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error,
129
MsnSession *session = servconn->session;
130
MsnServConnType type = servconn->type;
126
132
const char *names[] = { "Notification", "Switchboard" };
127
133
const char *name;
129
name = names[servconn->type];
133
case MSN_SERVCONN_ERROR_CONNECT:
134
reason = _("Unable to connect"); break;
135
case MSN_SERVCONN_ERROR_WRITE:
136
reason = _("Writing error"); break;
137
case MSN_SERVCONN_ERROR_READ:
138
reason = _("Reading error"); break;
140
reason = _("Unknown error"); break;
137
if (reason == NULL) {
140
case MSN_SERVCONN_ERROR_CONNECT:
141
reason = _("Unable to connect"); break;
142
case MSN_SERVCONN_ERROR_WRITE:
143
reason = _("Writing error"); break;
144
case MSN_SERVCONN_ERROR_READ:
145
reason = _("Reading error"); break;
147
reason = _("Unknown error"); break;
143
151
purple_debug_error("msn", "Connection error from %s server (%s): %s\n",
144
152
name, servconn->host, reason);
145
tmp = g_strdup_printf(_("Connection error from %s server:\n%s"),
148
if (servconn->type == MSN_SERVCONN_NS)
150
msn_session_set_error(servconn->session, MSN_ERROR_SERVCONN, tmp);
152
else if (servconn->type == MSN_SERVCONN_SB)
154
if (type == MSN_SERVCONN_SB)
154
156
MsnSwitchBoard *swboard;
155
157
swboard = servconn->cmdproc->data;
157
159
swboard->error = MSN_SB_ERROR_CONNECTION;
162
/* servconn->disconnect_cb may destroy servconn, so don't use it again */
160
163
msn_servconn_disconnect(servconn);
165
if (type == MSN_SERVCONN_NS)
167
char *tmp = g_strdup_printf(_("Connection error from %s server:\n%s"),
169
msn_session_set_error(session, MSN_ERROR_SERVCONN, tmp);
165
174
/**************************************************************************
184
193
servconn->connect_cb(servconn);
185
194
servconn->inpa = purple_input_add(servconn->fd, PURPLE_INPUT_READ,
196
servconn_timeout_renew(servconn);
190
200
purple_debug_error("msn", "Connection error: %s\n", error_message);
191
msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_CONNECT);
201
msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_CONNECT, error_message);
220
230
servconn->connected = TRUE;
221
231
servconn->httpconn->virgin = TRUE;
232
servconn_timeout_renew(servconn);
223
234
/* Someone wants to know we connected. */
224
235
servconn->connect_cb(servconn);
279
296
servconn->disconnect_cb(servconn);
300
servconn_idle_timeout_cb(MsnServConn *servconn)
302
msn_servconn_disconnect(servconn);
303
servconn->timeout_handle = 0;
308
servconn_timeout_renew(MsnServConn *servconn)
310
if (servconn->timeout_handle) {
311
purple_input_remove(servconn->timeout_handle);
312
servconn->timeout_handle = 0;
315
if (servconn->connected && servconn->timeout_sec) {
316
servconn->timeout_handle = purple_timeout_add_seconds(
317
servconn->timeout_sec, (GSourceFunc)servconn_idle_timeout_cb, servconn);
322
msn_servconn_set_idle_timeout(MsnServConn *servconn, guint seconds)
324
servconn->timeout_sec = seconds;
325
if (servconn->connected)
326
servconn_timeout_renew(servconn);
283
330
servconn_write_cb(gpointer data, gint source, PurpleInputCondition cond)
299
346
if (ret < 0 && errno == EAGAIN)
301
348
else if (ret <= 0) {
302
msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE);
349
msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE, NULL);
306
353
purple_circ_buffer_mark_read(servconn->tx_buf, ret);
354
servconn_timeout_renew(servconn);
358
msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE);
406
msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE, NULL);
409
servconn_timeout_renew(servconn);
380
429
purple_debug_error("msn", "servconn %03d read error, "
381
430
"len: %" G_GSSIZE_FORMAT ", errno: %d, error: %s\n",
382
431
servconn->num, len, errno, g_strerror(errno));
383
msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ);
432
msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ, NULL);