view sip-manual-out/bye_in.c @ 275:def9f6e4f49e default tip

doc/Use-outside-USA: Fake-NANP-numbers article is here
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 27 Nov 2023 21:49:19 -0800
parents f8a33603288f
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 <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "../libsip/parse.h"
#include "../libsip/uas_basic.h"
#include "../libsip/out_msg.h"

extern char call_id[];
extern int rtp_out_enable;

static void
bye_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 BYE for our call, responding with 200\n");
	rtp_out_enable = 0;
	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
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;

	printf("Received BYE for unknown call, responding with 481\n");
	start_response_out_msg(&resp, "481 Call-ID not found");
	rc = add_resp_basic_headers(&resp, ess, req->req_method);
	if (rc < 0) {
		fprintf(stderr, "sending 481 response: msg length exceeded\n");
		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;
{
	if (!strcmp(ess->call_id, call_id))
		bye_correct_call(req, ess, sin);
	else
		bye_unknown_call(req, ess, sin);
}