FreeCalypso > hg > themwi-system-sw
changeset 165:9419fe55824f
themwi-sip-out complete to the point of compiling and linking
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 12 Oct 2022 17:05:45 -0800 |
parents | baaa6c1a3d3b |
children | 8adcd220c6cf |
files | .hgignore sip-out/Makefile sip-out/reinvite.c |
diffstat | 3 files changed, 102 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Wed Oct 12 16:31:15 2022 -0800 +++ b/.hgignore Wed Oct 12 17:05:45 2022 -0800 @@ -12,6 +12,8 @@ ^sip-manual-out/sip-manual-out$ +^sip-out/themwi-sip-out$ + ^utils/sip-out-test$ ^utils/sip-rx-test$ ^utils/sip-udp-dump$
--- a/sip-out/Makefile Wed Oct 12 16:31:15 2022 -0800 +++ b/sip-out/Makefile Wed Oct 12 17:05:45 2022 -0800 @@ -3,12 +3,12 @@ PROG= themwi-sip-out OBJS= bye_in.o call_clear.o call_list.o call_setup.o disconnect.o invite.o \ main.o mgw_ops.o mgw_resp.o mgw_sock.o mncc_sig_in.o mncc_sig_out.o \ - mncc_sock.o readconf.o retrans.o shutdown.o sip_log.o sip_uas.o \ - sip_udp.o uac_out.o uac_resp.o + mncc_sock.o readconf.o reinvite.o retrans.o shutdown.o sip_log.o \ + sip_uas.o sip_udp.o uac_out.o uac_resp.o LIBS= ../liboutrt/liboutrt.a ../libsip/libsip.a ../libutil/libutil.a INSTBIN=/usr/local/bin -all: ${OBJS} +all: ${PROG} ${PROG}: ${OBJS} ${LIBS} ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sip-out/reinvite.c Wed Oct 12 17:05:45 2022 -0800 @@ -0,0 +1,97 @@ +/* + * 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 <sys/types.h> +#include <sys/socket.h> +#include <sys/time.h> +#include <netinet/in.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <syslog.h> +#include "../include/out_routes.h" +#include "../libsip/parse.h" +#include "../libsip/uas_basic.h" +#include "../libsip/out_msg.h" +#include "call.h" + +extern struct call *find_call_by_sip_id(); + +static void +invite_found_call(req, ess, sin, call) + struct sip_pkt_rx *req; + struct uas_parse_hdrs *ess; + struct sockaddr_in *sin; + struct call *call; +{ + struct sip_msg_out resp; + int rc; + + switch (call->sip_state) { + case SIP_STATE_INV_SENT: + case SIP_STATE_100_RCVD: + start_response_out_msg(&resp, "491 Outbound INVITE pending"); + break; + case SIP_STATE_CONNECTED: + start_response_out_msg(&resp, "200 OK"); + break; + case SIP_STATE_CANCEL_SENT: + case SIP_STATE_BYE_SENT: + case SIP_STATE_ACCEPT_100: + case SIP_STATE_ACCEPT_200: + case SIP_STATE_ENDED: + start_response_out_msg(&resp, "488 Call terminated"); + break; + case SIP_STATE_MSG_SIZE_ERR: + return; + default: + syslog(LOG_CRIT, + "FATAL: invalid SIP state 0x%x on incoming re-INVITE", + call->sip_state); + exit(1); + } + rc = add_resp_basic_headers(&resp, ess, req->req_method); + if (rc < 0) { + syslog(LOG_ERR, "Re-INVITE response message size error"); + 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; + + start_response_out_msg(&resp, "405 This gateway is outbound only"); + rc = add_resp_basic_headers(&resp, ess, req->req_method); + if (rc < 0) + 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; +{ + struct call *call; + + call = find_call_by_sip_id(ess->call_id); + if (call) + invite_found_call(req, ess, sin, call); + else + invite_unknown_call(req, ess, sin); +}