Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __PX_MBUF_H
00033 #define __PX_MBUF_H
00034
00035 typedef struct MBuf MBuf;
00036 typedef struct PushFilter PushFilter;
00037 typedef struct PullFilter PullFilter;
00038 typedef struct PushFilterOps PushFilterOps;
00039 typedef struct PullFilterOps PullFilterOps;
00040
00041 struct PushFilterOps
00042 {
00043
00044
00045
00046
00047 int (*init) (PushFilter *next, void *init_arg, void **priv_p);
00048
00049
00050
00051
00052
00053 int (*push) (PushFilter *next, void *priv,
00054 const uint8 *src, int len);
00055 int (*flush) (PushFilter *next, void *priv);
00056 void (*free) (void *priv);
00057 };
00058
00059 struct PullFilterOps
00060 {
00061
00062
00063
00064
00065 int (*init) (void **priv_p, void *init_arg, PullFilter *src);
00066
00067
00068
00069
00070
00071 int (*pull) (void *priv, PullFilter *src, int len,
00072 uint8 **data_p, uint8 *buf, int buflen);
00073 void (*free) (void *priv);
00074 };
00075
00076
00077
00078
00079 MBuf *mbuf_create(int len);
00080 MBuf *mbuf_create_from_data(uint8 *data, int len);
00081 int mbuf_tell(MBuf *mbuf);
00082 int mbuf_avail(MBuf *mbuf);
00083 int mbuf_size(MBuf *mbuf);
00084 int mbuf_grab(MBuf *mbuf, int len, uint8 **data_p);
00085 int mbuf_steal_data(MBuf *mbuf, uint8 **data_p);
00086 int mbuf_append(MBuf *dst, const uint8 *buf, int cnt);
00087 int mbuf_rewind(MBuf *mbuf);
00088 int mbuf_free(MBuf *mbuf);
00089
00090
00091
00092
00093 int pushf_create(PushFilter **res, const PushFilterOps *ops, void *init_arg,
00094 PushFilter *next);
00095 int pushf_write(PushFilter *mp, const uint8 *data, int len);
00096 void pushf_free_all(PushFilter *mp);
00097 void pushf_free(PushFilter *mp);
00098 int pushf_flush(PushFilter *mp);
00099
00100 int pushf_create_mbuf_writer(PushFilter **mp_p, MBuf *mbuf);
00101
00102
00103
00104
00105 int pullf_create(PullFilter **res, const PullFilterOps *ops,
00106 void *init_arg, PullFilter *src);
00107 int pullf_read(PullFilter *mp, int len, uint8 **data_p);
00108 int pullf_read_max(PullFilter *mp, int len,
00109 uint8 **data_p, uint8 *tmpbuf);
00110 void pullf_free(PullFilter *mp);
00111 int pullf_read_fixed(PullFilter *src, int len, uint8 *dst);
00112
00113 int pullf_create_mbuf_reader(PullFilter **pf_p, MBuf *mbuf);
00114
00115 #define GETBYTE(pf, dst) \
00116 do { \
00117 uint8 __b; \
00118 int __res = pullf_read_fixed(pf, 1, &__b); \
00119 if (__res < 0) \
00120 return __res; \
00121 (dst) = __b; \
00122 } while (0)
00123
00124 #endif