view sip-in/invite_dup.c @ 145:4b685a5d9bd4

sip-in code: split invite.c into 3 separate C modules
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 08 Oct 2022 19:31:05 -0800
parents sip-in/invite.c@c93c339271a7
children 54c2f271380d
line wrap: on
line source

/*
 * Here we process SIP INVITE retransmissions and/or re-INVITEs
 * for existing calls.
 */

#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 "../libsip/parse.h"
#include "../libsip/uas_basic.h"
#include "../libsip/sdp.h"
#include "../libsip/out_msg.h"
#include "call.h"

void
invite_existing_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;

	if (ess->cseq_num != call->invite_cseq) {
		start_response_out_msg(&resp, "501 Re-INVITE not supported");
		rc = add_resp_basic_headers(&resp, ess, req->req_method);
		if (rc < 0) {
			syslog(LOG_ERR,
		"sending 501 Re-INVITE error: response length exceeded");
			return;
		}
		out_msg_finish(&resp);
		sip_tx_packet(&resp, sin);
		return;
	}
	/* it's a retransmission, not a re-INVITE */
	switch (call->sip_state) {
	case SIP_STATE_INVITE_PROC:
		start_response_out_msg(&resp, "100 Proceeding");
		fill_invite_resp_from_call(&resp, call);
		out_msg_finish(&resp);
		sip_tx_packet(&resp, sin);
		return;
	case SIP_STATE_RINGING:
		start_response_out_msg(&resp, "180 Ringing");
		fill_invite_resp_from_call(&resp, call);
		out_msg_finish(&resp);
		sip_tx_packet(&resp, sin);
		return;
	case SIP_STATE_RINGING_REL:
		start_response_out_msg(&resp, "180 Ringing");
		fill_invite_resp_from_call(&resp, call);
		out_msg_add_header(&resp, "Require", "100rel");
		out_msg_add_header(&resp, "RSeq", "1");
		out_msg_finish(&resp);
		sip_tx_packet(&resp, sin);
		return;
	case SIP_STATE_INVITE_200:
	case SIP_STATE_CONNECTED:
		fill_invite_200_resp(&resp, call);
		sip_tx_packet(&resp, sin);
		return;
	case SIP_STATE_INVITE_ERR:
		start_response_out_msg(&resp, call->invite_fail);
		fill_invite_resp_from_call(&resp, call);
		out_msg_finish(&resp);
		sip_tx_packet(&resp, sin);
		return;
	default:
		/* silently discard */
		return;
	}
}