LCR is now uses socket based mISDN V2 API
[lcr.git] / callerid.c
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** caller id support file                                                    **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include <string.h>
13 #include <time.h>
14 #include "extension.h"
15 #include "message.h"
16 #include "callerid.h"
17
18 /* create caller id from digits by comparing with national and international
19  * prefixes.
20  */
21 char *nationalize_callerinfo(char *string, int *ntype, char *national, char *international)
22 {
23         if (!strncmp(international, string, strlen(international)))
24         {
25                 *ntype = INFO_NTYPE_INTERNATIONAL;
26                 return(string+strlen(international)); 
27         }
28         if (!strncmp(national, string, strlen(national)))
29         {
30                 *ntype = INFO_NTYPE_NATIONAL;
31                 return(string+strlen(national)); 
32         }
33         *ntype = INFO_NTYPE_SUBSCRIBER;
34         return(string);
35 }
36
37 /* create number (including access codes) from caller id
38  * prefixes.
39  */
40 char *numberrize_callerinfo(char *string, int ntype, char *national, char *international)
41 {
42         static char result[256];
43
44         switch(ntype)
45         {
46                 case INFO_NTYPE_INTERNATIONAL:
47                 strcpy(result, international);
48                 strncat(result, string, sizeof(result));
49                 result[sizeof(result)-1] = '\0';
50                 return(result);
51                 break;
52
53                 case INFO_NTYPE_NATIONAL:
54                 strcpy(result, national);
55                 strncat(result, string, sizeof(result));
56                 result[sizeof(result)-1] = '\0';
57                 return(result);
58                 break;
59
60                 default:
61                 return(string);
62         }
63 }
64
65
66