summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8089eba)
raw | patch | inline | side by side (parent: 8089eba)
author | ishmal <ishmal@users.sourceforge.net> | |
Sun, 21 May 2006 20:57:48 +0000 (20:57 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Sun, 21 May 2006 20:57:48 +0000 (20:57 +0000) |
src/pedro/pedrogui.cpp | patch | blob | history | |
src/pedro/pedroxmpp.cpp | patch | blob | history |
diff --git a/src/pedro/pedrogui.cpp b/src/pedro/pedrogui.cpp
index cbfea0938daee5df99b4024e6738b3c37be60f83..48dfa94e91c9401ab0452bf9d0fbf103c5a53491 100644 (file)
--- a/src/pedro/pedrogui.cpp
+++ b/src/pedro/pedrogui.cpp
table.resize(6, 2);
get_vbox()->pack_start(table);
- parent.client.setHost("gristle.org");
+ parent.client.setHost("broadway.dynalias.com");
parent.client.setPort(5223);
parent.client.setUsername("");
parent.client.setPassword("");
index 7ee3d599e0be1354ad42b0f6547555c7419449f4..f447b93565acd20cac1db7b3da3712e9588f0d6c 100644 (file)
--- a/src/pedro/pedroxmpp.cpp
+++ b/src/pedro/pedroxmpp.cpp
#include "pedroxmpp.h"
#include "pedrodom.h"
+#include <map>
+
#ifdef __WIN32__
#include <windows.h>
sslStream = SSL_new(sslContext);
SSL_set_fd(sslStream, sock);
- if (SSL_connect(sslStream)<=0)
+ int ret = SSL_connect(sslStream);
+ if (ret == 0)
+ {
+ fprintf(stderr, "SSL connection not successful\n");
+ disconnect();
+ return false;
+ }
+ else if (ret < 0)
{
- fprintf(stderr, "SSL connect error\n");
+ int err = SSL_get_error(sslStream, ret);
+ fprintf(stderr, "SSL connect error %d\n", err);
disconnect();
return false;
}
{
if (hostname.size()<1)
{
- printf("open: null hostname\n");
+ fprintf(stderr, "open: null hostname\n");
return false;
}
if (portno<1)
{
- printf("open: bad port number\n");
+ fprintf(stderr, "open: bad port number\n");
return false;
}
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
- printf("open: error creating socket\n");
+ fprintf(stderr, "open: error creating socket\n");
return false;
}
struct hostent *server = gethostbyname(c_hostname);
if (!server)
{
- printf("open: could not locate host '%s'\n", c_hostname);
+ fprintf(stderr, "open: could not locate host '%s'\n", c_hostname);
return false;
}
int ret = ::connect(sock, (const sockaddr *)&serv_addr, sizeof(serv_addr));
if (ret < 0)
{
- printf("open: could not connect to host '%s'\n", c_hostname);
+ fprintf(stderr, "open: could not connect to host '%s'\n", c_hostname);
return false;
}
{
if (!isConnected())
{
- printf("write: socket closed\n");
+ fprintf(stderr, "write: socket closed\n");
return false;
}
unsigned char c = (unsigned char)ch;
switch(SSL_get_error(sslStream, r))
{
default:
- printf("SSL write problem");
+ fprintf(stderr, "SSL write problem");
return -1;
}
}
if (send(sock, (const char *)&c, 1, 0) < 0)
//if (send(sock, &c, 1, 0) < 0)
{
- printf("write: could not send data\n");
+ fprintf(stderr, "write: could not send data\n");
return false;
}
}
{
if (!isConnected())
{
- printf("write(str): socket closed\n");
+ fprintf(stderr, "write(str): socket closed\n");
return false;
}
int len = strlen(str);
switch(SSL_get_error(sslStream, r))
{
default:
- printf("SSL write problem");
+ fprintf(stderr, "SSL write problem");
return -1;
}
}
if (send(sock, str, len, 0) < 0)
//if (send(sock, &c, 1, 0) < 0)
{
- printf("write: could not send data\n");
+ fprintf(stderr, "write: could not send data\n");
return false;
}
}
case SSL_ERROR_ZERO_RETURN:
return -1;
case SSL_ERROR_SYSCALL:
- printf("SSL read problem(syscall) %s\n",
+ fprintf(stderr, "SSL read problem(syscall) %s\n",
ERR_error_string(ERR_get_error(), NULL));
return -1;
default:
- printf("SSL read problem %s\n",
+ fprintf(stderr, "SSL read problem %s\n",
ERR_error_string(ERR_get_error(), NULL));
return -1;
}
{
if (recv(sock, (char *)&ch, 1, 0) <= 0)
{
- printf("read: could not receive data\n");
+ fprintf(stderr, "read: could not receive data\n");
disconnect();
return -1;
}
}
+static bool
+saslParse(const DOMString &s, std::map<DOMString, DOMString> &vals)
+{
+
+ vals.clear();
+
+ int p = 0;
+ int siz = s.size();
+
+ while (p < siz)
+ {
+ DOMString key;
+ DOMString value;
+ char ch = '\0';
+
+ //# Parse key
+ while (p<siz)
+ {
+ ch = s[p++];
+ if (ch == '=')
+ break;
+ key.push_back(ch);
+ }
+
+ //No value?
+ if (ch != '=')
+ break;
+
+ //# Parse value
+ bool quoted = false;
+ while (p<siz)
+ {
+ ch = s[p++];
+ if (ch == '"')
+ quoted = !quoted;
+ else if (ch == ',' && !quoted)
+ break;
+ else
+ value.push_back(ch);
+ }
+
+ //printf("# Key: '%s' Value: '%s'\n", key.c_str(), value.c_str());
+ vals[key] = value;
+ if (ch != ',')
+ break;
+ }
+
+ return true;
+}
+
+
+
+
bool XmppClient::saslMd5Authenticate()
{
DOMString challenge = Base64Decoder::decodeToString(b64challenge);
status("challenge:'%s'", challenge.c_str());
- unsigned int p1 = challenge.find("nonce=\"");
- if (p1 == DOMString::npos)
+ std::map<DOMString, DOMString> attrs;
+ if (!saslParse(challenge, attrs))
+ {
+ error("login: error parsing SASL challenge");
+ return false;
+ }
+
+ DOMString nonce = attrs["nonce"];
+ if (nonce.size()==0)
{
error("login: no SASL nonce sent by server");
return false;
}
- p1 += 7;
- unsigned int p2 = challenge.find("\"", p1);
- if (p2 == DOMString::npos)
+
+ DOMString realm = attrs["realm"];
+ if (nonce.size()==0)
{
- error("login: unterminated SASL nonce sent by server");
+ error("login: no SASL realm sent by server");
return false;
}
- DOMString nonce = challenge.substr(p1, p2-p1);
- //printf("nonce: '%s'\n", nonce.c_str());
+
+ status("SASL recv nonce: '%s' realm:'%s'\n", nonce.c_str(), realm.c_str());
+
char idBuf[7];
snprintf(idBuf, 6, "%dsasl", msgId++);
DOMString cnonce = Sha1::hashHex((unsigned char *)idBuf, 7);
challenge = Base64Decoder::decodeToString(b64challenge);
status("challenge: '%s'", challenge.c_str());
- p1 = challenge.find("rspauth=");
- if (p1 == DOMString::npos)
+
+ if (!saslParse(challenge, attrs))
+ {
+ error("login: error parsing SASL challenge");
+ return false;
+ }
+
+ DOMString rspauth = attrs["rspauth"];
+ if (rspauth.size()==0)
{
error("login: no SASL respauth sent by server\n");
return false;
return false;
recbuf = readStanza();
- status("server says: '%s", recbuf.c_str());
+ status("SASL recv: '%s", recbuf.c_str());
elem = parser.parse(recbuf);
//elem->print();
b64challenge = elem->getTagValue("challenge");
elem = parser.parse(recbuf);
}
+ //register, if user requests
+ if (doRegister)
+ {
+ if (!inBandRegistration())
+ return false;
+ }
+
//check for sasl authentication mechanisms
std::vector<Element *> elems =
elem->findElements("mechanism");
char *fmt =
"<iq type='get' id='reg1'>"
"<query xmlns='jabber:iq:register'/>"
- "</iq>\n";
+ "</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();
"<iq type='set' id='reg2'>"
"<query xmlns='jabber:iq:register'>"
"<username>%s</username>"
- "<password>&s</password>"
+ "<password>%s</password>"
"</query>"
- "</iq>\n";
+ "</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();
return false;
}
- //register, if user requests
- if (doRegister)
- {
- if (!inBandRegistration())
- return false;
- }
-
char *fmt =
"<stream:stream "
"to='%s' "