This file is indexed.

/usr/share/php/Horde/Log/Filter/Constraint.php is in php-horde-log 2.2.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
 * @author     James Pepin <james@jamespepin.com>
 * @category   Horde
 * @license    http://www.horde.org/licenses/bsd BSD
 * @package    Log
 * @subpackage Filters
 */

/**
 * Filters log events using defined constraints on one or more fields of the
 * $event array.
 *
 * @author     James Pepin <james@jamespepin.com>
 * @category   Horde
 * @license    http://www.horde.org/licenses/bsd BSD
 * @package    Log
 * @subpackage Filters
 *
 * @todo Implement constraint objects for the different types of filtering ie
 * regex,required,type..etc..  so we can add different constaints ad infinitum.
 */
class Horde_Log_Filter_Constraint implements Horde_Log_Filter
{
    /**
     * Constraint list.
     *
     * @var array
     */
    protected $_constraints = array();

    /**
     * Default constraint coupler.
     *
     * @var Horde_Constraint_Coupler
     * @default Horde_Constraint_And
     */
    protected $_coupler;

    /**
     * Constructor
     *
     * @param Horde_Constraint_Coupler $coupler  The default kind of
     *                                           constraint to use to couple
     *                                           multiple constraints.
     *                                           Defaults to And.
     */
    public function __construct(Horde_Constraint_Coupler $coupler = null)
    {
        $this->_coupler = is_null($coupler)
            ? new Horde_Constraint_And()
            : $coupler;
    }

    /**
     * Add a constraint to the filter
     *
     * @param string $field                 The field to apply the constraint
     *                                      to.
     * @param Horde_Constraint $constraint  The constraint to apply.
     *
     * @return Horde_Log_Filter_Constraint  A reference to $this to allow
     *                                      method chaining.
     */
    public function addConstraint($field, Horde_Constraint $constraint)
    {
        if (!isset($this->_constraints[$field])) {
            $this->_constraints[$field] = clone($this->_coupler);
        }
        $this->_constraints[$field]->addConstraint($constraint);

        return $this;
    }

    /**
     * Add a regular expression to filter by
     *
     * Takes a field name and a regex, if the regex does not match then the
     * event is filtered.
     *
     * @param string $field  The name of the field that should be part of the
     *                       event.
     * @param string $regex  The regular expression to filter by.
     * @return Horde_Log_Filter_Constraint  A reference to $this to allow
     *                                      method chaining.
     */
    public function addRegex($field, $regex)
    {
        return $this->addConstraint($field, new Horde_Constraint_PregMatch($regex));
    }

    /**
     * Add a required field to the filter
     *
     * If the field does not exist on the event, then it is filtered.
     *
     * @param string $field  The name of the field that should be part of the
     *                       event.
     *
     * @return Horde_Log_Filter_Constraint  A reference to $this to allow
     *                                      method chaining.
     */
    public function addRequiredField($field)
    {
        return $this->addConstraint($field, new Horde_Constraint_Not(new Horde_Constraint_Null()));
    }

    /**
     * Adds all arguments passed as required fields
     *
     * @return Horde_Log_Filter_Constraint  A reference to $this to allow
     *                                      method chaining.
     */
    public function addRequiredFields()
    {
        foreach (func_get_args() as $f) {
            $this->addRequiredField($f);
        }

        return $this;
    }

    /**
     * Returns Horde_Log_Filter::ACCEPT to accept the message,
     * Horde_Log_Filter::IGNORE to ignore it.
     *
     * @param array $event  Log event.
     *
     * @return boolean  accepted?
     */
    public function accept($event)
    {
        foreach ($this->_constraints as $field => $constraint) {
            $value = isset($event[$field]) ? $event[$field] : null;
            if (!$constraint->evaluate($value)) {
                return Horde_Log_Filter::IGNORE;
            }
        }

        return Horde_Log_Filter::ACCEPT;
    }

}