]> code.delx.au - pymsnt/blob - src/baseproto/glue.py
Reimport and tags (0.10.1)
[pymsnt] / src / baseproto / glue.py
1 # Copyright 2005 James Bunton <james@delx.cjb.net>
2 # Licensed for distribution under the GPL version 2, check COPYING for details
3
4 import utils
5 if(utils.checkTwisted()):
6 from twisted.xish.domish import Element
7 else:
8 from tlib.domish import Element
9 import avatar
10 import groupchat
11 import config
12 import debug
13 import lang
14
15
16 # The name of the transport
17 name = "Foo Transport"
18
19 # The URL of the transport's home page
20 url = "http://foo.jabberstudio.org"
21
22 # The transport version
23 version = "0.1"
24
25 # XDB '@' -> '%' mangling
26 mangle = True
27
28 # The transport identifier (eg, aim, icq, msn)
29 id = "foo"
30
31 # This should be set to the name space registration entries are in, in the xdb spool
32 namespace = "jabber:iq:register"
33
34
35
36 def isGroupJID(jid):
37 """ Returns True if the JID passed is a valid groupchat JID (eg, for MSN, if it does not contain '%') """
38 pass
39
40
41
42 def formRegEntry(username, password, nickname):
43 """ Returns a domish.Element representation of the data passed. This element will be written to the XDB spool file """
44 pass
45
46
47
48 def getAttributes(base):
49 """ This function should, given a spool domish.Element, pull the username and password
50 out of it and return them """
51 pass
52 # return username, password
53
54
55
56
57 def translateAccount(legacyaccount):
58 """ Translates the legacy account into a Jabber ID, eg, user@hotmail.com --> user%hotmail.com@msn.jabber.org """
59 pass
60
61
62 def startStats(statistics):
63 """ Fills the misciq.Statistics class with the statistics fields.
64 You must put a command_OnlineUsers and command_OnlineUsers_Desc
65 attributes into the lang classes for this to work.
66 Note that OnlineUsers is a builtin stat. You don't need to
67 reimplement it yourself. """
68 #statistics.stats["OnlineUsers"] = 0
69 pass
70
71 def updateStats(statistics):
72 """ This will get called regularly. Use it to update any global
73 statistics """
74 pass
75
76 class LegacyGroupchat(groupchat.BaseGroupchat):
77 """ A class to represent a groupchat on the legacy service. All the functions below
78 must be implemented to translate messages from Jabber to the legacy protocol.
79 Look in groupchat.py for available functions to call.
80 """
81 def __init__(self, session, resource, ID=None):
82 groupchat.BaseGroupchat.__init__(self, session, resource, ID)
83 # Initialisation stuff for the legacy protocol goes here
84
85 def removeMe(self):
86 """ Cleanly remove the the groupchat, including removing the user from the legacy room """
87 groupchat.BaseGroupchat.removeMe(self)
88
89 def sendLegacyMessage(self, message):
90 """ Send this message to the legacy room """
91
92 def sendContactInvite(self, contactJID):
93 """ Invite this user to the legacy room """
94
95
96
97 class LegacyList:
98 """ A base class that must have all functions reimplemented by legacy protocol to allow
99 legacy contact list to be accessible and modifiable from Jabber """
100 def __init__(self, session):
101 self.session = session
102
103 def removeMe(self):
104 self.session = None
105
106 def addContact(self, jid):
107 """ Must add this JID to the legacy list """
108 pass
109
110 def authContact(self, jid):
111 """ Must authorise this JID on the legacy service """
112 pass
113
114 def removeContact(self, jid):
115 """ Must remove this JID from the legacy list """
116 pass
117
118 def deauthContact(self, jid):
119 """ Must deauthorise this JID on the legacy service """
120 pass
121
122
123 class LegacyConnection:
124 """ A base class that must have all functions reimplemented by legacy protocols to translate
125 from Jabber to that legacy protocol. Any incoming events from the legacy system must be
126 translated by calling the appropriate functions in the Session, JabberConnection or PyTransport classes.
127 You must also set self.session.ready = True at some point (usually when you have been connected to the
128 legacy service """
129 def __init__(self, session):
130 self.session = session
131 self.legacyList = LegacyList()
132
133 def removeMe(self):
134 """ Called by PyTransport when the user's session is ending.
135 Must cleanly end the user's legacy protocol session and delete
136 this object. """
137 self.session = None
138 self.legacyList = None
139
140 def resourceOffline(self, resource):
141 """ Called whenever one of the local user's resources goes offline """
142 pass
143
144 def sendMessage(self, dest, resource, body, noerror):
145 """ Called whenever PyTransport wants to send a message to a remote user """
146 pass
147
148 def setStatus(self, nickname, show, status):
149 """ Called whenever PyTransport needs to change the status on the legacy service
150 'nickname' is the Jabber nickname, 'show' is a Jabber status description, and status
151 is a personal message describing the user's current status/activities """
152 pass
153
154 def updateAvatar(self, av=None):
155 """ Called whenever a new avatar needs to be set. Instance of avatar.Avatar is passed """
156 pass
157
158 def userTypingNotification(self, dest, composing):
159 """ Called by PyTransport whenever the Jabber user has sent typing notification to a contact """
160 pass
161
162