'Processes an Entry object with the linematched rules defined in a tracker config file
:param entry: Entry to be updated
:param rules: Ruleset to use.
:return:'

def process_tracker_config_rules(self, entry, rules=None):

    ignore_optionals = []
    if (rules is None):
        rules = self.tracker_config.find(u'parseinfo/linematched')
    fields = {key: val for (key, val) in entry.items() if key.startswith(u'irc_')}
    for rule in rules:
        log.debug((u'Processing    rule    %s' % rule.tag))
        if (rule.tag == u'var'):
            result = u''
            for element in rule:
                if (element.tag == u'string'):
                    result += element.get(u'value')
                elif (element.tag in [u'var', u'varenc']):
                    varname = element.get(u'name')
                    if (irc_prefix(varname) in fields):
                        value = fields[irc_prefix(varname)]
                    elif self.config.get(varname):
                        value = self.config.get(varname)
                    else:
                        log.error(u'Missing    variable    %s    from    config,    skipping    rule', irc_prefix(varname))
                        break
                    if (element.tag == u'varenc'):
                        value = quote(value.encode(u'utf-8'))
                    result += value
                else:
                    log.error(u'Unsupported    var    operation    %s,    skipping    rule', element.tag)
                    break
            else:
                log.debug(u'Result    for    rule    %s:    %s=%s', rule.tag, rule.get(u'name'), result)
                fields[irc_prefix(rule.get(u'name'))] = result
        elif (rule.tag == u'varreplace'):
            source_var = irc_prefix(rule.get(u'srcvar'))
            target_var = irc_prefix(rule.get(u'name'))
            regex = rule.get(u'regex')
            replace = rule.get(u'replace')
            if (source_var and target_var and (regex is not None) and (replace is not None) and (source_var in fields)):
                fields[target_var] = re.sub(regex, replace, fields[source_var])
                log.debug(u'varreplace:    %s=%s', target_var, fields[target_var])
            else:
                log.error(u'Invalid    varreplace    options,    skipping    rule')
        elif (rule.tag == u'extract'):
            source_var = irc_prefix(rule.get(u'srcvar'))
            if (source_var not in fields):
                if (rule.get(u'optional', u'false') == u'false'):
                    log.error(u'Error    processing    extract    rule,    non-optional    value    %s    missing!', source_var)
                ignore_optionals.append(source_var)
                continue
            if (rule.find(u'regex') is not None):
                regex = rule.find(u'regex').get(u'value')
            else:
                log.error(u'Regex    option    missing    on    extract    rule,    skipping    rule')
                continue
            group_names = [irc_prefix(x.get(u'name')) for x in rule.find(u'vars') if (x.tag == u'var')]
            match = re.search(regex, fields[source_var])
            if match:
                fields.update(dict(zip(group_names, match.groups())))
            else:
                log.debug(u'No    match    found    for    rule    extract')
        elif (rule.tag == u'extracttags'):
            source_var = irc_prefix(rule.get(u'srcvar'))
            split = rule.get(u'split')
            if (source_var in ignore_optionals):
                continue
            values = [strip_whitespace(x) for x in fields[source_var].split(split)]
            for element in rule:
                if (element.tag == u'setvarif'):
                    target_var = irc_prefix(element.get(u'varName'))
                    regex = element.get(u'regex')
                    value = element.get(u'value')
                    new_value = element.get(u'newValue')
                    if (regex is not None):
                        found_match = False
                        for val in values:
                            match = re.match(regex, val)
                            if match:
                                fields[target_var] = val
                                found_match = True
                        if (not found_match):
                            log.debug(u'No    matches    found    for    regex    %s', regex)
                    elif ((value is not None) and (new_value is not None)):
                        if (value in values):
                            fields[target_var] = new_value
                        else:
                            log.debug(u'No    match    found    for    value    %s    in    %s', value, source_var)
                    else:
                        log.error(u'Missing    regex/value/newValue    for    setvarif    command,    ignoring')
        elif (rule.tag == u'extractone'):
            for element in rule:
                if (element.tag == u'extract'):
                    source_var = irc_prefix(element.get(u'srcvar'))
                    if (element.find(u'regex') is not None):
                        regex = element.find(u'regex').get(u'value')
                    else:
                        log.error(u'Regex    option    missing    on    extract    rule,    skipping.')
                        continue
                    if (element.find(u'vars') is not None):
                        vars = [irc_prefix(var.get(u'name')) for var in element.find(u'vars')]
                    else:
                        log.error(u'No    variable    bindings    found    in    extract    rule,    skipping.')
                        continue
                    match = re.match(regex, fields.get(source_var, u''))
                    if match:
                        fields.update(dict(zip(vars, match.groups())))
                    else:
                        log.debug(u'No    match    for    extract    with    regex:    %s', regex)
                else:
                    log.error(u'Unsupported    extractone    tag:    %s', element.tag)
        elif (rule.tag == u'setregex'):
            source_var = irc_prefix(rule.get(u'srcvar'))
            regex = rule.get(u'regex')
            target_var = irc_prefix(rule.get(u'varName'))
            target_val = rule.get(u'newValue')
            if (source_var and regex and target_var and target_val):
                if ((source_var in fields) and re.search(regex, fields[source_var])):
                    fields[target_var] = target_val
            else:
                log.error(u'Option    missing    on    setregex,    skipping    rule')
        elif (rule.tag == u'if'):
            source_var = irc_prefix(rule.get(u'srcvar'))
            regex = rule.get(u'regex')
            if (source_var and regex):
                if ((source_var in fields) and re.match(regex, fields[source_var])):
                    fields.update(self.process_tracker_config_rules(fields, rule))
            else:
                log.error(u'Option    missing    for    if    statement,    skipping    rule')
        else:
            log.warning(u'Unsupported    linematched    tag:    %s', rule.tag)
    return fields
