From dac9576a8fe2db7a28c3d05f724e40d0742f0f77 Mon Sep 17 00:00:00 2001 From: ishmal Date: Mon, 22 May 2006 18:22:46 +0000 Subject: [PATCH] Add placeholders for registration modify and cancel --- src/pedro/pedroxmpp.cpp | 180 +++++++++++++++++++++++++++++++++++++++- src/pedro/pedroxmpp.h | 15 +++- 2 files changed, 192 insertions(+), 3 deletions(-) diff --git a/src/pedro/pedroxmpp.cpp b/src/pedro/pedroxmpp.cpp index f12a75093..4847ebfd8 100644 --- a/src/pedro/pedroxmpp.cpp +++ b/src/pedro/pedroxmpp.cpp @@ -3229,7 +3229,7 @@ bool XmppClient::write(char *fmt, ...) /** * Perform JEP-077 In-Band Registration */ -bool XmppClient::inBandRegistration() +bool XmppClient::inBandRegistrationNew() { Parser parser; @@ -3314,6 +3314,182 @@ bool XmppClient::inBandRegistration() } +/** + * Perform JEP-077 In-Band Registration + */ +bool XmppClient::inBandRegistrationModify() +{ + Parser parser; + + char *fmt = + "" + "" + "\n\n"; + if (!write(fmt)) + return false; + + DOMString recbuf = readStanza(); + status("RECV reg: %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; igetAttribute("var"); + if (fname == "FORM_TYPE") + continue; + fnames.push_back(fname); + status("field name:%s", fname.c_str()); + } + + delete elem; + + if (fnames.size() == 0) + { + error("server did not offer registration"); + return false; + } + + + 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) + { + 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_MODIFY); + evt.setTo(username); + evt.setFrom(host); + dispatchXmppEvent(evt); + + return true; +} + + +/** + * Perform JEP-077 In-Band Registration + */ +bool XmppClient::inBandRegistrationCancel() +{ + Parser parser; + + char *fmt = + "" + "" + "\n\n"; + if (!write(fmt)) + return false; + + DOMString recbuf = readStanza(); + status("RECV reg: %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; igetAttribute("var"); + if (fname == "FORM_TYPE") + continue; + fnames.push_back(fname); + status("field name:%s", fname.c_str()); + } + + delete elem; + + if (fnames.size() == 0) + { + error("server did not offer registration"); + return false; + } + + + 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) + { + 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_CANCEL); + evt.setTo(username); + evt.setFrom(host); + dispatchXmppEvent(evt); + + return true; +} + + @@ -3733,7 +3909,7 @@ bool XmppClient::saslAuthenticate() //register, if user requests if (doRegister) { - if (!inBandRegistration()) + if (!inBandRegistrationNew()) return false; } diff --git a/src/pedro/pedroxmpp.h b/src/pedro/pedroxmpp.h index 63d3d59e3..502dd1f08 100644 --- a/src/pedro/pedroxmpp.h +++ b/src/pedro/pedroxmpp.h @@ -1126,7 +1126,20 @@ private: bool iqAuthenticate(const DOMString &streamId); - bool inBandRegistration(); + /** + * Register a new account with a server + */ + bool inBandRegistrationNew(); + + /** + * Modify an existing account with a server + */ + bool inBandRegistrationModify(); + + /** + * Cancel an existing account with a server + */ + bool inBandRegistrationCancel(); bool keepGoing; -- 2.30.2