1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** reading and writing files for extensions **
10 \*****************************************************************************/
16 const char *ext_rights[] = {
25 const char *ext_yesno[] = {
34 * reads extension from given extension number and fills structure
36 int read_extension(struct extension *ext, char *num)
43 char param[256],param2[256];
46 int last_in_count = 0, last_out_count = 0;
48 /* save number, so &ext and ext.number can be given as parameters - without overwriting itself */
51 if (number[0] == '\0')
54 SPRINT(filename, "%s/%s/settings", EXTENSION_DATA, number);
56 if (!(fp = fopen(filename, "r"))) {
57 printf("the given extension doesn't exist: \"%s\"\n", filename);
58 PDEBUG(DEBUG_CONFIG, "the given extension doesn't exist: \"%s\"\n", filename);
63 memset(ext, 0, sizeof(struct extension));
64 SCPY(ext->number, number);
65 // ********** NOTE: also change value in apppbx constructor
66 ext->rights = 4; /* international */
68 ext->vbox_codec = CODEC_MONO;
71 while((fgets(buffer, sizeof(buffer), fp))) {
73 buffer[sizeof(buffer)-1] = '\0';
74 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
77 while(*p <= 32) { /* skip spaces */
82 if (*p==0 || *p=='#') /* ignore comments and empty line */
86 i=0; /* read option */
88 if (i+1 >= sizeof(option)) {
89 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
96 while(*p <= 32) { /* skip spaces */
104 if (*p!=0 && *p!='#') { /* param */
105 i=0; /* read param */
107 if (i+1 >= sizeof(param)) {
108 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
115 while(*p <= 32) { /* skip spaces */
121 if (*p!=0 && *p!='#') { /* param2 */
122 i=0; /* read param2 */
124 if (i+1 >= sizeof(param2)) {
125 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
134 /* at this point we have option and param */
137 if (!strcmp(option,"name")) {
138 SCPY(ext->name, param);
140 SCAT(ext->name, (char *)" ");
141 SCAT(ext->name, param2);
144 PDEBUG(DEBUG_CONFIG, "name of extension: %s\n",param);
146 if (!strcmp(option,"prefix")) {
147 SCPY(ext->prefix, param);
149 PDEBUG(DEBUG_CONFIG, "dial prefix on pickup: %s\n",param);
151 if (!strcmp(option,"next")) {
152 SCPY(ext->next, param);
154 PDEBUG(DEBUG_CONFIG, "dial next on pickup: %s\n",param);
156 if (!strcmp(option,"alarm")) {
157 SCPY(ext->alarm, param);
159 PDEBUG(DEBUG_CONFIG, "alarm message (if prefix): %s\n",param);
161 if (!strcmp(option,"cfu")) {
162 SCPY(ext->cfu, param);
164 PDEBUG(DEBUG_CONFIG, "call forward unconditional: %s\n",param);
166 if (!strcmp(option,"cfb")) {
167 SCPY(ext->cfb, param);
169 PDEBUG(DEBUG_CONFIG, "call forward when busy: %s\n",param);
171 if (!strcmp(option,"cfnr")) {
172 SCPY(ext->cfnr, param);
174 PDEBUG(DEBUG_CONFIG, "call forward on no response: %s\n",param);
176 if (!strcmp(option,"cfnr_delay")) {
177 ext->cfnr_delay = atoi(param);
178 if (ext->cfnr_delay < 0)
181 PDEBUG(DEBUG_CONFIG, "call forward no response delay: %d\n",ext->cfnr_delay);
183 if (!strcmp(option,"cfp")) {
184 SCPY(ext->cfp, param);
186 PDEBUG(DEBUG_CONFIG, "call forward parallel: %s\n",param);
188 if (!strcmp(option,"change_forward")) {
190 while(ext_yesno[i]) {
191 if (!strcasecmp(param,ext_yesno[i]))
196 ext->change_forward = i;
197 PDEBUG(DEBUG_CONFIG, "allow the change of forwarding: %s\n", ext_yesno[i]);
199 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_forward: %s\n", param);
202 if (!strcmp(option,"interfaces")) {
203 SCPY(ext->interfaces, param);
205 PDEBUG(DEBUG_CONFIG, "interfaces to ring calls to extension: %s %s\n",param,param2);
207 if (!strcmp(option,"callerid")) {
208 ext->callerid_present = INFO_PRESENT_ALLOWED;
209 if (!strncasecmp(param2, "anonymous", 9))
210 ext->callerid_present = INFO_PRESENT_RESTRICTED;
211 if (!strncasecmp(param, "non", 3)) {
212 ext->callerid[0] = '\0';
213 ext->callerid_present = INFO_PRESENT_NOTAVAIL;
214 ext->callerid_type = INFO_NTYPE_UNKNOWN;
215 PDEBUG(DEBUG_CONFIG, "caller id: ID NOT AVAILABLE\n");
220 ext->callerid_type = INFO_NTYPE_INTERNATIONAL;
221 SCPY(ext->callerid, param+1);
222 PDEBUG(DEBUG_CONFIG, "caller id: %s INTERNATIONAL\n",param+1);
226 ext->callerid_type = INFO_NTYPE_NATIONAL;
227 SCPY(ext->callerid, param+1);
228 PDEBUG(DEBUG_CONFIG, "caller id: %s NATIONAL\n",param+1);
232 ext->callerid_type = INFO_NTYPE_SUBSCRIBER;
233 SCPY(ext->callerid, param+1);
234 PDEBUG(DEBUG_CONFIG, "caller id: %s SUBSCRIBER\n",param+1);
237 ext->callerid_type = INFO_NTYPE_UNKNOWN;
238 SCPY(ext->callerid, param);
239 PDEBUG(DEBUG_CONFIG, "caller id: %s UNKNOWN\n",param);
241 ext->callerid[sizeof(ext->callerid)-1] = 0;
243 if (!strcmp(option,"id_next_call")) {
244 ext->id_next_call_present = INFO_PRESENT_ALLOWED;
245 if (!strncasecmp(param2, "anonymous", 9))
246 ext->id_next_call_present = INFO_PRESENT_RESTRICTED;
247 if (param[0] == '\0') {
248 ext->id_next_call_present = -1;
249 PDEBUG(DEBUG_CONFIG, "id next call: no id for next call\n");
251 if (!strncasecmp(param, "none", 3)) {
252 ext->id_next_call[0] = '\0';
253 ext->id_next_call_present = INFO_PRESENT_NOTAVAIL;
254 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
255 PDEBUG(DEBUG_CONFIG, "id next call: ID NOT AVAILABLE\n");
260 ext->id_next_call_type = INFO_NTYPE_INTERNATIONAL;
261 SCPY(ext->id_next_call, param+1);
262 PDEBUG(DEBUG_CONFIG, "id next call: %s INTERNATIONAL\n",param+1);
266 ext->id_next_call_type = INFO_NTYPE_NATIONAL;
267 SCPY(ext->id_next_call, param+1);
268 PDEBUG(DEBUG_CONFIG, "id next call: %s NATIONAL\n",param+1);
272 ext->id_next_call_type = INFO_NTYPE_SUBSCRIBER;
273 SCPY(ext->id_next_call, param+1);
274 PDEBUG(DEBUG_CONFIG, "id next call: %s SUBSCRIBER\n",param+1);
277 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
278 SCPY(ext->id_next_call, param);
279 PDEBUG(DEBUG_CONFIG, "id next call: %s UNKNOWN\n",param);
285 if (!strcmp(option,"change_callerid")) {
287 while(ext_yesno[i]) {
288 if (!strcasecmp(param,ext_yesno[i]))
293 ext->change_callerid = i;
294 PDEBUG(DEBUG_CONFIG, "allow the change of caller id: %s\n", ext_yesno[i]);
296 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_callerid: %s\n", param);
299 if (!strcmp(option,"anon-ignore")) {
301 while(ext_yesno[i]) {
302 if (!strcasecmp(param,ext_yesno[i]))
307 ext->anon_ignore = i;
308 PDEBUG(DEBUG_CONFIG, "ignore restriction of CLIP & COLP %s\n", ext_yesno[i]);
310 PDEBUG(DEBUG_CONFIG, "unknown parameter given anon-ignore: %s\n", param);
313 if (!strcmp(option,"clip")) {
314 if (!strcasecmp(param, "hide"))
315 ext->clip = CLIP_HIDE;
317 ext->clip = CLIP_ASIS;
319 PDEBUG(DEBUG_CONFIG, "clip: %d\n",ext->clip);
321 if (!strcmp(option,"colp")) {
322 if (!strcasecmp(param, "hide"))
323 ext->colp = COLP_HIDE;
324 else if (!strcasecmp(param, "force"))
325 ext->colp = COLP_FORCE;
327 ext->colp = COLP_ASIS;
329 PDEBUG(DEBUG_CONFIG, "colp: %d\n",ext->colp);
331 if (!strcmp(option,"clip_prefix")) {
332 SCPY(ext->clip_prefix, param);
334 PDEBUG(DEBUG_CONFIG, "clip prefix: %s\n",param);
336 if (!strcmp(option,"keypad")) {
338 while(ext_yesno[i]) {
339 if (!strcasecmp(param,ext_yesno[i]))
345 PDEBUG(DEBUG_CONFIG, "use keypad to do call control %s\n", ext_yesno[i]);
347 PDEBUG(DEBUG_CONFIG, "unknown parameter given keypad: %s\n", param);
350 if (!strcmp(option,"rights")) {
352 while(ext_rights[i]) {
353 if (!strcasecmp(param,ext_rights[i]))
359 PDEBUG(DEBUG_CONFIG, "rights to dial: %s\n", ext_rights[i]);
361 PDEBUG(DEBUG_CONFIG, "given rights unknown: %s\n", param);
364 if (!strcmp(option,"delete_ext")) {
366 while(ext_yesno[i]) {
367 if (!strcasecmp(param,ext_yesno[i]))
373 PDEBUG(DEBUG_CONFIG, "enables the delete key function for external calls: %s\n", ext_yesno[i]);
375 PDEBUG(DEBUG_CONFIG, "unknown parameter given delete: %s\n", param);
378 if (!strcmp(option,"noknocking")) {
380 while(ext_yesno[i]) {
381 if (!strcasecmp(param,ext_yesno[i]))
387 PDEBUG(DEBUG_CONFIG, "noknocking %s\n", ext_yesno[i]);
389 PDEBUG(DEBUG_CONFIG, "given noknocking param unknown: %s\n", param);
392 if (!strcmp(option,"rx_gain")
393 || !strcmp(option,"rxvol")) {
394 ext->rx_gain = atoi(param);
395 if (ext->rx_gain<-8 || ext->rx_gain>8)
398 PDEBUG(DEBUG_CONFIG, "receive volume: %d\n",ext->rx_gain);
400 if (!strcmp(option,"tx_gain")
401 || !strcmp(option,"txvol")) {
402 ext->tx_gain = atoi(param);
403 if (ext->tx_gain<-8 || ext->tx_gain>8)
406 PDEBUG(DEBUG_CONFIG, "transmit volume: %d\n",ext->tx_gain);
408 if (!strcmp(option,"own_setup")) {
410 while(ext_yesno[i]) {
411 if (!strcasecmp(param,ext_yesno[i]))
417 PDEBUG(DEBUG_CONFIG, "own_setup %s\n", ext_yesno[i]);
419 PDEBUG(DEBUG_CONFIG, "given own_setup param unknown: %s\n", param);
422 if (!strcmp(option,"own_proceeding")) {
424 while(ext_yesno[i]) {
425 if (!strcasecmp(param,ext_yesno[i]))
430 ext->own_proceeding = i;
431 PDEBUG(DEBUG_CONFIG, "own_proceeding %s\n", ext_yesno[i]);
433 PDEBUG(DEBUG_CONFIG, "given own_proceeding param unknown: %s\n", param);
436 if (!strcmp(option,"own_alerting")) {
438 while(ext_yesno[i]) {
439 if (!strcasecmp(param,ext_yesno[i]))
444 ext->own_alerting = i;
445 PDEBUG(DEBUG_CONFIG, "own_alerting %s\n", ext_yesno[i]);
447 PDEBUG(DEBUG_CONFIG, "given own_alerting param unknown: %s\n", param);
450 if (!strcmp(option,"own_cause")) {
452 while(ext_yesno[i]) {
453 if (!strcasecmp(param,ext_yesno[i]))
459 PDEBUG(DEBUG_CONFIG, "own_cause %s\n", ext_yesno[i]);
461 PDEBUG(DEBUG_CONFIG, "given own_cause param unknown: %s\n", param);
464 if (!strcmp(option,"facility")) {
466 while(ext_yesno[i]) {
467 if (!strcasecmp(param,ext_yesno[i]))
473 PDEBUG(DEBUG_CONFIG, "facility %s\n", ext_yesno[i]);
475 PDEBUG(DEBUG_CONFIG, "given facility param unknown: %s\n", param);
478 if (!strcmp(option,"display_cause")) {
479 if (!strcasecmp(param, "german"))
480 ext->display_cause = DISPLAY_CAUSE_GERMAN;
481 else if (!strcasecmp(param, "english"))
482 ext->display_cause = DISPLAY_CAUSE_ENGLISH;
483 else if (!strcasecmp(param, "german-location"))
484 ext->display_cause = DISPLAY_LOCATION_GERMAN;
485 else if (!strcasecmp(param, "english-location"))
486 ext->display_cause = DISPLAY_LOCATION_ENGLISH;
487 else if (!strcasecmp(param, "number"))
488 ext->display_cause = DISPLAY_CAUSE_NUMBER;
490 ext->display_cause = DISPLAY_CAUSE_NONE;
492 PDEBUG(DEBUG_CONFIG, "display cause: %d\n",ext->display_cause);
495 if (!strcmp(option,"display_ext")) {
496 if (!strcasecmp(param, "number"))
497 ext->display_ext = DISPLAY_CID_NUMBER;
498 else if (!strcasecmp(param, "abbrev"))
499 ext->display_ext = DISPLAY_CID_ABBREVIATION;
500 else if (!strcasecmp(param, "name"))
501 ext->display_ext = DISPLAY_CID_NAME;
502 else if (!strcasecmp(param, "number-name"))
503 ext->display_ext = DISPLAY_CID_NUMBER_NAME;
504 else if (!strcasecmp(param, "name-number"))
505 ext->display_ext = DISPLAY_CID_NAME_NUMBER;
506 else if (!strcasecmp(param, "abbrev-number"))
507 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER;
508 else if (!strcasecmp(param, "abbrev-name"))
509 ext->display_ext = DISPLAY_CID_ABBREV_NAME;
510 else if (!strcasecmp(param, "abbrev-name-number"))
511 ext->display_ext = DISPLAY_CID_ABBREV_NAME_NUMBER;
512 else if (!strcasecmp(param, "abbrev-number-name"))
513 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER_NAME;
515 ext->display_ext = DISPLAY_CID_ASIS;
517 PDEBUG(DEBUG_CONFIG, "display ext: %d\n",ext->display_ext);
520 if (!strcmp(option,"display_ext")) {
522 while(ext_yesno[i]) {
523 if (!strcasecmp(param,ext_yesno[i]))
528 ext->display_ext = i;
529 PDEBUG(DEBUG_CONFIG, "display ext %s\n", ext_yesno[i]);
531 PDEBUG(DEBUG_CONFIG, "given display_ext param unknown: %s\n", param);
534 if (!strcmp(option,"display_int")) {
536 while(ext_yesno[i]) {
537 if (!strcasecmp(param,ext_yesno[i]))
542 ext->display_int = i;
543 PDEBUG(DEBUG_CONFIG, "display int %s\n", ext_yesno[i]);
545 PDEBUG(DEBUG_CONFIG, "given display_int param unknown: %s\n", param);
548 if (!strcmp(option,"display_fake")) {
550 while(ext_yesno[i]) {
551 if (!strcasecmp(param,ext_yesno[i]))
556 ext->display_fake = i;
557 PDEBUG(DEBUG_CONFIG, "display fake caller ids %s\n", ext_yesno[i]);
559 PDEBUG(DEBUG_CONFIG, "given display_fake param unknown: %s\n", param);
562 if (!strcmp(option,"display_anon")) {
564 while(ext_yesno[i]) {
565 if (!strcasecmp(param,ext_yesno[i]))
570 ext->display_anon = i;
571 PDEBUG(DEBUG_CONFIG, "display anonymouse ids %s\n", ext_yesno[i]);
573 PDEBUG(DEBUG_CONFIG, "given display_anon param unknown: %s\n", param);
576 if (!strcmp(option,"display_menu")) {
578 while(ext_yesno[i]) {
579 if (!strcasecmp(param,ext_yesno[i]))
584 ext->display_menu = i;
585 PDEBUG(DEBUG_CONFIG, "display menu %s\n", ext_yesno[i]);
587 PDEBUG(DEBUG_CONFIG, "given display_menu param unknown: %s\n", param);
590 if (!strcmp(option,"display_dialing")) {
592 while(ext_yesno[i]) {
593 if (!strcasecmp(param,ext_yesno[i]))
598 ext->display_dialing = i;
599 PDEBUG(DEBUG_CONFIG, "display dialing %s\n", ext_yesno[i]);
601 PDEBUG(DEBUG_CONFIG, "given display_dialing param unknown: %s\n", param);
604 if (!strcmp(option,"display_name")) {
606 while(ext_yesno[i]) {
607 if (!strcasecmp(param,ext_yesno[i]))
612 ext->display_name = i;
613 PDEBUG(DEBUG_CONFIG, "display name %s\n", ext_yesno[i]);
615 PDEBUG(DEBUG_CONFIG, "given display_name param unknown: %s\n", param);
618 if (!strcmp(option,"tones_dir")) {
619 if (param[strlen(param)-1] == '/')
620 param[strlen(param)-1]=0;
621 SCPY(ext->tones_dir, param);
623 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
625 if (!strcmp(option,"record")) {
626 if (!strcasecmp(param, "mono"))
627 ext->record = CODEC_MONO;
628 else if (!strcasecmp(param, "stereo"))
629 ext->record = CODEC_STEREO;
630 else if (!strcasecmp(param, "8bit"))
631 ext->record = CODEC_8BIT;
632 else if (!strcasecmp(param, "law"))
633 ext->record = CODEC_LAW;
635 ext->record = CODEC_OFF;
636 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
638 if (!strcmp(option,"password")) {
639 SCPY(ext->password, param);
641 PDEBUG(DEBUG_CONFIG, "password: %s\n",param);
643 if (!strcmp(option,"vbox_mode")) {
644 if (!strcasecmp(param, "parallel"))
645 ext->vbox_mode = VBOX_MODE_PARALLEL;
646 else if (!strcasecmp(param, "announcement"))
647 ext->vbox_mode = VBOX_MODE_ANNOUNCEMENT;
649 ext->vbox_mode = VBOX_MODE_NORMAL;
650 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
652 if (!strcmp(option,"vbox_codec")) {
653 if (!strcasecmp(param, "stereo"))
654 ext->vbox_codec = CODEC_STEREO;
655 else if (!strcasecmp(param, "8bit"))
656 ext->vbox_codec = CODEC_8BIT;
657 else if (!strcasecmp(param, "law"))
658 ext->vbox_codec = CODEC_LAW;
660 ext->vbox_codec = CODEC_MONO;
661 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
663 if (!strcmp(option,"vbox_time")) {
664 ext->vbox_time = atoi(param);
665 if (ext->vbox_time < 0)
668 PDEBUG(DEBUG_CONFIG, "vbox time to record: %d\n",ext->vbox_time);
670 if (!strcmp(option,"vbox_display")) {
671 if (!strcasecmp(param, "detailed")
672 || !strcasecmp(param, "detailled"))
673 ext->vbox_display = VBOX_DISPLAY_DETAILED;
674 else if (!strcasecmp(param, "off"))
675 ext->vbox_display = VBOX_DISPLAY_OFF;
677 ext->vbox_display = VBOX_DISPLAY_BRIEF;
678 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
680 if (!strcmp(option,"vbox_language")) {
681 if (!strcasecmp(param, "german"))
682 ext->vbox_language = VBOX_LANGUAGE_GERMAN;
684 ext->vbox_language = VBOX_LANGUAGE_ENGLISH;
685 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
687 if (!strcmp(option,"vbox_email")) {
688 SCPY(ext->vbox_email, param);
689 PDEBUG(DEBUG_CONFIG, "given vbox email: %s\n", param);
691 if (!strcmp(option,"vbox_email_file")) {
693 while(ext_yesno[i]) {
694 if (!strcasecmp(param,ext_yesno[i]))
699 ext->vbox_email_file = i;
700 PDEBUG(DEBUG_CONFIG, "attach audio file %s\n", ext_yesno[i]);
702 PDEBUG(DEBUG_CONFIG, "given vbox_email_file param unknown: %s\n", param);
705 if (!strcmp(option,"vbox_free")) {
707 while(ext_yesno[i]) {
708 if (!strcasecmp(param,ext_yesno[i]))
714 PDEBUG(DEBUG_CONFIG, "vbox_free %s\n", ext_yesno[i]);
716 PDEBUG(DEBUG_CONFIG, "given vbox_free param unknown: %s\n", param);
719 if (!strcmp(option,"last_in")) {
720 if (param[0] && last_in_count<MAX_REMEMBER) {
721 SCPY(ext->last_in[last_in_count], param);
724 PDEBUG(DEBUG_CONFIG, "last_in dialed number: %s\n",param);
726 if (!strcmp(option,"last_out")) {
727 if (param[0] && last_out_count<MAX_REMEMBER) {
728 SCPY(ext->last_out[last_out_count], param);
731 PDEBUG(DEBUG_CONFIG, "last_out dialed number: %s\n",param);
733 if (!strcmp(option,"datacall")) {
735 while(ext_yesno[i]) {
736 if (!strcasecmp(param,ext_yesno[i]))
742 PDEBUG(DEBUG_CONFIG, "datacall %s\n", ext_yesno[i]);
744 PDEBUG(DEBUG_CONFIG, "given datacall param unknown: %s\n", param);
747 if (!strcmp(option,"seconds")) {
749 while(ext_yesno[i]) {
750 if (!strcasecmp(param,ext_yesno[i]))
755 ext->no_seconds = 1-i;
756 PDEBUG(DEBUG_CONFIG, "seconds %s\n", ext_yesno[i]);
758 PDEBUG(DEBUG_CONFIG, "unknown param for seconds: %s\n", param);
761 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n",filename,line,option);
772 * writes extension for given extension number from structure
774 int write_extension(struct extension *ext, char *number)
780 if (number[0] == '\0')
783 SPRINT(filename, "%s/%s/settings", EXTENSION_DATA, number);
785 if (!(fp = fopen(filename, "w"))) {
786 PERROR("Cannot open settings: \"%s\"\n", filename);
790 fprintf(fp,"# Settings of extension %s\n\n", number);
792 fprintf(fp,"# Name of extension:\n");
793 fprintf(fp,"name %s\n\n",ext->name);
795 fprintf(fp,"# Predialed prefix after pick-up of the phone\n");
796 fprintf(fp,"prefix %s\n\n",ext->prefix);
798 fprintf(fp,"# Next prefix to dial pick-up of the phone\n");
799 fprintf(fp,"# This will be cleared on hangup.\n");
800 fprintf(fp,"next %s\n\n",ext->next);
802 // fprintf(fp,"# Set up alarm message after prefix is dialed and connection is established\n");
803 // fprintf(fp,"alarm %s\n\n",ext->alarm);
805 fprintf(fp,"# Interface(s) to ring on calls to extension (as named in interface.conf)\n");
806 fprintf(fp,"# Seperate multiple interfaces by using komma without spaces\n");
807 fprintf(fp,"# Example: Int would ring on the interface with the name \"Int\"\n");
808 fprintf(fp,"# Int1,Int2 would ring incoming calls on both interfaces Int1 and Int2.\n");
809 fprintf(fp,"interfaces %s\n\n",ext->interfaces);
811 fprintf(fp,"# Call Forward Unconditional (CFU)\n");
812 fprintf(fp,"# No port will be called, CFB, CFNR and CFP is ignored.\n");
813 fprintf(fp,"# Use keyword \"vbox\" to forward call directly to answering machine.\n");
814 fprintf(fp,"cfu %s\n\n",ext->cfu);
816 fprintf(fp,"# Call Forward when Busy (CFB)\n");
817 fprintf(fp,"# If the extension is in use at least once, this forward is done.\n");
818 fprintf(fp,"# In case of busy line, CFNR and CFP is ignored.\n");
819 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine when busy.\n");
820 fprintf(fp,"cfb %s\n\n",ext->cfb);
822 fprintf(fp,"# Call Forward on No Response (CFNR)\n");
823 fprintf(fp,"# If noone answers, the call is forwarded, ports and CFP will be released.\n");
824 fprintf(fp,"# The default delay is 20 seconds.\n");
825 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine on no response.\n");
826 fprintf(fp,"cfnr %s\n",ext->cfnr);
827 fprintf(fp,"cfnr_delay %d\n\n",ext->cfnr_delay);
829 fprintf(fp,"# Call Forward Parallel (CFP)\n");
830 fprintf(fp,"# Call will ring on the forwarded number, simulaniousely with the ports.\n");
831 fprintf(fp,"cfp %s\n\n",ext->cfp);
833 fprintf(fp,"# Allow user to change call forwarding.\n");
834 fprintf(fp,"change_forward %s\n\n", ext_yesno[ext->change_forward]);
836 fprintf(fp,"# Caller id\n# This must be one of the following:\n");
837 fprintf(fp,"# <number> (as dialed from your local area)\n");
838 fprintf(fp,"# <number> anonymous (will only be shown to emergency phones)\n");
839 fprintf(fp,"# none (no number available at all)\n");
840 fprintf(fp,"# by default the number is of type UNKNOWN (for MULTIPOINT lines)\n");
841 fprintf(fp,"# if your caller id is not screened on outgoing calls use one of the following:\n");
842 fprintf(fp,"# use prefix 'i' for TYPE INTERNATIONAL (i<county code><areacode+number>)\n");
843 fprintf(fp,"# use prefix 'n' for TYPE NATIONAL (n<areacode+number>)\n");
844 fprintf(fp,"# use prefix 's' for TYPE SUBSCRIBER (s<local number>)\n");
845 if (ext->callerid_present == INFO_PRESENT_NOTAVAIL)
846 fprintf(fp,"callerid none\n\n");
848 switch(ext->callerid_type) {
849 case INFO_NTYPE_INTERNATIONAL:
850 fprintf(fp,"callerid i%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
852 case INFO_NTYPE_NATIONAL:
853 fprintf(fp,"callerid n%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
855 case INFO_NTYPE_SUBSCRIBER:
856 fprintf(fp,"callerid s%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
859 fprintf(fp,"callerid %s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
863 fprintf(fp,"# Caller id for next call (see caller id)\n");
864 if (ext->id_next_call_present < 0)
865 fprintf(fp,"id_next_call \n\n");
866 else if (ext->id_next_call_present == INFO_PRESENT_NOTAVAIL)
867 fprintf(fp,"id_next_call none\n\n");
869 switch(ext->id_next_call_type) {
870 case INFO_NTYPE_INTERNATIONAL:
871 fprintf(fp,"id_next_call i%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
873 case INFO_NTYPE_NATIONAL:
874 fprintf(fp,"id_next_call n%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
876 case INFO_NTYPE_SUBSCRIBER:
877 fprintf(fp,"id_next_call s%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
880 fprintf(fp,"id_next_call %s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
884 fprintf(fp,"# Allow user to change caller ID.\n");
885 fprintf(fp,"change_callerid %s\n\n", ext_yesno[ext->change_callerid]);
887 fprintf(fp,"# Caller Line Identification Presentation (CLIP)\n");
888 fprintf(fp,"# clip (asis|hide)\n");
889 fprintf(fp,"# asis: On forwarded calls the CLIP is used as presented by the calling party.\n");
890 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
893 fprintf(fp,"clip hide\n\n");
896 fprintf(fp,"clip asis\n\n");
899 fprintf(fp,"# Connected Line Identification Presentation (COLP)\n");
900 fprintf(fp,"# colp (asis|hide|force)\n");
901 fprintf(fp,"# asis: Provides colp as defined by the extension's caller id.\n");
902 fprintf(fp,"# On forwarded calls the COLP is used as presented by the called party.\n");
903 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
904 fprintf(fp,"# force: If COLP is not presented by forwarded calls the dialed number is used.\n");
907 fprintf(fp,"colp hide\n\n");
910 fprintf(fp,"colp force\n\n");
913 fprintf(fp,"colp asis\n\n");
916 fprintf(fp,"# CLIP Prefix\n");
917 fprintf(fp,"# Adds a prefix to incoming caller IDs, so telephones will be able to respond\n");
918 fprintf(fp,"# to unanswered calls from their list. The prefix must be the digit(s) to get\n");
919 fprintf(fp,"# an external line. The caller ID will then be extendet so that they can be\n");
920 fprintf(fp,"# dialed from internal telephones. Many telephones have this feature, but some\n");
921 fprintf(fp,"# don't.\n");
922 fprintf(fp,"clip_prefix %s\n\n",ext->clip_prefix);
924 fprintf(fp,"# Keypad control\n");
925 fprintf(fp,"# If supported by telephone, pressing a key on the keypad will not result in\n");
926 fprintf(fp,"# DTMF tone, but the digit is transmitted via D-channel diaing info.\n");
927 fprintf(fp,"keypad %s\n\n",(ext->keypad)?"yes":"no");
929 fprintf(fp,"# Ignore restriction of COLP and CLIP\n");
930 fprintf(fp,"# In this case even restricted numbers are presented to this extension.\n");
931 fprintf(fp,"# This also works for incoming external anonymous calls IF:\n");
932 fprintf(fp,"# You have the CLIRIGN feature like POLICE or equivalent.\n");
933 fprintf(fp,"anon-ignore %s\n\n",(ext->anon_ignore)?"yes":"no");
935 fprintf(fp,"# Dialing rights (none|internal|local|national|international)\n");
936 fprintf(fp,"rights %s\n\n",ext_rights[ext->rights]);
938 fprintf(fp,"# Delete function for external calls. '*' will delete the last digit, '#' will\n");
939 fprintf(fp,"# delete the complete number. Also enable 'display_dialing' to see on the\n");
940 fprintf(fp,"# display what actually happens.\n");
941 fprintf(fp,"delete_ext %s\n\n",ext_yesno[ext->delete_ext]);
943 fprintf(fp,"# If noknocking is enabled, the caller will get a busy message when the\n");
944 fprintf(fp,"# extension is doing at least one call.\n");
945 fprintf(fp,"noknocking %s\n\n",ext_yesno[ext->noknocking]);
947 fprintf(fp,"# Transmit volume (-8 .. 8)\n");
948 fprintf(fp,"# 0 = normal\n");
949 fprintf(fp,"# 1 = double, 2 = quadrupel, 8 = 256 times (amplitude)\n");
950 fprintf(fp,"# -1 = half, -2 = quarter, 8 = 1/256th (amplitude)\n");
951 fprintf(fp,"# Audio data is limited to the maximum value when exceeds limit.\n");
952 fprintf(fp,"tx_gain %d\n\n",ext->tx_gain);
954 fprintf(fp,"# Receive volume (-8 .. 8)\n");
955 fprintf(fp,"# (see tx_gain)\n");
956 fprintf(fp,"rx_gain %d\n\n",ext->rx_gain);
959 fprintf(fp,"# Force to use tones and announcements generated by the pbx.\n");
960 fprintf(fp,"# For internal calls always own tones are used. You may specify own tones for\n");
961 fprintf(fp,"# different call states:\n");
962 fprintf(fp,"# own_setup (dialtone and during dialing)\n");
963 fprintf(fp,"# own_proceeding (call in poceeding state)\n");
964 fprintf(fp,"# own_alerting (call is ringing)\n");
965 fprintf(fp,"# own_cause (when the call gets disconnected or failed to be completed)\n");
966 fprintf(fp,"own_setup %s\n",ext_yesno[ext->own_setup]);
967 fprintf(fp,"own_proceeding %s\n",ext_yesno[ext->own_proceeding]);
968 fprintf(fp,"own_alerting %s\n",ext_yesno[ext->own_alerting]);
969 fprintf(fp,"own_cause %s\n\n",ext_yesno[ext->own_cause]);
971 fprintf(fp,"# Allow facility information to be transfered to the telephone.\n");
972 fprintf(fp,"# This is equired to receive advice of charge.\n");
973 fprintf(fp,"facility %s\n\n",ext_yesno[ext->facility]);
975 fprintf(fp,"# Display clear causes using display messages (Q.850)\n# This must be one of the following:\n");
976 fprintf(fp,"# none (no displaying of clear causes)\n");
977 fprintf(fp,"# english (display cause text in english)\n");
978 fprintf(fp,"# german (display cause text in german)\n");
979 fprintf(fp,"# number (display cause number only)\n");
980 fprintf(fp,"# english-location (display cause text in english and location)\n");
981 fprintf(fp,"# german-location (display cause text in german and location)\n");
982 switch(ext->display_cause) {
983 case DISPLAY_CAUSE_ENGLISH:
984 fprintf(fp,"display_cause english\n\n");
986 case DISPLAY_CAUSE_GERMAN:
987 fprintf(fp,"display_cause german\n\n");
989 case DISPLAY_LOCATION_ENGLISH:
990 fprintf(fp,"display_cause english-location\n\n");
992 case DISPLAY_LOCATION_GERMAN:
993 fprintf(fp,"display_cause german-location\n\n");
995 case DISPLAY_CAUSE_NUMBER:
996 fprintf(fp,"display_cause number\n\n");
999 fprintf(fp,"display_cause none\n\n");
1002 fprintf(fp,"# Display external caller ids using display override (yes or no)\n");
1003 fprintf(fp,"# example: \"15551212\"\n");
1004 fprintf(fp,"display_ext %s\n\n",(ext->display_ext)?"yes":"no");
1006 fprintf(fp,"# Display internal caller ids using display override (yes or no)\n");
1007 fprintf(fp,"# example: \"200 (int)\"\n");
1008 fprintf(fp,"display_int %s\n\n",(ext->display_int)?"yes":"no");
1010 fprintf(fp,"# Display if calls are anonymous using display override (yes or no)\n");
1011 fprintf(fp,"# This makes only sense if the anon-ignore feature is enabled.\n");
1012 fprintf(fp,"# example: \"15551212 anon\"\n");
1013 fprintf(fp,"display_anon %s\n\n",(ext->display_anon)?"yes":"no");
1015 fprintf(fp,"# Display fake caller ids using display override (yes or no)\n");
1016 fprintf(fp,"# If the caller uses \"clip no screening\", you will see if the number is\n");
1017 fprintf(fp,"# real or fake\n");
1018 fprintf(fp,"# example: \"15551212 fake\"\n");
1019 fprintf(fp,"display_fake %s\n\n",(ext->display_fake)?"yes":"no");
1021 fprintf(fp,"# Display caller's name if available. (yes or no)\n");
1022 fprintf(fp,"# example: \"15551212 Axel\"\n");
1023 fprintf(fp,"display_name %s\n\n",(ext->display_name)?"yes":"no");
1025 fprintf(fp,"# Display menu when '*' and '#' is pressed. The menu shows all prefixes for\n");
1026 fprintf(fp,"# internal dialing by pressing '*' for previous prefix and '#' for next prefix.\n");
1027 fprintf(fp,"# Also the dialed prefix is show on display. (yes or no)\n");
1028 fprintf(fp,"display_menu %s\n\n",(ext->display_menu)?"yes":"no");
1030 fprintf(fp,"# Display digits as they are interpreted by pbx. (yes or no)\n");
1031 fprintf(fp,"display_dialing %s\n\n",(ext->display_dialing)?"yes":"no");
1033 fprintf(fp,"# Tones directory for announcements and patterns\n");
1034 fprintf(fp,"# Enter nothing for default tones as selected by options.conf or interface.conf.\n");
1035 fprintf(fp,"tones_dir %s\n\n",ext->tones_dir);
1037 fprintf(fp,"# Record calls to extension's directory. The file is written as wave.\n");
1038 fprintf(fp,"# This must be one of the following:\n");
1039 fprintf(fp,"# off (no recording)\n");
1040 fprintf(fp,"# mono (records wave 16 bit mono, 128kbits/s)\n");
1041 fprintf(fp,"# stereo (records wave 32 bit stereo, 256kbits/s)\n");
1042 fprintf(fp,"# 8bit (records wave 8 bit mono, 64kbits/s)\n");
1043 fprintf(fp,"# law (records xLaw encoded, as specified in options.conf, 64kbps/s)\n");
1044 switch(ext->record) {
1046 fprintf(fp,"record mono\n\n");
1049 fprintf(fp,"record stereo\n\n");
1052 fprintf(fp,"record 8bit\n\n");
1055 fprintf(fp,"record law\n\n");
1058 fprintf(fp,"record off\n\n");
1061 fprintf(fp,"# Password for callback and login\n");
1062 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1063 fprintf(fp,"password %s\n\n",ext->password);
1065 fprintf(fp,"# The Answering Machine. Enter the mode of answering machine.\n");
1066 fprintf(fp,"# This must be one of the following:\n");
1067 fprintf(fp,"# normal (plays announcement and records after that)\n");
1068 fprintf(fp,"# parallel (plays announcement and records also DURING announcement.)\n");
1069 fprintf(fp,"# announcement (just plays announcement and hangs up)\n");
1070 switch(ext->vbox_mode) {
1071 case VBOX_MODE_PARALLEL:
1072 fprintf(fp,"vbox_mode parallel\n\n");
1074 case VBOX_MODE_ANNOUNCEMENT:
1075 fprintf(fp,"vbox_mode announcement\n\n");
1078 fprintf(fp,"vbox_mode normal\n\n");
1081 fprintf(fp,"# The Answering Machine. Enter the type of codec for recording.\n");
1082 fprintf(fp,"# This must be one of the following:\n");
1083 fprintf(fp,"# law (alaw/ulas codec, as specified in options.conf)\n");
1084 fprintf(fp,"# mono (16 bit mono wave file)\n");
1085 fprintf(fp,"# stereo (16 bit stereo wave file)\n");
1086 fprintf(fp,"# 8bit (8 bit mono wave file)\n");
1087 switch(ext->vbox_codec) {
1089 fprintf(fp,"vbox_codec law\n\n");
1092 fprintf(fp,"vbox_codec stereo\n\n");
1095 fprintf(fp,"vbox_codec 8bit\n\n");
1098 fprintf(fp,"vbox_codec mono\n\n");
1101 fprintf(fp,"# The Answering Machine. Enter maximum time to record after announcement.\n");
1102 fprintf(fp,"# Leave empty, enter \"infinite\" or give time in seconds.\n");
1103 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1105 fprintf(fp,"vbox_time %d\n\n",ext->vbox_time);
1107 fprintf(fp,"vbox_time infinite\n\n");
1109 fprintf(fp,"# The Answering Machine. Enter mode for display current state.\n");
1110 fprintf(fp,"# This must be one of the following:\n");
1111 fprintf(fp,"# brief (displays brief information, for small displays)\n");
1112 fprintf(fp,"# detailed (displays detailed information, for larger displays)\n");
1113 fprintf(fp,"# off (don't display anything)\n");
1114 switch(ext->vbox_display) {
1115 case VBOX_DISPLAY_OFF:
1116 fprintf(fp,"vbox_display off\n\n");
1118 case VBOX_DISPLAY_DETAILED:
1119 fprintf(fp,"vbox_display detailed\n\n");
1122 fprintf(fp,"vbox_display brief\n\n");
1125 fprintf(fp,"# The Answering Machine. Enter type of language: \"english\" or \"german\"\n");
1126 fprintf(fp,"# Display information of the menu, will be provided as specified.\n");
1127 fprintf(fp,"# The menu's voice is located in \"vbox_english\" and \"vbox_german\".\n");
1128 if (ext->vbox_language)
1129 fprintf(fp,"vbox_language german\n\n");
1131 fprintf(fp,"vbox_language english\n\n");
1133 fprintf(fp,"# The Answering Machine. Enter email to send incoming messages to:\n");
1134 fprintf(fp,"# All incoming message will be send to the given address.\n");
1135 fprintf(fp,"# The audio file is attached if \"vbox_email_file\" is 'yes'\n");
1136 fprintf(fp,"vbox_email %s\n", ext->vbox_email);
1137 fprintf(fp,"vbox_email_file %s\n\n",ext_yesno[ext->vbox_email_file]);
1139 fprintf(fp,"# If audio path is connected prior answering of a call, say 'yes'\n");
1140 fprintf(fp,"# will cause the call to be billed after playing the announcement. (yes or no)\n");
1141 fprintf(fp,"vbox_free %s\n\n",(ext->vbox_free)?"yes":"no");
1143 fprintf(fp,"# Accept incoming data calls as it would be an audio call.\n");
1144 fprintf(fp,"datacall %s\n\n",ext_yesno[ext->datacall]);
1146 fprintf(fp,"# Include seconds (time) in the connect message. (Should be always enabled.)\n");
1147 fprintf(fp,"seconds %s\n\n",ext_yesno[1-ext->no_seconds]);
1149 fprintf(fp,"# Last outgoing and incoming numbers (including prefix)\n");
1151 while(i < MAX_REMEMBER) {
1152 if (ext->last_out[i][0])
1153 fprintf(fp,"last_out %s\n",ext->last_out[i]);
1157 while(i < MAX_REMEMBER) {
1158 if (ext->last_in[i][0])
1159 fprintf(fp,"last_in %s\n",ext->last_in[i]);
1170 /* write log for extension
1173 int write_log(char *number, char *callerid, char *calledid, time_t start, time_t stop, int aoce, int cause, int location)
1175 const char *mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1180 if (callerid[0] == '\0')
1181 callerid = (char *)"<unknown>";
1183 SPRINT(filename, "%s/%s/log", EXTENSION_DATA, number);
1185 if (!(fp = fopen(filename, "a"))) {
1186 PERROR("Cannot open log: \"%s\"\n", filename);
1190 tm = localtime(&start);
1191 fprintf(fp,"%s %2d %04d %02d:%02d:%02d %s", mon[tm->tm_mon], tm->tm_mday, tm->tm_year+1900, tm->tm_hour, tm->tm_min, tm->tm_sec, number);
1193 fprintf(fp," %2ld:%02d:%02d", (stop-start)/3600, (((unsigned int)(stop-start))/60)%60, ((unsigned int)(stop-start))%60);
1195 fprintf(fp," --:--:--");
1196 fprintf(fp," %s -> %s", callerid, calledid);
1197 if (cause >= 1 && cause <=127 && location>=0 && location<=15)
1198 fprintf(fp," (cause=%d '%s' location=%d '%s')", cause, isdn_cause[cause].german, location, isdn_location[location].german);
1208 * reads phone book of extextension and compares the given elements which
1209 * are: abreviation, phone number, name (name is not compared)
1210 * on success a 1 is returned and the pointers of elements are set to the
1213 int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, char **name_pointer)
1218 static char abbrev[32], phone[256], name[256];
1219 unsigned int line,i;
1221 int found = 0, found_if_more_digits = 0;
1223 SPRINT(filename, "%s/%s/phonebook", EXTENSION_DATA, number);
1225 if (!(fp = fopen(filename, "r"))) {
1226 PERROR("Cannot open phonebook: \"%s\"\n", filename);
1231 while((fgets(buffer, sizeof(buffer), fp))) {
1233 buffer[sizeof(buffer)-1] = '\0';
1234 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1237 while(*p <= 32) { /* skip spaces */
1242 if (*p==0 || *p=='#') /* ignore comments and empty line */
1249 i=0; /* read abbrev */
1251 if (i+1 >= sizeof(abbrev)) {
1252 PERROR_RUNTIME("Error in %s (line %d): abbrev too long.\n",filename,line);
1259 while(*p <= 32) { /* skip spaces */
1265 if (*p!=0 && *p!='#') { /* phone */
1266 i=0; /* read phone */
1268 if (i+1 >= sizeof(phone)) {
1269 PERROR_RUNTIME("Error in %s (line %d): phone too long.\n",filename,line);
1275 while(*p <= 32) { /* skip spaces */
1282 if (*p!=0 && *p!='#') { /* name */
1283 i=0; /* read name */
1285 if (i+1 >= sizeof(name)) {
1286 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1294 if (*abbrev_pointer) {
1295 if (!strncmp(*abbrev_pointer, abbrev, strlen(*abbrev_pointer))) {
1296 /* may match if abbreviation is longer */
1297 found_if_more_digits = 1;
1299 if (!!strcasecmp(*abbrev_pointer, abbrev))
1303 if (!!strcasecmp(*phone_pointer, phone))
1306 if (!!strcasecmp(*name_pointer, name))
1310 break; /* found entry */
1316 *abbrev_pointer = abbrev;
1317 *phone_pointer = phone;
1318 *name_pointer = name;
1322 if (found_if_more_digits)
1328 /* parsing secrets file
1330 * 'number' specifies the externsion number, not the caller id
1331 * 'remote_id' specifies the dialed number, or the caller id for incoming calls
1332 * the result is the auth, crypt and key string, and 1 is returned.
1333 * on failure or not matching number, the 0 is returned
1335 int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **crypt_pointer, char **key_pointer)
1341 static char auth[64], crypt[64], key[4096];
1342 unsigned int line,i;
1346 SPRINT(filename, "%s/%s/secrets", EXTENSION_DATA, number);
1348 if (!(fp = fopen(filename, "r"))) {
1349 PERROR("Cannot open secrets: \"%s\"\n", filename);
1354 while((fgets(buffer, sizeof(buffer), fp))) {
1356 buffer[sizeof(buffer)-1] = '\0';
1357 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1360 while(*p <= 32) { /* skip spaces */
1365 if (*p==0 || *p=='#') /* ignore comments and empty line */
1373 i=0; /* read auth */
1375 if (i+1 >= sizeof(remote)) {
1376 PERROR_RUNTIME("Error in %s (line %d): remote too long.\n",filename,line);
1383 while(*p <= 32) { /* skip spaces */
1389 if (*p!=0 && *p!='#') { /* auth */
1390 i=0; /* read auth */
1392 if (i+1 >= sizeof(auth)) {
1393 PERROR_RUNTIME("Error in %s (line %d): auth too long.\n",filename,line);
1399 while(*p <= 32) { /* skip spaces */
1406 if (*p!=0 && *p!='#') { /* crypt */
1407 i=0; /* read crypt */
1409 if (i+1 >= sizeof(crypt)) {
1410 PERROR_RUNTIME("Error in %s (line %d): crypt too long.\n",filename,line);
1416 while(*p <= 32) { /* skip spaces */
1423 if (*p!=0 && *p!='#') { /* key */
1426 if (i+1 >= sizeof(key)) {
1427 PERROR_RUNTIME("Error in %s (line %d): key too long.\n",filename,line);
1434 //printf("COMPARING: '%s' with '%s' %s %s %s\n", remote_id, remote, auth, crypt, key);
1436 if (!!strcasecmp(remote, remote_id))
1440 break; /* found entry */
1446 *auth_pointer = auth;
1447 *crypt_pointer = crypt;
1456 * the caller id is given and the name is returned. if the name is not found,
1458 * on success a 1 is returned and the pointers of elements are set to the
1461 char *parse_directory(char *number, int type)
1466 static char phone[32], name[64];
1467 unsigned int line,i;
1471 SPRINT(filename, "%s/directory.list", CONFIG_DATA);
1473 if (!(fp = fopen(filename, "r"))) {
1474 PERROR("Cannot open directory: \"%s\"\n", filename);
1479 while((fgets(buffer, sizeof(buffer), fp))) {
1481 buffer[sizeof(buffer)-1] = '\0';
1482 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1485 while(*p <= 32) { /* skip spaces */
1490 if (*p==0 || *p=='#') /* ignore comments and empty line */
1496 i=0; /* read number */
1498 if (i+1 >= sizeof(phone)) {
1499 PERROR_RUNTIME("Error in %s (line %d): number too long.\n",filename,line);
1506 while(*p <= 32) { /* skip spaces */
1512 i=0; /* read name */
1514 if (i+1 >= sizeof(name)) {
1515 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1522 if (phone[0] == 'i') {
1523 if (type != INFO_NTYPE_INTERNATIONAL)
1525 if (!strcmp(number, phone+1)) {
1531 if (phone[0] == 'n') {
1532 if (type != INFO_NTYPE_NATIONAL)
1534 if (!strcmp(number, phone+1)) {
1540 if (phone[0] == 's') {
1541 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1543 if (!strcmp(number, phone+1)) {
1549 if (!strncmp(phone, options.international, strlen(options.international))) {
1550 if (type != INFO_NTYPE_INTERNATIONAL)
1552 if (!strcmp(number, phone+strlen(options.international))) {
1558 if (!options.national[0]) { /* no national prefix */
1559 if (type == INFO_NTYPE_INTERNATIONAL)
1561 if (!strcmp(number, phone)) {
1567 if (!strncmp(phone, options.national, strlen(options.national))) {
1568 if (type != INFO_NTYPE_NATIONAL)
1570 if (!strcmp(number, phone+strlen(options.national))) {
1576 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1578 if (!strcmp(number, phone)) {
1592 /* parse callbackauth
1594 * searches for the given caller id and returns 1 == true or 0 == false
1596 int parse_callbackauth(char *number, struct caller_info *callerinfo)
1601 unsigned int line,i;
1603 static char caller_type[32], caller_id[64];
1606 SPRINT(filename, "%s/%s/callbackauth", EXTENSION_DATA, number);
1608 if (!(fp = fopen(filename, "r"))) {
1609 PDEBUG(DEBUG_EPOINT, "Cannot open callbackauth: \"%s\"\n", filename);
1614 while((fgets(buffer, sizeof(buffer), fp))) {
1616 buffer[sizeof(buffer)-1] = '\0';
1617 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1620 while(*p <= 32) { /* skip spaces */
1625 if (*p==0 || *p=='#') /* ignore comments and empty line */
1631 i=0; /* read caller_type */
1633 if (i+1 >= sizeof(caller_type)) {
1634 PERROR_RUNTIME("Error in %s (line %d): caller_type too long.\n",filename,line);
1637 caller_type[i+1] = '\0';
1638 caller_type[i++] = *p++;
1641 while(*p <= 32) { /* skip spaces */
1647 if (*p!=0 && *p!='#') { /* caller_id */
1648 i=0; /* read caller_id */
1650 if (i+1 >= sizeof(caller_id)) {
1651 PERROR_RUNTIME("Error in %s (line %d): caller_id too long.\n",filename,line);
1654 caller_id[i+1] = '\0';
1655 caller_id[i++] = *p++;
1660 if (caller_type[0]=='\0' && caller_id[0]=='\0')
1663 if (atoi(caller_type) != callerinfo->ntype)
1666 if (!!strcmp(caller_id, callerinfo->id))
1670 break; /* found entry */
1681 /* append line to callbackauth
1684 void append_callbackauth(char *number, struct caller_info *callerinfo)
1689 SPRINT(filename, "%s/%s/callbackauth", EXTENSION_DATA, number);
1691 if (callerinfo->id[0]=='\0') {
1692 PERROR("caller has no id.\n");
1695 if (!(fp = fopen(filename, "a"))) {
1696 PERROR("Cannot open callbackauth: \"%s\"\n", filename);
1700 fprintf(fp, "%6d %s\n", callerinfo->ntype, callerinfo->id);