Added processing of second caller id.
[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 const char *nationalize_callerinfo(const char *string, int *ntype, const char *national, const 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 const char *numberrize_callerinfo(const char *string, int ntype, const char *national, const char *international)
41 {
42         static char result[256];
43
44         switch(ntype)
45         {
46                 case INFO_NTYPE_NOTPRESENT:
47                 return("");
48
49                 case INFO_NTYPE_INTERNATIONAL:
50                 strcpy(result, international);
51                 strncat(result, string, sizeof(result)-strlen(result)-1);
52                 result[sizeof(result)-1] = '\0';
53                 return(result);
54                 break;
55
56                 case INFO_NTYPE_NATIONAL:
57                 strcpy(result, national);
58                 strncat(result, string, sizeof(result)-strlen(result)-1);
59                 result[sizeof(result)-1] = '\0';
60                 return(result);
61                 break;
62
63                 default:
64                 return(string);
65         }
66 }
67
68
69