Mercurial > pidgin
comparison libpurple/protocols/jabber/ibb.c @ 25733:51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Handle errors better in si.c
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Sun, 12 Oct 2008 17:41:26 +0000 |
parents | be762644486f |
children | 3918ed48d7a8 |
comparison
equal
deleted
inserted
replaced
25731:d6351b105e42 | 25733:51cbb9be484e |
---|---|
100 } | 100 } |
101 | 101 |
102 void | 102 void |
103 jabber_ibb_session_destroy(JabberIBBSession *sess) | 103 jabber_ibb_session_destroy(JabberIBBSession *sess) |
104 { | 104 { |
105 purple_debug_info("jabber", "IBB: destroying session %lx %s\n", sess, | 105 purple_debug_info("jabber", "IBB: destroying session %p %s\n", sess, |
106 sess->sid); | 106 sess->sid); |
107 | 107 |
108 if (jabber_ibb_session_get_state(sess) == JABBER_IBB_SESSION_OPENED) { | 108 if (jabber_ibb_session_get_state(sess) == JABBER_IBB_SESSION_OPENED) { |
109 jabber_ibb_session_close(sess); | 109 jabber_ibb_session_close(sess); |
110 } | 110 } |
111 | 111 |
112 purple_debug_info("jabber", "IBB: last_iq_id: %lx\n", sess->last_iq_id); | 112 purple_debug_info("jabber", "IBB: last_iq_id: %s\n", sess->last_iq_id); |
113 if (sess->last_iq_id) { | 113 if (sess->last_iq_id) { |
114 purple_debug_info("jabber", "IBB: removing callback for <iq/> %s\n", | 114 purple_debug_info("jabber", "IBB: removing callback for <iq/> %s\n", |
115 sess->last_iq_id); | 115 sess->last_iq_id); |
116 jabber_iq_remove_callback_by_id(jabber_ibb_session_get_js(sess), | 116 jabber_iq_remove_callback_by_id(jabber_ibb_session_get_js(sess), |
117 sess->last_iq_id); | 117 sess->last_iq_id); |
222 static void | 222 static void |
223 jabber_ibb_session_opened_cb(JabberStream *js, xmlnode *packet, gpointer data) | 223 jabber_ibb_session_opened_cb(JabberStream *js, xmlnode *packet, gpointer data) |
224 { | 224 { |
225 JabberIBBSession *sess = (JabberIBBSession *) data; | 225 JabberIBBSession *sess = (JabberIBBSession *) data; |
226 | 226 |
227 sess->state = JABBER_IBB_SESSION_OPENED; | 227 if (strcmp(xmlnode_get_attrib(packet, "type"), "error") == 0) { |
228 | 228 sess->state = JABBER_IBB_SESSION_ERROR; |
229 } else { | |
230 sess->state = JABBER_IBB_SESSION_OPENED; | |
231 } | |
232 | |
229 if (sess->opened_cb) { | 233 if (sess->opened_cb) { |
230 sess->opened_cb(sess); | 234 sess->opened_cb(sess); |
231 } | 235 } |
232 } | 236 } |
233 | 237 |
326 void | 330 void |
327 jabber_ibb_session_send_data(JabberIBBSession *sess, gpointer data, gsize size) | 331 jabber_ibb_session_send_data(JabberIBBSession *sess, gpointer data, gsize size) |
328 { | 332 { |
329 JabberIBBSessionState state = jabber_ibb_session_get_state(sess); | 333 JabberIBBSessionState state = jabber_ibb_session_get_state(sess); |
330 | 334 |
331 purple_debug_info("jabber", "sending data block of %d bytes on IBB stream\n", | 335 purple_debug_info("jabber", "sending data block of %ld bytes on IBB stream\n", |
332 size); | 336 size); |
333 | 337 |
334 if (state != JABBER_IBB_SESSION_OPENED) { | 338 if (state != JABBER_IBB_SESSION_OPENED) { |
335 purple_debug_error("jabber", | 339 purple_debug_error("jabber", |
336 "trying to send data on a non-open IBB session\n"); | 340 "trying to send data on a non-open IBB session\n"); |
352 xmlnode_insert_data(data_element, base64, strlen(base64)); | 356 xmlnode_insert_data(data_element, base64, strlen(base64)); |
353 | 357 |
354 xmlnode_insert_child(set->node, data_element); | 358 xmlnode_insert_child(set->node, data_element); |
355 | 359 |
356 purple_debug_info("jabber", | 360 purple_debug_info("jabber", |
357 "IBB: setting send <iq/> callback for session %lx %s\n", sess, | 361 "IBB: setting send <iq/> callback for session %p %s\n", sess, |
358 sess->sid); | 362 sess->sid); |
359 jabber_iq_set_callback(set, jabber_ibb_session_send_acknowledge_cb, sess); | 363 jabber_iq_set_callback(set, jabber_ibb_session_send_acknowledge_cb, sess); |
360 sess->last_iq_id = g_strdup(xmlnode_get_attrib(set->node, "id")); | 364 sess->last_iq_id = g_strdup(xmlnode_get_attrib(set->node, "id")); |
361 purple_debug_info("jabber", "IBB: set sess->last_iq_id: %lx %lx\n", | 365 purple_debug_info("jabber", "IBB: set sess->last_iq_id: %s %s\n", |
362 sess->last_iq_id, xmlnode_get_attrib(set->node, "id")); | 366 sess->last_iq_id, xmlnode_get_attrib(set->node, "id")); |
363 jabber_iq_send(set); | 367 jabber_iq_send(set); |
364 | 368 |
365 g_free(base64); | 369 g_free(base64); |
366 (sess->send_seq)++; | 370 (sess->send_seq)++; |
367 } | 371 } |
372 } | |
373 | |
374 static void | |
375 jabber_ibb_send_error_response(JabberStream *js, xmlnode *packet) | |
376 { | |
377 JabberIq *result = jabber_iq_new(js, JABBER_IQ_ERROR); | |
378 xmlnode *error = xmlnode_new("error"); | |
379 xmlnode *item_not_found = xmlnode_new("item-not-found"); | |
380 | |
381 xmlnode_set_namespace(item_not_found, | |
382 "urn:ietf:params:xml:ns:xmpp-stanzas"); | |
383 xmlnode_set_attrib(error, "code", "440"); | |
384 xmlnode_set_attrib(error, "type", "cancel"); | |
385 jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id")); | |
386 xmlnode_set_attrib(result->node, "to", | |
387 xmlnode_get_attrib(packet, "from")); | |
388 xmlnode_insert_child(error, item_not_found); | |
389 xmlnode_insert_child(result->node, error); | |
390 | |
391 jabber_iq_send(result); | |
368 } | 392 } |
369 | 393 |
370 void | 394 void |
371 jabber_ibb_parse(JabberStream *js, xmlnode *packet) | 395 jabber_ibb_parse(JabberStream *js, xmlnode *packet) |
372 { | 396 { |
410 | 434 |
411 g_free(base64); | 435 g_free(base64); |
412 | 436 |
413 if (rawdata) { | 437 if (rawdata) { |
414 purple_debug_info("jabber", | 438 purple_debug_info("jabber", |
415 "got %d bytes of data on IBB stream\n", size); | 439 "got %ld bytes of data on IBB stream\n", size); |
416 if (size > jabber_ibb_session_get_block_size(sess)) { | 440 if (size > jabber_ibb_session_get_block_size(sess)) { |
417 purple_debug_error("jabber", | 441 purple_debug_error("jabber", |
418 "IBB: received a too large packet\n"); | 442 "IBB: received a too large packet\n"); |
419 } else { | 443 } else { |
420 purple_debug_info("jabber", | 444 purple_debug_info("jabber", |
469 jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id")); | 493 jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id")); |
470 jabber_iq_send(result); | 494 jabber_iq_send(result); |
471 return; | 495 return; |
472 } | 496 } |
473 } | 497 } |
498 /* no open callback returned success, reject */ | |
499 jabber_ibb_send_error_response(js, packet); | |
474 } else { | 500 } else { |
475 /* send error reply */ | 501 /* send error reply */ |
476 JabberIq *result = jabber_iq_new(js, JABBER_IQ_ERROR); | 502 jabber_ibb_send_error_response(js, packet); |
477 xmlnode *error = xmlnode_new("error"); | |
478 xmlnode *item_not_found = xmlnode_new("item-not-found"); | |
479 | |
480 xmlnode_set_namespace(item_not_found, | |
481 "urn:ietf:params:xml:ns:xmpp-stanzas"); | |
482 xmlnode_set_attrib(error, "code", "440"); | |
483 xmlnode_set_attrib(error, "type", "cancel"); | |
484 jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id")); | |
485 xmlnode_set_attrib(result->node, "to", | |
486 xmlnode_get_attrib(packet, "from")); | |
487 xmlnode_insert_child(error, item_not_found); | |
488 xmlnode_insert_child(result->node, error); | |
489 | |
490 jabber_iq_send(result); | |
491 } | 503 } |
492 } | 504 } |
493 | 505 |
494 void | 506 void |
495 jabber_ibb_register_open_handler(JabberIBBOpenHandler *cb) | 507 jabber_ibb_register_open_handler(JabberIBBOpenHandler *cb) |