/src/zziplib/zzip/plugin.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 99 lines · 39 code · 14 blank · 46 comment · 0 complexity · c8e94e5cb5e7f015f39f37cfcd473b88 MD5 · raw file

  1. /*
  2. * Author:
  3. * Guido Draheim <guidod@gmx.de>
  4. *
  5. * Copyright (c) 2002,2003 Guido Draheim
  6. * All rights reserved
  7. * use under the restrictions of the
  8. * Lesser GNU General Public License
  9. * or alternatively the restrictions
  10. * of the Mozilla Public License 1.1
  11. *
  12. * the interfaces for the plugin_io system
  13. *
  14. * Using the following you can provide your own file I/O functions to
  15. * e.g. read data directly from memory, provide simple
  16. * "encryption"/"decryption" of on-disk .zip-files...
  17. * Note that this currently only provides a subset of the functionality
  18. * in zziplib. It does not attempt to provide any directory functions,
  19. * but if your program 1) only uses ordinary on-disk files and you
  20. * just want this for file obfuscation, or 2) you only access your
  21. * .zip archives using zzip_open & co., this is sufficient.
  22. *
  23. * Currently the default io are the POSIX functions, except
  24. * for 'filesize' that is zziplibs own provided zzip_filesize function,
  25. * using standard POSIX fd's. You are however free to replace this with
  26. * whatever data type you need, so long as you provide implementations
  27. * for all the functions, and the data type fits an int.
  28. *
  29. * all functions receiving ext_io are able to cope with both arguments
  30. * set to zero which will let them default to a ZIP ext and posix io.
  31. */
  32. #ifndef _ZZIP_PLUGIN_H /* zzip-io.h */
  33. #define _ZZIP_PLUGIN_H 1
  34. #include <zzip/zzip.h>
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /* we have renamed zzip_plugin_io.use_mmap to zzip_plugin_io.sys */
  39. #define ZZIP_PLUGIN_IO_SYS 1
  40. struct zzip_plugin_io { /* use "zzip_plugin_io_handlers" in applications !! */
  41. int (*open)(zzip_char_t* name, int flags, ...);
  42. int (*close)(int fd);
  43. zzip_ssize_t (*read)(int fd, void* buf, zzip_size_t len);
  44. zzip_off_t (*seeks)(int fd, zzip_off_t offset, int whence);
  45. zzip_off_t (*filesize)(int fd);
  46. long sys;
  47. long type;
  48. zzip_ssize_t (*write)(int fd, _zzip_const void* buf, zzip_size_t len);
  49. };
  50. typedef union _zzip_plugin_io
  51. {
  52. struct zzip_plugin_io fd;
  53. struct { void* padding[8]; } ptr;
  54. } zzip_plugin_io_handlers;
  55. #define _zzip_plugin_io_handlers zzip_plugin_io_handlers
  56. /* for backward compatibility, add the following to your application code:
  57. * #ifndef _zzip_plugin_io_handlers
  58. * #define _zzip_plugin_io_handlers struct zzip_plugin_io
  59. */
  60. typedef zzip_plugin_io_handlers* zzip_plugin_io_handlers_t;
  61. #ifdef ZZIP_LARGEFILE_RENAME
  62. #define zzip_filesize zzip_filesize64
  63. #define zzip_get_default_io zzip_get_default_io64
  64. #define zzip_init_io zzip_init_io64
  65. #endif
  66. _zzip_export zzip_off_t
  67. zzip_filesize(int fd);
  68. /* get the default file I/O functions.
  69. * This functions returns a pointer to an internal static structure.
  70. */
  71. _zzip_export zzip_plugin_io_t zzip_get_default_io(void);
  72. /*
  73. * Initializes a zzip_plugin_io_t to the zziplib default io.
  74. * This is useful if you only want to override e.g. the 'read' function.
  75. * all zzip functions that can receive a zzip_plugin_io_t can
  76. * handle a zero pointer in that place and default to posix io.
  77. */
  78. _zzip_export
  79. int zzip_init_io(zzip_plugin_io_handlers_t io, int flags);
  80. /* zzip_init_io flags : */
  81. # define ZZIP_IO_USE_MMAP 1
  82. #ifdef __cplusplus
  83. };
  84. #endif
  85. #endif