#
# Originally written by Darryl Vandorp
# http://randomthoughts.vandorp.ca/

from twisted.words.protocols.jabber import client, jid
from twisted.words.xish import domish
from twisted.internet import reactor
        
def authd(xmlstream):
    print "authenticated"

    presence = domish.Element(('jabber:client','presence'))
    xmlstream.send(presence)
    
    xmlstream.addObserver('/message',  debug)
    xmlstream.addObserver('/presence', debug)
    xmlstream.addObserver('/iq',       debug)   

def debug(elem):
    print elem.toXml().encode('utf-8')
    print "="*20
    
myJid = jid.JID('d@jabber.org/twisted_words')
factory = client.basicClientFactory(myJid, 'd')
factory.addBootstrap('//event/stream/authd',authd)
reactor.connectTCP('jabber.org',5222,factory)
reactor.run()
