archive_write_private.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*-
  2. * Copyright (c) 2003-2007 Tim Kientzle
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. *
  25. * $FreeBSD: head/lib/libarchive/archive_write_private.h 201155 2009-12-29 05:20:12Z kientzle $
  26. */
  27. #ifndef __LIBARCHIVE_BUILD
  28. #ifndef __LIBARCHIVE_TEST
  29. #error This header is only to be used internally to libarchive.
  30. #endif
  31. #endif
  32. #ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED
  33. #define ARCHIVE_WRITE_PRIVATE_H_INCLUDED
  34. #include "archive.h"
  35. #include "archive_string.h"
  36. #include "archive_private.h"
  37. struct archive_write;
  38. struct archive_write_filter {
  39. int64_t bytes_written;
  40. struct archive *archive; /* Associated archive. */
  41. struct archive_write_filter *next_filter; /* Who I write to. */
  42. int (*options)(struct archive_write_filter *,
  43. const char *key, const char *value);
  44. int (*open)(struct archive_write_filter *);
  45. int (*write)(struct archive_write_filter *, const void *, size_t);
  46. int (*close)(struct archive_write_filter *);
  47. int (*free)(struct archive_write_filter *);
  48. void *data;
  49. const char *name;
  50. int code;
  51. int bytes_per_block;
  52. int bytes_in_last_block;
  53. };
  54. #if ARCHIVE_VERSION < 4000000
  55. void __archive_write_filters_free(struct archive *);
  56. #endif
  57. struct archive_write_filter *__archive_write_allocate_filter(struct archive *);
  58. int __archive_write_output(struct archive_write *, const void *, size_t);
  59. int __archive_write_nulls(struct archive_write *, size_t);
  60. int __archive_write_filter(struct archive_write_filter *, const void *, size_t);
  61. int __archive_write_open_filter(struct archive_write_filter *);
  62. int __archive_write_close_filter(struct archive_write_filter *);
  63. struct archive_write {
  64. struct archive archive;
  65. /* Dev/ino of the archive being written. */
  66. int skip_file_set;
  67. int64_t skip_file_dev;
  68. int64_t skip_file_ino;
  69. /* Utility: Pointer to a block of nulls. */
  70. const unsigned char *nulls;
  71. size_t null_length;
  72. /* Callbacks to open/read/write/close archive stream. */
  73. archive_open_callback *client_opener;
  74. archive_write_callback *client_writer;
  75. archive_close_callback *client_closer;
  76. void *client_data;
  77. /*
  78. * Blocking information. Note that bytes_in_last_block is
  79. * misleadingly named; I should find a better name. These
  80. * control the final output from all compressors, including
  81. * compression_none.
  82. */
  83. int bytes_per_block;
  84. int bytes_in_last_block;
  85. /*
  86. * First and last write filters in the pipeline.
  87. */
  88. struct archive_write_filter *filter_first;
  89. struct archive_write_filter *filter_last;
  90. /*
  91. * Pointers to format-specific functions for writing. They're
  92. * initialized by archive_write_set_format_XXX() calls.
  93. */
  94. void *format_data;
  95. const char *format_name;
  96. int (*format_init)(struct archive_write *);
  97. int (*format_options)(struct archive_write *,
  98. const char *key, const char *value);
  99. int (*format_finish_entry)(struct archive_write *);
  100. int (*format_write_header)(struct archive_write *,
  101. struct archive_entry *);
  102. ssize_t (*format_write_data)(struct archive_write *,
  103. const void *buff, size_t);
  104. int (*format_close)(struct archive_write *);
  105. int (*format_free)(struct archive_write *);
  106. /*
  107. * Encryption passphrase.
  108. */
  109. char *passphrase;
  110. archive_passphrase_callback *passphrase_callback;
  111. void *passphrase_client_data;
  112. };
  113. /*
  114. * Utility function to format a USTAR header into a buffer. If
  115. * "strict" is set, this tries to create the absolutely most portable
  116. * version of a ustar header. If "strict" is set to 0, then it will
  117. * relax certain requirements.
  118. *
  119. * Generally, format-specific declarations don't belong in this
  120. * header; this is a rare example of a function that is shared by
  121. * two very similar formats (ustar and pax).
  122. */
  123. int
  124. __archive_write_format_header_ustar(struct archive_write *, char buff[512],
  125. struct archive_entry *, int tartype, int strict,
  126. struct archive_string_conv *);
  127. struct archive_write_program_data;
  128. struct archive_write_program_data * __archive_write_program_allocate(const char *program_name);
  129. int __archive_write_program_free(struct archive_write_program_data *);
  130. int __archive_write_program_open(struct archive_write_filter *,
  131. struct archive_write_program_data *, const char *);
  132. int __archive_write_program_close(struct archive_write_filter *,
  133. struct archive_write_program_data *);
  134. int __archive_write_program_write(struct archive_write_filter *,
  135. struct archive_write_program_data *, const void *, size_t);
  136. /*
  137. * Get a encryption passphrase.
  138. */
  139. const char * __archive_write_get_passphrase(struct archive_write *a);
  140. #endif