annotate sip-manual-out/main.c @ 119:056616f7e8ab

sip-manual-out: convert command line to getopt style
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 29 Sep 2022 14:03:06 -0800
parents 51e2f72dc5ab
children c62d0f28da6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This is the main module for sip-manual-out test program.
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/time.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/socket.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/errno.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <netinet/in.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <arpa/inet.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <string.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <strings.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <unistd.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../libsip/out_msg.h"
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../libsip/sdp.h"
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern int sip_socket;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern struct in_addr sip_bind_ip, sip_dest_ip;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern unsigned sip_bind_port, sip_dest_port;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern char sip_dest_domain[];
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern struct sockaddr_in dummy_rtp_endp;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct sockaddr_in sip_dest_sin;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 char from_uri[128], to_uri[128], call_id[128];
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 struct timeval cur_event_time;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 send_invite_req()
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 struct sip_msg_out msg;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 struct sdp_gen sdp;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 int rc;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 rc = start_request_out_msg(&msg, "INVITE", to_uri);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (rc < 0) {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 msg_size_err: fprintf(stderr, "composing INVITE req: msg size error\n");
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 exit(1);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 rc = add_req_boilerplate(&msg, "1 INVITE");
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (rc < 0)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 goto msg_size_err;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 rc = add_contact_header(&msg);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (rc < 0)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 goto msg_size_err;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 rc = out_msg_add_header(&msg, "Content-Type", "application/sdp");
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (rc < 0)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 goto msg_size_err;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 bzero(&sdp, sizeof sdp);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 sdp.conn_ip = dummy_rtp_endp.sin_addr;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 sdp.conn_port = ntohs(dummy_rtp_endp.sin_port);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 sdp.codec_mask = SDP_CODEC_MASK_BOTH;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 sdp.session_id = sdp.conn_port << 16;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 sdp.owner_ip = sip_bind_ip;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 rc = out_msg_finish_sdp(&msg, &sdp);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (rc < 0)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 goto msg_size_err;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 sip_tx_packet(&msg, &sip_dest_sin);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
119
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
61 static void
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
62 preliminary_proc(argc, argv)
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
63 char **argv;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
64 {
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
65 extern int optind;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
66 extern char *optarg;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
67 char *logfile;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
68 int opt, rc;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
69
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
70 logfile = 0;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
71 while ((opt = getopt(argc, argv, "l:")) != EOF) {
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
72 switch (opt) {
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
73 case 'l':
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
74 logfile = optarg;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
75 continue;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
76 default:
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
77 usage:
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
78 fprintf(stderr,
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
79 "usage: %s [options] dest-conf from-num to-num\n",
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
80 argv[0]);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
81 exit(1);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
82 }
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
83 }
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
84 if (argc != optind + 3)
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
85 goto usage;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
86 read_config_file(argv[optind]);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
87 open_sip_udp_socket();
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
88 obtain_dummy_rtp();
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
89 sip_dest_sin.sin_family = AF_INET;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
90 sip_dest_sin.sin_addr = sip_dest_ip;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
91 sip_dest_sin.sin_port = htons(sip_dest_port);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
92 sprintf(from_uri, "<sip:%s@%s>;tag=out%u", argv[optind+1],
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
93 inet_ntoa(sip_bind_ip), ntohs(dummy_rtp_endp.sin_port));
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
94 sprintf(to_uri, "sip:%s@%s", argv[optind+2], sip_dest_domain);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
95 if (logfile) {
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
96 rc = open_sip_log_file(logfile);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
97 if (rc < 0)
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
98 exit(1); /* error msg already printed */
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
99 }
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
100 }
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
101
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 main(argc, argv)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 char **argv;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 fd_set fds;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 int rc;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107
119
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
108 preliminary_proc(argc, argv);
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 gettimeofday(&cur_event_time, 0);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 sprintf(call_id, "%08u_%u@%s",
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 (unsigned)(cur_event_time.tv_sec % 100000000),
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 ntohs(dummy_rtp_endp.sin_port), inet_ntoa(sip_bind_ip));
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 send_invite_req();
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 /* main select loop */
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 for (;;) {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 FD_ZERO(&fds);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 FD_SET(sip_socket, &fds);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 rc = select(sip_socket+1, &fds, 0, 0, 0);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 if (rc < 0) {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 if (errno == EINTR)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 continue;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 perror("select");
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 exit(1);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 gettimeofday(&cur_event_time, 0);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 if (FD_ISSET(sip_socket, &fds))
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 sip_socket_select();
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }