~vish/ubuntu/maverick/pidgin/bug25979

« back to all changes in this revision

Viewing changes to libpurple/protocols/msn/servconn.c

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-10-09 19:40:26 UTC
  • mfrom: (1.4.1 upstream) (46.1.10 karmic)
  • Revision ID: james.westby@ubuntu.com-20091009194026-wbqqh0bsbz19nx5q
Tags: 1:2.6.2-1ubuntu7
* Don't stick the buddy list window to all desktops as some
  window managers have trouble to properly unstick it (LP: #346840)
  - debian/patches/11_buddy_list_really_show.patch
* Always use default tray icon size on KDE (LP: #209440)
  - debian/patches/62_tray_icon_size_kde.patch
* Use scrollbars in the preferences dialog if the screen height is
  below 700 px instead of 600 px
  - debian/patches/60_1024x600_gtkprefs.c.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "error.h"
27
27
 
28
28
static void read_cb(gpointer data, gint source, PurpleInputCondition cond);
 
29
static void servconn_timeout_renew(MsnServConn *servconn);
29
30
 
30
31
/**************************************************************************
31
32
 * Main
52
53
 
53
54
        servconn->tx_buf = purple_circ_buffer_new(MSN_BUF_LEN);
54
55
        servconn->tx_handler = 0;
 
56
        servconn->timeout_sec = 0;
 
57
        servconn->timeout_handle = 0;
55
58
 
56
59
        servconn->fd = -1;
57
60
 
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);
85
90
 
86
91
        msn_cmdproc_destroy(servconn->cmdproc);
87
92
        g_free(servconn);
118
123
 **************************************************************************/
119
124
 
120
125
void
121
 
msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error)
 
126
msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error,
 
127
                       const char *reason)
122
128
{
123
 
        char *tmp;
124
 
        const char *reason;
 
129
        MsnSession *session = servconn->session;
 
130
        MsnServConnType type = servconn->type;
125
131
 
126
132
        const char *names[] = { "Notification", "Switchboard" };
127
133
        const char *name;
128
134
 
129
 
        name = names[servconn->type];
 
135
        name = names[type];
130
136
 
131
 
        switch (error)
132
 
        {
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;
139
 
                default:
140
 
                        reason = _("Unknown error"); break;
 
137
        if (reason == NULL) {
 
138
                switch (error)
 
139
                {
 
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;
 
146
                        default:
 
147
                                reason = _("Unknown error"); break;
 
148
                }
141
149
        }
142
150
 
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"),
146
 
                                                  name, reason);
147
153
 
148
 
        if (servconn->type == MSN_SERVCONN_NS)
149
 
        {
150
 
                msn_session_set_error(servconn->session, MSN_ERROR_SERVCONN, tmp);
151
 
        }
152
 
        else if (servconn->type == MSN_SERVCONN_SB)
 
154
        if (type == MSN_SERVCONN_SB)
153
155
        {
154
156
                MsnSwitchBoard *swboard;
155
157
                swboard = servconn->cmdproc->data;
157
159
                        swboard->error = MSN_SB_ERROR_CONNECTION;
158
160
        }
159
161
 
 
162
        /* servconn->disconnect_cb may destroy servconn, so don't use it again */
160
163
        msn_servconn_disconnect(servconn);
161
164
 
162
 
        g_free(tmp);
 
165
        if (type == MSN_SERVCONN_NS)
 
166
        {
 
167
                char *tmp = g_strdup_printf(_("Connection error from %s server:\n%s"),
 
168
                                            name, reason);
 
169
                msn_session_set_error(session, MSN_ERROR_SERVCONN, tmp);
 
170
                g_free(tmp);
 
171
        }
163
172
}
164
173
 
165
174
/**************************************************************************
184
193
                servconn->connect_cb(servconn);
185
194
                servconn->inpa = purple_input_add(servconn->fd, PURPLE_INPUT_READ,
186
195
                        read_cb, data);
 
196
                servconn_timeout_renew(servconn);
187
197
        }
188
198
        else
189
199
        {
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);
192
202
        }
193
203
}
194
204
 
219
229
 
220
230
                servconn->connected = TRUE;
221
231
                servconn->httpconn->virgin = TRUE;
 
232
                servconn_timeout_renew(servconn);
222
233
 
223
234
                /* Someone wants to know we connected. */
224
235
                servconn->connect_cb(servconn);
267
278
                servconn->inpa = 0;
268
279
        }
269
280
 
 
281
        if (servconn->timeout_handle > 0)
 
282
        {
 
283
                purple_input_remove(servconn->timeout_handle);
 
284
                servconn->timeout_handle = 0;
 
285
        }
 
286
 
270
287
        close(servconn->fd);
271
288
 
272
289
        servconn->rx_buf = NULL;
279
296
                servconn->disconnect_cb(servconn);
280
297
}
281
298
 
 
299
static gboolean
 
300
servconn_idle_timeout_cb(MsnServConn *servconn)
 
301
{
 
302
        msn_servconn_disconnect(servconn);
 
303
        servconn->timeout_handle = 0;
 
304
        return FALSE;
 
305
}
 
306
 
 
307
static void
 
308
servconn_timeout_renew(MsnServConn *servconn)
 
309
{
 
310
        if (servconn->timeout_handle) {
 
311
                purple_input_remove(servconn->timeout_handle);
 
312
                servconn->timeout_handle = 0;
 
313
        }
 
314
 
 
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);
 
318
        }
 
319
}
 
320
 
 
321
void
 
322
msn_servconn_set_idle_timeout(MsnServConn *servconn, guint seconds)
 
323
{
 
324
        servconn->timeout_sec = seconds;
 
325
        if (servconn->connected)
 
326
                servconn_timeout_renew(servconn);
 
327
}
 
328
 
282
329
static void
283
330
servconn_write_cb(gpointer data, gint source, PurpleInputCondition cond)
284
331
{
299
346
        if (ret < 0 && errno == EAGAIN)
300
347
                return;
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);
303
350
                return;
304
351
        }
305
352
 
306
353
        purple_circ_buffer_mark_read(servconn->tx_buf, ret);
 
354
        servconn_timeout_renew(servconn);
307
355
}
308
356
 
309
357
gssize
355
403
 
356
404
        if (ret == -1)
357
405
        {
358
 
                msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE);
 
406
                msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE, NULL);
359
407
        }
360
408
 
 
409
        servconn_timeout_renew(servconn);
361
410
        return ret;
362
411
}
363
412
 
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);
384
433
 
385
434
                return;
386
435
        }
392
441
        servconn->rx_len += len;
393
442
 
394
443
        msn_servconn_process_data(servconn);
 
444
        servconn_timeout_renew(servconn);
395
445
}
396
446
 
397
447
void msn_servconn_process_data(MsnServConn *servconn)