3 * Memory buffer operations.
5 * Copyright (c) 2005 Marko Kreen
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * contrib/pgcrypto/mbuf.c
37 #define STEP (16*1024)
87 mbuf->
buf_end = newbuf + newlen;
118 mbuf =
palloc(
sizeof *mbuf);
135 mbuf =
palloc(
sizeof *mbuf);
169 *data_p = mbuf->
data;
197 if (op->
init != NULL)
199 res = op->
init(&priv, init_arg, src);
244/* may return less data than asked, 0 means eof */
270 if (res <= 0 || res ==
len)
273 /* read was shorter, use tmpbuf */
274 memcpy(
tmpbuf, *data_p, res);
284 /* so the caller must clear only on success */
290 memcpy(
tmpbuf + total, tmp, res);
298 * caller wants exactly len bytes and don't bother with references
311 px_debug(
"pullf_read_fixed: need=%d got=%d",
len, res);
363 if (op->
init != NULL)
365 res = op->
init(
next, init_arg, &priv);
437/* consumes all data, returns len on success */
451 * try to empty buffer
468 * buffer full, process
476 * now process directly from data
536 return res < 0 ? res : 0;
static int pull_from_mbuf(void *arg, PullFilter *src, int len, uint8 **data_p, uint8 *buf, int buflen)
int pullf_read_fixed(PullFilter *src, int len, uint8 *dst)
int pullf_create(PullFilter **pf_p, const PullFilterOps *op, void *init_arg, PullFilter *src)
int pushf_write(PushFilter *mp, const uint8 *data, int len)
int mbuf_avail(MBuf *mbuf)
int pushf_create(PushFilter **mp_p, const PushFilterOps *op, void *init_arg, PushFilter *next)
int pullf_read_max(PullFilter *pf, int len, uint8 **data_p, uint8 *tmpbuf)
int mbuf_free(MBuf *mbuf)
int pullf_create_mbuf_reader(PullFilter **mp_p, MBuf *src)
int mbuf_append(MBuf *dst, const uint8 *buf, int len)
int pullf_read(PullFilter *pf, int len, uint8 **data_p)
int pushf_create_mbuf_writer(PushFilter **res, MBuf *dst)
static void prepare_room(MBuf *mbuf, int block_len)
static const struct PullFilterOps mbuf_reader
MBuf * mbuf_create_from_data(uint8 *data, int len)
int mbuf_steal_data(MBuf *mbuf, uint8 **data_p)
MBuf * mbuf_create(int len)
void pushf_free_all(PushFilter *mp)
int pushf_flush(PushFilter *mp)
static const struct PushFilterOps mbuf_filter
static int wrap_process(PushFilter *mp, const uint8 *data, int len)
static int push_into_mbuf(PushFilter *next, void *arg, const uint8 *data, int len)
int mbuf_size(MBuf *mbuf)
int mbuf_grab(MBuf *mbuf, int len, uint8 **data_p)
void pushf_free(PushFilter *mp)
void pullf_free(PullFilter *pf)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
void px_debug(const char *fmt,...)
void px_memset(void *ptr, int c, size_t len)
#define PXE_PGP_CORRUPT_DATA
int(* init)(void **priv_p, void *init_arg, PullFilter *src)
int(* pull)(void *priv, PullFilter *src, int len, uint8 **data_p, uint8 *buf, int buflen)
int(* flush)(PushFilter *next, void *priv)
int(* init)(PushFilter *next, void *init_arg, void **priv_p)
int(* push)(PushFilter *next, void *priv, const uint8 *src, int len)
static StringInfoData tmpbuf