util.h 3.4 KB

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