FreeCalypso > hg > themwi-system-sw
view sip-manual-out/main.c @ 111:7a4d4b8d5f04
sip-in call clearing: unlink and free implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 28 Sep 2022 18:45:16 -0800 |
parents | 51e2f72dc5ab |
children | 056616f7e8ab |
line wrap: on
line source
/* * This is the main module for sip-manual-out test program. */ #include <sys/types.h> #include <sys/time.h> #include <sys/socket.h> #include <sys/errno.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <unistd.h> #include "../libsip/out_msg.h" #include "../libsip/sdp.h" extern int sip_socket; extern struct in_addr sip_bind_ip, sip_dest_ip; extern unsigned sip_bind_port, sip_dest_port; extern char sip_dest_domain[]; extern struct sockaddr_in dummy_rtp_endp; struct sockaddr_in sip_dest_sin; char from_uri[128], to_uri[128], call_id[128]; struct timeval cur_event_time; send_invite_req() { struct sip_msg_out msg; struct sdp_gen sdp; int rc; rc = start_request_out_msg(&msg, "INVITE", to_uri); if (rc < 0) { msg_size_err: fprintf(stderr, "composing INVITE req: msg size error\n"); exit(1); } rc = add_req_boilerplate(&msg, "1 INVITE"); if (rc < 0) goto msg_size_err; rc = add_contact_header(&msg); if (rc < 0) goto msg_size_err; rc = out_msg_add_header(&msg, "Content-Type", "application/sdp"); if (rc < 0) goto msg_size_err; bzero(&sdp, sizeof sdp); sdp.conn_ip = dummy_rtp_endp.sin_addr; sdp.conn_port = ntohs(dummy_rtp_endp.sin_port); sdp.codec_mask = SDP_CODEC_MASK_BOTH; sdp.session_id = sdp.conn_port << 16; sdp.owner_ip = sip_bind_ip; rc = out_msg_finish_sdp(&msg, &sdp); if (rc < 0) goto msg_size_err; sip_tx_packet(&msg, &sip_dest_sin); } main(argc, argv) char **argv; { fd_set fds; int rc; if (argc < 4 || argc > 5) { fprintf(stderr, "usage: %s dest-conf from-num to-num [logfile]\n", argv[0]); exit(1); } read_config_file(argv[1]); open_sip_udp_socket(); obtain_dummy_rtp(); sip_dest_sin.sin_family = AF_INET; sip_dest_sin.sin_addr = sip_dest_ip; sip_dest_sin.sin_port = htons(sip_dest_port); sprintf(from_uri, "<sip:%s@%s>;tag=out%u", argv[2], inet_ntoa(sip_bind_ip), ntohs(dummy_rtp_endp.sin_port)); sprintf(to_uri, "sip:%s@%s", argv[3], sip_dest_domain); if (argv[4]) { rc = open_sip_log_file(argv[4]); if (rc < 0) exit(1); /* error msg already printed */ } gettimeofday(&cur_event_time, 0); sprintf(call_id, "%08u_%u@%s", (unsigned)(cur_event_time.tv_sec % 100000000), ntohs(dummy_rtp_endp.sin_port), inet_ntoa(sip_bind_ip)); send_invite_req(); /* main select loop */ for (;;) { FD_ZERO(&fds); FD_SET(sip_socket, &fds); rc = select(sip_socket+1, &fds, 0, 0, 0); if (rc < 0) { if (errno == EINTR) continue; perror("select"); exit(1); } gettimeofday(&cur_event_time, 0); if (FD_ISSET(sip_socket, &fds)) sip_socket_select(); } }