1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** reading and writing files for extensions **
10 \*****************************************************************************/
16 char *ext_rights[] = {
34 * reads extension from given extension number and fills structure
36 int read_extension(struct extension *ext, char *number)
42 char param[256],param2[256];
45 int last_in_count = 0, last_out_count = 0;
47 if (number[0] == '\0')
50 SPRINT(filename, "%s/%s/%s/settings", INSTALL_DATA, options.extensions_dir, number);
52 if (!(fp = fopen(filename, "r")))
54 PDEBUG(DEBUG_CONFIG, "the given extension doesn't exist: \"%s\"\n", filename);
59 memset(ext, 0, sizeof(struct extension));
60 ext->rights = 4; /* international */
61 ext->tout_setup = 120;
62 ext->tout_dialing = 120;
63 ext->tout_proceeding = 120;
64 ext->tout_alerting = 120;
65 ext->tout_disconnect = 120;
66 // ext->tout_hold = 900;
67 // ext->tout_park = 900;
69 ext->vbox_codec = CODEC_MONO;
72 while((fgets(buffer, sizeof(buffer), fp)))
75 buffer[sizeof(buffer)-1] = '\0';
76 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
79 while(*p <= 32) /* skip spaces */
85 if (*p==0 || *p=='#') /* ignore comments and empty line */
89 i=0; /* read option */
92 if (i+1 >= sizeof(option))
94 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
101 while(*p <= 32) /* skip spaces */
110 if (*p!=0 && *p!='#') /* param */
112 i=0; /* read param */
115 if (i+1 >= sizeof(param))
117 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
124 while(*p <= 32) /* skip spaces */
131 if (*p!=0 && *p!='#') /* param2 */
133 i=0; /* read param2 */
136 if (i+1 >= sizeof(param2))
138 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
147 /* at this point we have option and param */
150 if (!strcmp(option,"name"))
152 SCPY(ext->name, param);
155 SCAT(ext->name, " ");
156 SCAT(ext->name, param2);
159 PDEBUG(DEBUG_CONFIG, "name of extension: %s\n",param);
161 if (!strcmp(option,"prefix"))
163 SCPY(ext->prefix, param);
165 PDEBUG(DEBUG_CONFIG, "dial prefix on pickup: %s\n",param);
167 if (!strcmp(option,"next"))
169 SCPY(ext->next, param);
171 PDEBUG(DEBUG_CONFIG, "dial next on pickup: %s\n",param);
173 if (!strcmp(option,"alarm"))
175 SCPY(ext->alarm, param);
177 PDEBUG(DEBUG_CONFIG, "alarm message (if prefix): %s\n",param);
179 if (!strcmp(option,"cfu"))
181 SCPY(ext->cfu, param);
183 PDEBUG(DEBUG_CONFIG, "call forward unconditional: %s\n",param);
185 if (!strcmp(option,"cfb"))
187 SCPY(ext->cfb, param);
189 PDEBUG(DEBUG_CONFIG, "call forward when busy: %s\n",param);
191 if (!strcmp(option,"cfnr"))
193 SCPY(ext->cfnr, param);
195 PDEBUG(DEBUG_CONFIG, "call forward on no response: %s\n",param);
197 if (!strcmp(option,"cfnr_delay"))
199 ext->cfnr_delay = atoi(param);
200 if (ext->cfnr_delay < 0)
203 PDEBUG(DEBUG_CONFIG, "call forward no response delay: %d\n",ext->cfnr_delay);
205 if (!strcmp(option,"cfp"))
207 SCPY(ext->cfp, param);
209 PDEBUG(DEBUG_CONFIG, "call forward parallel: %s\n",param);
211 if (!strcmp(option,"change_forward"))
216 if (!strcasecmp(param,ext_yesno[i]))
222 ext->change_forward = i;
223 PDEBUG(DEBUG_CONFIG, "allow the change of forwarding: %s\n", ext_yesno[i]);
226 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_forward: %s\n", param);
229 if (!strcmp(option,"interfaces"))
231 SCPY(ext->interfaces, param);
233 PDEBUG(DEBUG_CONFIG, "interfaces to ring calls to extension: %s %s\n",param,param2);
235 if (!strcmp(option,"callerid"))
237 ext->callerid_present = INFO_PRESENT_ALLOWED;
238 if (!strncasecmp(param2, "anonymous", 9))
239 ext->callerid_present = INFO_PRESENT_RESTRICTED;
240 if (!strncasecmp(param, "non", 3))
242 ext->callerid[0] = '\0';
243 ext->callerid_present = INFO_PRESENT_NOTAVAIL;
244 ext->callerid_type = INFO_NTYPE_UNKNOWN;
245 PDEBUG(DEBUG_CONFIG, "caller id: ID NOT AVAILABLE\n");
251 ext->callerid_type = INFO_NTYPE_INTERNATIONAL;
252 SCPY(ext->callerid, param+1);
253 PDEBUG(DEBUG_CONFIG, "caller id: %s INTERNATIONAL\n",param+1);
257 ext->callerid_type = INFO_NTYPE_NATIONAL;
258 SCPY(ext->callerid, param+1);
259 PDEBUG(DEBUG_CONFIG, "caller id: %s NATIONAL\n",param+1);
263 ext->callerid_type = INFO_NTYPE_SUBSCRIBER;
264 SCPY(ext->callerid, param+1);
265 PDEBUG(DEBUG_CONFIG, "caller id: %s SUBSCRIBER\n",param+1);
268 ext->callerid_type = INFO_NTYPE_UNKNOWN;
269 SCPY(ext->callerid, param);
270 PDEBUG(DEBUG_CONFIG, "caller id: %s UNKNOWN\n",param);
272 ext->callerid[sizeof(ext->callerid)-1] = 0;
274 if (!strcmp(option,"id_next_call"))
276 ext->id_next_call_present = INFO_PRESENT_ALLOWED;
277 if (!strncasecmp(param2, "anonymous", 9))
278 ext->id_next_call_present = INFO_PRESENT_RESTRICTED;
279 if (param[0] == '\0')
281 ext->id_next_call_present = -1;
282 PDEBUG(DEBUG_CONFIG, "id next call: no id for next call\n");
284 if (!strncasecmp(param, "none", 3))
286 ext->id_next_call[0] = '\0';
287 ext->id_next_call_present = INFO_PRESENT_NOTAVAIL;
288 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
289 PDEBUG(DEBUG_CONFIG, "id next call: ID NOT AVAILABLE\n");
295 ext->id_next_call_type = INFO_NTYPE_INTERNATIONAL;
296 SCPY(ext->id_next_call, param+1);
297 PDEBUG(DEBUG_CONFIG, "id next call: %s INTERNATIONAL\n",param+1);
301 ext->id_next_call_type = INFO_NTYPE_NATIONAL;
302 SCPY(ext->id_next_call, param+1);
303 PDEBUG(DEBUG_CONFIG, "id next call: %s NATIONAL\n",param+1);
307 ext->id_next_call_type = INFO_NTYPE_SUBSCRIBER;
308 SCPY(ext->id_next_call, param+1);
309 PDEBUG(DEBUG_CONFIG, "id next call: %s SUBSCRIBER\n",param+1);
312 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
313 SCPY(ext->id_next_call, param);
314 PDEBUG(DEBUG_CONFIG, "id next call: %s UNKNOWN\n",param);
320 if (!strcmp(option,"change_callerid"))
325 if (!strcasecmp(param,ext_yesno[i]))
331 ext->change_callerid = i;
332 PDEBUG(DEBUG_CONFIG, "allow the change of caller id: %s\n", ext_yesno[i]);
335 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_callerid: %s\n", param);
338 if (!strcmp(option,"anon-ignore"))
343 if (!strcasecmp(param,ext_yesno[i]))
349 ext->anon_ignore = i;
350 PDEBUG(DEBUG_CONFIG, "ignore restriction of CLIP & COLP %s\n", ext_yesno[i]);
353 PDEBUG(DEBUG_CONFIG, "unknown parameter given anon-ignore: %s\n", param);
356 if (!strcmp(option,"clip"))
358 if (!strcasecmp(param, "hide"))
359 ext->clip = CLIP_HIDE;
361 ext->clip = CLIP_ASIS;
363 PDEBUG(DEBUG_CONFIG, "clip: %d\n",ext->clip);
365 if (!strcmp(option,"colp"))
367 if (!strcasecmp(param, "hide"))
368 ext->colp = COLP_HIDE;
369 else if (!strcasecmp(param, "force"))
370 ext->colp = COLP_FORCE;
372 ext->colp = COLP_ASIS;
374 PDEBUG(DEBUG_CONFIG, "colp: %d\n",ext->colp);
376 if (!strcmp(option,"clip_prefix"))
378 SCPY(ext->clip_prefix, param);
380 PDEBUG(DEBUG_CONFIG, "clip prefix: %s\n",param);
382 if (!strcmp(option,"keypad"))
387 if (!strcasecmp(param,ext_yesno[i]))
394 PDEBUG(DEBUG_CONFIG, "use keypad to do call control %s\n", ext_yesno[i]);
397 PDEBUG(DEBUG_CONFIG, "unknown parameter given keypad: %s\n", param);
400 if (!strcmp(option,"centrex"))
405 if (!strcasecmp(param,ext_yesno[i]))
412 PDEBUG(DEBUG_CONFIG, "use centrex to display name %s\n", ext_yesno[i]);
415 PDEBUG(DEBUG_CONFIG, "unknown parameter given centrex: %s\n", param);
418 if (!strcmp(option,"rights"))
423 if (!strcasecmp(param,ext_rights[i]))
430 PDEBUG(DEBUG_CONFIG, "rights to dial: %s\n", ext_rights[i]);
433 PDEBUG(DEBUG_CONFIG, "given rights unknown: %s\n", param);
436 if (!strcmp(option,"delete_ext"))
441 if (!strcasecmp(param,ext_yesno[i]))
448 PDEBUG(DEBUG_CONFIG, "enables the delete key function for external calls: %s\n", ext_yesno[i]);
451 PDEBUG(DEBUG_CONFIG, "unknown parameter given delete: %s\n", param);
454 if (!strcmp(option,"noknocking"))
459 if (!strcasecmp(param,ext_yesno[i]))
466 PDEBUG(DEBUG_CONFIG, "noknocking %s\n", ext_yesno[i]);
469 PDEBUG(DEBUG_CONFIG, "given noknocking param unknown: %s\n", param);
472 if (!strcmp(option,"rxvol"))
474 ext->rxvol = atoi(param);
475 if (ext->rxvol<-8 || ext->rxvol>8)
478 PDEBUG(DEBUG_CONFIG, "receive volume: %d\n",ext->rxvol);
480 if (!strcmp(option,"txvol"))
482 ext->txvol = atoi(param);
483 if (ext->txvol<-8 || ext->txvol>8)
486 PDEBUG(DEBUG_CONFIG, "transmit volume: %d\n",ext->txvol);
488 if (!strcmp(option,"tout_setup"))
490 ext->tout_setup = atoi(param);
491 if (ext->tout_setup < 0)
494 PDEBUG(DEBUG_CONFIG, "timeout setup: %d\n",ext->tout_setup);
496 if (!strcmp(option,"tout_dialing"))
498 ext->tout_dialing = atoi(param);
499 if (ext->tout_dialing < 0)
500 ext->tout_dialing = 0;
502 PDEBUG(DEBUG_CONFIG, "timeout dialing: %d\n",ext->tout_dialing);
504 if (!strcmp(option,"tout_proceeding"))
506 ext->tout_proceeding = atoi(param);
507 if (ext->tout_proceeding < 0)
508 ext->tout_proceeding = 0;
510 PDEBUG(DEBUG_CONFIG, "timeout proceeding: %d\n",ext->tout_proceeding);
512 if (!strcmp(option,"tout_alerting"))
514 ext->tout_alerting = atoi(param);
515 if (ext->tout_alerting < 0)
516 ext->tout_alerting = 0;
518 PDEBUG(DEBUG_CONFIG, "timeout alerting: %d\n",ext->tout_alerting);
520 if (!strcmp(option,"tout_disconnect"))
522 ext->tout_disconnect = atoi(param);
523 if (ext->tout_disconnect < 0)
524 ext->tout_disconnect = 0;
526 PDEBUG(DEBUG_CONFIG, "timeout disconnect: %d\n",ext->tout_disconnect);
529 if (!strcmp(option,"tout_hold"))
531 ext->tout_hold = atoi(param);
532 if (ext->tout_hold < 0)
535 PDEBUG(DEBUG_CONFIG, "timeout hold: %d\n",ext->tout_hold);
537 if (!strcmp(option,"tout_park"))
539 ext->tout_park = atoi(param);
540 if (ext->tout_park < 0)
543 PDEBUG(DEBUG_CONFIG, "timeout park: %d\n",ext->tout_park);
546 if (!strcmp(option,"own_setup"))
551 if (!strcasecmp(param,ext_yesno[i]))
558 PDEBUG(DEBUG_CONFIG, "own_setup %s\n", ext_yesno[i]);
561 PDEBUG(DEBUG_CONFIG, "given own_setup param unknown: %s\n", param);
564 if (!strcmp(option,"own_proceeding"))
569 if (!strcasecmp(param,ext_yesno[i]))
575 ext->own_proceeding = i;
576 PDEBUG(DEBUG_CONFIG, "own_proceeding %s\n", ext_yesno[i]);
579 PDEBUG(DEBUG_CONFIG, "given own_proceeding param unknown: %s\n", param);
582 if (!strcmp(option,"own_alerting"))
587 if (!strcasecmp(param,ext_yesno[i]))
593 ext->own_alerting = i;
594 PDEBUG(DEBUG_CONFIG, "own_alerting %s\n", ext_yesno[i]);
597 PDEBUG(DEBUG_CONFIG, "given own_alerting param unknown: %s\n", param);
600 if (!strcmp(option,"own_cause"))
605 if (!strcasecmp(param,ext_yesno[i]))
612 PDEBUG(DEBUG_CONFIG, "own_cause %s\n", ext_yesno[i]);
615 PDEBUG(DEBUG_CONFIG, "given own_cause param unknown: %s\n", param);
618 if (!strcmp(option,"facility"))
623 if (!strcasecmp(param,ext_yesno[i]))
630 PDEBUG(DEBUG_CONFIG, "facility %s\n", ext_yesno[i]);
633 PDEBUG(DEBUG_CONFIG, "given facility param unknown: %s\n", param);
636 if (!strcmp(option,"display_cause"))
638 if (!strcasecmp(param, "german"))
639 ext->display_cause = DISPLAY_CAUSE_GERMAN;
640 else if (!strcasecmp(param, "english"))
641 ext->display_cause = DISPLAY_CAUSE_ENGLISH;
642 else if (!strcasecmp(param, "german-location"))
643 ext->display_cause = DISPLAY_LOCATION_GERMAN;
644 else if (!strcasecmp(param, "english-location"))
645 ext->display_cause = DISPLAY_LOCATION_ENGLISH;
646 else if (!strcasecmp(param, "number"))
647 ext->display_cause = DISPLAY_CAUSE_NUMBER;
649 ext->display_cause = DISPLAY_CAUSE_NONE;
651 PDEBUG(DEBUG_CONFIG, "display cause: %d\n",ext->display_cause);
654 if (!strcmp(option,"display_ext"))
656 if (!strcasecmp(param, "number"))
657 ext->display_ext = DISPLAY_CID_NUMBER;
658 else if (!strcasecmp(param, "abbrev"))
659 ext->display_ext = DISPLAY_CID_ABBREVIATION;
660 else if (!strcasecmp(param, "name"))
661 ext->display_ext = DISPLAY_CID_NAME;
662 else if (!strcasecmp(param, "number-name"))
663 ext->display_ext = DISPLAY_CID_NUMBER_NAME;
664 else if (!strcasecmp(param, "name-number"))
665 ext->display_ext = DISPLAY_CID_NAME_NUMBER;
666 else if (!strcasecmp(param, "abbrev-number"))
667 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER;
668 else if (!strcasecmp(param, "abbrev-name"))
669 ext->display_ext = DISPLAY_CID_ABBREV_NAME;
670 else if (!strcasecmp(param, "abbrev-name-number"))
671 ext->display_ext = DISPLAY_CID_ABBREV_NAME_NUMBER;
672 else if (!strcasecmp(param, "abbrev-number-name"))
673 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER_NAME;
675 ext->display_ext = DISPLAY_CID_ASIS;
677 PDEBUG(DEBUG_CONFIG, "display ext: %d\n",ext->display_ext);
680 if (!strcmp(option,"display_ext"))
685 if (!strcasecmp(param,ext_yesno[i]))
691 ext->display_ext = i;
692 PDEBUG(DEBUG_CONFIG, "display ext %s\n", ext_yesno[i]);
695 PDEBUG(DEBUG_CONFIG, "given display_ext param unknown: %s\n", param);
698 if (!strcmp(option,"display_int"))
703 if (!strcasecmp(param,ext_yesno[i]))
709 ext->display_int = i;
710 PDEBUG(DEBUG_CONFIG, "display int %s\n", ext_yesno[i]);
713 PDEBUG(DEBUG_CONFIG, "given display_int param unknown: %s\n", param);
716 if (!strcmp(option,"display_fake"))
721 if (!strcasecmp(param,ext_yesno[i]))
727 ext->display_fake = i;
728 PDEBUG(DEBUG_CONFIG, "display fake caller ids %s\n", ext_yesno[i]);
731 PDEBUG(DEBUG_CONFIG, "given display_fake param unknown: %s\n", param);
734 if (!strcmp(option,"display_anon"))
739 if (!strcasecmp(param,ext_yesno[i]))
745 ext->display_anon = i;
746 PDEBUG(DEBUG_CONFIG, "display anonymouse ids %s\n", ext_yesno[i]);
749 PDEBUG(DEBUG_CONFIG, "given display_anon param unknown: %s\n", param);
752 if (!strcmp(option,"display_menu"))
757 if (!strcasecmp(param,ext_yesno[i]))
763 ext->display_menu = i;
764 PDEBUG(DEBUG_CONFIG, "display menu %s\n", ext_yesno[i]);
767 PDEBUG(DEBUG_CONFIG, "given display_menu param unknown: %s\n", param);
770 if (!strcmp(option,"display_dialing"))
775 if (!strcasecmp(param,ext_yesno[i]))
781 ext->display_dialing = i;
782 PDEBUG(DEBUG_CONFIG, "display dialing %s\n", ext_yesno[i]);
785 PDEBUG(DEBUG_CONFIG, "given display_dialing param unknown: %s\n", param);
788 if (!strcmp(option,"display_name"))
793 if (!strcasecmp(param,ext_yesno[i]))
799 ext->display_name = i;
800 PDEBUG(DEBUG_CONFIG, "display name %s\n", ext_yesno[i]);
803 PDEBUG(DEBUG_CONFIG, "given display_name param unknown: %s\n", param);
806 if (!strcmp(option,"tones_dir"))
808 if (param[strlen(param)-1] == '/')
809 param[strlen(param)-1]=0;
810 SCPY(ext->tones_dir, param);
812 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
814 if (!strcmp(option,"record"))
816 if (!strcasecmp(param, "mono"))
817 ext->record = CODEC_MONO;
818 else if (!strcasecmp(param, "stereo"))
819 ext->record = CODEC_STEREO;
820 else if (!strcasecmp(param, "8bit"))
821 ext->record = CODEC_8BIT;
822 else if (!strcasecmp(param, "law"))
823 ext->record = CODEC_LAW;
825 ext->record = CODEC_OFF;
826 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
828 if (!strcmp(option,"password"))
830 SCPY(ext->password, param);
832 PDEBUG(DEBUG_CONFIG, "password: %s\n",param);
834 if (!strcmp(option,"vbox_mode"))
836 if (!strcasecmp(param, "parallel"))
837 ext->vbox_mode = VBOX_MODE_PARALLEL;
838 else if (!strcasecmp(param, "announcement"))
839 ext->vbox_mode = VBOX_MODE_ANNOUNCEMENT;
841 ext->vbox_mode = VBOX_MODE_NORMAL;
842 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
844 if (!strcmp(option,"vbox_codec"))
846 if (!strcasecmp(param, "stereo"))
847 ext->vbox_codec = CODEC_STEREO;
848 else if (!strcasecmp(param, "8bit"))
849 ext->vbox_codec = CODEC_8BIT;
850 else if (!strcasecmp(param, "law"))
851 ext->vbox_codec = CODEC_LAW;
853 ext->vbox_codec = CODEC_MONO;
854 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
856 if (!strcmp(option,"vbox_time"))
858 ext->vbox_time = atoi(param);
859 if (ext->vbox_time < 0)
862 PDEBUG(DEBUG_CONFIG, "vbox time to record: %d\n",ext->vbox_time);
864 if (!strcmp(option,"vbox_display"))
866 if (!strcasecmp(param, "detailed")
867 || !strcasecmp(param, "detailled"))
868 ext->vbox_display = VBOX_DISPLAY_DETAILED;
869 else if (!strcasecmp(param, "off"))
870 ext->vbox_display = VBOX_DISPLAY_OFF;
872 ext->vbox_display = VBOX_DISPLAY_BRIEF;
873 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
875 if (!strcmp(option,"vbox_language"))
877 if (!strcasecmp(param, "german"))
878 ext->vbox_language = VBOX_LANGUAGE_GERMAN;
880 ext->vbox_language = VBOX_LANGUAGE_ENGLISH;
881 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
883 if (!strcmp(option,"vbox_email"))
885 SCPY(ext->vbox_email, param);
886 PDEBUG(DEBUG_CONFIG, "given vbox email: %s\n", param);
888 if (!strcmp(option,"vbox_email_file"))
893 if (!strcasecmp(param,ext_yesno[i]))
899 ext->vbox_email_file = i;
900 PDEBUG(DEBUG_CONFIG, "attach audio file %s\n", ext_yesno[i]);
903 PDEBUG(DEBUG_CONFIG, "given vbox_email_file param unknown: %s\n", param);
906 if (!strcmp(option,"vbox_free"))
911 if (!strcasecmp(param,ext_yesno[i]))
918 PDEBUG(DEBUG_CONFIG, "vbox_free %s\n", ext_yesno[i]);
921 PDEBUG(DEBUG_CONFIG, "given vbox_free param unknown: %s\n", param);
924 if (!strcmp(option,"last_in"))
926 if (param[0] && last_in_count<MAX_REMEMBER)
928 SCPY(ext->last_in[last_in_count], param);
931 PDEBUG(DEBUG_CONFIG, "last_in dialed number: %s\n",param);
933 if (!strcmp(option,"last_out"))
935 if (param[0] && last_out_count<MAX_REMEMBER)
937 SCPY(ext->last_out[last_out_count], param);
940 PDEBUG(DEBUG_CONFIG, "last_out dialed number: %s\n",param);
942 if (!strcmp(option,"datacall"))
947 if (!strcasecmp(param,ext_yesno[i]))
954 PDEBUG(DEBUG_CONFIG, "datacall %s\n", ext_yesno[i]);
957 PDEBUG(DEBUG_CONFIG, "given datacall param unknown: %s\n", param);
960 if (!strcmp(option,"seconds"))
965 if (!strcasecmp(param,ext_yesno[i]))
971 ext->no_seconds = 1-i;
972 PDEBUG(DEBUG_CONFIG, "seconds %s\n", ext_yesno[i]);
975 PDEBUG(DEBUG_CONFIG, "unknown param for seconds: %s\n", param);
979 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n",filename,line,option);
990 * writes extension for given extension number from structure
992 int write_extension(struct extension *ext, char *number)
998 if (number[0] == '\0')
1001 SPRINT(filename, "%s/%s/%s/settings", INSTALL_DATA, options.extensions_dir, number);
1003 if (!(fp = fopen(filename, "w")))
1005 PERROR("Cannot open settings: \"%s\"\n", filename);
1009 fprintf(fp,"# Settings of extension %s\n\n", number);
1011 fprintf(fp,"# Name of extension:\n");
1012 fprintf(fp,"name %s\n\n",ext->name);
1014 fprintf(fp,"# Predialed prefix after pick-up of the phone\n");
1015 fprintf(fp,"prefix %s\n\n",ext->prefix);
1017 fprintf(fp,"# Next prefix to dial pick-up of the phone\n");
1018 fprintf(fp,"# This will be cleared on hangup.\n");
1019 fprintf(fp,"next %s\n\n",ext->next);
1021 // fprintf(fp,"# Set up alarm message after prefix is dialed and connection is established\n");
1022 // fprintf(fp,"alarm %s\n\n",ext->alarm);
1024 fprintf(fp,"# Ports to ring on calls to extension (starting from 1)\n");
1025 fprintf(fp,"# Seperate ports by using komma. (example: 1,3 would ring incoming calls on\n# port 1 and 3)\n");
1026 fprintf(fp,"interfaces %s\n\n",ext->interfaces);
1028 fprintf(fp,"# Call Forward Unconditional (CFU)\n");
1029 fprintf(fp,"# No port will be called, CFB, CFNR and CFP is ignored.\n");
1030 fprintf(fp,"# Use keyword \"vbox\" to forward call directly to answering machine.\n");
1031 fprintf(fp,"cfu %s\n\n",ext->cfu);
1033 fprintf(fp,"# Call Forward when Busy (CFB)\n");
1034 fprintf(fp,"# If the extension is in use at least once, this forward is done.\n");
1035 fprintf(fp,"# In case of busy line, CFNR and CFP is ignored.\n");
1036 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine when busy.\n");
1037 fprintf(fp,"cfb %s\n\n",ext->cfb);
1039 fprintf(fp,"# Call Forward on No Response (CFNR)\n");
1040 fprintf(fp,"# If noone answers, the call is forwarded, ports and CFP will be released.\n");
1041 fprintf(fp,"# The default delay is 20 seconds.\n");
1042 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine on no response.\n");
1043 fprintf(fp,"cfnr %s\n",ext->cfnr);
1044 fprintf(fp,"cfnr_delay %d\n\n",ext->cfnr_delay);
1046 fprintf(fp,"# Call Forward Parallel (CFP)\n");
1047 fprintf(fp,"# Call will ring on the forwarded number, simulaniousely with the ports.\n");
1048 fprintf(fp,"cfp %s\n\n",ext->cfp);
1050 fprintf(fp,"# Allow user to change call forwarding.\n");
1051 fprintf(fp,"change_forward %s\n\n", ext_yesno[ext->change_forward]);
1053 fprintf(fp,"# Caller id\n# This must be one of the following:\n");
1054 fprintf(fp,"# <number> (as dialed from your local area)\n");
1055 fprintf(fp,"# <number> anonymous (will only be shown to emergency phones)\n");
1056 fprintf(fp,"# none (no number available at all)\n");
1057 fprintf(fp,"# by default the number is of type UNKNOWN (for MULTIPOINT lines)\n");
1058 fprintf(fp,"# if your caller id is not screened on outgoing calls use one of the following:\n");
1059 fprintf(fp,"# use prefix 'i' for TYPE INTERNATIONAL (i<county code><areacode+number>)\n");
1060 fprintf(fp,"# use prefix 'n' for TYPE NATIONAL (n<areacode+number>)\n");
1061 fprintf(fp,"# use prefix 's' for TYPE SUBSCRIBER (s<local number>)\n");
1062 if (ext->callerid_present == INFO_PRESENT_NOTAVAIL)
1063 fprintf(fp,"callerid none\n\n");
1066 switch(ext->callerid_type)
1068 case INFO_NTYPE_INTERNATIONAL:
1069 fprintf(fp,"callerid i%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1071 case INFO_NTYPE_NATIONAL:
1072 fprintf(fp,"callerid n%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1074 case INFO_NTYPE_SUBSCRIBER:
1075 fprintf(fp,"callerid s%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1078 fprintf(fp,"callerid %s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1082 fprintf(fp,"# Caller id for next call (see caller id)\n");
1083 if (ext->id_next_call_present < 0)
1084 fprintf(fp,"id_next_call \n\n");
1085 else if (ext->id_next_call_present == INFO_PRESENT_NOTAVAIL)
1086 fprintf(fp,"id_next_call none\n\n");
1089 switch(ext->id_next_call_type)
1091 case INFO_NTYPE_INTERNATIONAL:
1092 fprintf(fp,"id_next_call i%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1094 case INFO_NTYPE_NATIONAL:
1095 fprintf(fp,"id_next_call n%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1097 case INFO_NTYPE_SUBSCRIBER:
1098 fprintf(fp,"id_next_call s%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1101 fprintf(fp,"id_next_call %s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1105 fprintf(fp,"# Allow user to change caller ID.\n");
1106 fprintf(fp,"change_callerid %s\n\n", ext_yesno[ext->change_callerid]);
1108 fprintf(fp,"# Caller Line Identification Presentation (CLIP)\n");
1109 fprintf(fp,"# clip (asis|hide)\n");
1110 fprintf(fp,"# asis: On forwarded calls the CLIP is used as presented by the calling party.\n");
1111 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1115 fprintf(fp,"clip hide\n\n");
1118 fprintf(fp,"clip asis\n\n");
1121 fprintf(fp,"# Connected Line Identification Presentation (COLP)\n");
1122 fprintf(fp,"# colp (asis|hide|force)\n");
1123 fprintf(fp,"# asis: Provides colp as defined by the extension's caller id.\n");
1124 fprintf(fp,"# On forwarded calls the COLP is used as presented by the called party.\n");
1125 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1126 fprintf(fp,"# force: If COLP is not presented by forwarded calls the dialed number is used.\n");
1130 fprintf(fp,"colp hide\n\n");
1133 fprintf(fp,"colp force\n\n");
1136 fprintf(fp,"colp asis\n\n");
1139 fprintf(fp,"# CLIP Prefix\n");
1140 fprintf(fp,"# Adds a prefix to incomming caller IDs, so telephones will be able to respond\n");
1141 fprintf(fp,"# to unanswered calls from their list. The prefix must be the digit(s) to get\n");
1142 fprintf(fp,"# an external line. The caller ID will then be extendet so that they can be\n");
1143 fprintf(fp,"# dialed from internal telephones. Many telephones have this feature, but some\n");
1144 fprintf(fp,"# don't.\n");
1145 fprintf(fp,"clip_prefix %s\n\n",ext->clip_prefix);
1147 fprintf(fp,"# Keypad control\n");
1148 fprintf(fp,"# If supported by telephone, pressing a key on the keypad will not result in\n");
1149 fprintf(fp,"# DTMF tone, but the digit is transmitted via D-channel diaing info.\n");
1150 fprintf(fp,"keypad %s\n\n",(ext->keypad)?"yes":"no");
1152 fprintf(fp,"# Called Name Identification Presentation (CNIP/CONP)\n");
1153 fprintf(fp,"# If supported by telephone, special information element on the d-channel are\n");
1154 fprintf(fp,"# used to show name of caller. It is supported by newer Siemens telephones\n# (Centrex).\n");
1155 fprintf(fp,"centrex %s #this is currently not working!!!\n\n",(ext->centrex)?"yes":"no");
1157 fprintf(fp,"# Ignore restriction of COLP and CLIP\n");
1158 fprintf(fp,"# In this case even restricted numbers are presented to this extension.\n");
1159 fprintf(fp,"# This also works for incoming external anonymous calls IF:\n");
1160 fprintf(fp,"# You have the CLIRIGN feature like POLICE or equivalent.\n");
1161 fprintf(fp,"anon-ignore %s\n\n",(ext->anon_ignore)?"yes":"no");
1163 fprintf(fp,"# Dialing rights (none|internal|local|national|international)\n");
1164 fprintf(fp,"rights %s\n\n",ext_rights[ext->rights]);
1166 fprintf(fp,"# Delete function for external calls. '*' will delete the last digit, '#' will\n");
1167 fprintf(fp,"# delete the complete number. Also enable 'display_dialing' to see on the\n");
1168 fprintf(fp,"# display what actually happens.\n");
1169 fprintf(fp,"delete_ext %s\n\n",ext_yesno[ext->delete_ext]);
1171 fprintf(fp,"# If noknocking is enabled, the caller will get a busy message when the\n");
1172 fprintf(fp,"# extension is doing at least one call.\n");
1173 fprintf(fp,"noknocking %s\n\n",ext_yesno[ext->noknocking]);
1175 fprintf(fp,"# Transmit volume (-8 .. 8)\n");
1176 fprintf(fp,"# 0 = normal\n");
1177 fprintf(fp,"# 1 = double, 2 = quadrupel, 8 = 256 times (amplitude)\n");
1178 fprintf(fp,"# -1 = half, -2 = quarter, 8 = 1/256th (amplitude)\n");
1179 fprintf(fp,"# Audio data is limited to the maximum value when exceeds limit.\n");
1180 fprintf(fp,"txvol %d\n\n",ext->txvol);
1182 fprintf(fp,"# Receive volume (-8 .. 8)\n");
1183 fprintf(fp,"# (see txvol)\n");
1184 fprintf(fp,"rxvol %d\n\n",ext->rxvol);
1186 fprintf(fp,"# Timeout values\n# The keywords specify the following timeouts:\n");
1187 fprintf(fp,"# tout_setup: after pickup before dialing anything. (default 60 seconds)\n");
1188 fprintf(fp,"# tout_dialing: after dialing last digit of uncomplete number (default 15)\n");
1189 fprintf(fp,"# tout_proceeding: after start proceeding (default 120)\n");
1190 fprintf(fp,"# tout_alerting: after start ringing (default 120)\n");
1191 fprintf(fp,"# tout_disconnect: after disconnect (default 120)\n");
1192 // fprintf(fp,"# tout_hold: maximum time to hold a call (default 900)\n");
1193 // fprintf(fp,"# tout_park: maximum time to park a call (default 900)\n");
1194 fprintf(fp,"# All timeouts may be disabled by using keyword 'off' instead of seconds.\n");
1195 fprintf(fp,"# All timeouts refer to internal ports only. External timeouts are controlled\n");
1196 fprintf(fp,"# by external line.\n");
1197 if (ext->tout_setup)
1198 fprintf(fp,"tout_setup %d\n",ext->tout_setup);
1200 fprintf(fp,"tout_setup off\n");
1201 if (ext->tout_dialing)
1202 fprintf(fp,"tout_dialing %d\n",ext->tout_dialing);
1204 fprintf(fp,"tout_dialing off\n");
1205 if (ext->tout_proceeding)
1206 fprintf(fp,"tout_proceeding %d\n",ext->tout_proceeding);
1208 fprintf(fp,"tout_proceeding off\n");
1209 if (ext->tout_alerting)
1210 fprintf(fp,"tout_alerting %d\n",ext->tout_alerting);
1212 fprintf(fp,"tout_alerting off\n");
1213 if (ext->tout_disconnect)
1214 fprintf(fp,"tout_disconnect %d\n\n",ext->tout_disconnect);
1216 fprintf(fp,"tout_disconnect off\n\n");
1217 // if (ext->tout_hold)
1218 // fprintf(fp,"tout_hold %d\n",ext->tout_hold);
1220 // fprintf(fp,"tout_hold off\n");
1221 // if (ext->tout_park)
1222 // fprintf(fp,"tout_park %d\n\n",ext->tout_park);
1224 // fprintf(fp,"tout_park off\n\n");
1226 fprintf(fp,"# Force to use tones and announcements generated by the pbx.\n");
1227 fprintf(fp,"# For internal calls always own tones are used. You may specify own tones for\n");
1228 fprintf(fp,"# different call states:\n");
1229 fprintf(fp,"# own_setup (dialtone and during dialing)\n");
1230 fprintf(fp,"# own_proceeding (call in poceeding state)\n");
1231 fprintf(fp,"# own_alerting (call is ringing)\n");
1232 fprintf(fp,"# own_cause (when the call gets disconnected or failed to be completed)\n");
1233 fprintf(fp,"own_setup %s\n",ext_yesno[ext->own_setup]);
1234 fprintf(fp,"own_proceeding %s\n",ext_yesno[ext->own_proceeding]);
1235 fprintf(fp,"own_alerting %s\n",ext_yesno[ext->own_alerting]);
1236 fprintf(fp,"own_cause %s\n\n",ext_yesno[ext->own_cause]);
1238 fprintf(fp,"# Allow facility information to be transfered to the telephone.\n");
1239 fprintf(fp,"# This is equired to receive advice of charge.\n");
1240 fprintf(fp,"facility %s\n\n",ext_yesno[ext->facility]);
1242 fprintf(fp,"# Display clear causes using display messages (Q.850)\n# This must be one of the following:\n");
1243 fprintf(fp,"# none (no displaying of clear causes)\n");
1244 fprintf(fp,"# english (display cause text in english)\n");
1245 fprintf(fp,"# german (display cause text in german)\n");
1246 fprintf(fp,"# number (display cause number only)\n");
1247 fprintf(fp,"# english-location (display cause text in english and location)\n");
1248 fprintf(fp,"# german-location (display cause text in german and location)\n");
1249 switch(ext->display_cause)
1251 case DISPLAY_CAUSE_ENGLISH:
1252 fprintf(fp,"display_cause english\n\n");
1254 case DISPLAY_CAUSE_GERMAN:
1255 fprintf(fp,"display_cause german\n\n");
1257 case DISPLAY_LOCATION_ENGLISH:
1258 fprintf(fp,"display_cause english-location\n\n");
1260 case DISPLAY_LOCATION_GERMAN:
1261 fprintf(fp,"display_cause german-location\n\n");
1263 case DISPLAY_CAUSE_NUMBER:
1264 fprintf(fp,"display_cause number\n\n");
1267 fprintf(fp,"display_cause none\n\n");
1270 fprintf(fp,"# Display external caller ids using display override (yes or no)\n");
1271 fprintf(fp,"# example: \"15551212\"\n");
1272 fprintf(fp,"display_ext %s\n\n",(ext->display_ext)?"yes":"no");
1274 fprintf(fp,"# Display internal caller ids using display override (yes or no)\n");
1275 fprintf(fp,"# example: \"200 (int)\"\n");
1276 fprintf(fp,"display_int %s\n\n",(ext->display_int)?"yes":"no");
1278 fprintf(fp,"# Display if calls are anonymous using display override (yes or no)\n");
1279 fprintf(fp,"# This makes only sense if the anon-ignore feature is enabled.\n");
1280 fprintf(fp,"# example: \"15551212 anon\"\n");
1281 fprintf(fp,"display_anon %s\n\n",(ext->display_anon)?"yes":"no");
1283 fprintf(fp,"# Display fake caller ids using display override (yes or no)\n");
1284 fprintf(fp,"# If the caller uses \"clip no screening\", you will see if the number is\n");
1285 fprintf(fp,"# real or fake\n");
1286 fprintf(fp,"# example: \"15551212 fake\"\n");
1287 fprintf(fp,"display_fake %s\n\n",(ext->display_fake)?"yes":"no");
1289 fprintf(fp,"# Display caller's name if available. (yes or no)\n");
1290 fprintf(fp,"# example: \"15551212 Axel\"\n");
1291 fprintf(fp,"display_name %s\n\n",(ext->display_name)?"yes":"no");
1293 fprintf(fp,"# Display menu when '*' and '#' is pressed. The menu shows all prefixes for\n");
1294 fprintf(fp,"# internal dialing by pressing '*' for previous prefix and '#' for next prefix.\n");
1295 fprintf(fp,"# Also the dialed prefix is show on display. (yes or no)\n");
1296 fprintf(fp,"display_menu %s\n\n",(ext->display_menu)?"yes":"no");
1298 fprintf(fp,"# Display digits as they are interpreted by pbx. (yes or no)\n");
1299 fprintf(fp,"display_dialing %s\n\n",(ext->display_dialing)?"yes":"no");
1301 fprintf(fp,"# Tones directory for announcements and patterns\n");
1302 fprintf(fp,"# Enter nothing for default tones as selected by options.conf.\n");
1303 fprintf(fp,"tones_dir %s\n\n",ext->tones_dir);
1305 fprintf(fp,"# Record calls to extension's directory. The file is written as wave.\n");
1306 fprintf(fp,"# This must be one of the following:\n");
1307 fprintf(fp,"# off (no recording)\n");
1308 fprintf(fp,"# mono (records wave 16 bit mono, 128kbits/s)\n");
1309 fprintf(fp,"# stereo (records wave 32 bit stereo, 256kbits/s)\n");
1310 fprintf(fp,"# 8bit (records wave 8 bit mono, 64kbits/s)\n");
1311 fprintf(fp,"# law (records xLaw encoded, as specified in options.conf, 64kbps/s)\n");
1315 fprintf(fp,"record mono\n\n");
1318 fprintf(fp,"record stereo\n\n");
1321 fprintf(fp,"record 8bit\n\n");
1324 fprintf(fp,"record law\n\n");
1327 fprintf(fp,"record off\n\n");
1330 fprintf(fp,"# Password for callback and login\n");
1331 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1332 fprintf(fp,"password %s\n\n",ext->password);
1334 fprintf(fp,"# The Answering Machine. Enter the mode of answering machine.\n");
1335 fprintf(fp,"# This must be one of the following:\n");
1336 fprintf(fp,"# normal (plays announcement and records after that)\n");
1337 fprintf(fp,"# parallel (plays announcement and records also DURING announcement.)\n");
1338 fprintf(fp,"# announcement (just plays announcement and hangs up)\n");
1339 switch(ext->vbox_mode)
1341 case VBOX_MODE_PARALLEL:
1342 fprintf(fp,"vbox_mode parallel\n\n");
1344 case VBOX_MODE_ANNOUNCEMENT:
1345 fprintf(fp,"vbox_mode announcement\n\n");
1348 fprintf(fp,"vbox_mode normal\n\n");
1351 fprintf(fp,"# The Answering Machine. Enter the type of codec for recording.\n");
1352 fprintf(fp,"# This must be one of the following:\n");
1353 fprintf(fp,"# law (alaw/ulas codec, as specified in options.conf)\n");
1354 fprintf(fp,"# mono (16 bit mono wave file)\n");
1355 fprintf(fp,"# stereo (16 bit stereo wave file)\n");
1356 fprintf(fp,"# 8bit (8 bit mono wave file)\n");
1357 switch(ext->vbox_codec)
1360 fprintf(fp,"vbox_codec law\n\n");
1363 fprintf(fp,"vbox_codec stereo\n\n");
1366 fprintf(fp,"vbox_codec 8bit\n\n");
1369 fprintf(fp,"vbox_codec mono\n\n");
1372 fprintf(fp,"# The Answering Machine. Enter maximum time to record after announcement.\n");
1373 fprintf(fp,"# Leave empty, enter \"infinite\" or give time in seconds.\n");
1374 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1376 fprintf(fp,"vbox_time %d\n\n",ext->vbox_time);
1378 fprintf(fp,"vbox_time infinite\n\n");
1380 fprintf(fp,"# The Answering Machine. Enter mode for display current state.\n");
1381 fprintf(fp,"# This must be one of the following:\n");
1382 fprintf(fp,"# brief (displays brief information, for small displays)\n");
1383 fprintf(fp,"# detailed (displays detailed information, for larger displays)\n");
1384 fprintf(fp,"# off (don't display anything)\n");
1385 switch(ext->vbox_display)
1387 case VBOX_DISPLAY_OFF:
1388 fprintf(fp,"vbox_display off\n\n");
1390 case VBOX_DISPLAY_DETAILED:
1391 fprintf(fp,"vbox_display detailed\n\n");
1394 fprintf(fp,"vbox_display brief\n\n");
1397 fprintf(fp,"# The Answering Machine. Enter type of language: \"english\" or \"german\"\n");
1398 fprintf(fp,"# Display information of the menu, will be provided as specified.\n");
1399 fprintf(fp,"# The menu's voice is located in \"vbox_english\" and \"vbox_german\".\n");
1400 if (ext->vbox_language)
1401 fprintf(fp,"vbox_language german\n\n");
1403 fprintf(fp,"vbox_language english\n\n");
1405 fprintf(fp,"# The Answering Machine. Enter email to send incoming messages to:\n");
1406 fprintf(fp,"# All incoming message will be send to the given address.\n");
1407 fprintf(fp,"# The audio file is attached if \"vbox_email_file\" is 'yes'\n");
1408 fprintf(fp,"vbox_email %s\n", ext->vbox_email);
1409 fprintf(fp,"vbox_email_file %s\n\n",ext_yesno[ext->vbox_email_file]);
1411 fprintf(fp,"# If audio path is connected prior answering of a call, say 'yes'\n");
1412 fprintf(fp,"# will cause the call to be billed after playing the announcement. (yes or no)\n");
1413 fprintf(fp,"vbox_free %s\n\n",(ext->vbox_free)?"yes":"no");
1415 fprintf(fp,"# Accept incoming data calls as it would be an audio call.\n");
1416 fprintf(fp,"datacall %s\n\n",ext_yesno[ext->datacall]);
1418 fprintf(fp,"# Include seconds (time) in the connect message. (Should be always enabled.)\n");
1419 fprintf(fp,"seconds %s\n\n",ext_yesno[1-ext->no_seconds]);
1421 fprintf(fp,"# Last outgoing and incoming numbers (including prefix)\n");
1423 while(i < MAX_REMEMBER)
1425 if (ext->last_out[i][0])
1426 fprintf(fp,"last_out %s\n",ext->last_out[i]);
1430 while(i < MAX_REMEMBER)
1432 if (ext->last_in[i][0])
1433 fprintf(fp,"last_in %s\n",ext->last_in[i]);
1444 /* write log for extension
1447 int write_log(char *number, char *callerid, char *calledid, time_t start, time_t stop, int aoce, int cause, int location)
1449 char *mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1454 if (callerid[0] == '\0')
1455 callerid = "<unknown>";
1457 SPRINT(filename, "%s/%s/%s/log", INSTALL_DATA, options.extensions_dir, number);
1459 if (!(fp = fopen(filename, "a")))
1461 PERROR("Cannot open log: \"%s\"\n", filename);
1465 tm = localtime(&start);
1466 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);
1468 fprintf(fp," %2ld:%02ld:%02ld", (stop-start)/3600, (((unsigned long)(stop-start))/60)%60, ((unsigned long)(stop-start))%60);
1470 fprintf(fp," --:--:--");
1471 fprintf(fp," %s -> %s", callerid, calledid);
1472 if (cause >= 1 && cause <=127 && location>=0 && location<=15)
1473 fprintf(fp," (cause=%d '%s' location=%d '%s')", cause, isdn_cause[cause].german, location, isdn_location[location].german);
1483 * reads phone book of extextension and compares the given elements which
1484 * are: abreviation, phone number, name (name is not compared)
1485 * on success a 1 is returned and the pointers of elements are set to the
1488 int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, char **name_pointer)
1493 static char abbrev[32], phone[256], name[256];
1494 unsigned int line,i;
1496 int found = 0, found_if_more_digits = 0;
1498 SPRINT(filename, "%s/%s/%s/phonebook", INSTALL_DATA, options.extensions_dir, number);
1500 if (!(fp = fopen(filename, "r")))
1502 PERROR("Cannot open phonebook: \"%s\"\n", filename);
1507 while((fgets(buffer, sizeof(buffer), fp)))
1510 buffer[sizeof(buffer)-1] = '\0';
1511 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1514 while(*p <= 32) /* skip spaces */
1520 if (*p==0 || *p=='#') /* ignore comments and empty line */
1527 i=0; /* read abbrev */
1530 if (i+1 >= sizeof(abbrev))
1532 PERROR_RUNTIME("Error in %s (line %d): abbrev too long.\n",filename,line);
1539 while(*p <= 32) /* skip spaces */
1546 if (*p!=0 && *p!='#') /* phone */
1548 i=0; /* read phone */
1551 if (i+1 >= sizeof(phone))
1553 PERROR_RUNTIME("Error in %s (line %d): phone too long.\n",filename,line);
1559 while(*p <= 32) /* skip spaces */
1567 if (*p!=0 && *p!='#') /* name */
1569 i=0; /* read name */
1572 if (i+1 >= sizeof(name))
1574 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1582 if (*abbrev_pointer)
1584 if (!strncmp(*abbrev_pointer, abbrev, strlen(*abbrev_pointer)))
1586 /* may match if abbreviation is longer */
1587 found_if_more_digits = 1;
1589 if (!!strcasecmp(*abbrev_pointer, abbrev))
1593 if (!!strcasecmp(*phone_pointer, phone))
1596 if (!!strcasecmp(*name_pointer, name))
1600 break; /* found entry */
1607 *abbrev_pointer = abbrev;
1608 *phone_pointer = phone;
1609 *name_pointer = name;
1614 if (found_if_more_digits)
1620 /* parsing secrets file
1622 * 'number' specifies the externsion number, not the caller id
1623 * 'remote_id' specifies the dialed number, or the caller id for incoming calls
1624 * the result is the auth, crypt and key string, and 1 is returned.
1625 * on failure or not matching number, the 0 is returned
1627 int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **crypt_pointer, char **key_pointer)
1633 static char auth[64], crypt[64], key[4096];
1634 unsigned int line,i;
1638 SPRINT(filename, "%s/%s/%s/secrets", INSTALL_DATA, options.extensions_dir, number);
1640 if (!(fp = fopen(filename, "r")))
1642 PERROR("Cannot open secrets: \"%s\"\n", filename);
1647 while((fgets(buffer, sizeof(buffer), fp)))
1650 buffer[sizeof(buffer)-1] = '\0';
1651 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1654 while(*p <= 32) /* skip spaces */
1660 if (*p==0 || *p=='#') /* ignore comments and empty line */
1668 i=0; /* read auth */
1671 if (i+1 >= sizeof(remote))
1673 PERROR_RUNTIME("Error in %s (line %d): remote too long.\n",filename,line);
1680 while(*p <= 32) /* skip spaces */
1687 if (*p!=0 && *p!='#') /* auth */
1689 i=0; /* read auth */
1692 if (i+1 >= sizeof(auth))
1694 PERROR_RUNTIME("Error in %s (line %d): auth too long.\n",filename,line);
1700 while(*p <= 32) /* skip spaces */
1708 if (*p!=0 && *p!='#') /* crypt */
1710 i=0; /* read crypt */
1713 if (i+1 >= sizeof(crypt))
1715 PERROR_RUNTIME("Error in %s (line %d): crypt too long.\n",filename,line);
1721 while(*p <= 32) /* skip spaces */
1729 if (*p!=0 && *p!='#') /* key */
1734 if (i+1 >= sizeof(key))
1736 PERROR_RUNTIME("Error in %s (line %d): key too long.\n",filename,line);
1743 //printf("COMPARING: '%s' with '%s' %s %s %s\n", remote_id, remote, auth, crypt, key);
1745 if (!!strcasecmp(remote, remote_id))
1749 break; /* found entry */
1756 *auth_pointer = auth;
1757 *crypt_pointer = crypt;
1766 * the caller id is given and the name is returned. if the name is not found,
1768 * on success a 1 is returned and the pointers of elements are set to the
1771 char *parse_directory(char *number, int type)
1776 static char phone[32], name[64];
1777 unsigned int line,i;
1781 SPRINT(filename, "%s/directory.list", INSTALL_DATA);
1783 if (!(fp = fopen(filename, "r")))
1785 PERROR("Cannot open directory: \"%s\"\n", filename);
1790 while((fgets(buffer, sizeof(buffer), fp)))
1793 buffer[sizeof(buffer)-1] = '\0';
1794 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1797 while(*p <= 32) /* skip spaces */
1803 if (*p==0 || *p=='#') /* ignore comments and empty line */
1809 i=0; /* read number */
1812 if (i+1 >= sizeof(phone))
1814 PERROR_RUNTIME("Error in %s (line %d): number too long.\n",filename,line);
1821 while(*p <= 32) /* skip spaces */
1828 i=0; /* read name */
1831 if (i+1 >= sizeof(name))
1833 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1840 if (phone[0] == 'i')
1842 if (type != INFO_NTYPE_INTERNATIONAL)
1844 if (!strcmp(number, phone+1))
1851 if (phone[0] == 'n')
1853 if (type != INFO_NTYPE_NATIONAL)
1855 if (!strcmp(number, phone+1))
1862 if (phone[0] == 's')
1864 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1866 if (!strcmp(number, phone+1))
1873 if (!strncmp(phone, options.international, strlen(options.international)))
1875 if (type != INFO_NTYPE_INTERNATIONAL)
1877 if (!strcmp(number, phone+strlen(options.international)))
1884 if (!options.national[0]) /* no national prefix */
1886 if (type == INFO_NTYPE_INTERNATIONAL)
1888 if (!strcmp(number, phone))
1895 if (!strncmp(phone, options.national, strlen(options.national)))
1897 if (type != INFO_NTYPE_NATIONAL)
1899 if (!strcmp(number, phone+strlen(options.national)))
1906 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1908 if (!strcmp(number, phone))
1923 /* parse callbackauth
1925 * searches for the given caller id and returns 1 == true or 0 == false
1927 int parse_callbackauth(char *number, struct caller_info *callerinfo)
1932 unsigned int line,i;
1934 static char caller_type[32], caller_id[64];
1937 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
1939 if (!(fp = fopen(filename, "r")))
1941 PDEBUG(DEBUG_EPOINT, "Cannot open callbackauth: \"%s\"\n", filename);
1946 while((fgets(buffer, sizeof(buffer), fp)))
1949 buffer[sizeof(buffer)-1] = '\0';
1950 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1953 while(*p <= 32) /* skip spaces */
1959 if (*p==0 || *p=='#') /* ignore comments and empty line */
1965 i=0; /* read caller_type */
1968 if (i+1 >= sizeof(caller_type))
1970 PERROR_RUNTIME("Error in %s (line %d): caller_type too long.\n",filename,line);
1973 caller_type[i+1] = '\0';
1974 caller_type[i++] = *p++;
1977 while(*p <= 32) /* skip spaces */
1984 if (*p!=0 && *p!='#') /* caller_id */
1986 i=0; /* read caller_id */
1989 if (i+1 >= sizeof(caller_id))
1991 PERROR_RUNTIME("Error in %s (line %d): caller_id too long.\n",filename,line);
1994 caller_id[i+1] = '\0';
1995 caller_id[i++] = *p++;
2000 if (caller_type[0]=='\0' && caller_id[0]=='\0')
2003 if (atoi(caller_type) != callerinfo->ntype)
2006 if (!!strcmp(caller_id, callerinfo->id))
2010 break; /* found entry */
2021 /* append line to callbackauth
2024 void append_callbackauth(char *number, struct caller_info *callerinfo)
2029 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
2031 if (callerinfo->id[0]=='\0')
2033 PERROR("caller has no id.\n");
2036 if (!(fp = fopen(filename, "a")))
2038 PERROR("Cannot open callbackauth: \"%s\"\n", filename);
2042 fprintf(fp, "%6d %s\n", callerinfo->ntype, callerinfo->id);