comparison libpurple/protocols/msn/servconn.c @ 27646:8e31eec7b621

Propagate connect errors from the MSN proxy callback to the servconn error handling function so that the real proxy error is displayed instead of a generic "Connect Error". Fixes #8280.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Tue, 21 Jul 2009 04:31:27 +0000
parents 97ba0d9e6e54
children 33856dfb5cbf
comparison
equal deleted inserted replaced
27645:97ba0d9e6e54 27646:8e31eec7b621
121 /************************************************************************** 121 /**************************************************************************
122 * Utility 122 * Utility
123 **************************************************************************/ 123 **************************************************************************/
124 124
125 void 125 void
126 msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error) 126 msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error,
127 const char *reason)
127 { 128 {
128 MsnSession *session = servconn->session; 129 MsnSession *session = servconn->session;
129 MsnServConnType type = servconn->type; 130 MsnServConnType type = servconn->type;
130 const char *reason;
131 131
132 const char *names[] = { "Notification", "Switchboard" }; 132 const char *names[] = { "Notification", "Switchboard" };
133 const char *name; 133 const char *name;
134 134
135 name = names[type]; 135 name = names[type];
136 136
137 switch (error) 137 if (reason == NULL) {
138 { 138 switch (error)
139 case MSN_SERVCONN_ERROR_CONNECT: 139 {
140 reason = _("Unable to connect"); break; 140 case MSN_SERVCONN_ERROR_CONNECT:
141 case MSN_SERVCONN_ERROR_WRITE: 141 reason = _("Unable to connect"); break;
142 reason = _("Writing error"); break; 142 case MSN_SERVCONN_ERROR_WRITE:
143 case MSN_SERVCONN_ERROR_READ: 143 reason = _("Writing error"); break;
144 reason = _("Reading error"); break; 144 case MSN_SERVCONN_ERROR_READ:
145 default: 145 reason = _("Reading error"); break;
146 reason = _("Unknown error"); break; 146 default:
147 reason = _("Unknown error"); break;
148 }
147 } 149 }
148 150
149 purple_debug_error("msn", "Connection error from %s server (%s): %s\n", 151 purple_debug_error("msn", "Connection error from %s server (%s): %s\n",
150 name, servconn->host, reason); 152 name, servconn->host, reason);
151 153
194 servconn_timeout_renew(servconn); 196 servconn_timeout_renew(servconn);
195 } 197 }
196 else 198 else
197 { 199 {
198 purple_debug_error("msn", "Connection error: %s\n", error_message); 200 purple_debug_error("msn", "Connection error: %s\n", error_message);
199 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_CONNECT); 201 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_CONNECT, error_message);
200 } 202 }
201 } 203 }
202 204
203 gboolean 205 gboolean
204 msn_servconn_connect(MsnServConn *servconn, const char *host, int port, gboolean force) 206 msn_servconn_connect(MsnServConn *servconn, const char *host, int port, gboolean force)
342 ret = write(servconn->fd, servconn->tx_buf->outptr, writelen); 344 ret = write(servconn->fd, servconn->tx_buf->outptr, writelen);
343 345
344 if (ret < 0 && errno == EAGAIN) 346 if (ret < 0 && errno == EAGAIN)
345 return; 347 return;
346 else if (ret <= 0) { 348 else if (ret <= 0) {
347 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE); 349 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE, NULL);
348 return; 350 return;
349 } 351 }
350 352
351 purple_circ_buffer_mark_read(servconn->tx_buf, ret); 353 purple_circ_buffer_mark_read(servconn->tx_buf, ret);
352 servconn_timeout_renew(servconn); 354 servconn_timeout_renew(servconn);
399 ret = msn_httpconn_write(servconn->httpconn, buf, len); 401 ret = msn_httpconn_write(servconn->httpconn, buf, len);
400 } 402 }
401 403
402 if (ret == -1) 404 if (ret == -1)
403 { 405 {
404 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE); 406 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE, NULL);
405 } 407 }
406 408
407 servconn_timeout_renew(servconn); 409 servconn_timeout_renew(servconn);
408 return ret; 410 return ret;
409 } 411 }
425 return; 427 return;
426 if (len <= 0) { 428 if (len <= 0) {
427 purple_debug_error("msn", "servconn %03d read error, " 429 purple_debug_error("msn", "servconn %03d read error, "
428 "len: %" G_GSSIZE_FORMAT ", errno: %d, error: %s\n", 430 "len: %" G_GSSIZE_FORMAT ", errno: %d, error: %s\n",
429 servconn->num, len, errno, g_strerror(errno)); 431 servconn->num, len, errno, g_strerror(errno));
430 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ); 432 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ, NULL);
431 433
432 return; 434 return;
433 } 435 }
434 436
435 buf[len] = '\0'; 437 buf[len] = '\0';