view sip-in/mgw_sock.c @ 79:b0df2b200d77

sip-in: implement SIP CANCEL
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 20 Sep 2022 18:58:11 -0800
parents 02761f1ae5e5
children 372209628038
line wrap: on
line source

/*
 * In this module we implement our local socket interface to themwi-mgw.
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <syslog.h>
#include "../include/tmgw_ctrl.h"

static char tmgw_socket_pathname[] = "/var/gsm/tmgw_socket";

int mgw_socket;

open_tmgw_socket()
{
	struct sockaddr_un sa;
	unsigned sa_len;
	int rc;

	mgw_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0);
	if (mgw_socket < 0) {
		syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m");
		return(-1);
	}
	fill_sockaddr_un(tmgw_socket_pathname, &sa, &sa_len);
	rc = connect(mgw_socket, (struct sockaddr *) &sa, sa_len);
	if (rc < 0) {
		syslog(LOG_ERR, "connect to %s: %m", tmgw_socket_pathname);
		return(-1);
	}
	update_max_fd(mgw_socket);
	return(0);
}

void
mgw_socket_select()
{
	struct tmgw_ctrl_resp msg;
	int rc;

	rc = recv(mgw_socket, &msg, sizeof msg, 0);
	if (rc < 0) {
		syslog(LOG_CRIT, "error reading from TMGW socket: %m");
		exit(1);
	}
	if (rc != sizeof(struct tmgw_ctrl_resp)) {
		syslog(LOG_CRIT,
			"response packet from TMGW has wrong length: %d bytes",
			rc);
		exit(1);
	}
	process_tmgw_response(&msg);
}

send_req_to_tmgw(msg)
	struct tmgw_ctrl_req *msg;
{
	return send(mgw_socket, msg, sizeof(struct tmgw_ctrl_req), 0);
}