annotate libsip/sdp_gen.c @ 94:2c22b40408fb

sip-in BYE UAC: use new libsip function for response ident
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 24 Sep 2022 15:14:50 -0800
parents 9f045dcff60e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement generation of outgoing SDP descriptions.
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <netinet/in.h>
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <arpa/inet.h>
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "sdp.h"
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "out_msg.h"
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 format_sdp_in_buffer(gen, buf, lenptr)
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 struct sdp_gen *gen;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *buf;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 unsigned *lenptr;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 {
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char *dp, *codec_list;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 dp = buf;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 strcpy(dp, "v=0\r\n");
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 dp += 5;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 sprintf(dp, "o=- %u %u IN IP4 %s\r\n", gen->session_id, gen->version,
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 inet_ntoa(gen->owner_ip));
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 dp = index(dp, '\0');
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 strcpy(dp, "s=-\r\n");
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 dp += 5;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 sprintf(dp, "c=IN IP4 %s\r\n", inet_ntoa(gen->conn_ip));
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 dp = index(dp, '\0');
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 strcpy(dp, "t=0 0\r\n");
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 dp += 7;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 switch (gen->codec_mask) {
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 case SDP_CODEC_MASK_PCMU:
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 codec_list = "0";
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 break;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 case SDP_CODEC_MASK_PCMA:
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 codec_list = "8";
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 break;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 case SDP_CODEC_MASK_BOTH:
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 codec_list = "0 8";
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 break;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 case SDP_CODEC_MASK_BOTH | SDP_CODEC_MASK_PCMA_PREF:
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 codec_list = "8 0";
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 break;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 default:
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 return(-2);
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 sprintf(dp, "m=audio %u RTP/AVP %s\r\n", gen->conn_port, codec_list);
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 dp = index(dp, '\0');
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (gen->codec_mask & SDP_CODEC_MASK_PCMU) {
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 strcpy(dp, "a=rtpmap:0 PCMU/8000\r\n");
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 dp += 22;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (gen->codec_mask & SDP_CODEC_MASK_PCMA) {
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 strcpy(dp, "a=rtpmap:8 PCMA/8000\r\n");
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 dp += 22;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 strcpy(dp, "a=sendrecv\r\n");
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 dp += 12;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 strcpy(dp, "a=ptime:20\r\n");
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 dp += 12;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 *lenptr = (dp - buf);
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 return(0);
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 out_msg_finish_sdp(msg, gen)
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 struct sip_msg_out *msg;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 struct sdp_gen *gen;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 {
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 char sdp_buf[256];
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 unsigned sdp_len;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 int rc;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 rc = format_sdp_in_buffer(gen, sdp_buf, &sdp_len);
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (rc < 0)
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 return rc;
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 return out_msg_finish_body(msg, sdp_buf, sdp_len);
9f045dcff60e libsip: SDP generation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }