view libnumdb/check_short.c @ 256:63252528a56c

sip-out: add CDR log line
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 15 Aug 2023 10:11:51 -0800
parents 1d590563e64b
children
line wrap: on
line source

/*
 * The library function implemented in this module looks up 4-digit short
 * dialing numbers in ThemWi number db to determine their disposition.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "../include/number_db_file.h"

extern struct numdb_file_hdr numdb_hdr;
extern struct short_number_map *numdb_short_numbers;

static int
compare_short_num(p1, p2)
	struct short_number_map *p1, *p2;
{
	if (p1->short_code < p2->short_code)
		return(-1);
	else if (p1->short_code > p2->short_code)
		return(1);
	else
		return(0);
}

lookup_short_dial_number(numstr, nanp_buf)
	char *numstr, *nanp_buf;
{
	struct short_number_map key, *res;

	if (!numdb_short_numbers || !numdb_hdr.short_number_count)
		return(0);
	key.short_code = strtoul(numstr, 0, 10);
	res = bsearch(&key, numdb_short_numbers, numdb_hdr.short_number_count,
			sizeof(struct short_number_map), compare_short_num);
	if (!res)
		return(0);
	if (res->prefix < 200000 || res->prefix > 999999) {
		/* either ITN or an invalid record, also treated as an ITN */
		nanp_buf[0] = '\0';
		return(1);
	}
	sprintf(nanp_buf, "%06u%04u", res->prefix, res->short_code);
	return(1);
}