Imported Upstream version 1.16.0
[platform/upstream/gpgme.git] / src / data.h
index 3d404af..648d976 100644 (file)
 # include <sys/types.h>
 #endif
 #include <limits.h>
+#include <stdint.h>
 
 #include "gpgme.h"
 
+/* Figure out the standard size for internal data buffers.  */
+#ifdef PIPE_BUF
+# define BUFFER_SIZE PIPE_BUF
+#else
+# ifdef _POSIX_PIPE_BUF
+#  define BUFFER_SIZE _POSIX_PIPE_BUF
+# else
+#  ifdef HAVE_W32_SYSTEM
+#   define BUFFER_SIZE 4096
+#  else
+#   define BUFFER_SIZE 512
+#  endif
+# endif
+#endif
+
+
 \f
 /* Read up to SIZE bytes into buffer BUFFER from the data object with
    the handle DH.  Return the number of characters read, 0 on EOF and
@@ -48,7 +65,7 @@ typedef gpgme_ssize_t (*gpgme_data_write_cb) (gpgme_data_t dh,
                                               size_t size);
 
 /* Set the current position from where the next read or write starts
-   in the data object with the handle DH to OFFSET, relativ to
+   in the data object with the handle DH to OFFSET, relative to
    WHENCE.  */
 typedef gpgme_off_t (*gpgme_data_seek_cb) (gpgme_data_t dh,
                                             gpgme_off_t offset,
@@ -73,22 +90,35 @@ struct gpgme_data
 {
   struct _gpgme_data_cbs *cbs;
   gpgme_data_encoding_t encoding;
-
-#ifdef PIPE_BUF
-#define BUFFER_SIZE PIPE_BUF
-#else
-#ifdef _POSIX_PIPE_BUF
-#define BUFFER_SIZE _POSIX_PIPE_BUF
-#else
-#define BUFFER_SIZE 512
-#endif
-#endif
-  char pending[BUFFER_SIZE];
-  int pending_len;
+  unsigned int propidx;  /* Index into the property table.  */
 
   /* File name of the data object.  */
   char *file_name;
 
+  /* Hint on the to be expected total size of the data.  */
+  gpgme_off_t size_hint;
+
+  /* If no 0 the size of an allocated inbound or outpund buffers.  The
+   * value is at least BUFFER_SIZE and capped at 1MiB.  */
+  unsigned int io_buffer_size;
+
+  /* If not NULL a malloced buffer used for inbound data used instead
+   * of the handler's static buffer.  Its size is io_buffer_size.  */
+  char *inbound_buffer;
+
+  /* A default memory space for the outbound handler and the number of
+   * actual pending bytes.  If outbound_buffer is not NULL, this is a
+   * malloced buffer used instead of the outboundspace.  Its malloced
+   * size is io_buffer_size. */
+  char outboundspace[BUFFER_SIZE];
+  unsigned int outbound_pending;
+  char *outbound_buffer;
+
+  /* If set sensitive data is conveyed via the internal buffer.  This
+   * flags overwrites the memory of the buffers with zero before they
+   * are released. */
+  unsigned int sensitive:1;
+
   union
   {
     /* For gpgme_data_new_from_fd.  */
@@ -97,6 +127,9 @@ struct gpgme_data
     /* For gpgme_data_new_from_stream.  */
     FILE *stream;
 
+    /* For gpgme_data_new_from_estream.  */
+    gpgrt_stream_t e_stream;
+
     /* For gpgme_data_new_from_cbs.  */
     struct
     {
@@ -124,7 +157,28 @@ struct gpgme_data
   } data;
 };
 
+
+/* The data property types.  */
+typedef enum
+  {
+    DATA_PROP_NONE = 0,   /* Dummy property. */
+    DATA_PROP_BLANKOUT    /* Do not return the held data.  */
+  } data_prop_t;
+
+
 \f
+/* Return the data object's serial number for handle DH.  */
+uint64_t _gpgme_data_get_dserial (gpgme_data_t dh);
+
+/* Set an internal property of a data object.  */
+gpg_error_t _gpgme_data_set_prop (gpgme_data_t dh, uint64_t dserial,
+                                  data_prop_t name, int value);
+
+/* Get an internal property of a data object.  */
+gpg_error_t _gpgme_data_get_prop (gpgme_data_t dh, uint64_t dserial,
+                                  data_prop_t name, int *r_value);
+
+/* Create a new data object.  */
 gpgme_error_t _gpgme_data_new (gpgme_data_t *r_dh,
                               struct _gpgme_data_cbs *cbs);
 
@@ -134,4 +188,8 @@ void _gpgme_data_release (gpgme_data_t dh);
    return -1.  */
 int _gpgme_data_get_fd (gpgme_data_t dh);
 
+/* Get the size-hint value for DH or 0 if not available.  */
+gpgme_off_t _gpgme_data_get_size_hint (gpgme_data_t dh);
+
+
 #endif /* DATA_H */