view smpp-trx-sa/enq_link_stat.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 1bf989f60aa3
children
line wrap: on
line source

/*
 * This module tracks and logs the times of enquire_link packets
 * from the SMPP server.
 */

#include <sys/types.h>
#include <sys/file.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <unistd.h>

extern char fmt_time[32];

static int status_fd, status_enable;
static char last_enq_time[32];

void
log_enquire_link_open(filename)
	char *filename;
{
	status_fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666);
	if (status_fd < 0) {
		perror(filename);
		exit(1);
	}
	status_enable = 1;
}

static void
write_enq_link_times()
{
	char buf[128];

	sprintf(buf, "%s\n%s\n", last_enq_time, fmt_time);
	lseek(status_fd, 0, SEEK_SET);
	write(status_fd, buf, strlen(buf));
}

void
log_enquire_link_item()
{
	if (!status_enable)
		return;
	if (last_enq_time[0])
		write_enq_link_times();
	strcpy(last_enq_time, fmt_time);
}