blob: 12d3e05e7740a462ed51d5b442f6c3ea26c567ae (
plain)
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
|
/** **************************************************************************
* util.h
*
* Copyright 2008 Bryan Ischo <bryan@ischo.com>
*
* This file is part of libs3.
*
* libs3 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* libs3 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License version 3
* along with libs3, in a file named COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
************************************************************************** **/
#ifndef UTIL_H
#define UTIL_H
#include <curl/curl.h>
#include <curl/multi.h>
#include "libs3.h"
// Derived from S3 documentation
// This is the maximum number of bytes needed in a "compacted meta header"
// buffer, which is a buffer storing all of the compacted meta headers.
#define COMPACTED_METADATA_BUFFER_SIZE \
(S3_MAX_METADATA_COUNT * sizeof(S3_METADATA_HEADER_NAME_PREFIX "n: v"))
// Maximum url encoded key size; since every single character could require
// URL encoding, it's 3 times the size of a key (since each url encoded
// character takes 3 characters: %NN)
#define MAX_URLENCODED_KEY_SIZE (3 * S3_MAX_KEY_SIZE)
// This is the maximum size of a URI that could be passed to S3:
// https://s3.amazonaws.com/${BUCKET}/${KEY}?acl
// 255 is the maximum bucket length
#define MAX_URI_SIZE \
((sizeof("https://" S3_HOSTNAME "/") - 1) + 255 + 1 + \
MAX_URLENCODED_KEY_SIZE + (sizeof("?torrent" - 1)) + 1)
// Maximum size of a canonicalized resource
#define MAX_CANONICALIZED_RESOURCE_SIZE \
(1 + 255 + 1 + MAX_URLENCODED_KEY_SIZE + (sizeof("?torrent") - 1) + 1)
// Mutex functions -----------------------------------------------------------
// Create a mutex. Returns 0 if none could be created.
struct S3Mutex *mutex_create();
// Lock a mutex
void mutex_lock(struct S3Mutex *mutex);
// Unlock a mutex
void mutex_unlock(struct S3Mutex *mutex);
// Destroy a mutex
void mutex_destroy(struct S3Mutex *mutex);
// Utilities -----------------------------------------------------------------
// URL-encodes a string from [src] into [dest]. [dest] must have at least
// 3x the number of characters that [source] has. At most [maxSrcSize] bytes
// from [src] are encoded; if more are present in [src], 0 is returned from
// urlEncode, else nonzero is returned.
int urlEncode(char *dest, const char *src, int maxSrcSize);
// Returns < 0 on failure >= 0 on success
time_t parseIso8601Time(const char *str);
uint64_t parseUnsignedInt(const char *str);
#endif /* UTIL_H */
|