| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """A bare-bones and non-compliant XMPP server. | 5 """A bare-bones and non-compliant XMPP server. |
| 6 | 6 |
| 7 Just enough of the protocol is implemented to get it to work with | 7 Just enough of the protocol is implemented to get it to work with |
| 8 Chrome's sync notification system. | 8 Chrome's sync notification system. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 channel: The channel on which to send the notification. | 567 channel: The channel on which to send the notification. |
| 568 data: The notification payload. | 568 data: The notification payload. |
| 569 """ | 569 """ |
| 570 notification_stanza = self.MakeNotification(channel, data) | 570 notification_stanza = self.MakeNotification(channel, data) |
| 571 self.ForwardNotification(None, notification_stanza) | 571 self.ForwardNotification(None, notification_stanza) |
| 572 notification_stanza.unlink() | 572 notification_stanza.unlink() |
| 573 | 573 |
| 574 def SetAuthenticated(self, auth_valid): | 574 def SetAuthenticated(self, auth_valid): |
| 575 self._authenticated = auth_valid | 575 self._authenticated = auth_valid |
| 576 | 576 |
| 577 # We check authentication only when establishing new connections. We close |
| 578 # all existing connections here to make sure previously connected clients |
| 579 # pick up on the change. It's a hack, but it works well enough for our |
| 580 # purposes. |
| 581 if not self._authenticated: |
| 582 for connection in self._handshake_done_connections: |
| 583 connection.close() |
| 584 |
| 577 def GetAuthenticated(self): | 585 def GetAuthenticated(self): |
| 578 return self._authenticated | 586 return self._authenticated |
| 579 | 587 |
| 580 # XmppConnection delegate methods. | 588 # XmppConnection delegate methods. |
| 581 def OnXmppHandshakeDone(self, xmpp_connection): | 589 def OnXmppHandshakeDone(self, xmpp_connection): |
| 582 self._handshake_done_connections.add(xmpp_connection) | 590 self._handshake_done_connections.add(xmpp_connection) |
| 583 | 591 |
| 584 def OnXmppConnectionClosed(self, xmpp_connection): | 592 def OnXmppConnectionClosed(self, xmpp_connection): |
| 585 self._connections.discard(xmpp_connection) | 593 self._connections.discard(xmpp_connection) |
| 586 self._handshake_done_connections.discard(xmpp_connection) | 594 self._handshake_done_connections.discard(xmpp_connection) |
| 587 | 595 |
| 588 def ForwardNotification(self, unused_xmpp_connection, notification_stanza): | 596 def ForwardNotification(self, unused_xmpp_connection, notification_stanza): |
| 589 if self._notifications_enabled: | 597 if self._notifications_enabled: |
| 590 for connection in self._handshake_done_connections: | 598 for connection in self._handshake_done_connections: |
| 591 print 'Sending notification to %s' % connection | 599 print 'Sending notification to %s' % connection |
| 592 connection.ForwardNotification(notification_stanza) | 600 connection.ForwardNotification(notification_stanza) |
| 593 else: | 601 else: |
| 594 print 'Notifications disabled; dropping notification' | 602 print 'Notifications disabled; dropping notification' |
| OLD | NEW |