1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** reading and writing files for extensions **
10 \*****************************************************************************/
16 const char *ext_rights[] = {
25 const char *ext_yesno[] = {
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/settings", EXTENSION_DATA, number);
56 if (!(fp = fopen(filename, "r")))
58 printf("the given extension doesn't exist: \"%s\"\n", filename);
59 PDEBUG(DEBUG_CONFIG, "the given extension doesn't exist: \"%s\"\n", filename);
64 memset(ext, 0, sizeof(struct extension));
65 SCPY(ext->number, number);
66 // ********** NOTE: also change value in apppbx constructor
67 ext->rights = 4; /* international */
69 ext->vbox_codec = CODEC_MONO;
72 while((fgets(buffer, sizeof(buffer), fp)))
75 buffer[sizeof(buffer)-1] = '\0';
76 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
79 while(*p <= 32) /* skip spaces */
85 if (*p==0 || *p=='#') /* ignore comments and empty line */
89 i=0; /* read option */
92 if (i+1 >= sizeof(option))
94 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
101 while(*p <= 32) /* skip spaces */
110 if (*p!=0 && *p!='#') /* param */
112 i=0; /* read param */
115 if (i+1 >= sizeof(param))
117 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
124 while(*p <= 32) /* skip spaces */
131 if (*p!=0 && *p!='#') /* param2 */
133 i=0; /* read param2 */
136 if (i+1 >= sizeof(param2))
138 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
147 /* at this point we have option and param */
150 if (!strcmp(option,"name"))
152 SCPY(ext->name, param);
155 SCAT(ext->name, (char *)" ");
156 SCAT(ext->name, param2);
159 PDEBUG(DEBUG_CONFIG, "name of extension: %s\n",param);
161 if (!strcmp(option,"prefix"))
163 SCPY(ext->prefix, param);
165 PDEBUG(DEBUG_CONFIG, "dial prefix on pickup: %s\n",param);
167 if (!strcmp(option,"next"))
169 SCPY(ext->next, param);
171 PDEBUG(DEBUG_CONFIG, "dial next on pickup: %s\n",param);
173 if (!strcmp(option,"alarm"))
175 SCPY(ext->alarm, param);
177 PDEBUG(DEBUG_CONFIG, "alarm message (if prefix): %s\n",param);
179 if (!strcmp(option,"cfu"))
181 SCPY(ext->cfu, param);
183 PDEBUG(DEBUG_CONFIG, "call forward unconditional: %s\n",param);
185 if (!strcmp(option,"cfb"))
187 SCPY(ext->cfb, param);
189 PDEBUG(DEBUG_CONFIG, "call forward when busy: %s\n",param);
191 if (!strcmp(option,"cfnr"))
193 SCPY(ext->cfnr, param);
195 PDEBUG(DEBUG_CONFIG, "call forward on no response: %s\n",param);
197 if (!strcmp(option,"cfnr_delay"))
199 ext->cfnr_delay = atoi(param);
200 if (ext->cfnr_delay < 0)
203 PDEBUG(DEBUG_CONFIG, "call forward no response delay: %d\n",ext->cfnr_delay);
205 if (!strcmp(option,"cfp"))
207 SCPY(ext->cfp, param);
209 PDEBUG(DEBUG_CONFIG, "call forward parallel: %s\n",param);
211 if (!strcmp(option,"change_forward"))
216 if (!strcasecmp(param,ext_yesno[i]))
222 ext->change_forward = i;
223 PDEBUG(DEBUG_CONFIG, "allow the change of forwarding: %s\n", ext_yesno[i]);
226 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_forward: %s\n", param);
229 if (!strcmp(option,"interfaces"))
231 SCPY(ext->interfaces, param);
233 PDEBUG(DEBUG_CONFIG, "interfaces to ring calls to extension: %s %s\n",param,param2);
235 if (!strcmp(option,"callerid"))
237 ext->callerid_present = INFO_PRESENT_ALLOWED;
238 if (!strncasecmp(param2, "anonymous", 9))
239 ext->callerid_present = INFO_PRESENT_RESTRICTED;
240 if (!strncasecmp(param, "non", 3))
242 ext->callerid[0] = '\0';
243 ext->callerid_present = INFO_PRESENT_NOTAVAIL;
244 ext->callerid_type = INFO_NTYPE_UNKNOWN;
245 PDEBUG(DEBUG_CONFIG, "caller id: ID NOT AVAILABLE\n");
251 ext->callerid_type = INFO_NTYPE_INTERNATIONAL;
252 SCPY(ext->callerid, param+1);
253 PDEBUG(DEBUG_CONFIG, "caller id: %s INTERNATIONAL\n",param+1);
257 ext->callerid_type = INFO_NTYPE_NATIONAL;
258 SCPY(ext->callerid, param+1);
259 PDEBUG(DEBUG_CONFIG, "caller id: %s NATIONAL\n",param+1);
263 ext->callerid_type = INFO_NTYPE_SUBSCRIBER;
264 SCPY(ext->callerid, param+1);
265 PDEBUG(DEBUG_CONFIG, "caller id: %s SUBSCRIBER\n",param+1);
268 ext->callerid_type = INFO_NTYPE_UNKNOWN;
269 SCPY(ext->callerid, param);
270 PDEBUG(DEBUG_CONFIG, "caller id: %s UNKNOWN\n",param);
272 ext->callerid[sizeof(ext->callerid)-1] = 0;
274 if (!strcmp(option,"id_next_call"))
276 ext->id_next_call_present = INFO_PRESENT_ALLOWED;
277 if (!strncasecmp(param2, "anonymous", 9))
278 ext->id_next_call_present = INFO_PRESENT_RESTRICTED;
279 if (param[0] == '\0')
281 ext->id_next_call_present = -1;
282 PDEBUG(DEBUG_CONFIG, "id next call: no id for next call\n");
284 if (!strncasecmp(param, "none", 3))
286 ext->id_next_call[0] = '\0';
287 ext->id_next_call_present = INFO_PRESENT_NOTAVAIL;
288 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
289 PDEBUG(DEBUG_CONFIG, "id next call: ID NOT AVAILABLE\n");
295 ext->id_next_call_type = INFO_NTYPE_INTERNATIONAL;
296 SCPY(ext->id_next_call, param+1);
297 PDEBUG(DEBUG_CONFIG, "id next call: %s INTERNATIONAL\n",param+1);
301 ext->id_next_call_type = INFO_NTYPE_NATIONAL;
302 SCPY(ext->id_next_call, param+1);
303 PDEBUG(DEBUG_CONFIG, "id next call: %s NATIONAL\n",param+1);
307 ext->id_next_call_type = INFO_NTYPE_SUBSCRIBER;
308 SCPY(ext->id_next_call, param+1);
309 PDEBUG(DEBUG_CONFIG, "id next call: %s SUBSCRIBER\n",param+1);
312 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
313 SCPY(ext->id_next_call, param);
314 PDEBUG(DEBUG_CONFIG, "id next call: %s UNKNOWN\n",param);
320 if (!strcmp(option,"change_callerid"))
325 if (!strcasecmp(param,ext_yesno[i]))
331 ext->change_callerid = i;
332 PDEBUG(DEBUG_CONFIG, "allow the change of caller id: %s\n", ext_yesno[i]);
335 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_callerid: %s\n", param);
338 if (!strcmp(option,"anon-ignore"))
343 if (!strcasecmp(param,ext_yesno[i]))
349 ext->anon_ignore = i;
350 PDEBUG(DEBUG_CONFIG, "ignore restriction of CLIP & COLP %s\n", ext_yesno[i]);
353 PDEBUG(DEBUG_CONFIG, "unknown parameter given anon-ignore: %s\n", param);
356 if (!strcmp(option,"clip"))
358 if (!strcasecmp(param, "hide"))
359 ext->clip = CLIP_HIDE;
361 ext->clip = CLIP_ASIS;
363 PDEBUG(DEBUG_CONFIG, "clip: %d\n",ext->clip);
365 if (!strcmp(option,"colp"))
367 if (!strcasecmp(param, "hide"))
368 ext->colp = COLP_HIDE;
369 else if (!strcasecmp(param, "force"))
370 ext->colp = COLP_FORCE;
372 ext->colp = COLP_ASIS;
374 PDEBUG(DEBUG_CONFIG, "colp: %d\n",ext->colp);
376 if (!strcmp(option,"clip_prefix"))
378 SCPY(ext->clip_prefix, param);
380 PDEBUG(DEBUG_CONFIG, "clip prefix: %s\n",param);
382 if (!strcmp(option,"keypad"))
387 if (!strcasecmp(param,ext_yesno[i]))
394 PDEBUG(DEBUG_CONFIG, "use keypad to do call control %s\n", ext_yesno[i]);
397 PDEBUG(DEBUG_CONFIG, "unknown parameter given keypad: %s\n", param);
400 if (!strcmp(option,"rights"))
405 if (!strcasecmp(param,ext_rights[i]))
412 PDEBUG(DEBUG_CONFIG, "rights to dial: %s\n", ext_rights[i]);
415 PDEBUG(DEBUG_CONFIG, "given rights unknown: %s\n", param);
418 if (!strcmp(option,"delete_ext"))
423 if (!strcasecmp(param,ext_yesno[i]))
430 PDEBUG(DEBUG_CONFIG, "enables the delete key function for external calls: %s\n", ext_yesno[i]);
433 PDEBUG(DEBUG_CONFIG, "unknown parameter given delete: %s\n", param);
436 if (!strcmp(option,"noknocking"))
441 if (!strcasecmp(param,ext_yesno[i]))
448 PDEBUG(DEBUG_CONFIG, "noknocking %s\n", ext_yesno[i]);
451 PDEBUG(DEBUG_CONFIG, "given noknocking param unknown: %s\n", param);
454 if (!strcmp(option,"rx_gain")
455 || !strcmp(option,"rxvol"))
457 ext->rx_gain = atoi(param);
458 if (ext->rx_gain<-8 || ext->rx_gain>8)
461 PDEBUG(DEBUG_CONFIG, "receive volume: %d\n",ext->rx_gain);
463 if (!strcmp(option,"tx_gain")
464 || !strcmp(option,"txvol"))
466 ext->tx_gain = atoi(param);
467 if (ext->tx_gain<-8 || ext->tx_gain>8)
470 PDEBUG(DEBUG_CONFIG, "transmit volume: %d\n",ext->tx_gain);
472 if (!strcmp(option,"own_setup"))
477 if (!strcasecmp(param,ext_yesno[i]))
484 PDEBUG(DEBUG_CONFIG, "own_setup %s\n", ext_yesno[i]);
487 PDEBUG(DEBUG_CONFIG, "given own_setup param unknown: %s\n", param);
490 if (!strcmp(option,"own_proceeding"))
495 if (!strcasecmp(param,ext_yesno[i]))
501 ext->own_proceeding = i;
502 PDEBUG(DEBUG_CONFIG, "own_proceeding %s\n", ext_yesno[i]);
505 PDEBUG(DEBUG_CONFIG, "given own_proceeding param unknown: %s\n", param);
508 if (!strcmp(option,"own_alerting"))
513 if (!strcasecmp(param,ext_yesno[i]))
519 ext->own_alerting = i;
520 PDEBUG(DEBUG_CONFIG, "own_alerting %s\n", ext_yesno[i]);
523 PDEBUG(DEBUG_CONFIG, "given own_alerting param unknown: %s\n", param);
526 if (!strcmp(option,"own_cause"))
531 if (!strcasecmp(param,ext_yesno[i]))
538 PDEBUG(DEBUG_CONFIG, "own_cause %s\n", ext_yesno[i]);
541 PDEBUG(DEBUG_CONFIG, "given own_cause param unknown: %s\n", param);
544 if (!strcmp(option,"facility"))
549 if (!strcasecmp(param,ext_yesno[i]))
556 PDEBUG(DEBUG_CONFIG, "facility %s\n", ext_yesno[i]);
559 PDEBUG(DEBUG_CONFIG, "given facility param unknown: %s\n", param);
562 if (!strcmp(option,"display_cause"))
564 if (!strcasecmp(param, "german"))
565 ext->display_cause = DISPLAY_CAUSE_GERMAN;
566 else if (!strcasecmp(param, "english"))
567 ext->display_cause = DISPLAY_CAUSE_ENGLISH;
568 else if (!strcasecmp(param, "german-location"))
569 ext->display_cause = DISPLAY_LOCATION_GERMAN;
570 else if (!strcasecmp(param, "english-location"))
571 ext->display_cause = DISPLAY_LOCATION_ENGLISH;
572 else if (!strcasecmp(param, "number"))
573 ext->display_cause = DISPLAY_CAUSE_NUMBER;
575 ext->display_cause = DISPLAY_CAUSE_NONE;
577 PDEBUG(DEBUG_CONFIG, "display cause: %d\n",ext->display_cause);
580 if (!strcmp(option,"display_ext"))
582 if (!strcasecmp(param, "number"))
583 ext->display_ext = DISPLAY_CID_NUMBER;
584 else if (!strcasecmp(param, "abbrev"))
585 ext->display_ext = DISPLAY_CID_ABBREVIATION;
586 else if (!strcasecmp(param, "name"))
587 ext->display_ext = DISPLAY_CID_NAME;
588 else if (!strcasecmp(param, "number-name"))
589 ext->display_ext = DISPLAY_CID_NUMBER_NAME;
590 else if (!strcasecmp(param, "name-number"))
591 ext->display_ext = DISPLAY_CID_NAME_NUMBER;
592 else if (!strcasecmp(param, "abbrev-number"))
593 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER;
594 else if (!strcasecmp(param, "abbrev-name"))
595 ext->display_ext = DISPLAY_CID_ABBREV_NAME;
596 else if (!strcasecmp(param, "abbrev-name-number"))
597 ext->display_ext = DISPLAY_CID_ABBREV_NAME_NUMBER;
598 else if (!strcasecmp(param, "abbrev-number-name"))
599 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER_NAME;
601 ext->display_ext = DISPLAY_CID_ASIS;
603 PDEBUG(DEBUG_CONFIG, "display ext: %d\n",ext->display_ext);
606 if (!strcmp(option,"display_ext"))
611 if (!strcasecmp(param,ext_yesno[i]))
617 ext->display_ext = i;
618 PDEBUG(DEBUG_CONFIG, "display ext %s\n", ext_yesno[i]);
621 PDEBUG(DEBUG_CONFIG, "given display_ext param unknown: %s\n", param);
624 if (!strcmp(option,"display_int"))
629 if (!strcasecmp(param,ext_yesno[i]))
635 ext->display_int = i;
636 PDEBUG(DEBUG_CONFIG, "display int %s\n", ext_yesno[i]);
639 PDEBUG(DEBUG_CONFIG, "given display_int param unknown: %s\n", param);
642 if (!strcmp(option,"display_fake"))
647 if (!strcasecmp(param,ext_yesno[i]))
653 ext->display_fake = i;
654 PDEBUG(DEBUG_CONFIG, "display fake caller ids %s\n", ext_yesno[i]);
657 PDEBUG(DEBUG_CONFIG, "given display_fake param unknown: %s\n", param);
660 if (!strcmp(option,"display_anon"))
665 if (!strcasecmp(param,ext_yesno[i]))
671 ext->display_anon = i;
672 PDEBUG(DEBUG_CONFIG, "display anonymouse ids %s\n", ext_yesno[i]);
675 PDEBUG(DEBUG_CONFIG, "given display_anon param unknown: %s\n", param);
678 if (!strcmp(option,"display_menu"))
683 if (!strcasecmp(param,ext_yesno[i]))
689 ext->display_menu = i;
690 PDEBUG(DEBUG_CONFIG, "display menu %s\n", ext_yesno[i]);
693 PDEBUG(DEBUG_CONFIG, "given display_menu param unknown: %s\n", param);
696 if (!strcmp(option,"display_dialing"))
701 if (!strcasecmp(param,ext_yesno[i]))
707 ext->display_dialing = i;
708 PDEBUG(DEBUG_CONFIG, "display dialing %s\n", ext_yesno[i]);
711 PDEBUG(DEBUG_CONFIG, "given display_dialing param unknown: %s\n", param);
714 if (!strcmp(option,"display_name"))
719 if (!strcasecmp(param,ext_yesno[i]))
725 ext->display_name = i;
726 PDEBUG(DEBUG_CONFIG, "display name %s\n", ext_yesno[i]);
729 PDEBUG(DEBUG_CONFIG, "given display_name param unknown: %s\n", param);
732 if (!strcmp(option,"tones_dir"))
734 if (param[strlen(param)-1] == '/')
735 param[strlen(param)-1]=0;
736 SCPY(ext->tones_dir, param);
738 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
740 if (!strcmp(option,"record"))
742 if (!strcasecmp(param, "mono"))
743 ext->record = CODEC_MONO;
744 else if (!strcasecmp(param, "stereo"))
745 ext->record = CODEC_STEREO;
746 else if (!strcasecmp(param, "8bit"))
747 ext->record = CODEC_8BIT;
748 else if (!strcasecmp(param, "law"))
749 ext->record = CODEC_LAW;
751 ext->record = CODEC_OFF;
752 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
754 if (!strcmp(option,"password"))
756 SCPY(ext->password, param);
758 PDEBUG(DEBUG_CONFIG, "password: %s\n",param);
760 if (!strcmp(option,"vbox_mode"))
762 if (!strcasecmp(param, "parallel"))
763 ext->vbox_mode = VBOX_MODE_PARALLEL;
764 else if (!strcasecmp(param, "announcement"))
765 ext->vbox_mode = VBOX_MODE_ANNOUNCEMENT;
767 ext->vbox_mode = VBOX_MODE_NORMAL;
768 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
770 if (!strcmp(option,"vbox_codec"))
772 if (!strcasecmp(param, "stereo"))
773 ext->vbox_codec = CODEC_STEREO;
774 else if (!strcasecmp(param, "8bit"))
775 ext->vbox_codec = CODEC_8BIT;
776 else if (!strcasecmp(param, "law"))
777 ext->vbox_codec = CODEC_LAW;
779 ext->vbox_codec = CODEC_MONO;
780 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
782 if (!strcmp(option,"vbox_time"))
784 ext->vbox_time = atoi(param);
785 if (ext->vbox_time < 0)
788 PDEBUG(DEBUG_CONFIG, "vbox time to record: %d\n",ext->vbox_time);
790 if (!strcmp(option,"vbox_display"))
792 if (!strcasecmp(param, "detailed")
793 || !strcasecmp(param, "detailled"))
794 ext->vbox_display = VBOX_DISPLAY_DETAILED;
795 else if (!strcasecmp(param, "off"))
796 ext->vbox_display = VBOX_DISPLAY_OFF;
798 ext->vbox_display = VBOX_DISPLAY_BRIEF;
799 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
801 if (!strcmp(option,"vbox_language"))
803 if (!strcasecmp(param, "german"))
804 ext->vbox_language = VBOX_LANGUAGE_GERMAN;
806 ext->vbox_language = VBOX_LANGUAGE_ENGLISH;
807 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
809 if (!strcmp(option,"vbox_email"))
811 SCPY(ext->vbox_email, param);
812 PDEBUG(DEBUG_CONFIG, "given vbox email: %s\n", param);
814 if (!strcmp(option,"vbox_email_file"))
819 if (!strcasecmp(param,ext_yesno[i]))
825 ext->vbox_email_file = i;
826 PDEBUG(DEBUG_CONFIG, "attach audio file %s\n", ext_yesno[i]);
829 PDEBUG(DEBUG_CONFIG, "given vbox_email_file param unknown: %s\n", param);
832 if (!strcmp(option,"vbox_free"))
837 if (!strcasecmp(param,ext_yesno[i]))
844 PDEBUG(DEBUG_CONFIG, "vbox_free %s\n", ext_yesno[i]);
847 PDEBUG(DEBUG_CONFIG, "given vbox_free param unknown: %s\n", param);
850 if (!strcmp(option,"last_in"))
852 if (param[0] && last_in_count<MAX_REMEMBER)
854 SCPY(ext->last_in[last_in_count], param);
857 PDEBUG(DEBUG_CONFIG, "last_in dialed number: %s\n",param);
859 if (!strcmp(option,"last_out"))
861 if (param[0] && last_out_count<MAX_REMEMBER)
863 SCPY(ext->last_out[last_out_count], param);
866 PDEBUG(DEBUG_CONFIG, "last_out dialed number: %s\n",param);
868 if (!strcmp(option,"datacall"))
873 if (!strcasecmp(param,ext_yesno[i]))
880 PDEBUG(DEBUG_CONFIG, "datacall %s\n", ext_yesno[i]);
883 PDEBUG(DEBUG_CONFIG, "given datacall param unknown: %s\n", param);
886 if (!strcmp(option,"seconds"))
891 if (!strcasecmp(param,ext_yesno[i]))
897 ext->no_seconds = 1-i;
898 PDEBUG(DEBUG_CONFIG, "seconds %s\n", ext_yesno[i]);
901 PDEBUG(DEBUG_CONFIG, "unknown param for seconds: %s\n", param);
905 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n",filename,line,option);
916 * writes extension for given extension number from structure
918 int write_extension(struct extension *ext, char *number)
924 if (number[0] == '\0')
927 SPRINT(filename, "%s/%s/settings", EXTENSION_DATA, number);
929 if (!(fp = fopen(filename, "w")))
931 PERROR("Cannot open settings: \"%s\"\n", filename);
935 fprintf(fp,"# Settings of extension %s\n\n", number);
937 fprintf(fp,"# Name of extension:\n");
938 fprintf(fp,"name %s\n\n",ext->name);
940 fprintf(fp,"# Predialed prefix after pick-up of the phone\n");
941 fprintf(fp,"prefix %s\n\n",ext->prefix);
943 fprintf(fp,"# Next prefix to dial pick-up of the phone\n");
944 fprintf(fp,"# This will be cleared on hangup.\n");
945 fprintf(fp,"next %s\n\n",ext->next);
947 // fprintf(fp,"# Set up alarm message after prefix is dialed and connection is established\n");
948 // fprintf(fp,"alarm %s\n\n",ext->alarm);
950 fprintf(fp,"# Interface(s) to ring on calls to extension (as named in interface.conf)\n");
951 fprintf(fp,"# Seperate multiple interfaces by using komma without spaces\n");
952 fprintf(fp,"# Example: Int would ring on the interface with the name \"Int\"\n");
953 fprintf(fp,"# Int1,Int2 would ring incoming calls on both interfaces Int1 and Int2.\n");
954 fprintf(fp,"interfaces %s\n\n",ext->interfaces);
956 fprintf(fp,"# Call Forward Unconditional (CFU)\n");
957 fprintf(fp,"# No port will be called, CFB, CFNR and CFP is ignored.\n");
958 fprintf(fp,"# Use keyword \"vbox\" to forward call directly to answering machine.\n");
959 fprintf(fp,"cfu %s\n\n",ext->cfu);
961 fprintf(fp,"# Call Forward when Busy (CFB)\n");
962 fprintf(fp,"# If the extension is in use at least once, this forward is done.\n");
963 fprintf(fp,"# In case of busy line, CFNR and CFP is ignored.\n");
964 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine when busy.\n");
965 fprintf(fp,"cfb %s\n\n",ext->cfb);
967 fprintf(fp,"# Call Forward on No Response (CFNR)\n");
968 fprintf(fp,"# If noone answers, the call is forwarded, ports and CFP will be released.\n");
969 fprintf(fp,"# The default delay is 20 seconds.\n");
970 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine on no response.\n");
971 fprintf(fp,"cfnr %s\n",ext->cfnr);
972 fprintf(fp,"cfnr_delay %d\n\n",ext->cfnr_delay);
974 fprintf(fp,"# Call Forward Parallel (CFP)\n");
975 fprintf(fp,"# Call will ring on the forwarded number, simulaniousely with the ports.\n");
976 fprintf(fp,"cfp %s\n\n",ext->cfp);
978 fprintf(fp,"# Allow user to change call forwarding.\n");
979 fprintf(fp,"change_forward %s\n\n", ext_yesno[ext->change_forward]);
981 fprintf(fp,"# Caller id\n# This must be one of the following:\n");
982 fprintf(fp,"# <number> (as dialed from your local area)\n");
983 fprintf(fp,"# <number> anonymous (will only be shown to emergency phones)\n");
984 fprintf(fp,"# none (no number available at all)\n");
985 fprintf(fp,"# by default the number is of type UNKNOWN (for MULTIPOINT lines)\n");
986 fprintf(fp,"# if your caller id is not screened on outgoing calls use one of the following:\n");
987 fprintf(fp,"# use prefix 'i' for TYPE INTERNATIONAL (i<county code><areacode+number>)\n");
988 fprintf(fp,"# use prefix 'n' for TYPE NATIONAL (n<areacode+number>)\n");
989 fprintf(fp,"# use prefix 's' for TYPE SUBSCRIBER (s<local number>)\n");
990 if (ext->callerid_present == INFO_PRESENT_NOTAVAIL)
991 fprintf(fp,"callerid none\n\n");
994 switch(ext->callerid_type)
996 case INFO_NTYPE_INTERNATIONAL:
997 fprintf(fp,"callerid i%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
999 case INFO_NTYPE_NATIONAL:
1000 fprintf(fp,"callerid n%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1002 case INFO_NTYPE_SUBSCRIBER:
1003 fprintf(fp,"callerid s%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1006 fprintf(fp,"callerid %s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1010 fprintf(fp,"# Caller id for next call (see caller id)\n");
1011 if (ext->id_next_call_present < 0)
1012 fprintf(fp,"id_next_call \n\n");
1013 else if (ext->id_next_call_present == INFO_PRESENT_NOTAVAIL)
1014 fprintf(fp,"id_next_call none\n\n");
1017 switch(ext->id_next_call_type)
1019 case INFO_NTYPE_INTERNATIONAL:
1020 fprintf(fp,"id_next_call i%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1022 case INFO_NTYPE_NATIONAL:
1023 fprintf(fp,"id_next_call n%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1025 case INFO_NTYPE_SUBSCRIBER:
1026 fprintf(fp,"id_next_call s%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1029 fprintf(fp,"id_next_call %s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1033 fprintf(fp,"# Allow user to change caller ID.\n");
1034 fprintf(fp,"change_callerid %s\n\n", ext_yesno[ext->change_callerid]);
1036 fprintf(fp,"# Caller Line Identification Presentation (CLIP)\n");
1037 fprintf(fp,"# clip (asis|hide)\n");
1038 fprintf(fp,"# asis: On forwarded calls the CLIP is used as presented by the calling party.\n");
1039 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1043 fprintf(fp,"clip hide\n\n");
1046 fprintf(fp,"clip asis\n\n");
1049 fprintf(fp,"# Connected Line Identification Presentation (COLP)\n");
1050 fprintf(fp,"# colp (asis|hide|force)\n");
1051 fprintf(fp,"# asis: Provides colp as defined by the extension's caller id.\n");
1052 fprintf(fp,"# On forwarded calls the COLP is used as presented by the called party.\n");
1053 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1054 fprintf(fp,"# force: If COLP is not presented by forwarded calls the dialed number is used.\n");
1058 fprintf(fp,"colp hide\n\n");
1061 fprintf(fp,"colp force\n\n");
1064 fprintf(fp,"colp asis\n\n");
1067 fprintf(fp,"# CLIP Prefix\n");
1068 fprintf(fp,"# Adds a prefix to incoming caller IDs, so telephones will be able to respond\n");
1069 fprintf(fp,"# to unanswered calls from their list. The prefix must be the digit(s) to get\n");
1070 fprintf(fp,"# an external line. The caller ID will then be extendet so that they can be\n");
1071 fprintf(fp,"# dialed from internal telephones. Many telephones have this feature, but some\n");
1072 fprintf(fp,"# don't.\n");
1073 fprintf(fp,"clip_prefix %s\n\n",ext->clip_prefix);
1075 fprintf(fp,"# Keypad control\n");
1076 fprintf(fp,"# If supported by telephone, pressing a key on the keypad will not result in\n");
1077 fprintf(fp,"# DTMF tone, but the digit is transmitted via D-channel diaing info.\n");
1078 fprintf(fp,"keypad %s\n\n",(ext->keypad)?"yes":"no");
1080 fprintf(fp,"# Ignore restriction of COLP and CLIP\n");
1081 fprintf(fp,"# In this case even restricted numbers are presented to this extension.\n");
1082 fprintf(fp,"# This also works for incoming external anonymous calls IF:\n");
1083 fprintf(fp,"# You have the CLIRIGN feature like POLICE or equivalent.\n");
1084 fprintf(fp,"anon-ignore %s\n\n",(ext->anon_ignore)?"yes":"no");
1086 fprintf(fp,"# Dialing rights (none|internal|local|national|international)\n");
1087 fprintf(fp,"rights %s\n\n",ext_rights[ext->rights]);
1089 fprintf(fp,"# Delete function for external calls. '*' will delete the last digit, '#' will\n");
1090 fprintf(fp,"# delete the complete number. Also enable 'display_dialing' to see on the\n");
1091 fprintf(fp,"# display what actually happens.\n");
1092 fprintf(fp,"delete_ext %s\n\n",ext_yesno[ext->delete_ext]);
1094 fprintf(fp,"# If noknocking is enabled, the caller will get a busy message when the\n");
1095 fprintf(fp,"# extension is doing at least one call.\n");
1096 fprintf(fp,"noknocking %s\n\n",ext_yesno[ext->noknocking]);
1098 fprintf(fp,"# Transmit volume (-8 .. 8)\n");
1099 fprintf(fp,"# 0 = normal\n");
1100 fprintf(fp,"# 1 = double, 2 = quadrupel, 8 = 256 times (amplitude)\n");
1101 fprintf(fp,"# -1 = half, -2 = quarter, 8 = 1/256th (amplitude)\n");
1102 fprintf(fp,"# Audio data is limited to the maximum value when exceeds limit.\n");
1103 fprintf(fp,"tx_gain %d\n\n",ext->tx_gain);
1105 fprintf(fp,"# Receive volume (-8 .. 8)\n");
1106 fprintf(fp,"# (see tx_gain)\n");
1107 fprintf(fp,"rx_gain %d\n\n",ext->rx_gain);
1110 fprintf(fp,"# Force to use tones and announcements generated by the pbx.\n");
1111 fprintf(fp,"# For internal calls always own tones are used. You may specify own tones for\n");
1112 fprintf(fp,"# different call states:\n");
1113 fprintf(fp,"# own_setup (dialtone and during dialing)\n");
1114 fprintf(fp,"# own_proceeding (call in poceeding state)\n");
1115 fprintf(fp,"# own_alerting (call is ringing)\n");
1116 fprintf(fp,"# own_cause (when the call gets disconnected or failed to be completed)\n");
1117 fprintf(fp,"own_setup %s\n",ext_yesno[ext->own_setup]);
1118 fprintf(fp,"own_proceeding %s\n",ext_yesno[ext->own_proceeding]);
1119 fprintf(fp,"own_alerting %s\n",ext_yesno[ext->own_alerting]);
1120 fprintf(fp,"own_cause %s\n\n",ext_yesno[ext->own_cause]);
1122 fprintf(fp,"# Allow facility information to be transfered to the telephone.\n");
1123 fprintf(fp,"# This is equired to receive advice of charge.\n");
1124 fprintf(fp,"facility %s\n\n",ext_yesno[ext->facility]);
1126 fprintf(fp,"# Display clear causes using display messages (Q.850)\n# This must be one of the following:\n");
1127 fprintf(fp,"# none (no displaying of clear causes)\n");
1128 fprintf(fp,"# english (display cause text in english)\n");
1129 fprintf(fp,"# german (display cause text in german)\n");
1130 fprintf(fp,"# number (display cause number only)\n");
1131 fprintf(fp,"# english-location (display cause text in english and location)\n");
1132 fprintf(fp,"# german-location (display cause text in german and location)\n");
1133 switch(ext->display_cause)
1135 case DISPLAY_CAUSE_ENGLISH:
1136 fprintf(fp,"display_cause english\n\n");
1138 case DISPLAY_CAUSE_GERMAN:
1139 fprintf(fp,"display_cause german\n\n");
1141 case DISPLAY_LOCATION_ENGLISH:
1142 fprintf(fp,"display_cause english-location\n\n");
1144 case DISPLAY_LOCATION_GERMAN:
1145 fprintf(fp,"display_cause german-location\n\n");
1147 case DISPLAY_CAUSE_NUMBER:
1148 fprintf(fp,"display_cause number\n\n");
1151 fprintf(fp,"display_cause none\n\n");
1154 fprintf(fp,"# Display external caller ids using display override (yes or no)\n");
1155 fprintf(fp,"# example: \"15551212\"\n");
1156 fprintf(fp,"display_ext %s\n\n",(ext->display_ext)?"yes":"no");
1158 fprintf(fp,"# Display internal caller ids using display override (yes or no)\n");
1159 fprintf(fp,"# example: \"200 (int)\"\n");
1160 fprintf(fp,"display_int %s\n\n",(ext->display_int)?"yes":"no");
1162 fprintf(fp,"# Display if calls are anonymous using display override (yes or no)\n");
1163 fprintf(fp,"# This makes only sense if the anon-ignore feature is enabled.\n");
1164 fprintf(fp,"# example: \"15551212 anon\"\n");
1165 fprintf(fp,"display_anon %s\n\n",(ext->display_anon)?"yes":"no");
1167 fprintf(fp,"# Display fake caller ids using display override (yes or no)\n");
1168 fprintf(fp,"# If the caller uses \"clip no screening\", you will see if the number is\n");
1169 fprintf(fp,"# real or fake\n");
1170 fprintf(fp,"# example: \"15551212 fake\"\n");
1171 fprintf(fp,"display_fake %s\n\n",(ext->display_fake)?"yes":"no");
1173 fprintf(fp,"# Display caller's name if available. (yes or no)\n");
1174 fprintf(fp,"# example: \"15551212 Axel\"\n");
1175 fprintf(fp,"display_name %s\n\n",(ext->display_name)?"yes":"no");
1177 fprintf(fp,"# Display menu when '*' and '#' is pressed. The menu shows all prefixes for\n");
1178 fprintf(fp,"# internal dialing by pressing '*' for previous prefix and '#' for next prefix.\n");
1179 fprintf(fp,"# Also the dialed prefix is show on display. (yes or no)\n");
1180 fprintf(fp,"display_menu %s\n\n",(ext->display_menu)?"yes":"no");
1182 fprintf(fp,"# Display digits as they are interpreted by pbx. (yes or no)\n");
1183 fprintf(fp,"display_dialing %s\n\n",(ext->display_dialing)?"yes":"no");
1185 fprintf(fp,"# Tones directory for announcements and patterns\n");
1186 fprintf(fp,"# Enter nothing for default tones as selected by options.conf.\n");
1187 fprintf(fp,"tones_dir %s\n\n",ext->tones_dir);
1189 fprintf(fp,"# Record calls to extension's directory. The file is written as wave.\n");
1190 fprintf(fp,"# This must be one of the following:\n");
1191 fprintf(fp,"# off (no recording)\n");
1192 fprintf(fp,"# mono (records wave 16 bit mono, 128kbits/s)\n");
1193 fprintf(fp,"# stereo (records wave 32 bit stereo, 256kbits/s)\n");
1194 fprintf(fp,"# 8bit (records wave 8 bit mono, 64kbits/s)\n");
1195 fprintf(fp,"# law (records xLaw encoded, as specified in options.conf, 64kbps/s)\n");
1199 fprintf(fp,"record mono\n\n");
1202 fprintf(fp,"record stereo\n\n");
1205 fprintf(fp,"record 8bit\n\n");
1208 fprintf(fp,"record law\n\n");
1211 fprintf(fp,"record off\n\n");
1214 fprintf(fp,"# Password for callback and login\n");
1215 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1216 fprintf(fp,"password %s\n\n",ext->password);
1218 fprintf(fp,"# The Answering Machine. Enter the mode of answering machine.\n");
1219 fprintf(fp,"# This must be one of the following:\n");
1220 fprintf(fp,"# normal (plays announcement and records after that)\n");
1221 fprintf(fp,"# parallel (plays announcement and records also DURING announcement.)\n");
1222 fprintf(fp,"# announcement (just plays announcement and hangs up)\n");
1223 switch(ext->vbox_mode)
1225 case VBOX_MODE_PARALLEL:
1226 fprintf(fp,"vbox_mode parallel\n\n");
1228 case VBOX_MODE_ANNOUNCEMENT:
1229 fprintf(fp,"vbox_mode announcement\n\n");
1232 fprintf(fp,"vbox_mode normal\n\n");
1235 fprintf(fp,"# The Answering Machine. Enter the type of codec for recording.\n");
1236 fprintf(fp,"# This must be one of the following:\n");
1237 fprintf(fp,"# law (alaw/ulas codec, as specified in options.conf)\n");
1238 fprintf(fp,"# mono (16 bit mono wave file)\n");
1239 fprintf(fp,"# stereo (16 bit stereo wave file)\n");
1240 fprintf(fp,"# 8bit (8 bit mono wave file)\n");
1241 switch(ext->vbox_codec)
1244 fprintf(fp,"vbox_codec law\n\n");
1247 fprintf(fp,"vbox_codec stereo\n\n");
1250 fprintf(fp,"vbox_codec 8bit\n\n");
1253 fprintf(fp,"vbox_codec mono\n\n");
1256 fprintf(fp,"# The Answering Machine. Enter maximum time to record after announcement.\n");
1257 fprintf(fp,"# Leave empty, enter \"infinite\" or give time in seconds.\n");
1258 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1260 fprintf(fp,"vbox_time %d\n\n",ext->vbox_time);
1262 fprintf(fp,"vbox_time infinite\n\n");
1264 fprintf(fp,"# The Answering Machine. Enter mode for display current state.\n");
1265 fprintf(fp,"# This must be one of the following:\n");
1266 fprintf(fp,"# brief (displays brief information, for small displays)\n");
1267 fprintf(fp,"# detailed (displays detailed information, for larger displays)\n");
1268 fprintf(fp,"# off (don't display anything)\n");
1269 switch(ext->vbox_display)
1271 case VBOX_DISPLAY_OFF:
1272 fprintf(fp,"vbox_display off\n\n");
1274 case VBOX_DISPLAY_DETAILED:
1275 fprintf(fp,"vbox_display detailed\n\n");
1278 fprintf(fp,"vbox_display brief\n\n");
1281 fprintf(fp,"# The Answering Machine. Enter type of language: \"english\" or \"german\"\n");
1282 fprintf(fp,"# Display information of the menu, will be provided as specified.\n");
1283 fprintf(fp,"# The menu's voice is located in \"vbox_english\" and \"vbox_german\".\n");
1284 if (ext->vbox_language)
1285 fprintf(fp,"vbox_language german\n\n");
1287 fprintf(fp,"vbox_language english\n\n");
1289 fprintf(fp,"# The Answering Machine. Enter email to send incoming messages to:\n");
1290 fprintf(fp,"# All incoming message will be send to the given address.\n");
1291 fprintf(fp,"# The audio file is attached if \"vbox_email_file\" is 'yes'\n");
1292 fprintf(fp,"vbox_email %s\n", ext->vbox_email);
1293 fprintf(fp,"vbox_email_file %s\n\n",ext_yesno[ext->vbox_email_file]);
1295 fprintf(fp,"# If audio path is connected prior answering of a call, say 'yes'\n");
1296 fprintf(fp,"# will cause the call to be billed after playing the announcement. (yes or no)\n");
1297 fprintf(fp,"vbox_free %s\n\n",(ext->vbox_free)?"yes":"no");
1299 fprintf(fp,"# Accept incoming data calls as it would be an audio call.\n");
1300 fprintf(fp,"datacall %s\n\n",ext_yesno[ext->datacall]);
1302 fprintf(fp,"# Include seconds (time) in the connect message. (Should be always enabled.)\n");
1303 fprintf(fp,"seconds %s\n\n",ext_yesno[1-ext->no_seconds]);
1305 fprintf(fp,"# Last outgoing and incoming numbers (including prefix)\n");
1307 while(i < MAX_REMEMBER)
1309 if (ext->last_out[i][0])
1310 fprintf(fp,"last_out %s\n",ext->last_out[i]);
1314 while(i < MAX_REMEMBER)
1316 if (ext->last_in[i][0])
1317 fprintf(fp,"last_in %s\n",ext->last_in[i]);
1328 /* write log for extension
1331 int write_log(char *number, char *callerid, char *calledid, time_t start, time_t stop, int aoce, int cause, int location)
1333 const char *mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1338 if (callerid[0] == '\0')
1339 callerid = (char *)"<unknown>";
1341 SPRINT(filename, "%s/%s/log", EXTENSION_DATA, number);
1343 if (!(fp = fopen(filename, "a")))
1345 PERROR("Cannot open log: \"%s\"\n", filename);
1349 tm = localtime(&start);
1350 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);
1352 fprintf(fp," %2ld:%02d:%02d", (stop-start)/3600, (((unsigned int)(stop-start))/60)%60, ((unsigned int)(stop-start))%60);
1354 fprintf(fp," --:--:--");
1355 fprintf(fp," %s -> %s", callerid, calledid);
1356 if (cause >= 1 && cause <=127 && location>=0 && location<=15)
1357 fprintf(fp," (cause=%d '%s' location=%d '%s')", cause, isdn_cause[cause].german, location, isdn_location[location].german);
1367 * reads phone book of extextension and compares the given elements which
1368 * are: abreviation, phone number, name (name is not compared)
1369 * on success a 1 is returned and the pointers of elements are set to the
1372 int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, char **name_pointer)
1377 static char abbrev[32], phone[256], name[256];
1378 unsigned int line,i;
1380 int found = 0, found_if_more_digits = 0;
1382 SPRINT(filename, "%s/%s/phonebook", EXTENSION_DATA, number);
1384 if (!(fp = fopen(filename, "r")))
1386 PERROR("Cannot open phonebook: \"%s\"\n", filename);
1391 while((fgets(buffer, sizeof(buffer), fp)))
1394 buffer[sizeof(buffer)-1] = '\0';
1395 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1398 while(*p <= 32) /* skip spaces */
1404 if (*p==0 || *p=='#') /* ignore comments and empty line */
1411 i=0; /* read abbrev */
1414 if (i+1 >= sizeof(abbrev))
1416 PERROR_RUNTIME("Error in %s (line %d): abbrev too long.\n",filename,line);
1423 while(*p <= 32) /* skip spaces */
1430 if (*p!=0 && *p!='#') /* phone */
1432 i=0; /* read phone */
1435 if (i+1 >= sizeof(phone))
1437 PERROR_RUNTIME("Error in %s (line %d): phone too long.\n",filename,line);
1443 while(*p <= 32) /* skip spaces */
1451 if (*p!=0 && *p!='#') /* name */
1453 i=0; /* read name */
1456 if (i+1 >= sizeof(name))
1458 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1466 if (*abbrev_pointer)
1468 if (!strncmp(*abbrev_pointer, abbrev, strlen(*abbrev_pointer)))
1470 /* may match if abbreviation is longer */
1471 found_if_more_digits = 1;
1473 if (!!strcasecmp(*abbrev_pointer, abbrev))
1477 if (!!strcasecmp(*phone_pointer, phone))
1480 if (!!strcasecmp(*name_pointer, name))
1484 break; /* found entry */
1491 *abbrev_pointer = abbrev;
1492 *phone_pointer = phone;
1493 *name_pointer = name;
1498 if (found_if_more_digits)
1504 /* parsing secrets file
1506 * 'number' specifies the externsion number, not the caller id
1507 * 'remote_id' specifies the dialed number, or the caller id for incoming calls
1508 * the result is the auth, crypt and key string, and 1 is returned.
1509 * on failure or not matching number, the 0 is returned
1511 int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **crypt_pointer, char **key_pointer)
1517 static char auth[64], crypt[64], key[4096];
1518 unsigned int line,i;
1522 SPRINT(filename, "%s/%s/secrets", EXTENSION_DATA, number);
1524 if (!(fp = fopen(filename, "r")))
1526 PERROR("Cannot open secrets: \"%s\"\n", filename);
1531 while((fgets(buffer, sizeof(buffer), fp)))
1534 buffer[sizeof(buffer)-1] = '\0';
1535 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1538 while(*p <= 32) /* skip spaces */
1544 if (*p==0 || *p=='#') /* ignore comments and empty line */
1552 i=0; /* read auth */
1555 if (i+1 >= sizeof(remote))
1557 PERROR_RUNTIME("Error in %s (line %d): remote too long.\n",filename,line);
1564 while(*p <= 32) /* skip spaces */
1571 if (*p!=0 && *p!='#') /* auth */
1573 i=0; /* read auth */
1576 if (i+1 >= sizeof(auth))
1578 PERROR_RUNTIME("Error in %s (line %d): auth too long.\n",filename,line);
1584 while(*p <= 32) /* skip spaces */
1592 if (*p!=0 && *p!='#') /* crypt */
1594 i=0; /* read crypt */
1597 if (i+1 >= sizeof(crypt))
1599 PERROR_RUNTIME("Error in %s (line %d): crypt too long.\n",filename,line);
1605 while(*p <= 32) /* skip spaces */
1613 if (*p!=0 && *p!='#') /* key */
1618 if (i+1 >= sizeof(key))
1620 PERROR_RUNTIME("Error in %s (line %d): key too long.\n",filename,line);
1627 //printf("COMPARING: '%s' with '%s' %s %s %s\n", remote_id, remote, auth, crypt, key);
1629 if (!!strcasecmp(remote, remote_id))
1633 break; /* found entry */
1640 *auth_pointer = auth;
1641 *crypt_pointer = crypt;
1650 * the caller id is given and the name is returned. if the name is not found,
1652 * on success a 1 is returned and the pointers of elements are set to the
1655 char *parse_directory(char *number, int type)
1660 static char phone[32], name[64];
1661 unsigned int line,i;
1665 SPRINT(filename, "%s/directory.list", CONFIG_DATA);
1667 if (!(fp = fopen(filename, "r")))
1669 PERROR("Cannot open directory: \"%s\"\n", filename);
1674 while((fgets(buffer, sizeof(buffer), fp)))
1677 buffer[sizeof(buffer)-1] = '\0';
1678 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1681 while(*p <= 32) /* skip spaces */
1687 if (*p==0 || *p=='#') /* ignore comments and empty line */
1693 i=0; /* read number */
1696 if (i+1 >= sizeof(phone))
1698 PERROR_RUNTIME("Error in %s (line %d): number too long.\n",filename,line);
1705 while(*p <= 32) /* skip spaces */
1712 i=0; /* read name */
1715 if (i+1 >= sizeof(name))
1717 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1724 if (phone[0] == 'i')
1726 if (type != INFO_NTYPE_INTERNATIONAL)
1728 if (!strcmp(number, phone+1))
1735 if (phone[0] == 'n')
1737 if (type != INFO_NTYPE_NATIONAL)
1739 if (!strcmp(number, phone+1))
1746 if (phone[0] == 's')
1748 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1750 if (!strcmp(number, phone+1))
1757 if (!strncmp(phone, options.international, strlen(options.international)))
1759 if (type != INFO_NTYPE_INTERNATIONAL)
1761 if (!strcmp(number, phone+strlen(options.international)))
1768 if (!options.national[0]) /* no national prefix */
1770 if (type == INFO_NTYPE_INTERNATIONAL)
1772 if (!strcmp(number, phone))
1779 if (!strncmp(phone, options.national, strlen(options.national)))
1781 if (type != INFO_NTYPE_NATIONAL)
1783 if (!strcmp(number, phone+strlen(options.national)))
1790 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1792 if (!strcmp(number, phone))
1807 /* parse callbackauth
1809 * searches for the given caller id and returns 1 == true or 0 == false
1811 int parse_callbackauth(char *number, struct caller_info *callerinfo)
1816 unsigned int line,i;
1818 static char caller_type[32], caller_id[64];
1821 SPRINT(filename, "%s/%s/callbackauth", EXTENSION_DATA, number);
1823 if (!(fp = fopen(filename, "r")))
1825 PDEBUG(DEBUG_EPOINT, "Cannot open callbackauth: \"%s\"\n", filename);
1830 while((fgets(buffer, sizeof(buffer), fp)))
1833 buffer[sizeof(buffer)-1] = '\0';
1834 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1837 while(*p <= 32) /* skip spaces */
1843 if (*p==0 || *p=='#') /* ignore comments and empty line */
1849 i=0; /* read caller_type */
1852 if (i+1 >= sizeof(caller_type))
1854 PERROR_RUNTIME("Error in %s (line %d): caller_type too long.\n",filename,line);
1857 caller_type[i+1] = '\0';
1858 caller_type[i++] = *p++;
1861 while(*p <= 32) /* skip spaces */
1868 if (*p!=0 && *p!='#') /* caller_id */
1870 i=0; /* read caller_id */
1873 if (i+1 >= sizeof(caller_id))
1875 PERROR_RUNTIME("Error in %s (line %d): caller_id too long.\n",filename,line);
1878 caller_id[i+1] = '\0';
1879 caller_id[i++] = *p++;
1884 if (caller_type[0]=='\0' && caller_id[0]=='\0')
1887 if (atoi(caller_type) != callerinfo->ntype)
1890 if (!!strcmp(caller_id, callerinfo->id))
1894 break; /* found entry */
1905 /* append line to callbackauth
1908 void append_callbackauth(char *number, struct caller_info *callerinfo)
1913 SPRINT(filename, "%s/%s/callbackauth", EXTENSION_DATA, number);
1915 if (callerinfo->id[0]=='\0')
1917 PERROR("caller has no id.\n");
1920 if (!(fp = fopen(filename, "a")))
1922 PERROR("Cannot open callbackauth: \"%s\"\n", filename);
1926 fprintf(fp, "%6d %s\n", callerinfo->ntype, callerinfo->id);