/src/opensips/parser/sdp/sdp.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * SDP parser interface |
3 | | * |
4 | | * Copyright (C) 2008 SOMA Networks, INC. |
5 | | * |
6 | | * This file is part of opensips, a free SIP server. |
7 | | * |
8 | | * opensips is free software; you can redistribute it and/or modify |
9 | | * it under the terms of the GNU General Public License as published by |
10 | | * the Free Software Foundation; either version 2 of the License, or |
11 | | * (at your option) any later version |
12 | | * |
13 | | * opensips is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU General Public License |
19 | | * along with this program; if not, write to the Free Software |
20 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | | * |
22 | | * |
23 | | * HISTORY: |
24 | | * -------- |
25 | | * 2007-09-09 osas: ported and enhanced sdp parsing functions from nathelper module |
26 | | * 2008-04-22 osas: integrated RFC4975 attributes - patch provided by Denis Bilenko (denik) |
27 | | * |
28 | | */ |
29 | | |
30 | | |
31 | | #ifndef SDP_H |
32 | | #define SDP_H |
33 | | |
34 | | #include "../msg_parser.h" |
35 | | #include "../../mem/mem.h" |
36 | | |
37 | | #define NO_HOLD 0 |
38 | 0 | #define RFC2543_HOLD 1 |
39 | 0 | #define RFC3264_HOLD 2 |
40 | | |
41 | | typedef struct sdp_attr { |
42 | | struct sdp_attr *next; |
43 | | str attribute; |
44 | | str value; |
45 | | } sdp_attr_t; |
46 | | |
47 | 0 | #define MAX_CUSTOM_ATTRS 16 |
48 | | typedef struct sdp_payload_attr { |
49 | | struct sdp_payload_attr *next; |
50 | | /**< payload index inside stream */ |
51 | | int payload_num; |
52 | | str rtp_payload; |
53 | | str rtp_enc; |
54 | | str rtp_clock; |
55 | | str rtp_params; |
56 | | str fmtp_string; |
57 | | str custom_attrs[MAX_CUSTOM_ATTRS]; |
58 | | int custom_attrs_size; |
59 | | /* payload pointing to this one via apt= |
60 | | * SEE RFC 4588 */ |
61 | | struct sdp_payload_attr* linked_payload; |
62 | | } sdp_payload_attr_t; |
63 | | |
64 | | typedef struct sdp_stream_cell { |
65 | | struct sdp_stream_cell *next; |
66 | | /**< body of the entire stream */ |
67 | | str body; |
68 | | /* c=<network type> <address type> <connection address> */ |
69 | | /**< connection address family: AF_INET/AF_INET6 */ |
70 | | int pf; |
71 | | /**< connection address */ |
72 | | str ip_addr; |
73 | | /**< stream index inside a session */ |
74 | | int stream_num; |
75 | | /**< flag indicating if this is an RTP stream */ |
76 | | int is_rtp; |
77 | | /**< flag indicating if this stream is on hold */ |
78 | | int is_on_hold; |
79 | | /* m=<media> <port> <transport> <payloads> */ |
80 | | str media; |
81 | | str port; |
82 | | str transport; |
83 | | str sendrecv_mode; |
84 | | str ptime; |
85 | | str payloads; |
86 | | /**< number of payloads inside a stream */ |
87 | | int payloads_num; |
88 | | /* b=<bwtype>:<bandwidth> */ |
89 | | /**< alphanumeric modifier giving the meaning of the <bandwidth> figure: |
90 | | CT - conference total; |
91 | | AS - application specific */ |
92 | | str bw_type; |
93 | | /**< The <bandwidth> is interpreted as kilobits per second by default */ |
94 | | str bw_width; |
95 | | /* RFC3605: Real Time Control Protocol (RTCP) attribute in |
96 | | * Session Description Protocol (SDP) */ |
97 | | /* a=rtcp: port [nettype space addrtype space connection-address] CRLF */ |
98 | | /**< RFC3605: rtcp attribute */ |
99 | | str rtcp_port; |
100 | | /**< RFC4975: path attribute */ |
101 | | str path; |
102 | | /**< RFC4975: max-size attribute */ |
103 | | str max_size; |
104 | | /**< RFC4975: accept-types attribute */ |
105 | | str accept_types; |
106 | | /**< RFC4975: accept-wrapped-types attribute */ |
107 | | str accept_wrapped_types; |
108 | | /**< fast access pointers to payloads */ |
109 | | struct sdp_payload_attr **p_payload_attr; |
110 | | struct sdp_payload_attr *payload_attr; |
111 | | struct sdp_attr *attr; |
112 | | } sdp_stream_cell_t; |
113 | | |
114 | | typedef struct sdp_session_cell { |
115 | | struct sdp_session_cell *next; |
116 | | /**< body of the entire session */ |
117 | | str body; |
118 | | /**< session index inside sdp */ |
119 | | int session_num; |
120 | | /**< the Content-Disposition header (for Content-Type:multipart/mixed) */ |
121 | | str cnt_disp; |
122 | | /* c=<network type> <address type> <connection address> */ |
123 | | /**< connection address family: AF_INET/AF_INET6 */ |
124 | | int pf; |
125 | | /**< connection address */ |
126 | | str ip_addr; |
127 | | /* o=<username> <session id> <version> <network type> <addr type> <addr> */ |
128 | | /**< origin address family: AF_INET/AF_INET6 */ |
129 | | int o_pf; |
130 | | /**< origin address */ |
131 | | str o_ip_addr; |
132 | | /* b=<bwtype>:<bandwidth> */ |
133 | | /**< alphanumeric modifier giving the meaning of the <bandwidth> figure: |
134 | | CT - conference total; |
135 | | AS - application specific */ |
136 | | str bw_type; |
137 | | /**< The <bandwidth> is interpreted as kilobits per second by default */ |
138 | | str bw_width; |
139 | | /**< number of streams inside a session */ |
140 | | int streams_num; |
141 | | struct sdp_stream_cell* streams; |
142 | | struct sdp_attr *attr; |
143 | | } sdp_session_cell_t; |
144 | | |
145 | | /** |
146 | | * Here we hold the head of the parsed sdp structure |
147 | | */ |
148 | | typedef struct sdp_info { |
149 | | int sessions_num; /**< number of SDP sessions */ |
150 | | int streams_num; /**< total number of streams for all SDP sessions */ |
151 | | struct sdp_session_cell *sessions; |
152 | | } sdp_info_t; |
153 | | |
154 | | |
155 | | /* |
156 | | * Parse SDP. |
157 | | */ |
158 | | sdp_info_t* parse_sdp(struct sip_msg* _m); |
159 | | int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, |
160 | | sdp_info_t* _sdp); |
161 | | |
162 | | /** |
163 | | * Get a session for the given sdp based on position inside SDP. |
164 | | */ |
165 | | sdp_session_cell_t* get_sdp_session(sdp_info_t* sdp, int session_num); |
166 | | |
167 | | /** |
168 | | * Get a stream for the given sdp based on positions inside SDP. |
169 | | */ |
170 | | sdp_stream_cell_t* get_sdp_stream(sdp_info_t* sdp, int session_num, |
171 | | int stream_num); |
172 | | |
173 | | /** |
174 | | * Get a payload from a stream based on payload. |
175 | | */ |
176 | | sdp_payload_attr_t* get_sdp_payload4payload(sdp_stream_cell_t *stream, str *rtp_payload); |
177 | | |
178 | | /** |
179 | | * Get a payload from a stream based on position. |
180 | | */ |
181 | | sdp_payload_attr_t* get_sdp_payload4index(sdp_stream_cell_t *stream, int index); |
182 | | |
183 | | /** |
184 | | * Free all memory associated with parsed structure. |
185 | | */ |
186 | | void free_sdp_content(sdp_info_t* sdp); |
187 | | /** |
188 | | * Free all memory associated with parsed structure. |
189 | | * |
190 | | * Note: this will also pkg_free() the given pointer |
191 | | */ |
192 | | static inline void free_sdp(sdp_info_t* sdp) |
193 | 0 | { |
194 | 0 | free_sdp_content(sdp); |
195 | 0 | pkg_free(sdp); |
196 | 0 | } Unexecuted instantiation: fuzz_msg_parser.c:free_sdp Unexecuted instantiation: sdp_ops.c:free_sdp Unexecuted instantiation: sdp.c:free_sdp Unexecuted instantiation: sdp_helpr_funcs.c:free_sdp Unexecuted instantiation: transformations.c:free_sdp |
197 | | |
198 | | /** |
199 | | * Print the content of the given sdp_info structure. |
200 | | * |
201 | | * Note: only for debug purposes. |
202 | | */ |
203 | | void print_sdp(sdp_info_t* sdp, int log_level); |
204 | | /** |
205 | | * Print the content of the given sdp_session structure. |
206 | | * |
207 | | * Note: only for debug purposes. |
208 | | */ |
209 | | void print_sdp_session(sdp_session_cell_t* sdp_session, int log_level); |
210 | | /** |
211 | | * Print the content of the given sdp_stream structure. |
212 | | * |
213 | | * Note: only for debug purposes. |
214 | | */ |
215 | | void print_sdp_stream(sdp_stream_cell_t *stream, int log_level); |
216 | | |
217 | | /** |
218 | | * Creates and initialize a new sdp_info structure |
219 | | */ |
220 | | static inline sdp_info_t* new_sdp(void) |
221 | 0 | { |
222 | 0 | sdp_info_t* sdp; |
223 | |
|
224 | 0 | sdp = (sdp_info_t*)pkg_malloc(sizeof(sdp_info_t)); |
225 | 0 | if (sdp == NULL) { |
226 | 0 | LM_ERR("No memory left\n"); |
227 | 0 | return NULL; |
228 | 0 | } |
229 | 0 | memset( sdp, 0, sizeof(sdp_info_t)); |
230 | |
|
231 | 0 | return sdp; |
232 | 0 | } Unexecuted instantiation: fuzz_msg_parser.c:new_sdp Unexecuted instantiation: sdp_ops.c:new_sdp Unexecuted instantiation: sdp.c:new_sdp Unexecuted instantiation: sdp_helpr_funcs.c:new_sdp Unexecuted instantiation: transformations.c:new_sdp |
233 | | |
234 | | |
235 | | /** |
236 | | * Get the first SDP from the body |
237 | | */ |
238 | | static inline sdp_info_t* get_sdp(struct sip_msg* _m) |
239 | 0 | { |
240 | 0 | struct body_part *p; |
241 | 0 | if (_m->body) { |
242 | 0 | for( p=&_m->body->first ; p ; p=p->next) |
243 | 0 | if (p->mime==((TYPE_APPLICATION<<16)+SUBTYPE_SDP) |
244 | 0 | && p->parsed ) |
245 | 0 | return (sdp_info_t*)p->parsed; |
246 | 0 | } |
247 | 0 | return NULL; |
248 | 0 | } Unexecuted instantiation: fuzz_msg_parser.c:get_sdp Unexecuted instantiation: sdp_ops.c:get_sdp Unexecuted instantiation: sdp.c:get_sdp Unexecuted instantiation: sdp_helpr_funcs.c:get_sdp Unexecuted instantiation: transformations.c:get_sdp |
249 | | |
250 | | #endif /* SDP_H */ |