FreeCalypso > hg > themwi-system-sw
comparison sip-manual-out/main.c @ 71:d74b545a3c2a
sip-manual-out: new test program
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Tue, 20 Sep 2022 10:14:18 -0800 |
| parents | |
| children | 51e2f72dc5ab |
comparison
equal
deleted
inserted
replaced
| 70:47976db01894 | 71:d74b545a3c2a |
|---|---|
| 1 /* | |
| 2 * This is the main module for sip-manual-out test program. | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 #include <sys/time.h> | |
| 7 #include <sys/socket.h> | |
| 8 #include <sys/errno.h> | |
| 9 #include <netinet/in.h> | |
| 10 #include <arpa/inet.h> | |
| 11 #include <stdio.h> | |
| 12 #include <stdlib.h> | |
| 13 #include <string.h> | |
| 14 #include <strings.h> | |
| 15 #include <unistd.h> | |
| 16 #include "../libsip/out_msg.h" | |
| 17 #include "../libsip/sdp.h" | |
| 18 | |
| 19 extern int sip_socket; | |
| 20 extern struct in_addr sip_bind_ip, sip_dest_ip; | |
| 21 extern unsigned sip_bind_port, sip_dest_port; | |
| 22 extern char sip_dest_domain[]; | |
| 23 extern struct sockaddr_in dummy_rtp_endp; | |
| 24 | |
| 25 struct sockaddr_in sip_dest_sin; | |
| 26 char from_uri[128], to_uri[128], call_id[128]; | |
| 27 struct timeval cur_event_time; | |
| 28 | |
| 29 send_invite_req() | |
| 30 { | |
| 31 struct sip_msg_out msg; | |
| 32 struct sdp_gen sdp; | |
| 33 int rc; | |
| 34 | |
| 35 rc = start_request_out_msg(&msg, "INVITE", to_uri); | |
| 36 if (rc < 0) { | |
| 37 msg_size_err: fprintf(stderr, "composing INVITE req: msg size error\n"); | |
| 38 exit(1); | |
| 39 } | |
| 40 rc = add_req_boilerplate(&msg, "1 INVITE"); | |
| 41 if (rc < 0) | |
| 42 goto msg_size_err; | |
| 43 rc = add_contact_header(&msg); | |
| 44 if (rc < 0) | |
| 45 goto msg_size_err; | |
| 46 rc = out_msg_add_header(&msg, "Content-Type", "application/sdp"); | |
| 47 if (rc < 0) | |
| 48 goto msg_size_err; | |
| 49 bzero(&sdp, sizeof sdp); | |
| 50 sdp.conn_ip = dummy_rtp_endp.sin_addr; | |
| 51 sdp.conn_port = ntohs(dummy_rtp_endp.sin_port); | |
| 52 sdp.codec_mask = SDP_CODEC_MASK_BOTH; | |
| 53 sdp.session_id = sdp.conn_port << 16; | |
| 54 sdp.owner_ip = sip_bind_ip; | |
| 55 rc = out_msg_finish_sdp(&msg, &sdp); | |
| 56 if (rc < 0) | |
| 57 goto msg_size_err; | |
| 58 sip_tx_packet(&msg, &sip_dest_sin); | |
| 59 } | |
| 60 | |
| 61 main(argc, argv) | |
| 62 char **argv; | |
| 63 { | |
| 64 fd_set fds; | |
| 65 int rc; | |
| 66 | |
| 67 if (argc < 4 || argc > 5) { | |
| 68 fprintf(stderr, | |
| 69 "usage: %s dest-conf from-num to-num [logfile]\n", | |
| 70 argv[0]); | |
| 71 exit(1); | |
| 72 } | |
| 73 read_config_file(argv[1]); | |
| 74 open_sip_udp_socket(); | |
| 75 obtain_dummy_rtp(); | |
| 76 sip_dest_sin.sin_family = AF_INET; | |
| 77 sip_dest_sin.sin_addr = sip_dest_ip; | |
| 78 sip_dest_sin.sin_port = htons(sip_dest_port); | |
| 79 sprintf(from_uri, "sip:%s@%s", argv[2], inet_ntoa(sip_bind_ip)); | |
| 80 sprintf(to_uri, "sip:%s@%s", argv[3], sip_dest_domain); | |
| 81 if (argv[4]) { | |
| 82 rc = open_sip_log_file(argv[4]); | |
| 83 if (rc < 0) | |
| 84 exit(1); /* error msg already printed */ | |
| 85 } | |
| 86 gettimeofday(&cur_event_time, 0); | |
| 87 sprintf(call_id, "%08u_%u@%s", | |
| 88 (unsigned)(cur_event_time.tv_sec % 100000000), | |
| 89 ntohs(dummy_rtp_endp.sin_port), inet_ntoa(sip_bind_ip)); | |
| 90 send_invite_req(); | |
| 91 /* main select loop */ | |
| 92 for (;;) { | |
| 93 FD_ZERO(&fds); | |
| 94 FD_SET(sip_socket, &fds); | |
| 95 rc = select(sip_socket+1, &fds, 0, 0, 0); | |
| 96 if (rc < 0) { | |
| 97 if (errno == EINTR) | |
| 98 continue; | |
| 99 perror("select"); | |
| 100 exit(1); | |
| 101 } | |
| 102 gettimeofday(&cur_event_time, 0); | |
| 103 if (FD_ISSET(sip_socket, &fds)) | |
| 104 sip_socket_select(); | |
| 105 } | |
| 106 } |
