view sip-out/uac_resp.c @ 156:0bacca1f2f7b

sip-out: handle all INVITE responses, except errors
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 07:13:55 -0800
parents 2730ccb44549
children c0a391f28e91
line wrap: on
line source

/*
 * In this module we implement our handling of SIP responses in the UAC 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/resp_ident.h"
#include "call.h"

extern struct call *find_call_by_sip_id();

void
process_sip_response(msg, sin)
	struct sip_pkt_rx *msg;
	struct sockaddr_in *sin;
{
	struct sip_resp_ident rid;
	struct call *call;
	int rc;

	rc = sip_resp_extract_ident(msg, &rid);
	if (rc < 0) {
		syslog(LOG_ERR, "SIP %03u response: bad or missing %s header",
			msg->status_code, rid.error_field);
		return;
	}
	call = find_call_by_sip_id(rid.call_id);
	if (!call) {
		syslog(LOG_ERR, "SIP %03u response: unmatched Call-ID",
			msg->status_code);
		return;
	}
	if (rid.cseq_num == 1 && !strcmp(rid.cseq_method, "INVITE"))
		handle_invite_response(call, msg, sin);
	else if (rid.cseq_num == 1 && !strcmp(rid.cseq_method, "CANCEL"))
		handle_cancel_response(call, msg, sin);
	else if (rid.cseq_num == 2 && !strcmp(rid.cseq_method, "BYE"))
		handle_bye_response(call, msg, sin);
	else
		syslog(LOG_ERR,
			"UAC received %03u response with unknown CSeq %u %.32s",
			msg->status_code, rid.cseq_num, rid.cseq_method);
}