Fixed linker flags for chan LCR
[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                 *ntype = INFO_NTYPE_INTERNATIONAL;
25                 return(string+strlen(international)); 
26         }
27         if (!strncmp(national, string, strlen(national))) {
28                 *ntype = INFO_NTYPE_NATIONAL;
29                 return(string+strlen(national)); 
30         }
31         *ntype = INFO_NTYPE_SUBSCRIBER;
32         return(string);
33 }
34
35 /* create number (including access codes) from caller id
36  * prefixes.
37  */
38 const char *numberrize_callerinfo(const char *string, int ntype, const char *national, const char *international)
39 {
40         static char result[256];
41
42         switch(ntype) {
43                 case INFO_NTYPE_NOTPRESENT:
44                 return("");
45
46                 case INFO_NTYPE_INTERNATIONAL:
47                 strcpy(result, international);
48                 strncat(result, string, sizeof(result)-strlen(result)-1);
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)-strlen(result)-1);
56                 result[sizeof(result)-1] = '\0';
57                 return(result);
58                 break;
59
60                 default:
61                 return(string);
62         }
63 }
64
65
66