util.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 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. * <https://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. * <https://www.gnu.org/licenses/>.
  30. *
  31. ************************************************************************** **/
  32. #ifndef UTIL_H
  33. #define UTIL_H
  34. #ifndef WINSCP
  35. #include <curl/curl.h>
  36. #include <curl/multi.h>
  37. #endif
  38. #include <stdint.h>
  39. #include "libs3.h"
  40. // acl groups
  41. #define ACS_URL "http://acs.amazonaws.com/groups/"
  42. #define ACS_GROUP_ALL_USERS ACS_URL "global/AllUsers"
  43. #define ACS_GROUP_AWS_USERS ACS_URL "global/AuthenticatedUsers"
  44. #define ACS_GROUP_LOG_DELIVERY ACS_URL "s3/LogDelivery"
  45. // Derived from S3 documentation
  46. // This is the maximum number of bytes needed in a "compacted meta header"
  47. // buffer, which is a buffer storing all of the compacted meta headers.
  48. #define COMPACTED_METADATA_BUFFER_SIZE S3_MAX_METADATA_SIZE // WINSCP
  49. // Maximum url encoded key size; since every single character could require
  50. // URL encoding, it's 3 times the size of a key (since each url encoded
  51. // character takes 3 characters: %NN)
  52. #define MAX_URLENCODED_KEY_SIZE (3 * S3_MAX_KEY_SIZE)
  53. // This is the maximum size of a URI that could be passed to S3:
  54. // https://s3.amazonaws.com/${BUCKET}/${KEY}?acl
  55. // 255 is the maximum bucket length
  56. #define MAX_URI_SIZE \
  57. ((sizeof("https:///") - 1) + S3_MAX_HOSTNAME_SIZE + 255 + 1 + \
  58. MAX_URLENCODED_KEY_SIZE + (sizeof("?torrent") - 1) + 1)
  59. // Maximum size of a canonicalized resource
  60. #define MAX_CANONICALIZED_RESOURCE_SIZE \
  61. (1 + 255 + 1 + MAX_URLENCODED_KEY_SIZE + (sizeof("?torrent") - 1) + 1)
  62. #define MAX_ACCESS_KEY_ID_LENGTH S3_MAX_ACCESS_KEY_ID_LENGTH
  63. #define S3_MAX_SCOPE_LENGTH 3 // WINSCP "s3"/"sts"
  64. // Maximum length of a credential string
  65. // <access key>/<yyyymmdd>/<region>/<scope>/aws4_request // WINSCP
  66. #define MAX_CREDENTIAL_SIZE \
  67. (MAX_ACCESS_KEY_ID_LENGTH + 1) + 8 + 1 + S3_MAX_REGION_LENGTH + sizeof("//aws4_request") + S3_MAX_SCOPE_LENGTH // WINSCP
  68. // Utilities -----------------------------------------------------------------
  69. // URL-encodes a string from [src] into [dest]. [dest] must have at least
  70. // 3x the number of characters that [source] has. At most [maxSrcSize] bytes
  71. // from [src] are encoded; if more are present in [src], 0 is returned from
  72. // urlEncode, else nonzero is returned.
  73. int urlEncode(char *dest, const char *src, int maxSrcSize, int encodeSlash);
  74. // Returns < 0 on failure >= 0 on success
  75. int64_t parseIso8601Time(const char *str);
  76. uint64_t parseUnsignedInt(const char *str);
  77. // Because Windows seems to be missing isblank(), use our own; it's a very
  78. // easy function to write in any case
  79. int is_blank(char c);
  80. #endif /* UTIL_H */