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 */
68 ext->vbox_codec = CODEC_MONO;
71 while((fgets(buffer, sizeof(buffer), fp)))
74 buffer[sizeof(buffer)-1] = '\0';
75 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
78 while(*p <= 32) /* skip spaces */
84 if (*p==0 || *p=='#') /* ignore comments and empty line */
88 i=0; /* read option */
91 if (i+1 >= sizeof(option))
93 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
100 while(*p <= 32) /* skip spaces */
109 if (*p!=0 && *p!='#') /* param */
111 i=0; /* read param */
114 if (i+1 >= sizeof(param))
116 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
123 while(*p <= 32) /* skip spaces */
130 if (*p!=0 && *p!='#') /* param2 */
132 i=0; /* read param2 */
135 if (i+1 >= sizeof(param2))
137 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
146 /* at this point we have option and param */
149 if (!strcmp(option,"name"))
151 SCPY(ext->name, param);
154 SCAT(ext->name, " ");
155 SCAT(ext->name, param2);
158 PDEBUG(DEBUG_CONFIG, "name of extension: %s\n",param);
160 if (!strcmp(option,"prefix"))
162 SCPY(ext->prefix, param);
164 PDEBUG(DEBUG_CONFIG, "dial prefix on pickup: %s\n",param);
166 if (!strcmp(option,"next"))
168 SCPY(ext->next, param);
170 PDEBUG(DEBUG_CONFIG, "dial next on pickup: %s\n",param);
172 if (!strcmp(option,"alarm"))
174 SCPY(ext->alarm, param);
176 PDEBUG(DEBUG_CONFIG, "alarm message (if prefix): %s\n",param);
178 if (!strcmp(option,"cfu"))
180 SCPY(ext->cfu, param);
182 PDEBUG(DEBUG_CONFIG, "call forward unconditional: %s\n",param);
184 if (!strcmp(option,"cfb"))
186 SCPY(ext->cfb, param);
188 PDEBUG(DEBUG_CONFIG, "call forward when busy: %s\n",param);
190 if (!strcmp(option,"cfnr"))
192 SCPY(ext->cfnr, param);
194 PDEBUG(DEBUG_CONFIG, "call forward on no response: %s\n",param);
196 if (!strcmp(option,"cfnr_delay"))
198 ext->cfnr_delay = atoi(param);
199 if (ext->cfnr_delay < 0)
202 PDEBUG(DEBUG_CONFIG, "call forward no response delay: %d\n",ext->cfnr_delay);
204 if (!strcmp(option,"cfp"))
206 SCPY(ext->cfp, param);
208 PDEBUG(DEBUG_CONFIG, "call forward parallel: %s\n",param);
210 if (!strcmp(option,"change_forward"))
215 if (!strcasecmp(param,ext_yesno[i]))
221 ext->change_forward = i;
222 PDEBUG(DEBUG_CONFIG, "allow the change of forwarding: %s\n", ext_yesno[i]);
225 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_forward: %s\n", param);
228 if (!strcmp(option,"interfaces"))
230 SCPY(ext->interfaces, param);
232 PDEBUG(DEBUG_CONFIG, "interfaces to ring calls to extension: %s %s\n",param,param2);
234 if (!strcmp(option,"callerid"))
236 ext->callerid_present = INFO_PRESENT_ALLOWED;
237 if (!strncasecmp(param2, "anonymous", 9))
238 ext->callerid_present = INFO_PRESENT_RESTRICTED;
239 if (!strncasecmp(param, "non", 3))
241 ext->callerid[0] = '\0';
242 ext->callerid_present = INFO_PRESENT_NOTAVAIL;
243 ext->callerid_type = INFO_NTYPE_UNKNOWN;
244 PDEBUG(DEBUG_CONFIG, "caller id: ID NOT AVAILABLE\n");
250 ext->callerid_type = INFO_NTYPE_INTERNATIONAL;
251 SCPY(ext->callerid, param+1);
252 PDEBUG(DEBUG_CONFIG, "caller id: %s INTERNATIONAL\n",param+1);
256 ext->callerid_type = INFO_NTYPE_NATIONAL;
257 SCPY(ext->callerid, param+1);
258 PDEBUG(DEBUG_CONFIG, "caller id: %s NATIONAL\n",param+1);
262 ext->callerid_type = INFO_NTYPE_SUBSCRIBER;
263 SCPY(ext->callerid, param+1);
264 PDEBUG(DEBUG_CONFIG, "caller id: %s SUBSCRIBER\n",param+1);
267 ext->callerid_type = INFO_NTYPE_UNKNOWN;
268 SCPY(ext->callerid, param);
269 PDEBUG(DEBUG_CONFIG, "caller id: %s UNKNOWN\n",param);
271 ext->callerid[sizeof(ext->callerid)-1] = 0;
273 if (!strcmp(option,"id_next_call"))
275 ext->id_next_call_present = INFO_PRESENT_ALLOWED;
276 if (!strncasecmp(param2, "anonymous", 9))
277 ext->id_next_call_present = INFO_PRESENT_RESTRICTED;
278 if (param[0] == '\0')
280 ext->id_next_call_present = -1;
281 PDEBUG(DEBUG_CONFIG, "id next call: no id for next call\n");
283 if (!strncasecmp(param, "none", 3))
285 ext->id_next_call[0] = '\0';
286 ext->id_next_call_present = INFO_PRESENT_NOTAVAIL;
287 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
288 PDEBUG(DEBUG_CONFIG, "id next call: ID NOT AVAILABLE\n");
294 ext->id_next_call_type = INFO_NTYPE_INTERNATIONAL;
295 SCPY(ext->id_next_call, param+1);
296 PDEBUG(DEBUG_CONFIG, "id next call: %s INTERNATIONAL\n",param+1);
300 ext->id_next_call_type = INFO_NTYPE_NATIONAL;
301 SCPY(ext->id_next_call, param+1);
302 PDEBUG(DEBUG_CONFIG, "id next call: %s NATIONAL\n",param+1);
306 ext->id_next_call_type = INFO_NTYPE_SUBSCRIBER;
307 SCPY(ext->id_next_call, param+1);
308 PDEBUG(DEBUG_CONFIG, "id next call: %s SUBSCRIBER\n",param+1);
311 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
312 SCPY(ext->id_next_call, param);
313 PDEBUG(DEBUG_CONFIG, "id next call: %s UNKNOWN\n",param);
319 if (!strcmp(option,"change_callerid"))
324 if (!strcasecmp(param,ext_yesno[i]))
330 ext->change_callerid = i;
331 PDEBUG(DEBUG_CONFIG, "allow the change of caller id: %s\n", ext_yesno[i]);
334 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_callerid: %s\n", param);
337 if (!strcmp(option,"anon-ignore"))
342 if (!strcasecmp(param,ext_yesno[i]))
348 ext->anon_ignore = i;
349 PDEBUG(DEBUG_CONFIG, "ignore restriction of CLIP & COLP %s\n", ext_yesno[i]);
352 PDEBUG(DEBUG_CONFIG, "unknown parameter given anon-ignore: %s\n", param);
355 if (!strcmp(option,"clip"))
357 if (!strcasecmp(param, "hide"))
358 ext->clip = CLIP_HIDE;
360 ext->clip = CLIP_ASIS;
362 PDEBUG(DEBUG_CONFIG, "clip: %d\n",ext->clip);
364 if (!strcmp(option,"colp"))
366 if (!strcasecmp(param, "hide"))
367 ext->colp = COLP_HIDE;
368 else if (!strcasecmp(param, "force"))
369 ext->colp = COLP_FORCE;
371 ext->colp = COLP_ASIS;
373 PDEBUG(DEBUG_CONFIG, "colp: %d\n",ext->colp);
375 if (!strcmp(option,"clip_prefix"))
377 SCPY(ext->clip_prefix, param);
379 PDEBUG(DEBUG_CONFIG, "clip prefix: %s\n",param);
381 if (!strcmp(option,"keypad"))
386 if (!strcasecmp(param,ext_yesno[i]))
393 PDEBUG(DEBUG_CONFIG, "use keypad to do call control %s\n", ext_yesno[i]);
396 PDEBUG(DEBUG_CONFIG, "unknown parameter given keypad: %s\n", param);
399 if (!strcmp(option,"rights"))
404 if (!strcasecmp(param,ext_rights[i]))
411 PDEBUG(DEBUG_CONFIG, "rights to dial: %s\n", ext_rights[i]);
414 PDEBUG(DEBUG_CONFIG, "given rights unknown: %s\n", param);
417 if (!strcmp(option,"delete_ext"))
422 if (!strcasecmp(param,ext_yesno[i]))
429 PDEBUG(DEBUG_CONFIG, "enables the delete key function for external calls: %s\n", ext_yesno[i]);
432 PDEBUG(DEBUG_CONFIG, "unknown parameter given delete: %s\n", param);
435 if (!strcmp(option,"noknocking"))
440 if (!strcasecmp(param,ext_yesno[i]))
447 PDEBUG(DEBUG_CONFIG, "noknocking %s\n", ext_yesno[i]);
450 PDEBUG(DEBUG_CONFIG, "given noknocking param unknown: %s\n", param);
453 if (!strcmp(option,"rx_gain")
454 || !strcmp(option,"rxvol"))
456 ext->rx_gain = atoi(param);
457 if (ext->rx_gain<-8 || ext->rx_gain>8)
460 PDEBUG(DEBUG_CONFIG, "receive volume: %d\n",ext->rx_gain);
462 if (!strcmp(option,"tx_gain")
463 || !strcmp(option,"txvol"))
465 ext->tx_gain = atoi(param);
466 if (ext->tx_gain<-8 || ext->tx_gain>8)
469 PDEBUG(DEBUG_CONFIG, "transmit volume: %d\n",ext->tx_gain);
471 if (!strcmp(option,"own_setup"))
476 if (!strcasecmp(param,ext_yesno[i]))
483 PDEBUG(DEBUG_CONFIG, "own_setup %s\n", ext_yesno[i]);
486 PDEBUG(DEBUG_CONFIG, "given own_setup param unknown: %s\n", param);
489 if (!strcmp(option,"own_proceeding"))
494 if (!strcasecmp(param,ext_yesno[i]))
500 ext->own_proceeding = i;
501 PDEBUG(DEBUG_CONFIG, "own_proceeding %s\n", ext_yesno[i]);
504 PDEBUG(DEBUG_CONFIG, "given own_proceeding param unknown: %s\n", param);
507 if (!strcmp(option,"own_alerting"))
512 if (!strcasecmp(param,ext_yesno[i]))
518 ext->own_alerting = i;
519 PDEBUG(DEBUG_CONFIG, "own_alerting %s\n", ext_yesno[i]);
522 PDEBUG(DEBUG_CONFIG, "given own_alerting param unknown: %s\n", param);
525 if (!strcmp(option,"own_cause"))
530 if (!strcasecmp(param,ext_yesno[i]))
537 PDEBUG(DEBUG_CONFIG, "own_cause %s\n", ext_yesno[i]);
540 PDEBUG(DEBUG_CONFIG, "given own_cause param unknown: %s\n", param);
543 if (!strcmp(option,"facility"))
548 if (!strcasecmp(param,ext_yesno[i]))
555 PDEBUG(DEBUG_CONFIG, "facility %s\n", ext_yesno[i]);
558 PDEBUG(DEBUG_CONFIG, "given facility param unknown: %s\n", param);
561 if (!strcmp(option,"display_cause"))
563 if (!strcasecmp(param, "german"))
564 ext->display_cause = DISPLAY_CAUSE_GERMAN;
565 else if (!strcasecmp(param, "english"))
566 ext->display_cause = DISPLAY_CAUSE_ENGLISH;
567 else if (!strcasecmp(param, "german-location"))
568 ext->display_cause = DISPLAY_LOCATION_GERMAN;
569 else if (!strcasecmp(param, "english-location"))
570 ext->display_cause = DISPLAY_LOCATION_ENGLISH;
571 else if (!strcasecmp(param, "number"))
572 ext->display_cause = DISPLAY_CAUSE_NUMBER;
574 ext->display_cause = DISPLAY_CAUSE_NONE;
576 PDEBUG(DEBUG_CONFIG, "display cause: %d\n",ext->display_cause);
579 if (!strcmp(option,"display_ext"))
581 if (!strcasecmp(param, "number"))
582 ext->display_ext = DISPLAY_CID_NUMBER;
583 else if (!strcasecmp(param, "abbrev"))
584 ext->display_ext = DISPLAY_CID_ABBREVIATION;
585 else if (!strcasecmp(param, "name"))
586 ext->display_ext = DISPLAY_CID_NAME;
587 else if (!strcasecmp(param, "number-name"))
588 ext->display_ext = DISPLAY_CID_NUMBER_NAME;
589 else if (!strcasecmp(param, "name-number"))
590 ext->display_ext = DISPLAY_CID_NAME_NUMBER;
591 else if (!strcasecmp(param, "abbrev-number"))
592 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER;
593 else if (!strcasecmp(param, "abbrev-name"))
594 ext->display_ext = DISPLAY_CID_ABBREV_NAME;
595 else if (!strcasecmp(param, "abbrev-name-number"))
596 ext->display_ext = DISPLAY_CID_ABBREV_NAME_NUMBER;
597 else if (!strcasecmp(param, "abbrev-number-name"))
598 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER_NAME;
600 ext->display_ext = DISPLAY_CID_ASIS;
602 PDEBUG(DEBUG_CONFIG, "display ext: %d\n",ext->display_ext);
605 if (!strcmp(option,"display_ext"))
610 if (!strcasecmp(param,ext_yesno[i]))
616 ext->display_ext = i;
617 PDEBUG(DEBUG_CONFIG, "display ext %s\n", ext_yesno[i]);
620 PDEBUG(DEBUG_CONFIG, "given display_ext param unknown: %s\n", param);
623 if (!strcmp(option,"display_int"))
628 if (!strcasecmp(param,ext_yesno[i]))
634 ext->display_int = i;
635 PDEBUG(DEBUG_CONFIG, "display int %s\n", ext_yesno[i]);
638 PDEBUG(DEBUG_CONFIG, "given display_int param unknown: %s\n", param);
641 if (!strcmp(option,"display_fake"))
646 if (!strcasecmp(param,ext_yesno[i]))
652 ext->display_fake = i;
653 PDEBUG(DEBUG_CONFIG, "display fake caller ids %s\n", ext_yesno[i]);
656 PDEBUG(DEBUG_CONFIG, "given display_fake param unknown: %s\n", param);
659 if (!strcmp(option,"display_anon"))
664 if (!strcasecmp(param,ext_yesno[i]))
670 ext->display_anon = i;
671 PDEBUG(DEBUG_CONFIG, "display anonymouse ids %s\n", ext_yesno[i]);
674 PDEBUG(DEBUG_CONFIG, "given display_anon param unknown: %s\n", param);
677 if (!strcmp(option,"display_menu"))
682 if (!strcasecmp(param,ext_yesno[i]))
688 ext->display_menu = i;
689 PDEBUG(DEBUG_CONFIG, "display menu %s\n", ext_yesno[i]);
692 PDEBUG(DEBUG_CONFIG, "given display_menu param unknown: %s\n", param);
695 if (!strcmp(option,"display_dialing"))
700 if (!strcasecmp(param,ext_yesno[i]))
706 ext->display_dialing = i;
707 PDEBUG(DEBUG_CONFIG, "display dialing %s\n", ext_yesno[i]);
710 PDEBUG(DEBUG_CONFIG, "given display_dialing param unknown: %s\n", param);
713 if (!strcmp(option,"display_name"))
718 if (!strcasecmp(param,ext_yesno[i]))
724 ext->display_name = i;
725 PDEBUG(DEBUG_CONFIG, "display name %s\n", ext_yesno[i]);
728 PDEBUG(DEBUG_CONFIG, "given display_name param unknown: %s\n", param);
731 if (!strcmp(option,"tones_dir"))
733 if (param[strlen(param)-1] == '/')
734 param[strlen(param)-1]=0;
735 SCPY(ext->tones_dir, param);
737 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
739 if (!strcmp(option,"record"))
741 if (!strcasecmp(param, "mono"))
742 ext->record = CODEC_MONO;
743 else if (!strcasecmp(param, "stereo"))
744 ext->record = CODEC_STEREO;
745 else if (!strcasecmp(param, "8bit"))
746 ext->record = CODEC_8BIT;
747 else if (!strcasecmp(param, "law"))
748 ext->record = CODEC_LAW;
750 ext->record = CODEC_OFF;
751 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
753 if (!strcmp(option,"password"))
755 SCPY(ext->password, param);
757 PDEBUG(DEBUG_CONFIG, "password: %s\n",param);
759 if (!strcmp(option,"vbox_mode"))
761 if (!strcasecmp(param, "parallel"))
762 ext->vbox_mode = VBOX_MODE_PARALLEL;
763 else if (!strcasecmp(param, "announcement"))
764 ext->vbox_mode = VBOX_MODE_ANNOUNCEMENT;
766 ext->vbox_mode = VBOX_MODE_NORMAL;
767 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
769 if (!strcmp(option,"vbox_codec"))
771 if (!strcasecmp(param, "stereo"))
772 ext->vbox_codec = CODEC_STEREO;
773 else if (!strcasecmp(param, "8bit"))
774 ext->vbox_codec = CODEC_8BIT;
775 else if (!strcasecmp(param, "law"))
776 ext->vbox_codec = CODEC_LAW;
778 ext->vbox_codec = CODEC_MONO;
779 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
781 if (!strcmp(option,"vbox_time"))
783 ext->vbox_time = atoi(param);
784 if (ext->vbox_time < 0)
787 PDEBUG(DEBUG_CONFIG, "vbox time to record: %d\n",ext->vbox_time);
789 if (!strcmp(option,"vbox_display"))
791 if (!strcasecmp(param, "detailed")
792 || !strcasecmp(param, "detailled"))
793 ext->vbox_display = VBOX_DISPLAY_DETAILED;
794 else if (!strcasecmp(param, "off"))
795 ext->vbox_display = VBOX_DISPLAY_OFF;
797 ext->vbox_display = VBOX_DISPLAY_BRIEF;
798 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
800 if (!strcmp(option,"vbox_language"))
802 if (!strcasecmp(param, "german"))
803 ext->vbox_language = VBOX_LANGUAGE_GERMAN;
805 ext->vbox_language = VBOX_LANGUAGE_ENGLISH;
806 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
808 if (!strcmp(option,"vbox_email"))
810 SCPY(ext->vbox_email, param);
811 PDEBUG(DEBUG_CONFIG, "given vbox email: %s\n", param);
813 if (!strcmp(option,"vbox_email_file"))
818 if (!strcasecmp(param,ext_yesno[i]))
824 ext->vbox_email_file = i;
825 PDEBUG(DEBUG_CONFIG, "attach audio file %s\n", ext_yesno[i]);
828 PDEBUG(DEBUG_CONFIG, "given vbox_email_file param unknown: %s\n", param);
831 if (!strcmp(option,"vbox_free"))
836 if (!strcasecmp(param,ext_yesno[i]))
843 PDEBUG(DEBUG_CONFIG, "vbox_free %s\n", ext_yesno[i]);
846 PDEBUG(DEBUG_CONFIG, "given vbox_free param unknown: %s\n", param);
849 if (!strcmp(option,"last_in"))
851 if (param[0] && last_in_count<MAX_REMEMBER)
853 SCPY(ext->last_in[last_in_count], param);
856 PDEBUG(DEBUG_CONFIG, "last_in dialed number: %s\n",param);
858 if (!strcmp(option,"last_out"))
860 if (param[0] && last_out_count<MAX_REMEMBER)
862 SCPY(ext->last_out[last_out_count], param);
865 PDEBUG(DEBUG_CONFIG, "last_out dialed number: %s\n",param);
867 if (!strcmp(option,"datacall"))
872 if (!strcasecmp(param,ext_yesno[i]))
879 PDEBUG(DEBUG_CONFIG, "datacall %s\n", ext_yesno[i]);
882 PDEBUG(DEBUG_CONFIG, "given datacall param unknown: %s\n", param);
885 if (!strcmp(option,"seconds"))
890 if (!strcasecmp(param,ext_yesno[i]))
896 ext->no_seconds = 1-i;
897 PDEBUG(DEBUG_CONFIG, "seconds %s\n", ext_yesno[i]);
900 PDEBUG(DEBUG_CONFIG, "unknown param for seconds: %s\n", param);
904 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n",filename,line,option);
915 * writes extension for given extension number from structure
917 int write_extension(struct extension *ext, char *number)
923 if (number[0] == '\0')
926 SPRINT(filename, "%s/%s/%s/settings", INSTALL_DATA, options.extensions_dir, number);
928 if (!(fp = fopen(filename, "w")))
930 PERROR("Cannot open settings: \"%s\"\n", filename);
934 fprintf(fp,"# Settings of extension %s\n\n", number);
936 fprintf(fp,"# Name of extension:\n");
937 fprintf(fp,"name %s\n\n",ext->name);
939 fprintf(fp,"# Predialed prefix after pick-up of the phone\n");
940 fprintf(fp,"prefix %s\n\n",ext->prefix);
942 fprintf(fp,"# Next prefix to dial pick-up of the phone\n");
943 fprintf(fp,"# This will be cleared on hangup.\n");
944 fprintf(fp,"next %s\n\n",ext->next);
946 // fprintf(fp,"# Set up alarm message after prefix is dialed and connection is established\n");
947 // fprintf(fp,"alarm %s\n\n",ext->alarm);
949 fprintf(fp,"# Interface(s) to ring on calls to extension (as named in interface.conf)\n");
950 fprintf(fp,"# Seperate multiple interfaces by using komma without spaces\n");
951 fprintf(fp,"# Example: Int would ring on the interface with the name \"Int\"");
952 fprintf(fp,"# Int1,Int2 would ring incoming calls on both interfaces Int1 and Int2.\n");
953 fprintf(fp,"interfaces %s\n\n",ext->interfaces);
955 fprintf(fp,"# Call Forward Unconditional (CFU)\n");
956 fprintf(fp,"# No port will be called, CFB, CFNR and CFP is ignored.\n");
957 fprintf(fp,"# Use keyword \"vbox\" to forward call directly to answering machine.\n");
958 fprintf(fp,"cfu %s\n\n",ext->cfu);
960 fprintf(fp,"# Call Forward when Busy (CFB)\n");
961 fprintf(fp,"# If the extension is in use at least once, this forward is done.\n");
962 fprintf(fp,"# In case of busy line, CFNR and CFP is ignored.\n");
963 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine when busy.\n");
964 fprintf(fp,"cfb %s\n\n",ext->cfb);
966 fprintf(fp,"# Call Forward on No Response (CFNR)\n");
967 fprintf(fp,"# If noone answers, the call is forwarded, ports and CFP will be released.\n");
968 fprintf(fp,"# The default delay is 20 seconds.\n");
969 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine on no response.\n");
970 fprintf(fp,"cfnr %s\n",ext->cfnr);
971 fprintf(fp,"cfnr_delay %d\n\n",ext->cfnr_delay);
973 fprintf(fp,"# Call Forward Parallel (CFP)\n");
974 fprintf(fp,"# Call will ring on the forwarded number, simulaniousely with the ports.\n");
975 fprintf(fp,"cfp %s\n\n",ext->cfp);
977 fprintf(fp,"# Allow user to change call forwarding.\n");
978 fprintf(fp,"change_forward %s\n\n", ext_yesno[ext->change_forward]);
980 fprintf(fp,"# Caller id\n# This must be one of the following:\n");
981 fprintf(fp,"# <number> (as dialed from your local area)\n");
982 fprintf(fp,"# <number> anonymous (will only be shown to emergency phones)\n");
983 fprintf(fp,"# none (no number available at all)\n");
984 fprintf(fp,"# by default the number is of type UNKNOWN (for MULTIPOINT lines)\n");
985 fprintf(fp,"# if your caller id is not screened on outgoing calls use one of the following:\n");
986 fprintf(fp,"# use prefix 'i' for TYPE INTERNATIONAL (i<county code><areacode+number>)\n");
987 fprintf(fp,"# use prefix 'n' for TYPE NATIONAL (n<areacode+number>)\n");
988 fprintf(fp,"# use prefix 's' for TYPE SUBSCRIBER (s<local number>)\n");
989 if (ext->callerid_present == INFO_PRESENT_NOTAVAIL)
990 fprintf(fp,"callerid none\n\n");
993 switch(ext->callerid_type)
995 case INFO_NTYPE_INTERNATIONAL:
996 fprintf(fp,"callerid i%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
998 case INFO_NTYPE_NATIONAL:
999 fprintf(fp,"callerid n%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1001 case INFO_NTYPE_SUBSCRIBER:
1002 fprintf(fp,"callerid s%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1005 fprintf(fp,"callerid %s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1009 fprintf(fp,"# Caller id for next call (see caller id)\n");
1010 if (ext->id_next_call_present < 0)
1011 fprintf(fp,"id_next_call \n\n");
1012 else if (ext->id_next_call_present == INFO_PRESENT_NOTAVAIL)
1013 fprintf(fp,"id_next_call none\n\n");
1016 switch(ext->id_next_call_type)
1018 case INFO_NTYPE_INTERNATIONAL:
1019 fprintf(fp,"id_next_call i%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1021 case INFO_NTYPE_NATIONAL:
1022 fprintf(fp,"id_next_call n%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1024 case INFO_NTYPE_SUBSCRIBER:
1025 fprintf(fp,"id_next_call s%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1028 fprintf(fp,"id_next_call %s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1032 fprintf(fp,"# Allow user to change caller ID.\n");
1033 fprintf(fp,"change_callerid %s\n\n", ext_yesno[ext->change_callerid]);
1035 fprintf(fp,"# Caller Line Identification Presentation (CLIP)\n");
1036 fprintf(fp,"# clip (asis|hide)\n");
1037 fprintf(fp,"# asis: On forwarded calls the CLIP is used as presented by the calling party.\n");
1038 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1042 fprintf(fp,"clip hide\n\n");
1045 fprintf(fp,"clip asis\n\n");
1048 fprintf(fp,"# Connected Line Identification Presentation (COLP)\n");
1049 fprintf(fp,"# colp (asis|hide|force)\n");
1050 fprintf(fp,"# asis: Provides colp as defined by the extension's caller id.\n");
1051 fprintf(fp,"# On forwarded calls the COLP is used as presented by the called party.\n");
1052 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1053 fprintf(fp,"# force: If COLP is not presented by forwarded calls the dialed number is used.\n");
1057 fprintf(fp,"colp hide\n\n");
1060 fprintf(fp,"colp force\n\n");
1063 fprintf(fp,"colp asis\n\n");
1066 fprintf(fp,"# CLIP Prefix\n");
1067 fprintf(fp,"# Adds a prefix to incoming caller IDs, so telephones will be able to respond\n");
1068 fprintf(fp,"# to unanswered calls from their list. The prefix must be the digit(s) to get\n");
1069 fprintf(fp,"# an external line. The caller ID will then be extendet so that they can be\n");
1070 fprintf(fp,"# dialed from internal telephones. Many telephones have this feature, but some\n");
1071 fprintf(fp,"# don't.\n");
1072 fprintf(fp,"clip_prefix %s\n\n",ext->clip_prefix);
1074 fprintf(fp,"# Keypad control\n");
1075 fprintf(fp,"# If supported by telephone, pressing a key on the keypad will not result in\n");
1076 fprintf(fp,"# DTMF tone, but the digit is transmitted via D-channel diaing info.\n");
1077 fprintf(fp,"keypad %s\n\n",(ext->keypad)?"yes":"no");
1079 fprintf(fp,"# Ignore restriction of COLP and CLIP\n");
1080 fprintf(fp,"# In this case even restricted numbers are presented to this extension.\n");
1081 fprintf(fp,"# This also works for incoming external anonymous calls IF:\n");
1082 fprintf(fp,"# You have the CLIRIGN feature like POLICE or equivalent.\n");
1083 fprintf(fp,"anon-ignore %s\n\n",(ext->anon_ignore)?"yes":"no");
1085 fprintf(fp,"# Dialing rights (none|internal|local|national|international)\n");
1086 fprintf(fp,"rights %s\n\n",ext_rights[ext->rights]);
1088 fprintf(fp,"# Delete function for external calls. '*' will delete the last digit, '#' will\n");
1089 fprintf(fp,"# delete the complete number. Also enable 'display_dialing' to see on the\n");
1090 fprintf(fp,"# display what actually happens.\n");
1091 fprintf(fp,"delete_ext %s\n\n",ext_yesno[ext->delete_ext]);
1093 fprintf(fp,"# If noknocking is enabled, the caller will get a busy message when the\n");
1094 fprintf(fp,"# extension is doing at least one call.\n");
1095 fprintf(fp,"noknocking %s\n\n",ext_yesno[ext->noknocking]);
1097 fprintf(fp,"# Transmit volume (-8 .. 8)\n");
1098 fprintf(fp,"# 0 = normal\n");
1099 fprintf(fp,"# 1 = double, 2 = quadrupel, 8 = 256 times (amplitude)\n");
1100 fprintf(fp,"# -1 = half, -2 = quarter, 8 = 1/256th (amplitude)\n");
1101 fprintf(fp,"# Audio data is limited to the maximum value when exceeds limit.\n");
1102 fprintf(fp,"tx_gain %d\n\n",ext->tx_gain);
1104 fprintf(fp,"# Receive volume (-8 .. 8)\n");
1105 fprintf(fp,"# (see tx_gain)\n");
1106 fprintf(fp,"rx_gain %d\n\n",ext->rx_gain);
1109 fprintf(fp,"# Force to use tones and announcements generated by the pbx.\n");
1110 fprintf(fp,"# For internal calls always own tones are used. You may specify own tones for\n");
1111 fprintf(fp,"# different call states:\n");
1112 fprintf(fp,"# own_setup (dialtone and during dialing)\n");
1113 fprintf(fp,"# own_proceeding (call in poceeding state)\n");
1114 fprintf(fp,"# own_alerting (call is ringing)\n");
1115 fprintf(fp,"# own_cause (when the call gets disconnected or failed to be completed)\n");
1116 fprintf(fp,"own_setup %s\n",ext_yesno[ext->own_setup]);
1117 fprintf(fp,"own_proceeding %s\n",ext_yesno[ext->own_proceeding]);
1118 fprintf(fp,"own_alerting %s\n",ext_yesno[ext->own_alerting]);
1119 fprintf(fp,"own_cause %s\n\n",ext_yesno[ext->own_cause]);
1121 fprintf(fp,"# Allow facility information to be transfered to the telephone.\n");
1122 fprintf(fp,"# This is equired to receive advice of charge.\n");
1123 fprintf(fp,"facility %s\n\n",ext_yesno[ext->facility]);
1125 fprintf(fp,"# Display clear causes using display messages (Q.850)\n# This must be one of the following:\n");
1126 fprintf(fp,"# none (no displaying of clear causes)\n");
1127 fprintf(fp,"# english (display cause text in english)\n");
1128 fprintf(fp,"# german (display cause text in german)\n");
1129 fprintf(fp,"# number (display cause number only)\n");
1130 fprintf(fp,"# english-location (display cause text in english and location)\n");
1131 fprintf(fp,"# german-location (display cause text in german and location)\n");
1132 switch(ext->display_cause)
1134 case DISPLAY_CAUSE_ENGLISH:
1135 fprintf(fp,"display_cause english\n\n");
1137 case DISPLAY_CAUSE_GERMAN:
1138 fprintf(fp,"display_cause german\n\n");
1140 case DISPLAY_LOCATION_ENGLISH:
1141 fprintf(fp,"display_cause english-location\n\n");
1143 case DISPLAY_LOCATION_GERMAN:
1144 fprintf(fp,"display_cause german-location\n\n");
1146 case DISPLAY_CAUSE_NUMBER:
1147 fprintf(fp,"display_cause number\n\n");
1150 fprintf(fp,"display_cause none\n\n");
1153 fprintf(fp,"# Display external caller ids using display override (yes or no)\n");
1154 fprintf(fp,"# example: \"15551212\"\n");
1155 fprintf(fp,"display_ext %s\n\n",(ext->display_ext)?"yes":"no");
1157 fprintf(fp,"# Display internal caller ids using display override (yes or no)\n");
1158 fprintf(fp,"# example: \"200 (int)\"\n");
1159 fprintf(fp,"display_int %s\n\n",(ext->display_int)?"yes":"no");
1161 fprintf(fp,"# Display if calls are anonymous using display override (yes or no)\n");
1162 fprintf(fp,"# This makes only sense if the anon-ignore feature is enabled.\n");
1163 fprintf(fp,"# example: \"15551212 anon\"\n");
1164 fprintf(fp,"display_anon %s\n\n",(ext->display_anon)?"yes":"no");
1166 fprintf(fp,"# Display fake caller ids using display override (yes or no)\n");
1167 fprintf(fp,"# If the caller uses \"clip no screening\", you will see if the number is\n");
1168 fprintf(fp,"# real or fake\n");
1169 fprintf(fp,"# example: \"15551212 fake\"\n");
1170 fprintf(fp,"display_fake %s\n\n",(ext->display_fake)?"yes":"no");
1172 fprintf(fp,"# Display caller's name if available. (yes or no)\n");
1173 fprintf(fp,"# example: \"15551212 Axel\"\n");
1174 fprintf(fp,"display_name %s\n\n",(ext->display_name)?"yes":"no");
1176 fprintf(fp,"# Display menu when '*' and '#' is pressed. The menu shows all prefixes for\n");
1177 fprintf(fp,"# internal dialing by pressing '*' for previous prefix and '#' for next prefix.\n");
1178 fprintf(fp,"# Also the dialed prefix is show on display. (yes or no)\n");
1179 fprintf(fp,"display_menu %s\n\n",(ext->display_menu)?"yes":"no");
1181 fprintf(fp,"# Display digits as they are interpreted by pbx. (yes or no)\n");
1182 fprintf(fp,"display_dialing %s\n\n",(ext->display_dialing)?"yes":"no");
1184 fprintf(fp,"# Tones directory for announcements and patterns\n");
1185 fprintf(fp,"# Enter nothing for default tones as selected by options.conf.\n");
1186 fprintf(fp,"tones_dir %s\n\n",ext->tones_dir);
1188 fprintf(fp,"# Record calls to extension's directory. The file is written as wave.\n");
1189 fprintf(fp,"# This must be one of the following:\n");
1190 fprintf(fp,"# off (no recording)\n");
1191 fprintf(fp,"# mono (records wave 16 bit mono, 128kbits/s)\n");
1192 fprintf(fp,"# stereo (records wave 32 bit stereo, 256kbits/s)\n");
1193 fprintf(fp,"# 8bit (records wave 8 bit mono, 64kbits/s)\n");
1194 fprintf(fp,"# law (records xLaw encoded, as specified in options.conf, 64kbps/s)\n");
1198 fprintf(fp,"record mono\n\n");
1201 fprintf(fp,"record stereo\n\n");
1204 fprintf(fp,"record 8bit\n\n");
1207 fprintf(fp,"record law\n\n");
1210 fprintf(fp,"record off\n\n");
1213 fprintf(fp,"# Password for callback and login\n");
1214 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1215 fprintf(fp,"password %s\n\n",ext->password);
1217 fprintf(fp,"# The Answering Machine. Enter the mode of answering machine.\n");
1218 fprintf(fp,"# This must be one of the following:\n");
1219 fprintf(fp,"# normal (plays announcement and records after that)\n");
1220 fprintf(fp,"# parallel (plays announcement and records also DURING announcement.)\n");
1221 fprintf(fp,"# announcement (just plays announcement and hangs up)\n");
1222 switch(ext->vbox_mode)
1224 case VBOX_MODE_PARALLEL:
1225 fprintf(fp,"vbox_mode parallel\n\n");
1227 case VBOX_MODE_ANNOUNCEMENT:
1228 fprintf(fp,"vbox_mode announcement\n\n");
1231 fprintf(fp,"vbox_mode normal\n\n");
1234 fprintf(fp,"# The Answering Machine. Enter the type of codec for recording.\n");
1235 fprintf(fp,"# This must be one of the following:\n");
1236 fprintf(fp,"# law (alaw/ulas codec, as specified in options.conf)\n");
1237 fprintf(fp,"# mono (16 bit mono wave file)\n");
1238 fprintf(fp,"# stereo (16 bit stereo wave file)\n");
1239 fprintf(fp,"# 8bit (8 bit mono wave file)\n");
1240 switch(ext->vbox_codec)
1243 fprintf(fp,"vbox_codec law\n\n");
1246 fprintf(fp,"vbox_codec stereo\n\n");
1249 fprintf(fp,"vbox_codec 8bit\n\n");
1252 fprintf(fp,"vbox_codec mono\n\n");
1255 fprintf(fp,"# The Answering Machine. Enter maximum time to record after announcement.\n");
1256 fprintf(fp,"# Leave empty, enter \"infinite\" or give time in seconds.\n");
1257 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1259 fprintf(fp,"vbox_time %d\n\n",ext->vbox_time);
1261 fprintf(fp,"vbox_time infinite\n\n");
1263 fprintf(fp,"# The Answering Machine. Enter mode for display current state.\n");
1264 fprintf(fp,"# This must be one of the following:\n");
1265 fprintf(fp,"# brief (displays brief information, for small displays)\n");
1266 fprintf(fp,"# detailed (displays detailed information, for larger displays)\n");
1267 fprintf(fp,"# off (don't display anything)\n");
1268 switch(ext->vbox_display)
1270 case VBOX_DISPLAY_OFF:
1271 fprintf(fp,"vbox_display off\n\n");
1273 case VBOX_DISPLAY_DETAILED:
1274 fprintf(fp,"vbox_display detailed\n\n");
1277 fprintf(fp,"vbox_display brief\n\n");
1280 fprintf(fp,"# The Answering Machine. Enter type of language: \"english\" or \"german\"\n");
1281 fprintf(fp,"# Display information of the menu, will be provided as specified.\n");
1282 fprintf(fp,"# The menu's voice is located in \"vbox_english\" and \"vbox_german\".\n");
1283 if (ext->vbox_language)
1284 fprintf(fp,"vbox_language german\n\n");
1286 fprintf(fp,"vbox_language english\n\n");
1288 fprintf(fp,"# The Answering Machine. Enter email to send incoming messages to:\n");
1289 fprintf(fp,"# All incoming message will be send to the given address.\n");
1290 fprintf(fp,"# The audio file is attached if \"vbox_email_file\" is 'yes'\n");
1291 fprintf(fp,"vbox_email %s\n", ext->vbox_email);
1292 fprintf(fp,"vbox_email_file %s\n\n",ext_yesno[ext->vbox_email_file]);
1294 fprintf(fp,"# If audio path is connected prior answering of a call, say 'yes'\n");
1295 fprintf(fp,"# will cause the call to be billed after playing the announcement. (yes or no)\n");
1296 fprintf(fp,"vbox_free %s\n\n",(ext->vbox_free)?"yes":"no");
1298 fprintf(fp,"# Accept incoming data calls as it would be an audio call.\n");
1299 fprintf(fp,"datacall %s\n\n",ext_yesno[ext->datacall]);
1301 fprintf(fp,"# Include seconds (time) in the connect message. (Should be always enabled.)\n");
1302 fprintf(fp,"seconds %s\n\n",ext_yesno[1-ext->no_seconds]);
1304 fprintf(fp,"# Last outgoing and incoming numbers (including prefix)\n");
1306 while(i < MAX_REMEMBER)
1308 if (ext->last_out[i][0])
1309 fprintf(fp,"last_out %s\n",ext->last_out[i]);
1313 while(i < MAX_REMEMBER)
1315 if (ext->last_in[i][0])
1316 fprintf(fp,"last_in %s\n",ext->last_in[i]);
1327 /* write log for extension
1330 int write_log(char *number, char *callerid, char *calledid, time_t start, time_t stop, int aoce, int cause, int location)
1332 char *mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1337 if (callerid[0] == '\0')
1338 callerid = "<unknown>";
1340 SPRINT(filename, "%s/%s/%s/log", INSTALL_DATA, options.extensions_dir, number);
1342 if (!(fp = fopen(filename, "a")))
1344 PERROR("Cannot open log: \"%s\"\n", filename);
1348 tm = localtime(&start);
1349 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);
1351 fprintf(fp," %2ld:%02ld:%02ld", (stop-start)/3600, (((unsigned long)(stop-start))/60)%60, ((unsigned long)(stop-start))%60);
1353 fprintf(fp," --:--:--");
1354 fprintf(fp," %s -> %s", callerid, calledid);
1355 if (cause >= 1 && cause <=127 && location>=0 && location<=15)
1356 fprintf(fp," (cause=%d '%s' location=%d '%s')", cause, isdn_cause[cause].german, location, isdn_location[location].german);
1366 * reads phone book of extextension and compares the given elements which
1367 * are: abreviation, phone number, name (name is not compared)
1368 * on success a 1 is returned and the pointers of elements are set to the
1371 int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, char **name_pointer)
1376 static char abbrev[32], phone[256], name[256];
1377 unsigned int line,i;
1379 int found = 0, found_if_more_digits = 0;
1381 SPRINT(filename, "%s/%s/%s/phonebook", INSTALL_DATA, options.extensions_dir, number);
1383 if (!(fp = fopen(filename, "r")))
1385 PERROR("Cannot open phonebook: \"%s\"\n", filename);
1390 while((fgets(buffer, sizeof(buffer), fp)))
1393 buffer[sizeof(buffer)-1] = '\0';
1394 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1397 while(*p <= 32) /* skip spaces */
1403 if (*p==0 || *p=='#') /* ignore comments and empty line */
1410 i=0; /* read abbrev */
1413 if (i+1 >= sizeof(abbrev))
1415 PERROR_RUNTIME("Error in %s (line %d): abbrev too long.\n",filename,line);
1422 while(*p <= 32) /* skip spaces */
1429 if (*p!=0 && *p!='#') /* phone */
1431 i=0; /* read phone */
1434 if (i+1 >= sizeof(phone))
1436 PERROR_RUNTIME("Error in %s (line %d): phone too long.\n",filename,line);
1442 while(*p <= 32) /* skip spaces */
1450 if (*p!=0 && *p!='#') /* name */
1452 i=0; /* read name */
1455 if (i+1 >= sizeof(name))
1457 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1465 if (*abbrev_pointer)
1467 if (!strncmp(*abbrev_pointer, abbrev, strlen(*abbrev_pointer)))
1469 /* may match if abbreviation is longer */
1470 found_if_more_digits = 1;
1472 if (!!strcasecmp(*abbrev_pointer, abbrev))
1476 if (!!strcasecmp(*phone_pointer, phone))
1479 if (!!strcasecmp(*name_pointer, name))
1483 break; /* found entry */
1490 *abbrev_pointer = abbrev;
1491 *phone_pointer = phone;
1492 *name_pointer = name;
1497 if (found_if_more_digits)
1503 /* parsing secrets file
1505 * 'number' specifies the externsion number, not the caller id
1506 * 'remote_id' specifies the dialed number, or the caller id for incoming calls
1507 * the result is the auth, crypt and key string, and 1 is returned.
1508 * on failure or not matching number, the 0 is returned
1510 int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **crypt_pointer, char **key_pointer)
1516 static char auth[64], crypt[64], key[4096];
1517 unsigned int line,i;
1521 SPRINT(filename, "%s/%s/%s/secrets", INSTALL_DATA, options.extensions_dir, number);
1523 if (!(fp = fopen(filename, "r")))
1525 PERROR("Cannot open secrets: \"%s\"\n", filename);
1530 while((fgets(buffer, sizeof(buffer), fp)))
1533 buffer[sizeof(buffer)-1] = '\0';
1534 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1537 while(*p <= 32) /* skip spaces */
1543 if (*p==0 || *p=='#') /* ignore comments and empty line */
1551 i=0; /* read auth */
1554 if (i+1 >= sizeof(remote))
1556 PERROR_RUNTIME("Error in %s (line %d): remote too long.\n",filename,line);
1563 while(*p <= 32) /* skip spaces */
1570 if (*p!=0 && *p!='#') /* auth */
1572 i=0; /* read auth */
1575 if (i+1 >= sizeof(auth))
1577 PERROR_RUNTIME("Error in %s (line %d): auth too long.\n",filename,line);
1583 while(*p <= 32) /* skip spaces */
1591 if (*p!=0 && *p!='#') /* crypt */
1593 i=0; /* read crypt */
1596 if (i+1 >= sizeof(crypt))
1598 PERROR_RUNTIME("Error in %s (line %d): crypt too long.\n",filename,line);
1604 while(*p <= 32) /* skip spaces */
1612 if (*p!=0 && *p!='#') /* key */
1617 if (i+1 >= sizeof(key))
1619 PERROR_RUNTIME("Error in %s (line %d): key too long.\n",filename,line);
1626 //printf("COMPARING: '%s' with '%s' %s %s %s\n", remote_id, remote, auth, crypt, key);
1628 if (!!strcasecmp(remote, remote_id))
1632 break; /* found entry */
1639 *auth_pointer = auth;
1640 *crypt_pointer = crypt;
1649 * the caller id is given and the name is returned. if the name is not found,
1651 * on success a 1 is returned and the pointers of elements are set to the
1654 char *parse_directory(char *number, int type)
1659 static char phone[32], name[64];
1660 unsigned int line,i;
1664 SPRINT(filename, "%s/directory.list", INSTALL_DATA);
1666 if (!(fp = fopen(filename, "r")))
1668 PERROR("Cannot open directory: \"%s\"\n", filename);
1673 while((fgets(buffer, sizeof(buffer), fp)))
1676 buffer[sizeof(buffer)-1] = '\0';
1677 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1680 while(*p <= 32) /* skip spaces */
1686 if (*p==0 || *p=='#') /* ignore comments and empty line */
1692 i=0; /* read number */
1695 if (i+1 >= sizeof(phone))
1697 PERROR_RUNTIME("Error in %s (line %d): number too long.\n",filename,line);
1704 while(*p <= 32) /* skip spaces */
1711 i=0; /* read name */
1714 if (i+1 >= sizeof(name))
1716 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1723 if (phone[0] == 'i')
1725 if (type != INFO_NTYPE_INTERNATIONAL)
1727 if (!strcmp(number, phone+1))
1734 if (phone[0] == 'n')
1736 if (type != INFO_NTYPE_NATIONAL)
1738 if (!strcmp(number, phone+1))
1745 if (phone[0] == 's')
1747 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1749 if (!strcmp(number, phone+1))
1756 if (!strncmp(phone, options.international, strlen(options.international)))
1758 if (type != INFO_NTYPE_INTERNATIONAL)
1760 if (!strcmp(number, phone+strlen(options.international)))
1767 if (!options.national[0]) /* no national prefix */
1769 if (type == INFO_NTYPE_INTERNATIONAL)
1771 if (!strcmp(number, phone))
1778 if (!strncmp(phone, options.national, strlen(options.national)))
1780 if (type != INFO_NTYPE_NATIONAL)
1782 if (!strcmp(number, phone+strlen(options.national)))
1789 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1791 if (!strcmp(number, phone))
1806 /* parse callbackauth
1808 * searches for the given caller id and returns 1 == true or 0 == false
1810 int parse_callbackauth(char *number, struct caller_info *callerinfo)
1815 unsigned int line,i;
1817 static char caller_type[32], caller_id[64];
1820 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
1822 if (!(fp = fopen(filename, "r")))
1824 PDEBUG(DEBUG_EPOINT, "Cannot open callbackauth: \"%s\"\n", filename);
1829 while((fgets(buffer, sizeof(buffer), fp)))
1832 buffer[sizeof(buffer)-1] = '\0';
1833 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1836 while(*p <= 32) /* skip spaces */
1842 if (*p==0 || *p=='#') /* ignore comments and empty line */
1848 i=0; /* read caller_type */
1851 if (i+1 >= sizeof(caller_type))
1853 PERROR_RUNTIME("Error in %s (line %d): caller_type too long.\n",filename,line);
1856 caller_type[i+1] = '\0';
1857 caller_type[i++] = *p++;
1860 while(*p <= 32) /* skip spaces */
1867 if (*p!=0 && *p!='#') /* caller_id */
1869 i=0; /* read caller_id */
1872 if (i+1 >= sizeof(caller_id))
1874 PERROR_RUNTIME("Error in %s (line %d): caller_id too long.\n",filename,line);
1877 caller_id[i+1] = '\0';
1878 caller_id[i++] = *p++;
1883 if (caller_type[0]=='\0' && caller_id[0]=='\0')
1886 if (atoi(caller_type) != callerinfo->ntype)
1889 if (!!strcmp(caller_id, callerinfo->id))
1893 break; /* found entry */
1904 /* append line to callbackauth
1907 void append_callbackauth(char *number, struct caller_info *callerinfo)
1912 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
1914 if (callerinfo->id[0]=='\0')
1916 PERROR("caller has no id.\n");
1919 if (!(fp = fopen(filename, "a")))
1921 PERROR("Cannot open callbackauth: \"%s\"\n", filename);
1925 fprintf(fp, "%6d %s\n", callerinfo->ntype, callerinfo->id);