# Path: UtmpHead.py
# class UtmpHead:
#     utmphead = None
#     _fields = [
#         ['next', Array(I32, Config.USHM_SIZE)],
#         ['hashhead', Array(I32, Config.UTMP_HASHSIZE + 1)],
#         ['number', I32()],
#         ['listhead', I32()],
#         ['list_prev', Array(I32, Config.USHM_SIZE)],
#         ['list_next', Array(I32, Config.USHM_SIZE)],
#         ['uptime', I32()],
#     ]
# 
#     def read(self, pos, len):
#         return UtmpHead.utmphead.read(len, pos)
# 
#     def write(self, pos, data):
#         UtmpHead.utmphead.write(data, pos)
# 
#     @staticmethod
#     def GetInt(pos, idx = 0):
#         return struct.unpack('=i', UtmpHead.utmphead.read(4, pos + idx * 4))[0]
# 
#     @staticmethod
#     def SetInt(pos, idx, val):
#         UtmpHead.utmphead.write(struct.pack('=i', val), pos + idx * 4)
# 
#     @staticmethod
#     def GetHashHead(hash):
#         return UtmpHead.GetInt(HASHHEAD_POS, hash)
# 
#     @staticmethod
#     def SetHashHead(hash, val):
#         return UtmpHead.SetInt(HASHHEAD_POS, hash, val)
# 
#     @staticmethod
#     def GetListHead():
#         return UtmpHead.GetInt(LISTHEAD_POS)
# 
#     @staticmethod
#     def SetListHead(val):
#         return UtmpHead.SetInt(LISTHEAD_POS, 0, val)
# 
#     @staticmethod
#     def GetListNext(pos):
#         return UtmpHead.GetInt(LISTNEXT_POS, pos)
# 
#     @staticmethod
#     def SetListNext(pos, val):
#         return UtmpHead.SetInt(LISTNEXT_POS, pos, val)
# 
#     @staticmethod
#     def GetListPrev(pos):
#         return UtmpHead.GetInt(LISTPREV_POS, pos)
# 
#     @staticmethod
#     def SetListPrev(pos, val):
#         return UtmpHead.SetInt(LISTPREV_POS, pos, val)
# 
#     @staticmethod
#     def GetNext(pos):
#         return UtmpHead.GetInt(NEXT_POS, pos)
# 
#     @staticmethod
#     def SetNext(pos, val):
#         return UtmpHead.SetInt(NEXT_POS, pos, val)
# 
#     @staticmethod
#     def GetNumber():
#         return UtmpHead.GetInt(NUMBER_POS, 0)
# 
#     @staticmethod
#     def SetNumber(number):
#         return UtmpHead.SetInt(NUMBER_POS, 0, number)
# 
#     @staticmethod
#     def DecNumber():
#         return UtmpHead.SetNumber(UtmpHead.GetNumber() - 1)
# 
#     @staticmethod
#     def IncNumber():
#         return UtmpHead.SetNumber(UtmpHead.GetNumber() + 1)
# 
#     @staticmethod
#     def GetUptime():
#         return UtmpHead.GetInt(UPTIME_POS, 0)
# 
#     @staticmethod
#     def SetUptime(uptime):
#         return UtmpHead.SetInt(UPTIME_POS, 0, uptime)
# 
#     @staticmethod
#     def SetReadOnly(readonly):
#         UtmpHead.utmphead.detach()
#         UtmpHead.utmphead.attach(None, (sysv_ipc.SHM_RDONLY if readonly else 0))
# 
# Path: Log.py
# class Log:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     DEBUG = '\033[90m'
# 
#     _debug = True
#     _info = True
#     _warning = True
#     _error = True
# 
#     @staticmethod
#     def debug(msg):
#         if (Log._debug):
#             print Log.DEBUG, "%s [DEBUG]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
#     
#     @staticmethod
#     def error(msg):
#         if (Log._error):
#             print Log.FAIL, "%s [ERROR]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             exc_info = sys.exc_info()
#             if exc_info[0] is not None:
#                 # handling exception
#                 traceback.print_exc()
#             sys.stdout.flush()
# 
#     @staticmethod
#     def warn(msg):
#         if (Log._warning):
#             print Log.WARNING, "%s [WARN] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
# 
#     @staticmethod
#     def info(msg):
#         if (Log._info):
#             print Log.OKGREEN, "%s [INFO] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()


from UtmpHead import UtmpHead
from Log import Log
        from Utmp import Utmp
                from Utmp import Utmp
        from Utmp import Utmp
            from Utmp import Utmp
import Config
            self.set_listprev(node.list_prev())
            self.set_listnext(node)
            node.set_listprev(self)
            self.list_prev().set_listnext(self)
            UtmpHead.SetListHead(self._loginid)
            return True

        count = 0
        node = node.list_next()
        while ((node.get_userid().lower() < userid.lower()) and (node != Login.list_head())):
            node = node.list_next()
            count += 1
            if (count > Config.USHM_SIZE):
                UtmpHead.SetListHead(0)
                Utmp.RebuildList()
                return False
        self.set_listprev(node.list_prev())
        self.set_listnext(node)
        node.set_listprev(self)
        self.list_prev().set_listnext(self)
        return True

    # UtmpHead.HASH
    @staticmethod
    def hash_head(userid):
        hashkey = Utmp.Hash(userid)
        hashhead = UtmpHead.GetHashHead(hashkey)
        return hashkey, Login(hashhead)

    def set_hashnext(self, hashnext):

