1
/****************************************************************************
2
** jabio.cpp - handles JabTasks
3
** Copyright (C) 2001, 2002 Justin Karneges
5
** This program is free software; you can redistribute it and/or
6
** modify it under the terms of the GNU General Public License
7
** as published by the Free Software Foundation; either version 2
8
** of the License, or (at your option) any later version.
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
19
****************************************************************************/
25
/****************************************************************************
27
****************************************************************************/
28
JabTask::JabTask(JabTask *_parent)
32
v_io = parent()->io();
39
JabTask::JabTask(JabIO *_parent)
48
JabTask *JabTask::parent()
53
QDomDocument *JabTask::doc()
58
JabTask *JabTask::find(const char *s)
60
const QObjectList *p = children();
66
for(; it.current(); ++it) {
67
j = static_cast<JabTask*>(it.current());
75
JabTask *JabTask::findById(const QString &s)
77
const QObjectList *p = children();
83
for(; it.current(); ++it) {
84
j = static_cast<JabTask*>(it.current());
92
bool JabTask::stamp2TS(const QString &ts, QDateTime *d)
97
int year = ts.mid(0,4).toInt();
98
int month = ts.mid(4,2).toInt();
99
int day = ts.mid(6,2).toInt();
101
int hour = ts.mid(9,2).toInt();
102
int min = ts.mid(12,2).toInt();
103
int sec = ts.mid(15,2).toInt();
106
xd.setYMD(year, month, day);
111
xt.setHMS(hour, min, sec);
121
QString JabTask::TS2stamp(const QDateTime &d)
125
str.sprintf("%04d%02d%02dT%02d:%02d:%02d",
136
QDomElement JabTask::textTag(const QString &name, const QString &content)
138
QDomElement tag = doc()->createElement(name);
139
QDomText text = doc()->createTextNode(content);
140
tag.appendChild(text);
145
QString JabTask::tagContent(const QDomElement &e)
147
// look for some tag content
148
for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
149
QDomText i = n.toText();
158
QDomElement JabTask::findSubTag(const QDomElement &e, const QString &name, bool *found)
163
for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
164
QDomElement i = n.toElement();
167
if(i.tagName() == name) {
178
QDomElement JabTask::createIQ(const QString &type, const QString &to, const QString &id)
180
QDomElement iq = doc()->createElement("iq");
182
iq.setAttribute("type", type);
184
iq.setAttribute("to", to);
186
iq.setAttribute("id", id);
191
QDomElement JabTask::queryTag(const QDomElement &e)
194
QDomElement q = findSubTag(e, "query", &found);
198
QString JabTask::queryNS(const QDomElement &e)
201
QDomElement q = findSubTag(e, "query", &found);
203
return q.attribute("xmlns");
208
JabRoster JabTask::xmlReadRoster(const QDomElement &q, bool push)
212
for(QDomNode n = q.firstChild(); !n.isNull(); n = n.nextSibling()) {
213
QDomElement i = n.toElement();
217
if(i.tagName() == "item") {
218
JabRosterEntry entry;
221
entry.jid = i.attribute("jid");
222
entry.sub = i.attribute("subscription");
223
entry.nick = i.attribute("name");
226
found = i.hasAttribute("ask");
227
if(found && i.attribute("ask") == "subscribe")
236
for(QDomNode n = i.firstChild(); !n.isNull(); n = n.nextSibling()) {
237
QDomElement tag = n.toElement();
241
if(tag.tagName() == "group")
242
entry.groups.append(tagContent(tag));
245
JabRosterEntry *tmp = new JabRosterEntry(entry);
253
QString JabTask::getErrorString(const QDomElement &e)
256
QDomElement tag = findSubTag(e, "error", &found);
260
return tagContent(tag);
263
void JabTask::done(JabTask *j)
269
QString JabTask::toString()
274
bool JabTask::fromString(const QString &)
279
void JabTask::setSuccess(bool b)
284
JabTask *p = parent();
289
void JabTask::setError(const QString &s)
294
void JabTask::send(const QDomElement &x)
299
bool JabTask::take(const QDomElement &x)
301
const QObjectList *p = children();
305
// pass along the xml
306
QObjectListIt it(*p);
308
for(; it.current(); ++it) {
309
j = static_cast<JabTask*>(it.current());
317
void JabTask::childEvent(QChildEvent *e)
320
childAdded((JabTask *)e->child());
321
else if(e->removed())
322
childRemoved((JabTask *)e->child());
326
/****************************************************************************
328
****************************************************************************/
332
v_root = new JabTask(this);
339
QString JabIO::getId()
342
s.sprintf("a%x", id_seed);
347
JabTask *JabIO::root()
359
const QObjectList *p = root()->children();
362
QObjectListIt it(*p);
363
for(; it.current(); ++it) {
364
JabTask *j = (JabTask *)it.current();
370
void JabIO::doneJT(JabTask *p)
372
if(p->parent()->isRoot())
378
void JabIO::distribute(const QDomElement &x)
380
if(!root()->take(x)) {
381
//printf("JabIO: packet was ignored.\n");
385
void JabIO::send(const QDomElement &x)
388
QTextStream ts(&out, IO_WriteOnly);
391
pdb(DEBUG_JABBER, QString("JabIO: outgoing: [\n%1]\n").arg(out));
395
void JabIO::incomingPacket(const QDomElement &x)
398
QTextStream ts(&out, IO_WriteOnly);
401
pdb(DEBUG_JABXML, QString("JabIO: incoming: [\n%1]\n").arg(out));
405
JabTask *JabIO::find(const char *s)
407
return root()->find(s);
410
JabTask *JabIO::findById(const QString &s)
412
return root()->findById(s);