cleanup: remove NULL checks before free() all over the code
[mplayer/glamo.git] / stream / freesdp / parser.c
blob0774ce84f88e84847641de778be9a622dccaa386
1 /*
2 This file is part of FreeSDP
3 Copyright (C) 2001,2002,2003 Federico Montesino Pouzols <fedemp@altern.org>
5 FreeSDP is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 Benjamin Zores, (C) 2006
20 added support in parser for the a=control: lines.
21 added support in parser for the a=range: lines.
24 /**
25 * @file parser.c
27 * @short Parsing module implementation.
29 * This file implements the parsing routine <code>fsdp_parse</code>
30 * and the <code>fsdp_get_xxxx</code> routines that allow to get the
31 * session properties from a session description object build through
32 * the application of <code>fsdp_parse</code> to a textual SDP session
33 * description.
34 **/
36 #include "parserpriv.h"
38 /**
39 * \brief find the start of the next line
40 * \param c pointer to current position in string
41 * \return pointer to start of next line or NULL if illegal (i.e.
42 * a '\r' is not followed by a '\n'
44 static const char *next_line(const char *c) {
45 c += strcspn(c, "\n\r");
46 if (*c == 0) return c;
47 if (*c == '\r') c++;
48 if (*c == '\n')
49 return c + 1;
50 return NULL;
53 /**
54 * Moves the <code>c<code> pointer up to the beginning of the next
55 * line.
57 * @param c char pointer to pointer
58 * @retval FSDPE_ILLEGAL_CHARACTER, when an illegal '\r' character
59 * (not followed by a '\n') is found, returns
61 #define NEXT_LINE(c) do { if (!(c = next_line(c))) return FSDPE_ILLEGAL_CHARACTER; } while (0);
63 fsdp_error_t
64 fsdp_parse (const char *text_description, fsdp_description_t * dsc)
66 fsdp_error_t result;
67 const char *p = text_description, *p2;
68 unsigned int index, j;
69 /* temps for sscanf */
70 const unsigned int TEMPCHARS = 6;
71 char fsdp_buf[TEMPCHARS][MAXSHORTFIELDLEN];
72 char longfsdp_buf[MAXLONGFIELDLEN];
73 const unsigned int TEMPINTS = 2;
74 unsigned long int wuint[TEMPINTS];
76 if ((NULL == text_description) || (NULL == dsc))
77 return FSDPE_INVALID_PARAMETER;
79 /***************************************************************************/
80 /* A) parse session-level description */
81 /***************************************************************************/
83 /* `v=' line (protocol version) */
84 /* according to the RFC, only `v=0' is valid */
85 if (sscanf (p, "v=%1lu", &wuint[0]))
87 if (wuint[0] != 0)
88 return FSDPE_INVALID_VERSION;
90 else
92 return FSDPE_MISSING_VERSION;
94 NEXT_LINE (p);
96 /* `o=' line (owner/creator and session identifier) */
97 /* o=<username> <session id> <version> <network type> <address type>
98 <address> */
99 if (!strncmp (p, "o=", 2))
101 p += 2;
102 /* note that the following max lengths may vary in the future and
103 are quite arbitary */
104 if (sscanf
106 "%" MSFLENS "[\x21-\xFF] %" MSFLENS "[0-9] %" MSFLENS
107 "[0-9] %2s %3s %" MSFLENS "s", fsdp_buf[0], fsdp_buf[1],
108 fsdp_buf[2], fsdp_buf[3], fsdp_buf[4], fsdp_buf[5]) != 6)
109 return FSDPE_INVALID_OWNER;
110 dsc->o_username = strdup (fsdp_buf[0]);
111 dsc->o_session_id = strdup (fsdp_buf[1]);
112 dsc->o_announcement_version = strdup (fsdp_buf[2]);
113 if (!strncmp (fsdp_buf[3], "IN", 2))
115 dsc->o_network_type = FSDP_NETWORK_TYPE_INET;
116 if (!strncmp (fsdp_buf[4], "IP4", 3))
117 dsc->o_address_type = FSDP_ADDRESS_TYPE_IPV4;
118 else if (!strncmp (fsdp_buf[4], "IP6", 3))
119 dsc->o_address_type = FSDP_ADDRESS_TYPE_IPV6;
120 else
121 return FSDPE_INVALID_OWNER;
123 else
125 return FSDPE_INVALID_OWNER;
127 /* TODO? check valid unicast address/FQDN */
128 dsc->o_address = strdup (fsdp_buf[5]);
130 else
132 return FSDPE_MISSING_OWNER;
134 NEXT_LINE (p);
136 /* `s=' line (session name) -note that the name string cannot be empty */
137 /* s=<session name> */
138 if (!strncmp (p, "s=", 2))
140 if (sscanf (p, "s=%" MLFLENS "[^\r\n]", longfsdp_buf) < 1)
141 return FSDPE_EMPTY_NAME;
142 dsc->s_name = strdup (longfsdp_buf);
144 else
146 return FSDPE_MISSING_NAME;
148 NEXT_LINE (p);
150 /* `i=' line (session information) [optional] */
151 /* i=<session description> */
152 if (!strncmp (p, "i=", 2)
153 && sscanf (p, "i=%" MLFLENS "[^\r\n]", longfsdp_buf))
155 dsc->i_information = strdup (longfsdp_buf);
156 NEXT_LINE (p);
158 else
160 /* (optional) information absent */
163 /* `u=' line (URI of description) [optional] */
164 /* u=<URI> */
165 if (!strncmp (p, "u=", 2)
166 && sscanf (p, "u=%" MLFLENS "[^\r\n]", longfsdp_buf))
168 /* TODO? check valid uri */
169 dsc->u_uri = strdup (longfsdp_buf);
170 NEXT_LINE (p);
172 else
174 /* (optional) uri absent */
177 /* `e=' lines (email address) [zero or more] */
178 /* e=<email address> */
179 p2 = p;
180 j = 0;
181 while (!strncmp (p2, "e=", 2))
183 /* First, count how many emails are there */
184 j++;
185 NEXT_LINE (p2);
187 dsc->emails_count = j;
188 if (dsc->emails_count > 0)
190 /* Then, build the array of emails */
191 dsc->emails = calloc (j, sizeof (const char *));
192 for (j = 0; j < dsc->emails_count; j++)
194 sscanf (p, "e=%" MLFLENS "[^\r\n]", longfsdp_buf);
195 /* TODO? check valid email-address. */
196 dsc->emails[j] = strdup (longfsdp_buf);
197 NEXT_LINE (p);
201 /* `p=' lines (phone number) [zero or more] */
202 /* p=<phone number> */
203 j = 0;
204 /* assert ( p2 == p ); */
205 while (!strncmp (p2, "p=", 2))
207 j++;
208 NEXT_LINE (p2);
210 dsc->phones_count = j;
211 if (dsc->phones_count > 0)
213 dsc->phones = calloc (j, sizeof (const char *));
214 for (j = 0; j < dsc->phones_count; j++)
216 sscanf (p, "p=%" MLFLENS "[^\r\n]", longfsdp_buf);
217 /* TODO? check valid phone-number. */
218 dsc->phones[j] = strdup (longfsdp_buf);
219 NEXT_LINE (p);
223 /* `c=' line (connection information - not required if included in all media) [optional] */
224 /* c=<network type> <address type> <connection address> */
225 result = fsdp_parse_c (&p, &(dsc->c_network_type), &(dsc->c_address_type),
226 &(dsc->c_address));
227 if (FSDPE_OK != result)
228 return result;
230 /* `b=' lines (bandwidth information) [optional] */
231 /* b=<modifier>:<bandwidth-value> */
232 result =
233 fsdp_parse_b (&p, &(dsc->bw_modifiers), &(dsc->bw_modifiers_count));
234 if (FSDPE_OK != result)
235 return result;
237 /* A.1) Time descriptions: */
239 /* `t=' lines (time the session is active) [1 or more] */
240 /* t=<start time> <stop time> */
241 j = 0;
242 p2 = p;
243 while (!strncmp (p2, "t=", 2))
245 j++;
246 NEXT_LINE (p2);
247 while (!strncmp (p2, "r=", 2))
248 NEXT_LINE (p2);
250 dsc->time_periods_count = j;
251 if (dsc->time_periods_count == 0)
252 return FSDPE_MISSING_TIME;
253 dsc->time_periods = calloc (dsc->time_periods_count,
254 sizeof (fsdp_time_period_t *));
255 index = 0;
256 for (j = 0; j < dsc->time_periods_count; j++)
258 unsigned int h = 0;
259 if (sscanf (p, "t=%10lu %10lu", &wuint[0], &wuint[1]) != 2)
261 /* not all periods have been successfully parsed */
262 dsc->time_periods_count = j;
263 return FSDPE_INVALID_TIME;
265 dsc->time_periods[j] = calloc (1, sizeof (fsdp_time_period_t));
267 /* convert from NTP to time_t time */
268 if (wuint[0] != 0)
269 wuint[0] -= NTP_EPOCH_OFFSET;
270 if (wuint[1] != 0)
271 wuint[1] -= NTP_EPOCH_OFFSET;
272 dsc->time_periods[j]->start = wuint[0];
273 dsc->time_periods[j]->stop = wuint[1];
274 NEXT_LINE (p);
276 /* `r' lines [zero or more repeat times for each t=] */
277 /*r=<repeat interval> <active duration> <list of offsets from
278 start-time> */
279 p2 = p;
280 while (!strncmp (p2, "r=", 2))
282 h++;
283 NEXT_LINE (p2);
285 dsc->time_periods[j]->repeats_count = h;
286 if (h > 0)
288 unsigned int index2 = 0;
289 dsc->time_periods[j]->repeats =
290 calloc (h, sizeof (fsdp_repeat_t *));
291 for (h = 0; h < dsc->time_periods[j]->repeats_count; h++)
294 get_repeat_values(p,&(dsc->time_periods[index].repeats[index2]));
295 fsdp_error_t get_repeat_values (const char *r, fsdp_repeat_t
296 *repeat);
298 if (sscanf (p, "r=%10s %10s %" MLFLENS "[^\r\n]",
299 fsdp_buf[0], fsdp_buf[1], longfsdp_buf) == 3)
301 fsdp_repeat_t *repeat;
302 dsc->time_periods[j]->repeats[h] =
303 calloc (1, sizeof (fsdp_repeat_t));
304 repeat = dsc->time_periods[j]->repeats[h];
305 /* get interval, duration and list of offsets */
306 result =
307 fsdp_repeat_time_to_uint (fsdp_buf[0],
308 &(repeat->interval));
309 if (result == FSDPE_OK)
311 result =
312 fsdp_repeat_time_to_uint (fsdp_buf[1],
313 &(repeat->duration));
314 if (result == FSDPE_OK)
316 unsigned int k = 1;
317 const char *i = longfsdp_buf;
318 while (NULL != (i = strchr (i, ' ')))
320 k++;
321 if (NULL != i)
322 i++;
324 repeat->offsets_count = k;
325 repeat->offsets = calloc (k, sizeof (time_t));
326 i = longfsdp_buf;
327 for (k = 0;
328 (k < repeat->offsets_count)
329 && (result == FSDPE_OK); k++)
331 result =
332 fsdp_repeat_time_to_uint (i,
333 &(repeat->
334 offsets[k]));
335 i = strchr (i, ' ');
336 if (NULL != i)
337 i++;
339 if (k < repeat->offsets_count)
341 /* there where invalid repeat offsets */
342 dsc->time_periods[j]->repeats_count = k;
343 return FSDPE_INVALID_REPEAT;
347 if (result != FSDPE_OK)
349 /* not all repeats have been succesfully parsed */
350 dsc->time_periods[j]->repeats_count = h;
351 return FSDPE_INVALID_REPEAT;
353 NEXT_LINE (p);
355 else
357 /* not all repeats have been succesfully parsed */
358 dsc->time_periods[j]->repeats_count = h;
359 return FSDPE_INVALID_REPEAT;
361 index2++;
366 /* `z=' line (time zone adjustments) [zero or more] */
367 /* z=<adjustment time> <offset> <adjustment time> <offset> .... */
368 if (!strncmp (p, "z=", 2))
370 if (sscanf (p, "z=%" MLFLENS "[^\r\n]", longfsdp_buf))
372 /* TODO: guess how many pairs are there and process them */
373 dsc->timezone_adj = strdup (longfsdp_buf);
374 NEXT_LINE (p);
376 else
378 return FSDPE_INVALID_TIMEZONE;
382 /* `k=' line (encryption key) [optional] */
383 /* k=<method>
384 k=<method>:<encryption key> */
385 result = fsdp_parse_k (&p, &(dsc->k_encryption_method),
386 &(dsc->k_encryption_content));
387 if (result != FSDPE_OK)
388 return result;
390 /* A.2) Attributes */
391 /* `a=' lines (session attribute) [0 or more] */
392 /* a=<attribute>
393 a=<attribute>:<value> */
394 while (!strncmp (p, "a=", 2))
396 /* The "9" length specifier of the first string is subject to
397 changes */
398 if (sscanf
399 (p, "a=%9[^:\r\n]:%" MSFLENS "[^\r\n]", fsdp_buf[0],
400 fsdp_buf[1]) == 2)
402 /* session-level value attributes */
403 if (!strncmp (fsdp_buf[0], "cat", 3))
404 dsc->a_category = strdup (fsdp_buf[1]);
405 else if (!strncmp (fsdp_buf[0], "keywds", 6))
406 dsc->a_keywords = strdup (fsdp_buf[1]);
407 else if (!strncmp (fsdp_buf[0], "tool", 4))
408 dsc->a_keywords = strdup (fsdp_buf[1]);
409 else if (!strncmp (fsdp_buf[0], "rtpmap", 6))
410 fsdp_parse_rtpmap (&(dsc->a_rtpmaps),
411 &(dsc->a_rtpmaps_count), fsdp_buf[1]);
412 else if (!strncmp (fsdp_buf[0], "type", 4))
414 if (!strncmp (fsdp_buf[1], "broadcast", 9))
415 dsc->a_type = FSDP_SESSION_TYPE_BROADCAST;
416 else if (!strncmp (fsdp_buf[1], "meeting", 7))
417 dsc->a_type = FSDP_SESSION_TYPE_MEETING;
418 else if (!strncmp (fsdp_buf[1], "moderated", 9))
419 dsc->a_type = FSDP_SESSION_TYPE_MODERATED;
420 else if (!strncmp (fsdp_buf[1], "test", 4))
421 dsc->a_type = FSDP_SESSION_TYPE_TEST;
422 else if (!strncmp (fsdp_buf[1], "H332", 4))
423 dsc->a_type = FSDP_SESSION_TYPE_H332;
424 else
425 return FSDPE_INVALID_SESSION_TYPE;
427 else if (!strncmp (fsdp_buf[0], "charset", 7))
428 dsc->a_charset = strdup (fsdp_buf[1]);
429 else if (!strncmp (fsdp_buf[0], "sdplang", 7))
431 if (NULL == dsc->a_sdplangs)
433 dsc->a_sdplangs_count = 0;
434 dsc->a_sdplangs =
435 calloc (SDPLANGS_MAX_COUNT, sizeof (char *));
437 if (dsc->a_sdplangs_count < SDPLANGS_MAX_COUNT)
439 dsc->a_sdplangs[dsc->a_sdplangs_count] =
440 strdup (fsdp_buf[1]);
441 dsc->a_sdplangs_count++;
444 else if (!strncmp (fsdp_buf[0], "lang", 4))
446 if (NULL == dsc->a_langs)
448 dsc->a_langs_count = 0;
449 dsc->a_langs = calloc (SDPLANGS_MAX_COUNT, sizeof (char *));
451 if (dsc->a_langs_count < SDPLANGS_MAX_COUNT)
453 dsc->a_langs[dsc->a_langs_count] = strdup (fsdp_buf[1]);
454 dsc->a_langs_count++;
457 else if (!strncmp (fsdp_buf[0], "control", 7))
459 if (NULL == dsc->a_controls)
461 dsc->a_controls_count = 0;
462 dsc->a_controls =
463 calloc (SDPCONTROLS_MAX_COUNT, sizeof (char *));
465 if (dsc->a_controls_count < SDPCONTROLS_MAX_COUNT)
467 dsc->a_controls[dsc->a_controls_count] =
468 strdup (fsdp_buf[1]);
469 dsc->a_controls_count++;
472 else if (!strncmp (fsdp_buf[0], "range", 5))
474 free (dsc->a_range);
475 dsc->a_range = strdup (fsdp_buf[1]);
477 else
479 /* ignore unknown attributes, but provide access to them */
480 *longfsdp_buf = '\0';
481 strncat (longfsdp_buf, fsdp_buf[0], MAXLONGFIELDLEN-1);
482 strncat (longfsdp_buf, ":", MAXLONGFIELDLEN-strlen(longfsdp_buf)-1);
483 strncat (longfsdp_buf, fsdp_buf[1], MAXLONGFIELDLEN-strlen(longfsdp_buf)-1);
484 if (NULL == dsc->unidentified_attributes)
486 dsc->unidentified_attributes_count = 0;
487 dsc->unidentified_attributes =
488 calloc (UNIDENTIFIED_ATTRIBUTES_MAX_COUNT,
489 sizeof (char *));
491 if (dsc->unidentified_attributes_count <
492 UNIDENTIFIED_ATTRIBUTES_MAX_COUNT)
494 dsc->unidentified_attributes
495 [dsc->unidentified_attributes_count] =
496 strdup (longfsdp_buf);
497 dsc->unidentified_attributes_count++;
500 NEXT_LINE (p);
502 else if (sscanf (p, "a=%20s", fsdp_buf[0]) == 1)
504 /* session-level property attributes */
505 if (!strncmp (fsdp_buf[0], "recvonly", 8))
506 dsc->a_sendrecv_mode = FSDP_SENDRECV_RECVONLY;
507 else if (!strncmp (fsdp_buf[0], "sendonly", 8))
508 dsc->a_sendrecv_mode = FSDP_SENDRECV_SENDONLY;
509 else if (!strncmp (fsdp_buf[0], "inactive", 8))
510 dsc->a_sendrecv_mode = FSDP_SENDRECV_INACTIVE;
511 else if (!strncmp (fsdp_buf[0], "sendrecv", 8))
512 dsc->a_sendrecv_mode = FSDP_SENDRECV_SENDRECV;
513 else
515 /* ignore unknown attributes, but provide access to them */
516 *longfsdp_buf = '\0';
517 strncat (longfsdp_buf, fsdp_buf[0], MAXLONGFIELDLEN-1);
518 if (NULL == dsc->unidentified_attributes)
520 dsc->unidentified_attributes_count = 0;
521 dsc->unidentified_attributes =
522 calloc (UNIDENTIFIED_ATTRIBUTES_MAX_COUNT,
523 sizeof (char *));
525 if (dsc->unidentified_attributes_count <
526 UNIDENTIFIED_ATTRIBUTES_MAX_COUNT)
528 dsc->unidentified_attributes
529 [dsc->unidentified_attributes_count] =
530 strdup (longfsdp_buf);
531 dsc->unidentified_attributes_count++;
534 NEXT_LINE (p);
536 else
537 return FSDPE_INVALID_ATTRIBUTE;
540 /***************************************************************************/
541 /* B) parse media-level descriptions */
542 /***************************************************************************/
543 p2 = p;
544 j = 0;
545 while ((*p2 != '\0') && !strncmp (p2, "m=", 2))
547 char c;
548 j++;
549 NEXT_LINE (p2);
550 while (sscanf (p2, "%c=", &c) == 1)
552 if (c == 'i' || c == 'c' || c == 'b' || c == 'k' || c == 'a')
554 NEXT_LINE (p2);
556 else if (c == 'm')
558 break;
560 else
562 return FSDPE_INVALID_LINE;
566 dsc->media_announcements_count = j;
567 if (dsc->media_announcements_count == 0)
570 /*return FSDPE_MISSING_MEDIA; */
572 else
573 { /* dsc->media_announcements_count > 0 */
574 dsc->media_announcements =
575 calloc (j, sizeof (fsdp_media_announcement_t *));
576 for (j = 0; j < dsc->media_announcements_count; j++)
578 fsdp_media_announcement_t *media = NULL;
579 /* `m=' line (media name, transport address and format list) */
580 /* m=<media> <port> <transport> <fmt list> */
581 /* The max. string lengths are subject to change */
582 if (sscanf (p, "m=%11s %8s %7s %" MLFLENS "[^\r\n]",
583 fsdp_buf[0], fsdp_buf[1], fsdp_buf[2],
584 longfsdp_buf) != 4)
586 return FSDPE_INVALID_MEDIA;
588 else
590 dsc->media_announcements[j] =
591 calloc (1, sizeof (fsdp_media_announcement_t));
592 media = dsc->media_announcements[j];
593 if (!strncmp (fsdp_buf[0], "audio", 5))
594 media->media_type = FSDP_MEDIA_AUDIO;
595 else if (!strncmp (fsdp_buf[0], "video", 5))
596 media->media_type = FSDP_MEDIA_VIDEO;
597 else if (!strncmp (fsdp_buf[0], "application", 11))
598 media->media_type = FSDP_MEDIA_APPLICATION;
599 else if (!strncmp (fsdp_buf[0], "data", 4))
600 media->media_type = FSDP_MEDIA_DATA;
601 else if (!strncmp (fsdp_buf[0], "control", 7))
602 media->media_type = FSDP_MEDIA_CONTROL;
603 else
604 return FSDPE_UNKNOWN_MEDIA_TYPE;
605 { /* try to get port specification as port/number */
606 char *slash;
607 if ((slash = strchr (fsdp_buf[1], '/')))
609 *slash = '\0';
610 slash++;
611 media->port = strtol (fsdp_buf[1], NULL, 10);
612 media->port_count = strtol (slash, NULL, 10);
614 else
616 media->port = strtol (fsdp_buf[1], NULL, 10);
617 media->port_count = 0;
620 if (!strncmp (fsdp_buf[2], "RTP/AVP", 7))
621 media->transport = FSDP_TP_RTP_AVP;
622 else if (!strncmp (fsdp_buf[2], "udp", 3))
623 media->transport = FSDP_TP_UDP;
624 else if (!strncmp (fsdp_buf[2], "TCP", 3))
625 media->transport = FSDP_TP_TCP;
626 else if (!strncmp (fsdp_buf[2], "UDPTL", 5))
627 media->transport = FSDP_TP_UDPTL;
628 else if (!strncmp (fsdp_buf[2], "vat", 3))
629 media->transport = FSDP_TP_VAT;
630 else if (!strncmp (fsdp_buf[2], "rtp", 3))
631 media->transport = FSDP_TP_OLD_RTP;
632 else
633 return FSDPE_UNKNOWN_MEDIA_TRANSPORT;
635 unsigned int k = 0;
636 char *s = longfsdp_buf;
637 while (NULL != (s = strchr (s, ' ')))
639 k++;
640 if (NULL != s)
641 s++;
643 k++; /* when there is no space left, count the last format */
644 media->formats_count = k;
645 media->formats = calloc (k, sizeof (char *));
646 s = longfsdp_buf;
647 for (k = 0; k < media->formats_count; k++)
649 char *space = strchr (s, ' ');
650 if (NULL != space)
651 *space = '\0';
652 media->formats[k] = strdup (s);
653 s = space + 1;
656 NEXT_LINE (p);
659 /* `i=' line (media title) [optional] */
660 /* i=<media title> */
661 if (!strncmp (p, "i=", 2)
662 && sscanf (p, "i=%" MLFLENS "[^\r\n]", longfsdp_buf))
664 media->i_title = strdup (longfsdp_buf);
665 NEXT_LINE (p);
667 else
669 /* (optional) information absent */
672 /* `c=' line (connection information - overrides session-level
673 line) [optional if provided at session-level] */
674 /* c=<network type> <address type> <connection address> */
675 result = fsdp_parse_c (&p, &(media->c_network_type),
676 &(media->c_address_type),
677 &(media->c_address));
678 if (result != FSDPE_OK)
679 return result;
681 /* `b=' lines (bandwidth information) [optional] */
682 /* b=<modifier>:<bandwidth-value> */
683 result = fsdp_parse_b (&p, &(media->bw_modifiers),
684 &(media->bw_modifiers_count));
685 if (FSDPE_OK != result)
686 return result;
688 /* `k=' line (encryption key) [optional] */
689 /* k=<method>
690 k=<method>:<encryption key> */
691 result = fsdp_parse_k (&p, &(media->k_encryption_method),
692 &(media->k_encryption_content));
693 if (result != FSDPE_OK)
694 return result;
696 /* B.1) Attributes */
698 /* `a=' lines (zero or more media attribute lines) [optional] */
699 /* a=<attribute>
700 a=<attribute>:<value> */
701 while (!strncmp (p, "a=", 2))
703 if (sscanf
704 (p, "a=%9[^:\r\n]:%" MLFLENS "[^\r\n]", fsdp_buf[0],
705 longfsdp_buf) == 2)
707 /* media-level value attributes */
708 if (!strncmp (fsdp_buf[0], "ptime", 5))
709 media->a_ptime = strtoul (longfsdp_buf, NULL, 10);
710 else if (!strncmp (fsdp_buf[0], "maxptime", 8))
711 media->a_maxptime = strtoul (longfsdp_buf, NULL, 10);
712 else if (!strncmp (fsdp_buf[0], "rtpmap", 6))
713 fsdp_parse_rtpmap (&(media->a_rtpmaps),
714 &(media->a_rtpmaps_count),
715 longfsdp_buf);
716 else if (!strncmp (fsdp_buf[0], "orient", 6))
718 if (!strncmp (longfsdp_buf, "portrait", 8))
719 media->a_orient = FSDP_ORIENT_PORTRAIT;
720 else if (!strncmp (longfsdp_buf, "landscape", 9))
721 media->a_orient = FSDP_ORIENT_LANDSCAPE;
722 else if (!strncmp (longfsdp_buf, "seascape", 9))
723 media->a_orient = FSDP_ORIENT_SEASCAPE;
725 else if (!strncmp (fsdp_buf[0], "sdplang", 7))
727 if (NULL == dsc->a_sdplangs)
729 media->a_sdplangs_count = 0;
730 media->a_sdplangs =
731 calloc (SDPLANGS_MAX_COUNT, sizeof (char *));
733 if (media->a_sdplangs_count < SDPLANGS_MAX_COUNT)
735 media->a_sdplangs[dsc->a_sdplangs_count] =
736 strdup (longfsdp_buf);
737 media->a_sdplangs_count++;
740 else if (!strncmp (fsdp_buf[0], "lang", 4))
742 if (NULL == dsc->a_langs)
744 media->a_langs_count = 0;
745 media->a_langs =
746 calloc (SDPLANGS_MAX_COUNT, sizeof (char *));
748 if (media->a_langs_count < SDPLANGS_MAX_COUNT)
750 media->a_langs[dsc->a_langs_count] =
751 strdup (longfsdp_buf);
752 media->a_langs_count++;
755 else if (!strncmp (fsdp_buf[0], "control", 7))
757 if (NULL == media->a_controls)
759 media->a_controls_count = 0;
760 media->a_controls =
761 calloc (SDPCONTROLS_MAX_COUNT, sizeof (char *));
763 if (media->a_controls_count < SDPCONTROLS_MAX_COUNT)
765 media->a_controls[media->a_controls_count] =
766 strdup (longfsdp_buf);
767 media->a_controls_count++;
770 else if (!strncmp (fsdp_buf[0], "range", 5))
772 free (media->a_range);
773 media->a_range = strdup (fsdp_buf[1]);
775 else if (!strncmp (fsdp_buf[0], "framerate", 9))
776 media->a_framerate = strtod (longfsdp_buf, NULL);
777 else if (!strncmp (fsdp_buf[0], "fmtp", 4))
779 if (NULL == media->a_fmtps)
781 media->a_fmtps_count = 0;
782 media->a_fmtps =
783 calloc (SDPLANGS_MAX_COUNT, sizeof (char *));
785 if (media->a_fmtps_count < SDPLANGS_MAX_COUNT)
787 media->a_fmtps[media->a_fmtps_count] =
788 strdup (longfsdp_buf);
789 media->a_fmtps_count++;
792 else if (!strncmp (fsdp_buf[0], "rtcp", 4))
794 int opts = 0;
795 /* rtcp attribute: a=rtcp:<port> <nettype> <addrtype> <address> */
796 opts =
797 sscanf (longfsdp_buf, "%lu %2s %3s %" MSFLENS "s",
798 &wuint[0], fsdp_buf[0], fsdp_buf[1],
799 fsdp_buf[2]);
800 if (opts >= 1)
802 media->a_rtcp_port = wuint[0];
803 if (opts >= 2)
805 if (!strncmp (fsdp_buf[0], "IN", 2))
807 media->a_rtcp_network_type =
808 FSDP_NETWORK_TYPE_INET;
809 } /* else
810 ; TODO: define error code? */
811 if (opts >= 3)
813 if (!strncmp (fsdp_buf[1], "IP4", 3))
814 media->a_rtcp_address_type =
815 FSDP_ADDRESS_TYPE_IPV4;
816 else if (!strncmp (fsdp_buf[1], "IP6", 3))
817 media->a_rtcp_address_type =
818 FSDP_ADDRESS_TYPE_IPV6;
819 else
820 return FSDPE_INVALID_CONNECTION_NETTYPE;
821 /*add specific code? */
822 if (opts >= 4)
823 media->a_rtcp_address =
824 strdup (fsdp_buf[2]);
829 else
831 /* ignore unknown attributes, but provide access to them */
832 *fsdp_buf[1] = '\0';
833 strncat (fsdp_buf[1], fsdp_buf[0], MAXSHORTFIELDLEN-1);
834 strncat (fsdp_buf[1], ":", MAXSHORTFIELDLEN-strlen(fsdp_buf[1])-1);
835 strncat (fsdp_buf[1], longfsdp_buf, MAXSHORTFIELDLEN-strlen(fsdp_buf[1])-1);
836 if (NULL == media->unidentified_attributes)
838 media->unidentified_attributes_count = 0;
839 media->unidentified_attributes =
840 calloc (UNIDENTIFIED_ATTRIBUTES_MAX_COUNT,
841 sizeof (char *));
843 if (media->unidentified_attributes_count <
844 UNIDENTIFIED_ATTRIBUTES_MAX_COUNT)
846 media->unidentified_attributes
847 [media->unidentified_attributes_count] =
848 strdup (fsdp_buf[1]);
849 media->unidentified_attributes_count++;
852 NEXT_LINE (p);
854 else if (sscanf (p, "a=%8s", fsdp_buf[0]) == 1)
856 /* media-level property attributes */
857 if (!strncmp (fsdp_buf[0], "recvonly", 8))
858 media->a_sendrecv_mode = FSDP_SENDRECV_RECVONLY;
859 else if (!strncmp (fsdp_buf[0], "sendonly", 8))
860 media->a_sendrecv_mode = FSDP_SENDRECV_SENDONLY;
861 else if (!strncmp (fsdp_buf[0], "inactive", 8))
862 media->a_sendrecv_mode = FSDP_SENDRECV_INACTIVE;
863 else if (!strncmp (fsdp_buf[0], "sendrecv", 8))
864 media->a_sendrecv_mode = FSDP_SENDRECV_SENDRECV;
865 else
867 /* ignore unknown attributes, but provide access to them */
868 *longfsdp_buf = '\0';
869 strncat (longfsdp_buf, fsdp_buf[0], MAXLONGFIELDLEN-1);
870 if (NULL == media->unidentified_attributes)
872 media->unidentified_attributes_count = 0;
873 media->unidentified_attributes =
874 calloc (UNIDENTIFIED_ATTRIBUTES_MAX_COUNT,
875 sizeof (char *));
877 if (media->unidentified_attributes_count <
878 UNIDENTIFIED_ATTRIBUTES_MAX_COUNT)
880 media->unidentified_attributes
881 [media->unidentified_attributes_count] =
882 strdup (longfsdp_buf);
883 media->unidentified_attributes_count++;
886 NEXT_LINE (p);
888 else
889 return FSDPE_INVALID_ATTRIBUTE;
891 } /* end of for */
894 /* Check c= has been given at session level or at media level for
895 all media */
896 if (NULL == dsc->c_address.address)
898 unsigned int c;
899 for (c = 0; c < dsc->media_announcements_count; c++)
900 if (NULL == dsc->media_announcements[c]->c_address.address)
901 return FSDPE_MISSING_CONNECTION_INFO;
904 /* finish */
905 if (*p == '\0')
906 return FSDPE_OK;
907 else
908 return FSDPE_OVERFILLED;
911 static fsdp_error_t
912 fsdp_parse_c (const char **p, fsdp_network_type_t * ntype,
913 fsdp_address_type_t * atype,
914 fsdp_connection_address_t * address)
916 const unsigned int TEMPCHARS = 3;
917 char fsdp_buf[TEMPCHARS][MAXSHORTFIELDLEN];
919 if (!strncmp (*p, "c=", 2))
921 if (sscanf (*p, "c=%2s %3s %" MSFLENS "s",
922 fsdp_buf[0], fsdp_buf[1], fsdp_buf[2]))
924 if (!strncmp (fsdp_buf[0], "IN", 2))
926 *ntype = FSDP_NETWORK_TYPE_INET;
927 if (!strncmp (fsdp_buf[1], "IP4", 3))
928 *atype = FSDP_ADDRESS_TYPE_IPV4;
929 else if (!strncmp (fsdp_buf[1], "IP6", 3))
930 *atype = FSDP_ADDRESS_TYPE_IPV6;
931 else
932 return FSDPE_INVALID_CONNECTION_NETTYPE;
934 else
936 return FSDPE_INVALID_CONNECTION_ADDRTYPE;
939 char *slash = strchr (fsdp_buf[2], '/');
940 if (NULL == slash)
942 address->address = strdup (fsdp_buf[2]);
943 address->address_ttl = 0;
944 address->address_count = 0;
946 else
948 /* address is IP4 multicast */
949 char *slash2;
950 *slash = '\0';
951 slash++;
952 address->address = strdup (fsdp_buf[2]);
953 slash2 = strchr (slash + 1, '/');
954 if (NULL == slash2)
956 address->address_ttl = strtol (slash, NULL, 10);
957 address->address_count = 0;
959 else
961 *slash2 = '\0';
962 slash2++;
963 address->address_ttl = strtol (slash, NULL, 10);
964 address->address_count = strtol (slash2, NULL, 10);
968 NEXT_LINE (*p);
970 else
972 return FSDPE_INVALID_CONNECTION;
975 return FSDPE_OK;
978 static fsdp_error_t
979 fsdp_parse_b (const char **p, fsdp_bw_modifier_t ** bw_modifiers,
980 unsigned int *bw_modifiers_count)
982 char fsdp_buf[MAXSHORTFIELDLEN];
983 unsigned long int wuint;
984 unsigned int i = 0;
985 const char *lp = *p;
987 /* count b= lines */
988 while (!strncmp (lp, "b=", 2))
990 NEXT_LINE (lp);
991 i++;
993 *bw_modifiers = calloc (i, sizeof (fsdp_bw_modifier_t));
994 *bw_modifiers_count = i;
996 while (i > 0)
998 unsigned int index = *bw_modifiers_count - i;
999 if (2 == sscanf (*p, "b=%20[^:\r\n]:%lu", fsdp_buf, &wuint))
1001 if (!strncmp (fsdp_buf, "CT", 2))
1002 (*bw_modifiers)[index].b_mod_type =
1003 FSDP_BW_MOD_TYPE_CONFERENCE_TOTAL;
1004 else if (!strncmp (fsdp_buf, "AS", 2))
1005 (*bw_modifiers)[index].b_mod_type =
1006 FSDP_BW_MOD_TYPE_APPLICATION_SPECIFIC;
1007 else if (!strncmp (fsdp_buf, "RS", 2))
1008 (*bw_modifiers)[index].b_mod_type = FSDP_BW_MOD_TYPE_RTCP_SENDERS;
1009 else if (!strncmp (fsdp_buf, "RR", 2))
1010 (*bw_modifiers)[index].b_mod_type =
1011 FSDP_BW_MOD_TYPE_RTCP_RECEIVERS;
1012 else
1014 (*bw_modifiers)[index].b_mod_type = FSDP_BW_MOD_TYPE_UNKNOWN;
1015 (*bw_modifiers)[index].b_unknown_bw_modt =
1016 (char *) strdup (fsdp_buf);
1018 (*bw_modifiers)[index].b_value = wuint;
1019 NEXT_LINE (*p);
1021 else
1023 *bw_modifiers_count -= i;
1024 return FSDPE_INVALID_BANDWIDTH;
1026 i--;
1028 return FSDPE_OK;
1031 static fsdp_error_t
1032 fsdp_parse_k (const char **p, fsdp_encryption_method_t * method,
1033 char **content)
1035 char fsdp_buf[MAXSHORTFIELDLEN];
1036 char longfsdp_buf[MAXLONGFIELDLEN];
1038 if (!strncmp (*p, "k=", 2))
1040 if (sscanf (*p, "k=prompt"))
1042 *method = FSDP_ENCRYPTION_METHOD_PROMPT;
1043 *content = NULL;
1044 NEXT_LINE (*p);
1046 else
1048 if (sscanf
1049 (*p, "k=%6[^:\r\n]:%" MLFLENS "s", fsdp_buf, longfsdp_buf))
1051 if (!strncmp (fsdp_buf, "clear", 5))
1052 *method = FSDP_ENCRYPTION_METHOD_CLEAR;
1053 else if (!strncmp (fsdp_buf, "base64", 6))
1054 *method = FSDP_ENCRYPTION_METHOD_BASE64;
1055 else if (!strncmp (fsdp_buf, "uri", 3))
1056 *method = FSDP_ENCRYPTION_METHOD_URI;
1057 else
1058 return FSDPE_INVALID_ENCRYPTION_METHOD;
1059 *content = strdup (longfsdp_buf);
1060 NEXT_LINE (*p);
1064 return FSDPE_OK;
1067 static fsdp_error_t
1068 fsdp_parse_rtpmap (fsdp_rtpmap_t *** rtpmap, unsigned int *counter,
1069 const char *value)
1071 fsdp_error_t result = FSDPE_OK;
1073 if (0 == *counter)
1075 *counter = 0;
1076 *rtpmap = calloc (MEDIA_RTPMAPS_MAX_COUNT, sizeof (fsdp_rtpmap_t *));
1078 if (*counter < MEDIA_RTPMAPS_MAX_COUNT)
1080 unsigned int c = *counter;
1081 fsdp_rtpmap_t **map = *rtpmap;
1082 char fsdp_buf[MAXSHORTFIELDLEN];
1083 char longfsdp_buf[MAXLONGFIELDLEN];
1084 map[c] = calloc (1, sizeof (fsdp_rtpmap_t));
1086 /* a=rtpmap:<payload type> <encoding name>/<clock rate>[/<encoding
1087 parameters]> */
1088 if (2 == sscanf (value, "%s %s", fsdp_buf, longfsdp_buf))
1090 char *slash1;
1091 map[c]->pt = strdup (fsdp_buf);
1092 /* parse <encoding name>/<clock rate>[/<encoding parameters>] */
1093 slash1 = strchr (longfsdp_buf, '/');
1094 if (NULL == slash1)
1096 result = FSDPE_INVALID_ATTRIBUTE_RTPMAP;
1098 else
1100 char *slash2;
1101 *slash1 = '\0';
1102 slash1++;
1103 map[c]->encoding_name = strdup (longfsdp_buf);
1104 slash2 = strchr (slash1, '/');
1105 if (NULL != slash2)
1107 *slash2 = '\0';
1108 slash2++;
1109 map[c]->parameters = strdup (slash2);
1111 map[c]->clock_rate = strtol (slash1, NULL, 10);
1113 (*counter)++;
1116 return result;
1119 static fsdp_error_t
1120 fsdp_repeat_time_to_uint (const char *time, unsigned long int *seconds)
1122 const unsigned long SECONDS_PER_DAY = 86400;
1123 const unsigned long SECONDS_PER_HOUR = 3600;
1124 const unsigned long SECONDS_PER_MINUTE = 60;
1125 char c;
1126 unsigned long int wuint;
1128 if (sscanf (time, "%lu%c", &wuint, &c) == 2)
1130 /* time with unit specification character */
1131 switch (c)
1133 case 'd':
1134 *seconds = wuint * SECONDS_PER_DAY;
1135 break;
1136 case 'h':
1137 *seconds = wuint * SECONDS_PER_HOUR;
1138 break;
1139 case 'm':
1140 *seconds = wuint * SECONDS_PER_MINUTE;
1141 break;
1142 case 's':
1143 *seconds = wuint;
1144 break;
1145 default:
1146 return FSDPE_INVALID_REPEAT;
1147 break;
1150 else if (sscanf (time, "%lu", &wuint) == 1)
1152 /* time without unit specification character */
1153 *seconds = wuint;
1155 else
1157 return FSDPE_INVALID_REPEAT;
1159 return FSDPE_OK;
1162 unsigned int
1163 fsdp_get_version (const fsdp_description_t * dsc)
1165 if (!dsc)
1166 return 0;
1167 return dsc->version;
1170 const char *
1171 fsdp_get_owner_username (const fsdp_description_t * dsc)
1173 if (!dsc)
1174 return NULL;
1175 return dsc->o_username;
1178 const char *
1179 fsdp_get_session_id (const fsdp_description_t * dsc)
1181 if (!dsc)
1182 return NULL;
1183 return dsc->o_session_id;
1186 const char *
1187 fsdp_get_announcement_version (const fsdp_description_t * dsc)
1189 if (!dsc)
1190 return NULL;
1191 return dsc->o_announcement_version;
1194 fsdp_network_type_t
1195 fsdp_get_owner_network_type (const fsdp_description_t * dsc)
1197 if (!dsc)
1198 return FSDP_NETWORK_TYPE_UNDEFINED;
1199 return dsc->o_network_type;
1202 fsdp_address_type_t
1203 fsdp_get_owner_address_type (const fsdp_description_t * dsc)
1205 if (!dsc)
1206 return FSDP_ADDRESS_TYPE_UNDEFINED;
1207 return dsc->o_address_type;
1210 const char *
1211 fsdp_get_owner_address (const fsdp_description_t * dsc)
1213 if (!dsc)
1214 return NULL;
1215 return dsc->o_address;
1218 const char *
1219 fsdp_get_name (const fsdp_description_t * dsc)
1221 if (!dsc)
1222 return NULL;
1223 return dsc->s_name;
1226 const char *
1227 fsdp_get_information (const fsdp_description_t * dsc)
1229 if (!dsc)
1230 return NULL;
1231 return dsc->i_information;
1234 const char *
1235 fsdp_get_uri (const fsdp_description_t * dsc)
1237 if (!dsc)
1238 return NULL;
1239 return dsc->u_uri;
1242 unsigned int
1243 fsdp_get_emails_count (const fsdp_description_t * dsc)
1245 if (!dsc)
1246 return 0;
1247 return dsc->emails_count;
1250 const char *
1251 fsdp_get_email (const fsdp_description_t * dsc, unsigned int index)
1253 if ((!dsc) || (index >= dsc->emails_count))
1254 return NULL;
1255 return dsc->emails[index];
1258 unsigned int
1259 fsdp_get_phones_count (const fsdp_description_t * dsc)
1261 if (!dsc)
1262 return 0;
1263 return dsc->phones_count;
1266 const char *
1267 fsdp_get_phone (const fsdp_description_t * dsc, unsigned int index)
1269 if ((!dsc) || (index >= dsc->phones_count))
1270 return NULL;
1271 return dsc->phones[index];
1274 fsdp_network_type_t
1275 fsdp_get_global_conn_network_type (const fsdp_description_t * dsc)
1277 if (!dsc)
1278 return FSDP_NETWORK_TYPE_UNDEFINED;
1279 return dsc->c_network_type;
1282 fsdp_address_type_t
1283 fsdp_get_global_conn_address_type (const fsdp_description_t * dsc)
1285 if (!dsc)
1286 return FSDP_ADDRESS_TYPE_UNDEFINED;
1287 return dsc->c_address_type;
1290 const char *
1291 fsdp_get_global_conn_address (const fsdp_description_t * dsc)
1293 if (!dsc)
1294 return NULL;
1295 return dsc->c_address.address;
1298 unsigned int
1299 fsdp_get_global_conn_address_ttl (const fsdp_description_t * dsc)
1301 if (!dsc)
1302 return 0;
1303 return dsc->c_address.address_ttl;
1306 unsigned int
1307 fsdp_get_global_conn_address_count (const fsdp_description_t * dsc)
1309 if (!dsc)
1310 return 0;
1311 return dsc->c_address.address_count;
1314 unsigned int
1315 fsdp_get_bw_modifier_count (const fsdp_description_t * dsc)
1317 if (!dsc)
1318 return 0;
1319 return dsc->bw_modifiers_count;
1322 fsdp_bw_modifier_type_t
1323 fsdp_get_bw_modifier_type (const fsdp_description_t * dsc, unsigned int index)
1325 if ((!dsc) || (index >= dsc->bw_modifiers_count))
1326 return FSDP_BW_MOD_TYPE_UNDEFINED;
1327 return dsc->bw_modifiers[index].b_mod_type;
1330 const char *
1331 fsdp_get_bw_modifier_type_unknown (const fsdp_description_t * dsc,
1332 unsigned int index)
1334 if ((!dsc) || (index >= dsc->bw_modifiers_count) ||
1335 (dsc->bw_modifiers[index].b_mod_type != FSDP_BW_MOD_TYPE_UNKNOWN))
1336 return NULL;
1337 return dsc->bw_modifiers[index].b_unknown_bw_modt;
1340 unsigned long int
1341 fsdp_get_bw_value (const fsdp_description_t * dsc, unsigned int index)
1343 if ((!dsc) || (index >= dsc->bw_modifiers_count))
1344 return 0;
1345 return dsc->bw_modifiers[index].b_value;
1348 time_t
1349 fsdp_get_period_start (const fsdp_description_t * dsc, unsigned int index)
1351 if ((!dsc) || (index >= dsc->time_periods_count))
1352 return 0;
1353 return dsc->time_periods[index]->start;
1356 time_t
1357 fsdp_get_period_stop (const fsdp_description_t * dsc, unsigned int index)
1359 if ((!dsc) || (index >= dsc->time_periods_count))
1360 return 0;
1361 return dsc->time_periods[index]->stop;
1364 unsigned int
1365 fsdp_get_period_repeats_count (const fsdp_description_t * dsc,
1366 unsigned int index)
1368 if ((!dsc) || (index >= dsc->time_periods_count))
1369 return 0;
1370 return dsc->time_periods[index]->repeats_count;
1373 unsigned long int
1374 fsdp_get_period_repeat_interval (const fsdp_description_t * dsc,
1375 unsigned int index, unsigned int rindex)
1377 if ((!dsc) || (index >= dsc->time_periods_count))
1378 return 0;
1379 return dsc->time_periods[index]->repeats[rindex]->interval;
1382 unsigned long int
1383 fsdp_get_period_repeat_duration (const fsdp_description_t * dsc,
1384 unsigned int index, unsigned int rindex)
1386 if ((!dsc) || (index >= dsc->time_periods_count))
1387 return 0;
1388 return dsc->time_periods[index]->repeats[rindex]->duration;
1391 const unsigned long int *
1392 fsdp_get_period_repeat_offsets (const fsdp_description_t * dsc,
1393 unsigned int index, unsigned int rindex)
1395 if ((!dsc) || (index >= dsc->time_periods_count))
1396 return NULL;
1397 return dsc->time_periods[index]->repeats[rindex]->offsets;
1400 const char *
1401 fsdp_get_timezone_adj (const fsdp_description_t * dsc)
1403 if (!dsc)
1404 return NULL;
1405 return dsc->timezone_adj;
1408 unsigned int
1409 fsdp_get_unidentified_attribute_count (const fsdp_description_t * dsc)
1411 if (!dsc)
1412 return 0;
1413 return dsc->unidentified_attributes_count;
1416 const char *
1417 fsdp_get_unidentified_attribute (const fsdp_description_t * dsc,
1418 unsigned int index)
1420 if (!dsc || (index < dsc->unidentified_attributes_count))
1421 return NULL;
1422 return dsc->unidentified_attributes[index];
1425 fsdp_encryption_method_t
1426 fsdp_get_encryption_method (const fsdp_description_t * dsc)
1428 if (!dsc)
1429 return FSDP_ENCRYPTION_METHOD_UNDEFINED;
1430 return dsc->k_encryption_method;
1433 const char *
1434 fsdp_get_encryption_content (const fsdp_description_t * dsc)
1436 if (!dsc || (dsc->k_encryption_method == FSDP_ENCRYPTION_METHOD_UNDEFINED))
1437 return NULL;
1438 return dsc->k_encryption_content;
1441 const char *
1442 fsdp_get_str_att (const fsdp_description_t * dsc, fsdp_session_str_att_t att)
1444 /*TODO: change these individual attributes with a table, thus
1445 avoiding this slow switch */
1446 char *result;
1448 if (!dsc)
1449 return NULL;
1451 switch (att)
1453 case FSDP_SESSION_STR_ATT_CATEGORY:
1454 result = dsc->a_category;
1455 break;
1456 case FSDP_SESSION_STR_ATT_KEYWORDS:
1457 result = dsc->a_keywords;
1458 break;
1459 case FSDP_SESSION_STR_ATT_TOOL:
1460 result = dsc->a_tool;
1461 break;
1462 case FSDP_SESSION_STR_ATT_CHARSET:
1463 result = dsc->a_charset;
1464 break;
1465 default:
1466 result = NULL;
1468 return result;
1471 unsigned int
1472 fsdp_get_sdplang_count (const fsdp_description_t * dsc)
1474 if (!dsc)
1475 return 0;
1476 return dsc->a_sdplangs_count;
1479 const char *
1480 fsdp_get_sdplang (const fsdp_description_t * dsc, unsigned int index)
1482 if ((!dsc) || (index >= dsc->a_sdplangs_count))
1483 return NULL;
1484 return dsc->a_sdplangs[index];
1487 unsigned int
1488 fsdp_get_control_count (const fsdp_description_t * dsc)
1490 if (!dsc)
1491 return 0;
1492 return dsc->a_controls_count;
1495 const char *
1496 fsdp_get_control (const fsdp_description_t * dsc, unsigned int index)
1498 if ((!dsc) || (index >= dsc->a_controls_count))
1499 return NULL;
1500 return dsc->a_controls[index];
1503 const char *
1504 fsdp_get_range (const fsdp_description_t * dsc)
1506 return dsc->a_range;
1509 fsdp_sendrecv_mode_t
1510 fsdp_get_sendrecv_mode (const fsdp_description_t * dsc)
1512 if (!dsc)
1513 return FSDP_SENDRECV_UNDEFINED;
1514 return dsc->a_sendrecv_mode;
1517 fsdp_session_type_t
1518 fsdp_get_session_type (const fsdp_description_t * dsc)
1520 if (!dsc)
1521 return FSDP_SESSION_TYPE_UNDEFINED;
1522 return dsc->a_type;
1525 unsigned int
1526 fsdp_get_media_count (const fsdp_description_t * dsc)
1528 if (!dsc)
1529 return 0;
1530 return dsc->media_announcements_count;
1533 const fsdp_media_description_t *
1534 fsdp_get_media (const fsdp_description_t * dsc, unsigned int index)
1536 if ((index >= dsc->media_announcements_count))
1537 return NULL;
1538 return dsc->media_announcements[index];
1541 fsdp_media_t
1542 fsdp_get_media_type (const fsdp_media_description_t * dsc)
1544 if (!dsc)
1545 return FSDP_MEDIA_UNDEFINED;
1546 return dsc->media_type;
1549 unsigned int
1550 fsdp_get_media_port (const fsdp_media_description_t * dsc)
1552 if (!dsc)
1553 return 0;
1554 return dsc->port;
1557 unsigned int
1558 fsdp_get_media_port_count (const fsdp_media_description_t * dsc)
1560 if (!dsc)
1561 return 0;
1562 return dsc->port_count;
1565 fsdp_transport_protocol_t
1566 fsdp_get_media_transport_protocol (const fsdp_media_description_t * dsc)
1568 if (!dsc)
1569 return FSDP_TP_UNDEFINED;
1570 return dsc->transport;
1573 unsigned int
1574 fsdp_get_media_formats_count (const fsdp_media_description_t * dsc)
1576 if (!dsc)
1577 return 0;
1578 return dsc->formats_count;
1581 const char *
1582 fsdp_get_media_format (const fsdp_media_description_t * dsc,
1583 unsigned int index)
1585 if (!dsc || (index < dsc->formats_count - 1))
1586 return NULL;
1587 return dsc->formats[index];
1590 const char *
1591 fsdp_get_media_title (const fsdp_media_description_t * dsc)
1593 if (!dsc)
1594 return NULL;
1595 return dsc->i_title;
1598 fsdp_network_type_t
1599 fsdp_get_media_network_type (const fsdp_media_description_t * dsc)
1601 if (!dsc)
1602 return FSDP_NETWORK_TYPE_UNDEFINED;
1603 return dsc->c_network_type;
1606 fsdp_address_type_t
1607 fsdp_get_media_address_type (const fsdp_media_description_t * dsc)
1609 if (!dsc)
1610 return FSDP_ADDRESS_TYPE_UNDEFINED;
1611 return dsc->c_address_type;
1614 const char *
1615 fsdp_get_media_address (const fsdp_media_description_t * dsc)
1617 if (!dsc)
1618 return NULL;
1619 return dsc->c_address.address;
1622 unsigned int
1623 fsdp_get_media_address_ttl (const fsdp_media_description_t * mdsc)
1625 if (!mdsc)
1626 return 0;
1627 return mdsc->c_address.address_ttl;
1630 unsigned int
1631 fsdp_get_media_address_count (const fsdp_media_description_t * mdsc)
1633 if (!mdsc)
1634 return 0;
1635 return mdsc->c_address.address_count;
1638 fsdp_bw_modifier_type_t
1639 fsdp_get_media_bw_modifier_type (const fsdp_media_description_t * dsc,
1640 unsigned int index)
1642 if (!dsc || (index >= dsc->bw_modifiers_count))
1643 return FSDP_BW_MOD_TYPE_UNDEFINED;
1644 return dsc->bw_modifiers[index].b_mod_type;
1647 const char *
1648 fsdp_get_media_bw_modifier_type_unknown (const fsdp_media_description_t * dsc,
1649 unsigned int index)
1651 if (!dsc || (index >= dsc->bw_modifiers_count) ||
1652 (FSDP_BW_MOD_TYPE_UNKNOWN != dsc->bw_modifiers[index].b_mod_type))
1653 return NULL;
1654 return dsc->bw_modifiers[index].b_unknown_bw_modt;
1657 unsigned long int
1658 fsdp_get_media_bw_value (const fsdp_media_description_t * dsc,
1659 unsigned int index)
1661 if (!dsc || (index >= dsc->bw_modifiers_count))
1662 return 0;
1663 return dsc->bw_modifiers[index].b_value;
1666 fsdp_encryption_method_t
1667 fsdp_get_media_encryption_method (const fsdp_media_description_t * dsc)
1669 if (!dsc)
1670 return FSDP_ENCRYPTION_METHOD_UNDEFINED;
1671 return dsc->k_encryption_method;
1674 const char *
1675 fsdp_get_media_encryption_content (const fsdp_media_description_t * dsc)
1677 if (!dsc)
1678 return NULL;
1679 return dsc->k_encryption_content;
1682 unsigned int
1683 fsdp_get_media_ptime (const fsdp_media_description_t * dsc)
1685 if (!dsc)
1686 return 0;
1687 return dsc->a_ptime;
1690 unsigned int
1691 fsdp_get_media_maxptime (const fsdp_media_description_t * dsc)
1693 if (!dsc)
1694 return 0;
1695 return dsc->a_maxptime;
1698 unsigned int
1699 fsdp_get_media_rtpmap_count (const fsdp_media_description_t * mdsc)
1701 if (!mdsc)
1702 return 0;
1703 return mdsc->a_rtpmaps_count;
1706 const char *
1707 fsdp_get_media_rtpmap_payload_type (const fsdp_media_description_t * mdsc,
1708 unsigned int index)
1710 if (!mdsc || (index >= mdsc->a_rtpmaps_count))
1711 return NULL;
1712 return mdsc->a_rtpmaps[index]->pt;
1715 const char *
1716 fsdp_get_media_rtpmap_encoding_name (const fsdp_media_description_t * mdsc,
1717 unsigned int index)
1719 if (!mdsc || (index >= mdsc->a_rtpmaps_count))
1720 return NULL;
1721 return mdsc->a_rtpmaps[index]->encoding_name;
1724 unsigned int
1725 fsdp_get_media_rtpmap_clock_rate (const fsdp_media_description_t * mdsc,
1726 unsigned int index)
1728 if (!mdsc || (index >= mdsc->a_rtpmaps_count))
1729 return 0;
1730 return mdsc->a_rtpmaps[index]->clock_rate;
1733 const char *
1734 fsdp_get_media_rtpmap_encoding_parameters (const fsdp_description_t * mdsc,
1735 unsigned int index)
1737 if (!mdsc || (index >= mdsc->a_rtpmaps_count))
1738 return NULL;
1739 return mdsc->a_rtpmaps[index]->parameters;
1742 unsigned int
1743 fsdp_get_media_sdplang_count (const fsdp_media_description_t * mdsc)
1745 if (!mdsc)
1746 return 0;
1747 return mdsc->a_sdplangs_count;
1750 const char *
1751 fsdp_get_media_sdplang (const fsdp_media_description_t * mdsc,
1752 unsigned int index)
1754 if (!mdsc || (index >= mdsc->a_sdplangs_count))
1755 return NULL;
1756 return mdsc->a_sdplangs[index];
1759 unsigned int
1760 fsdp_get_media_lang_count (const fsdp_media_description_t * mdsc)
1762 if (!mdsc)
1763 return 0;
1764 return mdsc->a_langs_count;
1767 const char *
1768 fsdp_get_media_lang (const fsdp_media_description_t * mdsc,
1769 unsigned int index)
1771 if (!mdsc || (index >= mdsc->a_langs_count))
1772 return NULL;
1773 return mdsc->a_langs[index];
1776 unsigned int
1777 fsdp_get_media_control_count (const fsdp_media_description_t * mdsc)
1779 if (!mdsc)
1780 return 0;
1781 return mdsc->a_controls_count;
1784 char *
1785 fsdp_get_media_control (const fsdp_media_description_t * mdsc,
1786 unsigned int index)
1788 if (!mdsc || (index >= mdsc->a_controls_count))
1789 return NULL;
1790 return mdsc->a_controls[index];
1793 char *
1794 fsdp_get_media_range (const fsdp_media_description_t * mdsc)
1796 return mdsc->a_range;
1799 unsigned int
1800 fsdp_get_media_fmtp_count (const fsdp_media_description_t * mdsc)
1802 if (!mdsc)
1803 return 0;
1804 return mdsc->a_fmtps_count;
1807 const char *
1808 fsdp_get_media_fmtp (const fsdp_media_description_t * mdsc,
1809 unsigned int index)
1811 if (!mdsc || (index >= mdsc->a_fmtps_count))
1812 return NULL;
1813 return mdsc->a_fmtps[index];
1816 fsdp_orient_t
1817 fsdp_get_media_orient (const fsdp_media_description_t * dsc)
1819 if (!dsc)
1820 return FSDP_ORIENT_UNDEFINED;
1821 return dsc->a_orient;
1824 fsdp_sendrecv_mode_t
1825 fsdp_get_media_sendrecv (const fsdp_media_description_t * dsc)
1827 if (!dsc)
1828 return FSDP_SENDRECV_UNDEFINED;
1829 return dsc->a_sendrecv_mode;
1832 float
1833 fsdp_get_media_framerate (const fsdp_media_description_t * dsc)
1835 if (!dsc)
1836 return 0;
1837 return dsc->a_framerate;
1840 unsigned int
1841 fsdp_get_media_quality (const fsdp_media_description_t * dsc)
1843 if (!dsc)
1844 return 0;
1845 return dsc->a_quality;
1848 unsigned int
1849 fsdp_get_media_rtcp_port (const fsdp_media_description_t * dsc)
1851 if (!dsc)
1852 return 0;
1853 return dsc->a_rtcp_port;
1856 fsdp_network_type_t
1857 fsdp_get_media_rtcp_network_type (const fsdp_media_description_t * dsc)
1859 if (!dsc)
1860 return FSDP_NETWORK_TYPE_UNDEFINED;
1861 return dsc->a_rtcp_network_type;
1864 fsdp_address_type_t
1865 fsdp_get_media_rtcp_address_type (const fsdp_media_description_t * dsc)
1867 if (!dsc)
1868 return FSDP_ADDRESS_TYPE_UNDEFINED;
1869 return dsc->a_rtcp_address_type;
1872 const char *
1873 fsdp_get_media_rtcp_address (const fsdp_media_description_t * dsc)
1875 if (!dsc)
1876 return NULL;
1877 return dsc->a_rtcp_address;
1880 unsigned int
1881 fsdp_get_media_unidentified_attribute_count (const fsdp_media_description_t
1882 * mdsc)
1884 if (!mdsc)
1885 return 0;
1886 return mdsc->unidentified_attributes_count;
1889 const char *
1890 fsdp_get_media_unidentified_attribute (const fsdp_media_description_t * mdsc,
1891 unsigned int index)
1893 if (!mdsc || (index < mdsc->unidentified_attributes_count))
1894 return NULL;
1895 return mdsc->unidentified_attributes[index];