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,"centrex"))
404 if (!strcasecmp(param,ext_yesno[i]))
411 PDEBUG(DEBUG_CONFIG, "use centrex to display name %s\n", ext_yesno[i]);
414 PDEBUG(DEBUG_CONFIG, "unknown parameter given centrex: %s\n", param);
417 if (!strcmp(option,"rights"))
422 if (!strcasecmp(param,ext_rights[i]))
429 PDEBUG(DEBUG_CONFIG, "rights to dial: %s\n", ext_rights[i]);
432 PDEBUG(DEBUG_CONFIG, "given rights unknown: %s\n", param);
435 if (!strcmp(option,"delete_ext"))
440 if (!strcasecmp(param,ext_yesno[i]))
447 PDEBUG(DEBUG_CONFIG, "enables the delete key function for external calls: %s\n", ext_yesno[i]);
450 PDEBUG(DEBUG_CONFIG, "unknown parameter given delete: %s\n", param);
453 if (!strcmp(option,"noknocking"))
458 if (!strcasecmp(param,ext_yesno[i]))
465 PDEBUG(DEBUG_CONFIG, "noknocking %s\n", ext_yesno[i]);
468 PDEBUG(DEBUG_CONFIG, "given noknocking param unknown: %s\n", param);
471 if (!strcmp(option,"rx_gain")
472 || !strcmp(option,"rxvol"))
474 ext->rx_gain = atoi(param);
475 if (ext->rx_gain<-8 || ext->rx_gain>8)
478 PDEBUG(DEBUG_CONFIG, "receive volume: %d\n",ext->rx_gain);
480 if (!strcmp(option,"tx_gain")
481 || !strcmp(option,"txvol"))
483 ext->tx_gain = atoi(param);
484 if (ext->tx_gain<-8 || ext->tx_gain>8)
487 PDEBUG(DEBUG_CONFIG, "transmit volume: %d\n",ext->tx_gain);
489 if (!strcmp(option,"own_setup"))
494 if (!strcasecmp(param,ext_yesno[i]))
501 PDEBUG(DEBUG_CONFIG, "own_setup %s\n", ext_yesno[i]);
504 PDEBUG(DEBUG_CONFIG, "given own_setup param unknown: %s\n", param);
507 if (!strcmp(option,"own_proceeding"))
512 if (!strcasecmp(param,ext_yesno[i]))
518 ext->own_proceeding = i;
519 PDEBUG(DEBUG_CONFIG, "own_proceeding %s\n", ext_yesno[i]);
522 PDEBUG(DEBUG_CONFIG, "given own_proceeding param unknown: %s\n", param);
525 if (!strcmp(option,"own_alerting"))
530 if (!strcasecmp(param,ext_yesno[i]))
536 ext->own_alerting = i;
537 PDEBUG(DEBUG_CONFIG, "own_alerting %s\n", ext_yesno[i]);
540 PDEBUG(DEBUG_CONFIG, "given own_alerting param unknown: %s\n", param);
543 if (!strcmp(option,"own_cause"))
548 if (!strcasecmp(param,ext_yesno[i]))
555 PDEBUG(DEBUG_CONFIG, "own_cause %s\n", ext_yesno[i]);
558 PDEBUG(DEBUG_CONFIG, "given own_cause param unknown: %s\n", param);
561 if (!strcmp(option,"facility"))
566 if (!strcasecmp(param,ext_yesno[i]))
573 PDEBUG(DEBUG_CONFIG, "facility %s\n", ext_yesno[i]);
576 PDEBUG(DEBUG_CONFIG, "given facility param unknown: %s\n", param);
579 if (!strcmp(option,"display_cause"))
581 if (!strcasecmp(param, "german"))
582 ext->display_cause = DISPLAY_CAUSE_GERMAN;
583 else if (!strcasecmp(param, "english"))
584 ext->display_cause = DISPLAY_CAUSE_ENGLISH;
585 else if (!strcasecmp(param, "german-location"))
586 ext->display_cause = DISPLAY_LOCATION_GERMAN;
587 else if (!strcasecmp(param, "english-location"))
588 ext->display_cause = DISPLAY_LOCATION_ENGLISH;
589 else if (!strcasecmp(param, "number"))
590 ext->display_cause = DISPLAY_CAUSE_NUMBER;
592 ext->display_cause = DISPLAY_CAUSE_NONE;
594 PDEBUG(DEBUG_CONFIG, "display cause: %d\n",ext->display_cause);
597 if (!strcmp(option,"display_ext"))
599 if (!strcasecmp(param, "number"))
600 ext->display_ext = DISPLAY_CID_NUMBER;
601 else if (!strcasecmp(param, "abbrev"))
602 ext->display_ext = DISPLAY_CID_ABBREVIATION;
603 else if (!strcasecmp(param, "name"))
604 ext->display_ext = DISPLAY_CID_NAME;
605 else if (!strcasecmp(param, "number-name"))
606 ext->display_ext = DISPLAY_CID_NUMBER_NAME;
607 else if (!strcasecmp(param, "name-number"))
608 ext->display_ext = DISPLAY_CID_NAME_NUMBER;
609 else if (!strcasecmp(param, "abbrev-number"))
610 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER;
611 else if (!strcasecmp(param, "abbrev-name"))
612 ext->display_ext = DISPLAY_CID_ABBREV_NAME;
613 else if (!strcasecmp(param, "abbrev-name-number"))
614 ext->display_ext = DISPLAY_CID_ABBREV_NAME_NUMBER;
615 else if (!strcasecmp(param, "abbrev-number-name"))
616 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER_NAME;
618 ext->display_ext = DISPLAY_CID_ASIS;
620 PDEBUG(DEBUG_CONFIG, "display ext: %d\n",ext->display_ext);
623 if (!strcmp(option,"display_ext"))
628 if (!strcasecmp(param,ext_yesno[i]))
634 ext->display_ext = i;
635 PDEBUG(DEBUG_CONFIG, "display ext %s\n", ext_yesno[i]);
638 PDEBUG(DEBUG_CONFIG, "given display_ext param unknown: %s\n", param);
641 if (!strcmp(option,"display_int"))
646 if (!strcasecmp(param,ext_yesno[i]))
652 ext->display_int = i;
653 PDEBUG(DEBUG_CONFIG, "display int %s\n", ext_yesno[i]);
656 PDEBUG(DEBUG_CONFIG, "given display_int param unknown: %s\n", param);
659 if (!strcmp(option,"display_fake"))
664 if (!strcasecmp(param,ext_yesno[i]))
670 ext->display_fake = i;
671 PDEBUG(DEBUG_CONFIG, "display fake caller ids %s\n", ext_yesno[i]);
674 PDEBUG(DEBUG_CONFIG, "given display_fake param unknown: %s\n", param);
677 if (!strcmp(option,"display_anon"))
682 if (!strcasecmp(param,ext_yesno[i]))
688 ext->display_anon = i;
689 PDEBUG(DEBUG_CONFIG, "display anonymouse ids %s\n", ext_yesno[i]);
692 PDEBUG(DEBUG_CONFIG, "given display_anon param unknown: %s\n", param);
695 if (!strcmp(option,"display_menu"))
700 if (!strcasecmp(param,ext_yesno[i]))
706 ext->display_menu = i;
707 PDEBUG(DEBUG_CONFIG, "display menu %s\n", ext_yesno[i]);
710 PDEBUG(DEBUG_CONFIG, "given display_menu param unknown: %s\n", param);
713 if (!strcmp(option,"display_dialing"))
718 if (!strcasecmp(param,ext_yesno[i]))
724 ext->display_dialing = i;
725 PDEBUG(DEBUG_CONFIG, "display dialing %s\n", ext_yesno[i]);
728 PDEBUG(DEBUG_CONFIG, "given display_dialing param unknown: %s\n", param);
731 if (!strcmp(option,"display_name"))
736 if (!strcasecmp(param,ext_yesno[i]))
742 ext->display_name = i;
743 PDEBUG(DEBUG_CONFIG, "display name %s\n", ext_yesno[i]);
746 PDEBUG(DEBUG_CONFIG, "given display_name param unknown: %s\n", param);
749 if (!strcmp(option,"tones_dir"))
751 if (param[strlen(param)-1] == '/')
752 param[strlen(param)-1]=0;
753 SCPY(ext->tones_dir, param);
755 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
757 if (!strcmp(option,"record"))
759 if (!strcasecmp(param, "mono"))
760 ext->record = CODEC_MONO;
761 else if (!strcasecmp(param, "stereo"))
762 ext->record = CODEC_STEREO;
763 else if (!strcasecmp(param, "8bit"))
764 ext->record = CODEC_8BIT;
765 else if (!strcasecmp(param, "law"))
766 ext->record = CODEC_LAW;
768 ext->record = CODEC_OFF;
769 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
771 if (!strcmp(option,"password"))
773 SCPY(ext->password, param);
775 PDEBUG(DEBUG_CONFIG, "password: %s\n",param);
777 if (!strcmp(option,"vbox_mode"))
779 if (!strcasecmp(param, "parallel"))
780 ext->vbox_mode = VBOX_MODE_PARALLEL;
781 else if (!strcasecmp(param, "announcement"))
782 ext->vbox_mode = VBOX_MODE_ANNOUNCEMENT;
784 ext->vbox_mode = VBOX_MODE_NORMAL;
785 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
787 if (!strcmp(option,"vbox_codec"))
789 if (!strcasecmp(param, "stereo"))
790 ext->vbox_codec = CODEC_STEREO;
791 else if (!strcasecmp(param, "8bit"))
792 ext->vbox_codec = CODEC_8BIT;
793 else if (!strcasecmp(param, "law"))
794 ext->vbox_codec = CODEC_LAW;
796 ext->vbox_codec = CODEC_MONO;
797 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
799 if (!strcmp(option,"vbox_time"))
801 ext->vbox_time = atoi(param);
802 if (ext->vbox_time < 0)
805 PDEBUG(DEBUG_CONFIG, "vbox time to record: %d\n",ext->vbox_time);
807 if (!strcmp(option,"vbox_display"))
809 if (!strcasecmp(param, "detailed")
810 || !strcasecmp(param, "detailled"))
811 ext->vbox_display = VBOX_DISPLAY_DETAILED;
812 else if (!strcasecmp(param, "off"))
813 ext->vbox_display = VBOX_DISPLAY_OFF;
815 ext->vbox_display = VBOX_DISPLAY_BRIEF;
816 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
818 if (!strcmp(option,"vbox_language"))
820 if (!strcasecmp(param, "german"))
821 ext->vbox_language = VBOX_LANGUAGE_GERMAN;
823 ext->vbox_language = VBOX_LANGUAGE_ENGLISH;
824 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
826 if (!strcmp(option,"vbox_email"))
828 SCPY(ext->vbox_email, param);
829 PDEBUG(DEBUG_CONFIG, "given vbox email: %s\n", param);
831 if (!strcmp(option,"vbox_email_file"))
836 if (!strcasecmp(param,ext_yesno[i]))
842 ext->vbox_email_file = i;
843 PDEBUG(DEBUG_CONFIG, "attach audio file %s\n", ext_yesno[i]);
846 PDEBUG(DEBUG_CONFIG, "given vbox_email_file param unknown: %s\n", param);
849 if (!strcmp(option,"vbox_free"))
854 if (!strcasecmp(param,ext_yesno[i]))
861 PDEBUG(DEBUG_CONFIG, "vbox_free %s\n", ext_yesno[i]);
864 PDEBUG(DEBUG_CONFIG, "given vbox_free param unknown: %s\n", param);
867 if (!strcmp(option,"last_in"))
869 if (param[0] && last_in_count<MAX_REMEMBER)
871 SCPY(ext->last_in[last_in_count], param);
874 PDEBUG(DEBUG_CONFIG, "last_in dialed number: %s\n",param);
876 if (!strcmp(option,"last_out"))
878 if (param[0] && last_out_count<MAX_REMEMBER)
880 SCPY(ext->last_out[last_out_count], param);
883 PDEBUG(DEBUG_CONFIG, "last_out dialed number: %s\n",param);
885 if (!strcmp(option,"datacall"))
890 if (!strcasecmp(param,ext_yesno[i]))
897 PDEBUG(DEBUG_CONFIG, "datacall %s\n", ext_yesno[i]);
900 PDEBUG(DEBUG_CONFIG, "given datacall param unknown: %s\n", param);
903 if (!strcmp(option,"seconds"))
908 if (!strcasecmp(param,ext_yesno[i]))
914 ext->no_seconds = 1-i;
915 PDEBUG(DEBUG_CONFIG, "seconds %s\n", ext_yesno[i]);
918 PDEBUG(DEBUG_CONFIG, "unknown param for seconds: %s\n", param);
922 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n",filename,line,option);
933 * writes extension for given extension number from structure
935 int write_extension(struct extension *ext, char *number)
941 if (number[0] == '\0')
944 SPRINT(filename, "%s/%s/%s/settings", INSTALL_DATA, options.extensions_dir, number);
946 if (!(fp = fopen(filename, "w")))
948 PERROR("Cannot open settings: \"%s\"\n", filename);
952 fprintf(fp,"# Settings of extension %s\n\n", number);
954 fprintf(fp,"# Name of extension:\n");
955 fprintf(fp,"name %s\n\n",ext->name);
957 fprintf(fp,"# Predialed prefix after pick-up of the phone\n");
958 fprintf(fp,"prefix %s\n\n",ext->prefix);
960 fprintf(fp,"# Next prefix to dial pick-up of the phone\n");
961 fprintf(fp,"# This will be cleared on hangup.\n");
962 fprintf(fp,"next %s\n\n",ext->next);
964 // fprintf(fp,"# Set up alarm message after prefix is dialed and connection is established\n");
965 // fprintf(fp,"alarm %s\n\n",ext->alarm);
967 fprintf(fp,"# Interface(s) to ring on calls to extension (as named in interface.conf)\n");
968 fprintf(fp,"# Seperate multiple interfaces by using komma without spaces\n");
969 fprintf(fp,"# Example: Int would ring on the interface with the name \"Int\"");
970 fprintf(fp,"# Int1,Int2 would ring incoming calls on both interfaces Int1 and Int2.\n");
971 fprintf(fp,"interfaces %s\n\n",ext->interfaces);
973 fprintf(fp,"# Call Forward Unconditional (CFU)\n");
974 fprintf(fp,"# No port will be called, CFB, CFNR and CFP is ignored.\n");
975 fprintf(fp,"# Use keyword \"vbox\" to forward call directly to answering machine.\n");
976 fprintf(fp,"cfu %s\n\n",ext->cfu);
978 fprintf(fp,"# Call Forward when Busy (CFB)\n");
979 fprintf(fp,"# If the extension is in use at least once, this forward is done.\n");
980 fprintf(fp,"# In case of busy line, CFNR and CFP is ignored.\n");
981 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine when busy.\n");
982 fprintf(fp,"cfb %s\n\n",ext->cfb);
984 fprintf(fp,"# Call Forward on No Response (CFNR)\n");
985 fprintf(fp,"# If noone answers, the call is forwarded, ports and CFP will be released.\n");
986 fprintf(fp,"# The default delay is 20 seconds.\n");
987 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine on no response.\n");
988 fprintf(fp,"cfnr %s\n",ext->cfnr);
989 fprintf(fp,"cfnr_delay %d\n\n",ext->cfnr_delay);
991 fprintf(fp,"# Call Forward Parallel (CFP)\n");
992 fprintf(fp,"# Call will ring on the forwarded number, simulaniousely with the ports.\n");
993 fprintf(fp,"cfp %s\n\n",ext->cfp);
995 fprintf(fp,"# Allow user to change call forwarding.\n");
996 fprintf(fp,"change_forward %s\n\n", ext_yesno[ext->change_forward]);
998 fprintf(fp,"# Caller id\n# This must be one of the following:\n");
999 fprintf(fp,"# <number> (as dialed from your local area)\n");
1000 fprintf(fp,"# <number> anonymous (will only be shown to emergency phones)\n");
1001 fprintf(fp,"# none (no number available at all)\n");
1002 fprintf(fp,"# by default the number is of type UNKNOWN (for MULTIPOINT lines)\n");
1003 fprintf(fp,"# if your caller id is not screened on outgoing calls use one of the following:\n");
1004 fprintf(fp,"# use prefix 'i' for TYPE INTERNATIONAL (i<county code><areacode+number>)\n");
1005 fprintf(fp,"# use prefix 'n' for TYPE NATIONAL (n<areacode+number>)\n");
1006 fprintf(fp,"# use prefix 's' for TYPE SUBSCRIBER (s<local number>)\n");
1007 if (ext->callerid_present == INFO_PRESENT_NOTAVAIL)
1008 fprintf(fp,"callerid none\n\n");
1011 switch(ext->callerid_type)
1013 case INFO_NTYPE_INTERNATIONAL:
1014 fprintf(fp,"callerid i%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1016 case INFO_NTYPE_NATIONAL:
1017 fprintf(fp,"callerid n%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1019 case INFO_NTYPE_SUBSCRIBER:
1020 fprintf(fp,"callerid s%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1023 fprintf(fp,"callerid %s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1027 fprintf(fp,"# Caller id for next call (see caller id)\n");
1028 if (ext->id_next_call_present < 0)
1029 fprintf(fp,"id_next_call \n\n");
1030 else if (ext->id_next_call_present == INFO_PRESENT_NOTAVAIL)
1031 fprintf(fp,"id_next_call none\n\n");
1034 switch(ext->id_next_call_type)
1036 case INFO_NTYPE_INTERNATIONAL:
1037 fprintf(fp,"id_next_call i%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1039 case INFO_NTYPE_NATIONAL:
1040 fprintf(fp,"id_next_call n%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1042 case INFO_NTYPE_SUBSCRIBER:
1043 fprintf(fp,"id_next_call s%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1046 fprintf(fp,"id_next_call %s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1050 fprintf(fp,"# Allow user to change caller ID.\n");
1051 fprintf(fp,"change_callerid %s\n\n", ext_yesno[ext->change_callerid]);
1053 fprintf(fp,"# Caller Line Identification Presentation (CLIP)\n");
1054 fprintf(fp,"# clip (asis|hide)\n");
1055 fprintf(fp,"# asis: On forwarded calls the CLIP is used as presented by the calling party.\n");
1056 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1060 fprintf(fp,"clip hide\n\n");
1063 fprintf(fp,"clip asis\n\n");
1066 fprintf(fp,"# Connected Line Identification Presentation (COLP)\n");
1067 fprintf(fp,"# colp (asis|hide|force)\n");
1068 fprintf(fp,"# asis: Provides colp as defined by the extension's caller id.\n");
1069 fprintf(fp,"# On forwarded calls the COLP is used as presented by the called party.\n");
1070 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1071 fprintf(fp,"# force: If COLP is not presented by forwarded calls the dialed number is used.\n");
1075 fprintf(fp,"colp hide\n\n");
1078 fprintf(fp,"colp force\n\n");
1081 fprintf(fp,"colp asis\n\n");
1084 fprintf(fp,"# CLIP Prefix\n");
1085 fprintf(fp,"# Adds a prefix to incoming caller IDs, so telephones will be able to respond\n");
1086 fprintf(fp,"# to unanswered calls from their list. The prefix must be the digit(s) to get\n");
1087 fprintf(fp,"# an external line. The caller ID will then be extendet so that they can be\n");
1088 fprintf(fp,"# dialed from internal telephones. Many telephones have this feature, but some\n");
1089 fprintf(fp,"# don't.\n");
1090 fprintf(fp,"clip_prefix %s\n\n",ext->clip_prefix);
1092 fprintf(fp,"# Keypad control\n");
1093 fprintf(fp,"# If supported by telephone, pressing a key on the keypad will not result in\n");
1094 fprintf(fp,"# DTMF tone, but the digit is transmitted via D-channel diaing info.\n");
1095 fprintf(fp,"keypad %s\n\n",(ext->keypad)?"yes":"no");
1097 fprintf(fp,"# Called Name Identification Presentation (CNIP/CONP)\n");
1098 fprintf(fp,"# If supported by telephone, special information element on the d-channel are\n");
1099 fprintf(fp,"# used to show name of caller. It is supported by newer Siemens telephones\n# (Centrex).\n");
1100 fprintf(fp,"centrex %s #this is currently not working!!!\n\n",(ext->centrex)?"yes":"no");
1102 fprintf(fp,"# Ignore restriction of COLP and CLIP\n");
1103 fprintf(fp,"# In this case even restricted numbers are presented to this extension.\n");
1104 fprintf(fp,"# This also works for incoming external anonymous calls IF:\n");
1105 fprintf(fp,"# You have the CLIRIGN feature like POLICE or equivalent.\n");
1106 fprintf(fp,"anon-ignore %s\n\n",(ext->anon_ignore)?"yes":"no");
1108 fprintf(fp,"# Dialing rights (none|internal|local|national|international)\n");
1109 fprintf(fp,"rights %s\n\n",ext_rights[ext->rights]);
1111 fprintf(fp,"# Delete function for external calls. '*' will delete the last digit, '#' will\n");
1112 fprintf(fp,"# delete the complete number. Also enable 'display_dialing' to see on the\n");
1113 fprintf(fp,"# display what actually happens.\n");
1114 fprintf(fp,"delete_ext %s\n\n",ext_yesno[ext->delete_ext]);
1116 fprintf(fp,"# If noknocking is enabled, the caller will get a busy message when the\n");
1117 fprintf(fp,"# extension is doing at least one call.\n");
1118 fprintf(fp,"noknocking %s\n\n",ext_yesno[ext->noknocking]);
1120 fprintf(fp,"# Transmit volume (-8 .. 8)\n");
1121 fprintf(fp,"# 0 = normal\n");
1122 fprintf(fp,"# 1 = double, 2 = quadrupel, 8 = 256 times (amplitude)\n");
1123 fprintf(fp,"# -1 = half, -2 = quarter, 8 = 1/256th (amplitude)\n");
1124 fprintf(fp,"# Audio data is limited to the maximum value when exceeds limit.\n");
1125 fprintf(fp,"tx_gain %d\n\n",ext->tx_gain);
1127 fprintf(fp,"# Receive volume (-8 .. 8)\n");
1128 fprintf(fp,"# (see tx_gain)\n");
1129 fprintf(fp,"rx_gain %d\n\n",ext->rx_gain);
1132 fprintf(fp,"# Force to use tones and announcements generated by the pbx.\n");
1133 fprintf(fp,"# For internal calls always own tones are used. You may specify own tones for\n");
1134 fprintf(fp,"# different call states:\n");
1135 fprintf(fp,"# own_setup (dialtone and during dialing)\n");
1136 fprintf(fp,"# own_proceeding (call in poceeding state)\n");
1137 fprintf(fp,"# own_alerting (call is ringing)\n");
1138 fprintf(fp,"# own_cause (when the call gets disconnected or failed to be completed)\n");
1139 fprintf(fp,"own_setup %s\n",ext_yesno[ext->own_setup]);
1140 fprintf(fp,"own_proceeding %s\n",ext_yesno[ext->own_proceeding]);
1141 fprintf(fp,"own_alerting %s\n",ext_yesno[ext->own_alerting]);
1142 fprintf(fp,"own_cause %s\n\n",ext_yesno[ext->own_cause]);
1144 fprintf(fp,"# Allow facility information to be transfered to the telephone.\n");
1145 fprintf(fp,"# This is equired to receive advice of charge.\n");
1146 fprintf(fp,"facility %s\n\n",ext_yesno[ext->facility]);
1148 fprintf(fp,"# Display clear causes using display messages (Q.850)\n# This must be one of the following:\n");
1149 fprintf(fp,"# none (no displaying of clear causes)\n");
1150 fprintf(fp,"# english (display cause text in english)\n");
1151 fprintf(fp,"# german (display cause text in german)\n");
1152 fprintf(fp,"# number (display cause number only)\n");
1153 fprintf(fp,"# english-location (display cause text in english and location)\n");
1154 fprintf(fp,"# german-location (display cause text in german and location)\n");
1155 switch(ext->display_cause)
1157 case DISPLAY_CAUSE_ENGLISH:
1158 fprintf(fp,"display_cause english\n\n");
1160 case DISPLAY_CAUSE_GERMAN:
1161 fprintf(fp,"display_cause german\n\n");
1163 case DISPLAY_LOCATION_ENGLISH:
1164 fprintf(fp,"display_cause english-location\n\n");
1166 case DISPLAY_LOCATION_GERMAN:
1167 fprintf(fp,"display_cause german-location\n\n");
1169 case DISPLAY_CAUSE_NUMBER:
1170 fprintf(fp,"display_cause number\n\n");
1173 fprintf(fp,"display_cause none\n\n");
1176 fprintf(fp,"# Display external caller ids using display override (yes or no)\n");
1177 fprintf(fp,"# example: \"15551212\"\n");
1178 fprintf(fp,"display_ext %s\n\n",(ext->display_ext)?"yes":"no");
1180 fprintf(fp,"# Display internal caller ids using display override (yes or no)\n");
1181 fprintf(fp,"# example: \"200 (int)\"\n");
1182 fprintf(fp,"display_int %s\n\n",(ext->display_int)?"yes":"no");
1184 fprintf(fp,"# Display if calls are anonymous using display override (yes or no)\n");
1185 fprintf(fp,"# This makes only sense if the anon-ignore feature is enabled.\n");
1186 fprintf(fp,"# example: \"15551212 anon\"\n");
1187 fprintf(fp,"display_anon %s\n\n",(ext->display_anon)?"yes":"no");
1189 fprintf(fp,"# Display fake caller ids using display override (yes or no)\n");
1190 fprintf(fp,"# If the caller uses \"clip no screening\", you will see if the number is\n");
1191 fprintf(fp,"# real or fake\n");
1192 fprintf(fp,"# example: \"15551212 fake\"\n");
1193 fprintf(fp,"display_fake %s\n\n",(ext->display_fake)?"yes":"no");
1195 fprintf(fp,"# Display caller's name if available. (yes or no)\n");
1196 fprintf(fp,"# example: \"15551212 Axel\"\n");
1197 fprintf(fp,"display_name %s\n\n",(ext->display_name)?"yes":"no");
1199 fprintf(fp,"# Display menu when '*' and '#' is pressed. The menu shows all prefixes for\n");
1200 fprintf(fp,"# internal dialing by pressing '*' for previous prefix and '#' for next prefix.\n");
1201 fprintf(fp,"# Also the dialed prefix is show on display. (yes or no)\n");
1202 fprintf(fp,"display_menu %s\n\n",(ext->display_menu)?"yes":"no");
1204 fprintf(fp,"# Display digits as they are interpreted by pbx. (yes or no)\n");
1205 fprintf(fp,"display_dialing %s\n\n",(ext->display_dialing)?"yes":"no");
1207 fprintf(fp,"# Tones directory for announcements and patterns\n");
1208 fprintf(fp,"# Enter nothing for default tones as selected by options.conf.\n");
1209 fprintf(fp,"tones_dir %s\n\n",ext->tones_dir);
1211 fprintf(fp,"# Record calls to extension's directory. The file is written as wave.\n");
1212 fprintf(fp,"# This must be one of the following:\n");
1213 fprintf(fp,"# off (no recording)\n");
1214 fprintf(fp,"# mono (records wave 16 bit mono, 128kbits/s)\n");
1215 fprintf(fp,"# stereo (records wave 32 bit stereo, 256kbits/s)\n");
1216 fprintf(fp,"# 8bit (records wave 8 bit mono, 64kbits/s)\n");
1217 fprintf(fp,"# law (records xLaw encoded, as specified in options.conf, 64kbps/s)\n");
1221 fprintf(fp,"record mono\n\n");
1224 fprintf(fp,"record stereo\n\n");
1227 fprintf(fp,"record 8bit\n\n");
1230 fprintf(fp,"record law\n\n");
1233 fprintf(fp,"record off\n\n");
1236 fprintf(fp,"# Password for callback and login\n");
1237 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1238 fprintf(fp,"password %s\n\n",ext->password);
1240 fprintf(fp,"# The Answering Machine. Enter the mode of answering machine.\n");
1241 fprintf(fp,"# This must be one of the following:\n");
1242 fprintf(fp,"# normal (plays announcement and records after that)\n");
1243 fprintf(fp,"# parallel (plays announcement and records also DURING announcement.)\n");
1244 fprintf(fp,"# announcement (just plays announcement and hangs up)\n");
1245 switch(ext->vbox_mode)
1247 case VBOX_MODE_PARALLEL:
1248 fprintf(fp,"vbox_mode parallel\n\n");
1250 case VBOX_MODE_ANNOUNCEMENT:
1251 fprintf(fp,"vbox_mode announcement\n\n");
1254 fprintf(fp,"vbox_mode normal\n\n");
1257 fprintf(fp,"# The Answering Machine. Enter the type of codec for recording.\n");
1258 fprintf(fp,"# This must be one of the following:\n");
1259 fprintf(fp,"# law (alaw/ulas codec, as specified in options.conf)\n");
1260 fprintf(fp,"# mono (16 bit mono wave file)\n");
1261 fprintf(fp,"# stereo (16 bit stereo wave file)\n");
1262 fprintf(fp,"# 8bit (8 bit mono wave file)\n");
1263 switch(ext->vbox_codec)
1266 fprintf(fp,"vbox_codec law\n\n");
1269 fprintf(fp,"vbox_codec stereo\n\n");
1272 fprintf(fp,"vbox_codec 8bit\n\n");
1275 fprintf(fp,"vbox_codec mono\n\n");
1278 fprintf(fp,"# The Answering Machine. Enter maximum time to record after announcement.\n");
1279 fprintf(fp,"# Leave empty, enter \"infinite\" or give time in seconds.\n");
1280 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1282 fprintf(fp,"vbox_time %d\n\n",ext->vbox_time);
1284 fprintf(fp,"vbox_time infinite\n\n");
1286 fprintf(fp,"# The Answering Machine. Enter mode for display current state.\n");
1287 fprintf(fp,"# This must be one of the following:\n");
1288 fprintf(fp,"# brief (displays brief information, for small displays)\n");
1289 fprintf(fp,"# detailed (displays detailed information, for larger displays)\n");
1290 fprintf(fp,"# off (don't display anything)\n");
1291 switch(ext->vbox_display)
1293 case VBOX_DISPLAY_OFF:
1294 fprintf(fp,"vbox_display off\n\n");
1296 case VBOX_DISPLAY_DETAILED:
1297 fprintf(fp,"vbox_display detailed\n\n");
1300 fprintf(fp,"vbox_display brief\n\n");
1303 fprintf(fp,"# The Answering Machine. Enter type of language: \"english\" or \"german\"\n");
1304 fprintf(fp,"# Display information of the menu, will be provided as specified.\n");
1305 fprintf(fp,"# The menu's voice is located in \"vbox_english\" and \"vbox_german\".\n");
1306 if (ext->vbox_language)
1307 fprintf(fp,"vbox_language german\n\n");
1309 fprintf(fp,"vbox_language english\n\n");
1311 fprintf(fp,"# The Answering Machine. Enter email to send incoming messages to:\n");
1312 fprintf(fp,"# All incoming message will be send to the given address.\n");
1313 fprintf(fp,"# The audio file is attached if \"vbox_email_file\" is 'yes'\n");
1314 fprintf(fp,"vbox_email %s\n", ext->vbox_email);
1315 fprintf(fp,"vbox_email_file %s\n\n",ext_yesno[ext->vbox_email_file]);
1317 fprintf(fp,"# If audio path is connected prior answering of a call, say 'yes'\n");
1318 fprintf(fp,"# will cause the call to be billed after playing the announcement. (yes or no)\n");
1319 fprintf(fp,"vbox_free %s\n\n",(ext->vbox_free)?"yes":"no");
1321 fprintf(fp,"# Accept incoming data calls as it would be an audio call.\n");
1322 fprintf(fp,"datacall %s\n\n",ext_yesno[ext->datacall]);
1324 fprintf(fp,"# Include seconds (time) in the connect message. (Should be always enabled.)\n");
1325 fprintf(fp,"seconds %s\n\n",ext_yesno[1-ext->no_seconds]);
1327 fprintf(fp,"# Last outgoing and incoming numbers (including prefix)\n");
1329 while(i < MAX_REMEMBER)
1331 if (ext->last_out[i][0])
1332 fprintf(fp,"last_out %s\n",ext->last_out[i]);
1336 while(i < MAX_REMEMBER)
1338 if (ext->last_in[i][0])
1339 fprintf(fp,"last_in %s\n",ext->last_in[i]);
1350 /* write log for extension
1353 int write_log(char *number, char *callerid, char *calledid, time_t start, time_t stop, int aoce, int cause, int location)
1355 char *mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1360 if (callerid[0] == '\0')
1361 callerid = "<unknown>";
1363 SPRINT(filename, "%s/%s/%s/log", INSTALL_DATA, options.extensions_dir, number);
1365 if (!(fp = fopen(filename, "a")))
1367 PERROR("Cannot open log: \"%s\"\n", filename);
1371 tm = localtime(&start);
1372 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);
1374 fprintf(fp," %2ld:%02ld:%02ld", (stop-start)/3600, (((unsigned long)(stop-start))/60)%60, ((unsigned long)(stop-start))%60);
1376 fprintf(fp," --:--:--");
1377 fprintf(fp," %s -> %s", callerid, calledid);
1378 if (cause >= 1 && cause <=127 && location>=0 && location<=15)
1379 fprintf(fp," (cause=%d '%s' location=%d '%s')", cause, isdn_cause[cause].german, location, isdn_location[location].german);
1389 * reads phone book of extextension and compares the given elements which
1390 * are: abreviation, phone number, name (name is not compared)
1391 * on success a 1 is returned and the pointers of elements are set to the
1394 int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, char **name_pointer)
1399 static char abbrev[32], phone[256], name[256];
1400 unsigned int line,i;
1402 int found = 0, found_if_more_digits = 0;
1404 SPRINT(filename, "%s/%s/%s/phonebook", INSTALL_DATA, options.extensions_dir, number);
1406 if (!(fp = fopen(filename, "r")))
1408 PERROR("Cannot open phonebook: \"%s\"\n", filename);
1413 while((fgets(buffer, sizeof(buffer), fp)))
1416 buffer[sizeof(buffer)-1] = '\0';
1417 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1420 while(*p <= 32) /* skip spaces */
1426 if (*p==0 || *p=='#') /* ignore comments and empty line */
1433 i=0; /* read abbrev */
1436 if (i+1 >= sizeof(abbrev))
1438 PERROR_RUNTIME("Error in %s (line %d): abbrev too long.\n",filename,line);
1445 while(*p <= 32) /* skip spaces */
1452 if (*p!=0 && *p!='#') /* phone */
1454 i=0; /* read phone */
1457 if (i+1 >= sizeof(phone))
1459 PERROR_RUNTIME("Error in %s (line %d): phone too long.\n",filename,line);
1465 while(*p <= 32) /* skip spaces */
1473 if (*p!=0 && *p!='#') /* name */
1475 i=0; /* read name */
1478 if (i+1 >= sizeof(name))
1480 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1488 if (*abbrev_pointer)
1490 if (!strncmp(*abbrev_pointer, abbrev, strlen(*abbrev_pointer)))
1492 /* may match if abbreviation is longer */
1493 found_if_more_digits = 1;
1495 if (!!strcasecmp(*abbrev_pointer, abbrev))
1499 if (!!strcasecmp(*phone_pointer, phone))
1502 if (!!strcasecmp(*name_pointer, name))
1506 break; /* found entry */
1513 *abbrev_pointer = abbrev;
1514 *phone_pointer = phone;
1515 *name_pointer = name;
1520 if (found_if_more_digits)
1526 /* parsing secrets file
1528 * 'number' specifies the externsion number, not the caller id
1529 * 'remote_id' specifies the dialed number, or the caller id for incoming calls
1530 * the result is the auth, crypt and key string, and 1 is returned.
1531 * on failure or not matching number, the 0 is returned
1533 int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **crypt_pointer, char **key_pointer)
1539 static char auth[64], crypt[64], key[4096];
1540 unsigned int line,i;
1544 SPRINT(filename, "%s/%s/%s/secrets", INSTALL_DATA, options.extensions_dir, number);
1546 if (!(fp = fopen(filename, "r")))
1548 PERROR("Cannot open secrets: \"%s\"\n", filename);
1553 while((fgets(buffer, sizeof(buffer), fp)))
1556 buffer[sizeof(buffer)-1] = '\0';
1557 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1560 while(*p <= 32) /* skip spaces */
1566 if (*p==0 || *p=='#') /* ignore comments and empty line */
1574 i=0; /* read auth */
1577 if (i+1 >= sizeof(remote))
1579 PERROR_RUNTIME("Error in %s (line %d): remote too long.\n",filename,line);
1586 while(*p <= 32) /* skip spaces */
1593 if (*p!=0 && *p!='#') /* auth */
1595 i=0; /* read auth */
1598 if (i+1 >= sizeof(auth))
1600 PERROR_RUNTIME("Error in %s (line %d): auth too long.\n",filename,line);
1606 while(*p <= 32) /* skip spaces */
1614 if (*p!=0 && *p!='#') /* crypt */
1616 i=0; /* read crypt */
1619 if (i+1 >= sizeof(crypt))
1621 PERROR_RUNTIME("Error in %s (line %d): crypt too long.\n",filename,line);
1627 while(*p <= 32) /* skip spaces */
1635 if (*p!=0 && *p!='#') /* key */
1640 if (i+1 >= sizeof(key))
1642 PERROR_RUNTIME("Error in %s (line %d): key too long.\n",filename,line);
1649 //printf("COMPARING: '%s' with '%s' %s %s %s\n", remote_id, remote, auth, crypt, key);
1651 if (!!strcasecmp(remote, remote_id))
1655 break; /* found entry */
1662 *auth_pointer = auth;
1663 *crypt_pointer = crypt;
1672 * the caller id is given and the name is returned. if the name is not found,
1674 * on success a 1 is returned and the pointers of elements are set to the
1677 char *parse_directory(char *number, int type)
1682 static char phone[32], name[64];
1683 unsigned int line,i;
1687 SPRINT(filename, "%s/directory.list", INSTALL_DATA);
1689 if (!(fp = fopen(filename, "r")))
1691 PERROR("Cannot open directory: \"%s\"\n", filename);
1696 while((fgets(buffer, sizeof(buffer), fp)))
1699 buffer[sizeof(buffer)-1] = '\0';
1700 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1703 while(*p <= 32) /* skip spaces */
1709 if (*p==0 || *p=='#') /* ignore comments and empty line */
1715 i=0; /* read number */
1718 if (i+1 >= sizeof(phone))
1720 PERROR_RUNTIME("Error in %s (line %d): number too long.\n",filename,line);
1727 while(*p <= 32) /* skip spaces */
1734 i=0; /* read name */
1737 if (i+1 >= sizeof(name))
1739 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1746 if (phone[0] == 'i')
1748 if (type != INFO_NTYPE_INTERNATIONAL)
1750 if (!strcmp(number, phone+1))
1757 if (phone[0] == 'n')
1759 if (type != INFO_NTYPE_NATIONAL)
1761 if (!strcmp(number, phone+1))
1768 if (phone[0] == 's')
1770 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1772 if (!strcmp(number, phone+1))
1779 if (!strncmp(phone, options.international, strlen(options.international)))
1781 if (type != INFO_NTYPE_INTERNATIONAL)
1783 if (!strcmp(number, phone+strlen(options.international)))
1790 if (!options.national[0]) /* no national prefix */
1792 if (type == INFO_NTYPE_INTERNATIONAL)
1794 if (!strcmp(number, phone))
1801 if (!strncmp(phone, options.national, strlen(options.national)))
1803 if (type != INFO_NTYPE_NATIONAL)
1805 if (!strcmp(number, phone+strlen(options.national)))
1812 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1814 if (!strcmp(number, phone))
1829 /* parse callbackauth
1831 * searches for the given caller id and returns 1 == true or 0 == false
1833 int parse_callbackauth(char *number, struct caller_info *callerinfo)
1838 unsigned int line,i;
1840 static char caller_type[32], caller_id[64];
1843 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
1845 if (!(fp = fopen(filename, "r")))
1847 PDEBUG(DEBUG_EPOINT, "Cannot open callbackauth: \"%s\"\n", filename);
1852 while((fgets(buffer, sizeof(buffer), fp)))
1855 buffer[sizeof(buffer)-1] = '\0';
1856 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1859 while(*p <= 32) /* skip spaces */
1865 if (*p==0 || *p=='#') /* ignore comments and empty line */
1871 i=0; /* read caller_type */
1874 if (i+1 >= sizeof(caller_type))
1876 PERROR_RUNTIME("Error in %s (line %d): caller_type too long.\n",filename,line);
1879 caller_type[i+1] = '\0';
1880 caller_type[i++] = *p++;
1883 while(*p <= 32) /* skip spaces */
1890 if (*p!=0 && *p!='#') /* caller_id */
1892 i=0; /* read caller_id */
1895 if (i+1 >= sizeof(caller_id))
1897 PERROR_RUNTIME("Error in %s (line %d): caller_id too long.\n",filename,line);
1900 caller_id[i+1] = '\0';
1901 caller_id[i++] = *p++;
1906 if (caller_type[0]=='\0' && caller_id[0]=='\0')
1909 if (atoi(caller_type) != callerinfo->ntype)
1912 if (!!strcmp(caller_id, callerinfo->id))
1916 break; /* found entry */
1927 /* append line to callbackauth
1930 void append_callbackauth(char *number, struct caller_info *callerinfo)
1935 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
1937 if (callerinfo->id[0]=='\0')
1939 PERROR("caller has no id.\n");
1942 if (!(fp = fopen(filename, "a")))
1944 PERROR("Cannot open callbackauth: \"%s\"\n", filename);
1948 fprintf(fp, "%6d %s\n", callerinfo->ntype, callerinfo->id);