Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

bugfix: channel deletion issue in webif #1

Merged
merged 3 commits into from

2 participants

@malphx

Hi guys,
I've made two small modifications in the webif files to correct an issue with channel deletion.
It appears that the usage of super() caused the trouble in Channel.delete(self,...).
I also added a return to "deletechan.html" in views.py.

Cheers,
Franck

@malphx

Proposal of an OP_UNSUBSCRIBE protocol opcode.
The purpose of this opcode is to permit to a client, already subscribed to multiple channels, to unsubscribe from one or more channels without the need to disconnect/reconnect.

@rep rep merged commit 17586bb into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 2 deletions.
  1. +23 −1 broker/feedbroker.py
  2. +1 −1  webif/models.py
  3. +1 −0  webif/views.py
View
24 broker/feedbroker.py
@@ -24,6 +24,7 @@
OP_AUTH = 2
OP_PUBLISH = 3
OP_SUBSCRIBE = 4
+OP_UNSUBSCRIBE = 5
MAXBUF = 1024**2
SIZES = {
@@ -32,6 +33,7 @@
OP_AUTH: 5+256+20,
OP_PUBLISH: 5+MAXBUF,
OP_SUBSCRIBE: 5+256*2,
+ OP_UNSUBSCRIBE: 5+256*2,
}
@@ -86,7 +88,7 @@ def sendinfo(self):
self.conn.write(self.msginfo())
def auth(self, ident, hash):
- p = self.db.query('hpfeeds.authkey', {'identifier': str(ident)}, limit=1)
+ p = self.db.query('hpfeeds.auth_key', {'identifier': str(ident)}, limit=1)
p._when(self.checkauth, hash)
def dbexc(e):
@@ -152,6 +154,19 @@ def io_in(self, data):
continue
self._event('subscribe', self, chan)
+ elif opcode == OP_UNSUBSCRIBE:
+ rest = buffer(data, 0)
+ ident, chan = rest[1:1+ord(rest[0])], rest[1+ord(rest[0]):]
+
+ if not ident in self.idents:
+ self.error('identfail.')
+ continue
+
+ if not chan in self.subchans:
+ self.error('accessfail.')
+ continue
+
+ self._event('unsubscribe', self, chan)
elif opcode == OP_AUTH:
rest = buffer(data, 0)
ident, hash = rest[1:1+ord(rest[0])], rest[1+ord(rest[0]):]
@@ -216,6 +231,7 @@ def _newconn(self, c, addr):
self.connections.add(fc)
fc._on('close', self._connclose)
fc._on('subscribe', self._subscribe)
+ fc._on('unsubscribe', self._unsubscribe)
fc._on('publish', self._publish)
def _newconnplain(self, c, addr):
@@ -224,6 +240,7 @@ def _newconnplain(self, c, addr):
self.connections.add(fc)
fc._on('close', self._connclose)
fc._on('subscribe', self._subscribe)
+ fc._on('unsubscribe', self._unsubscribe)
fc._on('publish', self._publish)
def _connclose(self, c):
@@ -242,6 +259,11 @@ def _subscribe(self, c, chan):
logging.debug('broker subscribe to {0} by {1}'.format(chan, c.addr))
self.subscribermap[chan].append(c)
self.conn2chans[c].append(chan)
+
+ def _unsubscribe(self, c, chan):
+ logging.debug('broker unsubscribe to {0} by {1}'.format(chan, c.addr))
+ self.subscribermap[chan].remove(c)
+ self.conn2chans[c].remove(chan)
def main():
fb = FeedBroker()
View
2  webif/models.py
@@ -74,7 +74,7 @@ def delete(self, *args, **kwargs):
if self.name in ak.subscribe: ak.subscribe.remove(self.name)
ak.save()
- super(Document, self).delete(*args, **kwargs)
+ self.__class__.objects(pk=self.pk).delete()
# deleted
def anypub(self):
View
1  webif/views.py
@@ -250,6 +250,7 @@ def deletechan(request, ch):
confirmed = request.GET.get('confirm', 'no') == 'yes'
if confirmed:
cobj.delete()
+ return render_to_response('deletechan.html', {'deleted': True, 'ch': ch}, context_instance=RequestContext(request))
return render_to_response('deletechan.html', {'deleted': False, 'ch': ch}, context_instance=RequestContext(request))
Something went wrong with that request. Please try again.