# Path: UtmpHead.py
# class UtmpHead:
#     utmphead = None
#     _fields = [
#         ['next', Array(I32, Config.USHM_SIZE)],
#         ['hashhead', Array(I32, Config.UTMP_HASHSIZE + 1)],
#         ['number', I32()],
#         ['listhead', I32()],
#         ['list_prev', Array(I32, Config.USHM_SIZE)],
#         ['list_next', Array(I32, Config.USHM_SIZE)],
#         ['uptime', I32()],
#     ]
# 
#     def read(self, pos, len):
#         return UtmpHead.utmphead.read(len, pos)
# 
#     def write(self, pos, data):
#         UtmpHead.utmphead.write(data, pos)
# 
#     @staticmethod
#     def GetInt(pos, idx = 0):
#         return struct.unpack('=i', UtmpHead.utmphead.read(4, pos + idx * 4))[0]
# 
#     @staticmethod
#     def SetInt(pos, idx, val):
#         UtmpHead.utmphead.write(struct.pack('=i', val), pos + idx * 4)
# 
#     @staticmethod
#     def GetHashHead(hash):
#         return UtmpHead.GetInt(HASHHEAD_POS, hash)
# 
#     @staticmethod
#     def SetHashHead(hash, val):
#         return UtmpHead.SetInt(HASHHEAD_POS, hash, val)
# 
#     @staticmethod
#     def GetListHead():
#         return UtmpHead.GetInt(LISTHEAD_POS)
# 
#     @staticmethod
#     def SetListHead(val):
#         return UtmpHead.SetInt(LISTHEAD_POS, 0, val)
# 
#     @staticmethod
#     def GetListNext(pos):
#         return UtmpHead.GetInt(LISTNEXT_POS, pos)
# 
#     @staticmethod
#     def SetListNext(pos, val):
#         return UtmpHead.SetInt(LISTNEXT_POS, pos, val)
# 
#     @staticmethod
#     def GetListPrev(pos):
#         return UtmpHead.GetInt(LISTPREV_POS, pos)
# 
#     @staticmethod
#     def SetListPrev(pos, val):
#         return UtmpHead.SetInt(LISTPREV_POS, pos, val)
# 
#     @staticmethod
#     def GetNext(pos):
#         return UtmpHead.GetInt(NEXT_POS, pos)
# 
#     @staticmethod
#     def SetNext(pos, val):
#         return UtmpHead.SetInt(NEXT_POS, pos, val)
# 
#     @staticmethod
#     def GetNumber():
#         return UtmpHead.GetInt(NUMBER_POS, 0)
# 
#     @staticmethod
#     def SetNumber(number):
#         return UtmpHead.SetInt(NUMBER_POS, 0, number)
# 
#     @staticmethod
#     def DecNumber():
#         return UtmpHead.SetNumber(UtmpHead.GetNumber() - 1)
# 
#     @staticmethod
#     def IncNumber():
#         return UtmpHead.SetNumber(UtmpHead.GetNumber() + 1)
# 
#     @staticmethod
#     def GetUptime():
#         return UtmpHead.GetInt(UPTIME_POS, 0)
# 
#     @staticmethod
#     def SetUptime(uptime):
#         return UtmpHead.SetInt(UPTIME_POS, 0, uptime)
# 
#     @staticmethod
#     def SetReadOnly(readonly):
#         UtmpHead.utmphead.detach()
#         UtmpHead.utmphead.attach(None, (sysv_ipc.SHM_RDONLY if readonly else 0))
# 
# Path: Log.py
# class Log:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     DEBUG = '\033[90m'
# 
#     _debug = True
#     _info = True
#     _warning = True
#     _error = True
# 
#     @staticmethod
#     def debug(msg):
#         if (Log._debug):
#             print Log.DEBUG, "%s [DEBUG]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
#     
#     @staticmethod
#     def error(msg):
#         if (Log._error):
#             print Log.FAIL, "%s [ERROR]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             exc_info = sys.exc_info()
#             if exc_info[0] is not None:
#                 # handling exception
#                 traceback.print_exc()
#             sys.stdout.flush()
# 
#     @staticmethod
#     def warn(msg):
#         if (Log._warning):
#             print Log.WARNING, "%s [WARN] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
# 
#     @staticmethod
#     def info(msg):
#         if (Log._info):
#             print Log.OKGREEN, "%s [INFO] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()


# Path: Login.py
from UtmpHead import UtmpHead
from Log import Log
        from Utmp import Utmp
                from Utmp import Utmp
        from Utmp import Utmp
            from Utmp import Utmp
import Config

            self.set_listprev(node.list_prev())
            self.set_listnext(node)
            node.set_listprev(self)
            self.list_prev().set_listnext(self)
            UtmpHead.SetListHead(self._loginid)
            return True

        count = 0
        node = node.list_next()
        while ((node.get_userid().lower() < userid.lower()) and (node != Login.list_head())):
            node = node.list_next()
            count += 1
            if (count > Config.USHM_SIZE):
                UtmpHead.SetListHead(0)
                Utmp.RebuildList()
                return False
        self.set_listprev(node.list_prev())
        self.set_listnext(node)
        node.set_listprev(self)
        self.list_prev().set_listnext(self)
        return True

    # UtmpHead.HASH
    @staticmethod
    def hash_head(userid):
        hashkey = Utmp.Hash(userid)
        hashhead = UtmpHead.GetHashHead(hashkey)
        return hashkey, Login(hashhead)

    def set_hashnext(self, hashnext):

        UtmpHead.SetNext(self._loginid - 1, hashnext._loginid)