From: ishmal Date: Sun, 21 May 2006 03:51:47 +0000 (+0000) Subject: first hack at in-band registration X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=807349d6392a6fcaa65a58a04b9fb8261f9e928d;p=inkscape.git first hack at in-band registration --- diff --git a/src/pedro/pedrogui.cpp b/src/pedro/pedrogui.cpp index e2ab05a2e..cbfea0938 100644 --- a/src/pedro/pedrogui.cpp +++ b/src/pedro/pedrogui.cpp @@ -428,7 +428,7 @@ bool Roster::buttonPressCallback(GdkEventButton* event) bool Roster::doSetup() { set_size_request(200,200); - + pixbuf_available = Gdk::Pixbuf::create_from_inline( sizeof(icon_available), icon_available, false); pixbuf_away = Gdk::Pixbuf::create_from_inline( @@ -1145,7 +1145,7 @@ bool ConnectDialog::doSetup() Gtk::Widget* pMenuBar = uiManager->get_widget("/MenuBar"); get_vbox()->pack_start(*pMenuBar, Gtk::PACK_SHRINK); - table.resize(5, 2); + table.resize(6, 2); get_vbox()->pack_start(table); parent.client.setHost("gristle.org"); @@ -1184,6 +1184,11 @@ bool ConnectDialog::doSetup() resourceField.set_text(parent.client.getResource()); table.attach(resourceField, 1, 2, 4, 5); + registerLabel.set_text("Register"); + table.attach(registerLabel, 0, 1, 5, 6); + registerButton.set_active(false); + table.attach(registerButton, 1, 2, 5, 6); + add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); @@ -1943,6 +1948,7 @@ void PedroGui::connectCallback() client.setUsername(dialog.getUser()); client.setPassword(dialog.getPass()); client.setResource(dialog.getResource()); + client.setDoRegister(dialog.getRegister()); client.connect(); } } diff --git a/src/pedro/pedrogui.h b/src/pedro/pedrogui.h index b42ee7ab8..2605a894e 100644 --- a/src/pedro/pedrogui.h +++ b/src/pedro/pedrogui.h @@ -104,7 +104,7 @@ private: Glib::RefPtr pixbuf_error; Glib::RefPtr pixbuf_offline; Glib::RefPtr pixbuf_xa; - + class RosterColumns : public Gtk::TreeModel::ColumnRecord { public: @@ -379,6 +379,8 @@ public: { return passField.get_text(); } DOMString getResource() { return resourceField.get_text(); } + bool getRegister() + { return registerButton.get_active(); } private: @@ -387,18 +389,20 @@ private: bool doSetup(); - Gtk::Table table; - - Gtk::Label hostLabel; - Gtk::Entry hostField; - Gtk::Label portLabel; - Gtk::SpinButton portSpinner; - Gtk::Label userLabel; - Gtk::Entry userField; - Gtk::Label passLabel; - Gtk::Entry passField; - Gtk::Label resourceLabel; - Gtk::Entry resourceField; + Gtk::Table table; + + Gtk::Label hostLabel; + Gtk::Entry hostField; + Gtk::Label portLabel; + Gtk::SpinButton portSpinner; + Gtk::Label userLabel; + Gtk::Entry userField; + Gtk::Label passLabel; + Gtk::Entry passField; + Gtk::Label resourceLabel; + Gtk::Entry resourceField; + Gtk::Label registerLabel; + Gtk::CheckButton registerButton; PedroGui &parent; }; diff --git a/src/pedro/pedroxmpp.cpp b/src/pedro/pedroxmpp.cpp index f5ce69e0b..7ee3d599e 100644 --- a/src/pedro/pedroxmpp.cpp +++ b/src/pedro/pedroxmpp.cpp @@ -2393,6 +2393,7 @@ void XmppClient::assign(const XmppClient &other) password = other.password; resource = other.resource; connected = other.connected; + doRegister = other.doRegister; groupChats = other.groupChats; } @@ -2402,6 +2403,7 @@ void XmppClient::init() sock = new TcpSocket(); msgId = 0; connected = false; + doRegister = false; for (int i=0 ; i" + "" + "\n"; + if (!write(fmt)) + return false; + + DOMString recbuf = readStanza(); + Element *elem = parser.parse(recbuf); + elem->print(); + + //# does the entity send the "instructions" tag? + bool hasInstructions = + (elem->findElements("instructions").size() > 0); + delete elem; + + if (!hasInstructions) + { + error("server did not offer registration"); + return false; + } + + fmt = + "" + "" + "%s" + "&s" + "" + "\n"; + if (!write(fmt, toXml(username).c_str(), toXml(password).c_str() )) + return false; + + + recbuf = readStanza(); + elem = parser.parse(recbuf); + elem->print(); + + std::vector list = elem->findElements("error"); + if (list.size()>0) + { + Element *errElem = list[0]; + DOMString code = errElem->getAttribute("code"); + DOMString errMsg = "Registration error. "; + if (code == "409") + { + errMsg.append("conflict with existing user name"); + } + if (code == "406") + { + errMsg.append("some registration information was not provided"); + } + error((char *)errMsg.c_str()); + delete elem; + return false; + } + + delete elem; + + XmppEvent evt(XmppEvent::EVENT_REGISTRATION_NEW); + dispatchXmppEvent(evt); + return true; +} bool XmppClient::createSession() @@ -3510,6 +3581,13 @@ bool XmppClient::createSession() return false; } + //register, if user requests + if (doRegister) + { + if (!inBandRegistration()) + return false; + } + char *fmt = "::iterator iter; for (iter=roster.begin() ; iter != roster.end() ; iter++) { @@ -4334,6 +4412,8 @@ int XmppClient::inputStreamOpen(const DOMString &fromJid, const DOMString &strea return streamNr; } + + /** * */ @@ -4772,7 +4852,7 @@ DOMString XmppGroupChat::getGroupJid() } -void XmppGroupChat::userAdd(const DOMString &nick, +void XmppGroupChat::userAdd(const DOMString &nick, const DOMString &jid) { std::vector::iterator iter; @@ -4785,7 +4865,7 @@ void XmppGroupChat::userAdd(const DOMString &nick, userList.push_back(user); } -void XmppGroupChat::userShow(const DOMString &nick, +void XmppGroupChat::userShow(const DOMString &nick, const DOMString &show) { DOMString theShow = show; diff --git a/src/pedro/pedroxmpp.h b/src/pedro/pedroxmpp.h index d938a25fd..74985bfa2 100644 --- a/src/pedro/pedroxmpp.h +++ b/src/pedro/pedroxmpp.h @@ -97,6 +97,7 @@ typedef enum EVENT_CONNECTED, EVENT_DISCONNECTED, EVENT_PRESENCE, + EVENT_REGISTRATION_NEW, EVENT_ROSTER, EVENT_MESSAGE, EVENT_MUC_JOIN, @@ -552,6 +553,10 @@ public: */ virtual bool write(char *fmt, ...); + //####################### + //# V A R I A B L E S + //####################### + /** * */ @@ -633,12 +638,33 @@ public: */ virtual DOMString getJid() { return jid; } + /** * */ virtual int getMsgId() { return msgId++; } + /** + * + */ + virtual void setDoRegister(bool val) + { doRegister = val; } + + + /** + * + */ + virtual bool getDoRegister() + { return doRegister; } + + + + //####################### + //# P R O C E S S I N G + //####################### + + /** * */ @@ -689,7 +715,7 @@ public: * */ virtual void rosterShow(const DOMString &jid, const DOMString &show); - + //####################### //# CHAT (individual) //####################### @@ -934,8 +960,12 @@ private: bool iqAuthenticate(const DOMString &streamId); + bool inBandRegistration(); + bool keepGoing; + bool doRegister; + static const int writeBufLen = 2048; unsigned char writeBuf[writeBufLen]; @@ -994,7 +1024,7 @@ public: /** * */ - virtual void userAdd(const DOMString &nick, + virtual void userAdd(const DOMString &nick, const DOMString &jid); /** *