Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jabglue.c @ 684:3282276e7413
Switch IQ packet creation to the new IQ system
Use iqs_new() instead of jutil_iqnew().
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 06 Feb 2006 20:02:09 +0100 |
parents | e175f5d96f04 |
children | 98de2d166a11 |
comparison
equal
deleted
inserted
replaced
683:c5e0d8c3f00c | 684:3282276e7413 |
---|---|
453 } | 453 } |
454 | 454 |
455 // Note: the caller should check the jid is correct | 455 // Note: the caller should check the jid is correct |
456 void jb_addbuddy(const char *jid, const char *name, const char *group) | 456 void jb_addbuddy(const char *jid, const char *name, const char *group) |
457 { | 457 { |
458 xmlnode x, y, z; | 458 xmlnode y, z; |
459 iqs *iqn; | |
459 char *cleanjid; | 460 char *cleanjid; |
460 | 461 |
461 if (!online) return; | 462 if (!online) return; |
462 | 463 |
463 cleanjid = jidtodisp(jid); | 464 cleanjid = jidtodisp(jid); |
464 | 465 |
465 // We don't check if the jabber user already exists in the roster, | 466 // We don't check if the jabber user already exists in the roster, |
466 // because it allows to re-ask for notification. | 467 // because it allows to re-ask for notification. |
467 | 468 |
468 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | 469 iqn = iqs_new(JPACKET__SET, NS_ROSTER, NULL, IQS_DEFAULT_TIMEOUT); |
469 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); | 470 y = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "item"); |
470 | 471 |
471 xmlnode_put_attrib(y, "jid", cleanjid); | 472 xmlnode_put_attrib(y, "jid", cleanjid); |
472 | 473 |
473 if (name) { | 474 if (name) { |
474 gchar *name_utf8 = to_utf8(name); | 475 gchar *name_utf8 = to_utf8(name); |
481 z = xmlnode_insert_tag(y, "group"); | 482 z = xmlnode_insert_tag(y, "group"); |
482 xmlnode_insert_cdata(z, group_utf8, (unsigned) -1); | 483 xmlnode_insert_cdata(z, group_utf8, (unsigned) -1); |
483 g_free(group_utf8); | 484 g_free(group_utf8); |
484 } | 485 } |
485 | 486 |
486 jab_send(jc, x); | 487 jab_send(jc, iqn->xmldata); |
487 xmlnode_free(x); | 488 iqs_del(iqn->id); // XXX |
488 | 489 |
489 jb_subscr_request_auth(cleanjid); | 490 jb_subscr_request_auth(cleanjid); |
490 | 491 |
491 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending); | 492 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending); |
492 g_free(cleanjid); | 493 g_free(cleanjid); |
496 } | 497 } |
497 | 498 |
498 void jb_delbuddy(const char *jid) | 499 void jb_delbuddy(const char *jid) |
499 { | 500 { |
500 xmlnode x, y, z; | 501 xmlnode x, y, z; |
502 iqs *iqn; | |
501 char *cleanjid; | 503 char *cleanjid; |
502 | 504 |
503 if (!online) return; | 505 if (!online) return; |
504 | 506 |
505 cleanjid = jidtodisp(jid); | 507 cleanjid = jidtodisp(jid); |
506 | 508 |
507 // If the current buddy is an agent, unsubscribe from it | 509 // If the current buddy is an agent, unsubscribe from it |
508 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) { | 510 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) { |
509 scr_LogPrint(LPRINT_LOGNORM, "Unregistering from the %s agent", cleanjid); | 511 scr_LogPrint(LPRINT_LOGNORM, "Unregistering from the %s agent", cleanjid); |
510 | 512 |
511 x = jutil_iqnew(JPACKET__SET, NS_REGISTER); | 513 iqn = iqs_new(JPACKET__SET, NS_REGISTER, NULL, IQS_DEFAULT_TIMEOUT); |
512 xmlnode_put_attrib(x, "to", cleanjid); | 514 xmlnode_put_attrib(iqn->xmldata, "to", cleanjid); |
513 y = xmlnode_get_tag(x, "query"); | 515 y = xmlnode_get_tag(iqn->xmldata, "query"); |
514 xmlnode_insert_tag(y, "remove"); | 516 xmlnode_insert_tag(y, "remove"); |
515 jab_send(jc, x); | 517 jab_send(jc, iqn->xmldata); |
516 xmlnode_free(x); | 518 iqs_del(iqn->id); // XXX |
517 } | 519 } |
518 | 520 |
519 // Cancel the subscriptions | 521 // Cancel the subscriptions |
520 x = jutil_presnew(JPACKET__UNSUBSCRIBED, cleanjid, 0); // Cancel "from" | 522 x = jutil_presnew(JPACKET__UNSUBSCRIBED, cleanjid, 0); // Cancel "from" |
521 jab_send(jc, x); | 523 jab_send(jc, x); |
523 x = jutil_presnew(JPACKET__UNSUBSCRIBE, cleanjid, 0); // Cancel "to" | 525 x = jutil_presnew(JPACKET__UNSUBSCRIBE, cleanjid, 0); // Cancel "to" |
524 jab_send(jc, x); | 526 jab_send(jc, x); |
525 xmlnode_free(x); | 527 xmlnode_free(x); |
526 | 528 |
527 // Ask for removal from roster | 529 // Ask for removal from roster |
528 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | 530 iqn = iqs_new(JPACKET__SET, NS_ROSTER, NULL, IQS_DEFAULT_TIMEOUT); |
529 y = xmlnode_get_tag(x, "query"); | 531 y = xmlnode_get_tag(iqn->xmldata, "query"); |
530 z = xmlnode_insert_tag(y, "item"); | 532 z = xmlnode_insert_tag(y, "item"); |
531 xmlnode_put_attrib(z, "jid", cleanjid); | 533 xmlnode_put_attrib(z, "jid", cleanjid); |
532 xmlnode_put_attrib(z, "subscription", "remove"); | 534 xmlnode_put_attrib(z, "subscription", "remove"); |
533 jab_send(jc, x); | 535 jab_send(jc, iqn->xmldata); |
534 xmlnode_free(x); | 536 iqs_del(iqn->id); // XXX |
535 | 537 |
536 roster_del_user(cleanjid); | 538 roster_del_user(cleanjid); |
537 g_free(cleanjid); | 539 g_free(cleanjid); |
538 buddylist_build(); | 540 buddylist_build(); |
539 | 541 |
540 update_roster = TRUE; | 542 update_roster = TRUE; |
541 } | 543 } |
542 | 544 |
543 void jb_updatebuddy(const char *jid, const char *name, const char *group) | 545 void jb_updatebuddy(const char *jid, const char *name, const char *group) |
544 { | 546 { |
545 xmlnode x, y; | 547 xmlnode y; |
548 iqs *iqn; | |
546 char *cleanjid; | 549 char *cleanjid; |
547 gchar *name_utf8; | 550 gchar *name_utf8; |
548 | 551 |
549 if (!online) return; | 552 if (!online) return; |
550 | 553 |
551 // XXX We should check name's and group's correctness | 554 // XXX We should check name's and group's correctness |
552 | 555 |
553 cleanjid = jidtodisp(jid); | 556 cleanjid = jidtodisp(jid); |
554 name_utf8 = to_utf8(name); | 557 name_utf8 = to_utf8(name); |
555 | 558 |
556 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | 559 iqn = iqs_new(JPACKET__SET, NS_ROSTER, NULL, IQS_DEFAULT_TIMEOUT); |
557 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); | 560 y = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "item"); |
558 xmlnode_put_attrib(y, "jid", cleanjid); | 561 xmlnode_put_attrib(y, "jid", cleanjid); |
559 xmlnode_put_attrib(y, "name", name_utf8); | 562 xmlnode_put_attrib(y, "name", name_utf8); |
560 | 563 |
561 if (group) { | 564 if (group) { |
562 gchar *group_utf8 = to_utf8(group); | 565 gchar *group_utf8 = to_utf8(group); |
563 y = xmlnode_insert_tag(y, "group"); | 566 y = xmlnode_insert_tag(y, "group"); |
564 xmlnode_insert_cdata(y, group_utf8, (unsigned) -1); | 567 xmlnode_insert_cdata(y, group_utf8, (unsigned) -1); |
565 g_free(group_utf8); | 568 g_free(group_utf8); |
566 } | 569 } |
567 | 570 |
568 jab_send(jc, x); | 571 jab_send(jc, iqn->xmldata); |
569 xmlnode_free(x); | 572 iqs_del(iqn->id); // XXX |
570 g_free(name_utf8); | 573 g_free(name_utf8); |
571 g_free(cleanjid); | 574 g_free(cleanjid); |
572 } | 575 } |
573 | 576 |
574 // Join a MUC room | 577 // Join a MUC room |
616 | 619 |
617 // Unlock a MUC room | 620 // Unlock a MUC room |
618 // room syntax: "room@server" | 621 // room syntax: "room@server" |
619 void jb_room_unlock(const char *room) | 622 void jb_room_unlock(const char *room) |
620 { | 623 { |
621 xmlnode x, y, z; | 624 xmlnode y, z; |
625 iqs *iqn; | |
622 | 626 |
623 if (!online || !room) return; | 627 if (!online || !room) return; |
624 | 628 |
625 x = jutil_iqnew(JPACKET__SET, "http://jabber.org/protocol/muc#owner"); | 629 iqn = iqs_new(JPACKET__SET, "http://jabber.org/protocol/muc#owner", |
626 xmlnode_put_attrib(x, "id", "unlock1"); // XXX | 630 "unlock", IQS_DEFAULT_TIMEOUT); |
627 xmlnode_put_attrib(x, "to", room); | 631 xmlnode_put_attrib(iqn->xmldata, "to", room); |
628 y = xmlnode_get_tag(x, "query"); | 632 y = xmlnode_get_tag(iqn->xmldata, "query"); |
629 z = xmlnode_insert_tag(y, "x"); | 633 z = xmlnode_insert_tag(y, "x"); |
630 xmlnode_put_attrib(z, "xmlns", "jabber:x:data"); | 634 xmlnode_put_attrib(z, "xmlns", "jabber:x:data"); |
631 xmlnode_put_attrib(z, "type", "submit"); | 635 xmlnode_put_attrib(z, "type", "submit"); |
632 | 636 |
633 jab_send(jc, x); | 637 jab_send(jc, iqn->xmldata); |
634 xmlnode_free(x); | 638 iqs_del(iqn->id); // XXX |
635 jb_reset_keepalive(); | 639 jb_reset_keepalive(); |
636 } | 640 } |
637 | 641 |
638 // Destroy a MUC room | 642 // Destroy a MUC room |
639 // room syntax: "room@server" | 643 // room syntax: "room@server" |
640 void jb_room_destroy(const char *room, const char *venue, const char *reason) | 644 void jb_room_destroy(const char *room, const char *venue, const char *reason) |
641 { | 645 { |
642 xmlnode x, y, z; | 646 xmlnode y, z; |
647 iqs *iqn; | |
643 | 648 |
644 if (!online || !room) return; | 649 if (!online || !room) return; |
645 | 650 |
646 x = jutil_iqnew(JPACKET__SET, "http://jabber.org/protocol/muc#owner"); | 651 iqn = iqs_new(JPACKET__SET, "http://jabber.org/protocol/muc#owner", |
647 xmlnode_put_attrib(x, "id", "destroy1"); // XXX | 652 "destroy", IQS_DEFAULT_TIMEOUT); |
648 xmlnode_put_attrib(x, "to", room); | 653 xmlnode_put_attrib(iqn->xmldata, "to", room); |
649 y = xmlnode_get_tag(x, "query"); | 654 y = xmlnode_get_tag(iqn->xmldata, "query"); |
650 z = xmlnode_insert_tag(y, "destroy"); | 655 z = xmlnode_insert_tag(y, "destroy"); |
651 | 656 |
652 if (venue && *venue) | 657 if (venue && *venue) |
653 xmlnode_put_attrib(z, "jid", venue); | 658 xmlnode_put_attrib(z, "jid", venue); |
654 | 659 |
657 y = xmlnode_insert_tag(z, "reason"); | 662 y = xmlnode_insert_tag(z, "reason"); |
658 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1); | 663 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1); |
659 g_free(utf8_reason); | 664 g_free(utf8_reason); |
660 } | 665 } |
661 | 666 |
662 jab_send(jc, x); | 667 jab_send(jc, iqn->xmldata); |
663 xmlnode_free(x); | 668 iqs_del(iqn->id); // XXX |
664 jb_reset_keepalive(); | 669 jb_reset_keepalive(); |
665 } | 670 } |
666 | 671 |
667 // Change role or affiliation of a MUC user | 672 // Change role or affiliation of a MUC user |
668 // room syntax: "room@server" | 673 // room syntax: "room@server" |
673 // The reason can be null | 678 // The reason can be null |
674 // Return 0 if everything is ok | 679 // Return 0 if everything is ok |
675 int jb_room_setattrib(const char *roomid, const char *jid, const char *nick, | 680 int jb_room_setattrib(const char *roomid, const char *jid, const char *nick, |
676 struct role_affil ra, const char *reason) | 681 struct role_affil ra, const char *reason) |
677 { | 682 { |
678 xmlnode x, y, z; | 683 xmlnode y, z; |
684 iqs *iqn; | |
679 | 685 |
680 if (!online || !roomid) return 1; | 686 if (!online || !roomid) return 1; |
681 if (!jid && !nick) return 1; | 687 if (!jid && !nick) return 1; |
682 | 688 |
683 if (check_jid_syntax((char*)roomid)) { | 689 if (check_jid_syntax((char*)roomid)) { |
690 } | 696 } |
691 | 697 |
692 if (ra.type == type_affil && ra.val.affil == affil_outcast && !jid) | 698 if (ra.type == type_affil && ra.val.affil == affil_outcast && !jid) |
693 return 1; // Shouldn't happen (jid mandatory when banning) | 699 return 1; // Shouldn't happen (jid mandatory when banning) |
694 | 700 |
695 x = jutil_iqnew(JPACKET__SET, "http://jabber.org/protocol/muc#admin"); | 701 iqn = iqs_new(JPACKET__SET, "http://jabber.org/protocol/muc#admin", |
696 xmlnode_put_attrib(x, "id", "roleaffil1"); // XXX | 702 "roleaffil", IQS_DEFAULT_TIMEOUT); |
697 xmlnode_put_attrib(x, "to", roomid); | 703 xmlnode_put_attrib(iqn->xmldata, "to", roomid); |
698 xmlnode_put_attrib(x, "type", "set"); | 704 xmlnode_put_attrib(iqn->xmldata, "type", "set"); |
699 y = xmlnode_get_tag(x, "query"); | 705 y = xmlnode_get_tag(iqn->xmldata, "query"); |
700 z = xmlnode_insert_tag(y, "item"); | 706 z = xmlnode_insert_tag(y, "item"); |
701 | 707 |
702 if (jid) { | 708 if (jid) { |
703 gchar *utf8_jid = to_utf8(jid); | 709 gchar *utf8_jid = to_utf8(jid); |
704 xmlnode_put_attrib(z, "jid", utf8_jid); | 710 xmlnode_put_attrib(z, "jid", utf8_jid); |
719 y = xmlnode_insert_tag(z, "reason"); | 725 y = xmlnode_insert_tag(z, "reason"); |
720 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1); | 726 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1); |
721 g_free(utf8_reason); | 727 g_free(utf8_reason); |
722 } | 728 } |
723 | 729 |
724 jab_send(jc, x); | 730 jab_send(jc, iqn->xmldata); |
725 xmlnode_free(x); | 731 iqs_del(iqn->id); // XXX |
726 jb_reset_keepalive(); | 732 jb_reset_keepalive(); |
727 | 733 |
728 return 0; | 734 return 0; |
729 } | 735 } |
730 | 736 |