from twisted.web import resource, server, static
from twisted.names import client
-from twisted.internet import reactor
+from twisted.internet import reactor, error
from authgateengine import login_optional, getSessionData
import simplejson, md5, sys, os, time, config, weakref, traceback
import qwebirc.ircclient as ircclient
self.closed = False
self.cleanupschedule = None
- def subscribe(self, channel):
+ def subscribe(self, channel, notifier):
+ timeout_entry = reactor.callLater(config.HTTP_AJAX_REQUEST_TIMEOUT, self.timeout, channel)
+ def cancel_timeout(result):
+ if channel in self.subscriptions:
+ self.subscriptions.remove(channel)
+ try:
+ timeout_entry.cancel()
+ except error.AlreadyCalled:
+ pass
+ notifier.addCallbacks(cancel_timeout, cancel_timeout)
+
if len(self.subscriptions) >= config.MAXSUBSCRIPTIONS:
self.subscriptions.pop(0).close()
self.subscriptions.append(channel)
self.flush()
+ def timeout(self, channel):
+ if self.schedule:
+ return
+
+ channel.write(simplejson.dumps([]))
+ if channel in self.subscriptions:
+ self.subscriptions.remove(channel)
+
def flush(self, scheduled=False):
if scheduled:
self.schedule = None
_, ip, port = request.transport.getPeer()
- nick, ident, realname = request.args.get("nick"), "webchat", config.REALNAME
-
+ nick = request.args.get("nick")
if not nick:
raise AJAXException("Nickname not supplied")
-
- nick = nick[0]
+ nick = ircclient.irc_decode(nick[0])
+ ident, realname = "webchat", config.REALNAME
+
for i in xrange(10):
id = get_session_id()
if not Sessions.get(id):
return session
def subscribe(self, request):
- self.getSession(request).subscribe(SingleUseChannel(request))
+ request.channel._savedTimeOut = None # HACK
+ self.getSession(request).subscribe(SingleUseChannel(request), request.notifyFinish())
return NOT_DONE_YET
def push(self, request):
raise AJAXException("No command specified")
self.__total_hit()
- command = command[0]
+ decoded = ircclient.irc_decode(command[0])
session = self.getSession(request)
- try:
- decoded = command.decode("utf-8")
- except UnicodeDecodeError:
- decoded = command.decode("iso-8859-1", "ignore")
-
if len(decoded) > config.MAXLINELEN:
session.disconnect()
raise AJAXException("Line too long")