summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: caade51)
raw | patch | inline | side by side (parent: caade51)
author | ishmal <ishmal@users.sourceforge.net> | |
Mon, 22 May 2006 18:22:46 +0000 (18:22 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Mon, 22 May 2006 18:22:46 +0000 (18:22 +0000) |
src/pedro/pedroxmpp.cpp | patch | blob | history | |
src/pedro/pedroxmpp.h | patch | blob | history |
index f12a75093f675bfe714e826cfefae8f15131296d..4847ebfd8379ad1203f2f5e99ea155cdbd06ed63 100644 (file)
--- a/src/pedro/pedroxmpp.cpp
+++ b/src/pedro/pedroxmpp.cpp
/**
* Perform JEP-077 In-Band Registration
*/
-bool XmppClient::inBandRegistration()
+bool XmppClient::inBandRegistrationNew()
{
Parser parser;
}
+/**
+ * Perform JEP-077 In-Band Registration
+ */
+bool XmppClient::inBandRegistrationModify()
+{
+ Parser parser;
+
+ char *fmt =
+ "<iq type='get' id='reg1'>"
+ "<query xmlns='jabber:iq:register'/>"
+ "</iq>\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<Element *> fields = elem->findElements("field");
+ std::vector<DOMString> fnames;
+ for (unsigned int i=0; i<fields.size() ; i++)
+ {
+ DOMString fname = fields[i]->getAttribute("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 =
+ "<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)
+ {
+ 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 =
+ "<iq type='get' id='reg1'>"
+ "<query xmlns='jabber:iq:register'/>"
+ "</iq>\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<Element *> fields = elem->findElements("field");
+ std::vector<DOMString> fnames;
+ for (unsigned int i=0; i<fields.size() ; i++)
+ {
+ DOMString fname = fields[i]->getAttribute("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 =
+ "<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)
+ {
+ 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;
+}
+
+
//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 63d3d59e3369f837e473e0352af4b88a178527b4..502dd1f082cd085b4307f9bd7546a29e586beb92 100644 (file)
--- a/src/pedro/pedroxmpp.h
+++ b/src/pedro/pedroxmpp.h
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;