Use DECLARE_ALIGNED macro instead of gcc __attribute__.
[mplayer/glamo.git] / stream / freesdp / parser.c
blob34e6737a05a993f7a407a2d8d1638d768472d7a0
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 if (dsc->a_range)
475 free (dsc->a_range);
476 dsc->a_range = strdup (fsdp_buf[1]);
478 else
480 /* ignore unknown attributes, but provide access to them */
481 *longfsdp_buf = '\0';
482 strncat (longfsdp_buf, fsdp_buf[0], MAXLONGFIELDLEN-1);
483 strncat (longfsdp_buf, ":", MAXLONGFIELDLEN-strlen(longfsdp_buf)-1);
484 strncat (longfsdp_buf, fsdp_buf[1], MAXLONGFIELDLEN-strlen(longfsdp_buf)-1);
485 if (NULL == dsc->unidentified_attributes)
487 dsc->unidentified_attributes_count = 0;
488 dsc->unidentified_attributes =
489 calloc (UNIDENTIFIED_ATTRIBUTES_MAX_COUNT,
490 sizeof (char *));
492 if (dsc->unidentified_attributes_count <
493 UNIDENTIFIED_ATTRIBUTES_MAX_COUNT)
495 dsc->unidentified_attributes
496 [dsc->unidentified_attributes_count] =
497 strdup (longfsdp_buf);
498 dsc->unidentified_attributes_count++;
501 NEXT_LINE (p);
503 else if (sscanf (p, "a=%20s", fsdp_buf[0]) == 1)
505 /* session-level property attributes */
506 if (!strncmp (fsdp_buf[0], "recvonly", 8))
507 dsc->a_sendrecv_mode = FSDP_SENDRECV_RECVONLY;
508 else if (!strncmp (fsdp_buf[0], "sendonly", 8))
509 dsc->a_sendrecv_mode = FSDP_SENDRECV_SENDONLY;
510 else if (!strncmp (fsdp_buf[0], "inactive", 8))
511 dsc->a_sendrecv_mode = FSDP_SENDRECV_INACTIVE;
512 else if (!strncmp (fsdp_buf[0], "sendrecv", 8))
513 dsc->a_sendrecv_mode = FSDP_SENDRECV_SENDRECV;
514 else
516 /* ignore unknown attributes, but provide access to them */
517 *longfsdp_buf = '\0';
518 strncat (longfsdp_buf, fsdp_buf[0], MAXLONGFIELDLEN-1);
519 if (NULL == dsc->unidentified_attributes)
521 dsc->unidentified_attributes_count = 0;
522 dsc->unidentified_attributes =
523 calloc (UNIDENTIFIED_ATTRIBUTES_MAX_COUNT,
524 sizeof (char *));
526 if (dsc->unidentified_attributes_count <
527 UNIDENTIFIED_ATTRIBUTES_MAX_COUNT)
529 dsc->unidentified_attributes
530 [dsc->unidentified_attributes_count] =
531 strdup (longfsdp_buf);
532 dsc->unidentified_attributes_count++;
535 NEXT_LINE (p);
537 else
538 return FSDPE_INVALID_ATTRIBUTE;
541 /***************************************************************************/
542 /* B) parse media-level descriptions */
543 /***************************************************************************/
544 p2 = p;
545 j = 0;
546 while ((*p2 != '\0') && !strncmp (p2, "m=", 2))
548 char c;
549 j++;
550 NEXT_LINE (p2);
551 while (sscanf (p2, "%c=", &c) == 1)
553 if (c == 'i' || c == 'c' || c == 'b' || c == 'k' || c == 'a')
555 NEXT_LINE (p2);
557 else if (c == 'm')
559 break;
561 else
563 return FSDPE_INVALID_LINE;
567 dsc->media_announcements_count = j;
568 if (dsc->media_announcements_count == 0)
571 /*return FSDPE_MISSING_MEDIA; */
573 else
574 { /* dsc->media_announcements_count > 0 */
575 dsc->media_announcements =
576 calloc (j, sizeof (fsdp_media_announcement_t *));
577 for (j = 0; j < dsc->media_announcements_count; j++)
579 fsdp_media_announcement_t *media = NULL;
580 /* `m=' line (media name, transport address and format list) */
581 /* m=<media> <port> <transport> <fmt list> */
582 /* The max. string lengths are subject to change */
583 if (sscanf (p, "m=%11s %8s %7s %" MLFLENS "[^\r\n]",
584 fsdp_buf[0], fsdp_buf[1], fsdp_buf[2],
585 longfsdp_buf) != 4)
587 return FSDPE_INVALID_MEDIA;
589 else
591 dsc->media_announcements[j] =
592 calloc (1, sizeof (fsdp_media_announcement_t));
593 media = dsc->media_announcements[j];
594 if (!strncmp (fsdp_buf[0], "audio", 5))
595 media->media_type = FSDP_MEDIA_AUDIO;
596 else if (!strncmp (fsdp_buf[0], "video", 5))
597 media->media_type = FSDP_MEDIA_VIDEO;
598 else if (!strncmp (fsdp_buf[0], "application", 11))
599 media->media_type = FSDP_MEDIA_APPLICATION;
600 else if (!strncmp (fsdp_buf[0], "data", 4))
601 media->media_type = FSDP_MEDIA_DATA;
602 else if (!strncmp (fsdp_buf[0], "control", 7))
603 media->media_type = FSDP_MEDIA_CONTROL;
604 else
605 return FSDPE_UNKNOWN_MEDIA_TYPE;
606 { /* try to get port specification as port/number */
607 char *slash;
608 if ((slash = strchr (fsdp_buf[1], '/')))
610 *slash = '\0';
611 slash++;
612 media->port = strtol (fsdp_buf[1], NULL, 10);
613 media->port_count = strtol (slash, NULL, 10);
615 else
617 media->port = strtol (fsdp_buf[1], NULL, 10);
618 media->port_count = 0;
621 if (!strncmp (fsdp_buf[2], "RTP/AVP", 7))
622 media->transport = FSDP_TP_RTP_AVP;
623 else if (!strncmp (fsdp_buf[2], "udp", 3))
624 media->transport = FSDP_TP_UDP;
625 else if (!strncmp (fsdp_buf[2], "TCP", 3))
626 media->transport = FSDP_TP_TCP;
627 else if (!strncmp (fsdp_buf[2], "UDPTL", 5))
628 media->transport = FSDP_TP_UDPTL;
629 else if (!strncmp (fsdp_buf[2], "vat", 3))
630 media->transport = FSDP_TP_VAT;
631 else if (!strncmp (fsdp_buf[2], "rtp", 3))
632 media->transport = FSDP_TP_OLD_RTP;
633 else
634 return FSDPE_UNKNOWN_MEDIA_TRANSPORT;
636 unsigned int k = 0;
637 char *s = longfsdp_buf;
638 while (NULL != (s = strchr (s, ' ')))
640 k++;
641 if (NULL != s)
642 s++;
644 k++; /* when there is no space left, count the last format */
645 media->formats_count = k;
646 media->formats = calloc (k, sizeof (char *));
647 s = longfsdp_buf;
648 for (k = 0; k < media->formats_count; k++)
650 char *space = strchr (s, ' ');
651 if (NULL != space)
652 *space = '\0';
653 media->formats[k] = strdup (s);
654 s = space + 1;
657 NEXT_LINE (p);
660 /* `i=' line (media title) [optional] */
661 /* i=<media title> */
662 if (!strncmp (p, "i=", 2)
663 && sscanf (p, "i=%" MLFLENS "[^\r\n]", longfsdp_buf))
665 media->i_title = strdup (longfsdp_buf);
666 NEXT_LINE (p);
668 else
670 /* (optional) information absent */
673 /* `c=' line (connection information - overrides session-level
674 line) [optional if provided at session-level] */
675 /* c=<network type> <address type> <connection address> */
676 result = fsdp_parse_c (&p, &(media->c_network_type),
677 &(media->c_address_type),
678 &(media->c_address));
679 if (result != FSDPE_OK)
680 return result;
682 /* `b=' lines (bandwidth information) [optional] */
683 /* b=<modifier>:<bandwidth-value> */
684 result = fsdp_parse_b (&p, &(media->bw_modifiers),
685 &(media->bw_modifiers_count));
686 if (FSDPE_OK != result)
687 return result;
689 /* `k=' line (encryption key) [optional] */
690 /* k=<method>
691 k=<method>:<encryption key> */
692 result = fsdp_parse_k (&p, &(media->k_encryption_method),
693 &(media->k_encryption_content));
694 if (result != FSDPE_OK)
695 return result;
697 /* B.1) Attributes */
699 /* `a=' lines (zero or more media attribute lines) [optional] */
700 /* a=<attribute>
701 a=<attribute>:<value> */
702 while (!strncmp (p, "a=", 2))
704 if (sscanf
705 (p, "a=%9[^:\r\n]:%" MLFLENS "[^\r\n]", fsdp_buf[0],
706 longfsdp_buf) == 2)
708 /* media-level value attributes */
709 if (!strncmp (fsdp_buf[0], "ptime", 5))
710 media->a_ptime = strtoul (longfsdp_buf, NULL, 10);
711 else if (!strncmp (fsdp_buf[0], "maxptime", 8))
712 media->a_maxptime = strtoul (longfsdp_buf, NULL, 10);
713 else if (!strncmp (fsdp_buf[0], "rtpmap", 6))
714 fsdp_parse_rtpmap (&(media->a_rtpmaps),
715 &(media->a_rtpmaps_count),
716 longfsdp_buf);
717 else if (!strncmp (fsdp_buf[0], "orient", 6))
719 if (!strncmp (longfsdp_buf, "portrait", 8))
720 media->a_orient = FSDP_ORIENT_PORTRAIT;
721 else if (!strncmp (longfsdp_buf, "landscape", 9))
722 media->a_orient = FSDP_ORIENT_LANDSCAPE;
723 else if (!strncmp (longfsdp_buf, "seascape", 9))
724 media->a_orient = FSDP_ORIENT_SEASCAPE;
726 else if (!strncmp (fsdp_buf[0], "sdplang", 7))
728 if (NULL == dsc->a_sdplangs)
730 media->a_sdplangs_count = 0;
731 media->a_sdplangs =
732 calloc (SDPLANGS_MAX_COUNT, sizeof (char *));
734 if (media->a_sdplangs_count < SDPLANGS_MAX_COUNT)
736 media->a_sdplangs[dsc->a_sdplangs_count] =
737 strdup (longfsdp_buf);
738 media->a_sdplangs_count++;
741 else if (!strncmp (fsdp_buf[0], "lang", 4))
743 if (NULL == dsc->a_langs)
745 media->a_langs_count = 0;
746 media->a_langs =
747 calloc (SDPLANGS_MAX_COUNT, sizeof (char *));
749 if (media->a_langs_count < SDPLANGS_MAX_COUNT)
751 media->a_langs[dsc->a_langs_count] =
752 strdup (longfsdp_buf);
753 media->a_langs_count++;
756 else if (!strncmp (fsdp_buf[0], "control", 7))
758 if (NULL == media->a_controls)
760 media->a_controls_count = 0;
761 media->a_controls =
762 calloc (SDPCONTROLS_MAX_COUNT, sizeof (char *));
764 if (media->a_controls_count < SDPCONTROLS_MAX_COUNT)
766 media->a_controls[media->a_controls_count] =
767 strdup (longfsdp_buf);
768 media->a_controls_count++;
771 else if (!strncmp (fsdp_buf[0], "range", 5))
773 if (media->a_range)
774 free (media->a_range);
775 media->a_range = strdup (fsdp_buf[1]);
777 else if (!strncmp (fsdp_buf[0], "framerate", 9))
778 media->a_framerate = strtod (longfsdp_buf, NULL);
779 else if (!strncmp (fsdp_buf[0], "fmtp", 4))
781 if (NULL == media->a_fmtps)
783 media->a_fmtps_count = 0;
784 media->a_fmtps =
785 calloc (SDPLANGS_MAX_COUNT, sizeof (char *));
787 if (media->a_fmtps_count < SDPLANGS_MAX_COUNT)
789 media->a_fmtps[media->a_fmtps_count] =
790 strdup (longfsdp_buf);
791 media->a_fmtps_count++;
794 else if (!strncmp (fsdp_buf[0], "rtcp", 4))
796 int opts = 0;
797 /* rtcp attribute: a=rtcp:<port> <nettype> <addrtype> <address> */
798 opts =
799 sscanf (longfsdp_buf, "%lu %2s %3s %" MSFLENS "s",
800 &wuint[0], fsdp_buf[0], fsdp_buf[1],
801 fsdp_buf[2]);
802 if (opts >= 1)
804 media->a_rtcp_port = wuint[0];
805 if (opts >= 2)
807 if (!strncmp (fsdp_buf[0], "IN", 2))
809 media->a_rtcp_network_type =
810 FSDP_NETWORK_TYPE_INET;
811 } /* else
812 ; TODO: define error code? */
813 if (opts >= 3)
815 if (!strncmp (fsdp_buf[1], "IP4", 3))
816 media->a_rtcp_address_type =
817 FSDP_ADDRESS_TYPE_IPV4;
818 else if (!strncmp (fsdp_buf[1], "IP6", 3))
819 media->a_rtcp_address_type =
820 FSDP_ADDRESS_TYPE_IPV6;
821 else
822 return FSDPE_INVALID_CONNECTION_NETTYPE;
823 /*add specific code? */
824 if (opts >= 4)
825 media->a_rtcp_address =
826 strdup (fsdp_buf[2]);
831 else
833 /* ignore unknown attributes, but provide access to them */
834 *fsdp_buf[1] = '\0';
835 strncat (fsdp_buf[1], fsdp_buf[0], MAXSHORTFIELDLEN-1);
836 strncat (fsdp_buf[1], ":", MAXSHORTFIELDLEN-strlen(fsdp_buf[1])-1);
837 strncat (fsdp_buf[1], longfsdp_buf, MAXSHORTFIELDLEN-strlen(fsdp_buf[1])-1);
838 if (NULL == media->unidentified_attributes)
840 media->unidentified_attributes_count = 0;
841 media->unidentified_attributes =
842 calloc (UNIDENTIFIED_ATTRIBUTES_MAX_COUNT,
843 sizeof (char *));
845 if (media->unidentified_attributes_count <
846 UNIDENTIFIED_ATTRIBUTES_MAX_COUNT)
848 media->unidentified_attributes
849 [media->unidentified_attributes_count] =
850 strdup (fsdp_buf[1]);
851 media->unidentified_attributes_count++;
854 NEXT_LINE (p);
856 else if (sscanf (p, "a=%8s", fsdp_buf[0]) == 1)
858 /* media-level property attributes */
859 if (!strncmp (fsdp_buf[0], "recvonly", 8))
860 media->a_sendrecv_mode = FSDP_SENDRECV_RECVONLY;
861 else if (!strncmp (fsdp_buf[0], "sendonly", 8))
862 media->a_sendrecv_mode = FSDP_SENDRECV_SENDONLY;
863 else if (!strncmp (fsdp_buf[0], "inactive", 8))
864 media->a_sendrecv_mode = FSDP_SENDRECV_INACTIVE;
865 else if (!strncmp (fsdp_buf[0], "sendrecv", 8))
866 media->a_sendrecv_mode = FSDP_SENDRECV_SENDRECV;
867 else
869 /* ignore unknown attributes, but provide access to them */
870 *longfsdp_buf = '\0';
871 strncat (longfsdp_buf, fsdp_buf[0], MAXLONGFIELDLEN-1);
872 if (NULL == media->unidentified_attributes)
874 media->unidentified_attributes_count = 0;
875 media->unidentified_attributes =
876 calloc (UNIDENTIFIED_ATTRIBUTES_MAX_COUNT,
877 sizeof (char *));
879 if (media->unidentified_attributes_count <
880 UNIDENTIFIED_ATTRIBUTES_MAX_COUNT)
882 media->unidentified_attributes
883 [media->unidentified_attributes_count] =
884 strdup (longfsdp_buf);
885 media->unidentified_attributes_count++;
888 NEXT_LINE (p);
890 else
891 return FSDPE_INVALID_ATTRIBUTE;
893 } /* end of for */
896 /* Check c= has been given at session level or at media level for
897 all media */
898 if (NULL == dsc->c_address.address)
900 unsigned int c;
901 for (c = 0; c < dsc->media_announcements_count; c++)
902 if (NULL == dsc->media_announcements[c]->c_address.address)
903 return FSDPE_MISSING_CONNECTION_INFO;
906 /* finish */
907 if (*p == '\0')
908 return FSDPE_OK;
909 else
910 return FSDPE_OVERFILLED;
913 static fsdp_error_t
914 fsdp_parse_c (const char **p, fsdp_network_type_t * ntype,
915 fsdp_address_type_t * atype,
916 fsdp_connection_address_t * address)
918 const unsigned int TEMPCHARS = 3;
919 char fsdp_buf[TEMPCHARS][MAXSHORTFIELDLEN];
921 if (!strncmp (*p, "c=", 2))
923 if (sscanf (*p, "c=%2s %3s %" MSFLENS "s",
924 fsdp_buf[0], fsdp_buf[1], fsdp_buf[2]))
926 if (!strncmp (fsdp_buf[0], "IN", 2))
928 *ntype = FSDP_NETWORK_TYPE_INET;
929 if (!strncmp (fsdp_buf[1], "IP4", 3))
930 *atype = FSDP_ADDRESS_TYPE_IPV4;
931 else if (!strncmp (fsdp_buf[1], "IP6", 3))
932 *atype = FSDP_ADDRESS_TYPE_IPV6;
933 else
934 return FSDPE_INVALID_CONNECTION_NETTYPE;
936 else
938 return FSDPE_INVALID_CONNECTION_ADDRTYPE;
941 char *slash = strchr (fsdp_buf[2], '/');
942 if (NULL == slash)
944 address->address = strdup (fsdp_buf[2]);
945 address->address_ttl = 0;
946 address->address_count = 0;
948 else
950 /* address is IP4 multicast */
951 char *slash2;
952 *slash = '\0';
953 slash++;
954 address->address = strdup (fsdp_buf[2]);
955 slash2 = strchr (slash + 1, '/');
956 if (NULL == slash2)
958 address->address_ttl = strtol (slash, NULL, 10);
959 address->address_count = 0;
961 else
963 *slash2 = '\0';
964 slash2++;
965 address->address_ttl = strtol (slash, NULL, 10);
966 address->address_count = strtol (slash2, NULL, 10);
970 NEXT_LINE (*p);
972 else
974 return FSDPE_INVALID_CONNECTION;
977 return FSDPE_OK;
980 static fsdp_error_t
981 fsdp_parse_b (const char **p, fsdp_bw_modifier_t ** bw_modifiers,
982 unsigned int *bw_modifiers_count)
984 char fsdp_buf[MAXSHORTFIELDLEN];
985 unsigned long int wuint;
986 unsigned int i = 0;
987 const char *lp = *p;
989 /* count b= lines */
990 while (!strncmp (lp, "b=", 2))
992 NEXT_LINE (lp);
993 i++;
995 *bw_modifiers = calloc (i, sizeof (fsdp_bw_modifier_t));
996 *bw_modifiers_count = i;
998 while (i > 0)
1000 unsigned int index = *bw_modifiers_count - i;
1001 if (2 == sscanf (*p, "b=%20[^:\r\n]:%lu", fsdp_buf, &wuint))
1003 if (!strncmp (fsdp_buf, "CT", 2))
1004 (*bw_modifiers)[index].b_mod_type =
1005 FSDP_BW_MOD_TYPE_CONFERENCE_TOTAL;
1006 else if (!strncmp (fsdp_buf, "AS", 2))
1007 (*bw_modifiers)[index].b_mod_type =
1008 FSDP_BW_MOD_TYPE_APPLICATION_SPECIFIC;
1009 else if (!strncmp (fsdp_buf, "RS", 2))
1010 (*bw_modifiers)[index].b_mod_type = FSDP_BW_MOD_TYPE_RTCP_SENDERS;
1011 else if (!strncmp (fsdp_buf, "RR", 2))
1012 (*bw_modifiers)[index].b_mod_type =
1013 FSDP_BW_MOD_TYPE_RTCP_RECEIVERS;
1014 else
1016 (*bw_modifiers)[index].b_mod_type = FSDP_BW_MOD_TYPE_UNKNOWN;
1017 (*bw_modifiers)[index].b_unknown_bw_modt =
1018 (char *) strdup (fsdp_buf);
1020 (*bw_modifiers)[index].b_value = wuint;
1021 NEXT_LINE (*p);
1023 else
1025 *bw_modifiers_count -= i;
1026 return FSDPE_INVALID_BANDWIDTH;
1028 i--;
1030 return FSDPE_OK;
1033 static fsdp_error_t
1034 fsdp_parse_k (const char **p, fsdp_encryption_method_t * method,
1035 char **content)
1037 char fsdp_buf[MAXSHORTFIELDLEN];
1038 char longfsdp_buf[MAXLONGFIELDLEN];
1040 if (!strncmp (*p, "k=", 2))
1042 if (sscanf (*p, "k=prompt"))
1044 *method = FSDP_ENCRYPTION_METHOD_PROMPT;
1045 *content = NULL;
1046 NEXT_LINE (*p);
1048 else
1050 if (sscanf
1051 (*p, "k=%6[^:\r\n]:%" MLFLENS "s", fsdp_buf, longfsdp_buf))
1053 if (!strncmp (fsdp_buf, "clear", 5))
1054 *method = FSDP_ENCRYPTION_METHOD_CLEAR;
1055 else if (!strncmp (fsdp_buf, "base64", 6))
1056 *method = FSDP_ENCRYPTION_METHOD_BASE64;
1057 else if (!strncmp (fsdp_buf, "uri", 3))
1058 *method = FSDP_ENCRYPTION_METHOD_URI;
1059 else
1060 return FSDPE_INVALID_ENCRYPTION_METHOD;
1061 *content = strdup (longfsdp_buf);
1062 NEXT_LINE (*p);
1066 return FSDPE_OK;
1069 static fsdp_error_t
1070 fsdp_parse_rtpmap (fsdp_rtpmap_t *** rtpmap, unsigned int *counter,
1071 const char *value)
1073 fsdp_error_t result = FSDPE_OK;
1075 if (0 == *counter)
1077 *counter = 0;
1078 *rtpmap = calloc (MEDIA_RTPMAPS_MAX_COUNT, sizeof (fsdp_rtpmap_t *));
1080 if (*counter < MEDIA_RTPMAPS_MAX_COUNT)
1082 unsigned int c = *counter;
1083 fsdp_rtpmap_t **map = *rtpmap;
1084 char fsdp_buf[MAXSHORTFIELDLEN];
1085 char longfsdp_buf[MAXLONGFIELDLEN];
1086 map[c] = calloc (1, sizeof (fsdp_rtpmap_t));
1088 /* a=rtpmap:<payload type> <encoding name>/<clock rate>[/<encoding
1089 parameters]> */
1090 if (2 == sscanf (value, "%s %s", fsdp_buf, longfsdp_buf))
1092 char *slash1;
1093 map[c]->pt = strdup (fsdp_buf);
1094 /* parse <encoding name>/<clock rate>[/<encoding parameters>] */
1095 slash1 = strchr (longfsdp_buf, '/');
1096 if (NULL == slash1)
1098 result = FSDPE_INVALID_ATTRIBUTE_RTPMAP;
1100 else
1102 char *slash2;
1103 *slash1 = '\0';
1104 slash1++;
1105 map[c]->encoding_name = strdup (longfsdp_buf);
1106 slash2 = strchr (slash1, '/');
1107 if (NULL != slash2)
1109 *slash2 = '\0';
1110 slash2++;
1111 map[c]->parameters = strdup (slash2);
1113 map[c]->clock_rate = strtol (slash1, NULL, 10);
1115 (*counter)++;
1118 return result;
1121 static fsdp_error_t
1122 fsdp_repeat_time_to_uint (const char *time, unsigned long int *seconds)
1124 const unsigned long SECONDS_PER_DAY = 86400;
1125 const unsigned long SECONDS_PER_HOUR = 3600;
1126 const unsigned long SECONDS_PER_MINUTE = 60;
1127 char c;
1128 unsigned long int wuint;
1130 if (sscanf (time, "%lu%c", &wuint, &c) == 2)
1132 /* time with unit specification character */
1133 switch (c)
1135 case 'd':
1136 *seconds = wuint * SECONDS_PER_DAY;
1137 break;
1138 case 'h':
1139 *seconds = wuint * SECONDS_PER_HOUR;
1140 break;
1141 case 'm':
1142 *seconds = wuint * SECONDS_PER_MINUTE;
1143 break;
1144 case 's':
1145 *seconds = wuint;
1146 break;
1147 default:
1148 return FSDPE_INVALID_REPEAT;
1149 break;
1152 else if (sscanf (time, "%lu", &wuint) == 1)
1154 /* time without unit specification character */
1155 *seconds = wuint;
1157 else
1159 return FSDPE_INVALID_REPEAT;
1161 return FSDPE_OK;
1164 unsigned int
1165 fsdp_get_version (const fsdp_description_t * dsc)
1167 if (!dsc)
1168 return 0;
1169 return dsc->version;
1172 const char *
1173 fsdp_get_owner_username (const fsdp_description_t * dsc)
1175 if (!dsc)
1176 return NULL;
1177 return dsc->o_username;
1180 const char *
1181 fsdp_get_session_id (const fsdp_description_t * dsc)
1183 if (!dsc)
1184 return NULL;
1185 return dsc->o_session_id;
1188 const char *
1189 fsdp_get_announcement_version (const fsdp_description_t * dsc)
1191 if (!dsc)
1192 return NULL;
1193 return dsc->o_announcement_version;
1196 fsdp_network_type_t
1197 fsdp_get_owner_network_type (const fsdp_description_t * dsc)
1199 if (!dsc)
1200 return FSDP_NETWORK_TYPE_UNDEFINED;
1201 return dsc->o_network_type;
1204 fsdp_address_type_t
1205 fsdp_get_owner_address_type (const fsdp_description_t * dsc)
1207 if (!dsc)
1208 return FSDP_ADDRESS_TYPE_UNDEFINED;
1209 return dsc->o_address_type;
1212 const char *
1213 fsdp_get_owner_address (const fsdp_description_t * dsc)
1215 if (!dsc)
1216 return NULL;
1217 return dsc->o_address;
1220 const char *
1221 fsdp_get_name (const fsdp_description_t * dsc)
1223 if (!dsc)
1224 return NULL;
1225 return dsc->s_name;
1228 const char *
1229 fsdp_get_information (const fsdp_description_t * dsc)
1231 if (!dsc)
1232 return NULL;
1233 return dsc->i_information;
1236 const char *
1237 fsdp_get_uri (const fsdp_description_t * dsc)
1239 if (!dsc)
1240 return NULL;
1241 return dsc->u_uri;
1244 unsigned int
1245 fsdp_get_emails_count (const fsdp_description_t * dsc)
1247 if (!dsc)
1248 return 0;
1249 return dsc->emails_count;
1252 const char *
1253 fsdp_get_email (const fsdp_description_t * dsc, unsigned int index)
1255 if ((!dsc) || (index >= dsc->emails_count))
1256 return NULL;
1257 return dsc->emails[index];
1260 unsigned int
1261 fsdp_get_phones_count (const fsdp_description_t * dsc)
1263 if (!dsc)
1264 return 0;
1265 return dsc->phones_count;
1268 const char *
1269 fsdp_get_phone (const fsdp_description_t * dsc, unsigned int index)
1271 if ((!dsc) || (index >= dsc->phones_count))
1272 return NULL;
1273 return dsc->phones[index];
1276 fsdp_network_type_t
1277 fsdp_get_global_conn_network_type (const fsdp_description_t * dsc)
1279 if (!dsc)
1280 return FSDP_NETWORK_TYPE_UNDEFINED;
1281 return dsc->c_network_type;
1284 fsdp_address_type_t
1285 fsdp_get_global_conn_address_type (const fsdp_description_t * dsc)
1287 if (!dsc)
1288 return FSDP_ADDRESS_TYPE_UNDEFINED;
1289 return dsc->c_address_type;
1292 const char *
1293 fsdp_get_global_conn_address (const fsdp_description_t * dsc)
1295 if (!dsc)
1296 return NULL;
1297 return dsc->c_address.address;
1300 unsigned int
1301 fsdp_get_global_conn_address_ttl (const fsdp_description_t * dsc)
1303 if (!dsc)
1304 return 0;
1305 return dsc->c_address.address_ttl;
1308 unsigned int
1309 fsdp_get_global_conn_address_count (const fsdp_description_t * dsc)
1311 if (!dsc)
1312 return 0;
1313 return dsc->c_address.address_count;
1316 unsigned int
1317 fsdp_get_bw_modifier_count (const fsdp_description_t * dsc)
1319 if (!dsc)
1320 return 0;
1321 return dsc->bw_modifiers_count;
1324 fsdp_bw_modifier_type_t
1325 fsdp_get_bw_modifier_type (const fsdp_description_t * dsc, unsigned int index)
1327 if ((!dsc) || (index >= dsc->bw_modifiers_count))
1328 return FSDP_BW_MOD_TYPE_UNDEFINED;
1329 return dsc->bw_modifiers[index].b_mod_type;
1332 const char *
1333 fsdp_get_bw_modifier_type_unknown (const fsdp_description_t * dsc,
1334 unsigned int index)
1336 if ((!dsc) || (index >= dsc->bw_modifiers_count) ||
1337 (dsc->bw_modifiers[index].b_mod_type != FSDP_BW_MOD_TYPE_UNKNOWN))
1338 return NULL;
1339 return dsc->bw_modifiers[index].b_unknown_bw_modt;
1342 unsigned long int
1343 fsdp_get_bw_value (const fsdp_description_t * dsc, unsigned int index)
1345 if ((!dsc) || (index >= dsc->bw_modifiers_count))
1346 return 0;
1347 return dsc->bw_modifiers[index].b_value;
1350 time_t
1351 fsdp_get_period_start (const fsdp_description_t * dsc, unsigned int index)
1353 if ((!dsc) || (index >= dsc->time_periods_count))
1354 return 0;
1355 return dsc->time_periods[index]->start;
1358 time_t
1359 fsdp_get_period_stop (const fsdp_description_t * dsc, unsigned int index)
1361 if ((!dsc) || (index >= dsc->time_periods_count))
1362 return 0;
1363 return dsc->time_periods[index]->stop;
1366 unsigned int
1367 fsdp_get_period_repeats_count (const fsdp_description_t * dsc,
1368 unsigned int index)
1370 if ((!dsc) || (index >= dsc->time_periods_count))
1371 return 0;
1372 return dsc->time_periods[index]->repeats_count;
1375 unsigned long int
1376 fsdp_get_period_repeat_interval (const fsdp_description_t * dsc,
1377 unsigned int index, unsigned int rindex)
1379 if ((!dsc) || (index >= dsc->time_periods_count))
1380 return 0;
1381 return dsc->time_periods[index]->repeats[rindex]->interval;
1384 unsigned long int
1385 fsdp_get_period_repeat_duration (const fsdp_description_t * dsc,
1386 unsigned int index, unsigned int rindex)
1388 if ((!dsc) || (index >= dsc->time_periods_count))
1389 return 0;
1390 return dsc->time_periods[index]->repeats[rindex]->duration;
1393 const unsigned long int *
1394 fsdp_get_period_repeat_offsets (const fsdp_description_t * dsc,
1395 unsigned int index, unsigned int rindex)
1397 if ((!dsc) || (index >= dsc->time_periods_count))
1398 return NULL;
1399 return dsc->time_periods[index]->repeats[rindex]->offsets;
1402 const char *
1403 fsdp_get_timezone_adj (const fsdp_description_t * dsc)
1405 if (!dsc)
1406 return NULL;
1407 return dsc->timezone_adj;
1410 unsigned int
1411 fsdp_get_unidentified_attribute_count (const fsdp_description_t * dsc)
1413 if (!dsc)
1414 return 0;
1415 return dsc->unidentified_attributes_count;
1418 const char *
1419 fsdp_get_unidentified_attribute (const fsdp_description_t * dsc,
1420 unsigned int index)
1422 if (!dsc || (index < dsc->unidentified_attributes_count))
1423 return NULL;
1424 return dsc->unidentified_attributes[index];
1427 fsdp_encryption_method_t
1428 fsdp_get_encryption_method (const fsdp_description_t * dsc)
1430 if (!dsc)
1431 return FSDP_ENCRYPTION_METHOD_UNDEFINED;
1432 return dsc->k_encryption_method;
1435 const char *
1436 fsdp_get_encryption_content (const fsdp_description_t * dsc)
1438 if (!dsc || (dsc->k_encryption_method == FSDP_ENCRYPTION_METHOD_UNDEFINED))
1439 return NULL;
1440 return dsc->k_encryption_content;
1443 unsigned int
1444 fsdp_get_rtpmap_count (const fsdp_description_t * dsc)
1446 if (!dsc)
1447 return 0;
1448 return dsc->a_rtpmaps_count;
1451 const char *
1452 fsdp_get_rtpmap_payload_type (const fsdp_description_t * dsc,
1453 unsigned int index)
1455 if ((!dsc) || (index >= dsc->a_rtpmaps_count))
1456 return NULL;
1457 return dsc->a_rtpmaps[index]->pt;
1460 const char *
1461 fsdp_get_rtpmap_encoding_name (const fsdp_description_t * dsc,
1462 unsigned int index)
1464 if ((!dsc) || (index >= dsc->a_rtpmaps_count))
1465 return NULL;
1466 return dsc->a_rtpmaps[index]->encoding_name;
1469 unsigned int
1470 fsdp_get_rtpmap_clock_rate (const fsdp_description_t * dsc,
1471 unsigned int index)
1473 if ((!dsc) || (index >= dsc->a_rtpmaps_count))
1474 return 0;
1475 return dsc->a_rtpmaps[index]->clock_rate;
1478 const char *
1479 fsdp_get_rtpmap_encoding_parameters (const fsdp_description_t * dsc,
1480 unsigned int index)
1482 if ((!dsc) || (index >= dsc->a_rtpmaps_count))
1483 return NULL;
1484 return dsc->a_rtpmaps[index]->parameters;
1487 const char *
1488 fsdp_get_str_att (const fsdp_description_t * dsc, fsdp_session_str_att_t att)
1490 /*TODO: change these individual attributes with a table, thus
1491 avoiding this slow switch */
1492 char *result;
1494 if (!dsc)
1495 return NULL;
1497 switch (att)
1499 case FSDP_SESSION_STR_ATT_CATEGORY:
1500 result = dsc->a_category;
1501 break;
1502 case FSDP_SESSION_STR_ATT_KEYWORDS:
1503 result = dsc->a_keywords;
1504 break;
1505 case FSDP_SESSION_STR_ATT_TOOL:
1506 result = dsc->a_tool;
1507 break;
1508 case FSDP_SESSION_STR_ATT_CHARSET:
1509 result = dsc->a_charset;
1510 break;
1511 default:
1512 result = NULL;
1514 return result;
1517 unsigned int
1518 fsdp_get_sdplang_count (const fsdp_description_t * dsc)
1520 if (!dsc)
1521 return 0;
1522 return dsc->a_sdplangs_count;
1525 const char *
1526 fsdp_get_sdplang (const fsdp_description_t * dsc, unsigned int index)
1528 if ((!dsc) || (index >= dsc->a_sdplangs_count))
1529 return NULL;
1530 return dsc->a_sdplangs[index];
1533 unsigned int
1534 fsdp_get_lang_count (const fsdp_description_t * dsc)
1536 if (!dsc)
1537 return 0;
1538 return dsc->a_langs_count;
1541 const char *
1542 fsdp_get_lang (const fsdp_description_t * dsc, unsigned int index)
1544 if ((!dsc) || (index >= dsc->a_langs_count))
1545 return NULL;
1546 return dsc->a_langs[index];
1549 unsigned int
1550 fsdp_get_control_count (const fsdp_description_t * dsc)
1552 if (!dsc)
1553 return 0;
1554 return dsc->a_controls_count;
1557 const char *
1558 fsdp_get_control (const fsdp_description_t * dsc, unsigned int index)
1560 if ((!dsc) || (index >= dsc->a_controls_count))
1561 return NULL;
1562 return dsc->a_controls[index];
1565 const char *
1566 fsdp_get_range (const fsdp_description_t * dsc)
1568 return dsc->a_range;
1571 fsdp_sendrecv_mode_t
1572 fsdp_get_sendrecv_mode (const fsdp_description_t * dsc)
1574 if (!dsc)
1575 return FSDP_SENDRECV_UNDEFINED;
1576 return dsc->a_sendrecv_mode;
1579 fsdp_session_type_t
1580 fsdp_get_session_type (const fsdp_description_t * dsc)
1582 if (!dsc)
1583 return FSDP_SESSION_TYPE_UNDEFINED;
1584 return dsc->a_type;
1587 unsigned int
1588 fsdp_get_media_count (const fsdp_description_t * dsc)
1590 if (!dsc)
1591 return 0;
1592 return dsc->media_announcements_count;
1595 const fsdp_media_description_t *
1596 fsdp_get_media (const fsdp_description_t * dsc, unsigned int index)
1598 if ((index >= dsc->media_announcements_count))
1599 return NULL;
1600 return dsc->media_announcements[index];
1603 fsdp_media_t
1604 fsdp_get_media_type (const fsdp_media_description_t * dsc)
1606 if (!dsc)
1607 return FSDP_MEDIA_UNDEFINED;
1608 return dsc->media_type;
1611 unsigned int
1612 fsdp_get_media_port (const fsdp_media_description_t * dsc)
1614 if (!dsc)
1615 return 0;
1616 return dsc->port;
1619 unsigned int
1620 fsdp_get_media_port_count (const fsdp_media_description_t * dsc)
1622 if (!dsc)
1623 return 0;
1624 return dsc->port_count;
1627 fsdp_transport_protocol_t
1628 fsdp_get_media_transport_protocol (const fsdp_media_description_t * dsc)
1630 if (!dsc)
1631 return FSDP_TP_UNDEFINED;
1632 return dsc->transport;
1635 unsigned int
1636 fsdp_get_media_formats_count (const fsdp_media_description_t * dsc)
1638 if (!dsc)
1639 return 0;
1640 return dsc->formats_count;
1643 const char *
1644 fsdp_get_media_format (const fsdp_media_description_t * dsc,
1645 unsigned int index)
1647 if (!dsc || (index < dsc->formats_count - 1))
1648 return NULL;
1649 return dsc->formats[index];
1652 const char *
1653 fsdp_get_media_title (const fsdp_media_description_t * dsc)
1655 if (!dsc)
1656 return NULL;
1657 return dsc->i_title;
1660 fsdp_network_type_t
1661 fsdp_get_media_network_type (const fsdp_media_description_t * dsc)
1663 if (!dsc)
1664 return FSDP_NETWORK_TYPE_UNDEFINED;
1665 return dsc->c_network_type;
1668 fsdp_address_type_t
1669 fsdp_get_media_address_type (const fsdp_media_description_t * dsc)
1671 if (!dsc)
1672 return FSDP_ADDRESS_TYPE_UNDEFINED;
1673 return dsc->c_address_type;
1676 const char *
1677 fsdp_get_media_address (const fsdp_media_description_t * dsc)
1679 if (!dsc)
1680 return NULL;
1681 return dsc->c_address.address;
1684 unsigned int
1685 fsdp_get_media_address_ttl (const fsdp_media_description_t * mdsc)
1687 if (!mdsc)
1688 return 0;
1689 return mdsc->c_address.address_ttl;
1692 unsigned int
1693 fsdp_get_media_address_count (const fsdp_media_description_t * mdsc)
1695 if (!mdsc)
1696 return 0;
1697 return mdsc->c_address.address_count;
1700 fsdp_bw_modifier_type_t
1701 fsdp_get_media_bw_modifier_type (const fsdp_media_description_t * dsc,
1702 unsigned int index)
1704 if (!dsc || (index >= dsc->bw_modifiers_count))
1705 return FSDP_BW_MOD_TYPE_UNDEFINED;
1706 return dsc->bw_modifiers[index].b_mod_type;
1709 const char *
1710 fsdp_get_media_bw_modifier_type_unknown (const fsdp_media_description_t * dsc,
1711 unsigned int index)
1713 if (!dsc || (index >= dsc->bw_modifiers_count) ||
1714 (FSDP_BW_MOD_TYPE_UNKNOWN != dsc->bw_modifiers[index].b_mod_type))
1715 return NULL;
1716 return dsc->bw_modifiers[index].b_unknown_bw_modt;
1719 unsigned long int
1720 fsdp_get_media_bw_value (const fsdp_media_description_t * dsc,
1721 unsigned int index)
1723 if (!dsc || (index >= dsc->bw_modifiers_count))
1724 return 0;
1725 return dsc->bw_modifiers[index].b_value;
1728 fsdp_encryption_method_t
1729 fsdp_get_media_encryption_method (const fsdp_media_description_t * dsc)
1731 if (!dsc)
1732 return FSDP_ENCRYPTION_METHOD_UNDEFINED;
1733 return dsc->k_encryption_method;
1736 const char *
1737 fsdp_get_media_encryption_content (const fsdp_media_description_t * dsc)
1739 if (!dsc)
1740 return NULL;
1741 return dsc->k_encryption_content;
1744 unsigned int
1745 fsdp_get_media_ptime (const fsdp_media_description_t * dsc)
1747 if (!dsc)
1748 return 0;
1749 return dsc->a_ptime;
1752 unsigned int
1753 fsdp_get_media_maxptime (const fsdp_media_description_t * dsc)
1755 if (!dsc)
1756 return 0;
1757 return dsc->a_maxptime;
1760 unsigned int
1761 fsdp_get_media_rtpmap_count (const fsdp_media_description_t * mdsc)
1763 if (!mdsc)
1764 return 0;
1765 return mdsc->a_rtpmaps_count;
1768 const char *
1769 fsdp_get_media_rtpmap_payload_type (const fsdp_media_description_t * mdsc,
1770 unsigned int index)
1772 if (!mdsc || (index >= mdsc->a_rtpmaps_count))
1773 return NULL;
1774 return mdsc->a_rtpmaps[index]->pt;
1777 const char *
1778 fsdp_get_media_rtpmap_encoding_name (const fsdp_media_description_t * mdsc,
1779 unsigned int index)
1781 if (!mdsc || (index >= mdsc->a_rtpmaps_count))
1782 return NULL;
1783 return mdsc->a_rtpmaps[index]->encoding_name;
1786 unsigned int
1787 fsdp_get_media_rtpmap_clock_rate (const fsdp_media_description_t * mdsc,
1788 unsigned int index)
1790 if (!mdsc || (index >= mdsc->a_rtpmaps_count))
1791 return 0;
1792 return mdsc->a_rtpmaps[index]->clock_rate;
1795 const char *
1796 fsdp_get_media_rtpmap_encoding_parameters (const fsdp_description_t * mdsc,
1797 unsigned int index)
1799 if (!mdsc || (index >= mdsc->a_rtpmaps_count))
1800 return NULL;
1801 return mdsc->a_rtpmaps[index]->parameters;
1804 unsigned int
1805 fsdp_get_media_sdplang_count (const fsdp_media_description_t * mdsc)
1807 if (!mdsc)
1808 return 0;
1809 return mdsc->a_sdplangs_count;
1812 const char *
1813 fsdp_get_media_sdplang (const fsdp_media_description_t * mdsc,
1814 unsigned int index)
1816 if (!mdsc || (index >= mdsc->a_sdplangs_count))
1817 return NULL;
1818 return mdsc->a_sdplangs[index];
1821 unsigned int
1822 fsdp_get_media_lang_count (const fsdp_media_description_t * mdsc)
1824 if (!mdsc)
1825 return 0;
1826 return mdsc->a_langs_count;
1829 const char *
1830 fsdp_get_media_lang (const fsdp_media_description_t * mdsc,
1831 unsigned int index)
1833 if (!mdsc || (index >= mdsc->a_langs_count))
1834 return NULL;
1835 return mdsc->a_langs[index];
1838 unsigned int
1839 fsdp_get_media_control_count (const fsdp_media_description_t * mdsc)
1841 if (!mdsc)
1842 return 0;
1843 return mdsc->a_controls_count;
1846 char *
1847 fsdp_get_media_control (const fsdp_media_description_t * mdsc,
1848 unsigned int index)
1850 if (!mdsc || (index >= mdsc->a_controls_count))
1851 return NULL;
1852 return mdsc->a_controls[index];
1855 char *
1856 fsdp_get_media_range (const fsdp_media_description_t * mdsc)
1858 return mdsc->a_range;
1861 unsigned int
1862 fsdp_get_media_fmtp_count (const fsdp_media_description_t * mdsc)
1864 if (!mdsc)
1865 return 0;
1866 return mdsc->a_fmtps_count;
1869 const char *
1870 fsdp_get_media_fmtp (const fsdp_media_description_t * mdsc,
1871 unsigned int index)
1873 if (!mdsc || (index >= mdsc->a_fmtps_count))
1874 return NULL;
1875 return mdsc->a_fmtps[index];
1878 fsdp_orient_t
1879 fsdp_get_media_orient (const fsdp_media_description_t * dsc)
1881 if (!dsc)
1882 return FSDP_ORIENT_UNDEFINED;
1883 return dsc->a_orient;
1886 fsdp_sendrecv_mode_t
1887 fsdp_get_media_sendrecv (const fsdp_media_description_t * dsc)
1889 if (!dsc)
1890 return FSDP_SENDRECV_UNDEFINED;
1891 return dsc->a_sendrecv_mode;
1894 float
1895 fsdp_get_media_framerate (const fsdp_media_description_t * dsc)
1897 if (!dsc)
1898 return 0;
1899 return dsc->a_framerate;
1902 unsigned int
1903 fsdp_get_media_quality (const fsdp_media_description_t * dsc)
1905 if (!dsc)
1906 return 0;
1907 return dsc->a_quality;
1910 unsigned int
1911 fsdp_get_media_rtcp_port (const fsdp_media_description_t * dsc)
1913 if (!dsc)
1914 return 0;
1915 return dsc->a_rtcp_port;
1918 fsdp_network_type_t
1919 fsdp_get_media_rtcp_network_type (const fsdp_media_description_t * dsc)
1921 if (!dsc)
1922 return FSDP_NETWORK_TYPE_UNDEFINED;
1923 return dsc->a_rtcp_network_type;
1926 fsdp_address_type_t
1927 fsdp_get_media_rtcp_address_type (const fsdp_media_description_t * dsc)
1929 if (!dsc)
1930 return FSDP_ADDRESS_TYPE_UNDEFINED;
1931 return dsc->a_rtcp_address_type;
1934 const char *
1935 fsdp_get_media_rtcp_address (const fsdp_media_description_t * dsc)
1937 if (!dsc)
1938 return NULL;
1939 return dsc->a_rtcp_address;
1942 unsigned int
1943 fsdp_get_media_unidentified_attribute_count (const fsdp_media_description_t
1944 * mdsc)
1946 if (!mdsc)
1947 return 0;
1948 return mdsc->unidentified_attributes_count;
1951 const char *
1952 fsdp_get_media_unidentified_attribute (const fsdp_media_description_t * mdsc,
1953 unsigned int index)
1955 if (!mdsc || (index < mdsc->unidentified_attributes_count))
1956 return NULL;
1957 return mdsc->unidentified_attributes[index];