diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-02-16 09:44:49 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-02-16 09:44:49 +0100 |
commit | 20553c1afe035b2e020409fd516d0288b748dc7f (patch) | |
tree | 9b7cc32ee2560d86315339b9716c1a790a680afc /3rdparty/Sabre/HTTP/Util.php | |
parent | 19827b8b35de6192d54bf7600e9e29800c93b21b (diff) | |
download | nextcloud-server-20553c1afe035b2e020409fd516d0288b748dc7f.tar.gz nextcloud-server-20553c1afe035b2e020409fd516d0288b748dc7f.zip |
Revert "remove the 3rdparty files. everything is now in https://gitorious.org/owncloud/3rdparty"
This reverts commit dccdeca2581f705c69eb4266aa646173f588a9de.
Diffstat (limited to '3rdparty/Sabre/HTTP/Util.php')
-rw-r--r-- | 3rdparty/Sabre/HTTP/Util.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/3rdparty/Sabre/HTTP/Util.php b/3rdparty/Sabre/HTTP/Util.php new file mode 100644 index 00000000000..8a6bd7df487 --- /dev/null +++ b/3rdparty/Sabre/HTTP/Util.php @@ -0,0 +1,65 @@ +<?php + +/** + * HTTP utility methods + * + * @package Sabre + * @subpackage HTTP + * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @author Paul Voegler + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class Sabre_HTTP_Util { + + /** + * Parses a RFC2616-compatible date string + * + * This method returns false if the date is invalid + * + * @param string $dateHeader + * @return bool|DateTime + */ + static function parseHTTPDate($dateHeader) { + + //RFC 2616 section 3.3.1 Full Date + //Only the format is checked, valid ranges are checked by strtotime below + $month = '(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)'; + $weekday = '(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)'; + $wkday = '(Mon|Tue|Wed|Thu|Fri|Sat|Sun)'; + $time = '[0-2]\d(\:[0-5]\d){2}'; + $date3 = $month . ' ([1-3]\d| \d)'; + $date2 = '[0-3]\d\-' . $month . '\-\d\d'; + //4-digit year cannot begin with 0 - unix timestamp begins in 1970 + $date1 = '[0-3]\d ' . $month . ' [1-9]\d{3}'; + + //ANSI C's asctime() format + //4-digit year cannot begin with 0 - unix timestamp begins in 1970 + $asctime_date = $wkday . ' ' . $date3 . ' ' . $time . ' [1-9]\d{3}'; + //RFC 850, obsoleted by RFC 1036 + $rfc850_date = $weekday . ', ' . $date2 . ' ' . $time . ' GMT'; + //RFC 822, updated by RFC 1123 + $rfc1123_date = $wkday . ', ' . $date1 . ' ' . $time . ' GMT'; + //allowed date formats by RFC 2616 + $HTTP_date = "($rfc1123_date|$rfc850_date|$asctime_date)"; + + //allow for space around the string and strip it + $dateHeader = trim($dateHeader, ' '); + if (!preg_match('/^' . $HTTP_date . '$/', $dateHeader)) + return false; + + //append implicit GMT timezone to ANSI C time format + if (strpos($dateHeader, ' GMT') === false) + $dateHeader .= ' GMT'; + + + $realDate = strtotime($dateHeader); + //strtotime can return -1 or false in case of error + if ($realDate !== false && $realDate >= 0) + return new DateTime('@' . $realDate, new DateTimeZone('UTC')); + + return false; + + } + +} |