Code

Add placeholders for registration modify and cancel
authorishmal <ishmal@users.sourceforge.net>
Mon, 22 May 2006 18:22:46 +0000 (18:22 +0000)
committerishmal <ishmal@users.sourceforge.net>
Mon, 22 May 2006 18:22:46 +0000 (18:22 +0000)
src/pedro/pedroxmpp.cpp
src/pedro/pedroxmpp.h

index f12a75093f675bfe714e826cfefae8f15131296d..4847ebfd8379ad1203f2f5e99ea155cdbd06ed63 100644 (file)
@@ -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 =
+     "<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;
+}
+
+
 
 
 
@@ -3733,7 +3909,7 @@ bool XmppClient::saslAuthenticate()
     //register, if user requests
     if (doRegister)
         {
-        if (!inBandRegistration())
+        if (!inBandRegistrationNew())
             return false;
         }
 
index 63d3d59e3369f837e473e0352af4b88a178527b4..502dd1f082cd085b4307f9bd7546a29e586beb92 100644 (file)
@@ -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;