-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathsdp_parse.c
More file actions
1955 lines (1680 loc) · 51.1 KB
/
Copy pathsdp_parse.c
File metadata and controls
1955 lines (1680 loc) · 51.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**@ingroup sdp_parser
* @CFILE sdp_parse.c
* @brief Simple SDP parser interface.
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
* @author Kai Vehmanen <kai.vehmanen@nokia.com>
*
* @date Created: Fri Feb 18 10:25:08 2000 ppessi
*
* @sa @RFC4566, @RFC2327.
*/
#include "config.h"
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/su_string.h>
#include "sofia-sip/sdp.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <limits.h>
#include <assert.h>
/** @typedef struct sdp_parser_s sdp_parser_t;
*
* SDP parser handle.
*
* The SDP parser handle returned by sdp_parse() contains either
* a successfully parsed SDP session #sdp_session_t or an error message.
* If sdp_session() returns non-NULL, parsing was successful.
*
* @sa #sdp_session_t, sdp_parse(), sdp_session(), sdp_parsing_error(),
* sdp_sanity_check(), sdp_parser_home(), sdp_parser_free(), @RFC4566,
* @RFC2327.
*/
struct sdp_parser_s {
su_home_t pr_home[1];
union {
char pru_error[128];
sdp_session_t pru_session[1];
} pr_output;
char *pr_message;
sdp_mode_t pr_session_mode;
unsigned pr_ok : 1;
unsigned pr_strict : 1;
unsigned pr_anynet : 1;
unsigned pr_mode_0000 : 1;
unsigned pr_mode_manual : 1;
unsigned pr_insane : 1;
unsigned pr_c_missing : 1;
unsigned pr_config : 1;
};
#define is_posdigit(c) ((c) >= '1' && (c) <= '9')
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define is_space(c) ((c) == ' ')
#define is_tab(c) ((c) == '\t')
#define pr_error pr_output.pru_error
#define pr_session pr_output.pru_session
#ifdef _MSC_VER
#undef STRICT
#endif
#define STRICT(pr) (pr->pr_strict)
/* Static parser object used when running out of memory */
static const struct sdp_parser_s no_mem_error =
{
{ SU_HOME_INIT(no_mem_error) },
{ "sdp: not enough memory" }
};
/* Internal prototypes */
static void parse_message(sdp_parser_t *p);
static int parsing_error(sdp_parser_t *p, char const *fmt, ...);
/** Parse an SDP message.
*
* The function sdp_parse() parses an SDP message @a msg of size @a
* msgsize. If msgsize is -1, the size of message is calculated using
* strlen().
*
* Parsing is done according to the given @a flags.
*
* The SDP message may not contain a NUL.
*
* The parsing result is stored to an #sdp_session_t structure.
*
* @param home memory home
* @param msg pointer to message
* @param msgsize size of the message (excluding final NUL, if any)
* @param flags flags affecting the parsing.
*
* The following flags are used by parser:
*
* @li #sdp_f_strict Parser should accept only messages conforming strictly
* to the specification.
* @li #sdp_f_anynet Parser accepts unknown network or address types.
* @li #sdp_f_insane Do not run sanity check.
* @li #sdp_f_c_missing Sanity check does not require c= for each m= line
* @li #sdp_f_mode_0000 Parser regards "c=IN IP4 0.0.0.0" as "a=inactive"
* (likewise with c=IN IP6 ::)
* @li #sdp_f_mode_manual Do not generate or parse SDP mode
* @li #sdp_f_config Parse config files (any line can be missing)
*
* @return
* Always a valid parser handle.
*
* @todo Parser accepts some non-conforming SDP even with #sdp_f_strict.
*
* @sa sdp_session(), sdp_parsing_error(), sdp_sanity_check(),
* sdp_parser_home(), sdp_parser_free(), @RFC4566, @RFC2327.
*/
sdp_parser_t *
sdp_parse(su_home_t *home, char const msg[], issize_t msgsize, int flags)
{
sdp_parser_t *p;
char *b;
size_t len;
if (msg == NULL) {
p = su_home_clone(home, sizeof(*p));
if (p)
parsing_error(p, "invalid input message");
else
p = (sdp_parser_t*)&no_mem_error;
return p;
}
if (msgsize == -1)
len = strlen(msg);
else
len = msgsize;
if (len > ISSIZE_MAX)
len = ISSIZE_MAX;
p = su_home_clone(home, sizeof(*p) + len + 1);
if (p) {
b = strncpy((void *)(p + 1), msg, len);
b[len] = 0;
p->pr_message = b;
p->pr_strict = (flags & sdp_f_strict) != 0;
p->pr_anynet = (flags & sdp_f_anynet) != 0;
p->pr_mode_0000 = (flags & sdp_f_mode_0000) != 0;
p->pr_insane = (flags & sdp_f_insane) != 0;
p->pr_c_missing = (flags & sdp_f_c_missing) != 0;
if (flags & sdp_f_config)
p->pr_c_missing = 1, p->pr_config = 1;
p->pr_mode_manual = (flags & sdp_f_mode_manual) != 0;
p->pr_session_mode = sdp_sendrecv;
parse_message(p);
return p;
}
if (p)
sdp_parser_free(p);
return (sdp_parser_t*)&no_mem_error;
}
/** Obtain memory home used by parser */
su_home_t *sdp_parser_home(sdp_parser_t *parser)
{
if (parser != &no_mem_error)
return parser->pr_home;
else
return NULL;
}
/** Retrieve an SDP session structure.
*
* The function sdp_session() returns a pointer to the SDP session
* structure associated with the SDP parser @a p. The pointer and all the
* data in the structure are valid until sdp_parser_free() is called.
*
* @param p SDP parser
*
* @return
* The function sdp_session() returns a pointer to an parsed SDP message
* or NULL, if an error has occurred. */
sdp_session_t *
sdp_session(sdp_parser_t *p)
{
return p && p->pr_ok ? p->pr_session : NULL;
}
/** Get a parsing error message.
*
* The function sdp_parsing_error() returns the error message associated
* with an SDP parser @a p.
*
* @param p SDP parser
*
* @return
* The function sdp_parsing_error() returns a C string describing parsing
* error, or NULL if no error occurred.
*/
char const *sdp_parsing_error(sdp_parser_t *p)
{
return !p->pr_ok ? p->pr_error : NULL;
}
/** Free an SDP parser.
*
* The function sdp_parser_free() frees an SDP parser object along with
* the memory blocks associated with it.
*
* @param p pointer to the SDP parser to be freed
*/
void sdp_parser_free(sdp_parser_t *p)
{
if (p && p != &no_mem_error)
su_home_unref(p->pr_home);
}
/* ========================================================================= */
/* =========================================================================
* Private part
*/
/* Parsing tokens */
#define SPACE " "
#define TAB "\011"
#define CRLF "\015\012"
#define ALPHA "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define DIGIT "0123456789"
#define TOKEN ALPHA DIGIT "-!#$%&'*+.^_`{|}~"
/* ========================================================================= */
/* Parsing functions */
static void post_session(sdp_parser_t *p, sdp_session_t *sdp);
static void parse_origin(sdp_parser_t *p, char *r, sdp_origin_t **result);
static void parse_subject(sdp_parser_t *p, char *r, sdp_text_t **result);
static void parse_information(sdp_parser_t *p, char *r, sdp_text_t **result);
static void parse_uri(sdp_parser_t *p, char *r, sdp_text_t **result);
static void parse_email(sdp_parser_t *p, char *r, sdp_list_t **result);
static void parse_phone(sdp_parser_t *p, char *r, sdp_list_t **result);
static void parse_connection(sdp_parser_t *p, char *r, sdp_connection_t **result);
static void parse_bandwidth(sdp_parser_t *p, char *r, sdp_bandwidth_t **result);
static void parse_time(sdp_parser_t *p, char *r, sdp_time_t **result);
static void parse_repeat(sdp_parser_t *p, char *r, sdp_repeat_t **result);
static void parse_zone(sdp_parser_t *p, char *r, sdp_zone_t **result);
static void parse_key(sdp_parser_t *p, char *r, sdp_key_t **result);
static void parse_session_attr(sdp_parser_t *p, char *r, sdp_attribute_t **result);
static void parse_media(sdp_parser_t *p, char *r, sdp_media_t **result);
static void parse_payload(sdp_parser_t *p, char *r, sdp_rtpmap_t **result);
static void parse_media_attr(sdp_parser_t *p, char *r, sdp_media_t *m,
sdp_attribute_t **result);
static int parse_rtpmap(sdp_parser_t *p, char *r, sdp_media_t *m);
static int parse_fmtp(sdp_parser_t *p, char *r, sdp_media_t *m);
static void parse_text_list(sdp_parser_t *p, char *r, sdp_list_t **result);
static void parse_descs(sdp_parser_t *p, char *r, char *m, sdp_media_t **result);
static int parse_ul(sdp_parser_t *p, char **r, unsigned long *result,
unsigned long max_value);
static int parse_ull(sdp_parser_t *p, char **r, uint64_t *result,
uint64_t max_value);
static void parse_alloc_error(sdp_parser_t *p, const char *typename);
static char *next(char **message, const char *sep, const char *strip);
static char *token(char **message, const char *sep, const char *legal,
const char *strip);
#if 0
static void check_mandatory(sdp_parser_t *p, sdp_session_t *sdp);
#endif
/* -------------------------------------------------------------------------
* Macro PARSE_ALLOC
*
* Description:
* This macro declares a pointer (v) of given type (t). It then allocates
* an structure of given type (t). If allocation was succesful, it assigns
* the XX_size member with appropriate value.
*/
#define PARSE_ALLOC(p, t, v) \
t *v = su_salloc(p->pr_home, sizeof(*v)); \
if (!v && (parse_alloc_error(p, #t), 1)) return;
/* -------------------------------------------------------------------------
* Macro PARSE_CHECK_REST
*
* Description:
* This macro check if there is extra data at the end of field.
*/
#define PARSE_CHECK_REST(p, s, n)\
if (*s && (parsing_error(p, "extra data after %s (\"%.04s\")", n, s), 1)) \
return
/* -------------------------------------------------------------------------
* Function parse_message() - parse an SDP message
*
* Description:
* This function parses an SDP message, which is copied into the
* p->pr_message. The p->pr_message is modified during the parsing,
* and parts of it are returned in p->pr_session.
*
* Parameters:
* p - pointer to SDP parser object
*/
static void parse_message(sdp_parser_t *p)
{
/*
announcement = proto-version
origin-field
session-name-field
information-field
uri-field
email-fields
phone-fields
connection-field
bandwidth-fields
time-fields
key-field
attribute-fields
media-descriptions
*/
sdp_session_t *sdp = p->pr_session;
char *record, *rest;
char const *strip;
char *message = p->pr_message;
char field = '\0';
sdp_list_t **emails = &sdp->sdp_emails;
sdp_list_t **phones = &sdp->sdp_phones;
sdp_bandwidth_t **bandwidths = &sdp->sdp_bandwidths;
sdp_time_t **times = &sdp->sdp_time;
sdp_repeat_t **repeats = NULL;
sdp_zone_t **zones = NULL;
sdp_attribute_t **attributes = &sdp->sdp_attributes;
if (!STRICT(p))
strip = SPACE TAB; /* skip initial whitespace */
else
strip = "";
p->pr_ok = 1;
p->pr_session->sdp_size = sizeof(p->pr_session);
/* Require that version comes first */
record = next(&message, CRLF, strip);
if (!su_strmatch(record, "v=0")) {
if (!p->pr_config || !record || record[1] != '=') {
parsing_error(p, "bad SDP message");
return;
}
}
else {
record = next(&message, CRLF, strip);
}
/*
XXX - the lines in SDP are in certain order, which we don't check here.
For stricter parsing we might want to parse o= and s= next.
*/
for (;
record && p->pr_ok;
record = next(&message, CRLF, strip)) {
field = record[0];
if (strlen(record) < 2) {
return;
}
rest = record + 2; rest += strspn(rest, strip);
if (record[1] != '=') {
parsing_error(p, "bad line \"%s\"", record);
return;
}
switch (field) {
case 'o':
parse_origin(p, rest, &sdp->sdp_origin);
break;
case 's':
parse_subject(p, rest, &sdp->sdp_subject);
break;
case 'i':
parse_information(p, rest, &sdp->sdp_information);
break;
case 'u':
parse_uri(p, rest, &sdp->sdp_uri);
break;
case 'e':
parse_email(p, rest, emails);
emails = &(*emails)->l_next;
break;
case 'p':
parse_phone(p, rest, phones);
phones = &(*phones)->l_next;
break;
case 'c':
parse_connection(p, rest, &sdp->sdp_connection);
break;
case 'b':
parse_bandwidth(p, rest, bandwidths);
bandwidths = &(*bandwidths)->b_next;
break;
case 't':
parse_time(p, rest, times);
repeats = &(*times)->t_repeat;
zones = &(*times)->t_zone;
times = &(*times)->t_next;
break;
case 'r':
if (repeats)
parse_repeat(p, rest, repeats);
else
parsing_error(p, "repeat field without time field");
break;
case 'z':
if (zones)
parse_zone(p, rest, zones), zones = NULL;
else
parsing_error(p, "zone field without time field");
break;
case 'k':
parse_key(p, rest, &sdp->sdp_key);
break;
case 'a':
parse_session_attr(p, rest, attributes);
if (*attributes)
attributes = &(*attributes)->a_next;
break;
case 'm':
parse_descs(p, record, message, &sdp->sdp_media);
post_session(p, sdp);
return;
default:
parsing_error(p, "unknown field \"%s\"", record);
return;
}
}
post_session(p, sdp);
}
#ifdef SOFIA_AUTO_CORRECT_INADDR_ANY
int sdp_connection_is_inaddr_any(sdp_connection_t const *c)
{
return
c &&
c->c_nettype == sdp_net_in &&
((c->c_addrtype == sdp_addr_ip4 && su_strmatch(c->c_address, "0.0.0.0")) ||
(c->c_addrtype == sdp_addr_ip6 && su_strmatch(c->c_address, "::")));
}
#endif
/**Postprocess session description.
*
* Postprocessing includes setting the session backpointer for each media,
* doing sanity checks and setting rejected and mode flags.
*/
static void post_session(sdp_parser_t *p, sdp_session_t *sdp)
{
sdp_media_t *m;
#ifdef SOFIA_AUTO_CORRECT_INADDR_ANY
sdp_connection_t const *c;
#endif
if (!p->pr_ok)
return;
/* Set session back-pointer */
for (m = sdp->sdp_media; m; m = m->m_next) {
m->m_session = sdp;
}
if (p->pr_config) {
if (sdp->sdp_version[0] != 0)
parsing_error(p, "Incorrect version");
return;
}
/* Go through all media and set mode */
for (m = sdp->sdp_media; m; m = m->m_next) {
if (m->m_port == 0) {
m->m_mode = sdp_inactive;
m->m_rejected = 1;
continue;
}
#ifdef SOFIA_AUTO_CORRECT_INADDR_ANY
c = sdp_media_connections(m);
if (p->pr_mode_0000 && sdp_connection_is_inaddr_any(c)) {
/* Reset recvonly flag */
m->m_mode &= ~sdp_recvonly;
}
#endif
}
if (p->pr_insane)
return;
/* Verify that all mandatory fields are present */
if (sdp_sanity_check(p) < 0)
return;
}
/** Validates that all mandatory fields exist
*
* Checks that all necessary fields (v=, o=) exists in the parsed sdp. If
* strict, check that all mandatory fields (c=, o=, s=, t=) are present.
* This function also goes through all media, marks rejected media as such,
* and updates the mode accordingly.
*
* @retval 0 if parsed SDP description is valid
* @retval -1 if some SDP line is missing
* @retval -2 if c= line is missing
*/
int sdp_sanity_check(sdp_parser_t *p)
{
sdp_session_t *sdp = p->pr_session;
sdp_media_t *m;
if (!p || !p->pr_ok)
return -1;
else if (sdp->sdp_version[0] != 0)
return parsing_error(p, "Incorrect version");
else if (!sdp->sdp_origin)
return parsing_error(p, "No o= present");
else if (p->pr_strict && !sdp->sdp_subject)
return parsing_error(p, "No s= present");
else if (p->pr_strict && !sdp->sdp_time)
return parsing_error(p, "No t= present");
/* If there is no session level c= check that one exists for all media */
/* c= line may be missing if this is a RTSP description */
if (!p->pr_c_missing && !sdp->sdp_connection) {
for (m = sdp->sdp_media ; m ; m = m->m_next) {
if (!m->m_connections && !m->m_rejected) {
parsing_error(p, "No c= on either session level or all mediums");
return -2;
}
}
}
return 0;
}
#if 0
/**
* Parse a "v=" field
*
* The function parser_version() parses the SDP version field.
*
* @param p pointer to SDP parser object
* @param r pointer to record data
* @param result pointer to which parsed record is assigned
*/
static void parse_version(sdp_parser_t *p, char *r, sdp_version_t *result)
{
/*
proto-version = "v=" 1*DIGIT CRLF
;[RFC2327] describes version 0
*/
if (parse_ul(p, &r, result, 0))
parsing_error(p, "version \"%s\" is invalid", r);
else if (*result > 0)
parsing_error(p, "unknown version v=%s", r);
}
#endif
/* -------------------------------------------------------------------------
* Function parse_origin() - parse an "o=" field
*
* Description:
* This function parses an SDP origin field.
*
* Parameters:
* p - pointer to SDP parser object
* r - pointer to record data
* result - pointer to which parsed record is assigned
*/
static void parse_origin(sdp_parser_t *p, char *r, sdp_origin_t **result)
{
/*
origin-field = "o=" username space
sess-id space sess-version space
nettype space addrtype space
addr CRLF
username = safe
;pretty wide definition, but doesn't include space
sess-id = 1*(DIGIT)
;should be unique for this originating username/host
sess-version = 1*(DIGIT)
;0 is a new session
*/
PARSE_ALLOC(p, sdp_origin_t, o);
*result = o;
o->o_username = token(&r, SPACE TAB, NULL, SPACE TAB);
if (!o->o_username) {
parsing_error(p, "invalid username");
return;
}
if (parse_ull(p, &r, &o->o_id, 0)) {
parsing_error(p, "invalid session id");
return;
}
if (parse_ull(p, &r, &o->o_version, 0)) {
parsing_error(p, "invalid session version");
return;
}
parse_connection(p, r, &o->o_address);
}
/* -------------------------------------------------------------------------
* Function parse_subject() - parse an "s=" field
*
* Description:
* This function parses an SDP subject field.
*
* Parameters:
* p - pointer to SDP parser object
* r - pointer to record data
* result - pointer to which parsed record is assigned
*/
static void parse_subject(sdp_parser_t *p, char *r, sdp_text_t **result)
{
/*
session-name-field = "s=" text CRLF
text = byte-string
*/
*result = r;
}
/* -------------------------------------------------------------------------
* Function parse_information() - parse an "i=" field
*
* Description:
* This function parses an SDP information field.
*
* Parameters:
* p - pointer to SDP parser object
* r - pointer to record data
* result - pointer to which parsed record is assigned
*/
static void parse_information(sdp_parser_t *p, char *r, sdp_text_t **result)
{
/*
information-field = ["i=" text CRLF]
*/
if (result) *result = r;
}
/* -------------------------------------------------------------------------
* Function parse_uri() - parse an "u=" field
*
* Description:
* This function parses an SDP URI field.
*
* Parameters:
* p - pointer to SDP parser object
* r - pointer to record data
* result - pointer to which parsed record is assigned
*/
static void parse_uri(sdp_parser_t *p, char *r, sdp_text_t **result)
{
/*
uri-field = ["u=" uri CRLF]
uri= ;defined in RFC1630
*/
/* XXX - no syntax checking here */
*result = r;
}
/* -------------------------------------------------------------------------
* Function parse_email() - parse an "e=" field
*
* Description:
* This function parses an SDP email field.
*
* Parameters:
* p - pointer to SDP parser object
* r - pointer to record data
* result - pointer to which parsed record is assigned
*/
static void parse_email(sdp_parser_t *p, char *r, sdp_list_t **result)
{
/*
email-fields = *("e=" email-address CRLF)
email-address = email | email "(" email-safe ")" |
email-safe "<" email ">"
email = ;defined in RFC822 */
parse_text_list(p, r, result);
}
/* -------------------------------------------------------------------------
* Function parse_phone() - parse an "p=" field
*
* Description:
* This function parses an SDP phone field.
*
* Parameters:
* p - pointer to SDP parser object
* r - pointer to record data
* result - pointer to which parsed record is assigned
*/
static void parse_phone(sdp_parser_t *p, char *r, sdp_list_t **result)
{
/*
phone-fields = *("p=" phone-number CRLF)
phone-number = phone | phone "(" email-safe ")" |
email-safe "<" phone ">"
phone = "+" POS-DIGIT 1*(space | "-" | DIGIT)
;there must be a space or hyphen between the
;international code and the rest of the number.
*/
parse_text_list(p, r, result);
}
/* -------------------------------------------------------------------------
* Function parse_connection() - parse an "c=" field
*
* Description:
* This function parses an SDP connection field.
*
* Parameters:
* p - pointer to SDP parser object
* r - pointer to record data
* result - pointer to which parsed record is assigned
*/
static void parse_connection(sdp_parser_t *p, char *r, sdp_connection_t **result)
{
/*
connection-field = ["c=" nettype space addrtype space
connection-address CRLF]
;a connection field must be present
;in every media description or at the
;session-level
nettype = "IN"
;list to be extended
addrtype = "IP4" | "IP6"
;list to be extended
connection-address = multicast-address
| addr
multicast-address = 3*(decimal-uchar ".") decimal-uchar "/" ttl
[ "/" integer ]
;multicast addresses may be in the range
;224.0.0.0 to 239.255.255.255
ttl = decimal-uchar
addr = FQDN | unicast-address
FQDN = 4*(alpha-numeric|"-"|".")
;fully qualified domain name as specified in RFC1035
unicast-address = IP4-address | IP6-address
IP4-address = b1 "." decimal-uchar "." decimal-uchar "." b4
b1 = decimal-uchar
;less than "224"; not "0" or "127"
b4 = decimal-uchar
;not "0"
IP6-address = ;to be defined
*/
PARSE_ALLOC(p, sdp_connection_t, c);
*result = c;
if (su_casenmatch(r, "IN", 2)) {
char *s;
/* nettype is internet */
c->c_nettype = sdp_net_in;
s = token(&r, SPACE TAB, NULL, NULL);
/* addrtype */
s = token(&r, SPACE TAB, NULL, NULL);
if (su_casematch(s, "IP4"))
c->c_addrtype = sdp_addr_ip4;
else if (su_casematch(s, "IP6"))
c->c_addrtype = sdp_addr_ip6;
else {
parsing_error(p, "unknown IN address type: %s", s);
return;
}
/* address */
s = next(&r, SPACE TAB, SPACE TAB);
c->c_address = s;
if (!s || !*s) {
parsing_error(p, "invalid address");
return;
}
/* ttl */
s = strchr(s, '/');
if (s) {
unsigned long value;
*s++ = 0;
if (parse_ul(p, &s, &value, 256) ||
(*s && *s != '/')) {
parsing_error(p, "invalid ttl");
return;
}
c->c_ttl = value;
c->c_mcast = 1;
/* multiple groups */
value = 1;
if (*s++ == '/')
if (parse_ul(p, &s, &value, 0) || *s) {
parsing_error(p, "invalid number of multicast groups");
return;
}
c->c_groups = value;
}
else
c->c_groups = 1;
}
else if (p->pr_anynet) {
c->c_nettype = sdp_net_x;
c->c_addrtype = sdp_addr_x;
c->c_address = r;
c->c_ttl = 0;
c->c_groups = 1;
}
else
parsing_error(p, "invalid address");
}
/* -------------------------------------------------------------------------
* Function parse_bandwidth() - parse an "b=" field
*
* Description:
* This function parses an SDP bandwidth field.
*
* Parameters:
* p - pointer to SDP parser object
* r - pointer to record data
* result - pointer to which parsed record is assigned
*/
static void parse_bandwidth(sdp_parser_t *p, char *r, sdp_bandwidth_t **result)
{
/*
bandwidth-fields = *("b=" bwtype ":" bandwidth CRLF)
bwtype = token
bandwidth = 1*(DIGIT)
*/
/* NOTE: bwtype can also be like X-barf */
sdp_bandwidth_e modifier;
char *name;
unsigned long value;
name = token(&r, ":", TOKEN, SPACE TAB);
if (name == NULL || parse_ul(p, &r, &value, 0)) {
parsing_error(p, "invalid bandwidth");
return;
}
if (su_casematch(name, "CT"))
modifier = sdp_bw_ct, name = "CT";
else if (su_casematch(name, "TIAS") == 1)
modifier = sdp_bw_tias, name = "TIAS";
else if (su_casematch(name, "AS") == 1)
modifier = sdp_bw_as, name = "AS";
else if (su_casematch(name, "RS") == 1)
modifier = sdp_bw_rs, name = "RS";
else if (su_casematch(name, "RR") == 1)
modifier = sdp_bw_rr, name = "RR";
else
modifier = sdp_bw_x, name = "BW-X";
if (STRICT(p))
PARSE_CHECK_REST(p, r, "b");
{
PARSE_ALLOC(p, sdp_bandwidth_t, b);
*result = b;
b->b_modifier = modifier;
b->b_modifier_name = name;
b->b_value = value;
}
}
/* -------------------------------------------------------------------------
* Function parse_time() - parse an "t=" field
*
* Description:
* This function parses an SDP time field.
*
* Parameters:
* p - pointer to SDP parser object
* r - pointer to record data
* result - pointer to which parsed record is assigned
*/
static void parse_time(sdp_parser_t *p, char *r, sdp_time_t **result)
{
/*
time-fields = 1*( "t=" start-time SP stop-time
*(CRLF repeat-fields) CRLF)
[zone-adjustments CRLF]
start-time = time / "0"
stop-time = time / "0"
time = POS-DIGIT 9*DIGIT
; Decimal representation of NTP time in
; seconds since 1900. The representation
; of NTP time is an unbounded length field
; containing at least 10 digits. Unlike the
; 64-bit representation used elsewhere, time
; in SDP does not wrap in the year 2036.
*/
PARSE_ALLOC(p, sdp_time_t, t);
*result = t;
if (parse_ul(p, &r, &t->t_start, 0) ||
parse_ul(p, &r, &t->t_stop, 0))
parsing_error(p, "invalid time");
else if (STRICT(p)) {
PARSE_CHECK_REST(p, r, "t");
}
}
/**
* Parse an "r=" field
*
* The function parse_repeat() parses an SDP repeat field.
*