# Path: txircd/modbase.py
# class Command(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def onUse(self, user, data):
#         pass
#     def processParams(self, user, params):
#         return {
#             "user": user,
#             "params": params
#         }
#     def updateActivity(self, user):
#         user.lastactivity = now()
# 
# Path: txircd/server.py
# class ModuleMessage(Command):
#     arguments = [
#         ("destserver", String()),
#         ("type", String()),
#         ("args", ListOf(String()))
#     ]
#     errors = {
#         HandshakeNotYetComplete: "HANDSHAKE_NOT_COMPLETE"
#     }


from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.server import ModuleMessage
        del user.cache["sasl_authenticating"]
        if user.server != self.ircd.name:
            self.ircd.servers[user.server].callRemote(ModuleMessage, destserver=user.server, type="SASL", args=["release", user.uuid])
    
    def saslMessage(self, command, args):
        if args[1] in self.ircd.userid:
            user = self.ircd.userid[args[1]]
        else:
            return
        if args[0] == "start":
            user.cache["sasl_authenticating"] = [args[2], ""]
            self.startSaslAuth(user, args[2])
        elif args[0] == "process":
            self.processSaslAuth(user, args[2])
        elif args[0] == "release":
            del user.cache["sasl_authenticating"]
    
    def startSaslAuth(self, user, mechanism):
        result = self.ircd.module_data_cache["sasl_agent"].saslStart(user, mechanism)
        if result == "fail":
            self.sendFailure(user)
    
    def processSaslAuth(self, user, authstr):
        if authstr == "*": # indicates client is aborting authentication
            self.sendFailure(user)
            return
        if authstr != "+": # A single plus sign as input indicates an empty SASL packet that we shouldn't append to data
            user.cache["sasl_authenticating"][1] += authstr
        if len(authstr) == 400:
            return # A string of length 400 means another line is coming with additional data, so don't process any more yet

# Path: txircd/modbase.py
# class Command(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def onUse(self, user, data):
#         pass
#     def processParams(self, user, params):
#         return {
#             "user": user,
#             "params": params
#         }
#     def updateActivity(self, user):
#         user.lastactivity = now()
# 
# Path: txircd/server.py
# class ModuleMessage(Command):
#     arguments = [
#         ("destserver", String()),
#         ("type", String()),
#         ("args", ListOf(String()))
#     ]
#     errors = {
#         HandshakeNotYetComplete: "HANDSHAKE_NOT_COMPLETE"
#     }


# Path: txircd/modules/ircv3_sasl.py
from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.server import ModuleMessage

        del user.cache["sasl_authenticating"]
        if user.server != self.ircd.name:
            self.ircd.servers[user.server].callRemote(ModuleMessage, destserver=user.server, type="SASL", args=["release", user.uuid])
    
    def saslMessage(self, command, args):
        if args[1] in self.ircd.userid:
            user = self.ircd.userid[args[1]]
        else:
            return
        if args[0] == "start":
            user.cache["sasl_authenticating"] = [args[2], ""]
            self.startSaslAuth(user, args[2])
        elif args[0] == "process":
            self.processSaslAuth(user, args[2])
        elif args[0] == "release":
            del user.cache["sasl_authenticating"]
    
    def startSaslAuth(self, user, mechanism):
        result = self.ircd.module_data_cache["sasl_agent"].saslStart(user, mechanism)
        if result == "fail":
            self.sendFailure(user)
    
    def processSaslAuth(self, user, authstr):
        if authstr == "*": # indicates client is aborting authentication
            self.sendFailure(user)
            return
        if authstr != "+": # A single plus sign as input indicates an empty SASL packet that we shouldn't append to data
            user.cache["sasl_authenticating"][1] += authstr
        if len(authstr) == 400:
            return # A string of length 400 means another line is coming with additional data, so don't process any more yet

        result = self.ircd.module_data_cache["sasl_agent"].saslNext(user, user.cache["sasl_authenticating"][1])