# HG changeset patch # User Mychaela Falconia # Date 1665301928 28800 # Node ID b512477398973170db20ffc01da6065aef0bff41 # Parent 94b5831c017f8e2c478b00a3c1b445a23f4a2272 sip-manual-out: attempt to play along with re-INVITEs diff -r 94b5831c017f -r b51247739897 sip-manual-out/Makefile --- a/sip-manual-out/Makefile Sat Oct 08 23:01:32 2022 -0800 +++ b/sip-manual-out/Makefile Sat Oct 08 23:52:08 2022 -0800 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 PROG= sip-manual-out -OBJS= bye_in.o disc_cmd.o dummy_rtp.o main.o readconf.o sip_log.o sip_udp.o \ - uac.o uas.o +OBJS= bye_in.o disc_cmd.o dummy_rtp.o main.o readconf.o reinvite.o sip_log.o \ + sip_udp.o uac.o uas.o LIBS= ../libsip/libsip.a ../libutil/libutil.a INSTBIN=/usr/local/bin diff -r 94b5831c017f -r b51247739897 sip-manual-out/reinvite.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sip-manual-out/reinvite.c Sat Oct 08 23:52:08 2022 -0800 @@ -0,0 +1,70 @@ +/* + * Here we handle incoming INVITE requests in the UAS role: even though + * we are strictly outbound, BulkVS servers will send us periodic + * re-INVITEs as keepalives, and we have to play along. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "../libsip/parse.h" +#include "../libsip/uas_basic.h" +#include "../libsip/out_msg.h" + +extern char call_id[]; + +static void +invite_correct_call(req, ess, sin) + struct sip_pkt_rx *req; + struct uas_parse_hdrs *ess; + struct sockaddr_in *sin; +{ + struct sip_msg_out resp; + int rc; + + printf("Received re-INVITE for our call, responding with 200\n"); + start_response_out_msg(&resp, "200 OK"); + rc = add_resp_basic_headers(&resp, ess, req->req_method); + if (rc < 0) { + fprintf(stderr, "sending 200 response: msg length exceeded\n"); + return; + } + out_msg_finish(&resp); + sip_tx_packet(&resp, sin); +} + +static void +invite_unknown_call(req, ess, sin) + struct sip_pkt_rx *req; + struct uas_parse_hdrs *ess; + struct sockaddr_in *sin; +{ + struct sip_msg_out resp; + int rc; + + printf("Received INVITE for unknown call, responding with 405\n"); + start_response_out_msg(&resp, "405 This gateway is outbound only"); + rc = add_resp_basic_headers(&resp, ess, req->req_method); + if (rc < 0) { + fprintf(stderr, "sending 405 response: msg length exceeded\n"); + return; + } + out_msg_finish(&resp); + sip_tx_packet(&resp, sin); +} + +void +handle_invite_req(req, ess, sin) + struct sip_pkt_rx *req; + struct uas_parse_hdrs *ess; + struct sockaddr_in *sin; +{ + if (!strcmp(ess->call_id, call_id)) + invite_correct_call(req, ess, sin); + else + invite_unknown_call(req, ess, sin); +} diff -r 94b5831c017f -r b51247739897 sip-manual-out/uas.c --- a/sip-manual-out/uas.c Sat Oct 08 23:01:32 2022 -0800 +++ b/sip-manual-out/uas.c Sat Oct 08 23:52:08 2022 -0800 @@ -30,7 +30,7 @@ "sending 501 error: response length exceeded\n"); return; } - rc = out_msg_add_header(&resp, "Allow", "BYE"); + rc = out_msg_add_header(&resp, "Allow", "INVITE,ACK,BYE"); if (rc < 0) goto too_long; out_msg_finish(&resp); @@ -52,10 +52,12 @@ return; } /* dispatch by method */ - if (!strcmp(msg->req_method, "BYE")) + if (!strcmp(msg->req_method, "INVITE")) + handle_invite_req(msg, &ess, sin); + else if (!strcmp(msg->req_method, "ACK")) + printf("Received ACK request, swallowing it\n"); + else if (!strcmp(msg->req_method, "BYE")) handle_bye_req(msg, &ess, sin); - else if (!strcmp(msg->req_method, "ACK")) - printf("Received unexpected ACK, swallowing it\n"); else unsupported_method(msg, &ess, sin); }