1/* 2 * Copyright (c) 2011 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#ifndef webdavfs_webdav_utils_h 25#define webdavfs_webdav_utils_h 26 27/* Arrays of asctime-date day and month strs, rfc1123-date day and month strs, and rfc850-date day and month strs. */ 28static const char* kDayStrs[] = { 29 "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", 30 "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; 31 32static const char* kMonthStrs[] = { 33 "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", 34 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 35 "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"}; 36 37/* NOTE that these are ordered this way on purpose. */ 38static const char* kUSTimeZones[] = {"PST", "PDT", "MST", "MDT", "CST", "CDT", "EST", "EDT"}; 39 40static const uint8_t daysInMonth[16] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0, 0, 0}; 41 42typedef struct { 43 SInt32 year; 44 SInt8 month; 45 SInt8 day; 46 SInt8 hour; 47 SInt8 minute; 48 double second; 49}Date; 50 51const UInt8* CFGregorianDateCreateWithBytes(CFAllocatorRef alloc, const UInt8* bytes, CFIndex length, Date* date, CFTimeZoneRef* tz); 52 53CFIndex CFGregorianDateCreateWithString(CFAllocatorRef alloc, CFStringRef str, Date* date, CFTimeZoneRef* tz); 54 55Boolean IsLeapYear(SInt32 year); 56 57Boolean DateIsValid(Date gdate); 58 59/* 60 * DateBytesToTime parses the RFC 850, RFC 1123, and asctime formatted 61 * date/time bytes and returns time_t. If the parse fails, this function 62 * returns a time_t set to -1. 63 */ 64time_t DateBytesToTime( 65 const UInt8 *bytes, /* -> pointer to bytes to parse */ 66 CFIndex length); /* -> number of bytes to parse */ 67 68char* createUTF8CStringFromCFString(CFStringRef in_string); 69 70/* 71 * DateStringToTime parses the RFC 850, RFC 1123, and asctime formatted 72 * date/time CFString and returns time_t. If the parse fails, this function 73 * returns -1. 74 */ 75time_t DateStringToTime( /* <- time_t value; -1 if error */ 76 CFStringRef str); /* -> CFString to parse */ 77 78#endif 79