Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/jabber.c @ 17607:ca0b86f3dbd2
Implemented a callback for a successful registration, supplying the username and password to the application when available, in the way explained by Sean.
author | Andreas Monitzer <pidgin@monitzer.com> |
---|---|
date | Fri, 22 Jun 2007 00:05:35 +0000 |
parents | 108f3b42976f |
children | a8b1159fd95b |
comparison
equal
deleted
inserted
replaced
17606:108f3b42976f | 17607:ca0b86f3dbd2 |
---|---|
640 } | 640 } |
641 | 641 |
642 static void | 642 static void |
643 jabber_registration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | 643 jabber_registration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
644 { | 644 { |
645 PurpleAccount *account = purple_connection_get_account(js->gc); | |
645 const char *type = xmlnode_get_attrib(packet, "type"); | 646 const char *type = xmlnode_get_attrib(packet, "type"); |
646 char *buf; | 647 char *buf; |
647 char *to = data; | 648 char *to = data; |
648 | 649 |
649 if(!strcmp(type, "result")) { | 650 if(!strcmp(type, "result")) { |
650 if(js->registration) | 651 if(js->registration) { |
651 buf = g_strdup_printf(_("Registration of %s@%s successful"), | 652 buf = g_strdup_printf(_("Registration of %s@%s successful"), |
652 js->user->node, js->user->domain); | 653 js->user->node, js->user->domain); |
654 if(account->registration_cb) { | |
655 char *jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); | |
656 (account->registration_cb)(account, TRUE, jid, js->password, account->registration_cb_user_data); | |
657 g_free(jid); | |
658 /* the password shouldn't be kept around longer than necessary */ | |
659 if(js->password) { | |
660 g_free(js->password); | |
661 js->password = NULL; | |
662 } | |
663 } | |
664 } | |
653 else | 665 else |
654 buf = g_strdup_printf(_("Registration to %s successful"), | 666 buf = g_strdup_printf(_("Registration to %s successful"), |
655 to); | 667 to); |
656 purple_notify_info(NULL, _("Registration Successful"), | 668 purple_notify_info(NULL, _("Registration Successful"), |
657 _("Registration Successful"), buf); | 669 _("Registration Successful"), buf); |
663 msg = g_strdup(_("Unknown Error")); | 675 msg = g_strdup(_("Unknown Error")); |
664 | 676 |
665 purple_notify_error(NULL, _("Registration Failed"), | 677 purple_notify_error(NULL, _("Registration Failed"), |
666 _("Registration Failed"), msg); | 678 _("Registration Failed"), msg); |
667 g_free(msg); | 679 g_free(msg); |
680 if(account->registration_cb) { | |
681 char *jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); | |
682 (account->registration_cb)(account, FALSE, NULL, NULL, account->registration_cb_user_data); | |
683 g_free(jid); | |
684 /* the password shouldn't be kept around longer than necessary */ | |
685 if(js->password) { | |
686 g_free(js->password); | |
687 js->password = NULL; | |
688 } | |
689 } | |
668 } | 690 } |
669 g_free(to); | 691 g_free(to); |
670 if(js->registration) | 692 if(js->registration) |
671 jabber_connection_schedule_close(js); | 693 jabber_connection_schedule_close(js); |
672 } | 694 } |
731 if(cbdata->js->registration && !strcmp(id, "username")) { | 753 if(cbdata->js->registration && !strcmp(id, "username")) { |
732 if(cbdata->js->user->node) | 754 if(cbdata->js->user->node) |
733 g_free(cbdata->js->user->node); | 755 g_free(cbdata->js->user->node); |
734 cbdata->js->user->node = g_strdup(value); | 756 cbdata->js->user->node = g_strdup(value); |
735 } | 757 } |
758 if(cbdata->js->registration && !strcmp(id, "password")) { | |
759 if(cbdata->js->password) | |
760 g_free(cbdata->js->password); | |
761 cbdata->js->password = g_strdup(value); | |
762 } | |
736 } | 763 } |
737 } | 764 } |
738 | 765 |
739 if(cbdata->js->registration) { | 766 if(cbdata->js->registration) { |
740 username = g_strdup_printf("%s@%s/%s", cbdata->js->user->node, cbdata->js->user->domain, | 767 username = g_strdup_printf("%s@%s/%s", cbdata->js->user->node, cbdata->js->user->domain, |
750 } | 777 } |
751 | 778 |
752 static void | 779 static void |
753 jabber_register_cancel_cb(JabberRegisterCBData *cbdata, PurpleRequestFields *fields) | 780 jabber_register_cancel_cb(JabberRegisterCBData *cbdata, PurpleRequestFields *fields) |
754 { | 781 { |
755 if(cbdata->js->registration) | 782 PurpleAccount *account = purple_connection_get_account(cbdata->js->gc); |
783 if(cbdata->js->registration) { | |
784 if(account->registration_cb) | |
785 (account->registration_cb)(account, FALSE, NULL, NULL, account->registration_cb_user_data); | |
756 jabber_connection_schedule_close(cbdata->js); | 786 jabber_connection_schedule_close(cbdata->js); |
787 } | |
757 g_free(cbdata->who); | 788 g_free(cbdata->who); |
758 g_free(cbdata); | 789 g_free(cbdata); |
759 } | 790 } |
760 | 791 |
761 static void jabber_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) | 792 static void jabber_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) |
774 jabber_iq_send(iq); | 805 jabber_iq_send(iq); |
775 } | 806 } |
776 | 807 |
777 void jabber_register_parse(JabberStream *js, xmlnode *packet) | 808 void jabber_register_parse(JabberStream *js, xmlnode *packet) |
778 { | 809 { |
810 PurpleAccount *account = purple_connection_get_account(js->gc); | |
779 const char *type; | 811 const char *type; |
780 const char *from = xmlnode_get_attrib(packet, "from"); | 812 const char *from = xmlnode_get_attrib(packet, "from"); |
781 PurpleRequestFields *fields; | 813 PurpleRequestFields *fields; |
782 PurpleRequestFieldGroup *group; | 814 PurpleRequestFieldGroup *group; |
783 PurpleRequestField *field; | 815 PurpleRequestField *field; |
795 query = xmlnode_get_child(packet, "query"); | 827 query = xmlnode_get_child(packet, "query"); |
796 | 828 |
797 if(js->registration && xmlnode_get_child(query, "registered")) { | 829 if(js->registration && xmlnode_get_child(query, "registered")) { |
798 purple_notify_error(NULL, _("Already Registered"), | 830 purple_notify_error(NULL, _("Already Registered"), |
799 _("Already Registered"), NULL); | 831 _("Already Registered"), NULL); |
800 if(js->registration) | 832 if(js->registration) { |
833 if(account->registration_cb) | |
834 (account->registration_cb)(account, FALSE, NULL, NULL, account->registration_cb_user_data); | |
801 jabber_connection_schedule_close(js); | 835 jabber_connection_schedule_close(js); |
836 } | |
802 return; | 837 return; |
803 } | 838 } |
804 | 839 |
805 if((x = xmlnode_get_child_with_namespace(packet, "x", | 840 if((x = xmlnode_get_child_with_namespace(packet, "x", |
806 "jabber:x:data"))) { | 841 "jabber:x:data"))) { |
815 if((href = xmlnode_get_data(url))) { | 850 if((href = xmlnode_get_data(url))) { |
816 purple_notify_uri(NULL, href); | 851 purple_notify_uri(NULL, href); |
817 g_free(href); | 852 g_free(href); |
818 if(js->registration) { | 853 if(js->registration) { |
819 js->gc->wants_to_die = TRUE; | 854 js->gc->wants_to_die = TRUE; |
855 if(account->registration_cb) /* succeeded, but we have no login info */ | |
856 (account->registration_cb)(account, TRUE, NULL, NULL, account->registration_cb_user_data); | |
820 jabber_connection_schedule_close(js); | 857 jabber_connection_schedule_close(js); |
821 } | 858 } |
822 return; | 859 return; |
823 } | 860 } |
824 } | 861 } |
1095 if(js->sasl_cb) | 1132 if(js->sasl_cb) |
1096 g_free(js->sasl_cb); | 1133 g_free(js->sasl_cb); |
1097 #endif | 1134 #endif |
1098 if(js->serverFQDN) | 1135 if(js->serverFQDN) |
1099 g_free(js->serverFQDN); | 1136 g_free(js->serverFQDN); |
1137 if(js->password) | |
1138 g_free(js->password); | |
1100 g_free(js->server_name); | 1139 g_free(js->server_name); |
1101 g_free(js->gmail_last_time); | 1140 g_free(js->gmail_last_time); |
1102 g_free(js->gmail_last_tid); | 1141 g_free(js->gmail_last_tid); |
1103 if(js->old_msg) | 1142 if(js->old_msg) |
1104 g_free(js->old_msg); | 1143 g_free(js->old_msg); |