Rename PACKETW to WPACKET
[openssl.git] / ssl / packet_locl.h
index d34034dedb09d36465b8bbc6198c83ec264de329..88bc7ddebc621a8294975742bbd0dc89dc7c6341 100644 (file)
@@ -548,6 +548,82 @@ __owur static ossl_inline int PACKET_get_length_prefixed_3(PACKET *pkt,
 
     return 1;
 }
+
+/* Writeable packets */
+
+typedef struct packetw_buf {
+    /* The buffer where we store the output data */
+    BUF_MEM *buf;
+
+    /* Pointer to where we are currently writing */
+    unsigned char *curr;
+
+    /* Number of bytes written so far */
+    size_t written;
+
+    /*
+     * Maximum number of bytes we will allow to be written to this WPACKET. Zero
+     * if no maximum
+     */
+    size_t maxsize;
+} WPACKET_BUF;
+
+typedef struct packetw_st WPACKET;
+struct packetw_st {
+    /* The parent WPACKET if we have one or NULL otherwise */
+    WPACKET *parent;
+
+    /* The actual buffer - shared with sub-packets */
+    WPACKET_BUF *wbuf;
+
+    /* Flags for this WPACKET */
+    unsigned int flags;
+
+    /*
+     * Pointer to where the length of this WPACKET goes (or NULL if we don't
+     * write the length)
+     */
+    unsigned char *packet_len;
+
+    /* Number of bytes in the packet_len */
+    size_t lenbytes;
+
+    /* Number of bytes written to the buf prior to this packet starting */
+    size_t pwritten;
+
+    /* True if we have an active sub-packet or false otherwise */
+    int haschild;
+
+    /* True if WPACKET_close() has been called on this WPACKET */
+    int isclosed;
+};
+
+/* Flags */
+#define OPENSSL_WPACKET_FLAGS_NONE                      0
+/* Error on WPACKET_close() if no data written to the WPACKET */
+#define OPENSSL_WPACKET_FLAGS_NON_ZERO_LENGTH           1
+/*
+ * Abandon all changes on WPACKET_close() if no data written to the WPACKET,
+ * i.e. this does not write out a zero packet length
+ */
+#define OPENSSL_WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH    2
+
+int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes);
+int WPACKET_init(WPACKET *pkt, BUF_MEM *buf);
+int WPACKET_set_flags(WPACKET *pkt, unsigned int flags);
+int WPACKET_set_packet_len(WPACKET *pkt, unsigned char *packet_len,
+                           size_t lenbytes);
+int WPACKET_close(WPACKET *pkt);
+int WPACKET_get_sub_packet_len(WPACKET *pkt, WPACKET *subpkt, size_t lenbytes);
+int WPACKET_get_sub_packet(WPACKET *pkt, WPACKET *subpkt);
+int WPACKET_allocate_bytes(WPACKET *pkt, size_t bytes,
+                           unsigned char **allocbytes);
+int WPACKET_put_bytes(WPACKET *pkt, unsigned int val, size_t bytes);
+int WPACKET_set_max_size(WPACKET *pkt, size_t maxsize);
+int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len);
+int WPACKET_get_total_written(WPACKET *pkt, size_t *written);
+int WPACKET_get_length(WPACKET *pkt, size_t *len);
+
 # ifdef __cplusplus
 }
 # endif