예제 #1
0
 /**
  * Validates If-Unmodified-Since Header Field in according to RFC 2616 Section 14.28
  *
  * <p><strong>RFC Specification</strong></p>
  *
  * <code>
  *        If-Unmodified-Since = "If-Unmodified-Since" ":" HTTP-date
  *
  *        HTTP-date    = rfc1123-date
  *
  *        rfc1123-date = wkday "," SP date SP time SP "GMT"
  *
  *        date        = 2DIGIT SP month SP 4DIGIT
  *                      ; day month year (e.g., 02 Jun 1982)
  *
  *        time        = 2DIGIT ":" 2DIGIT ":" 2DIGIT
  *                      ; 00:00:00 - 23:59:59
  *
  *        wkday       = "Mon" | "Tue" | "Wed"
  *                    | "Thu" | "Fri" | "Sat" | "Sun"
  *
  *        weekday     = "Monday" | "Tuesday" | "Wednesday"
  *                    | "Thursday" | "Friday" | "Saturday" | "Sunday"
  *
  *        month       = "Jan" | "Feb" | "Mar" | "Apr"
  *                    | "May" | "Jun" | "Jul" | "Aug"
  *                    | "Sep" | "Oct" | "Nov" | "Dec"
  * </code>
  *
  * @param string $data
  *   Data to validate
  *
  * @return boolean
  *   TRUE if valid and FALSE otherwise
  *
  * @link
  *   http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.28
  *   RFC 2616 Section 14.28
  *
  * @see Next\Validate\HTTP\Headers\Common\Date::validate()
  */
 public function validate($data)
 {
     $date = new Date();
     return $date->validate($data);
 }
예제 #2
0
    /**
     * Validates Content-Disposition Header Field in according to RFC 2183 Section 2
     *
     * <p><strong>RFC Specification</strong></p>
     *
     * <code>
     *        Content-Disposition = "Content-Disposition" ":"
     *                              disposition-type
     *                              *(";" disposition-param)
     *
     *        disposition-type := "inline"
     *                          / "attachment"
     *                          / extension-token
     *                          ; values are not case-sensitive
     *
     *        disposition-param := filename-param
     *                          / creation-date-param
     *                          / modification-date-param
     *                          / read-date-param
     *                          / size-param
     *                          / parameter
     *
     *        filename-param := "filename" "=" value
     *
     *        creation-date-param := "creation-date" "=" quoted-date-time
     *
     *        modification-date-param := "modification-date" "=" quoted-date-time
     *
     *        read-date-param := "read-date" "=" quoted-date-time
     *
     *        size-param := "size" "=" 1*DIGIT
     *
     *        quoted-date-time := quoted-string
     *                         ; contents MUST be an RFC 822 `date-time'
     *                         ; numeric timezones (+HHMM or -HHMM) MUST be used
     * </code>
     *
     * @param string $data
     *   Data to validate
     *
     * @return boolean
     *   TRUE if valid and FALSE otherwise
     *
     * @link
     *   http://tools.ietf.org/html/rfc2183#section-2
     *   RFC 2183 Section 2
     */
    public function validate($data)
    {
        preg_match(sprintf('/^(?:
                       (?<disposition>inline|attachment)

                       (?:;\\s*
                              filename=(?<filename>%s\\b)
                       )?

                       (?:;\\s*
                              creation-date=[\'"]?(?<creation>[ ,:a-zA-Z0-9]+)[\'"]?
                       )?

                       (?:;\\s*
                              modification-date=[\'"]?(?<modification>[ ,:a-zA-Z0-9]+)[\'"]?
                       )?

                       (?:;\\s*
                              read-date=[\'"]?(?<read>[ ,:a-zA-Z0-9]+)[\'"]?
                       )?

                       (?:;\\s*
                              size=[\'"]?(?<size>[0-9]+)[\'"]?
                       )?

                   )/x', self::TOKEN), $data, $matches);
        /**
         * @internal
         * Now we have to check the HTTP-dates
         * Instead of repeat gmdate() function several times, let's use Date Header Validator
         */
        $date = new Date();
        if (isset($matches['creation']) && !$date->validate($matches['creation'])) {
            return FALSE;
        }
        if (isset($matches['modification']) && !$date->validate($matches['modification'])) {
            return FALSE;
        }
        if (isset($matches['read']) && !$date->validate($matches['read'])) {
            return FALSE;
        }
        $matches = array_filter($matches);
        return count($matches) != 0;
    }
예제 #3
0
    /**
     * Validates Set-Cookie Header Field in according to RFC 2109 Section 4.2.2
     *
     * <p><strong>RFC Specification</strong></p>
     *
     * <code>
     *        Set-Cookie: "Set-Cookie:" cookies
     *
     *        cookies         =       1#cookie
     *        cookie          =       NAME "=" VALUE *(";" cookie-av)
     *        NAME            =       attr
     *        VALUE           =       value
     *        cookie-av       =       "Comment" "=" value
     *                        |       "Domain" "=" value
     *                        |       "Max-Age" "=" value
     *                        |       "Path" "=" value
     *                        |       "Secure"
     *                        |       "Version" "=" 1*DIGIT
     * </code>
     *
     * @param string $data
     *   Data to validate
     *
     * @return boolean
     *   TRUE if valid and FALSE otherwise
     *
     * @link
     *   http://tools.ietf.org/html/rfc2109#section-4.2.2
     *   RFC 2109 Section 4.2.2
     *
     * @link
     *   http://en.wikipedia.org/wiki/HTTP_Cookie
     */
    public function validate($data)
    {
        preg_match(sprintf('/(?:
                    (?<name>%s)\\="(?<value>%s)"

                    (?:;\\s*
                        version\\="(?<version>%s)"
                    )?

                    (?:;\\s*
                        comment\\="(?<comment>[^ \\t\\n\\r\\f\\v]+)"
                    )?

                    (?:;\\s*
                        (?:expires|max-age)\\="(?<expires>[ ,:a-zA-Z0-9-]+)"
                    )?

                    (?:;\\s*
                        path\\="(?<path>\\/[\\w\\#:.?+=&%%@!\\/-]*)"
                    )?

                    (?:;\\s*
                        domain\\="(?<domain>[\\w\\#:.?+=&%%@!\\/-]+)"
                    )?

                    (?:;\\s*
                        (?<secure>secure)
                    )?

                    (?:;\\s*
                        (?<httponly>httponly)
                    )?
                  )
                /ix', self::TOKEN, self::TOKEN, self::FLOAT), $data, $matches);
        $matches = array_filter($matches);
        /**
         * @internal
         * Now we have to check the HTTP-dates
         * Instead of repeat gmdate() function several times, let's use Date Header Validator
         */
        $date = new Date();
        if (isset($matches['expires']) && !$date->validate($matches['expires'])) {
            return FALSE;
        }
        return $matches != 0;
    }