summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9ee44fc)
raw | patch | inline | side by side (parent: 9ee44fc)
| author | ishmal <ishmal@users.sourceforge.net> | |
| Sat, 2 Dec 2006 17:19:20 +0000 (17:19 +0000) | ||
| committer | ishmal <ishmal@users.sourceforge.net> | |
| Sat, 2 Dec 2006 17:19:20 +0000 (17:19 +0000) |
| src/pedro/pedroxmpp.cpp | patch | blob | history | |
| src/pedro/pedroxmpp.h | patch | blob | history |
index 53bac92d5be8450a6426c05d2dac60730fbf0094..8757d04028af2e80f5694edb766d95a95efe4185 100644 (file)
--- a/src/pedro/pedroxmpp.cpp
+++ b/src/pedro/pedroxmpp.cpp
}
-static int strRIndex(const DOMString &str, char *key)
-{
- unsigned int p = str.find_last_of(key);
- if (p == str.npos)
- return -1;
- return p;
-}
-
-
-
DOMString XmppClient::toXml(const DOMString &str)
{
return Parser::encode(str);
static bool parseJid(const DOMString &fullJid,
DOMString &jid, DOMString &resource)
{
- int p = strRIndex(fullJid, "/");
- if (p < 0)
+ DOMString str = fullJid;
+ jid.clear();
+ resource.clear();
+ unsigned int p = str.size();
+ unsigned int p2 = str.rfind('/', p);
+ if (p2 != str.npos)
{
- jid = fullJid;
- resource = "";
- return true;
+ resource = str.substr(p2+1, p-(p2+1));
+ str = str.substr(0, p);
+ p = p2;
}
- jid = fullJid.substr(0, p);
- resource = fullJid.substr(p+1, fullJid.size()-(p+1));
+ jid = str.substr(0, p);
+ printf("fullJid:%s jid:%s rsrc:%s\n",
+ fullJid.c_str(), jid.c_str(), resource.c_str());
return true;
}
//elem->print();
DOMString bindType = elem->getTagAttribute("iq", "type");
//printf("##bindType:%s\n", bindType.c_str());
+ DOMString givenFullJid = elem->getTagValue("jid");
delete elem;
if (bindType != "result")
error("no binding with server failed");
return false;
}
+
+ //The server sent us a JID. We need to listen.
+ if (givenFullJid.size()>0)
+ {
+ DOMString givenJid, givenResource;
+ parseJid(givenFullJid, givenJid, givenResource);
+ status("given user: %s realm: %s, rsrc: %s",
+ givenJid.c_str(), givenResource.c_str());
+ setResource(givenResource);
+ }
+
fmt =
"<iq type='set' id='sess%d'>"
if (xmlSubj.size() > 0)
{
char *fmt =
- "<message to='%s' type='chat'>"
+ "<message to='%s' from='%s' type='chat'>"
"<subject>%s</subject><body>%s</body></message>\n";
- if (!write(fmt, user.c_str(),
+ if (!write(fmt, user.c_str(), jid.c_str(),
xmlSubj.c_str(), xmlMsg.c_str()))
return false;
}
else
{
char *fmt =
- "<message to='%s'>"
+ "<message to='%s' from='%s'>"
"<body>%s</body></message>\n";
- if (!write(fmt, user.c_str(), xmlMsg.c_str()))
+ if (!write(fmt, user.c_str(), jid.c_str(), xmlMsg.c_str()))
return false;
}
return true;
DOMString xmlMsg = toXml(msg);
- /*
char *fmt =
"<message from='%s' to='%s' type='groupchat'>"
"<body>%s</body></message>\n";
if (!write(fmt, jid.c_str(), groupJid.c_str(), xmlMsg.c_str()))
return false;
- */
+ /*
char *fmt =
"<message to='%s' type='groupchat'>"
"<body>%s</body></message>\n";
if (!write(fmt, groupJid.c_str(), xmlMsg.c_str()))
return false;
+ */
return true;
}
diff --git a/src/pedro/pedroxmpp.h b/src/pedro/pedroxmpp.h
index 0e07013e6f47f810f8e7f68777edb21eff6b7c76..a2fbd87a29df615c6bd53ef6da1536dec4e1a742 100644 (file)
--- a/src/pedro/pedroxmpp.h
+++ b/src/pedro/pedroxmpp.h
virtual void setResource(const DOMString &val)
{ resource = val; }
+ /**
+ *
+ */
+ virtual void setJid(const DOMString &val)
+ { jid = val; }
+
/**
*
*/
virtual DOMString getJid()
{ return jid; }
+
+
/**
*
*/