doc: Fix section of functions age(xid) and mxid_age(xid)
[pgsql.git] / contrib / pgcrypto / mbuf.h
blob97873c931f913397a6da8e03936917a1e9255720
1 /*
2 * mbuf.h
3 * Memory buffer operations.
5 * Copyright (c) 2005 Marko Kreen
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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
27 * SUCH DAMAGE.
29 * contrib/pgcrypto/mbuf.h
32 #ifndef __PX_MBUF_H
33 #define __PX_MBUF_H
35 typedef struct MBuf MBuf;
36 typedef struct PushFilter PushFilter;
37 typedef struct PullFilter PullFilter;
38 typedef struct PushFilterOps PushFilterOps;
39 typedef struct PullFilterOps PullFilterOps;
41 struct PushFilterOps
44 * should return needed buffer size, 0- no buffering, <0 on error if NULL,
45 * no buffering, and priv=init_arg
47 int (*init) (PushFilter *next, void *init_arg, void **priv_p);
50 * send data to next. should consume all? if null, it will be simply
51 * copied (in-place) returns 0 on error
53 int (*push) (PushFilter *next, void *priv,
54 const uint8 *src, int len);
55 int (*flush) (PushFilter *next, void *priv);
56 void (*free) (void *priv);
59 struct PullFilterOps
62 * should return needed buffer size, 0- no buffering, <0 on error if NULL,
63 * no buffering, and priv=init_arg
65 int (*init) (void **priv_p, void *init_arg, PullFilter *src);
68 * request data from src, put result ptr to data_p can use ptr from src or
69 * use buf as work area if NULL in-place copy
71 int (*pull) (void *priv, PullFilter *src, int len,
72 uint8 **data_p, uint8 *buf, int buflen);
73 void (*free) (void *priv);
77 * Memory buffer
79 MBuf *mbuf_create(int len);
80 MBuf *mbuf_create_from_data(uint8 *data, int len);
81 int mbuf_avail(MBuf *mbuf);
82 int mbuf_size(MBuf *mbuf);
83 int mbuf_grab(MBuf *mbuf, int len, uint8 **data_p);
84 int mbuf_steal_data(MBuf *mbuf, uint8 **data_p);
85 int mbuf_append(MBuf *dst, const uint8 *buf, int len);
86 int mbuf_free(MBuf *mbuf);
89 * Push filter
91 int pushf_create(PushFilter **mp_p, const PushFilterOps *op,
92 void *init_arg, PushFilter *next);
93 int pushf_write(PushFilter *mp, const uint8 *data, int len);
94 void pushf_free_all(PushFilter *mp);
95 void pushf_free(PushFilter *mp);
96 int pushf_flush(PushFilter *mp);
98 int pushf_create_mbuf_writer(PushFilter **res, MBuf *dst);
101 * Pull filter
103 int pullf_create(PullFilter **pf_p, const PullFilterOps *op,
104 void *init_arg, PullFilter *src);
105 int pullf_read(PullFilter *pf, int len, uint8 **data_p);
106 int pullf_read_max(PullFilter *pf, int len,
107 uint8 **data_p, uint8 *tmpbuf);
108 void pullf_free(PullFilter *pf);
109 int pullf_read_fixed(PullFilter *src, int len, uint8 *dst);
111 int pullf_create_mbuf_reader(PullFilter **mp_p, MBuf *src);
113 #define GETBYTE(pf, dst) \
114 do { \
115 uint8 __b; \
116 int __res = pullf_read_fixed(pf, 1, &__b); \
117 if (__res < 0) \
118 return __res; \
119 (dst) = __b; \
120 } while (0)
122 #endif /* __PX_MBUF_H */