'Finds the client_id and keywords for a client.
Args:
client: A VFSGRRClient record to find keywords for.
Returns:
A tuple (client_id, keywords) where client_id is the client identifier and
keywords is a list of keywords related to client.'

def AnalyzeClient(self, client):

    client_id = self._ClientIdFromURN(client.urn)
    keywords = [self._NormalizeKeyword(client_id), '.']
    def TryAppend(prefix, keyword):
        if keyword:
            keyword_string = self._NormalizeKeyword(utils.SmartStr(keyword))
            keywords.append(keyword_string)
            if prefix:
                keywords.append(((prefix + ':') + keyword_string))
    def TryAppendPrefixes(prefix, keyword, delimiter):
        TryAppend(prefix, keyword)
        segments = str(keyword).split(delimiter)
        for i in range(1, len(segments)):
            TryAppend(prefix, delimiter.join(segments[0:i]))
        return len(segments)
    def TryAppendIP(ip):
        TryAppend('ip', ip)
        if (TryAppendPrefixes('ip', str(ip), '.') == 4):
            return
        TryAppendPrefixes('ip', str(ip), ':')
    def TryAppendMac(mac):
        TryAppend('mac', mac)
        if (len(mac) == 12):
            TryAppend('mac', ':'.join([mac[i:(i + 2)] for i in range(0, 12, 2)]))
    s = client.Schema
    TryAppend('host', client.Get(s.HOSTNAME))
    TryAppendPrefixes('host', client.Get(s.HOSTNAME), '-')
    TryAppend('host', client.Get(s.FQDN))
    TryAppendPrefixes('host', client.Get(s.FQDN), '.')
    TryAppend('', client.Get(s.SYSTEM))
    TryAppend('', client.Get(s.UNAME))
    TryAppend('', client.Get(s.OS_RELEASE))
    TryAppend('', client.Get(s.OS_VERSION))
    TryAppend('', client.Get(s.KERNEL))
    TryAppend('', client.Get(s.ARCH))
    kb = client.Get(s.KNOWLEDGE_BASE)
    if kb:
        for user in kb.users:
            TryAppend('user', user.username)
            TryAppend('', user.full_name)
            if user.full_name:
                for name in user.full_name.split():
                    TryAppend('', name.strip('"\'()'))
    for username in client.Get(s.USERNAMES, []):
        TryAppend('user', username)
    for interface in client.Get(s.INTERFACES, []):
        if interface.mac_address:
            TryAppendMac(interface.mac_address.human_readable_address)
        for ip in interface.GetIPAddresses():
            TryAppendIP(ip)
    if client.Get(s.MAC_ADDRESS):
        for mac in str(client.Get(s.MAC_ADDRESS)).split('\n'):
            TryAppendMac(mac)
    for ip_list in client.Get(s.HOST_IPS, []):
        for ip in str(ip_list).split('\n'):
            TryAppendIP(ip)
    client_info = client.Get(s.CLIENT_INFO)
    if client_info:
        TryAppend('client', client_info.client_name)
        TryAppend('client', client_info.client_version)
        if client_info.labels:
            for label in client_info.labels:
                TryAppend('label', label)
    for label in client.GetLabelsNames():
        TryAppend('label', label)
    return (client_id, keywords)
