From: ishmal Date: Mon, 22 May 2006 19:33:16 +0000 (+0000) Subject: Improve code for password change and registration cancel X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fcc0e4e92ccd014163d7f252c395aa387b154893;p=inkscape.git Improve code for password change and registration cancel --- diff --git a/src/pedro/pedroxmpp.cpp b/src/pedro/pedroxmpp.cpp index 4847ebfd8..b531441f0 100644 --- a/src/pedro/pedroxmpp.cpp +++ b/src/pedro/pedroxmpp.cpp @@ -3289,12 +3289,12 @@ bool XmppClient::inBandRegistrationNew() { Element *errElem = list[0]; DOMString code = errElem->getAttribute("code"); - DOMString errMsg = "Registration error. "; + DOMString errMsg = "Registration error: "; if (code == "409") { errMsg.append("conflict with existing user name"); } - if (code == "406") + else if (code == "406") { errMsg.append("some registration information was not provided"); } @@ -3317,88 +3317,79 @@ bool XmppClient::inBandRegistrationNew() /** * Perform JEP-077 In-Band Registration */ -bool XmppClient::inBandRegistrationModify() +bool XmppClient::inBandRegistrationChangePassword(const DOMString &newpassword) { Parser parser; + //# Let's try it form-style to allow the common old/new password thing char *fmt = - "" - "" - "\n\n"; - if (!write(fmt)) + "" + " " + " " + " " + " jabber:iq:register:changepassword" + " " + " " + " %s" + " " + " " + " %s" + " " + " " + " %s" + " " + " " + " " + "\n\n"; + + if (!write(fmt, jid.c_str(), host.c_str(), + username.c_str(), password.c_str(), newpassword.c_str())) return false; DOMString recbuf = readStanza(); - status("RECV reg: %s", recbuf.c_str()); + status("RECV chpass: %s", recbuf.c_str()); Element *elem = parser.parse(recbuf); //elem->print(); - //# does the entity send the "instructions" tag? - std::vector fields = elem->findElements("field"); - std::vector fnames; - for (unsigned int i=0; i list = elem->findElements("error"); + if (list.size()==0) { - DOMString fname = fields[i]->getAttribute("var"); - if (fname == "FORM_TYPE") - continue; - fnames.push_back(fname); - status("field name:%s", fname.c_str()); + XmppEvent evt(XmppEvent::EVENT_REGISTRATION_CHANGE_PASS); + evt.setTo(username); + evt.setFrom(host); + dispatchXmppEvent(evt); + delete elem; + return true; } - delete elem; - if (fnames.size() == 0) + Element *errElem = list[0]; + DOMString errMsg = "Password change error: "; + if (errElem->findElements("bad-request").size()>0) { - error("server did not offer registration"); - return false; + errMsg.append("password change does not contain complete information"); } - - - fmt = - "" - "" - "%s" - "%s" - "" - "" - "\n\n"; - if (!write(fmt, toXml(username).c_str(), - toXml(password).c_str() )) - return false; - - - recbuf = readStanza(); - status("RECV reg: %s", recbuf.c_str()); - elem = parser.parse(recbuf); - //elem->print(); - - std::vector list = elem->findElements("error"); - if (list.size()>0) + else if (errElem->findElements("not-authorized").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; + errMsg.append("server does not consider the channel safe " + "enough to enable a password change"); + } + else if (errElem->findElements("not-allowed").size()>0) + { + errMsg.append("server does not allow password changes"); + } + else if (errElem->findElements("unexpected-request").size()>0) + { + errMsg.append( + "IQ set does not contain a 'from' address because " + "the entity is not registered with the server"); } delete elem; - XmppEvent evt(XmppEvent::EVENT_REGISTRATION_MODIFY); - evt.setTo(username); - evt.setFrom(host); - dispatchXmppEvent(evt); + error((char *)errMsg.c_str()); - return true; + return false; } @@ -3410,83 +3401,59 @@ bool XmppClient::inBandRegistrationCancel() Parser parser; char *fmt = - "" - "" - "\n\n"; - if (!write(fmt)) + "" + "" + "\n\n"; + if (!write(fmt, jid.c_str())) return false; DOMString recbuf = readStanza(); - status("RECV reg: %s", recbuf.c_str()); + status("RECV unreg: %s", recbuf.c_str()); Element *elem = parser.parse(recbuf); //elem->print(); - //# does the entity send the "instructions" tag? - std::vector fields = elem->findElements("field"); - std::vector fnames; - for (unsigned int i=0; i list = elem->findElements("error"); + if (list.size()==0) { - DOMString fname = fields[i]->getAttribute("var"); - if (fname == "FORM_TYPE") - continue; - fnames.push_back(fname); - status("field name:%s", fname.c_str()); + XmppEvent evt(XmppEvent::EVENT_REGISTRATION_CANCEL); + evt.setTo(username); + evt.setFrom(host); + dispatchXmppEvent(evt); + delete elem; + return true; } - delete elem; - if (fnames.size() == 0) + Element *errElem = list[0]; + DOMString errMsg = "Registration cancel error: "; + if (errElem->findElements("bad-request").size()>0) { - error("server did not offer registration"); - return false; + errMsg.append("The element was not the only child element of the element."); } - - - fmt = - "" - "" - "%s" - "%s" - "" - "" - "\n\n"; - if (!write(fmt, toXml(username).c_str(), - toXml(password).c_str() )) - return false; - - - recbuf = readStanza(); - status("RECV reg: %s", recbuf.c_str()); - elem = parser.parse(recbuf); - //elem->print(); - - std::vector list = elem->findElements("error"); - if (list.size()>0) + else if (errElem->findElements("forbidden").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; + errMsg.append("sender does not have sufficient permissions to cancel the registration"); + } + else if (errElem->findElements("not-allowed").size()>0) + { + errMsg.append("not allowed to cancel registrations in-band"); + } + else if (errElem->findElements("registration-required").size()>0) + { + errMsg.append("not previously registered"); + } + else if (errElem->findElements("unexpected-request").size()>0) + { + errMsg.append( + "IQ set does not contain a 'from' address because " + "the entity is not registered with the server"); } delete elem; - XmppEvent evt(XmppEvent::EVENT_REGISTRATION_CANCEL); - evt.setTo(username); - evt.setFrom(host); - dispatchXmppEvent(evt); + error((char *)errMsg.c_str()); - return true; + return false; } diff --git a/src/pedro/pedroxmpp.h b/src/pedro/pedroxmpp.h index 502dd1f08..12a69fa3b 100644 --- a/src/pedro/pedroxmpp.h +++ b/src/pedro/pedroxmpp.h @@ -139,10 +139,10 @@ public: static const int EVENT_REGISTRATION_NEW = 20; /** - * Client has successfully modified an existing account on a server. + * Client has successfully changed the password of an existing account on a server. * The server is in getFrom(), the user in getTo() */ - static const int EVENT_REGISTRATION_MODIFY = 21; + static const int EVENT_REGISTRATION_CHANGE_PASS = 21; /** * Client has successfully cancelled an existing account on a server. @@ -1132,9 +1132,9 @@ private: bool inBandRegistrationNew(); /** - * Modify an existing account with a server + * Change the password of an existing account with a server */ - bool inBandRegistrationModify(); + bool inBandRegistrationChangePassword(const DOMString &newPassword); /** * Cancel an existing account with a server