oRTP 0.23.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#if defined(ORTP_TIMESTAMP)
26#include <time.h>
27#endif
28
29
30#ifndef MIN
31#define MIN(a,b) (((a)>(b)) ? (b) : (a))
32#endif
33#ifndef MAX
34#define MAX(a,b) (((a)>(b)) ? (a) : (b))
35#endif
36
37#define return_if_fail(expr) if (!(expr)) {printf("%s:%i- assertion"#expr "failed\n",__FILE__,__LINE__); return;}
38#define return_val_if_fail(expr,ret) if (!(expr)) {printf("%s:%i- assertion" #expr "failed\n",__FILE__,__LINE__); return (ret);}
39
40
41typedef struct ortp_recv_addr {
42 int family;
43 union {
44 struct in_addr ipi_addr;
45 struct in6_addr ipi6_addr;
46 } addr;
48
49typedef struct msgb
50{
51 struct msgb *b_prev;
52 struct msgb *b_next;
53 struct msgb *b_cont;
54 struct datab *b_datap;
55 unsigned char *b_rptr;
56 unsigned char *b_wptr;
57 uint32_t reserved1;
58 uint32_t reserved2;
59#if defined(ORTP_TIMESTAMP)
60 struct timeval timestamp;
61#endif
62 ortp_recv_addr_t recv_addr;
63} mblk_t;
64
65
66
67typedef struct datab
68{
69 unsigned char *db_base;
70 unsigned char *db_lim;
71 void (*db_freefn)(void*);
72 int db_ref;
73} dblk_t;
74
75typedef struct _queue
76{
77 mblk_t _q_stopper;
78 int q_mcount; /*number of packet in the q */
79} queue_t;
80
81#ifdef __cplusplus
82extern "C" {
83#endif
84
85ORTP_PUBLIC void qinit(queue_t *q);
86
87ORTP_PUBLIC void putq(queue_t *q, mblk_t *m);
88
89ORTP_PUBLIC mblk_t * getq(queue_t *q);
90
91ORTP_PUBLIC void insq(queue_t *q,mblk_t *emp, mblk_t *mp);
92
93ORTP_PUBLIC void remq(queue_t *q, mblk_t *mp);
94
95ORTP_PUBLIC mblk_t * peekq(queue_t *q);
96
97/* remove and free all messages in the q */
98#define FLUSHALL 0
99ORTP_PUBLIC void flushq(queue_t *q, int how);
100
101ORTP_PUBLIC void mblk_init(mblk_t *mp);
102
103ORTP_PUBLIC void mblk_meta_copy(const mblk_t *source, mblk_t *dest);
104
105/* allocates a mblk_t, that points to a datab_t, that points to a buffer of size size. */
106ORTP_PUBLIC mblk_t *allocb(size_t size, int unused);
107#define BPRI_MED 0
108
109/* allocates a mblk_t, that points to a datab_t, that points to buf; buf will be freed using freefn */
110ORTP_PUBLIC mblk_t *esballoc(uint8_t *buf, size_t size, int pri, void (*freefn)(void*) );
111
112/* frees a mblk_t, and if the datab ref_count is 0, frees it and the buffer too */
113ORTP_PUBLIC void freeb(mblk_t *m);
114
115/* frees recursively (follow b_cont) a mblk_t, and if the datab
116ref_count is 0, frees it and the buffer too */
117ORTP_PUBLIC void freemsg(mblk_t *mp);
118
119/* duplicates a mblk_t , buffer is not duplicated*/
120ORTP_PUBLIC mblk_t *dupb(mblk_t *m);
121
122/* duplicates a complex mblk_t, buffer is not duplicated */
123ORTP_PUBLIC mblk_t *dupmsg(mblk_t* m);
124
125/* returns the size of data of a message */
126ORTP_PUBLIC size_t msgdsize(const mblk_t *mp);
127
128/* concatenates all fragment of a complex message*/
129ORTP_PUBLIC void msgpullup(mblk_t *mp,size_t len);
130
131/* duplicates a single message, but with buffer included */
132ORTP_PUBLIC mblk_t *copyb(mblk_t *mp);
133
134/* duplicates a complex message with buffer included */
135ORTP_PUBLIC mblk_t *copymsg(mblk_t *mp);
136
137ORTP_PUBLIC mblk_t * appendb(mblk_t *mp, const char *data, size_t size, bool_t pad);
138ORTP_PUBLIC void msgappend(mblk_t *mp, const char *data, size_t size, bool_t pad);
139
140ORTP_PUBLIC mblk_t *concatb(mblk_t *mp, mblk_t *newm);
141
142#define qempty(q) (&(q)->_q_stopper==(q)->_q_stopper.b_next)
143#define qfirst(q) ((q)->_q_stopper.b_next!=&(q)->_q_stopper ? (q)->_q_stopper.b_next : NULL)
144#define qbegin(q) ((q)->_q_stopper.b_next)
145#define qlast(q) ((q)->_q_stopper.b_prev!=&(q)->_q_stopper ? (q)->_q_stopper.b_prev : NULL)
146#define qend(q,mp) ((mp)==&(q)->_q_stopper)
147#define qnext(q,mp) ((mp)->b_next)
148
149typedef struct _msgb_allocator{
150 queue_t q;
152
153ORTP_PUBLIC void msgb_allocator_init(msgb_allocator_t *pa);
154ORTP_PUBLIC mblk_t *msgb_allocator_alloc(msgb_allocator_t *pa, size_t size);
155ORTP_PUBLIC void msgb_allocator_uninit(msgb_allocator_t *pa);
156
157#ifdef __cplusplus
158}
159#endif
160
161#endif
Definition: str_utils.h:149
Definition: str_utils.h:76
Definition: str_utils.h:68
Definition: str_utils.h:50
Definition: str_utils.h:41