Fix missing includes for GSM BS support
[lcr.git] / genext.c
1 /*****************************************************************************\
2 **                                                                           **
3 ** LCR                                                                       **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** generate extension                                                        **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <stdarg.h>
16 #include <sys/file.h>
17 #include <sys/stat.h>
18 #include <sys/types.h>
19 #include <errno.h>
20 #include "main.h"
21
22 int memuse = 0;
23 int mmemuse = 0;
24 int cmemuse = 0;
25 int ememuse = 0;
26 int pmemuse = 0;
27 int classuse = 0;
28 int fduse = 0;
29 int fhuse = 0;
30 struct isdn_cause isdn_cause[128];
31 struct isdn_location isdn_location[16];
32
33 void _printdebug(const char *file, const char *function, int line, unsigned int mask, const char *fmt, ...)
34 {
35 }
36
37 void _printerror(const char *file, const char *function, int line, const char *fmt, ...)
38 {
39         char buffer[4096];
40         va_list args;
41
42         va_start(args,fmt);
43         VUNPRINT(buffer,sizeof(buffer)-1,fmt,args);
44         buffer[sizeof(buffer)-1]=0;
45         va_end(args);
46
47         fprintf(stderr, "%s", buffer);
48 }
49
50 int main(int argc, char *argv[])
51 {
52         struct extension ext;
53         char pathname[256];
54         FILE *fp;
55         char options_error[256];
56
57         if (!read_options(options_error)) {
58                 PERROR("%s", options_error);
59                 return(-1);
60         }
61
62         if (argc != 4) {
63                 printf("Usage: %s <extension> <interfaces> <callerid>\n\n", argv[0]);
64                 printf("extension: any number for the extension (e.g 200)\n");
65                 printf("interfaces: internal interface(s) to reach extension, NOT port numbers\n");
66                 printf(" -> seperate multiple interfaces with commas. e.g Int1,Int2\n");
67                 printf("callerid: normal undefined called is (use what your telco assigned you)\n");
68                 return(0);
69         }
70
71         SPRINT(pathname, "%s/%s", EXTENSION_DATA, argv[1]);
72         if (mkdir(pathname, 0755) < 0) {
73                 if (errno == EEXIST)
74                         PERROR("Extension's directory already exists. Nothing done!\n");
75                 else    PERROR("Cannot open extension's directory '%s'.\n", pathname);
76                 return(-1);
77         }
78
79         memset(&ext, 0, sizeof(ext));
80         ext.rights = 4;
81         ext.cfnr_delay = 20;
82         ext.vbox_codec = CODEC_MONO;
83         UCPY(ext.interfaces, argv[2]);
84         UCPY(ext.callerid, argv[3]);
85         ext.callerid_present = INFO_PRESENT_ALLOWED;
86         ext.callerid_type = INFO_NTYPE_UNKNOWN;
87         ext.change_forward = 1;
88         ext.facility = 1;
89         write_extension(&ext, argv[1]);
90
91         SPRINT(pathname, "%s/%s/phonebook", EXTENSION_DATA, argv[1]);
92         if (!(fp = fopen(pathname, "w"))) {
93                 PERROR("Failed to write phonebook example '%s'.\n", pathname);
94                 return(-1);
95         } else {
96                 fprintf(fp, "# fromat: <shortcut> <phone number> [<Name>]\n");
97                 fprintf(fp, "# The shotcut may have any number of digits. \n");
98                 fprintf(fp, "# The phone number must include the dialing code for external, internal or\n");
99                 fprintf(fp, "# other type of dialing. \n");
100                 fprintf(fp, "# The name must not be in quotes. All 2 or 3 attributes must be seperated by\n");
101                 fprintf(fp, "# white space(s) and/or tab(s)\n");
102                 fprintf(fp, "# Empty lines and lines starting with '#' will be ignored.\n");
103                 fprintf(fp, "\n");
104                 fprintf(fp, "0   008003301000             German Telekom Service\n");
105                 fprintf(fp, "10  011880                   Directory Service Telegate\n");
106                 fprintf(fp, "11  011833                   Directory Service DTAG\n");
107                 fprintf(fp, "12  011811                   Directory Service Fred\n");
108                 fclose(fp);
109         }
110
111         SPRINT(pathname, "%s/%s/secrets", EXTENSION_DATA, argv[1]);
112         if (!(fp = fopen(pathname, "w"))) {
113                 PERROR("Failed to write secrets example '%s'.\n", pathname);
114                 return(-1);
115         } else {
116                 fprintf(fp, "# Format: <remote number> <key exchange> <cypher> [<key>]\n");
117                 fprintf(fp, "# The remote number must match the dialed number for outgoing calls.\n");
118                 fprintf(fp, "# The remote number must match the caller id for incoming calls.\n");
119                 fprintf(fp, "# The caller id must include the prefix digits as received.\n");
120                 fprintf(fp, "# The key exchange method must be given: e.g 'manual'\n");
121                 fprintf(fp, "# The cypher method must be given: e.g 'blowfish'\n");
122                 fprintf(fp, "# The key must be a string of characters (ASCII) or 0xXXXXXX...\n");
123                 fprintf(fp, "# All 2 or 3 attributes must be seperated by white space(s) and/or tab(s)\n");
124                 fprintf(fp, "# Empty lines and lines starting with '#' will be ignored.\n\n");
125                 fprintf(fp, "###############################################################################\n");
126                 fprintf(fp, "##       REFER TO THE DOCUMENTATION FOR DETAILS ON ENCRYPTION AND KEYS!      ##\n");
127                 fprintf(fp, "###############################################################################\n");
128                 fprintf(fp, "\n");
129                 fprintf(fp, "# This examples explains the format, NEVER USE IT, it would be dumb!\n");
130                 fprintf(fp, "021250993               manual  blowfish        0x012345678\n");
131                 fclose(fp);
132         }
133         printf("Extension %s created at %s/%s/.\n", argv[1], EXTENSION_DATA, argv[1]);
134
135         return(0);
136 }