summaryrefslogtreecommitdiff
path: root/examples/http_over_xmpp_transport.py
blob: 7a60c6fcf105c07746a7ee0b92925940217e8593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from sleekxmpp import ClientXMPP
import logging


# def tracefunc(frame, event, arg, indent=[0]):
#     prefix = "/Users/sangeeth/code/SleekXMPP/sleekxmpp/"
#     if not frame.f_code.co_filename.startswith(prefix):
#         return tracefunc
#     if event == "call":
#         indent[0] += 2
#         cn = getattr(
#             getattr(frame.f_locals.get("self"), "__class__", None),
#             "__name__", None
#         )
#         print "{}{} {} {}".format(
#             "." * indent[0], frame.f_code.co_filename[len(prefix):],
#             cn, frame.f_code.co_name
#         )
#     elif event == "return":
#         indent[0] -= 2
#     return tracefunc
#
#
# import sys
# sys.settrace(tracefunc)


class HTTPOverXMPPClient(ClientXMPP):
    def __init__(self, jid, password):
        ClientXMPP.__init__(self, jid, password)

    #     self.register_plugin('xep_0030')  # Service Discovery
    #     self.register_plugin('xep_0004')  # Data Forms
    #     self.register_plugin('xep_0060')  # PubSub
    #     self.register_plugin('xep_0199')  # XMPP Ping
    #
    #     self.add_event_handler("session_start", self.session_start)
    #     self.add_event_handler("connected", self.connected)
    #
    # def session_start(self, event):
    #     print "Client::session_start()"
    #     self.send_presence()
    #     print self.get_roster()
    #
    # def connected(self, event):
    #     print "Client::connected()"


def get_cred(filename="/tmp/.cred"):
    with open(filename, "r") as f:
        return f.readline().split()


if __name__ == "__main__":

    logging.basicConfig(
        level=logging.DEBUG, format='%(levelname)-8s %(message)s'
    )

    jid, password = get_cred()
    xmpp = HTTPOverXMPPClient(jid, password)
    if xmpp.connect(("talk.l.google.com", 5222)):
        print "Connected!"
        xmpp.process(block=True)
    else:
        print "Not connected!"
    print "Goodbye...."