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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 channel: The channel on which to send the notification. | 568 channel: The channel on which to send the notification. |
569 data: The notification payload. | 569 data: The notification payload. |
570 """ | 570 """ |
571 notification_stanza = self.MakeNotification(channel, data) | 571 notification_stanza = self.MakeNotification(channel, data) |
572 self.ForwardNotification(None, notification_stanza) | 572 self.ForwardNotification(None, notification_stanza) |
573 notification_stanza.unlink() | 573 notification_stanza.unlink() |
574 | 574 |
575 def SetAuthenticated(self, auth_valid): | 575 def SetAuthenticated(self, auth_valid): |
576 self._authenticated = auth_valid | 576 self._authenticated = auth_valid |
577 | 577 |
| 578 # We check authentication only when establishing new connections. We close |
| 579 # all existing connections here to make sure previously connected clients |
| 580 # pick up on the change. It's a hack, but it works well enough for our |
| 581 # purposes. |
| 582 if not self._authenticated: |
| 583 for connection in self._handshake_done_connections: |
| 584 connection.close() |
| 585 |
578 def GetAuthenticated(self): | 586 def GetAuthenticated(self): |
579 return self._authenticated | 587 return self._authenticated |
580 | 588 |
581 # XmppConnection delegate methods. | 589 # XmppConnection delegate methods. |
582 def OnXmppHandshakeDone(self, xmpp_connection): | 590 def OnXmppHandshakeDone(self, xmpp_connection): |
583 self._handshake_done_connections.add(xmpp_connection) | 591 self._handshake_done_connections.add(xmpp_connection) |
584 | 592 |
585 def OnXmppConnectionClosed(self, xmpp_connection): | 593 def OnXmppConnectionClosed(self, xmpp_connection): |
586 self._connections.discard(xmpp_connection) | 594 self._connections.discard(xmpp_connection) |
587 self._handshake_done_connections.discard(xmpp_connection) | 595 self._handshake_done_connections.discard(xmpp_connection) |
588 | 596 |
589 def ForwardNotification(self, unused_xmpp_connection, notification_stanza): | 597 def ForwardNotification(self, unused_xmpp_connection, notification_stanza): |
590 if self._notifications_enabled: | 598 if self._notifications_enabled: |
591 for connection in self._handshake_done_connections: | 599 for connection in self._handshake_done_connections: |
592 print 'Sending notification to %s' % connection | 600 print 'Sending notification to %s' % connection |
593 connection.ForwardNotification(notification_stanza) | 601 connection.ForwardNotification(notification_stanza) |
594 else: | 602 else: |
595 print 'Notifications disabled; dropping notification' | 603 print 'Notifications disabled; dropping notification' |
OLD | NEW |