comparison sip-manual-out/sdp_in.c @ 191:6ac96217c442

sip-manual-out: add SDP response parsing
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 17 Mar 2023 12:07:17 -0800
parents sip-out/invite.c@bfa9f0c0f0ac
children f8a33603288f
comparison
equal deleted inserted replaced
190:62ecc0aa081f 191:6ac96217c442
1 /*
2 * In this module we handle SDP responses to our INVITE.
3 */
4
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <arpa/inet.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <strings.h>
13 #include "../libsip/parse.h"
14 #include "../libsip/sdp.h"
15
16 extern char *get_single_header();
17 extern char *extract_to_tag();
18
19 struct sockaddr_in rtp_remote_addr;
20 int pcma_selected;
21
22 static
23 check_sdp_present(msg)
24 struct sip_pkt_rx *msg;
25 {
26 char *hval;
27
28 if (!msg->msg_body_len)
29 return 0;
30 hval = get_single_header(msg, "Content-Type", "c", (int *) 0);
31 if (!hval)
32 return 0;
33 if (!strcasecmp(hval, "application/sdp"))
34 return 1;
35 else
36 return 0;
37 }
38
39 void
40 extract_resp_sdp(msg)
41 struct sip_pkt_rx *msg;
42 {
43 struct sdp_parse sdp_parse;
44 int rc;
45
46 if (!check_sdp_present(msg)) {
47 printf("INVITE response has no SDP!\n");
48 return;
49 }
50 rc = parse_incoming_sdp(msg->msg_body, msg->msg_body_len, &sdp_parse);
51 if (rc < 0) {
52 printf("SDP parse error: %d\n", rc);
53 return;
54 }
55 switch (sdp_parse.codec_mask) {
56 case SDP_CODEC_MASK_PCMU:
57 case SDP_CODEC_MASK_BOTH:
58 pcma_selected = 0;
59 break;
60 case SDP_CODEC_MASK_PCMA:
61 case SDP_CODEC_MASK_BOTH | SDP_CODEC_MASK_PCMA_PREF:
62 pcma_selected = 1;
63 break;
64 default:
65 printf("SDP error: no supported codec\n");
66 return;
67 }
68 printf("SDP response: IP %s port %u codec %s\n",
69 inet_ntoa(sdp_parse.ip_addr), sdp_parse.audio_port,
70 pcma_selected ? "PCMA" : "PCMU");
71 rtp_remote_addr.sin_family = AF_INET;
72 rtp_remote_addr.sin_addr = sdp_parse.ip_addr;
73 rtp_remote_addr.sin_port = htons(sdp_parse.audio_port);
74 }