paulb@271 | 1 | #!/usr/bin/env python |
paulb@271 | 2 | |
paulb@271 | 3 | import libxml2dom.xmpp |
paulb@271 | 4 | import sys |
paulb@271 | 5 | |
paulb@271 | 6 | sender = "sender" in sys.argv |
paulb@271 | 7 | receiver = "receiver" in sys.argv |
paulb@271 | 8 | if not (sender or receiver): |
paulb@271 | 9 | print "Please specify sender or receiver." |
paulb@271 | 10 | sys.exit(1) |
paulb@271 | 11 | |
paulb@271 | 12 | s = libxml2dom.xmpp.Session(("localhost", 5222)) |
paulb@271 | 13 | d = s.connect("jeremy") |
paulb@271 | 14 | print "---- 1 ----" |
paulb@271 | 15 | print d.toString() |
paulb@271 | 16 | |
paulb@271 | 17 | auth = s.createAuth() |
paulb@271 | 18 | auth.mechanism = "PLAIN" |
paulb@271 | 19 | auth.setCredentials("paulb@jeremy", "paulb", "jabber") |
paulb@271 | 20 | d = s.send(auth) |
paulb@271 | 21 | print "---- 2 ----" |
paulb@271 | 22 | print d.toString() |
paulb@271 | 23 | |
paulb@271 | 24 | d = s.connect("jeremy") |
paulb@271 | 25 | print "---- 3 ----" |
paulb@271 | 26 | print d.toString() |
paulb@271 | 27 | |
paulb@271 | 28 | iq = s.createIq() |
paulb@271 | 29 | iq.makeBind() |
paulb@271 | 30 | if sender: |
paulb@271 | 31 | iq.bind.resource = "sender" |
paulb@271 | 32 | else: |
paulb@271 | 33 | iq.bind.resource = "receiver" |
paulb@271 | 34 | d = s.send(iq) |
paulb@271 | 35 | print "---- 4 ----" |
paulb@271 | 36 | print d.toString() |
paulb@271 | 37 | |
paulb@271 | 38 | iq = s.createIq() |
paulb@271 | 39 | iq.makeSession("jeremy") |
paulb@271 | 40 | d = s.send(iq) |
paulb@271 | 41 | print "---- 5 ----" |
paulb@271 | 42 | print d.toString() |
paulb@271 | 43 | |
paulb@271 | 44 | if sender: |
paulb@271 | 45 | message = s.createMessage() |
paulb@271 | 46 | message.from_ = "paulb@jeremy/sender" |
paulb@271 | 47 | message.to = "paulb@jeremy/receiver" |
paulb@271 | 48 | message.type = "chat" |
paulb@271 | 49 | body = message.ownerDocument.createElement("body") |
paulb@271 | 50 | message.appendChild(body) |
paulb@271 | 51 | text = message.ownerDocument.createTextNode("Hello!") |
paulb@271 | 52 | body.appendChild(text) |
paulb@271 | 53 | print message.toString() |
paulb@271 | 54 | s.send(message) |
paulb@271 | 55 | |
paulb@271 | 56 | # vim: tabstop=4 expandtab shiftwidth=4 |