]>
code.delx.au - pymsnt/blob - src/baseproto/glue.py
d273dfc9bf917be4154a65c34608e243f0995748
1 # Copyright 2004 James Bunton <james@delx.cjb.net>
2 # Licensed for distribution under the GPL version 2, check COPYING for details
4 from tlib
.domish
import Element
7 # The name of the transport
10 # The transport version
13 # XDB '@' -> '%' mangling
16 # The transport identifier (eg, aim, icq, msn)
19 # This should be set to the name space registration entries are in, in the xdb spool
20 namespace
= "jabber:iq:register"
25 """ Returns True if the JID passed is a valid groupchat JID (eg, for MSN, if it does not contain '%') """
30 def formRegEntry(username
, password
, nickname
):
31 """ Returns a domish.Element representation of the data passed. This element will be written to the XDB spool file """
36 def getAttributes(base
):
37 """ This function should, given a spool domish.Element, pull the username, password,
38 and nickname out of it and return them """
40 # return username, password, nickname
45 def translateAccount(legacyaccount
):
46 """ Translates the legacy account into a Jabber ID, eg, user@hotmail.com --> user%hotmail.com@msn.jabber.org """
51 class LegacyGroupchat(groupchat
.BaseGroupchat
):
52 """ A class to represent a groupchat on the legacy service. All the functions below
53 must be implemented to translate messages from Jabber to the legacy protocol.
54 Look in groupchat.py for available functions to call.
56 def __init__(self
, session
, resource
, ID
=None):
57 groupchat
.BaseGroupchat
.__init
__(self
, session
, resource
, ID
)
58 # Initialisation stuff for the legacy protocol goes here
61 """ Cleanly remove the the groupchat, including removing the user from the legacy room """
62 groupchat
.BaseGroupchat
.removeMe(self
)
64 def sendLegacyMessage(self
, message
):
65 """ Send this message to the legacy room """
67 def sendContactInvite(self
, contactJID
):
68 """ Invite this user to the legacy room """
73 class LegacyConnection
:
74 """ A base class that must have all functions reimplemented by legacy protocols to translate
75 from Jabber to that legacy protocol. Any incoming events from the legacy system must be
76 translated by calling the appropriate functions in the Session, JabberConnection or PyTransport classes.
77 You must also set self.session.ready = True at some point (usually when you have been connected to the
79 def __init__(self
, session
):
83 """ Called by PyTransport when the user's session is ending.
84 Must cleanly delete this object. Including sending an offline presence packet
85 for any contacts that may be on the user's list """
88 def resourceOffline(self
, resource
):
89 """ Called whenever one of the local user's resources goes offline """
92 def sendMessage(self
, dest
, resource
, body
, noerror
):
93 """ Called whenever PyTransport wants to send a message to a remote user """
96 def setStatus(self
, show
, friendly
):
97 """ Called whenever PyTransport needs to change the status on the legacy service
98 'show' is a Jabber status description, and friendly is a friendly name for the contact """
101 def newResourceOnline(self
, resource
):
102 """ Called by PyTransport when a new resource comes online. You should send them any legacy contacts' status """
105 def jabberSubscriptionReceived(self
, to
, subtype
):
106 """ Called by PyTransport whenever a Jabber subscription packet is received """
109 def userTypingNotification(self
, dest
, composing
):
110 """ Called by PyTransport whenever the Jabber user has sent typing notification to a contact """