summaryrefslogtreecommitdiffstats
path: root/callerid.c
blob: 9b31461c634b9527c7579d757ad4133680632d73 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*****************************************************************************\
**                                                                           **
** 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.
 */
const char *nationalize_callerinfo(const char *string, int *ntype, const char *national, const 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.
 */
const char *numberrize_callerinfo(const char *string, int ntype, const char *national, const char *international)
{
	static char result[256];

	switch(ntype) {
		case INFO_NTYPE_NOTPRESENT:
		return("");

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

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

		default:
		return(string);
	}
}