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