oRTP  0.20.0
str_utils.h
1 /*
2  The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
3  Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 #ifndef STR_UTILS_H
21 #define STR_UTILS_H
22 
23 
24 #include <ortp/port.h>
25 
26 
27 typedef struct msgb
28 {
29  struct msgb *b_prev;
30  struct msgb *b_next;
31  struct msgb *b_cont;
32  struct datab *b_datap;
33  unsigned char *b_rptr;
34  unsigned char *b_wptr;
35  uint32_t reserved1;
36  uint32_t reserved2;
37 } mblk_t;
38 
39 typedef struct datab
40 {
41  unsigned char *db_base;
42  unsigned char *db_lim;
43  void (*db_freefn)(void*);
44  int db_ref;
45 } dblk_t;
46 
47 typedef struct _queue
48 {
49  mblk_t _q_stopper;
50  int q_mcount; /*number of packet in the q */
51 } queue_t;
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 void qinit(queue_t *q);
58 
59 void putq(queue_t *q, mblk_t *m);
60 
61 mblk_t * getq(queue_t *q);
62 
63 void insq(queue_t *q,mblk_t *emp, mblk_t *mp);
64 
65 void remq(queue_t *q, mblk_t *mp);
66 
67 mblk_t * peekq(queue_t *q);
68 
69 /* remove and free all messages in the q */
70 #define FLUSHALL 0
71 void flushq(queue_t *q, int how);
72 
73 void mblk_init(mblk_t *mp);
74 
75 /* allocates a mblk_t, that points to a datab_t, that points to a buffer of size size. */
76 mblk_t *allocb(int size, int unused);
77 #define BPRI_MED 0
78 
79 /* allocates a mblk_t, that points to a datab_t, that points to buf; buf will be freed using freefn */
80 mblk_t *esballoc(uint8_t *buf, int size, int pri, void (*freefn)(void*) );
81 
82 /* frees a mblk_t, and if the datab ref_count is 0, frees it and the buffer too */
83 void freeb(mblk_t *m);
84 
85 /* frees recursively (follow b_cont) a mblk_t, and if the datab
86 ref_count is 0, frees it and the buffer too */
87 void freemsg(mblk_t *mp);
88 
89 /* duplicates a mblk_t , buffer is not duplicated*/
90 mblk_t *dupb(mblk_t *m);
91 
92 /* duplicates a complex mblk_t, buffer is not duplicated */
93 mblk_t *dupmsg(mblk_t* m);
94 
95 /* returns the size of data of a message */
96 int msgdsize(const mblk_t *mp);
97 
98 /* concatenates all fragment of a complex message*/
99 void msgpullup(mblk_t *mp,int len);
100 
101 /* duplicates a single message, but with buffer included */
102 mblk_t *copyb(mblk_t *mp);
103 
104 /* duplicates a complex message with buffer included */
105 mblk_t *copymsg(mblk_t *mp);
106 
107 mblk_t * appendb(mblk_t *mp, const char *data, int size, bool_t pad);
108 void msgappend(mblk_t *mp, const char *data, int size, bool_t pad);
109 
110 mblk_t *concatb(mblk_t *mp, mblk_t *newm);
111 
112 #define qempty(q) (&(q)->_q_stopper==(q)->_q_stopper.b_next)
113 #define qfirst(q) ((q)->_q_stopper.b_next!=&(q)->_q_stopper ? (q)->_q_stopper.b_next : NULL)
114 #define qbegin(q) ((q)->_q_stopper.b_next)
115 #define qlast(q) ((q)->_q_stopper.b_prev!=&(q)->_q_stopper ? (q)->_q_stopper.b_prev : NULL)
116 #define qend(q,mp) ((mp)==&(q)->_q_stopper)
117 #define qnext(q,mp) ((mp)->b_next)
118 
119 typedef struct _msgb_allocator{
120  queue_t q;
122 
123 void msgb_allocator_init(msgb_allocator_t *pa);
124 mblk_t *msgb_allocator_alloc(msgb_allocator_t *pa, int size);
125 void msgb_allocator_uninit(msgb_allocator_t *pa);
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #endif