1 /** ************************************************************************** 2 * util.h 3 * 4 * Copyright 2008 Bryan Ischo <bryan@ischo.com> 5 * 6 * This file is part of libs3. 7 * 8 * libs3 is free software: you can redistribute it and/or modify it under the 9 * terms of the GNU Lesser General Public License as published by the Free 10 * Software Foundation, version 3 or above of the License. You can also 11 * redistribute and/or modify it under the terms of the GNU General Public 12 * License, version 2 or above of the License. 13 * 14 * In addition, as a special exception, the copyright holders give 15 * permission to link the code of this library and its programs with the 16 * OpenSSL library, and distribute linked combinations including the two. 17 * 18 * libs3 is distributed in the hope that it will be useful, but WITHOUT ANY 19 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 21 * details. 22 * 23 * You should have received a copy of the GNU Lesser General Public License 24 * version 3 along with libs3, in a file named COPYING. If not, see 25 * <http://www.gnu.org/licenses/>. 26 * 27 * You should also have received a copy of the GNU General Public License 28 * version 2 along with libs3, in a file named COPYING-GPLv2. If not, see 29 * <http://www.gnu.org/licenses/>. 30 * 31 ************************************************************************** **/ 32 33 #ifndef UTIL_H 34 #define UTIL_H 35 36 #include <curl/curl.h> 37 #include <curl/multi.h> 38 #include <stdint.h> 39 #include "libs3.h" 40 41 // acl groups 42 #define ACS_URL "http://acs.amazonaws.com/groups/" 43 44 #define ACS_GROUP_ALL_USERS ACS_URL "global/AllUsers" 45 #define ACS_GROUP_AWS_USERS ACS_URL "global/AuthenticatedUsers" 46 #define ACS_GROUP_LOG_DELIVERY ACS_URL "s3/LogDelivery" 47 48 49 // Derived from S3 documentation 50 51 // This is the maximum number of bytes needed in a "compacted meta header" 52 // buffer, which is a buffer storing all of the compacted meta headers. 53 #define COMPACTED_METADATA_BUFFER_SIZE \ 54 (S3_MAX_METADATA_COUNT * sizeof(S3_METADATA_HEADER_NAME_PREFIX "n: v")) 55 56 // Maximum url encoded key size; since every single character could require 57 // URL encoding, it's 3 times the size of a key (since each url encoded 58 // character takes 3 characters: %NN) 59 #define MAX_URLENCODED_KEY_SIZE (3 * S3_MAX_KEY_SIZE) 60 61 // This is the maximum size of a URI that could be passed to S3: 62 // https://s3.amazonaws.com/${BUCKET}/${KEY}?acl 63 // 255 is the maximum bucket length 64 #define MAX_URI_SIZE \ 65 ((sizeof("https:///") - 1) + S3_MAX_HOSTNAME_SIZE + 255 + 1 + \ 66 MAX_URLENCODED_KEY_SIZE + (sizeof("?torrent") - 1) + 1) 67 68 // Maximum size of a canonicalized resource 69 #define MAX_CANONICALIZED_RESOURCE_SIZE \ 70 (1 + 255 + 1 + MAX_URLENCODED_KEY_SIZE + (sizeof("?torrent") - 1) + 1) 71 72 #define MAX_ACCESS_KEY_ID_LENGTH 32 73 74 // Maximum length of a credential string 75 // <access key>/<yyyymmdd>/<region>/s3/aws4_request 76 #define MAX_CREDENTIAL_SIZE \ 77 (MAX_ACCESS_KEY_ID_LENGTH + 1) + 8 + 1 + 32 + sizeof("/s3/aws4_request") 78 79 // Utilities ----------------------------------------------------------------- 80 81 // URL-encodes a string from [src] into [dest]. [dest] must have at least 82 // 3x the number of characters that [source] has. At most [maxSrcSize] bytes 83 // from [src] are encoded; if more are present in [src], 0 is returned from 84 // urlEncode, else nonzero is returned. 85 int urlEncode(char *dest, const char *src, int maxSrcSize, int encodeSlash); 86 87 // Returns < 0 on failure >= 0 on success 88 int64_t parseIso8601Time(const char *str); 89 90 uint64_t parseUnsignedInt(const char *str); 91 92 // Because Windows seems to be missing isblank(), use our own; it's a very 93 // easy function to write in any case 94 int is_blank(char c); 95 96 #endif /* UTIL_H */ 97