From b799ef30af6328e71e5103be67a3973a5a541e3f Mon Sep 17 00:00:00 2001 From: Bob Jamison Date: Mon, 22 May 2006 18:22:46 +0000 Subject: Add placeholders for registration modify and cancel (bzr r956) --- src/pedro/pedroxmpp.cpp | 180 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 178 insertions(+), 2 deletions(-) (limited to 'src/pedro/pedroxmpp.cpp') 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; } -- cgit v1.2.3