|
oRTP
0.22.0
|
00001 /* 00002 The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack. 00003 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 #ifndef STR_UTILS_H 00021 #define STR_UTILS_H 00022 00023 00024 #include <ortp/port.h> 00025 #if defined(ORTP_TIMESTAMP) 00026 #include <time.h> 00027 #endif 00028 00029 00030 #ifndef MIN 00031 #define MIN(a,b) (((a)>(b)) ? (b) : (a)) 00032 #endif 00033 #ifndef MAX 00034 #define MAX(a,b) (((a)>(b)) ? (a) : (b)) 00035 #endif 00036 00037 #define return_if_fail(expr) if (!(expr)) {printf("%s:%i- assertion"#expr "failed\n",__FILE__,__LINE__); return;} 00038 #define return_val_if_fail(expr,ret) if (!(expr)) {printf("%s:%i- assertion" #expr "failed\n",__FILE__,__LINE__); return (ret);} 00039 00040 00041 typedef struct ortp_recv_addr { 00042 int family; 00043 union { 00044 struct in_addr ipi_addr; 00045 struct in6_addr ipi6_addr; 00046 } addr; 00047 } ortp_recv_addr_t; 00048 00049 typedef struct msgb 00050 { 00051 struct msgb *b_prev; 00052 struct msgb *b_next; 00053 struct msgb *b_cont; 00054 struct datab *b_datap; 00055 unsigned char *b_rptr; 00056 unsigned char *b_wptr; 00057 uint32_t reserved1; 00058 uint32_t reserved2; 00059 #if defined(ORTP_TIMESTAMP) 00060 struct timeval timestamp; 00061 #endif 00062 ortp_recv_addr_t recv_addr; 00063 } mblk_t; 00064 00065 00066 00067 typedef struct datab 00068 { 00069 unsigned char *db_base; 00070 unsigned char *db_lim; 00071 void (*db_freefn)(void*); 00072 int db_ref; 00073 } dblk_t; 00074 00075 typedef struct _queue 00076 { 00077 mblk_t _q_stopper; 00078 int q_mcount; /*number of packet in the q */ 00079 } queue_t; 00080 00081 #ifdef __cplusplus 00082 extern "C" { 00083 #endif 00084 00085 ORTP_PUBLIC void qinit(queue_t *q); 00086 00087 ORTP_PUBLIC void putq(queue_t *q, mblk_t *m); 00088 00089 ORTP_PUBLIC mblk_t * getq(queue_t *q); 00090 00091 ORTP_PUBLIC void insq(queue_t *q,mblk_t *emp, mblk_t *mp); 00092 00093 ORTP_PUBLIC void remq(queue_t *q, mblk_t *mp); 00094 00095 ORTP_PUBLIC mblk_t * peekq(queue_t *q); 00096 00097 /* remove and free all messages in the q */ 00098 #define FLUSHALL 0 00099 ORTP_PUBLIC void flushq(queue_t *q, int how); 00100 00101 ORTP_PUBLIC void mblk_init(mblk_t *mp); 00102 00103 ORTP_PUBLIC void mblk_meta_copy(const mblk_t *source, mblk_t *dest); 00104 00105 /* allocates a mblk_t, that points to a datab_t, that points to a buffer of size size. */ 00106 ORTP_PUBLIC mblk_t *allocb(int size, int unused); 00107 #define BPRI_MED 0 00108 00109 /* allocates a mblk_t, that points to a datab_t, that points to buf; buf will be freed using freefn */ 00110 ORTP_PUBLIC mblk_t *esballoc(uint8_t *buf, int size, int pri, void (*freefn)(void*) ); 00111 00112 /* frees a mblk_t, and if the datab ref_count is 0, frees it and the buffer too */ 00113 ORTP_PUBLIC void freeb(mblk_t *m); 00114 00115 /* frees recursively (follow b_cont) a mblk_t, and if the datab 00116 ref_count is 0, frees it and the buffer too */ 00117 ORTP_PUBLIC void freemsg(mblk_t *mp); 00118 00119 /* duplicates a mblk_t , buffer is not duplicated*/ 00120 ORTP_PUBLIC mblk_t *dupb(mblk_t *m); 00121 00122 /* duplicates a complex mblk_t, buffer is not duplicated */ 00123 ORTP_PUBLIC mblk_t *dupmsg(mblk_t* m); 00124 00125 /* returns the size of data of a message */ 00126 ORTP_PUBLIC int msgdsize(const mblk_t *mp); 00127 00128 /* concatenates all fragment of a complex message*/ 00129 ORTP_PUBLIC void msgpullup(mblk_t *mp,int len); 00130 00131 /* duplicates a single message, but with buffer included */ 00132 ORTP_PUBLIC mblk_t *copyb(mblk_t *mp); 00133 00134 /* duplicates a complex message with buffer included */ 00135 ORTP_PUBLIC mblk_t *copymsg(mblk_t *mp); 00136 00137 ORTP_PUBLIC mblk_t * appendb(mblk_t *mp, const char *data, int size, bool_t pad); 00138 ORTP_PUBLIC void msgappend(mblk_t *mp, const char *data, int size, bool_t pad); 00139 00140 ORTP_PUBLIC mblk_t *concatb(mblk_t *mp, mblk_t *newm); 00141 00142 #define qempty(q) (&(q)->_q_stopper==(q)->_q_stopper.b_next) 00143 #define qfirst(q) ((q)->_q_stopper.b_next!=&(q)->_q_stopper ? (q)->_q_stopper.b_next : NULL) 00144 #define qbegin(q) ((q)->_q_stopper.b_next) 00145 #define qlast(q) ((q)->_q_stopper.b_prev!=&(q)->_q_stopper ? (q)->_q_stopper.b_prev : NULL) 00146 #define qend(q,mp) ((mp)==&(q)->_q_stopper) 00147 #define qnext(q,mp) ((mp)->b_next) 00148 00149 typedef struct _msgb_allocator{ 00150 queue_t q; 00151 }msgb_allocator_t; 00152 00153 ORTP_PUBLIC void msgb_allocator_init(msgb_allocator_t *pa); 00154 ORTP_PUBLIC mblk_t *msgb_allocator_alloc(msgb_allocator_t *pa, int size); 00155 ORTP_PUBLIC void msgb_allocator_uninit(msgb_allocator_t *pa); 00156 00157 #ifdef __cplusplus 00158 } 00159 #endif 00160 00161 #endif
1.7.6.1