comparison libsip/sdp_parse.c @ 0:35c0d9f03c0a

beginning with sipout-test-voice, a copy of sip-manual-out from themwi-system-sw
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Mar 2024 23:20:19 -0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:35c0d9f03c0a
1 /*
2 * Here we implement the function that parses received SDP descriptions.
3 */
4
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <arpa/inet.h>
9 #include <ctype.h>
10 #include <string.h>
11 #include <strings.h>
12 #include <stdlib.h>
13 #include "../include/tmgw_const.h"
14 #include "sdp.h"
15
16 parse_incoming_sdp(body, bodylen, dist)
17 char *body;
18 unsigned bodylen;
19 struct sdp_parse *dist;
20 {
21 char *cp, *endp;
22 int got_c = 0, got_m = 0, prefer_pcma = 0;
23 unsigned codec;
24
25 cp = body;
26 endp = body + bodylen;
27 while (cp < endp) {
28 if (!islower(cp[0]) || cp[1] != '=')
29 return(-1);
30 switch (cp[0]) {
31 case 'c':
32 if (got_c)
33 return(-1);
34 got_c = 1;
35 if (strncmp(cp + 2, "IN IP4 ", 7))
36 return(-1);
37 cp += 9;
38 dist->ip_addr.s_addr = inet_addr(cp);
39 if (dist->ip_addr.s_addr == INADDR_NONE)
40 return(-1);
41 break;
42 case 'm':
43 if (got_m)
44 return(-1);
45 got_m = 1;
46 if (strncmp(cp + 2, "audio ", 6))
47 return(-1);
48 cp += 8;
49 if (!isdigit(*cp))
50 return(-1);
51 dist->audio_port = strtoul(cp, &cp, 10);
52 if (strncmp(cp, " RTP/AVP", 8))
53 return(-1);
54 cp += 8;
55 dist->codec_mask = 0;
56 for (;;) {
57 if (*cp == '\r' || *cp == '\n')
58 break;
59 if (*cp++ != ' ')
60 return(-1);
61 codec = strtoul(cp, &cp, 10);
62 switch (codec) {
63 case PSTN_CODEC_PCMU:
64 dist->codec_mask |= SDP_CODEC_MASK_PCMU;
65 break;
66 case PSTN_CODEC_PCMA:
67 if (!dist->codec_mask)
68 prefer_pcma = 1;
69 dist->codec_mask |= SDP_CODEC_MASK_PCMA;
70 break;
71 }
72 }
73 if (dist->codec_mask == SDP_CODEC_MASK_BOTH &&
74 prefer_pcma)
75 dist->codec_mask |= SDP_CODEC_MASK_PCMA_PREF;
76 break;
77 default:
78 cp += 2;
79 }
80 for (;;) {
81 if (cp >= endp)
82 return(-1);
83 if (!*cp)
84 return(-1);
85 if (*cp == '\n') {
86 cp++;
87 break;
88 }
89 if (*cp == '\r') {
90 cp++;
91 if (cp >= endp)
92 return(-1);
93 if (*cp++ != '\n')
94 return(-1);
95 break;
96 }
97 cp++;
98 }
99 }
100 if (got_c && got_m)
101 return(0);
102 else
103 return(-1);
104 }