PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/amanda/tags/amanda261p2/device-src/s3-util.h

#
C Header | 124 lines | 47 code | 17 blank | 60 comment | 0 complexity | 1921dc054683ca7912c47e81c810972f MD5 | raw file
  1. /*
  2. * Copyright (c) 2005-2008 Zmanda Inc. All Rights Reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU Lesser General Public License version 2.1 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. * License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public License
  14. * along with this library; if not, write to the Free Software Foundation,
  15. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  16. *
  17. * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
  18. * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
  19. */
  20. #ifndef __S3_UTIL_H__
  21. #define __S3_UTIL_H__
  22. #ifdef HAVE_REGEX_H
  23. # ifdef HAVE_SYS_TYPES_H
  24. # include <sys/types.h>
  25. # endif
  26. #include <regex.h>
  27. #endif
  28. #include <glib.h>
  29. /*
  30. * Constants
  31. */
  32. /* number of raw bytes in MD5 hash */
  33. #define S3_MD5_HASH_BYTE_LEN 16
  34. /* length of an MD5 hash encoded as base64 (not including terminating NULL) */
  35. #define S3_MD5_HASH_B64_LEN 25
  36. /* length of an MD5 hash encoded as hexadecimal (not including terminating NULL) */
  37. #define S3_MD5_HASH_HEX_LEN 32
  38. /*
  39. * Types
  40. */
  41. #ifndef HAVE_REGEX_H
  42. typedef GRegex* regex_t;
  43. typedef gint regoff_t;
  44. typedef struct
  45. {
  46. regoff_t rm_so; /* Byte offset from string's start to substring's start. */
  47. regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
  48. } regmatch_t;
  49. typedef enum
  50. {
  51. REG_NOERROR = 0, /* Success. */
  52. REG_NOMATCH /* Didn't find a match (for regexec). */
  53. } reg_errcode_t;
  54. #endif
  55. /*
  56. * Functions
  57. */
  58. #ifndef USE_GETTEXT
  59. /* we don't use gettextize, so hack around this ... */
  60. #define _(str) (str)
  61. #endif
  62. /*
  63. * Wrapper around regexec to handle programmer errors.
  64. * Only returns if the regexec returns 0 (match) or REG_NOMATCH.
  65. * See regexec(3) documentation for the rest.
  66. */
  67. int
  68. s3_regexec_wrap(regex_t *regex,
  69. const char *str,
  70. size_t nmatch,
  71. regmatch_t pmatch[],
  72. int eflags);
  73. #ifndef HAVE_AMANDA_H
  74. char*
  75. find_regex_substring(const char* base_string,
  76. const regmatch_t match);
  77. #endif
  78. /*
  79. * Encode bytes using Base-64
  80. *
  81. * @note: GLib 2.12+ has a function for this (g_base64_encode)
  82. * but we support much older versions. gnulib does as well, but its
  83. * hard to use correctly (see its notes).
  84. *
  85. * @param to_enc: The data to encode.
  86. * @returns: A new, null-terminated string or NULL if to_enc is NULL.
  87. */
  88. gchar*
  89. s3_base64_encode(const GByteArray *to_enc);
  90. /*
  91. * Encode bytes using hexadecimal
  92. *
  93. * @param to_enc: The data to encode.
  94. * @returns: A new, null-terminated string or NULL if to_enc is NULL.
  95. */
  96. gchar*
  97. s3_hex_encode(const GByteArray *to_enc);
  98. /*
  99. * Compute the MD5 hash of a blob of data.
  100. *
  101. * @param to_hash: The data to compute the hash for.
  102. * @returns: A new GByteArray containing the MD5 hash of data or
  103. * NULL if to_hash is NULL.
  104. */
  105. GByteArray*
  106. s3_compute_md5_hash(const GByteArray *to_hash);
  107. #endif