view liboutrt/route_e164.c @ 265:e4a93ad611f3

liboutrt: add prefix length output arg to route_e164_number()
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 13 Nov 2023 15:09:10 -0800
parents 333dbb7ce704
children
line wrap: on
line source

/*
 * In this module we implement routing of calls to E.164 numbers.
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "../include/out_routes.h"

extern struct out_routes_header outrt_hdr;
extern struct sip_out_dest *outrt_dest_array;
extern struct inn_route *outrt_inn_array;

route_e164_number(target_num, destp, prefix_len_ret)
	char *target_num;
	struct sip_out_dest **destp;
	int *prefix_len_ret;
{
	unsigned inn_index;
	struct inn_route *rec;
	struct sip_out_dest *dest;
	char *pp, *tp;

	for (inn_index = 0; inn_index < outrt_hdr.num_inn; inn_index++) {
		rec = outrt_inn_array + inn_index;
		pp = rec->prefix;
		tp = target_num;
		while (*pp && *pp == *tp) {
			pp++;
			tp++;
		}
		if (*pp)
			continue;
		dest = outrt_dest_array + rec->sip_dest_id;
		*destp = dest;
		if (prefix_len_ret)
			*prefix_len_ret = pp - rec->prefix;
		return 1;
	}
	return 0;
}