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 *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/%s/settings", INSTALL_DATA, options.extensions_dir, number);
56 if (!(fp = fopen(filename, "r")))
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 */
67 ext->tout_setup = 120;
68 ext->tout_dialing = 120;
69 ext->tout_proceeding = 120;
70 ext->tout_alerting = 120;
71 ext->tout_disconnect = 120;
72 // ext->tout_hold = 900;
73 // ext->tout_park = 900;
75 ext->vbox_codec = CODEC_MONO;
78 while((fgets(buffer, sizeof(buffer), fp)))
81 buffer[sizeof(buffer)-1] = '\0';
82 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
85 while(*p <= 32) /* skip spaces */
91 if (*p==0 || *p=='#') /* ignore comments and empty line */
95 i=0; /* read option */
98 if (i+1 >= sizeof(option))
100 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
107 while(*p <= 32) /* skip spaces */
116 if (*p!=0 && *p!='#') /* param */
118 i=0; /* read param */
121 if (i+1 >= sizeof(param))
123 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
130 while(*p <= 32) /* skip spaces */
137 if (*p!=0 && *p!='#') /* param2 */
139 i=0; /* read param2 */
142 if (i+1 >= sizeof(param2))
144 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
153 /* at this point we have option and param */
156 if (!strcmp(option,"name"))
158 SCPY(ext->name, param);
161 SCAT(ext->name, " ");
162 SCAT(ext->name, param2);
165 PDEBUG(DEBUG_CONFIG, "name of extension: %s\n",param);
167 if (!strcmp(option,"prefix"))
169 SCPY(ext->prefix, param);
171 PDEBUG(DEBUG_CONFIG, "dial prefix on pickup: %s\n",param);
173 if (!strcmp(option,"next"))
175 SCPY(ext->next, param);
177 PDEBUG(DEBUG_CONFIG, "dial next on pickup: %s\n",param);
179 if (!strcmp(option,"alarm"))
181 SCPY(ext->alarm, param);
183 PDEBUG(DEBUG_CONFIG, "alarm message (if prefix): %s\n",param);
185 if (!strcmp(option,"cfu"))
187 SCPY(ext->cfu, param);
189 PDEBUG(DEBUG_CONFIG, "call forward unconditional: %s\n",param);
191 if (!strcmp(option,"cfb"))
193 SCPY(ext->cfb, param);
195 PDEBUG(DEBUG_CONFIG, "call forward when busy: %s\n",param);
197 if (!strcmp(option,"cfnr"))
199 SCPY(ext->cfnr, param);
201 PDEBUG(DEBUG_CONFIG, "call forward on no response: %s\n",param);
203 if (!strcmp(option,"cfnr_delay"))
205 ext->cfnr_delay = atoi(param);
206 if (ext->cfnr_delay < 0)
209 PDEBUG(DEBUG_CONFIG, "call forward no response delay: %d\n",ext->cfnr_delay);
211 if (!strcmp(option,"cfp"))
213 SCPY(ext->cfp, param);
215 PDEBUG(DEBUG_CONFIG, "call forward parallel: %s\n",param);
217 if (!strcmp(option,"change_forward"))
222 if (!strcasecmp(param,ext_yesno[i]))
228 ext->change_forward = i;
229 PDEBUG(DEBUG_CONFIG, "allow the change of forwarding: %s\n", ext_yesno[i]);
232 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_forward: %s\n", param);
235 if (!strcmp(option,"interfaces"))
237 SCPY(ext->interfaces, param);
239 PDEBUG(DEBUG_CONFIG, "interfaces to ring calls to extension: %s %s\n",param,param2);
241 if (!strcmp(option,"callerid"))
243 ext->callerid_present = INFO_PRESENT_ALLOWED;
244 if (!strncasecmp(param2, "anonymous", 9))
245 ext->callerid_present = INFO_PRESENT_RESTRICTED;
246 if (!strncasecmp(param, "non", 3))
248 ext->callerid[0] = '\0';
249 ext->callerid_present = INFO_PRESENT_NOTAVAIL;
250 ext->callerid_type = INFO_NTYPE_UNKNOWN;
251 PDEBUG(DEBUG_CONFIG, "caller id: ID NOT AVAILABLE\n");
257 ext->callerid_type = INFO_NTYPE_INTERNATIONAL;
258 SCPY(ext->callerid, param+1);
259 PDEBUG(DEBUG_CONFIG, "caller id: %s INTERNATIONAL\n",param+1);
263 ext->callerid_type = INFO_NTYPE_NATIONAL;
264 SCPY(ext->callerid, param+1);
265 PDEBUG(DEBUG_CONFIG, "caller id: %s NATIONAL\n",param+1);
269 ext->callerid_type = INFO_NTYPE_SUBSCRIBER;
270 SCPY(ext->callerid, param+1);
271 PDEBUG(DEBUG_CONFIG, "caller id: %s SUBSCRIBER\n",param+1);
274 ext->callerid_type = INFO_NTYPE_UNKNOWN;
275 SCPY(ext->callerid, param);
276 PDEBUG(DEBUG_CONFIG, "caller id: %s UNKNOWN\n",param);
278 ext->callerid[sizeof(ext->callerid)-1] = 0;
280 if (!strcmp(option,"id_next_call"))
282 ext->id_next_call_present = INFO_PRESENT_ALLOWED;
283 if (!strncasecmp(param2, "anonymous", 9))
284 ext->id_next_call_present = INFO_PRESENT_RESTRICTED;
285 if (param[0] == '\0')
287 ext->id_next_call_present = -1;
288 PDEBUG(DEBUG_CONFIG, "id next call: no id for next call\n");
290 if (!strncasecmp(param, "none", 3))
292 ext->id_next_call[0] = '\0';
293 ext->id_next_call_present = INFO_PRESENT_NOTAVAIL;
294 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
295 PDEBUG(DEBUG_CONFIG, "id next call: ID NOT AVAILABLE\n");
301 ext->id_next_call_type = INFO_NTYPE_INTERNATIONAL;
302 SCPY(ext->id_next_call, param+1);
303 PDEBUG(DEBUG_CONFIG, "id next call: %s INTERNATIONAL\n",param+1);
307 ext->id_next_call_type = INFO_NTYPE_NATIONAL;
308 SCPY(ext->id_next_call, param+1);
309 PDEBUG(DEBUG_CONFIG, "id next call: %s NATIONAL\n",param+1);
313 ext->id_next_call_type = INFO_NTYPE_SUBSCRIBER;
314 SCPY(ext->id_next_call, param+1);
315 PDEBUG(DEBUG_CONFIG, "id next call: %s SUBSCRIBER\n",param+1);
318 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
319 SCPY(ext->id_next_call, param);
320 PDEBUG(DEBUG_CONFIG, "id next call: %s UNKNOWN\n",param);
326 if (!strcmp(option,"change_callerid"))
331 if (!strcasecmp(param,ext_yesno[i]))
337 ext->change_callerid = i;
338 PDEBUG(DEBUG_CONFIG, "allow the change of caller id: %s\n", ext_yesno[i]);
341 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_callerid: %s\n", param);
344 if (!strcmp(option,"anon-ignore"))
349 if (!strcasecmp(param,ext_yesno[i]))
355 ext->anon_ignore = i;
356 PDEBUG(DEBUG_CONFIG, "ignore restriction of CLIP & COLP %s\n", ext_yesno[i]);
359 PDEBUG(DEBUG_CONFIG, "unknown parameter given anon-ignore: %s\n", param);
362 if (!strcmp(option,"clip"))
364 if (!strcasecmp(param, "hide"))
365 ext->clip = CLIP_HIDE;
367 ext->clip = CLIP_ASIS;
369 PDEBUG(DEBUG_CONFIG, "clip: %d\n",ext->clip);
371 if (!strcmp(option,"colp"))
373 if (!strcasecmp(param, "hide"))
374 ext->colp = COLP_HIDE;
375 else if (!strcasecmp(param, "force"))
376 ext->colp = COLP_FORCE;
378 ext->colp = COLP_ASIS;
380 PDEBUG(DEBUG_CONFIG, "colp: %d\n",ext->colp);
382 if (!strcmp(option,"clip_prefix"))
384 SCPY(ext->clip_prefix, param);
386 PDEBUG(DEBUG_CONFIG, "clip prefix: %s\n",param);
388 if (!strcmp(option,"keypad"))
393 if (!strcasecmp(param,ext_yesno[i]))
400 PDEBUG(DEBUG_CONFIG, "use keypad to do call control %s\n", ext_yesno[i]);
403 PDEBUG(DEBUG_CONFIG, "unknown parameter given keypad: %s\n", param);
406 if (!strcmp(option,"centrex"))
411 if (!strcasecmp(param,ext_yesno[i]))
418 PDEBUG(DEBUG_CONFIG, "use centrex to display name %s\n", ext_yesno[i]);
421 PDEBUG(DEBUG_CONFIG, "unknown parameter given centrex: %s\n", param);
424 if (!strcmp(option,"rights"))
429 if (!strcasecmp(param,ext_rights[i]))
436 PDEBUG(DEBUG_CONFIG, "rights to dial: %s\n", ext_rights[i]);
439 PDEBUG(DEBUG_CONFIG, "given rights unknown: %s\n", param);
442 if (!strcmp(option,"delete_ext"))
447 if (!strcasecmp(param,ext_yesno[i]))
454 PDEBUG(DEBUG_CONFIG, "enables the delete key function for external calls: %s\n", ext_yesno[i]);
457 PDEBUG(DEBUG_CONFIG, "unknown parameter given delete: %s\n", param);
460 if (!strcmp(option,"noknocking"))
465 if (!strcasecmp(param,ext_yesno[i]))
472 PDEBUG(DEBUG_CONFIG, "noknocking %s\n", ext_yesno[i]);
475 PDEBUG(DEBUG_CONFIG, "given noknocking param unknown: %s\n", param);
478 if (!strcmp(option,"rxvol"))
480 ext->rxvol = atoi(param);
481 if (ext->rxvol<-8 || ext->rxvol>8)
484 PDEBUG(DEBUG_CONFIG, "receive volume: %d\n",ext->rxvol);
486 if (!strcmp(option,"txvol"))
488 ext->txvol = atoi(param);
489 if (ext->txvol<-8 || ext->txvol>8)
492 PDEBUG(DEBUG_CONFIG, "transmit volume: %d\n",ext->txvol);
494 if (!strcmp(option,"tout_setup"))
496 ext->tout_setup = atoi(param);
497 if (ext->tout_setup < 0)
500 PDEBUG(DEBUG_CONFIG, "timeout setup: %d\n",ext->tout_setup);
502 if (!strcmp(option,"tout_dialing"))
504 ext->tout_dialing = atoi(param);
505 if (ext->tout_dialing < 0)
506 ext->tout_dialing = 0;
508 PDEBUG(DEBUG_CONFIG, "timeout dialing: %d\n",ext->tout_dialing);
510 if (!strcmp(option,"tout_proceeding"))
512 ext->tout_proceeding = atoi(param);
513 if (ext->tout_proceeding < 0)
514 ext->tout_proceeding = 0;
516 PDEBUG(DEBUG_CONFIG, "timeout proceeding: %d\n",ext->tout_proceeding);
518 if (!strcmp(option,"tout_alerting"))
520 ext->tout_alerting = atoi(param);
521 if (ext->tout_alerting < 0)
522 ext->tout_alerting = 0;
524 PDEBUG(DEBUG_CONFIG, "timeout alerting: %d\n",ext->tout_alerting);
526 if (!strcmp(option,"tout_disconnect"))
528 ext->tout_disconnect = atoi(param);
529 if (ext->tout_disconnect < 0)
530 ext->tout_disconnect = 0;
532 PDEBUG(DEBUG_CONFIG, "timeout disconnect: %d\n",ext->tout_disconnect);
535 if (!strcmp(option,"tout_hold"))
537 ext->tout_hold = atoi(param);
538 if (ext->tout_hold < 0)
541 PDEBUG(DEBUG_CONFIG, "timeout hold: %d\n",ext->tout_hold);
543 if (!strcmp(option,"tout_park"))
545 ext->tout_park = atoi(param);
546 if (ext->tout_park < 0)
549 PDEBUG(DEBUG_CONFIG, "timeout park: %d\n",ext->tout_park);
552 if (!strcmp(option,"own_setup"))
557 if (!strcasecmp(param,ext_yesno[i]))
564 PDEBUG(DEBUG_CONFIG, "own_setup %s\n", ext_yesno[i]);
567 PDEBUG(DEBUG_CONFIG, "given own_setup param unknown: %s\n", param);
570 if (!strcmp(option,"own_proceeding"))
575 if (!strcasecmp(param,ext_yesno[i]))
581 ext->own_proceeding = i;
582 PDEBUG(DEBUG_CONFIG, "own_proceeding %s\n", ext_yesno[i]);
585 PDEBUG(DEBUG_CONFIG, "given own_proceeding param unknown: %s\n", param);
588 if (!strcmp(option,"own_alerting"))
593 if (!strcasecmp(param,ext_yesno[i]))
599 ext->own_alerting = i;
600 PDEBUG(DEBUG_CONFIG, "own_alerting %s\n", ext_yesno[i]);
603 PDEBUG(DEBUG_CONFIG, "given own_alerting param unknown: %s\n", param);
606 if (!strcmp(option,"own_cause"))
611 if (!strcasecmp(param,ext_yesno[i]))
618 PDEBUG(DEBUG_CONFIG, "own_cause %s\n", ext_yesno[i]);
621 PDEBUG(DEBUG_CONFIG, "given own_cause param unknown: %s\n", param);
624 if (!strcmp(option,"facility"))
629 if (!strcasecmp(param,ext_yesno[i]))
636 PDEBUG(DEBUG_CONFIG, "facility %s\n", ext_yesno[i]);
639 PDEBUG(DEBUG_CONFIG, "given facility param unknown: %s\n", param);
642 if (!strcmp(option,"display_cause"))
644 if (!strcasecmp(param, "german"))
645 ext->display_cause = DISPLAY_CAUSE_GERMAN;
646 else if (!strcasecmp(param, "english"))
647 ext->display_cause = DISPLAY_CAUSE_ENGLISH;
648 else if (!strcasecmp(param, "german-location"))
649 ext->display_cause = DISPLAY_LOCATION_GERMAN;
650 else if (!strcasecmp(param, "english-location"))
651 ext->display_cause = DISPLAY_LOCATION_ENGLISH;
652 else if (!strcasecmp(param, "number"))
653 ext->display_cause = DISPLAY_CAUSE_NUMBER;
655 ext->display_cause = DISPLAY_CAUSE_NONE;
657 PDEBUG(DEBUG_CONFIG, "display cause: %d\n",ext->display_cause);
660 if (!strcmp(option,"display_ext"))
662 if (!strcasecmp(param, "number"))
663 ext->display_ext = DISPLAY_CID_NUMBER;
664 else if (!strcasecmp(param, "abbrev"))
665 ext->display_ext = DISPLAY_CID_ABBREVIATION;
666 else if (!strcasecmp(param, "name"))
667 ext->display_ext = DISPLAY_CID_NAME;
668 else if (!strcasecmp(param, "number-name"))
669 ext->display_ext = DISPLAY_CID_NUMBER_NAME;
670 else if (!strcasecmp(param, "name-number"))
671 ext->display_ext = DISPLAY_CID_NAME_NUMBER;
672 else if (!strcasecmp(param, "abbrev-number"))
673 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER;
674 else if (!strcasecmp(param, "abbrev-name"))
675 ext->display_ext = DISPLAY_CID_ABBREV_NAME;
676 else if (!strcasecmp(param, "abbrev-name-number"))
677 ext->display_ext = DISPLAY_CID_ABBREV_NAME_NUMBER;
678 else if (!strcasecmp(param, "abbrev-number-name"))
679 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER_NAME;
681 ext->display_ext = DISPLAY_CID_ASIS;
683 PDEBUG(DEBUG_CONFIG, "display ext: %d\n",ext->display_ext);
686 if (!strcmp(option,"display_ext"))
691 if (!strcasecmp(param,ext_yesno[i]))
697 ext->display_ext = i;
698 PDEBUG(DEBUG_CONFIG, "display ext %s\n", ext_yesno[i]);
701 PDEBUG(DEBUG_CONFIG, "given display_ext param unknown: %s\n", param);
704 if (!strcmp(option,"display_int"))
709 if (!strcasecmp(param,ext_yesno[i]))
715 ext->display_int = i;
716 PDEBUG(DEBUG_CONFIG, "display int %s\n", ext_yesno[i]);
719 PDEBUG(DEBUG_CONFIG, "given display_int param unknown: %s\n", param);
722 if (!strcmp(option,"display_fake"))
727 if (!strcasecmp(param,ext_yesno[i]))
733 ext->display_fake = i;
734 PDEBUG(DEBUG_CONFIG, "display fake caller ids %s\n", ext_yesno[i]);
737 PDEBUG(DEBUG_CONFIG, "given display_fake param unknown: %s\n", param);
740 if (!strcmp(option,"display_anon"))
745 if (!strcasecmp(param,ext_yesno[i]))
751 ext->display_anon = i;
752 PDEBUG(DEBUG_CONFIG, "display anonymouse ids %s\n", ext_yesno[i]);
755 PDEBUG(DEBUG_CONFIG, "given display_anon param unknown: %s\n", param);
758 if (!strcmp(option,"display_menu"))
763 if (!strcasecmp(param,ext_yesno[i]))
769 ext->display_menu = i;
770 PDEBUG(DEBUG_CONFIG, "display menu %s\n", ext_yesno[i]);
773 PDEBUG(DEBUG_CONFIG, "given display_menu param unknown: %s\n", param);
776 if (!strcmp(option,"display_dialing"))
781 if (!strcasecmp(param,ext_yesno[i]))
787 ext->display_dialing = i;
788 PDEBUG(DEBUG_CONFIG, "display dialing %s\n", ext_yesno[i]);
791 PDEBUG(DEBUG_CONFIG, "given display_dialing param unknown: %s\n", param);
794 if (!strcmp(option,"display_name"))
799 if (!strcasecmp(param,ext_yesno[i]))
805 ext->display_name = i;
806 PDEBUG(DEBUG_CONFIG, "display name %s\n", ext_yesno[i]);
809 PDEBUG(DEBUG_CONFIG, "given display_name param unknown: %s\n", param);
812 if (!strcmp(option,"tones_dir"))
814 if (param[strlen(param)-1] == '/')
815 param[strlen(param)-1]=0;
816 SCPY(ext->tones_dir, param);
818 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
820 if (!strcmp(option,"record"))
822 if (!strcasecmp(param, "mono"))
823 ext->record = CODEC_MONO;
824 else if (!strcasecmp(param, "stereo"))
825 ext->record = CODEC_STEREO;
826 else if (!strcasecmp(param, "8bit"))
827 ext->record = CODEC_8BIT;
828 else if (!strcasecmp(param, "law"))
829 ext->record = CODEC_LAW;
831 ext->record = CODEC_OFF;
832 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
834 if (!strcmp(option,"password"))
836 SCPY(ext->password, param);
838 PDEBUG(DEBUG_CONFIG, "password: %s\n",param);
840 if (!strcmp(option,"vbox_mode"))
842 if (!strcasecmp(param, "parallel"))
843 ext->vbox_mode = VBOX_MODE_PARALLEL;
844 else if (!strcasecmp(param, "announcement"))
845 ext->vbox_mode = VBOX_MODE_ANNOUNCEMENT;
847 ext->vbox_mode = VBOX_MODE_NORMAL;
848 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
850 if (!strcmp(option,"vbox_codec"))
852 if (!strcasecmp(param, "stereo"))
853 ext->vbox_codec = CODEC_STEREO;
854 else if (!strcasecmp(param, "8bit"))
855 ext->vbox_codec = CODEC_8BIT;
856 else if (!strcasecmp(param, "law"))
857 ext->vbox_codec = CODEC_LAW;
859 ext->vbox_codec = CODEC_MONO;
860 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
862 if (!strcmp(option,"vbox_time"))
864 ext->vbox_time = atoi(param);
865 if (ext->vbox_time < 0)
868 PDEBUG(DEBUG_CONFIG, "vbox time to record: %d\n",ext->vbox_time);
870 if (!strcmp(option,"vbox_display"))
872 if (!strcasecmp(param, "detailed")
873 || !strcasecmp(param, "detailled"))
874 ext->vbox_display = VBOX_DISPLAY_DETAILED;
875 else if (!strcasecmp(param, "off"))
876 ext->vbox_display = VBOX_DISPLAY_OFF;
878 ext->vbox_display = VBOX_DISPLAY_BRIEF;
879 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
881 if (!strcmp(option,"vbox_language"))
883 if (!strcasecmp(param, "german"))
884 ext->vbox_language = VBOX_LANGUAGE_GERMAN;
886 ext->vbox_language = VBOX_LANGUAGE_ENGLISH;
887 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
889 if (!strcmp(option,"vbox_email"))
891 SCPY(ext->vbox_email, param);
892 PDEBUG(DEBUG_CONFIG, "given vbox email: %s\n", param);
894 if (!strcmp(option,"vbox_email_file"))
899 if (!strcasecmp(param,ext_yesno[i]))
905 ext->vbox_email_file = i;
906 PDEBUG(DEBUG_CONFIG, "attach audio file %s\n", ext_yesno[i]);
909 PDEBUG(DEBUG_CONFIG, "given vbox_email_file param unknown: %s\n", param);
912 if (!strcmp(option,"vbox_free"))
917 if (!strcasecmp(param,ext_yesno[i]))
924 PDEBUG(DEBUG_CONFIG, "vbox_free %s\n", ext_yesno[i]);
927 PDEBUG(DEBUG_CONFIG, "given vbox_free param unknown: %s\n", param);
930 if (!strcmp(option,"last_in"))
932 if (param[0] && last_in_count<MAX_REMEMBER)
934 SCPY(ext->last_in[last_in_count], param);
937 PDEBUG(DEBUG_CONFIG, "last_in dialed number: %s\n",param);
939 if (!strcmp(option,"last_out"))
941 if (param[0] && last_out_count<MAX_REMEMBER)
943 SCPY(ext->last_out[last_out_count], param);
946 PDEBUG(DEBUG_CONFIG, "last_out dialed number: %s\n",param);
948 if (!strcmp(option,"datacall"))
953 if (!strcasecmp(param,ext_yesno[i]))
960 PDEBUG(DEBUG_CONFIG, "datacall %s\n", ext_yesno[i]);
963 PDEBUG(DEBUG_CONFIG, "given datacall param unknown: %s\n", param);
966 if (!strcmp(option,"seconds"))
971 if (!strcasecmp(param,ext_yesno[i]))
977 ext->no_seconds = 1-i;
978 PDEBUG(DEBUG_CONFIG, "seconds %s\n", ext_yesno[i]);
981 PDEBUG(DEBUG_CONFIG, "unknown param for seconds: %s\n", param);
985 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n",filename,line,option);
996 * writes extension for given extension number from structure
998 int write_extension(struct extension *ext, char *number)
1004 if (number[0] == '\0')
1007 SPRINT(filename, "%s/%s/%s/settings", INSTALL_DATA, options.extensions_dir, number);
1009 if (!(fp = fopen(filename, "w")))
1011 PERROR("Cannot open settings: \"%s\"\n", filename);
1015 fprintf(fp,"# Settings of extension %s\n\n", number);
1017 fprintf(fp,"# Name of extension:\n");
1018 fprintf(fp,"name %s\n\n",ext->name);
1020 fprintf(fp,"# Predialed prefix after pick-up of the phone\n");
1021 fprintf(fp,"prefix %s\n\n",ext->prefix);
1023 fprintf(fp,"# Next prefix to dial pick-up of the phone\n");
1024 fprintf(fp,"# This will be cleared on hangup.\n");
1025 fprintf(fp,"next %s\n\n",ext->next);
1027 // fprintf(fp,"# Set up alarm message after prefix is dialed and connection is established\n");
1028 // fprintf(fp,"alarm %s\n\n",ext->alarm);
1030 fprintf(fp,"# Interface(s) to ring on calls to extension (as named in interface.conf)\n");
1031 fprintf(fp,"# Seperate multiple interfaces by using komma without spaces\n");
1032 fprintf(fp,"# Example: Int would ring on the interface with the name \"Int\"");
1033 fprintf(fp,"# Int1,Int2 would ring incoming calls on both interfaces Int1 and Int2.\n");
1034 fprintf(fp,"interfaces %s\n\n",ext->interfaces);
1036 fprintf(fp,"# Call Forward Unconditional (CFU)\n");
1037 fprintf(fp,"# No port will be called, CFB, CFNR and CFP is ignored.\n");
1038 fprintf(fp,"# Use keyword \"vbox\" to forward call directly to answering machine.\n");
1039 fprintf(fp,"cfu %s\n\n",ext->cfu);
1041 fprintf(fp,"# Call Forward when Busy (CFB)\n");
1042 fprintf(fp,"# If the extension is in use at least once, this forward is done.\n");
1043 fprintf(fp,"# In case of busy line, CFNR and CFP is ignored.\n");
1044 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine when busy.\n");
1045 fprintf(fp,"cfb %s\n\n",ext->cfb);
1047 fprintf(fp,"# Call Forward on No Response (CFNR)\n");
1048 fprintf(fp,"# If noone answers, the call is forwarded, ports and CFP will be released.\n");
1049 fprintf(fp,"# The default delay is 20 seconds.\n");
1050 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine on no response.\n");
1051 fprintf(fp,"cfnr %s\n",ext->cfnr);
1052 fprintf(fp,"cfnr_delay %d\n\n",ext->cfnr_delay);
1054 fprintf(fp,"# Call Forward Parallel (CFP)\n");
1055 fprintf(fp,"# Call will ring on the forwarded number, simulaniousely with the ports.\n");
1056 fprintf(fp,"cfp %s\n\n",ext->cfp);
1058 fprintf(fp,"# Allow user to change call forwarding.\n");
1059 fprintf(fp,"change_forward %s\n\n", ext_yesno[ext->change_forward]);
1061 fprintf(fp,"# Caller id\n# This must be one of the following:\n");
1062 fprintf(fp,"# <number> (as dialed from your local area)\n");
1063 fprintf(fp,"# <number> anonymous (will only be shown to emergency phones)\n");
1064 fprintf(fp,"# none (no number available at all)\n");
1065 fprintf(fp,"# by default the number is of type UNKNOWN (for MULTIPOINT lines)\n");
1066 fprintf(fp,"# if your caller id is not screened on outgoing calls use one of the following:\n");
1067 fprintf(fp,"# use prefix 'i' for TYPE INTERNATIONAL (i<county code><areacode+number>)\n");
1068 fprintf(fp,"# use prefix 'n' for TYPE NATIONAL (n<areacode+number>)\n");
1069 fprintf(fp,"# use prefix 's' for TYPE SUBSCRIBER (s<local number>)\n");
1070 if (ext->callerid_present == INFO_PRESENT_NOTAVAIL)
1071 fprintf(fp,"callerid none\n\n");
1074 switch(ext->callerid_type)
1076 case INFO_NTYPE_INTERNATIONAL:
1077 fprintf(fp,"callerid i%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1079 case INFO_NTYPE_NATIONAL:
1080 fprintf(fp,"callerid n%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1082 case INFO_NTYPE_SUBSCRIBER:
1083 fprintf(fp,"callerid s%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1086 fprintf(fp,"callerid %s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1090 fprintf(fp,"# Caller id for next call (see caller id)\n");
1091 if (ext->id_next_call_present < 0)
1092 fprintf(fp,"id_next_call \n\n");
1093 else if (ext->id_next_call_present == INFO_PRESENT_NOTAVAIL)
1094 fprintf(fp,"id_next_call none\n\n");
1097 switch(ext->id_next_call_type)
1099 case INFO_NTYPE_INTERNATIONAL:
1100 fprintf(fp,"id_next_call i%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1102 case INFO_NTYPE_NATIONAL:
1103 fprintf(fp,"id_next_call n%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1105 case INFO_NTYPE_SUBSCRIBER:
1106 fprintf(fp,"id_next_call s%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1109 fprintf(fp,"id_next_call %s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1113 fprintf(fp,"# Allow user to change caller ID.\n");
1114 fprintf(fp,"change_callerid %s\n\n", ext_yesno[ext->change_callerid]);
1116 fprintf(fp,"# Caller Line Identification Presentation (CLIP)\n");
1117 fprintf(fp,"# clip (asis|hide)\n");
1118 fprintf(fp,"# asis: On forwarded calls the CLIP is used as presented by the calling party.\n");
1119 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1123 fprintf(fp,"clip hide\n\n");
1126 fprintf(fp,"clip asis\n\n");
1129 fprintf(fp,"# Connected Line Identification Presentation (COLP)\n");
1130 fprintf(fp,"# colp (asis|hide|force)\n");
1131 fprintf(fp,"# asis: Provides colp as defined by the extension's caller id.\n");
1132 fprintf(fp,"# On forwarded calls the COLP is used as presented by the called party.\n");
1133 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1134 fprintf(fp,"# force: If COLP is not presented by forwarded calls the dialed number is used.\n");
1138 fprintf(fp,"colp hide\n\n");
1141 fprintf(fp,"colp force\n\n");
1144 fprintf(fp,"colp asis\n\n");
1147 fprintf(fp,"# CLIP Prefix\n");
1148 fprintf(fp,"# Adds a prefix to incomming caller IDs, so telephones will be able to respond\n");
1149 fprintf(fp,"# to unanswered calls from their list. The prefix must be the digit(s) to get\n");
1150 fprintf(fp,"# an external line. The caller ID will then be extendet so that they can be\n");
1151 fprintf(fp,"# dialed from internal telephones. Many telephones have this feature, but some\n");
1152 fprintf(fp,"# don't.\n");
1153 fprintf(fp,"clip_prefix %s\n\n",ext->clip_prefix);
1155 fprintf(fp,"# Keypad control\n");
1156 fprintf(fp,"# If supported by telephone, pressing a key on the keypad will not result in\n");
1157 fprintf(fp,"# DTMF tone, but the digit is transmitted via D-channel diaing info.\n");
1158 fprintf(fp,"keypad %s\n\n",(ext->keypad)?"yes":"no");
1160 fprintf(fp,"# Called Name Identification Presentation (CNIP/CONP)\n");
1161 fprintf(fp,"# If supported by telephone, special information element on the d-channel are\n");
1162 fprintf(fp,"# used to show name of caller. It is supported by newer Siemens telephones\n# (Centrex).\n");
1163 fprintf(fp,"centrex %s #this is currently not working!!!\n\n",(ext->centrex)?"yes":"no");
1165 fprintf(fp,"# Ignore restriction of COLP and CLIP\n");
1166 fprintf(fp,"# In this case even restricted numbers are presented to this extension.\n");
1167 fprintf(fp,"# This also works for incoming external anonymous calls IF:\n");
1168 fprintf(fp,"# You have the CLIRIGN feature like POLICE or equivalent.\n");
1169 fprintf(fp,"anon-ignore %s\n\n",(ext->anon_ignore)?"yes":"no");
1171 fprintf(fp,"# Dialing rights (none|internal|local|national|international)\n");
1172 fprintf(fp,"rights %s\n\n",ext_rights[ext->rights]);
1174 fprintf(fp,"# Delete function for external calls. '*' will delete the last digit, '#' will\n");
1175 fprintf(fp,"# delete the complete number. Also enable 'display_dialing' to see on the\n");
1176 fprintf(fp,"# display what actually happens.\n");
1177 fprintf(fp,"delete_ext %s\n\n",ext_yesno[ext->delete_ext]);
1179 fprintf(fp,"# If noknocking is enabled, the caller will get a busy message when the\n");
1180 fprintf(fp,"# extension is doing at least one call.\n");
1181 fprintf(fp,"noknocking %s\n\n",ext_yesno[ext->noknocking]);
1183 fprintf(fp,"# Transmit volume (-8 .. 8)\n");
1184 fprintf(fp,"# 0 = normal\n");
1185 fprintf(fp,"# 1 = double, 2 = quadrupel, 8 = 256 times (amplitude)\n");
1186 fprintf(fp,"# -1 = half, -2 = quarter, 8 = 1/256th (amplitude)\n");
1187 fprintf(fp,"# Audio data is limited to the maximum value when exceeds limit.\n");
1188 fprintf(fp,"txvol %d\n\n",ext->txvol);
1190 fprintf(fp,"# Receive volume (-8 .. 8)\n");
1191 fprintf(fp,"# (see txvol)\n");
1192 fprintf(fp,"rxvol %d\n\n",ext->rxvol);
1194 fprintf(fp,"# Timeout values\n# The keywords specify the following timeouts:\n");
1195 fprintf(fp,"# tout_setup: after pickup before dialing anything. (default 60 seconds)\n");
1196 fprintf(fp,"# tout_dialing: after dialing last digit of uncomplete number (default 15)\n");
1197 fprintf(fp,"# tout_proceeding: after start proceeding (default 120)\n");
1198 fprintf(fp,"# tout_alerting: after start ringing (default 120)\n");
1199 fprintf(fp,"# tout_disconnect: after disconnect (default 120)\n");
1200 // fprintf(fp,"# tout_hold: maximum time to hold a call (default 900)\n");
1201 // fprintf(fp,"# tout_park: maximum time to park a call (default 900)\n");
1202 fprintf(fp,"# All timeouts may be disabled by using keyword 'off' instead of seconds.\n");
1203 fprintf(fp,"# All timeouts refer to internal ports only. External timeouts are controlled\n");
1204 fprintf(fp,"# by external line.\n");
1205 if (ext->tout_setup)
1206 fprintf(fp,"tout_setup %d\n",ext->tout_setup);
1208 fprintf(fp,"tout_setup off\n");
1209 if (ext->tout_dialing)
1210 fprintf(fp,"tout_dialing %d\n",ext->tout_dialing);
1212 fprintf(fp,"tout_dialing off\n");
1213 if (ext->tout_proceeding)
1214 fprintf(fp,"tout_proceeding %d\n",ext->tout_proceeding);
1216 fprintf(fp,"tout_proceeding off\n");
1217 if (ext->tout_alerting)
1218 fprintf(fp,"tout_alerting %d\n",ext->tout_alerting);
1220 fprintf(fp,"tout_alerting off\n");
1221 if (ext->tout_disconnect)
1222 fprintf(fp,"tout_disconnect %d\n\n",ext->tout_disconnect);
1224 fprintf(fp,"tout_disconnect off\n\n");
1225 // if (ext->tout_hold)
1226 // fprintf(fp,"tout_hold %d\n",ext->tout_hold);
1228 // fprintf(fp,"tout_hold off\n");
1229 // if (ext->tout_park)
1230 // fprintf(fp,"tout_park %d\n\n",ext->tout_park);
1232 // fprintf(fp,"tout_park off\n\n");
1234 fprintf(fp,"# Force to use tones and announcements generated by the pbx.\n");
1235 fprintf(fp,"# For internal calls always own tones are used. You may specify own tones for\n");
1236 fprintf(fp,"# different call states:\n");
1237 fprintf(fp,"# own_setup (dialtone and during dialing)\n");
1238 fprintf(fp,"# own_proceeding (call in poceeding state)\n");
1239 fprintf(fp,"# own_alerting (call is ringing)\n");
1240 fprintf(fp,"# own_cause (when the call gets disconnected or failed to be completed)\n");
1241 fprintf(fp,"own_setup %s\n",ext_yesno[ext->own_setup]);
1242 fprintf(fp,"own_proceeding %s\n",ext_yesno[ext->own_proceeding]);
1243 fprintf(fp,"own_alerting %s\n",ext_yesno[ext->own_alerting]);
1244 fprintf(fp,"own_cause %s\n\n",ext_yesno[ext->own_cause]);
1246 fprintf(fp,"# Allow facility information to be transfered to the telephone.\n");
1247 fprintf(fp,"# This is equired to receive advice of charge.\n");
1248 fprintf(fp,"facility %s\n\n",ext_yesno[ext->facility]);
1250 fprintf(fp,"# Display clear causes using display messages (Q.850)\n# This must be one of the following:\n");
1251 fprintf(fp,"# none (no displaying of clear causes)\n");
1252 fprintf(fp,"# english (display cause text in english)\n");
1253 fprintf(fp,"# german (display cause text in german)\n");
1254 fprintf(fp,"# number (display cause number only)\n");
1255 fprintf(fp,"# english-location (display cause text in english and location)\n");
1256 fprintf(fp,"# german-location (display cause text in german and location)\n");
1257 switch(ext->display_cause)
1259 case DISPLAY_CAUSE_ENGLISH:
1260 fprintf(fp,"display_cause english\n\n");
1262 case DISPLAY_CAUSE_GERMAN:
1263 fprintf(fp,"display_cause german\n\n");
1265 case DISPLAY_LOCATION_ENGLISH:
1266 fprintf(fp,"display_cause english-location\n\n");
1268 case DISPLAY_LOCATION_GERMAN:
1269 fprintf(fp,"display_cause german-location\n\n");
1271 case DISPLAY_CAUSE_NUMBER:
1272 fprintf(fp,"display_cause number\n\n");
1275 fprintf(fp,"display_cause none\n\n");
1278 fprintf(fp,"# Display external caller ids using display override (yes or no)\n");
1279 fprintf(fp,"# example: \"15551212\"\n");
1280 fprintf(fp,"display_ext %s\n\n",(ext->display_ext)?"yes":"no");
1282 fprintf(fp,"# Display internal caller ids using display override (yes or no)\n");
1283 fprintf(fp,"# example: \"200 (int)\"\n");
1284 fprintf(fp,"display_int %s\n\n",(ext->display_int)?"yes":"no");
1286 fprintf(fp,"# Display if calls are anonymous using display override (yes or no)\n");
1287 fprintf(fp,"# This makes only sense if the anon-ignore feature is enabled.\n");
1288 fprintf(fp,"# example: \"15551212 anon\"\n");
1289 fprintf(fp,"display_anon %s\n\n",(ext->display_anon)?"yes":"no");
1291 fprintf(fp,"# Display fake caller ids using display override (yes or no)\n");
1292 fprintf(fp,"# If the caller uses \"clip no screening\", you will see if the number is\n");
1293 fprintf(fp,"# real or fake\n");
1294 fprintf(fp,"# example: \"15551212 fake\"\n");
1295 fprintf(fp,"display_fake %s\n\n",(ext->display_fake)?"yes":"no");
1297 fprintf(fp,"# Display caller's name if available. (yes or no)\n");
1298 fprintf(fp,"# example: \"15551212 Axel\"\n");
1299 fprintf(fp,"display_name %s\n\n",(ext->display_name)?"yes":"no");
1301 fprintf(fp,"# Display menu when '*' and '#' is pressed. The menu shows all prefixes for\n");
1302 fprintf(fp,"# internal dialing by pressing '*' for previous prefix and '#' for next prefix.\n");
1303 fprintf(fp,"# Also the dialed prefix is show on display. (yes or no)\n");
1304 fprintf(fp,"display_menu %s\n\n",(ext->display_menu)?"yes":"no");
1306 fprintf(fp,"# Display digits as they are interpreted by pbx. (yes or no)\n");
1307 fprintf(fp,"display_dialing %s\n\n",(ext->display_dialing)?"yes":"no");
1309 fprintf(fp,"# Tones directory for announcements and patterns\n");
1310 fprintf(fp,"# Enter nothing for default tones as selected by options.conf.\n");
1311 fprintf(fp,"tones_dir %s\n\n",ext->tones_dir);
1313 fprintf(fp,"# Record calls to extension's directory. The file is written as wave.\n");
1314 fprintf(fp,"# This must be one of the following:\n");
1315 fprintf(fp,"# off (no recording)\n");
1316 fprintf(fp,"# mono (records wave 16 bit mono, 128kbits/s)\n");
1317 fprintf(fp,"# stereo (records wave 32 bit stereo, 256kbits/s)\n");
1318 fprintf(fp,"# 8bit (records wave 8 bit mono, 64kbits/s)\n");
1319 fprintf(fp,"# law (records xLaw encoded, as specified in options.conf, 64kbps/s)\n");
1323 fprintf(fp,"record mono\n\n");
1326 fprintf(fp,"record stereo\n\n");
1329 fprintf(fp,"record 8bit\n\n");
1332 fprintf(fp,"record law\n\n");
1335 fprintf(fp,"record off\n\n");
1338 fprintf(fp,"# Password for callback and login\n");
1339 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1340 fprintf(fp,"password %s\n\n",ext->password);
1342 fprintf(fp,"# The Answering Machine. Enter the mode of answering machine.\n");
1343 fprintf(fp,"# This must be one of the following:\n");
1344 fprintf(fp,"# normal (plays announcement and records after that)\n");
1345 fprintf(fp,"# parallel (plays announcement and records also DURING announcement.)\n");
1346 fprintf(fp,"# announcement (just plays announcement and hangs up)\n");
1347 switch(ext->vbox_mode)
1349 case VBOX_MODE_PARALLEL:
1350 fprintf(fp,"vbox_mode parallel\n\n");
1352 case VBOX_MODE_ANNOUNCEMENT:
1353 fprintf(fp,"vbox_mode announcement\n\n");
1356 fprintf(fp,"vbox_mode normal\n\n");
1359 fprintf(fp,"# The Answering Machine. Enter the type of codec for recording.\n");
1360 fprintf(fp,"# This must be one of the following:\n");
1361 fprintf(fp,"# law (alaw/ulas codec, as specified in options.conf)\n");
1362 fprintf(fp,"# mono (16 bit mono wave file)\n");
1363 fprintf(fp,"# stereo (16 bit stereo wave file)\n");
1364 fprintf(fp,"# 8bit (8 bit mono wave file)\n");
1365 switch(ext->vbox_codec)
1368 fprintf(fp,"vbox_codec law\n\n");
1371 fprintf(fp,"vbox_codec stereo\n\n");
1374 fprintf(fp,"vbox_codec 8bit\n\n");
1377 fprintf(fp,"vbox_codec mono\n\n");
1380 fprintf(fp,"# The Answering Machine. Enter maximum time to record after announcement.\n");
1381 fprintf(fp,"# Leave empty, enter \"infinite\" or give time in seconds.\n");
1382 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1384 fprintf(fp,"vbox_time %d\n\n",ext->vbox_time);
1386 fprintf(fp,"vbox_time infinite\n\n");
1388 fprintf(fp,"# The Answering Machine. Enter mode for display current state.\n");
1389 fprintf(fp,"# This must be one of the following:\n");
1390 fprintf(fp,"# brief (displays brief information, for small displays)\n");
1391 fprintf(fp,"# detailed (displays detailed information, for larger displays)\n");
1392 fprintf(fp,"# off (don't display anything)\n");
1393 switch(ext->vbox_display)
1395 case VBOX_DISPLAY_OFF:
1396 fprintf(fp,"vbox_display off\n\n");
1398 case VBOX_DISPLAY_DETAILED:
1399 fprintf(fp,"vbox_display detailed\n\n");
1402 fprintf(fp,"vbox_display brief\n\n");
1405 fprintf(fp,"# The Answering Machine. Enter type of language: \"english\" or \"german\"\n");
1406 fprintf(fp,"# Display information of the menu, will be provided as specified.\n");
1407 fprintf(fp,"# The menu's voice is located in \"vbox_english\" and \"vbox_german\".\n");
1408 if (ext->vbox_language)
1409 fprintf(fp,"vbox_language german\n\n");
1411 fprintf(fp,"vbox_language english\n\n");
1413 fprintf(fp,"# The Answering Machine. Enter email to send incoming messages to:\n");
1414 fprintf(fp,"# All incoming message will be send to the given address.\n");
1415 fprintf(fp,"# The audio file is attached if \"vbox_email_file\" is 'yes'\n");
1416 fprintf(fp,"vbox_email %s\n", ext->vbox_email);
1417 fprintf(fp,"vbox_email_file %s\n\n",ext_yesno[ext->vbox_email_file]);
1419 fprintf(fp,"# If audio path is connected prior answering of a call, say 'yes'\n");
1420 fprintf(fp,"# will cause the call to be billed after playing the announcement. (yes or no)\n");
1421 fprintf(fp,"vbox_free %s\n\n",(ext->vbox_free)?"yes":"no");
1423 fprintf(fp,"# Accept incoming data calls as it would be an audio call.\n");
1424 fprintf(fp,"datacall %s\n\n",ext_yesno[ext->datacall]);
1426 fprintf(fp,"# Include seconds (time) in the connect message. (Should be always enabled.)\n");
1427 fprintf(fp,"seconds %s\n\n",ext_yesno[1-ext->no_seconds]);
1429 fprintf(fp,"# Last outgoing and incoming numbers (including prefix)\n");
1431 while(i < MAX_REMEMBER)
1433 if (ext->last_out[i][0])
1434 fprintf(fp,"last_out %s\n",ext->last_out[i]);
1438 while(i < MAX_REMEMBER)
1440 if (ext->last_in[i][0])
1441 fprintf(fp,"last_in %s\n",ext->last_in[i]);
1452 /* write log for extension
1455 int write_log(char *number, char *callerid, char *calledid, time_t start, time_t stop, int aoce, int cause, int location)
1457 char *mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1462 if (callerid[0] == '\0')
1463 callerid = "<unknown>";
1465 SPRINT(filename, "%s/%s/%s/log", INSTALL_DATA, options.extensions_dir, number);
1467 if (!(fp = fopen(filename, "a")))
1469 PERROR("Cannot open log: \"%s\"\n", filename);
1473 tm = localtime(&start);
1474 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);
1476 fprintf(fp," %2ld:%02ld:%02ld", (stop-start)/3600, (((unsigned long)(stop-start))/60)%60, ((unsigned long)(stop-start))%60);
1478 fprintf(fp," --:--:--");
1479 fprintf(fp," %s -> %s", callerid, calledid);
1480 if (cause >= 1 && cause <=127 && location>=0 && location<=15)
1481 fprintf(fp," (cause=%d '%s' location=%d '%s')", cause, isdn_cause[cause].german, location, isdn_location[location].german);
1491 * reads phone book of extextension and compares the given elements which
1492 * are: abreviation, phone number, name (name is not compared)
1493 * on success a 1 is returned and the pointers of elements are set to the
1496 int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, char **name_pointer)
1501 static char abbrev[32], phone[256], name[256];
1502 unsigned int line,i;
1504 int found = 0, found_if_more_digits = 0;
1506 SPRINT(filename, "%s/%s/%s/phonebook", INSTALL_DATA, options.extensions_dir, number);
1508 if (!(fp = fopen(filename, "r")))
1510 PERROR("Cannot open phonebook: \"%s\"\n", filename);
1515 while((fgets(buffer, sizeof(buffer), fp)))
1518 buffer[sizeof(buffer)-1] = '\0';
1519 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1522 while(*p <= 32) /* skip spaces */
1528 if (*p==0 || *p=='#') /* ignore comments and empty line */
1535 i=0; /* read abbrev */
1538 if (i+1 >= sizeof(abbrev))
1540 PERROR_RUNTIME("Error in %s (line %d): abbrev too long.\n",filename,line);
1547 while(*p <= 32) /* skip spaces */
1554 if (*p!=0 && *p!='#') /* phone */
1556 i=0; /* read phone */
1559 if (i+1 >= sizeof(phone))
1561 PERROR_RUNTIME("Error in %s (line %d): phone too long.\n",filename,line);
1567 while(*p <= 32) /* skip spaces */
1575 if (*p!=0 && *p!='#') /* name */
1577 i=0; /* read name */
1580 if (i+1 >= sizeof(name))
1582 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1590 if (*abbrev_pointer)
1592 if (!strncmp(*abbrev_pointer, abbrev, strlen(*abbrev_pointer)))
1594 /* may match if abbreviation is longer */
1595 found_if_more_digits = 1;
1597 if (!!strcasecmp(*abbrev_pointer, abbrev))
1601 if (!!strcasecmp(*phone_pointer, phone))
1604 if (!!strcasecmp(*name_pointer, name))
1608 break; /* found entry */
1615 *abbrev_pointer = abbrev;
1616 *phone_pointer = phone;
1617 *name_pointer = name;
1622 if (found_if_more_digits)
1628 /* parsing secrets file
1630 * 'number' specifies the externsion number, not the caller id
1631 * 'remote_id' specifies the dialed number, or the caller id for incoming calls
1632 * the result is the auth, crypt and key string, and 1 is returned.
1633 * on failure or not matching number, the 0 is returned
1635 int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **crypt_pointer, char **key_pointer)
1641 static char auth[64], crypt[64], key[4096];
1642 unsigned int line,i;
1646 SPRINT(filename, "%s/%s/%s/secrets", INSTALL_DATA, options.extensions_dir, number);
1648 if (!(fp = fopen(filename, "r")))
1650 PERROR("Cannot open secrets: \"%s\"\n", filename);
1655 while((fgets(buffer, sizeof(buffer), fp)))
1658 buffer[sizeof(buffer)-1] = '\0';
1659 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1662 while(*p <= 32) /* skip spaces */
1668 if (*p==0 || *p=='#') /* ignore comments and empty line */
1676 i=0; /* read auth */
1679 if (i+1 >= sizeof(remote))
1681 PERROR_RUNTIME("Error in %s (line %d): remote too long.\n",filename,line);
1688 while(*p <= 32) /* skip spaces */
1695 if (*p!=0 && *p!='#') /* auth */
1697 i=0; /* read auth */
1700 if (i+1 >= sizeof(auth))
1702 PERROR_RUNTIME("Error in %s (line %d): auth too long.\n",filename,line);
1708 while(*p <= 32) /* skip spaces */
1716 if (*p!=0 && *p!='#') /* crypt */
1718 i=0; /* read crypt */
1721 if (i+1 >= sizeof(crypt))
1723 PERROR_RUNTIME("Error in %s (line %d): crypt too long.\n",filename,line);
1729 while(*p <= 32) /* skip spaces */
1737 if (*p!=0 && *p!='#') /* key */
1742 if (i+1 >= sizeof(key))
1744 PERROR_RUNTIME("Error in %s (line %d): key too long.\n",filename,line);
1751 //printf("COMPARING: '%s' with '%s' %s %s %s\n", remote_id, remote, auth, crypt, key);
1753 if (!!strcasecmp(remote, remote_id))
1757 break; /* found entry */
1764 *auth_pointer = auth;
1765 *crypt_pointer = crypt;
1774 * the caller id is given and the name is returned. if the name is not found,
1776 * on success a 1 is returned and the pointers of elements are set to the
1779 char *parse_directory(char *number, int type)
1784 static char phone[32], name[64];
1785 unsigned int line,i;
1789 SPRINT(filename, "%s/directory.list", INSTALL_DATA);
1791 if (!(fp = fopen(filename, "r")))
1793 PERROR("Cannot open directory: \"%s\"\n", filename);
1798 while((fgets(buffer, sizeof(buffer), fp)))
1801 buffer[sizeof(buffer)-1] = '\0';
1802 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1805 while(*p <= 32) /* skip spaces */
1811 if (*p==0 || *p=='#') /* ignore comments and empty line */
1817 i=0; /* read number */
1820 if (i+1 >= sizeof(phone))
1822 PERROR_RUNTIME("Error in %s (line %d): number too long.\n",filename,line);
1829 while(*p <= 32) /* skip spaces */
1836 i=0; /* read name */
1839 if (i+1 >= sizeof(name))
1841 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1848 if (phone[0] == 'i')
1850 if (type != INFO_NTYPE_INTERNATIONAL)
1852 if (!strcmp(number, phone+1))
1859 if (phone[0] == 'n')
1861 if (type != INFO_NTYPE_NATIONAL)
1863 if (!strcmp(number, phone+1))
1870 if (phone[0] == 's')
1872 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1874 if (!strcmp(number, phone+1))
1881 if (!strncmp(phone, options.international, strlen(options.international)))
1883 if (type != INFO_NTYPE_INTERNATIONAL)
1885 if (!strcmp(number, phone+strlen(options.international)))
1892 if (!options.national[0]) /* no national prefix */
1894 if (type == INFO_NTYPE_INTERNATIONAL)
1896 if (!strcmp(number, phone))
1903 if (!strncmp(phone, options.national, strlen(options.national)))
1905 if (type != INFO_NTYPE_NATIONAL)
1907 if (!strcmp(number, phone+strlen(options.national)))
1914 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1916 if (!strcmp(number, phone))
1931 /* parse callbackauth
1933 * searches for the given caller id and returns 1 == true or 0 == false
1935 int parse_callbackauth(char *number, struct caller_info *callerinfo)
1940 unsigned int line,i;
1942 static char caller_type[32], caller_id[64];
1945 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
1947 if (!(fp = fopen(filename, "r")))
1949 PDEBUG(DEBUG_EPOINT, "Cannot open callbackauth: \"%s\"\n", filename);
1954 while((fgets(buffer, sizeof(buffer), fp)))
1957 buffer[sizeof(buffer)-1] = '\0';
1958 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1961 while(*p <= 32) /* skip spaces */
1967 if (*p==0 || *p=='#') /* ignore comments and empty line */
1973 i=0; /* read caller_type */
1976 if (i+1 >= sizeof(caller_type))
1978 PERROR_RUNTIME("Error in %s (line %d): caller_type too long.\n",filename,line);
1981 caller_type[i+1] = '\0';
1982 caller_type[i++] = *p++;
1985 while(*p <= 32) /* skip spaces */
1992 if (*p!=0 && *p!='#') /* caller_id */
1994 i=0; /* read caller_id */
1997 if (i+1 >= sizeof(caller_id))
1999 PERROR_RUNTIME("Error in %s (line %d): caller_id too long.\n",filename,line);
2002 caller_id[i+1] = '\0';
2003 caller_id[i++] = *p++;
2008 if (caller_type[0]=='\0' && caller_id[0]=='\0')
2011 if (atoi(caller_type) != callerinfo->ntype)
2014 if (!!strcmp(caller_id, callerinfo->id))
2018 break; /* found entry */
2029 /* append line to callbackauth
2032 void append_callbackauth(char *number, struct caller_info *callerinfo)
2037 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
2039 if (callerinfo->id[0]=='\0')
2041 PERROR("caller has no id.\n");
2044 if (!(fp = fopen(filename, "a")))
2046 PERROR("Cannot open callbackauth: \"%s\"\n", filename);
2050 fprintf(fp, "%6d %s\n", callerinfo->ntype, callerinfo->id);