Mercurial > pidgin
comparison libgaim/protocols/oscar/peer.c @ 14402:648e33275d9d
[gaim-migrate @ 17110]
Make peer disconnection error messages a little better for oscar ft and
direct connect
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 01 Sep 2006 08:52:23 +0000 |
parents | 80b05108652c |
children | 118fd0dc5b6e |
comparison
equal
deleted
inserted
replaced
14401:4f51b45f4f70 | 14402:648e33275d9d |
---|---|
217 } | 217 } |
218 gaim_xfer_unref(conn->xfer); | 218 gaim_xfer_unref(conn->xfer); |
219 conn->xfer = NULL; | 219 conn->xfer = NULL; |
220 } | 220 } |
221 | 221 |
222 g_free(conn->sn); | |
223 g_free(conn->error_message); | |
222 g_free(conn->proxyip); | 224 g_free(conn->proxyip); |
223 g_free(conn->clientip); | 225 g_free(conn->clientip); |
224 g_free(conn->verifiedip); | 226 g_free(conn->verifiedip); |
225 gaim_circ_buffer_destroy(conn->buffer_outgoing); | 227 gaim_circ_buffer_destroy(conn->buffer_outgoing); |
226 | 228 |
230 | 232 |
231 return FALSE; | 233 return FALSE; |
232 } | 234 } |
233 | 235 |
234 void | 236 void |
235 peer_connection_destroy(PeerConnection *conn, OscarDisconnectReason reason) | 237 peer_connection_destroy(PeerConnection *conn, OscarDisconnectReason reason, const gchar *error_message) |
236 { | 238 { |
237 conn->disconnect_reason = reason; | |
238 if (conn->destroy_timeout != 0) | 239 if (conn->destroy_timeout != 0) |
239 gaim_timeout_remove(conn->destroy_timeout); | 240 gaim_timeout_remove(conn->destroy_timeout); |
241 conn->disconnect_reason = reason; | |
242 g_free(conn->error_message); | |
243 conn->error_message = g_strdup(error_message); | |
240 peer_connection_destroy_cb(conn); | 244 peer_connection_destroy_cb(conn); |
241 } | 245 } |
242 | 246 |
243 void | 247 void |
244 peer_connection_schedule_destroy(PeerConnection *conn, OscarDisconnectReason reason) | 248 peer_connection_schedule_destroy(PeerConnection *conn, OscarDisconnectReason reason, const gchar *error_message) |
245 { | 249 { |
246 if (conn->destroy_timeout != 0) | 250 if (conn->destroy_timeout != 0) |
247 /* Already taken care of */ | 251 /* Already taken care of */ |
248 return; | 252 return; |
249 | 253 |
250 gaim_debug_info("oscar", "Scheduling destruction of peer connection\n"); | 254 gaim_debug_info("oscar", "Scheduling destruction of peer connection\n"); |
251 conn->disconnect_reason = reason; | 255 conn->disconnect_reason = reason; |
256 g_free(conn->error_message); | |
257 conn->error_message = g_strdup(error_message); | |
252 conn->destroy_timeout = gaim_timeout_add(0, peer_connection_destroy_cb, conn); | 258 conn->destroy_timeout = gaim_timeout_add(0, peer_connection_destroy_cb, conn); |
253 } | 259 } |
254 | 260 |
255 /*******************************************************************/ | 261 /*******************************************************************/ |
256 /* Begin code for receiving data on a peer connection */ | 262 /* Begin code for receiving data on a peer connection */ |
287 read = recv(conn->fd, &header, 6, MSG_PEEK); | 293 read = recv(conn->fd, &header, 6, MSG_PEEK); |
288 | 294 |
289 /* Check if the remote user closed the connection */ | 295 /* Check if the remote user closed the connection */ |
290 if (read == 0) | 296 if (read == 0) |
291 { | 297 { |
292 peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED); | 298 peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED, NULL); |
293 return; | 299 return; |
294 } | 300 } |
295 | 301 |
296 /* If there was an error then close the connection */ | 302 /* If there was an error then close the connection */ |
297 if (read == -1) | 303 if (read == -1) |
298 { | 304 { |
299 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | 305 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
300 /* No worries */ | 306 /* No worries */ |
301 return; | 307 return; |
302 | 308 |
303 peer_connection_destroy(conn, OSCAR_DISCONNECT_LOST_CONNECTION); | 309 peer_connection_destroy(conn, |
310 OSCAR_DISCONNECT_LOST_CONNECTION, strerror(errno)); | |
304 return; | 311 return; |
305 } | 312 } |
306 | 313 |
307 conn->lastactivity = time(NULL); | 314 conn->lastactivity = time(NULL); |
308 | 315 |
319 gaim_debug_warning("oscar", "Expecting magic string to " | 326 gaim_debug_warning("oscar", "Expecting magic string to " |
320 "be %c%c%c%c but received magic string %c%c%c%c. " | 327 "be %c%c%c%c but received magic string %c%c%c%c. " |
321 "Closing connection.\n", | 328 "Closing connection.\n", |
322 conn->magic[0], conn->magic[1], conn->magic[2], | 329 conn->magic[0], conn->magic[1], conn->magic[2], |
323 conn->magic[3], header[0], header[1], header[2], header[3]); | 330 conn->magic[3], header[0], header[1], header[2], header[3]); |
324 peer_connection_destroy(conn, OSCAR_DISCONNECT_INVALID_DATA); | 331 peer_connection_destroy(conn, OSCAR_DISCONNECT_INVALID_DATA, NULL); |
325 return; | 332 return; |
326 } | 333 } |
327 | 334 |
328 /* Initialize a new temporary ByteStream for incoming data */ | 335 /* Initialize a new temporary ByteStream for incoming data */ |
329 conn->buffer_incoming.len = aimutil_get16(&header[4]) - 6; | 336 conn->buffer_incoming.len = aimutil_get16(&header[4]) - 6; |
338 0); | 345 0); |
339 | 346 |
340 /* Check if the remote user closed the connection */ | 347 /* Check if the remote user closed the connection */ |
341 if (read == 0) | 348 if (read == 0) |
342 { | 349 { |
343 peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED); | 350 peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED, NULL); |
344 return; | 351 return; |
345 } | 352 } |
346 | 353 |
347 if (read == -1) | 354 if (read == -1) |
348 { | 355 { |
349 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | 356 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
350 /* No worries */ | 357 /* No worries */ |
351 return; | 358 return; |
352 | 359 |
353 peer_connection_destroy(conn, OSCAR_DISCONNECT_LOST_CONNECTION); | 360 peer_connection_destroy(conn, |
361 OSCAR_DISCONNECT_LOST_CONNECTION, strerror(errno)); | |
354 return; | 362 return; |
355 } | 363 } |
356 | 364 |
357 conn->lastactivity = time(NULL); | 365 conn->lastactivity = time(NULL); |
358 conn->buffer_incoming.offset += read; | 366 conn->buffer_incoming.offset += read; |
405 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | 413 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
406 /* No worries */ | 414 /* No worries */ |
407 return; | 415 return; |
408 | 416 |
409 if (conn->ready) | 417 if (conn->ready) |
410 peer_connection_schedule_destroy(conn, OSCAR_DISCONNECT_LOST_CONNECTION); | 418 peer_connection_schedule_destroy(conn, |
419 OSCAR_DISCONNECT_LOST_CONNECTION, NULL); | |
411 else | 420 else |
412 { | 421 { |
413 /* | 422 /* |
414 * This could happen when unable to send a negotiation | 423 * This could happen when unable to send a negotiation |
415 * frame to a peer proxy server. | 424 * frame to a peer proxy server. |
808 return; | 817 return; |
809 } | 818 } |
810 } | 819 } |
811 | 820 |
812 /* Give up! */ | 821 /* Give up! */ |
813 peer_connection_destroy(conn, OSCAR_DISCONNECT_COULD_NOT_CONNECT); | 822 peer_connection_destroy(conn, OSCAR_DISCONNECT_COULD_NOT_CONNECT, NULL); |
814 } | 823 } |
815 | 824 |
816 /** | 825 /** |
817 * Initiate a peer connection with someone. | 826 * Initiate a peer connection with someone. |
818 */ | 827 */ |
840 gaim_conversation_present(conv); | 849 gaim_conversation_present(conv); |
841 return; | 850 return; |
842 } | 851 } |
843 | 852 |
844 /* Cancel the old connection and try again */ | 853 /* Cancel the old connection and try again */ |
845 peer_connection_destroy(conn, OSCAR_DISCONNECT_RETRYING); | 854 peer_connection_destroy(conn, OSCAR_DISCONNECT_RETRYING, NULL); |
846 } | 855 } |
847 } | 856 } |
848 | 857 |
849 conn = peer_connection_new(od, type, sn); | 858 conn = peer_connection_new(od, type, sn); |
850 conn->flags |= PEER_CONNECTION_FLAG_INITIATED_BY_ME; | 859 conn->flags |= PEER_CONNECTION_FLAG_INITIATED_BY_ME; |
883 | 892 |
884 conn = data; | 893 conn = data; |
885 | 894 |
886 aim_im_denytransfer(conn->od, conn->sn, conn->cookie, | 895 aim_im_denytransfer(conn->od, conn->sn, conn->cookie, |
887 AIM_TRANSFER_DENY_DECLINE); | 896 AIM_TRANSFER_DENY_DECLINE); |
888 peer_connection_destroy(conn, OSCAR_DISCONNECT_LOCAL_CLOSED); | 897 peer_connection_destroy(conn, OSCAR_DISCONNECT_LOCAL_CLOSED, NULL); |
889 } | 898 } |
890 | 899 |
891 /** | 900 /** |
892 * Someone else wants to establish a peer connection with us. | 901 * Someone else wants to establish a peer connection with us. |
893 */ | 902 */ |
936 if (conn != NULL) | 945 if (conn != NULL) |
937 { | 946 { |
938 /* Close the old direct IM and start a new one */ | 947 /* Close the old direct IM and start a new one */ |
939 gaim_debug_info("oscar", "Received new direct IM request " | 948 gaim_debug_info("oscar", "Received new direct IM request " |
940 "from %s. Destroying old connection.\n", sn); | 949 "from %s. Destroying old connection.\n", sn); |
941 peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED); | 950 peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED, NULL); |
942 } | 951 } |
943 } | 952 } |
944 | 953 |
945 /* Check for proper arguments */ | 954 /* Check for proper arguments */ |
946 if (args->type == OSCAR_CAPABILITY_SENDFILE) | 955 if (args->type == OSCAR_CAPABILITY_SENDFILE) |