FreeCalypso > hg > themwi-system-sw
view sip-out/bye_in.c @ 216:6aa2cd650943
tcpserv-dump: specify bind IP on the command line
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 24 Jul 2023 22:19:08 -0800 |
parents | bfa9f0c0f0ac |
children |
line wrap: on
line source
/* * Here we handle incoming BYE requests in the UAS role. */ #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/gsm48_const.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(); extern unsigned sip_linger_gotbye; extern unsigned sip_linger_response_err; static void bye_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: case SIP_STATE_CONNECTED: call->overall_state = OVERALL_STATE_TEARDOWN; disconnect_mncc(call, GSM48_CAUSE_LOC_NET_BEYOND, GSM48_CC_CAUSE_NORM_CALL_CLEAR); disconnect_tmgw(call); call->sip_state = SIP_STATE_ENDED; sip_mark_end_time(call, sip_linger_gotbye); break; case SIP_STATE_CANCEL_SENT: case SIP_STATE_BYE_SENT: call->sip_state = SIP_STATE_ENDED; sip_mark_end_time(call, sip_linger_gotbye); break; case SIP_STATE_ACCEPT_100: case SIP_STATE_ACCEPT_200: case SIP_STATE_ENDED: break; case SIP_STATE_MSG_SIZE_ERR: return; default: syslog(LOG_CRIT, "FATAL: invalid SIP state 0x%x on incoming BYE", call->sip_state); exit(1); } /* send 200 response to BYE */ start_response_out_msg(&resp, "200 OK"); rc = add_resp_basic_headers(&resp, ess, req->req_method); if (rc < 0) { syslog(LOG_ERR, "msg size error responding to BYE"); call->sip_state = SIP_STATE_MSG_SIZE_ERR; sip_mark_end_time(call, sip_linger_response_err); return; } out_msg_finish(&resp); sip_tx_packet(&resp, sin); } static void bye_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, "481 Call-ID not found"); 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_bye_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) bye_found_call(req, ess, sin, call); else bye_unknown_call(req, ess, sin); }