ijabber.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Public Jabber Interfaces.
  5. """
  6. from zope.interface import Attribute, Interface
  7. class IInitializer(Interface):
  8. """
  9. Interface for XML stream initializers.
  10. Initializers perform a step in getting the XML stream ready to be
  11. used for the exchange of XML stanzas.
  12. """
  13. class IInitiatingInitializer(IInitializer):
  14. """
  15. Interface for XML stream initializers for the initiating entity.
  16. """
  17. xmlstream = Attribute("""The associated XML stream""")
  18. def initialize():
  19. """
  20. Initiate the initialization step.
  21. May return a deferred when the initialization is done asynchronously.
  22. """
  23. class IIQResponseTracker(Interface):
  24. """
  25. IQ response tracker interface.
  26. The XMPP stanza C{iq} has a request-response nature that fits
  27. naturally with deferreds. You send out a request and when the response
  28. comes back a deferred is fired.
  29. The L{twisted.words.protocols.jabber.client.IQ} class implements a C{send}
  30. method that returns a deferred. This deferred is put in a dictionary that
  31. is kept in an L{XmlStream} object, keyed by the request stanzas C{id}
  32. attribute.
  33. An object providing this interface (usually an instance of L{XmlStream}),
  34. keeps the said dictionary and sets observers on the iq stanzas of type
  35. C{result} and C{error} and lets the callback fire the associated deferred.
  36. """
  37. iqDeferreds = Attribute("Dictionary of deferreds waiting for an iq "
  38. "response")
  39. class IXMPPHandler(Interface):
  40. """
  41. Interface for XMPP protocol handlers.
  42. Objects that provide this interface can be added to a stream manager to
  43. handle of (part of) an XMPP extension protocol.
  44. """
  45. parent = Attribute("""XML stream manager for this handler""")
  46. xmlstream = Attribute("""The managed XML stream""")
  47. def setHandlerParent(parent):
  48. """
  49. Set the parent of the handler.
  50. @type parent: L{IXMPPHandlerCollection}
  51. """
  52. def disownHandlerParent(parent):
  53. """
  54. Remove the parent of the handler.
  55. @type parent: L{IXMPPHandlerCollection}
  56. """
  57. def makeConnection(xs):
  58. """
  59. A connection over the underlying transport of the XML stream has been
  60. established.
  61. At this point, no traffic has been exchanged over the XML stream
  62. given in C{xs}.
  63. This should setup L{xmlstream} and call L{connectionMade}.
  64. @type xs:
  65. L{twisted.words.protocols.jabber.xmlstream.XmlStream}
  66. """
  67. def connectionMade():
  68. """
  69. Called after a connection has been established.
  70. This method can be used to change properties of the XML Stream, its
  71. authenticator or the stream manager prior to stream initialization
  72. (including authentication).
  73. """
  74. def connectionInitialized():
  75. """
  76. The XML stream has been initialized.
  77. At this point, authentication was successful, and XML stanzas can be
  78. exchanged over the XML stream L{xmlstream}. This method can be
  79. used to setup observers for incoming stanzas.
  80. """
  81. def connectionLost(reason):
  82. """
  83. The XML stream has been closed.
  84. Subsequent use of C{parent.send} will result in data being queued
  85. until a new connection has been established.
  86. @type reason: L{twisted.python.failure.Failure}
  87. """
  88. class IXMPPHandlerCollection(Interface):
  89. """
  90. Collection of handlers.
  91. Contain several handlers and manage their connection.
  92. """
  93. def __iter__():
  94. """
  95. Get an iterator over all child handlers.
  96. """
  97. def addHandler(handler):
  98. """
  99. Add a child handler.
  100. @type handler: L{IXMPPHandler}
  101. """
  102. def removeHandler(handler):
  103. """
  104. Remove a child handler.
  105. @type handler: L{IXMPPHandler}
  106. """
  107. class IService(Interface):
  108. """
  109. External server-side component service interface.
  110. Services that provide this interface can be added to L{ServiceManager} to
  111. implement (part of) the functionality of the server-side component.
  112. """
  113. def componentConnected(xs):
  114. """
  115. Parent component has established a connection.
  116. At this point, authentication was successful, and XML stanzas
  117. can be exchanged over the XML stream C{xs}. This method can be used
  118. to setup observers for incoming stanzas.
  119. @param xs: XML Stream that represents the established connection.
  120. @type xs: L{xmlstream.XmlStream}
  121. """
  122. def componentDisconnected():
  123. """
  124. Parent component has lost the connection to the Jabber server.
  125. Subsequent use of C{self.parent.send} will result in data being
  126. queued until a new connection has been established.
  127. """
  128. def transportConnected(xs):
  129. """
  130. Parent component has established a connection over the underlying
  131. transport.
  132. At this point, no traffic has been exchanged over the XML stream. This
  133. method can be used to change properties of the XML Stream (in C{xs}),
  134. the service manager or it's authenticator prior to stream
  135. initialization (including authentication).
  136. """