summaryrefslogblamecommitdiffstats
path: root/callerid.c
blob: 7d13f162364337dd93a326cfd83a1753e67a4739 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11










                                                                                




                      





                                                                                           
                                                                   



                                                      
                                                         

















                                                                                         


                                                        



                                         


                                                        









                               
/*****************************************************************************\
**                                                                           **
** PBX4Linux                                                                 **
**                                                                           **
**---------------------------------------------------------------------------**
** Copyright: Andreas Eversberg                                              **
**                                                                           **
** caller id support file                                                    **
**                                                                           **
\*****************************************************************************/ 

#include <string.h>
#include <time.h>
#include "extension.h"
#include "message.h"
#include "callerid.h"

/* create caller id from digits by comparing with national and international
 * prefixes.
 */
char *nationalize_callerinfo(char *string, int *ntype, char *national, char *international)
{
	if (!strncmp(international, string, strlen(international)))
	{
		*ntype = INFO_NTYPE_INTERNATIONAL;
		return(string+strlen(international)); 
	}
	if (!strncmp(national, string, strlen(national)))
	{
		*ntype = INFO_NTYPE_NATIONAL;
		return(string+strlen(national)); 
	}
	*ntype = INFO_NTYPE_SUBSCRIBER;
	return(string);
}

/* create number (including access codes) from caller id
 * prefixes.
 */
char *numberrize_callerinfo(char *string, int ntype, char *national, char *international)
{
	static char result[256];

	switch(ntype)
	{
		case INFO_NTYPE_INTERNATIONAL:
		strcpy(result, international);
		strncat(result, string, sizeof(result));
		result[sizeof(result)-1] = '\0';
		return(result);
		break;

		case INFO_NTYPE_NATIONAL:
		strcpy(result, national);
		strncat(result, string, sizeof(result));
		result[sizeof(result)-1] = '\0';
		return(result);
		break;

		default:
		return(string);
	}
}