summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5f72258)
raw | patch | inline | side by side (parent: 5f72258)
author | ishmal <ishmal@users.sourceforge.net> | |
Mon, 22 May 2006 19:33:16 +0000 (19:33 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Mon, 22 May 2006 19:33:16 +0000 (19:33 +0000) |
src/pedro/pedroxmpp.cpp | patch | blob | history | |
src/pedro/pedroxmpp.h | patch | blob | history |
index 4847ebfd8379ad1203f2f5e99ea155cdbd06ed63..b531441f026ab2e4cf3e8e401c753ea5ca05aa92 100644 (file)
--- a/src/pedro/pedroxmpp.cpp
+++ b/src/pedro/pedroxmpp.cpp
{
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");
}
/**
* 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 =
- "<iq type='get' id='reg1'>"
- "<query xmlns='jabber:iq:register'/>"
- "</iq>\n\n";
- if (!write(fmt))
+ "<iq type='set' from='%s' to='%s' id='change1'>"
+ " <query xmlns='jabber:iq:register'>"
+ " <x xmlns='jabber:x:data' type='form'>"
+ " <field type='hidden' var='FORM_TYPE'>"
+ " <value>jabber:iq:register:changepassword</value>"
+ " </field>"
+ " <field type='text-single' var='username'>"
+ " <value>%s</value>"
+ " </field>"
+ " <field type='text-private' var='old_password'>"
+ " <value>%s</value>"
+ " </field>"
+ " <field type='text-private' var='password'>"
+ " <value>%s</value>"
+ " </field>"
+ " </x>"
+ " </query>"
+ "</iq>\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<Element *> fields = elem->findElements("field");
- std::vector<DOMString> fnames;
- for (unsigned int i=0; i<fields.size() ; i++)
+ std::vector<Element *> 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 =
- "<iq type='set' id='reg2'>"
- "<query xmlns='jabber:iq:register'>"
- "<username>%s</username>"
- "<password>%s</password>"
- "<email/><name/>"
- "</query>"
- "</iq>\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<Element *> 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;
}
Parser parser;
char *fmt =
- "<iq type='get' id='reg1'>"
- "<query xmlns='jabber:iq:register'/>"
- "</iq>\n\n";
- if (!write(fmt))
+ "<iq type='set' from='%s' id='unreg1'>"
+ "<query xmlns='jabber:iq:register'><remove/></query>"
+ "</iq>\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<Element *> fields = elem->findElements("field");
- std::vector<DOMString> fnames;
- for (unsigned int i=0; i<fields.size() ; i++)
+ std::vector<Element *> 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 <remove/> element was not the only child element of the <query/> element.");
}
-
-
- fmt =
- "<iq type='set' id='reg2'>"
- "<query xmlns='jabber:iq:register'>"
- "<username>%s</username>"
- "<password>%s</password>"
- "<email/><name/>"
- "</query>"
- "</iq>\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<Element *> 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 502dd1f082cd085b4307f9bd7546a29e586beb92..12a69fa3b4923a0db91ff294a9daf6ebf24b16bf 100644 (file)
--- a/src/pedro/pedroxmpp.h
+++ b/src/pedro/pedroxmpp.h
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.
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