Mercurial > pidgin.yaz
comparison libpurple/protocols/bonjour/bonjour_ft.c @ 23020:ef0bcbe33689
applied changes from 3d595739f53a259d5dae408a05f64d2836f02ac9
through 05cdb341d2bf5165ab95cc42e52750624f0a7ad9
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Thu, 19 Jun 2008 02:56:37 +0000 |
parents | 3225c99785b8 |
children | aaaff38e144f |
comparison
equal
deleted
inserted
replaced
23019:adbcf5b84438 | 23020:ef0bcbe33689 |
---|---|
45 static unsigned int next_id = 0; | 45 static unsigned int next_id = 0; |
46 | 46 |
47 static void | 47 static void |
48 xep_ft_si_reject(BonjourData *bd, const char *id, const char *to, const char *error_code, const char *error_type) | 48 xep_ft_si_reject(BonjourData *bd, const char *id, const char *to, const char *error_code, const char *error_type) |
49 { | 49 { |
50 xmlnode *error_node = NULL; | 50 xmlnode *error_node; |
51 xmlnode *tmp_node = NULL; | 51 XepIq *iq; |
52 XepIq *iq = NULL; | |
53 | 52 |
54 g_return_if_fail(error_code != NULL); | 53 g_return_if_fail(error_code != NULL); |
55 g_return_if_fail(error_type != NULL); | 54 g_return_if_fail(error_type != NULL); |
56 | 55 |
57 if(!to || !id) | 56 if(!to || !id) |
66 xmlnode_set_attrib(error_node, "code", error_code); | 65 xmlnode_set_attrib(error_node, "code", error_code); |
67 xmlnode_set_attrib(error_node, "type", error_type); | 66 xmlnode_set_attrib(error_node, "type", error_type); |
68 | 67 |
69 /* TODO: Make this better */ | 68 /* TODO: Make this better */ |
70 if (!strcmp(error_code, "403")) { | 69 if (!strcmp(error_code, "403")) { |
71 tmp_node = xmlnode_new_child(error_node, "forbidden"); | 70 xmlnode *tmp_node = xmlnode_new_child(error_node, "forbidden"); |
72 xmlnode_set_namespace(tmp_node, "urn:ietf:params:xml:ns:xmpp-stanzas"); | 71 xmlnode_set_namespace(tmp_node, "urn:ietf:params:xml:ns:xmpp-stanzas"); |
73 | 72 |
74 tmp_node = xmlnode_new_child(error_node, "text"); | 73 tmp_node = xmlnode_new_child(error_node, "text"); |
75 xmlnode_set_namespace(tmp_node, "urn:ietf:params:xml:ns:xmpp-stanzas"); | 74 xmlnode_set_namespace(tmp_node, "urn:ietf:params:xml:ns:xmpp-stanzas"); |
76 xmlnode_insert_data(tmp_node, "Offer Declined", -1); | 75 xmlnode_insert_data(tmp_node, "Offer Declined", -1); |
77 } else if (!strcmp(error_code, "404")) { | 76 } else if (!strcmp(error_code, "404")) { |
78 tmp_node = xmlnode_new_child(error_node, "item-not-found"); | 77 xmlnode *tmp_node = xmlnode_new_child(error_node, "item-not-found"); |
79 xmlnode_set_namespace(tmp_node, "urn:ietf:params:xml:ns:xmpp-stanzas"); | 78 xmlnode_set_namespace(tmp_node, "urn:ietf:params:xml:ns:xmpp-stanzas"); |
80 } | 79 } |
81 | 80 |
82 xep_iq_send_and_free(iq); | 81 xep_iq_send_and_free(iq); |
83 } | 82 } |
88 bonjour_free_xfer(xfer); | 87 bonjour_free_xfer(xfer); |
89 } | 88 } |
90 | 89 |
91 static void bonjour_xfer_request_denied(PurpleXfer *xfer) | 90 static void bonjour_xfer_request_denied(PurpleXfer *xfer) |
92 { | 91 { |
93 XepXfer *xf = NULL; | 92 XepXfer *xf = xfer->data; |
94 | 93 |
95 purple_debug_info("bonjour", "Bonjour-xfer-request-denied.\n"); | 94 purple_debug_info("bonjour", "Bonjour-xfer-request-denied.\n"); |
96 | 95 |
97 xf = xfer->data; | |
98 if(xf) | 96 if(xf) |
99 xep_ft_si_reject(xf->data, xf->sid, xfer->who, "403", "cancel"); | 97 xep_ft_si_reject(xf->data, xf->sid, xfer->who, "403", "cancel"); |
100 | 98 |
101 bonjour_free_xfer(xfer); | 99 bonjour_free_xfer(xfer); |
102 } | 100 } |
147 } | 145 } |
148 | 146 |
149 static PurpleXfer* | 147 static PurpleXfer* |
150 bonjour_si_xfer_find(BonjourData *bd, const char *sid, const char *from) | 148 bonjour_si_xfer_find(BonjourData *bd, const char *sid, const char *from) |
151 { | 149 { |
152 GSList *xfers = NULL; | 150 GSList *xfers; |
153 PurpleXfer *xfer = NULL; | 151 PurpleXfer *xfer; |
154 XepXfer *xf = NULL; | 152 XepXfer *xf; |
155 | 153 |
156 if(!sid || !from || !bd) | 154 if(!sid || !from || !bd) |
157 return NULL; | 155 return NULL; |
158 | 156 |
159 purple_debug_info("bonjour", "Look for sid=%s from=%s xferlists.\n", | 157 purple_debug_info("bonjour", "Look for sid=%s from=%s xferlists.\n", |
177 } | 175 } |
178 | 176 |
179 static void | 177 static void |
180 xep_ft_si_offer(PurpleXfer *xfer, const gchar *to) | 178 xep_ft_si_offer(PurpleXfer *xfer, const gchar *to) |
181 { | 179 { |
182 xmlnode *si_node = NULL; | 180 xmlnode *si_node, *feature, *field, *file, *x; |
183 xmlnode *feature = NULL; | 181 XepIq *iq; |
184 xmlnode *field = NULL; | 182 XepXfer *xf = xfer->data; |
185 xmlnode *option = NULL; | |
186 xmlnode *value = NULL; | |
187 xmlnode *file = NULL; | |
188 xmlnode *x = NULL; | |
189 XepIq *iq = NULL; | |
190 XepXfer *xf = NULL; | |
191 BonjourData *bd = NULL; | 183 BonjourData *bd = NULL; |
192 char buf[32]; | 184 char buf[32]; |
193 | 185 |
194 xf = xfer->data; | |
195 if(!xf) | 186 if(!xf) |
196 return; | 187 return; |
197 | 188 |
198 bd = xf->data; | 189 bd = xf->data; |
199 if(!bd) | 190 if(!bd) |
232 field = xmlnode_new_child(x, "field"); | 223 field = xmlnode_new_child(x, "field"); |
233 xmlnode_set_attrib(field, "var", "stream-method"); | 224 xmlnode_set_attrib(field, "var", "stream-method"); |
234 xmlnode_set_attrib(field, "type", "list-single"); | 225 xmlnode_set_attrib(field, "type", "list-single"); |
235 | 226 |
236 if (xf->mode & XEP_BYTESTREAMS) { | 227 if (xf->mode & XEP_BYTESTREAMS) { |
237 option = xmlnode_new_child(field, "option"); | 228 xmlnode *option = xmlnode_new_child(field, "option"); |
238 value = xmlnode_new_child(option, "value"); | 229 xmlnode *value = xmlnode_new_child(option, "value"); |
239 xmlnode_insert_data(value, "http://jabber.org/protocol/bytestreams", -1); | 230 xmlnode_insert_data(value, "http://jabber.org/protocol/bytestreams", -1); |
240 } | 231 } |
241 if (xf->mode & XEP_IBB) { | 232 if (xf->mode & XEP_IBB) { |
242 option = xmlnode_new_child(field, "option"); | 233 xmlnode *option = xmlnode_new_child(field, "option"); |
243 value = xmlnode_new_child(option, "value"); | 234 xmlnode *value = xmlnode_new_child(option, "value"); |
244 xmlnode_insert_data(value, "http://jabber.org/protocol/ibb", -1); | 235 xmlnode_insert_data(value, "http://jabber.org/protocol/ibb", -1); |
245 } | 236 } |
246 | 237 |
247 xep_iq_send_and_free(iq); | 238 xep_iq_send_and_free(iq); |
248 } | 239 } |
249 | 240 |
250 static void | 241 static void |
251 xep_ft_si_result(PurpleXfer *xfer, char *to) | 242 xep_ft_si_result(PurpleXfer *xfer, char *to) |
252 { | 243 { |
253 xmlnode *si_node = NULL; | 244 xmlnode *si_node, *feature, *field, *value, *x; |
254 xmlnode *feature = NULL; | 245 XepIq *iq; |
255 xmlnode *field = NULL; | 246 XepXfer *xf; |
256 xmlnode *value = NULL; | |
257 xmlnode *x = NULL; | |
258 XepIq *iq = NULL; | |
259 XepXfer *xf = NULL; | |
260 BonjourData *bd; | 247 BonjourData *bd; |
261 | 248 |
262 if(!to || !xfer) | 249 if(!to || !xfer) |
263 return; | 250 return; |
264 xf = xfer->data; | 251 xf = xfer->data; |
293 } | 280 } |
294 | 281 |
295 static void | 282 static void |
296 bonjour_free_xfer(PurpleXfer *xfer) | 283 bonjour_free_xfer(PurpleXfer *xfer) |
297 { | 284 { |
298 XepXfer *xf = NULL; | 285 XepXfer *xf; |
299 BonjourData *bd = NULL; | |
300 | 286 |
301 if(xfer == NULL) { | 287 if(xfer == NULL) { |
302 purple_debug_info("bonjour", "bonjour-free-xfer-null.\n"); | 288 purple_debug_info("bonjour", "bonjour-free-xfer-null.\n"); |
303 return; | 289 return; |
304 } | 290 } |
305 | 291 |
306 purple_debug_info("bonjour", "bonjour-free-xfer-%p.\n", xfer); | 292 purple_debug_info("bonjour", "bonjour-free-xfer-%p.\n", xfer); |
307 | 293 |
308 xf = (XepXfer*)xfer->data; | 294 xf = (XepXfer*)xfer->data; |
309 if(xf != NULL) { | 295 if(xf != NULL) { |
310 bd = (BonjourData*)xf->data; | 296 BonjourData *bd = (BonjourData*)xf->data; |
311 if(bd != NULL) { | 297 if(bd != NULL) { |
312 bd->xfer_lists = g_slist_remove(bd->xfer_lists, xfer); | 298 bd->xfer_lists = g_slist_remove(bd->xfer_lists, xfer); |
313 purple_debug_info("bonjour", "B free xfer from lists(%p).\n", bd->xfer_lists); | 299 purple_debug_info("bonjour", "B free xfer from lists(%p).\n", bd->xfer_lists); |
314 } | 300 } |
315 if (xf->proxy_connection != NULL) | 301 if (xf->proxy_connection != NULL) |
330 | 316 |
331 PurpleXfer * | 317 PurpleXfer * |
332 bonjour_new_xfer(PurpleConnection *gc, const char *who) | 318 bonjour_new_xfer(PurpleConnection *gc, const char *who) |
333 { | 319 { |
334 PurpleXfer *xfer; | 320 PurpleXfer *xfer; |
335 XepXfer *xep_xfer = NULL; | 321 XepXfer *xep_xfer; |
336 BonjourData *bd = NULL; | 322 BonjourData *bd; |
337 | 323 |
338 if(who == NULL || gc == NULL) | 324 if(who == NULL || gc == NULL) |
339 return NULL; | 325 return NULL; |
340 | 326 |
341 purple_debug_info("bonjour", "Bonjour-new-xfer to %s.\n", who); | 327 purple_debug_info("bonjour", "Bonjour-new-xfer to %s.\n", who); |
365 } | 351 } |
366 | 352 |
367 void | 353 void |
368 bonjour_send_file(PurpleConnection *gc, const char *who, const char *file) | 354 bonjour_send_file(PurpleConnection *gc, const char *who, const char *file) |
369 { | 355 { |
370 PurpleXfer *xfer = NULL; | 356 PurpleXfer *xfer; |
371 | 357 |
372 g_return_if_fail(gc != NULL); | 358 g_return_if_fail(gc != NULL); |
373 g_return_if_fail(who != NULL); | 359 g_return_if_fail(who != NULL); |
374 | 360 |
375 purple_debug_info("bonjour", "Bonjour-send-file to=%s.\n", who); | 361 purple_debug_info("bonjour", "Bonjour-send-file to=%s.\n", who); |
384 } | 370 } |
385 | 371 |
386 static void | 372 static void |
387 bonjour_xfer_init(PurpleXfer *xfer) | 373 bonjour_xfer_init(PurpleXfer *xfer) |
388 { | 374 { |
389 PurpleBuddy *buddy = NULL; | 375 PurpleBuddy *buddy; |
390 BonjourBuddy *bb = NULL; | 376 BonjourBuddy *bb; |
391 XepXfer *xf = NULL; | 377 XepXfer *xf; |
392 | 378 |
393 xf = (XepXfer*)xfer->data; | 379 xf = (XepXfer*)xfer->data; |
394 if(xf == NULL) | 380 if(xf == NULL) |
395 return; | 381 return; |
396 | 382 |
397 purple_debug_info("bonjour", "Bonjour-xfer-init.\n"); | 383 purple_debug_info("bonjour", "Bonjour-xfer-init.\n"); |
398 | 384 |
399 buddy = purple_find_buddy(xfer->account, xfer->who); | 385 buddy = purple_find_buddy(xfer->account, xfer->who); |
400 /* this buddy is offline. */ | 386 /* this buddy is offline. */ |
401 if (buddy == NULL) | 387 if (buddy == NULL || buddy->proto_data == NULL) |
402 return; | 388 return; |
403 | 389 |
404 bb = (BonjourBuddy *)buddy->proto_data; | 390 bb = (BonjourBuddy *)buddy->proto_data; |
405 /* Assume it is the first IP. We could do something like keep track of which one is in use or something. */ | 391 /* Assume it is the first IP. We could do something like keep track of which one is in use or something. */ |
406 if (bb->ips) | 392 if (bb->ips) |
418 | 404 |
419 void | 405 void |
420 xep_si_parse(PurpleConnection *pc, xmlnode *packet, PurpleBuddy *pb) | 406 xep_si_parse(PurpleConnection *pc, xmlnode *packet, PurpleBuddy *pb) |
421 { | 407 { |
422 const char *type, *id; | 408 const char *type, *id; |
423 BonjourData *bd = NULL; | 409 BonjourData *bd; |
424 PurpleXfer *xfer = NULL; | 410 PurpleXfer *xfer; |
425 | 411 |
426 if(pc == NULL || packet == NULL || pb == NULL) | 412 if(pc == NULL || packet == NULL || pb == NULL) |
427 return; | 413 return; |
428 bd = (BonjourData*) pc->proto_data; | 414 bd = (BonjourData*) pc->proto_data; |
429 if(bd == NULL) | 415 if(bd == NULL) |
494 } | 480 } |
495 | 481 |
496 void | 482 void |
497 xep_bytestreams_parse(PurpleConnection *pc, xmlnode *packet, PurpleBuddy *pb) | 483 xep_bytestreams_parse(PurpleConnection *pc, xmlnode *packet, PurpleBuddy *pb) |
498 { | 484 { |
499 const char *type = NULL, *from = NULL; | 485 const char *type, *from; |
500 xmlnode *query = NULL, *streamhost = NULL; | 486 xmlnode *query; |
501 BonjourData *bd = NULL; | 487 BonjourData *bd; |
502 PurpleXfer *xfer = NULL; | |
503 XepXfer *xf = NULL; | |
504 int portnum; | |
505 | 488 |
506 if(pc == NULL || packet == NULL || pb == NULL) | 489 if(pc == NULL || packet == NULL || pb == NULL) |
507 return; | 490 return; |
508 | 491 |
509 bd = (BonjourData*) pc->proto_data; | 492 bd = (BonjourData*) pc->proto_data; |
517 query = xmlnode_get_child(packet,"query"); | 500 query = xmlnode_get_child(packet,"query"); |
518 if(type) { | 501 if(type) { |
519 if(!strcmp(type, "set")) { | 502 if(!strcmp(type, "set")) { |
520 const char *iq_id, *sid; | 503 const char *iq_id, *sid; |
521 gboolean found = FALSE; | 504 gboolean found = FALSE; |
505 PurpleXfer *xfer; | |
522 | 506 |
523 purple_debug_info("bonjour", "bytestream offer Message type - SET.\n"); | 507 purple_debug_info("bonjour", "bytestream offer Message type - SET.\n"); |
524 | 508 |
525 iq_id = xmlnode_get_attrib(packet, "id"); | 509 iq_id = xmlnode_get_attrib(packet, "id"); |
526 | 510 |
527 sid = xmlnode_get_attrib(query, "sid"); | 511 sid = xmlnode_get_attrib(query, "sid"); |
528 xfer = bonjour_si_xfer_find(bd, sid, from); | 512 xfer = bonjour_si_xfer_find(bd, sid, from); |
529 | 513 |
530 if(xfer) { | 514 if(xfer) { |
531 const char *jid, *host, *port; | 515 const char *jid, *host, *port; |
516 xmlnode *streamhost; | |
517 int portnum; | |
518 XepXfer *xf = NULL; | |
532 | 519 |
533 xf = (XepXfer*)xfer->data; | 520 xf = (XepXfer*)xfer->data; |
534 for(streamhost = xmlnode_get_child(query, "streamhost"); | 521 for(streamhost = xmlnode_get_child(query, "streamhost"); |
535 streamhost; | 522 streamhost; |
536 streamhost = xmlnode_get_next_twin(streamhost)) { | 523 streamhost = xmlnode_get_next_twin(streamhost)) { |
575 | 562 |
576 static void | 563 static void |
577 bonjour_xfer_receive(PurpleConnection *pc, const char *id, const char *sid, const char *from, | 564 bonjour_xfer_receive(PurpleConnection *pc, const char *id, const char *sid, const char *from, |
578 const int filesize, const char *filename, int option) | 565 const int filesize, const char *filename, int option) |
579 { | 566 { |
580 PurpleXfer *xfer = NULL; | 567 PurpleXfer *xfer; |
581 XepXfer *xf = NULL; | 568 XepXfer *xf; |
582 BonjourData *bd = NULL; | 569 BonjourData *bd; |
583 | 570 |
584 if(pc == NULL || id == NULL || from == NULL) | 571 if(pc == NULL || id == NULL || from == NULL) |
585 return; | 572 return; |
586 | 573 |
587 bd = (BonjourData*) pc->proto_data; | 574 bd = (BonjourData*) pc->proto_data; |
612 | 599 |
613 static void | 600 static void |
614 bonjour_sock5_request_cb(gpointer data, gint source, PurpleInputCondition cond) | 601 bonjour_sock5_request_cb(gpointer data, gint source, PurpleInputCondition cond) |
615 { | 602 { |
616 PurpleXfer *xfer = data; | 603 PurpleXfer *xfer = data; |
617 XepXfer *xf = NULL; | 604 XepXfer *xf = xfer->data; |
618 int acceptfd; | 605 int acceptfd; |
619 int len = 0; | 606 int len = 0; |
620 | 607 |
621 xf = xfer->data; | |
622 if(xf == NULL) | 608 if(xf == NULL) |
623 return; | 609 return; |
624 | 610 |
625 purple_debug_info("bonjour", "bonjour_sock5_request_cb - req_state = 0x%x\n", xf->sock5_req_state); | 611 purple_debug_info("bonjour", "bonjour_sock5_request_cb - req_state = 0x%x\n", xf->sock5_req_state); |
626 | 612 |
743 { | 729 { |
744 PurpleXfer *xfer = data; | 730 PurpleXfer *xfer = data; |
745 XepXfer *xf; | 731 XepXfer *xf; |
746 XepIq *iq; | 732 XepIq *iq; |
747 xmlnode *query, *streamhost; | 733 xmlnode *query, *streamhost; |
748 char *port; | 734 gchar *port; |
749 const char *next_ip; | 735 const char *next_ip, *local_ip; |
750 const char *local_ip = NULL; | 736 const char token [] = ";"; |
751 char token [] = ";"; | |
752 BonjourData *bd; | 737 BonjourData *bd; |
753 | 738 |
754 purple_debug_info("bonjour", "Bonjour-bytestreams-listen. sock=%d.\n", sock); | 739 purple_debug_info("bonjour", "Bonjour-bytestreams-listen. sock=%d.\n", sock); |
755 if (sock < 0 || xfer == NULL) { | 740 if (sock < 0 || xfer == NULL) { |
756 /*purple_xfer_cancel_local(xfer);*/ | 741 /*purple_xfer_cancel_local(xfer);*/ |
791 } | 776 } |
792 | 777 |
793 static void | 778 static void |
794 bonjour_bytestreams_init(PurpleXfer *xfer) | 779 bonjour_bytestreams_init(PurpleXfer *xfer) |
795 { | 780 { |
796 XepXfer *xf = NULL; | 781 XepXfer *xf; |
797 if(xfer == NULL) | 782 if(xfer == NULL) |
798 return; | 783 return; |
799 purple_debug_info("bonjour", "Bonjour-bytestreams-init.\n"); | 784 purple_debug_info("bonjour", "Bonjour-bytestreams-init.\n"); |
800 xf = xfer->data; | 785 xf = xfer->data; |
801 purple_network_listen_map_external(FALSE); | 786 purple_network_listen_map_external(FALSE); |
811 static void | 796 static void |
812 bonjour_bytestreams_connect_cb(gpointer data, gint source, const gchar *error_message) | 797 bonjour_bytestreams_connect_cb(gpointer data, gint source, const gchar *error_message) |
813 { | 798 { |
814 PurpleXfer *xfer = data; | 799 PurpleXfer *xfer = data; |
815 XepXfer *xf = xfer->data; | 800 XepXfer *xf = xfer->data; |
816 XepIq *iq = NULL; | 801 XepIq *iq; |
817 xmlnode *q_node, *tmp_node; | 802 xmlnode *q_node, *tmp_node; |
818 BonjourData *bd; | 803 BonjourData *bd; |
819 | 804 |
820 if(source < 0) { | 805 if(source < 0) { |
821 purple_debug_error("bonjour", "Error connecting via SOCKS5 - %s\n", | 806 purple_debug_error("bonjour", "Error connecting via SOCKS5 - %s\n", |
847 } | 832 } |
848 | 833 |
849 static void | 834 static void |
850 bonjour_bytestreams_connect(PurpleXfer *xfer, PurpleBuddy *pb) | 835 bonjour_bytestreams_connect(PurpleXfer *xfer, PurpleBuddy *pb) |
851 { | 836 { |
852 XepXfer *xf = NULL; | 837 XepXfer *xf; |
853 char dstaddr[41]; | 838 char dstaddr[41]; |
854 unsigned char hashval[20]; | 839 unsigned char hashval[20]; |
855 char *p = NULL; | 840 char *p; |
856 int i; | 841 int i; |
857 | 842 |
858 if(xfer == NULL) | 843 if(xfer == NULL) |
859 return; | 844 return; |
860 | 845 |