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 ext->rights = 4; /* international */
66 ext->tout_setup = 120;
67 ext->tout_dialing = 120;
68 ext->tout_proceeding = 120;
69 ext->tout_alerting = 120;
70 ext->tout_disconnect = 120;
71 // ext->tout_hold = 900;
72 // ext->tout_park = 900;
74 ext->vbox_codec = CODEC_MONO;
77 while((fgets(buffer, sizeof(buffer), fp)))
80 buffer[sizeof(buffer)-1] = '\0';
81 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
84 while(*p <= 32) /* skip spaces */
90 if (*p==0 || *p=='#') /* ignore comments and empty line */
94 i=0; /* read option */
97 if (i+1 >= sizeof(option))
99 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
106 while(*p <= 32) /* skip spaces */
115 if (*p!=0 && *p!='#') /* param */
117 i=0; /* read param */
120 if (i+1 >= sizeof(param))
122 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
129 while(*p <= 32) /* skip spaces */
136 if (*p!=0 && *p!='#') /* param2 */
138 i=0; /* read param2 */
141 if (i+1 >= sizeof(param2))
143 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
152 /* at this point we have option and param */
155 if (!strcmp(option,"name"))
157 SCPY(ext->name, param);
160 SCAT(ext->name, " ");
161 SCAT(ext->name, param2);
164 PDEBUG(DEBUG_CONFIG, "name of extension: %s\n",param);
166 if (!strcmp(option,"prefix"))
168 SCPY(ext->prefix, param);
170 PDEBUG(DEBUG_CONFIG, "dial prefix on pickup: %s\n",param);
172 if (!strcmp(option,"next"))
174 SCPY(ext->next, param);
176 PDEBUG(DEBUG_CONFIG, "dial next on pickup: %s\n",param);
178 if (!strcmp(option,"alarm"))
180 SCPY(ext->alarm, param);
182 PDEBUG(DEBUG_CONFIG, "alarm message (if prefix): %s\n",param);
184 if (!strcmp(option,"cfu"))
186 SCPY(ext->cfu, param);
188 PDEBUG(DEBUG_CONFIG, "call forward unconditional: %s\n",param);
190 if (!strcmp(option,"cfb"))
192 SCPY(ext->cfb, param);
194 PDEBUG(DEBUG_CONFIG, "call forward when busy: %s\n",param);
196 if (!strcmp(option,"cfnr"))
198 SCPY(ext->cfnr, param);
200 PDEBUG(DEBUG_CONFIG, "call forward on no response: %s\n",param);
202 if (!strcmp(option,"cfnr_delay"))
204 ext->cfnr_delay = atoi(param);
205 if (ext->cfnr_delay < 0)
208 PDEBUG(DEBUG_CONFIG, "call forward no response delay: %d\n",ext->cfnr_delay);
210 if (!strcmp(option,"cfp"))
212 SCPY(ext->cfp, param);
214 PDEBUG(DEBUG_CONFIG, "call forward parallel: %s\n",param);
216 if (!strcmp(option,"change_forward"))
221 if (!strcasecmp(param,ext_yesno[i]))
227 ext->change_forward = i;
228 PDEBUG(DEBUG_CONFIG, "allow the change of forwarding: %s\n", ext_yesno[i]);
231 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_forward: %s\n", param);
234 if (!strcmp(option,"interfaces"))
236 SCPY(ext->interfaces, param);
238 PDEBUG(DEBUG_CONFIG, "interfaces to ring calls to extension: %s %s\n",param,param2);
240 if (!strcmp(option,"callerid"))
242 ext->callerid_present = INFO_PRESENT_ALLOWED;
243 if (!strncasecmp(param2, "anonymous", 9))
244 ext->callerid_present = INFO_PRESENT_RESTRICTED;
245 if (!strncasecmp(param, "non", 3))
247 ext->callerid[0] = '\0';
248 ext->callerid_present = INFO_PRESENT_NOTAVAIL;
249 ext->callerid_type = INFO_NTYPE_UNKNOWN;
250 PDEBUG(DEBUG_CONFIG, "caller id: ID NOT AVAILABLE\n");
256 ext->callerid_type = INFO_NTYPE_INTERNATIONAL;
257 SCPY(ext->callerid, param+1);
258 PDEBUG(DEBUG_CONFIG, "caller id: %s INTERNATIONAL\n",param+1);
262 ext->callerid_type = INFO_NTYPE_NATIONAL;
263 SCPY(ext->callerid, param+1);
264 PDEBUG(DEBUG_CONFIG, "caller id: %s NATIONAL\n",param+1);
268 ext->callerid_type = INFO_NTYPE_SUBSCRIBER;
269 SCPY(ext->callerid, param+1);
270 PDEBUG(DEBUG_CONFIG, "caller id: %s SUBSCRIBER\n",param+1);
273 ext->callerid_type = INFO_NTYPE_UNKNOWN;
274 SCPY(ext->callerid, param);
275 PDEBUG(DEBUG_CONFIG, "caller id: %s UNKNOWN\n",param);
277 ext->callerid[sizeof(ext->callerid)-1] = 0;
279 if (!strcmp(option,"id_next_call"))
281 ext->id_next_call_present = INFO_PRESENT_ALLOWED;
282 if (!strncasecmp(param2, "anonymous", 9))
283 ext->id_next_call_present = INFO_PRESENT_RESTRICTED;
284 if (param[0] == '\0')
286 ext->id_next_call_present = -1;
287 PDEBUG(DEBUG_CONFIG, "id next call: no id for next call\n");
289 if (!strncasecmp(param, "none", 3))
291 ext->id_next_call[0] = '\0';
292 ext->id_next_call_present = INFO_PRESENT_NOTAVAIL;
293 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
294 PDEBUG(DEBUG_CONFIG, "id next call: ID NOT AVAILABLE\n");
300 ext->id_next_call_type = INFO_NTYPE_INTERNATIONAL;
301 SCPY(ext->id_next_call, param+1);
302 PDEBUG(DEBUG_CONFIG, "id next call: %s INTERNATIONAL\n",param+1);
306 ext->id_next_call_type = INFO_NTYPE_NATIONAL;
307 SCPY(ext->id_next_call, param+1);
308 PDEBUG(DEBUG_CONFIG, "id next call: %s NATIONAL\n",param+1);
312 ext->id_next_call_type = INFO_NTYPE_SUBSCRIBER;
313 SCPY(ext->id_next_call, param+1);
314 PDEBUG(DEBUG_CONFIG, "id next call: %s SUBSCRIBER\n",param+1);
317 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
318 SCPY(ext->id_next_call, param);
319 PDEBUG(DEBUG_CONFIG, "id next call: %s UNKNOWN\n",param);
325 if (!strcmp(option,"change_callerid"))
330 if (!strcasecmp(param,ext_yesno[i]))
336 ext->change_callerid = i;
337 PDEBUG(DEBUG_CONFIG, "allow the change of caller id: %s\n", ext_yesno[i]);
340 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_callerid: %s\n", param);
343 if (!strcmp(option,"anon-ignore"))
348 if (!strcasecmp(param,ext_yesno[i]))
354 ext->anon_ignore = i;
355 PDEBUG(DEBUG_CONFIG, "ignore restriction of CLIP & COLP %s\n", ext_yesno[i]);
358 PDEBUG(DEBUG_CONFIG, "unknown parameter given anon-ignore: %s\n", param);
361 if (!strcmp(option,"clip"))
363 if (!strcasecmp(param, "hide"))
364 ext->clip = CLIP_HIDE;
366 ext->clip = CLIP_ASIS;
368 PDEBUG(DEBUG_CONFIG, "clip: %d\n",ext->clip);
370 if (!strcmp(option,"colp"))
372 if (!strcasecmp(param, "hide"))
373 ext->colp = COLP_HIDE;
374 else if (!strcasecmp(param, "force"))
375 ext->colp = COLP_FORCE;
377 ext->colp = COLP_ASIS;
379 PDEBUG(DEBUG_CONFIG, "colp: %d\n",ext->colp);
381 if (!strcmp(option,"clip_prefix"))
383 SCPY(ext->clip_prefix, param);
385 PDEBUG(DEBUG_CONFIG, "clip prefix: %s\n",param);
387 if (!strcmp(option,"keypad"))
392 if (!strcasecmp(param,ext_yesno[i]))
399 PDEBUG(DEBUG_CONFIG, "use keypad to do call control %s\n", ext_yesno[i]);
402 PDEBUG(DEBUG_CONFIG, "unknown parameter given keypad: %s\n", param);
405 if (!strcmp(option,"centrex"))
410 if (!strcasecmp(param,ext_yesno[i]))
417 PDEBUG(DEBUG_CONFIG, "use centrex to display name %s\n", ext_yesno[i]);
420 PDEBUG(DEBUG_CONFIG, "unknown parameter given centrex: %s\n", param);
423 if (!strcmp(option,"rights"))
428 if (!strcasecmp(param,ext_rights[i]))
435 PDEBUG(DEBUG_CONFIG, "rights to dial: %s\n", ext_rights[i]);
438 PDEBUG(DEBUG_CONFIG, "given rights unknown: %s\n", param);
441 if (!strcmp(option,"delete_ext"))
446 if (!strcasecmp(param,ext_yesno[i]))
453 PDEBUG(DEBUG_CONFIG, "enables the delete key function for external calls: %s\n", ext_yesno[i]);
456 PDEBUG(DEBUG_CONFIG, "unknown parameter given delete: %s\n", param);
459 if (!strcmp(option,"noknocking"))
464 if (!strcasecmp(param,ext_yesno[i]))
471 PDEBUG(DEBUG_CONFIG, "noknocking %s\n", ext_yesno[i]);
474 PDEBUG(DEBUG_CONFIG, "given noknocking param unknown: %s\n", param);
477 if (!strcmp(option,"rxvol"))
479 ext->rxvol = atoi(param);
480 if (ext->rxvol<-8 || ext->rxvol>8)
483 PDEBUG(DEBUG_CONFIG, "receive volume: %d\n",ext->rxvol);
485 if (!strcmp(option,"txvol"))
487 ext->txvol = atoi(param);
488 if (ext->txvol<-8 || ext->txvol>8)
491 PDEBUG(DEBUG_CONFIG, "transmit volume: %d\n",ext->txvol);
493 if (!strcmp(option,"tout_setup"))
495 ext->tout_setup = atoi(param);
496 if (ext->tout_setup < 0)
499 PDEBUG(DEBUG_CONFIG, "timeout setup: %d\n",ext->tout_setup);
501 if (!strcmp(option,"tout_dialing"))
503 ext->tout_dialing = atoi(param);
504 if (ext->tout_dialing < 0)
505 ext->tout_dialing = 0;
507 PDEBUG(DEBUG_CONFIG, "timeout dialing: %d\n",ext->tout_dialing);
509 if (!strcmp(option,"tout_proceeding"))
511 ext->tout_proceeding = atoi(param);
512 if (ext->tout_proceeding < 0)
513 ext->tout_proceeding = 0;
515 PDEBUG(DEBUG_CONFIG, "timeout proceeding: %d\n",ext->tout_proceeding);
517 if (!strcmp(option,"tout_alerting"))
519 ext->tout_alerting = atoi(param);
520 if (ext->tout_alerting < 0)
521 ext->tout_alerting = 0;
523 PDEBUG(DEBUG_CONFIG, "timeout alerting: %d\n",ext->tout_alerting);
525 if (!strcmp(option,"tout_disconnect"))
527 ext->tout_disconnect = atoi(param);
528 if (ext->tout_disconnect < 0)
529 ext->tout_disconnect = 0;
531 PDEBUG(DEBUG_CONFIG, "timeout disconnect: %d\n",ext->tout_disconnect);
534 if (!strcmp(option,"tout_hold"))
536 ext->tout_hold = atoi(param);
537 if (ext->tout_hold < 0)
540 PDEBUG(DEBUG_CONFIG, "timeout hold: %d\n",ext->tout_hold);
542 if (!strcmp(option,"tout_park"))
544 ext->tout_park = atoi(param);
545 if (ext->tout_park < 0)
548 PDEBUG(DEBUG_CONFIG, "timeout park: %d\n",ext->tout_park);
551 if (!strcmp(option,"own_setup"))
556 if (!strcasecmp(param,ext_yesno[i]))
563 PDEBUG(DEBUG_CONFIG, "own_setup %s\n", ext_yesno[i]);
566 PDEBUG(DEBUG_CONFIG, "given own_setup param unknown: %s\n", param);
569 if (!strcmp(option,"own_proceeding"))
574 if (!strcasecmp(param,ext_yesno[i]))
580 ext->own_proceeding = i;
581 PDEBUG(DEBUG_CONFIG, "own_proceeding %s\n", ext_yesno[i]);
584 PDEBUG(DEBUG_CONFIG, "given own_proceeding param unknown: %s\n", param);
587 if (!strcmp(option,"own_alerting"))
592 if (!strcasecmp(param,ext_yesno[i]))
598 ext->own_alerting = i;
599 PDEBUG(DEBUG_CONFIG, "own_alerting %s\n", ext_yesno[i]);
602 PDEBUG(DEBUG_CONFIG, "given own_alerting param unknown: %s\n", param);
605 if (!strcmp(option,"own_cause"))
610 if (!strcasecmp(param,ext_yesno[i]))
617 PDEBUG(DEBUG_CONFIG, "own_cause %s\n", ext_yesno[i]);
620 PDEBUG(DEBUG_CONFIG, "given own_cause param unknown: %s\n", param);
623 if (!strcmp(option,"facility"))
628 if (!strcasecmp(param,ext_yesno[i]))
635 PDEBUG(DEBUG_CONFIG, "facility %s\n", ext_yesno[i]);
638 PDEBUG(DEBUG_CONFIG, "given facility param unknown: %s\n", param);
641 if (!strcmp(option,"display_cause"))
643 if (!strcasecmp(param, "german"))
644 ext->display_cause = DISPLAY_CAUSE_GERMAN;
645 else if (!strcasecmp(param, "english"))
646 ext->display_cause = DISPLAY_CAUSE_ENGLISH;
647 else if (!strcasecmp(param, "german-location"))
648 ext->display_cause = DISPLAY_LOCATION_GERMAN;
649 else if (!strcasecmp(param, "english-location"))
650 ext->display_cause = DISPLAY_LOCATION_ENGLISH;
651 else if (!strcasecmp(param, "number"))
652 ext->display_cause = DISPLAY_CAUSE_NUMBER;
654 ext->display_cause = DISPLAY_CAUSE_NONE;
656 PDEBUG(DEBUG_CONFIG, "display cause: %d\n",ext->display_cause);
659 if (!strcmp(option,"display_ext"))
661 if (!strcasecmp(param, "number"))
662 ext->display_ext = DISPLAY_CID_NUMBER;
663 else if (!strcasecmp(param, "abbrev"))
664 ext->display_ext = DISPLAY_CID_ABBREVIATION;
665 else if (!strcasecmp(param, "name"))
666 ext->display_ext = DISPLAY_CID_NAME;
667 else if (!strcasecmp(param, "number-name"))
668 ext->display_ext = DISPLAY_CID_NUMBER_NAME;
669 else if (!strcasecmp(param, "name-number"))
670 ext->display_ext = DISPLAY_CID_NAME_NUMBER;
671 else if (!strcasecmp(param, "abbrev-number"))
672 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER;
673 else if (!strcasecmp(param, "abbrev-name"))
674 ext->display_ext = DISPLAY_CID_ABBREV_NAME;
675 else if (!strcasecmp(param, "abbrev-name-number"))
676 ext->display_ext = DISPLAY_CID_ABBREV_NAME_NUMBER;
677 else if (!strcasecmp(param, "abbrev-number-name"))
678 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER_NAME;
680 ext->display_ext = DISPLAY_CID_ASIS;
682 PDEBUG(DEBUG_CONFIG, "display ext: %d\n",ext->display_ext);
685 if (!strcmp(option,"display_ext"))
690 if (!strcasecmp(param,ext_yesno[i]))
696 ext->display_ext = i;
697 PDEBUG(DEBUG_CONFIG, "display ext %s\n", ext_yesno[i]);
700 PDEBUG(DEBUG_CONFIG, "given display_ext param unknown: %s\n", param);
703 if (!strcmp(option,"display_int"))
708 if (!strcasecmp(param,ext_yesno[i]))
714 ext->display_int = i;
715 PDEBUG(DEBUG_CONFIG, "display int %s\n", ext_yesno[i]);
718 PDEBUG(DEBUG_CONFIG, "given display_int param unknown: %s\n", param);
721 if (!strcmp(option,"display_fake"))
726 if (!strcasecmp(param,ext_yesno[i]))
732 ext->display_fake = i;
733 PDEBUG(DEBUG_CONFIG, "display fake caller ids %s\n", ext_yesno[i]);
736 PDEBUG(DEBUG_CONFIG, "given display_fake param unknown: %s\n", param);
739 if (!strcmp(option,"display_anon"))
744 if (!strcasecmp(param,ext_yesno[i]))
750 ext->display_anon = i;
751 PDEBUG(DEBUG_CONFIG, "display anonymouse ids %s\n", ext_yesno[i]);
754 PDEBUG(DEBUG_CONFIG, "given display_anon param unknown: %s\n", param);
757 if (!strcmp(option,"display_menu"))
762 if (!strcasecmp(param,ext_yesno[i]))
768 ext->display_menu = i;
769 PDEBUG(DEBUG_CONFIG, "display menu %s\n", ext_yesno[i]);
772 PDEBUG(DEBUG_CONFIG, "given display_menu param unknown: %s\n", param);
775 if (!strcmp(option,"display_dialing"))
780 if (!strcasecmp(param,ext_yesno[i]))
786 ext->display_dialing = i;
787 PDEBUG(DEBUG_CONFIG, "display dialing %s\n", ext_yesno[i]);
790 PDEBUG(DEBUG_CONFIG, "given display_dialing param unknown: %s\n", param);
793 if (!strcmp(option,"display_name"))
798 if (!strcasecmp(param,ext_yesno[i]))
804 ext->display_name = i;
805 PDEBUG(DEBUG_CONFIG, "display name %s\n", ext_yesno[i]);
808 PDEBUG(DEBUG_CONFIG, "given display_name param unknown: %s\n", param);
811 if (!strcmp(option,"tones_dir"))
813 if (param[strlen(param)-1] == '/')
814 param[strlen(param)-1]=0;
815 SCPY(ext->tones_dir, param);
817 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
819 if (!strcmp(option,"record"))
821 if (!strcasecmp(param, "mono"))
822 ext->record = CODEC_MONO;
823 else if (!strcasecmp(param, "stereo"))
824 ext->record = CODEC_STEREO;
825 else if (!strcasecmp(param, "8bit"))
826 ext->record = CODEC_8BIT;
827 else if (!strcasecmp(param, "law"))
828 ext->record = CODEC_LAW;
830 ext->record = CODEC_OFF;
831 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
833 if (!strcmp(option,"password"))
835 SCPY(ext->password, param);
837 PDEBUG(DEBUG_CONFIG, "password: %s\n",param);
839 if (!strcmp(option,"vbox_mode"))
841 if (!strcasecmp(param, "parallel"))
842 ext->vbox_mode = VBOX_MODE_PARALLEL;
843 else if (!strcasecmp(param, "announcement"))
844 ext->vbox_mode = VBOX_MODE_ANNOUNCEMENT;
846 ext->vbox_mode = VBOX_MODE_NORMAL;
847 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
849 if (!strcmp(option,"vbox_codec"))
851 if (!strcasecmp(param, "stereo"))
852 ext->vbox_codec = CODEC_STEREO;
853 else if (!strcasecmp(param, "8bit"))
854 ext->vbox_codec = CODEC_8BIT;
855 else if (!strcasecmp(param, "law"))
856 ext->vbox_codec = CODEC_LAW;
858 ext->vbox_codec = CODEC_MONO;
859 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
861 if (!strcmp(option,"vbox_time"))
863 ext->vbox_time = atoi(param);
864 if (ext->vbox_time < 0)
867 PDEBUG(DEBUG_CONFIG, "vbox time to record: %d\n",ext->vbox_time);
869 if (!strcmp(option,"vbox_display"))
871 if (!strcasecmp(param, "detailed")
872 || !strcasecmp(param, "detailled"))
873 ext->vbox_display = VBOX_DISPLAY_DETAILED;
874 else if (!strcasecmp(param, "off"))
875 ext->vbox_display = VBOX_DISPLAY_OFF;
877 ext->vbox_display = VBOX_DISPLAY_BRIEF;
878 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
880 if (!strcmp(option,"vbox_language"))
882 if (!strcasecmp(param, "german"))
883 ext->vbox_language = VBOX_LANGUAGE_GERMAN;
885 ext->vbox_language = VBOX_LANGUAGE_ENGLISH;
886 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
888 if (!strcmp(option,"vbox_email"))
890 SCPY(ext->vbox_email, param);
891 PDEBUG(DEBUG_CONFIG, "given vbox email: %s\n", param);
893 if (!strcmp(option,"vbox_email_file"))
898 if (!strcasecmp(param,ext_yesno[i]))
904 ext->vbox_email_file = i;
905 PDEBUG(DEBUG_CONFIG, "attach audio file %s\n", ext_yesno[i]);
908 PDEBUG(DEBUG_CONFIG, "given vbox_email_file param unknown: %s\n", param);
911 if (!strcmp(option,"vbox_free"))
916 if (!strcasecmp(param,ext_yesno[i]))
923 PDEBUG(DEBUG_CONFIG, "vbox_free %s\n", ext_yesno[i]);
926 PDEBUG(DEBUG_CONFIG, "given vbox_free param unknown: %s\n", param);
929 if (!strcmp(option,"last_in"))
931 if (param[0] && last_in_count<MAX_REMEMBER)
933 SCPY(ext->last_in[last_in_count], param);
936 PDEBUG(DEBUG_CONFIG, "last_in dialed number: %s\n",param);
938 if (!strcmp(option,"last_out"))
940 if (param[0] && last_out_count<MAX_REMEMBER)
942 SCPY(ext->last_out[last_out_count], param);
945 PDEBUG(DEBUG_CONFIG, "last_out dialed number: %s\n",param);
947 if (!strcmp(option,"datacall"))
952 if (!strcasecmp(param,ext_yesno[i]))
959 PDEBUG(DEBUG_CONFIG, "datacall %s\n", ext_yesno[i]);
962 PDEBUG(DEBUG_CONFIG, "given datacall param unknown: %s\n", param);
965 if (!strcmp(option,"seconds"))
970 if (!strcasecmp(param,ext_yesno[i]))
976 ext->no_seconds = 1-i;
977 PDEBUG(DEBUG_CONFIG, "seconds %s\n", ext_yesno[i]);
980 PDEBUG(DEBUG_CONFIG, "unknown param for seconds: %s\n", param);
984 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n",filename,line,option);
995 * writes extension for given extension number from structure
997 int write_extension(struct extension *ext, char *number)
1003 if (number[0] == '\0')
1006 SPRINT(filename, "%s/%s/%s/settings", INSTALL_DATA, options.extensions_dir, number);
1008 if (!(fp = fopen(filename, "w")))
1010 PERROR("Cannot open settings: \"%s\"\n", filename);
1014 fprintf(fp,"# Settings of extension %s\n\n", number);
1016 fprintf(fp,"# Name of extension:\n");
1017 fprintf(fp,"name %s\n\n",ext->name);
1019 fprintf(fp,"# Predialed prefix after pick-up of the phone\n");
1020 fprintf(fp,"prefix %s\n\n",ext->prefix);
1022 fprintf(fp,"# Next prefix to dial pick-up of the phone\n");
1023 fprintf(fp,"# This will be cleared on hangup.\n");
1024 fprintf(fp,"next %s\n\n",ext->next);
1026 // fprintf(fp,"# Set up alarm message after prefix is dialed and connection is established\n");
1027 // fprintf(fp,"alarm %s\n\n",ext->alarm);
1029 fprintf(fp,"# Ports to ring on calls to extension (starting from 1)\n");
1030 fprintf(fp,"# Seperate ports by using komma. (example: 1,3 would ring incoming calls on\n# port 1 and 3)\n");
1031 fprintf(fp,"interfaces %s\n\n",ext->interfaces);
1033 fprintf(fp,"# Call Forward Unconditional (CFU)\n");
1034 fprintf(fp,"# No port will be called, CFB, CFNR and CFP is ignored.\n");
1035 fprintf(fp,"# Use keyword \"vbox\" to forward call directly to answering machine.\n");
1036 fprintf(fp,"cfu %s\n\n",ext->cfu);
1038 fprintf(fp,"# Call Forward when Busy (CFB)\n");
1039 fprintf(fp,"# If the extension is in use at least once, this forward is done.\n");
1040 fprintf(fp,"# In case of busy line, CFNR and CFP is ignored.\n");
1041 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine when busy.\n");
1042 fprintf(fp,"cfb %s\n\n",ext->cfb);
1044 fprintf(fp,"# Call Forward on No Response (CFNR)\n");
1045 fprintf(fp,"# If noone answers, the call is forwarded, ports and CFP will be released.\n");
1046 fprintf(fp,"# The default delay is 20 seconds.\n");
1047 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine on no response.\n");
1048 fprintf(fp,"cfnr %s\n",ext->cfnr);
1049 fprintf(fp,"cfnr_delay %d\n\n",ext->cfnr_delay);
1051 fprintf(fp,"# Call Forward Parallel (CFP)\n");
1052 fprintf(fp,"# Call will ring on the forwarded number, simulaniousely with the ports.\n");
1053 fprintf(fp,"cfp %s\n\n",ext->cfp);
1055 fprintf(fp,"# Allow user to change call forwarding.\n");
1056 fprintf(fp,"change_forward %s\n\n", ext_yesno[ext->change_forward]);
1058 fprintf(fp,"# Caller id\n# This must be one of the following:\n");
1059 fprintf(fp,"# <number> (as dialed from your local area)\n");
1060 fprintf(fp,"# <number> anonymous (will only be shown to emergency phones)\n");
1061 fprintf(fp,"# none (no number available at all)\n");
1062 fprintf(fp,"# by default the number is of type UNKNOWN (for MULTIPOINT lines)\n");
1063 fprintf(fp,"# if your caller id is not screened on outgoing calls use one of the following:\n");
1064 fprintf(fp,"# use prefix 'i' for TYPE INTERNATIONAL (i<county code><areacode+number>)\n");
1065 fprintf(fp,"# use prefix 'n' for TYPE NATIONAL (n<areacode+number>)\n");
1066 fprintf(fp,"# use prefix 's' for TYPE SUBSCRIBER (s<local number>)\n");
1067 if (ext->callerid_present == INFO_PRESENT_NOTAVAIL)
1068 fprintf(fp,"callerid none\n\n");
1071 switch(ext->callerid_type)
1073 case INFO_NTYPE_INTERNATIONAL:
1074 fprintf(fp,"callerid i%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1076 case INFO_NTYPE_NATIONAL:
1077 fprintf(fp,"callerid n%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1079 case INFO_NTYPE_SUBSCRIBER:
1080 fprintf(fp,"callerid s%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1083 fprintf(fp,"callerid %s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1087 fprintf(fp,"# Caller id for next call (see caller id)\n");
1088 if (ext->id_next_call_present < 0)
1089 fprintf(fp,"id_next_call \n\n");
1090 else if (ext->id_next_call_present == INFO_PRESENT_NOTAVAIL)
1091 fprintf(fp,"id_next_call none\n\n");
1094 switch(ext->id_next_call_type)
1096 case INFO_NTYPE_INTERNATIONAL:
1097 fprintf(fp,"id_next_call i%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1099 case INFO_NTYPE_NATIONAL:
1100 fprintf(fp,"id_next_call n%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1102 case INFO_NTYPE_SUBSCRIBER:
1103 fprintf(fp,"id_next_call s%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1106 fprintf(fp,"id_next_call %s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1110 fprintf(fp,"# Allow user to change caller ID.\n");
1111 fprintf(fp,"change_callerid %s\n\n", ext_yesno[ext->change_callerid]);
1113 fprintf(fp,"# Caller Line Identification Presentation (CLIP)\n");
1114 fprintf(fp,"# clip (asis|hide)\n");
1115 fprintf(fp,"# asis: On forwarded calls the CLIP is used as presented by the calling party.\n");
1116 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1120 fprintf(fp,"clip hide\n\n");
1123 fprintf(fp,"clip asis\n\n");
1126 fprintf(fp,"# Connected Line Identification Presentation (COLP)\n");
1127 fprintf(fp,"# colp (asis|hide|force)\n");
1128 fprintf(fp,"# asis: Provides colp as defined by the extension's caller id.\n");
1129 fprintf(fp,"# On forwarded calls the COLP is used as presented by the called party.\n");
1130 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1131 fprintf(fp,"# force: If COLP is not presented by forwarded calls the dialed number is used.\n");
1135 fprintf(fp,"colp hide\n\n");
1138 fprintf(fp,"colp force\n\n");
1141 fprintf(fp,"colp asis\n\n");
1144 fprintf(fp,"# CLIP Prefix\n");
1145 fprintf(fp,"# Adds a prefix to incomming caller IDs, so telephones will be able to respond\n");
1146 fprintf(fp,"# to unanswered calls from their list. The prefix must be the digit(s) to get\n");
1147 fprintf(fp,"# an external line. The caller ID will then be extendet so that they can be\n");
1148 fprintf(fp,"# dialed from internal telephones. Many telephones have this feature, but some\n");
1149 fprintf(fp,"# don't.\n");
1150 fprintf(fp,"clip_prefix %s\n\n",ext->clip_prefix);
1152 fprintf(fp,"# Keypad control\n");
1153 fprintf(fp,"# If supported by telephone, pressing a key on the keypad will not result in\n");
1154 fprintf(fp,"# DTMF tone, but the digit is transmitted via D-channel diaing info.\n");
1155 fprintf(fp,"keypad %s\n\n",(ext->keypad)?"yes":"no");
1157 fprintf(fp,"# Called Name Identification Presentation (CNIP/CONP)\n");
1158 fprintf(fp,"# If supported by telephone, special information element on the d-channel are\n");
1159 fprintf(fp,"# used to show name of caller. It is supported by newer Siemens telephones\n# (Centrex).\n");
1160 fprintf(fp,"centrex %s #this is currently not working!!!\n\n",(ext->centrex)?"yes":"no");
1162 fprintf(fp,"# Ignore restriction of COLP and CLIP\n");
1163 fprintf(fp,"# In this case even restricted numbers are presented to this extension.\n");
1164 fprintf(fp,"# This also works for incoming external anonymous calls IF:\n");
1165 fprintf(fp,"# You have the CLIRIGN feature like POLICE or equivalent.\n");
1166 fprintf(fp,"anon-ignore %s\n\n",(ext->anon_ignore)?"yes":"no");
1168 fprintf(fp,"# Dialing rights (none|internal|local|national|international)\n");
1169 fprintf(fp,"rights %s\n\n",ext_rights[ext->rights]);
1171 fprintf(fp,"# Delete function for external calls. '*' will delete the last digit, '#' will\n");
1172 fprintf(fp,"# delete the complete number. Also enable 'display_dialing' to see on the\n");
1173 fprintf(fp,"# display what actually happens.\n");
1174 fprintf(fp,"delete_ext %s\n\n",ext_yesno[ext->delete_ext]);
1176 fprintf(fp,"# If noknocking is enabled, the caller will get a busy message when the\n");
1177 fprintf(fp,"# extension is doing at least one call.\n");
1178 fprintf(fp,"noknocking %s\n\n",ext_yesno[ext->noknocking]);
1180 fprintf(fp,"# Transmit volume (-8 .. 8)\n");
1181 fprintf(fp,"# 0 = normal\n");
1182 fprintf(fp,"# 1 = double, 2 = quadrupel, 8 = 256 times (amplitude)\n");
1183 fprintf(fp,"# -1 = half, -2 = quarter, 8 = 1/256th (amplitude)\n");
1184 fprintf(fp,"# Audio data is limited to the maximum value when exceeds limit.\n");
1185 fprintf(fp,"txvol %d\n\n",ext->txvol);
1187 fprintf(fp,"# Receive volume (-8 .. 8)\n");
1188 fprintf(fp,"# (see txvol)\n");
1189 fprintf(fp,"rxvol %d\n\n",ext->rxvol);
1191 fprintf(fp,"# Timeout values\n# The keywords specify the following timeouts:\n");
1192 fprintf(fp,"# tout_setup: after pickup before dialing anything. (default 60 seconds)\n");
1193 fprintf(fp,"# tout_dialing: after dialing last digit of uncomplete number (default 15)\n");
1194 fprintf(fp,"# tout_proceeding: after start proceeding (default 120)\n");
1195 fprintf(fp,"# tout_alerting: after start ringing (default 120)\n");
1196 fprintf(fp,"# tout_disconnect: after disconnect (default 120)\n");
1197 // fprintf(fp,"# tout_hold: maximum time to hold a call (default 900)\n");
1198 // fprintf(fp,"# tout_park: maximum time to park a call (default 900)\n");
1199 fprintf(fp,"# All timeouts may be disabled by using keyword 'off' instead of seconds.\n");
1200 fprintf(fp,"# All timeouts refer to internal ports only. External timeouts are controlled\n");
1201 fprintf(fp,"# by external line.\n");
1202 if (ext->tout_setup)
1203 fprintf(fp,"tout_setup %d\n",ext->tout_setup);
1205 fprintf(fp,"tout_setup off\n");
1206 if (ext->tout_dialing)
1207 fprintf(fp,"tout_dialing %d\n",ext->tout_dialing);
1209 fprintf(fp,"tout_dialing off\n");
1210 if (ext->tout_proceeding)
1211 fprintf(fp,"tout_proceeding %d\n",ext->tout_proceeding);
1213 fprintf(fp,"tout_proceeding off\n");
1214 if (ext->tout_alerting)
1215 fprintf(fp,"tout_alerting %d\n",ext->tout_alerting);
1217 fprintf(fp,"tout_alerting off\n");
1218 if (ext->tout_disconnect)
1219 fprintf(fp,"tout_disconnect %d\n\n",ext->tout_disconnect);
1221 fprintf(fp,"tout_disconnect off\n\n");
1222 // if (ext->tout_hold)
1223 // fprintf(fp,"tout_hold %d\n",ext->tout_hold);
1225 // fprintf(fp,"tout_hold off\n");
1226 // if (ext->tout_park)
1227 // fprintf(fp,"tout_park %d\n\n",ext->tout_park);
1229 // fprintf(fp,"tout_park off\n\n");
1231 fprintf(fp,"# Force to use tones and announcements generated by the pbx.\n");
1232 fprintf(fp,"# For internal calls always own tones are used. You may specify own tones for\n");
1233 fprintf(fp,"# different call states:\n");
1234 fprintf(fp,"# own_setup (dialtone and during dialing)\n");
1235 fprintf(fp,"# own_proceeding (call in poceeding state)\n");
1236 fprintf(fp,"# own_alerting (call is ringing)\n");
1237 fprintf(fp,"# own_cause (when the call gets disconnected or failed to be completed)\n");
1238 fprintf(fp,"own_setup %s\n",ext_yesno[ext->own_setup]);
1239 fprintf(fp,"own_proceeding %s\n",ext_yesno[ext->own_proceeding]);
1240 fprintf(fp,"own_alerting %s\n",ext_yesno[ext->own_alerting]);
1241 fprintf(fp,"own_cause %s\n\n",ext_yesno[ext->own_cause]);
1243 fprintf(fp,"# Allow facility information to be transfered to the telephone.\n");
1244 fprintf(fp,"# This is equired to receive advice of charge.\n");
1245 fprintf(fp,"facility %s\n\n",ext_yesno[ext->facility]);
1247 fprintf(fp,"# Display clear causes using display messages (Q.850)\n# This must be one of the following:\n");
1248 fprintf(fp,"# none (no displaying of clear causes)\n");
1249 fprintf(fp,"# english (display cause text in english)\n");
1250 fprintf(fp,"# german (display cause text in german)\n");
1251 fprintf(fp,"# number (display cause number only)\n");
1252 fprintf(fp,"# english-location (display cause text in english and location)\n");
1253 fprintf(fp,"# german-location (display cause text in german and location)\n");
1254 switch(ext->display_cause)
1256 case DISPLAY_CAUSE_ENGLISH:
1257 fprintf(fp,"display_cause english\n\n");
1259 case DISPLAY_CAUSE_GERMAN:
1260 fprintf(fp,"display_cause german\n\n");
1262 case DISPLAY_LOCATION_ENGLISH:
1263 fprintf(fp,"display_cause english-location\n\n");
1265 case DISPLAY_LOCATION_GERMAN:
1266 fprintf(fp,"display_cause german-location\n\n");
1268 case DISPLAY_CAUSE_NUMBER:
1269 fprintf(fp,"display_cause number\n\n");
1272 fprintf(fp,"display_cause none\n\n");
1275 fprintf(fp,"# Display external caller ids using display override (yes or no)\n");
1276 fprintf(fp,"# example: \"15551212\"\n");
1277 fprintf(fp,"display_ext %s\n\n",(ext->display_ext)?"yes":"no");
1279 fprintf(fp,"# Display internal caller ids using display override (yes or no)\n");
1280 fprintf(fp,"# example: \"200 (int)\"\n");
1281 fprintf(fp,"display_int %s\n\n",(ext->display_int)?"yes":"no");
1283 fprintf(fp,"# Display if calls are anonymous using display override (yes or no)\n");
1284 fprintf(fp,"# This makes only sense if the anon-ignore feature is enabled.\n");
1285 fprintf(fp,"# example: \"15551212 anon\"\n");
1286 fprintf(fp,"display_anon %s\n\n",(ext->display_anon)?"yes":"no");
1288 fprintf(fp,"# Display fake caller ids using display override (yes or no)\n");
1289 fprintf(fp,"# If the caller uses \"clip no screening\", you will see if the number is\n");
1290 fprintf(fp,"# real or fake\n");
1291 fprintf(fp,"# example: \"15551212 fake\"\n");
1292 fprintf(fp,"display_fake %s\n\n",(ext->display_fake)?"yes":"no");
1294 fprintf(fp,"# Display caller's name if available. (yes or no)\n");
1295 fprintf(fp,"# example: \"15551212 Axel\"\n");
1296 fprintf(fp,"display_name %s\n\n",(ext->display_name)?"yes":"no");
1298 fprintf(fp,"# Display menu when '*' and '#' is pressed. The menu shows all prefixes for\n");
1299 fprintf(fp,"# internal dialing by pressing '*' for previous prefix and '#' for next prefix.\n");
1300 fprintf(fp,"# Also the dialed prefix is show on display. (yes or no)\n");
1301 fprintf(fp,"display_menu %s\n\n",(ext->display_menu)?"yes":"no");
1303 fprintf(fp,"# Display digits as they are interpreted by pbx. (yes or no)\n");
1304 fprintf(fp,"display_dialing %s\n\n",(ext->display_dialing)?"yes":"no");
1306 fprintf(fp,"# Tones directory for announcements and patterns\n");
1307 fprintf(fp,"# Enter nothing for default tones as selected by options.conf.\n");
1308 fprintf(fp,"tones_dir %s\n\n",ext->tones_dir);
1310 fprintf(fp,"# Record calls to extension's directory. The file is written as wave.\n");
1311 fprintf(fp,"# This must be one of the following:\n");
1312 fprintf(fp,"# off (no recording)\n");
1313 fprintf(fp,"# mono (records wave 16 bit mono, 128kbits/s)\n");
1314 fprintf(fp,"# stereo (records wave 32 bit stereo, 256kbits/s)\n");
1315 fprintf(fp,"# 8bit (records wave 8 bit mono, 64kbits/s)\n");
1316 fprintf(fp,"# law (records xLaw encoded, as specified in options.conf, 64kbps/s)\n");
1320 fprintf(fp,"record mono\n\n");
1323 fprintf(fp,"record stereo\n\n");
1326 fprintf(fp,"record 8bit\n\n");
1329 fprintf(fp,"record law\n\n");
1332 fprintf(fp,"record off\n\n");
1335 fprintf(fp,"# Password for callback and login\n");
1336 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1337 fprintf(fp,"password %s\n\n",ext->password);
1339 fprintf(fp,"# The Answering Machine. Enter the mode of answering machine.\n");
1340 fprintf(fp,"# This must be one of the following:\n");
1341 fprintf(fp,"# normal (plays announcement and records after that)\n");
1342 fprintf(fp,"# parallel (plays announcement and records also DURING announcement.)\n");
1343 fprintf(fp,"# announcement (just plays announcement and hangs up)\n");
1344 switch(ext->vbox_mode)
1346 case VBOX_MODE_PARALLEL:
1347 fprintf(fp,"vbox_mode parallel\n\n");
1349 case VBOX_MODE_ANNOUNCEMENT:
1350 fprintf(fp,"vbox_mode announcement\n\n");
1353 fprintf(fp,"vbox_mode normal\n\n");
1356 fprintf(fp,"# The Answering Machine. Enter the type of codec for recording.\n");
1357 fprintf(fp,"# This must be one of the following:\n");
1358 fprintf(fp,"# law (alaw/ulas codec, as specified in options.conf)\n");
1359 fprintf(fp,"# mono (16 bit mono wave file)\n");
1360 fprintf(fp,"# stereo (16 bit stereo wave file)\n");
1361 fprintf(fp,"# 8bit (8 bit mono wave file)\n");
1362 switch(ext->vbox_codec)
1365 fprintf(fp,"vbox_codec law\n\n");
1368 fprintf(fp,"vbox_codec stereo\n\n");
1371 fprintf(fp,"vbox_codec 8bit\n\n");
1374 fprintf(fp,"vbox_codec mono\n\n");
1377 fprintf(fp,"# The Answering Machine. Enter maximum time to record after announcement.\n");
1378 fprintf(fp,"# Leave empty, enter \"infinite\" or give time in seconds.\n");
1379 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1381 fprintf(fp,"vbox_time %d\n\n",ext->vbox_time);
1383 fprintf(fp,"vbox_time infinite\n\n");
1385 fprintf(fp,"# The Answering Machine. Enter mode for display current state.\n");
1386 fprintf(fp,"# This must be one of the following:\n");
1387 fprintf(fp,"# brief (displays brief information, for small displays)\n");
1388 fprintf(fp,"# detailed (displays detailed information, for larger displays)\n");
1389 fprintf(fp,"# off (don't display anything)\n");
1390 switch(ext->vbox_display)
1392 case VBOX_DISPLAY_OFF:
1393 fprintf(fp,"vbox_display off\n\n");
1395 case VBOX_DISPLAY_DETAILED:
1396 fprintf(fp,"vbox_display detailed\n\n");
1399 fprintf(fp,"vbox_display brief\n\n");
1402 fprintf(fp,"# The Answering Machine. Enter type of language: \"english\" or \"german\"\n");
1403 fprintf(fp,"# Display information of the menu, will be provided as specified.\n");
1404 fprintf(fp,"# The menu's voice is located in \"vbox_english\" and \"vbox_german\".\n");
1405 if (ext->vbox_language)
1406 fprintf(fp,"vbox_language german\n\n");
1408 fprintf(fp,"vbox_language english\n\n");
1410 fprintf(fp,"# The Answering Machine. Enter email to send incoming messages to:\n");
1411 fprintf(fp,"# All incoming message will be send to the given address.\n");
1412 fprintf(fp,"# The audio file is attached if \"vbox_email_file\" is 'yes'\n");
1413 fprintf(fp,"vbox_email %s\n", ext->vbox_email);
1414 fprintf(fp,"vbox_email_file %s\n\n",ext_yesno[ext->vbox_email_file]);
1416 fprintf(fp,"# If audio path is connected prior answering of a call, say 'yes'\n");
1417 fprintf(fp,"# will cause the call to be billed after playing the announcement. (yes or no)\n");
1418 fprintf(fp,"vbox_free %s\n\n",(ext->vbox_free)?"yes":"no");
1420 fprintf(fp,"# Accept incoming data calls as it would be an audio call.\n");
1421 fprintf(fp,"datacall %s\n\n",ext_yesno[ext->datacall]);
1423 fprintf(fp,"# Include seconds (time) in the connect message. (Should be always enabled.)\n");
1424 fprintf(fp,"seconds %s\n\n",ext_yesno[1-ext->no_seconds]);
1426 fprintf(fp,"# Last outgoing and incoming numbers (including prefix)\n");
1428 while(i < MAX_REMEMBER)
1430 if (ext->last_out[i][0])
1431 fprintf(fp,"last_out %s\n",ext->last_out[i]);
1435 while(i < MAX_REMEMBER)
1437 if (ext->last_in[i][0])
1438 fprintf(fp,"last_in %s\n",ext->last_in[i]);
1449 /* write log for extension
1452 int write_log(char *number, char *callerid, char *calledid, time_t start, time_t stop, int aoce, int cause, int location)
1454 char *mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1459 if (callerid[0] == '\0')
1460 callerid = "<unknown>";
1462 SPRINT(filename, "%s/%s/%s/log", INSTALL_DATA, options.extensions_dir, number);
1464 if (!(fp = fopen(filename, "a")))
1466 PERROR("Cannot open log: \"%s\"\n", filename);
1470 tm = localtime(&start);
1471 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);
1473 fprintf(fp," %2ld:%02ld:%02ld", (stop-start)/3600, (((unsigned long)(stop-start))/60)%60, ((unsigned long)(stop-start))%60);
1475 fprintf(fp," --:--:--");
1476 fprintf(fp," %s -> %s", callerid, calledid);
1477 if (cause >= 1 && cause <=127 && location>=0 && location<=15)
1478 fprintf(fp," (cause=%d '%s' location=%d '%s')", cause, isdn_cause[cause].german, location, isdn_location[location].german);
1488 * reads phone book of extextension and compares the given elements which
1489 * are: abreviation, phone number, name (name is not compared)
1490 * on success a 1 is returned and the pointers of elements are set to the
1493 int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, char **name_pointer)
1498 static char abbrev[32], phone[256], name[256];
1499 unsigned int line,i;
1501 int found = 0, found_if_more_digits = 0;
1503 SPRINT(filename, "%s/%s/%s/phonebook", INSTALL_DATA, options.extensions_dir, number);
1505 if (!(fp = fopen(filename, "r")))
1507 PERROR("Cannot open phonebook: \"%s\"\n", filename);
1512 while((fgets(buffer, sizeof(buffer), fp)))
1515 buffer[sizeof(buffer)-1] = '\0';
1516 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1519 while(*p <= 32) /* skip spaces */
1525 if (*p==0 || *p=='#') /* ignore comments and empty line */
1532 i=0; /* read abbrev */
1535 if (i+1 >= sizeof(abbrev))
1537 PERROR_RUNTIME("Error in %s (line %d): abbrev too long.\n",filename,line);
1544 while(*p <= 32) /* skip spaces */
1551 if (*p!=0 && *p!='#') /* phone */
1553 i=0; /* read phone */
1556 if (i+1 >= sizeof(phone))
1558 PERROR_RUNTIME("Error in %s (line %d): phone too long.\n",filename,line);
1564 while(*p <= 32) /* skip spaces */
1572 if (*p!=0 && *p!='#') /* name */
1574 i=0; /* read name */
1577 if (i+1 >= sizeof(name))
1579 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1587 if (*abbrev_pointer)
1589 if (!strncmp(*abbrev_pointer, abbrev, strlen(*abbrev_pointer)))
1591 /* may match if abbreviation is longer */
1592 found_if_more_digits = 1;
1594 if (!!strcasecmp(*abbrev_pointer, abbrev))
1598 if (!!strcasecmp(*phone_pointer, phone))
1601 if (!!strcasecmp(*name_pointer, name))
1605 break; /* found entry */
1612 *abbrev_pointer = abbrev;
1613 *phone_pointer = phone;
1614 *name_pointer = name;
1619 if (found_if_more_digits)
1625 /* parsing secrets file
1627 * 'number' specifies the externsion number, not the caller id
1628 * 'remote_id' specifies the dialed number, or the caller id for incoming calls
1629 * the result is the auth, crypt and key string, and 1 is returned.
1630 * on failure or not matching number, the 0 is returned
1632 int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **crypt_pointer, char **key_pointer)
1638 static char auth[64], crypt[64], key[4096];
1639 unsigned int line,i;
1643 SPRINT(filename, "%s/%s/%s/secrets", INSTALL_DATA, options.extensions_dir, number);
1645 if (!(fp = fopen(filename, "r")))
1647 PERROR("Cannot open secrets: \"%s\"\n", filename);
1652 while((fgets(buffer, sizeof(buffer), fp)))
1655 buffer[sizeof(buffer)-1] = '\0';
1656 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1659 while(*p <= 32) /* skip spaces */
1665 if (*p==0 || *p=='#') /* ignore comments and empty line */
1673 i=0; /* read auth */
1676 if (i+1 >= sizeof(remote))
1678 PERROR_RUNTIME("Error in %s (line %d): remote too long.\n",filename,line);
1685 while(*p <= 32) /* skip spaces */
1692 if (*p!=0 && *p!='#') /* auth */
1694 i=0; /* read auth */
1697 if (i+1 >= sizeof(auth))
1699 PERROR_RUNTIME("Error in %s (line %d): auth too long.\n",filename,line);
1705 while(*p <= 32) /* skip spaces */
1713 if (*p!=0 && *p!='#') /* crypt */
1715 i=0; /* read crypt */
1718 if (i+1 >= sizeof(crypt))
1720 PERROR_RUNTIME("Error in %s (line %d): crypt too long.\n",filename,line);
1726 while(*p <= 32) /* skip spaces */
1734 if (*p!=0 && *p!='#') /* key */
1739 if (i+1 >= sizeof(key))
1741 PERROR_RUNTIME("Error in %s (line %d): key too long.\n",filename,line);
1748 //printf("COMPARING: '%s' with '%s' %s %s %s\n", remote_id, remote, auth, crypt, key);
1750 if (!!strcasecmp(remote, remote_id))
1754 break; /* found entry */
1761 *auth_pointer = auth;
1762 *crypt_pointer = crypt;
1771 * the caller id is given and the name is returned. if the name is not found,
1773 * on success a 1 is returned and the pointers of elements are set to the
1776 char *parse_directory(char *number, int type)
1781 static char phone[32], name[64];
1782 unsigned int line,i;
1786 SPRINT(filename, "%s/directory.list", INSTALL_DATA);
1788 if (!(fp = fopen(filename, "r")))
1790 PERROR("Cannot open directory: \"%s\"\n", filename);
1795 while((fgets(buffer, sizeof(buffer), fp)))
1798 buffer[sizeof(buffer)-1] = '\0';
1799 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1802 while(*p <= 32) /* skip spaces */
1808 if (*p==0 || *p=='#') /* ignore comments and empty line */
1814 i=0; /* read number */
1817 if (i+1 >= sizeof(phone))
1819 PERROR_RUNTIME("Error in %s (line %d): number too long.\n",filename,line);
1826 while(*p <= 32) /* skip spaces */
1833 i=0; /* read name */
1836 if (i+1 >= sizeof(name))
1838 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1845 if (phone[0] == 'i')
1847 if (type != INFO_NTYPE_INTERNATIONAL)
1849 if (!strcmp(number, phone+1))
1856 if (phone[0] == 'n')
1858 if (type != INFO_NTYPE_NATIONAL)
1860 if (!strcmp(number, phone+1))
1867 if (phone[0] == 's')
1869 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1871 if (!strcmp(number, phone+1))
1878 if (!strncmp(phone, options.international, strlen(options.international)))
1880 if (type != INFO_NTYPE_INTERNATIONAL)
1882 if (!strcmp(number, phone+strlen(options.international)))
1889 if (!options.national[0]) /* no national prefix */
1891 if (type == INFO_NTYPE_INTERNATIONAL)
1893 if (!strcmp(number, phone))
1900 if (!strncmp(phone, options.national, strlen(options.national)))
1902 if (type != INFO_NTYPE_NATIONAL)
1904 if (!strcmp(number, phone+strlen(options.national)))
1911 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1913 if (!strcmp(number, phone))
1928 /* parse callbackauth
1930 * searches for the given caller id and returns 1 == true or 0 == false
1932 int parse_callbackauth(char *number, struct caller_info *callerinfo)
1937 unsigned int line,i;
1939 static char caller_type[32], caller_id[64];
1942 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
1944 if (!(fp = fopen(filename, "r")))
1946 PDEBUG(DEBUG_EPOINT, "Cannot open callbackauth: \"%s\"\n", filename);
1951 while((fgets(buffer, sizeof(buffer), fp)))
1954 buffer[sizeof(buffer)-1] = '\0';
1955 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1958 while(*p <= 32) /* skip spaces */
1964 if (*p==0 || *p=='#') /* ignore comments and empty line */
1970 i=0; /* read caller_type */
1973 if (i+1 >= sizeof(caller_type))
1975 PERROR_RUNTIME("Error in %s (line %d): caller_type too long.\n",filename,line);
1978 caller_type[i+1] = '\0';
1979 caller_type[i++] = *p++;
1982 while(*p <= 32) /* skip spaces */
1989 if (*p!=0 && *p!='#') /* caller_id */
1991 i=0; /* read caller_id */
1994 if (i+1 >= sizeof(caller_id))
1996 PERROR_RUNTIME("Error in %s (line %d): caller_id too long.\n",filename,line);
1999 caller_id[i+1] = '\0';
2000 caller_id[i++] = *p++;
2005 if (caller_type[0]=='\0' && caller_id[0]=='\0')
2008 if (atoi(caller_type) != callerinfo->ntype)
2011 if (!!strcmp(caller_id, callerinfo->id))
2015 break; /* found entry */
2026 /* append line to callbackauth
2029 void append_callbackauth(char *number, struct caller_info *callerinfo)
2034 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
2036 if (callerinfo->id[0]=='\0')
2038 PERROR("caller has no id.\n");
2041 if (!(fp = fopen(filename, "a")))
2043 PERROR("Cannot open callbackauth: \"%s\"\n", filename);
2047 fprintf(fp, "%6d %s\n", callerinfo->ntype, callerinfo->id);