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,"rxvol"))
473 ext->rxvol = atoi(param);
474 if (ext->rxvol<-8 || ext->rxvol>8)
477 PDEBUG(DEBUG_CONFIG, "receive volume: %d\n",ext->rxvol);
479 if (!strcmp(option,"txvol"))
481 ext->txvol = atoi(param);
482 if (ext->txvol<-8 || ext->txvol>8)
485 PDEBUG(DEBUG_CONFIG, "transmit volume: %d\n",ext->txvol);
487 if (!strcmp(option,"own_setup"))
492 if (!strcasecmp(param,ext_yesno[i]))
499 PDEBUG(DEBUG_CONFIG, "own_setup %s\n", ext_yesno[i]);
502 PDEBUG(DEBUG_CONFIG, "given own_setup param unknown: %s\n", param);
505 if (!strcmp(option,"own_proceeding"))
510 if (!strcasecmp(param,ext_yesno[i]))
516 ext->own_proceeding = i;
517 PDEBUG(DEBUG_CONFIG, "own_proceeding %s\n", ext_yesno[i]);
520 PDEBUG(DEBUG_CONFIG, "given own_proceeding param unknown: %s\n", param);
523 if (!strcmp(option,"own_alerting"))
528 if (!strcasecmp(param,ext_yesno[i]))
534 ext->own_alerting = i;
535 PDEBUG(DEBUG_CONFIG, "own_alerting %s\n", ext_yesno[i]);
538 PDEBUG(DEBUG_CONFIG, "given own_alerting param unknown: %s\n", param);
541 if (!strcmp(option,"own_cause"))
546 if (!strcasecmp(param,ext_yesno[i]))
553 PDEBUG(DEBUG_CONFIG, "own_cause %s\n", ext_yesno[i]);
556 PDEBUG(DEBUG_CONFIG, "given own_cause param unknown: %s\n", param);
559 if (!strcmp(option,"facility"))
564 if (!strcasecmp(param,ext_yesno[i]))
571 PDEBUG(DEBUG_CONFIG, "facility %s\n", ext_yesno[i]);
574 PDEBUG(DEBUG_CONFIG, "given facility param unknown: %s\n", param);
577 if (!strcmp(option,"display_cause"))
579 if (!strcasecmp(param, "german"))
580 ext->display_cause = DISPLAY_CAUSE_GERMAN;
581 else if (!strcasecmp(param, "english"))
582 ext->display_cause = DISPLAY_CAUSE_ENGLISH;
583 else if (!strcasecmp(param, "german-location"))
584 ext->display_cause = DISPLAY_LOCATION_GERMAN;
585 else if (!strcasecmp(param, "english-location"))
586 ext->display_cause = DISPLAY_LOCATION_ENGLISH;
587 else if (!strcasecmp(param, "number"))
588 ext->display_cause = DISPLAY_CAUSE_NUMBER;
590 ext->display_cause = DISPLAY_CAUSE_NONE;
592 PDEBUG(DEBUG_CONFIG, "display cause: %d\n",ext->display_cause);
595 if (!strcmp(option,"display_ext"))
597 if (!strcasecmp(param, "number"))
598 ext->display_ext = DISPLAY_CID_NUMBER;
599 else if (!strcasecmp(param, "abbrev"))
600 ext->display_ext = DISPLAY_CID_ABBREVIATION;
601 else if (!strcasecmp(param, "name"))
602 ext->display_ext = DISPLAY_CID_NAME;
603 else if (!strcasecmp(param, "number-name"))
604 ext->display_ext = DISPLAY_CID_NUMBER_NAME;
605 else if (!strcasecmp(param, "name-number"))
606 ext->display_ext = DISPLAY_CID_NAME_NUMBER;
607 else if (!strcasecmp(param, "abbrev-number"))
608 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER;
609 else if (!strcasecmp(param, "abbrev-name"))
610 ext->display_ext = DISPLAY_CID_ABBREV_NAME;
611 else if (!strcasecmp(param, "abbrev-name-number"))
612 ext->display_ext = DISPLAY_CID_ABBREV_NAME_NUMBER;
613 else if (!strcasecmp(param, "abbrev-number-name"))
614 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER_NAME;
616 ext->display_ext = DISPLAY_CID_ASIS;
618 PDEBUG(DEBUG_CONFIG, "display ext: %d\n",ext->display_ext);
621 if (!strcmp(option,"display_ext"))
626 if (!strcasecmp(param,ext_yesno[i]))
632 ext->display_ext = i;
633 PDEBUG(DEBUG_CONFIG, "display ext %s\n", ext_yesno[i]);
636 PDEBUG(DEBUG_CONFIG, "given display_ext param unknown: %s\n", param);
639 if (!strcmp(option,"display_int"))
644 if (!strcasecmp(param,ext_yesno[i]))
650 ext->display_int = i;
651 PDEBUG(DEBUG_CONFIG, "display int %s\n", ext_yesno[i]);
654 PDEBUG(DEBUG_CONFIG, "given display_int param unknown: %s\n", param);
657 if (!strcmp(option,"display_fake"))
662 if (!strcasecmp(param,ext_yesno[i]))
668 ext->display_fake = i;
669 PDEBUG(DEBUG_CONFIG, "display fake caller ids %s\n", ext_yesno[i]);
672 PDEBUG(DEBUG_CONFIG, "given display_fake param unknown: %s\n", param);
675 if (!strcmp(option,"display_anon"))
680 if (!strcasecmp(param,ext_yesno[i]))
686 ext->display_anon = i;
687 PDEBUG(DEBUG_CONFIG, "display anonymouse ids %s\n", ext_yesno[i]);
690 PDEBUG(DEBUG_CONFIG, "given display_anon param unknown: %s\n", param);
693 if (!strcmp(option,"display_menu"))
698 if (!strcasecmp(param,ext_yesno[i]))
704 ext->display_menu = i;
705 PDEBUG(DEBUG_CONFIG, "display menu %s\n", ext_yesno[i]);
708 PDEBUG(DEBUG_CONFIG, "given display_menu param unknown: %s\n", param);
711 if (!strcmp(option,"display_dialing"))
716 if (!strcasecmp(param,ext_yesno[i]))
722 ext->display_dialing = i;
723 PDEBUG(DEBUG_CONFIG, "display dialing %s\n", ext_yesno[i]);
726 PDEBUG(DEBUG_CONFIG, "given display_dialing param unknown: %s\n", param);
729 if (!strcmp(option,"display_name"))
734 if (!strcasecmp(param,ext_yesno[i]))
740 ext->display_name = i;
741 PDEBUG(DEBUG_CONFIG, "display name %s\n", ext_yesno[i]);
744 PDEBUG(DEBUG_CONFIG, "given display_name param unknown: %s\n", param);
747 if (!strcmp(option,"tones_dir"))
749 if (param[strlen(param)-1] == '/')
750 param[strlen(param)-1]=0;
751 SCPY(ext->tones_dir, param);
753 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
755 if (!strcmp(option,"record"))
757 if (!strcasecmp(param, "mono"))
758 ext->record = CODEC_MONO;
759 else if (!strcasecmp(param, "stereo"))
760 ext->record = CODEC_STEREO;
761 else if (!strcasecmp(param, "8bit"))
762 ext->record = CODEC_8BIT;
763 else if (!strcasecmp(param, "law"))
764 ext->record = CODEC_LAW;
766 ext->record = CODEC_OFF;
767 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
769 if (!strcmp(option,"password"))
771 SCPY(ext->password, param);
773 PDEBUG(DEBUG_CONFIG, "password: %s\n",param);
775 if (!strcmp(option,"vbox_mode"))
777 if (!strcasecmp(param, "parallel"))
778 ext->vbox_mode = VBOX_MODE_PARALLEL;
779 else if (!strcasecmp(param, "announcement"))
780 ext->vbox_mode = VBOX_MODE_ANNOUNCEMENT;
782 ext->vbox_mode = VBOX_MODE_NORMAL;
783 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
785 if (!strcmp(option,"vbox_codec"))
787 if (!strcasecmp(param, "stereo"))
788 ext->vbox_codec = CODEC_STEREO;
789 else if (!strcasecmp(param, "8bit"))
790 ext->vbox_codec = CODEC_8BIT;
791 else if (!strcasecmp(param, "law"))
792 ext->vbox_codec = CODEC_LAW;
794 ext->vbox_codec = CODEC_MONO;
795 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
797 if (!strcmp(option,"vbox_time"))
799 ext->vbox_time = atoi(param);
800 if (ext->vbox_time < 0)
803 PDEBUG(DEBUG_CONFIG, "vbox time to record: %d\n",ext->vbox_time);
805 if (!strcmp(option,"vbox_display"))
807 if (!strcasecmp(param, "detailed")
808 || !strcasecmp(param, "detailled"))
809 ext->vbox_display = VBOX_DISPLAY_DETAILED;
810 else if (!strcasecmp(param, "off"))
811 ext->vbox_display = VBOX_DISPLAY_OFF;
813 ext->vbox_display = VBOX_DISPLAY_BRIEF;
814 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
816 if (!strcmp(option,"vbox_language"))
818 if (!strcasecmp(param, "german"))
819 ext->vbox_language = VBOX_LANGUAGE_GERMAN;
821 ext->vbox_language = VBOX_LANGUAGE_ENGLISH;
822 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
824 if (!strcmp(option,"vbox_email"))
826 SCPY(ext->vbox_email, param);
827 PDEBUG(DEBUG_CONFIG, "given vbox email: %s\n", param);
829 if (!strcmp(option,"vbox_email_file"))
834 if (!strcasecmp(param,ext_yesno[i]))
840 ext->vbox_email_file = i;
841 PDEBUG(DEBUG_CONFIG, "attach audio file %s\n", ext_yesno[i]);
844 PDEBUG(DEBUG_CONFIG, "given vbox_email_file param unknown: %s\n", param);
847 if (!strcmp(option,"vbox_free"))
852 if (!strcasecmp(param,ext_yesno[i]))
859 PDEBUG(DEBUG_CONFIG, "vbox_free %s\n", ext_yesno[i]);
862 PDEBUG(DEBUG_CONFIG, "given vbox_free param unknown: %s\n", param);
865 if (!strcmp(option,"last_in"))
867 if (param[0] && last_in_count<MAX_REMEMBER)
869 SCPY(ext->last_in[last_in_count], param);
872 PDEBUG(DEBUG_CONFIG, "last_in dialed number: %s\n",param);
874 if (!strcmp(option,"last_out"))
876 if (param[0] && last_out_count<MAX_REMEMBER)
878 SCPY(ext->last_out[last_out_count], param);
881 PDEBUG(DEBUG_CONFIG, "last_out dialed number: %s\n",param);
883 if (!strcmp(option,"datacall"))
888 if (!strcasecmp(param,ext_yesno[i]))
895 PDEBUG(DEBUG_CONFIG, "datacall %s\n", ext_yesno[i]);
898 PDEBUG(DEBUG_CONFIG, "given datacall param unknown: %s\n", param);
901 if (!strcmp(option,"seconds"))
906 if (!strcasecmp(param,ext_yesno[i]))
912 ext->no_seconds = 1-i;
913 PDEBUG(DEBUG_CONFIG, "seconds %s\n", ext_yesno[i]);
916 PDEBUG(DEBUG_CONFIG, "unknown param for seconds: %s\n", param);
920 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n",filename,line,option);
931 * writes extension for given extension number from structure
933 int write_extension(struct extension *ext, char *number)
939 if (number[0] == '\0')
942 SPRINT(filename, "%s/%s/%s/settings", INSTALL_DATA, options.extensions_dir, number);
944 if (!(fp = fopen(filename, "w")))
946 PERROR("Cannot open settings: \"%s\"\n", filename);
950 fprintf(fp,"# Settings of extension %s\n\n", number);
952 fprintf(fp,"# Name of extension:\n");
953 fprintf(fp,"name %s\n\n",ext->name);
955 fprintf(fp,"# Predialed prefix after pick-up of the phone\n");
956 fprintf(fp,"prefix %s\n\n",ext->prefix);
958 fprintf(fp,"# Next prefix to dial pick-up of the phone\n");
959 fprintf(fp,"# This will be cleared on hangup.\n");
960 fprintf(fp,"next %s\n\n",ext->next);
962 // fprintf(fp,"# Set up alarm message after prefix is dialed and connection is established\n");
963 // fprintf(fp,"alarm %s\n\n",ext->alarm);
965 fprintf(fp,"# Interface(s) to ring on calls to extension (as named in interface.conf)\n");
966 fprintf(fp,"# Seperate multiple interfaces by using komma without spaces\n");
967 fprintf(fp,"# Example: Int would ring on the interface with the name \"Int\"");
968 fprintf(fp,"# Int1,Int2 would ring incoming calls on both interfaces Int1 and Int2.\n");
969 fprintf(fp,"interfaces %s\n\n",ext->interfaces);
971 fprintf(fp,"# Call Forward Unconditional (CFU)\n");
972 fprintf(fp,"# No port will be called, CFB, CFNR and CFP is ignored.\n");
973 fprintf(fp,"# Use keyword \"vbox\" to forward call directly to answering machine.\n");
974 fprintf(fp,"cfu %s\n\n",ext->cfu);
976 fprintf(fp,"# Call Forward when Busy (CFB)\n");
977 fprintf(fp,"# If the extension is in use at least once, this forward is done.\n");
978 fprintf(fp,"# In case of busy line, CFNR and CFP is ignored.\n");
979 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine when busy.\n");
980 fprintf(fp,"cfb %s\n\n",ext->cfb);
982 fprintf(fp,"# Call Forward on No Response (CFNR)\n");
983 fprintf(fp,"# If noone answers, the call is forwarded, ports and CFP will be released.\n");
984 fprintf(fp,"# The default delay is 20 seconds.\n");
985 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine on no response.\n");
986 fprintf(fp,"cfnr %s\n",ext->cfnr);
987 fprintf(fp,"cfnr_delay %d\n\n",ext->cfnr_delay);
989 fprintf(fp,"# Call Forward Parallel (CFP)\n");
990 fprintf(fp,"# Call will ring on the forwarded number, simulaniousely with the ports.\n");
991 fprintf(fp,"cfp %s\n\n",ext->cfp);
993 fprintf(fp,"# Allow user to change call forwarding.\n");
994 fprintf(fp,"change_forward %s\n\n", ext_yesno[ext->change_forward]);
996 fprintf(fp,"# Caller id\n# This must be one of the following:\n");
997 fprintf(fp,"# <number> (as dialed from your local area)\n");
998 fprintf(fp,"# <number> anonymous (will only be shown to emergency phones)\n");
999 fprintf(fp,"# none (no number available at all)\n");
1000 fprintf(fp,"# by default the number is of type UNKNOWN (for MULTIPOINT lines)\n");
1001 fprintf(fp,"# if your caller id is not screened on outgoing calls use one of the following:\n");
1002 fprintf(fp,"# use prefix 'i' for TYPE INTERNATIONAL (i<county code><areacode+number>)\n");
1003 fprintf(fp,"# use prefix 'n' for TYPE NATIONAL (n<areacode+number>)\n");
1004 fprintf(fp,"# use prefix 's' for TYPE SUBSCRIBER (s<local number>)\n");
1005 if (ext->callerid_present == INFO_PRESENT_NOTAVAIL)
1006 fprintf(fp,"callerid none\n\n");
1009 switch(ext->callerid_type)
1011 case INFO_NTYPE_INTERNATIONAL:
1012 fprintf(fp,"callerid i%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1014 case INFO_NTYPE_NATIONAL:
1015 fprintf(fp,"callerid n%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1017 case INFO_NTYPE_SUBSCRIBER:
1018 fprintf(fp,"callerid s%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1021 fprintf(fp,"callerid %s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1025 fprintf(fp,"# Caller id for next call (see caller id)\n");
1026 if (ext->id_next_call_present < 0)
1027 fprintf(fp,"id_next_call \n\n");
1028 else if (ext->id_next_call_present == INFO_PRESENT_NOTAVAIL)
1029 fprintf(fp,"id_next_call none\n\n");
1032 switch(ext->id_next_call_type)
1034 case INFO_NTYPE_INTERNATIONAL:
1035 fprintf(fp,"id_next_call i%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1037 case INFO_NTYPE_NATIONAL:
1038 fprintf(fp,"id_next_call n%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1040 case INFO_NTYPE_SUBSCRIBER:
1041 fprintf(fp,"id_next_call s%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1044 fprintf(fp,"id_next_call %s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1048 fprintf(fp,"# Allow user to change caller ID.\n");
1049 fprintf(fp,"change_callerid %s\n\n", ext_yesno[ext->change_callerid]);
1051 fprintf(fp,"# Caller Line Identification Presentation (CLIP)\n");
1052 fprintf(fp,"# clip (asis|hide)\n");
1053 fprintf(fp,"# asis: On forwarded calls the CLIP is used as presented by the calling party.\n");
1054 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1058 fprintf(fp,"clip hide\n\n");
1061 fprintf(fp,"clip asis\n\n");
1064 fprintf(fp,"# Connected Line Identification Presentation (COLP)\n");
1065 fprintf(fp,"# colp (asis|hide|force)\n");
1066 fprintf(fp,"# asis: Provides colp as defined by the extension's caller id.\n");
1067 fprintf(fp,"# On forwarded calls the COLP is used as presented by the called party.\n");
1068 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1069 fprintf(fp,"# force: If COLP is not presented by forwarded calls the dialed number is used.\n");
1073 fprintf(fp,"colp hide\n\n");
1076 fprintf(fp,"colp force\n\n");
1079 fprintf(fp,"colp asis\n\n");
1082 fprintf(fp,"# CLIP Prefix\n");
1083 fprintf(fp,"# Adds a prefix to incomming caller IDs, so telephones will be able to respond\n");
1084 fprintf(fp,"# to unanswered calls from their list. The prefix must be the digit(s) to get\n");
1085 fprintf(fp,"# an external line. The caller ID will then be extendet so that they can be\n");
1086 fprintf(fp,"# dialed from internal telephones. Many telephones have this feature, but some\n");
1087 fprintf(fp,"# don't.\n");
1088 fprintf(fp,"clip_prefix %s\n\n",ext->clip_prefix);
1090 fprintf(fp,"# Keypad control\n");
1091 fprintf(fp,"# If supported by telephone, pressing a key on the keypad will not result in\n");
1092 fprintf(fp,"# DTMF tone, but the digit is transmitted via D-channel diaing info.\n");
1093 fprintf(fp,"keypad %s\n\n",(ext->keypad)?"yes":"no");
1095 fprintf(fp,"# Called Name Identification Presentation (CNIP/CONP)\n");
1096 fprintf(fp,"# If supported by telephone, special information element on the d-channel are\n");
1097 fprintf(fp,"# used to show name of caller. It is supported by newer Siemens telephones\n# (Centrex).\n");
1098 fprintf(fp,"centrex %s #this is currently not working!!!\n\n",(ext->centrex)?"yes":"no");
1100 fprintf(fp,"# Ignore restriction of COLP and CLIP\n");
1101 fprintf(fp,"# In this case even restricted numbers are presented to this extension.\n");
1102 fprintf(fp,"# This also works for incoming external anonymous calls IF:\n");
1103 fprintf(fp,"# You have the CLIRIGN feature like POLICE or equivalent.\n");
1104 fprintf(fp,"anon-ignore %s\n\n",(ext->anon_ignore)?"yes":"no");
1106 fprintf(fp,"# Dialing rights (none|internal|local|national|international)\n");
1107 fprintf(fp,"rights %s\n\n",ext_rights[ext->rights]);
1109 fprintf(fp,"# Delete function for external calls. '*' will delete the last digit, '#' will\n");
1110 fprintf(fp,"# delete the complete number. Also enable 'display_dialing' to see on the\n");
1111 fprintf(fp,"# display what actually happens.\n");
1112 fprintf(fp,"delete_ext %s\n\n",ext_yesno[ext->delete_ext]);
1114 fprintf(fp,"# If noknocking is enabled, the caller will get a busy message when the\n");
1115 fprintf(fp,"# extension is doing at least one call.\n");
1116 fprintf(fp,"noknocking %s\n\n",ext_yesno[ext->noknocking]);
1118 fprintf(fp,"# Transmit volume (-8 .. 8)\n");
1119 fprintf(fp,"# 0 = normal\n");
1120 fprintf(fp,"# 1 = double, 2 = quadrupel, 8 = 256 times (amplitude)\n");
1121 fprintf(fp,"# -1 = half, -2 = quarter, 8 = 1/256th (amplitude)\n");
1122 fprintf(fp,"# Audio data is limited to the maximum value when exceeds limit.\n");
1123 fprintf(fp,"txvol %d\n\n",ext->txvol);
1125 fprintf(fp,"# Receive volume (-8 .. 8)\n");
1126 fprintf(fp,"# (see txvol)\n");
1127 fprintf(fp,"rxvol %d\n\n",ext->rxvol);
1130 fprintf(fp,"# Force to use tones and announcements generated by the pbx.\n");
1131 fprintf(fp,"# For internal calls always own tones are used. You may specify own tones for\n");
1132 fprintf(fp,"# different call states:\n");
1133 fprintf(fp,"# own_setup (dialtone and during dialing)\n");
1134 fprintf(fp,"# own_proceeding (call in poceeding state)\n");
1135 fprintf(fp,"# own_alerting (call is ringing)\n");
1136 fprintf(fp,"# own_cause (when the call gets disconnected or failed to be completed)\n");
1137 fprintf(fp,"own_setup %s\n",ext_yesno[ext->own_setup]);
1138 fprintf(fp,"own_proceeding %s\n",ext_yesno[ext->own_proceeding]);
1139 fprintf(fp,"own_alerting %s\n",ext_yesno[ext->own_alerting]);
1140 fprintf(fp,"own_cause %s\n\n",ext_yesno[ext->own_cause]);
1142 fprintf(fp,"# Allow facility information to be transfered to the telephone.\n");
1143 fprintf(fp,"# This is equired to receive advice of charge.\n");
1144 fprintf(fp,"facility %s\n\n",ext_yesno[ext->facility]);
1146 fprintf(fp,"# Display clear causes using display messages (Q.850)\n# This must be one of the following:\n");
1147 fprintf(fp,"# none (no displaying of clear causes)\n");
1148 fprintf(fp,"# english (display cause text in english)\n");
1149 fprintf(fp,"# german (display cause text in german)\n");
1150 fprintf(fp,"# number (display cause number only)\n");
1151 fprintf(fp,"# english-location (display cause text in english and location)\n");
1152 fprintf(fp,"# german-location (display cause text in german and location)\n");
1153 switch(ext->display_cause)
1155 case DISPLAY_CAUSE_ENGLISH:
1156 fprintf(fp,"display_cause english\n\n");
1158 case DISPLAY_CAUSE_GERMAN:
1159 fprintf(fp,"display_cause german\n\n");
1161 case DISPLAY_LOCATION_ENGLISH:
1162 fprintf(fp,"display_cause english-location\n\n");
1164 case DISPLAY_LOCATION_GERMAN:
1165 fprintf(fp,"display_cause german-location\n\n");
1167 case DISPLAY_CAUSE_NUMBER:
1168 fprintf(fp,"display_cause number\n\n");
1171 fprintf(fp,"display_cause none\n\n");
1174 fprintf(fp,"# Display external caller ids using display override (yes or no)\n");
1175 fprintf(fp,"# example: \"15551212\"\n");
1176 fprintf(fp,"display_ext %s\n\n",(ext->display_ext)?"yes":"no");
1178 fprintf(fp,"# Display internal caller ids using display override (yes or no)\n");
1179 fprintf(fp,"# example: \"200 (int)\"\n");
1180 fprintf(fp,"display_int %s\n\n",(ext->display_int)?"yes":"no");
1182 fprintf(fp,"# Display if calls are anonymous using display override (yes or no)\n");
1183 fprintf(fp,"# This makes only sense if the anon-ignore feature is enabled.\n");
1184 fprintf(fp,"# example: \"15551212 anon\"\n");
1185 fprintf(fp,"display_anon %s\n\n",(ext->display_anon)?"yes":"no");
1187 fprintf(fp,"# Display fake caller ids using display override (yes or no)\n");
1188 fprintf(fp,"# If the caller uses \"clip no screening\", you will see if the number is\n");
1189 fprintf(fp,"# real or fake\n");
1190 fprintf(fp,"# example: \"15551212 fake\"\n");
1191 fprintf(fp,"display_fake %s\n\n",(ext->display_fake)?"yes":"no");
1193 fprintf(fp,"# Display caller's name if available. (yes or no)\n");
1194 fprintf(fp,"# example: \"15551212 Axel\"\n");
1195 fprintf(fp,"display_name %s\n\n",(ext->display_name)?"yes":"no");
1197 fprintf(fp,"# Display menu when '*' and '#' is pressed. The menu shows all prefixes for\n");
1198 fprintf(fp,"# internal dialing by pressing '*' for previous prefix and '#' for next prefix.\n");
1199 fprintf(fp,"# Also the dialed prefix is show on display. (yes or no)\n");
1200 fprintf(fp,"display_menu %s\n\n",(ext->display_menu)?"yes":"no");
1202 fprintf(fp,"# Display digits as they are interpreted by pbx. (yes or no)\n");
1203 fprintf(fp,"display_dialing %s\n\n",(ext->display_dialing)?"yes":"no");
1205 fprintf(fp,"# Tones directory for announcements and patterns\n");
1206 fprintf(fp,"# Enter nothing for default tones as selected by options.conf.\n");
1207 fprintf(fp,"tones_dir %s\n\n",ext->tones_dir);
1209 fprintf(fp,"# Record calls to extension's directory. The file is written as wave.\n");
1210 fprintf(fp,"# This must be one of the following:\n");
1211 fprintf(fp,"# off (no recording)\n");
1212 fprintf(fp,"# mono (records wave 16 bit mono, 128kbits/s)\n");
1213 fprintf(fp,"# stereo (records wave 32 bit stereo, 256kbits/s)\n");
1214 fprintf(fp,"# 8bit (records wave 8 bit mono, 64kbits/s)\n");
1215 fprintf(fp,"# law (records xLaw encoded, as specified in options.conf, 64kbps/s)\n");
1219 fprintf(fp,"record mono\n\n");
1222 fprintf(fp,"record stereo\n\n");
1225 fprintf(fp,"record 8bit\n\n");
1228 fprintf(fp,"record law\n\n");
1231 fprintf(fp,"record off\n\n");
1234 fprintf(fp,"# Password for callback and login\n");
1235 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1236 fprintf(fp,"password %s\n\n",ext->password);
1238 fprintf(fp,"# The Answering Machine. Enter the mode of answering machine.\n");
1239 fprintf(fp,"# This must be one of the following:\n");
1240 fprintf(fp,"# normal (plays announcement and records after that)\n");
1241 fprintf(fp,"# parallel (plays announcement and records also DURING announcement.)\n");
1242 fprintf(fp,"# announcement (just plays announcement and hangs up)\n");
1243 switch(ext->vbox_mode)
1245 case VBOX_MODE_PARALLEL:
1246 fprintf(fp,"vbox_mode parallel\n\n");
1248 case VBOX_MODE_ANNOUNCEMENT:
1249 fprintf(fp,"vbox_mode announcement\n\n");
1252 fprintf(fp,"vbox_mode normal\n\n");
1255 fprintf(fp,"# The Answering Machine. Enter the type of codec for recording.\n");
1256 fprintf(fp,"# This must be one of the following:\n");
1257 fprintf(fp,"# law (alaw/ulas codec, as specified in options.conf)\n");
1258 fprintf(fp,"# mono (16 bit mono wave file)\n");
1259 fprintf(fp,"# stereo (16 bit stereo wave file)\n");
1260 fprintf(fp,"# 8bit (8 bit mono wave file)\n");
1261 switch(ext->vbox_codec)
1264 fprintf(fp,"vbox_codec law\n\n");
1267 fprintf(fp,"vbox_codec stereo\n\n");
1270 fprintf(fp,"vbox_codec 8bit\n\n");
1273 fprintf(fp,"vbox_codec mono\n\n");
1276 fprintf(fp,"# The Answering Machine. Enter maximum time to record after announcement.\n");
1277 fprintf(fp,"# Leave empty, enter \"infinite\" or give time in seconds.\n");
1278 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1280 fprintf(fp,"vbox_time %d\n\n",ext->vbox_time);
1282 fprintf(fp,"vbox_time infinite\n\n");
1284 fprintf(fp,"# The Answering Machine. Enter mode for display current state.\n");
1285 fprintf(fp,"# This must be one of the following:\n");
1286 fprintf(fp,"# brief (displays brief information, for small displays)\n");
1287 fprintf(fp,"# detailed (displays detailed information, for larger displays)\n");
1288 fprintf(fp,"# off (don't display anything)\n");
1289 switch(ext->vbox_display)
1291 case VBOX_DISPLAY_OFF:
1292 fprintf(fp,"vbox_display off\n\n");
1294 case VBOX_DISPLAY_DETAILED:
1295 fprintf(fp,"vbox_display detailed\n\n");
1298 fprintf(fp,"vbox_display brief\n\n");
1301 fprintf(fp,"# The Answering Machine. Enter type of language: \"english\" or \"german\"\n");
1302 fprintf(fp,"# Display information of the menu, will be provided as specified.\n");
1303 fprintf(fp,"# The menu's voice is located in \"vbox_english\" and \"vbox_german\".\n");
1304 if (ext->vbox_language)
1305 fprintf(fp,"vbox_language german\n\n");
1307 fprintf(fp,"vbox_language english\n\n");
1309 fprintf(fp,"# The Answering Machine. Enter email to send incoming messages to:\n");
1310 fprintf(fp,"# All incoming message will be send to the given address.\n");
1311 fprintf(fp,"# The audio file is attached if \"vbox_email_file\" is 'yes'\n");
1312 fprintf(fp,"vbox_email %s\n", ext->vbox_email);
1313 fprintf(fp,"vbox_email_file %s\n\n",ext_yesno[ext->vbox_email_file]);
1315 fprintf(fp,"# If audio path is connected prior answering of a call, say 'yes'\n");
1316 fprintf(fp,"# will cause the call to be billed after playing the announcement. (yes or no)\n");
1317 fprintf(fp,"vbox_free %s\n\n",(ext->vbox_free)?"yes":"no");
1319 fprintf(fp,"# Accept incoming data calls as it would be an audio call.\n");
1320 fprintf(fp,"datacall %s\n\n",ext_yesno[ext->datacall]);
1322 fprintf(fp,"# Include seconds (time) in the connect message. (Should be always enabled.)\n");
1323 fprintf(fp,"seconds %s\n\n",ext_yesno[1-ext->no_seconds]);
1325 fprintf(fp,"# Last outgoing and incoming numbers (including prefix)\n");
1327 while(i < MAX_REMEMBER)
1329 if (ext->last_out[i][0])
1330 fprintf(fp,"last_out %s\n",ext->last_out[i]);
1334 while(i < MAX_REMEMBER)
1336 if (ext->last_in[i][0])
1337 fprintf(fp,"last_in %s\n",ext->last_in[i]);
1348 /* write log for extension
1351 int write_log(char *number, char *callerid, char *calledid, time_t start, time_t stop, int aoce, int cause, int location)
1353 char *mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1358 if (callerid[0] == '\0')
1359 callerid = "<unknown>";
1361 SPRINT(filename, "%s/%s/%s/log", INSTALL_DATA, options.extensions_dir, number);
1363 if (!(fp = fopen(filename, "a")))
1365 PERROR("Cannot open log: \"%s\"\n", filename);
1369 tm = localtime(&start);
1370 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);
1372 fprintf(fp," %2ld:%02ld:%02ld", (stop-start)/3600, (((unsigned long)(stop-start))/60)%60, ((unsigned long)(stop-start))%60);
1374 fprintf(fp," --:--:--");
1375 fprintf(fp," %s -> %s", callerid, calledid);
1376 if (cause >= 1 && cause <=127 && location>=0 && location<=15)
1377 fprintf(fp," (cause=%d '%s' location=%d '%s')", cause, isdn_cause[cause].german, location, isdn_location[location].german);
1387 * reads phone book of extextension and compares the given elements which
1388 * are: abreviation, phone number, name (name is not compared)
1389 * on success a 1 is returned and the pointers of elements are set to the
1392 int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, char **name_pointer)
1397 static char abbrev[32], phone[256], name[256];
1398 unsigned int line,i;
1400 int found = 0, found_if_more_digits = 0;
1402 SPRINT(filename, "%s/%s/%s/phonebook", INSTALL_DATA, options.extensions_dir, number);
1404 if (!(fp = fopen(filename, "r")))
1406 PERROR("Cannot open phonebook: \"%s\"\n", filename);
1411 while((fgets(buffer, sizeof(buffer), fp)))
1414 buffer[sizeof(buffer)-1] = '\0';
1415 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1418 while(*p <= 32) /* skip spaces */
1424 if (*p==0 || *p=='#') /* ignore comments and empty line */
1431 i=0; /* read abbrev */
1434 if (i+1 >= sizeof(abbrev))
1436 PERROR_RUNTIME("Error in %s (line %d): abbrev too long.\n",filename,line);
1443 while(*p <= 32) /* skip spaces */
1450 if (*p!=0 && *p!='#') /* phone */
1452 i=0; /* read phone */
1455 if (i+1 >= sizeof(phone))
1457 PERROR_RUNTIME("Error in %s (line %d): phone too long.\n",filename,line);
1463 while(*p <= 32) /* skip spaces */
1471 if (*p!=0 && *p!='#') /* name */
1473 i=0; /* read name */
1476 if (i+1 >= sizeof(name))
1478 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1486 if (*abbrev_pointer)
1488 if (!strncmp(*abbrev_pointer, abbrev, strlen(*abbrev_pointer)))
1490 /* may match if abbreviation is longer */
1491 found_if_more_digits = 1;
1493 if (!!strcasecmp(*abbrev_pointer, abbrev))
1497 if (!!strcasecmp(*phone_pointer, phone))
1500 if (!!strcasecmp(*name_pointer, name))
1504 break; /* found entry */
1511 *abbrev_pointer = abbrev;
1512 *phone_pointer = phone;
1513 *name_pointer = name;
1518 if (found_if_more_digits)
1524 /* parsing secrets file
1526 * 'number' specifies the externsion number, not the caller id
1527 * 'remote_id' specifies the dialed number, or the caller id for incoming calls
1528 * the result is the auth, crypt and key string, and 1 is returned.
1529 * on failure or not matching number, the 0 is returned
1531 int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **crypt_pointer, char **key_pointer)
1537 static char auth[64], crypt[64], key[4096];
1538 unsigned int line,i;
1542 SPRINT(filename, "%s/%s/%s/secrets", INSTALL_DATA, options.extensions_dir, number);
1544 if (!(fp = fopen(filename, "r")))
1546 PERROR("Cannot open secrets: \"%s\"\n", filename);
1551 while((fgets(buffer, sizeof(buffer), fp)))
1554 buffer[sizeof(buffer)-1] = '\0';
1555 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1558 while(*p <= 32) /* skip spaces */
1564 if (*p==0 || *p=='#') /* ignore comments and empty line */
1572 i=0; /* read auth */
1575 if (i+1 >= sizeof(remote))
1577 PERROR_RUNTIME("Error in %s (line %d): remote too long.\n",filename,line);
1584 while(*p <= 32) /* skip spaces */
1591 if (*p!=0 && *p!='#') /* auth */
1593 i=0; /* read auth */
1596 if (i+1 >= sizeof(auth))
1598 PERROR_RUNTIME("Error in %s (line %d): auth too long.\n",filename,line);
1604 while(*p <= 32) /* skip spaces */
1612 if (*p!=0 && *p!='#') /* crypt */
1614 i=0; /* read crypt */
1617 if (i+1 >= sizeof(crypt))
1619 PERROR_RUNTIME("Error in %s (line %d): crypt too long.\n",filename,line);
1625 while(*p <= 32) /* skip spaces */
1633 if (*p!=0 && *p!='#') /* key */
1638 if (i+1 >= sizeof(key))
1640 PERROR_RUNTIME("Error in %s (line %d): key too long.\n",filename,line);
1647 //printf("COMPARING: '%s' with '%s' %s %s %s\n", remote_id, remote, auth, crypt, key);
1649 if (!!strcasecmp(remote, remote_id))
1653 break; /* found entry */
1660 *auth_pointer = auth;
1661 *crypt_pointer = crypt;
1670 * the caller id is given and the name is returned. if the name is not found,
1672 * on success a 1 is returned and the pointers of elements are set to the
1675 char *parse_directory(char *number, int type)
1680 static char phone[32], name[64];
1681 unsigned int line,i;
1685 SPRINT(filename, "%s/directory.list", INSTALL_DATA);
1687 if (!(fp = fopen(filename, "r")))
1689 PERROR("Cannot open directory: \"%s\"\n", filename);
1694 while((fgets(buffer, sizeof(buffer), fp)))
1697 buffer[sizeof(buffer)-1] = '\0';
1698 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1701 while(*p <= 32) /* skip spaces */
1707 if (*p==0 || *p=='#') /* ignore comments and empty line */
1713 i=0; /* read number */
1716 if (i+1 >= sizeof(phone))
1718 PERROR_RUNTIME("Error in %s (line %d): number too long.\n",filename,line);
1725 while(*p <= 32) /* skip spaces */
1732 i=0; /* read name */
1735 if (i+1 >= sizeof(name))
1737 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1744 if (phone[0] == 'i')
1746 if (type != INFO_NTYPE_INTERNATIONAL)
1748 if (!strcmp(number, phone+1))
1755 if (phone[0] == 'n')
1757 if (type != INFO_NTYPE_NATIONAL)
1759 if (!strcmp(number, phone+1))
1766 if (phone[0] == 's')
1768 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1770 if (!strcmp(number, phone+1))
1777 if (!strncmp(phone, options.international, strlen(options.international)))
1779 if (type != INFO_NTYPE_INTERNATIONAL)
1781 if (!strcmp(number, phone+strlen(options.international)))
1788 if (!options.national[0]) /* no national prefix */
1790 if (type == INFO_NTYPE_INTERNATIONAL)
1792 if (!strcmp(number, phone))
1799 if (!strncmp(phone, options.national, strlen(options.national)))
1801 if (type != INFO_NTYPE_NATIONAL)
1803 if (!strcmp(number, phone+strlen(options.national)))
1810 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1812 if (!strcmp(number, phone))
1827 /* parse callbackauth
1829 * searches for the given caller id and returns 1 == true or 0 == false
1831 int parse_callbackauth(char *number, struct caller_info *callerinfo)
1836 unsigned int line,i;
1838 static char caller_type[32], caller_id[64];
1841 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
1843 if (!(fp = fopen(filename, "r")))
1845 PDEBUG(DEBUG_EPOINT, "Cannot open callbackauth: \"%s\"\n", filename);
1850 while((fgets(buffer, sizeof(buffer), fp)))
1853 buffer[sizeof(buffer)-1] = '\0';
1854 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1857 while(*p <= 32) /* skip spaces */
1863 if (*p==0 || *p=='#') /* ignore comments and empty line */
1869 i=0; /* read caller_type */
1872 if (i+1 >= sizeof(caller_type))
1874 PERROR_RUNTIME("Error in %s (line %d): caller_type too long.\n",filename,line);
1877 caller_type[i+1] = '\0';
1878 caller_type[i++] = *p++;
1881 while(*p <= 32) /* skip spaces */
1888 if (*p!=0 && *p!='#') /* caller_id */
1890 i=0; /* read caller_id */
1893 if (i+1 >= sizeof(caller_id))
1895 PERROR_RUNTIME("Error in %s (line %d): caller_id too long.\n",filename,line);
1898 caller_id[i+1] = '\0';
1899 caller_id[i++] = *p++;
1904 if (caller_type[0]=='\0' && caller_id[0]=='\0')
1907 if (atoi(caller_type) != callerinfo->ntype)
1910 if (!!strcmp(caller_id, callerinfo->id))
1914 break; /* found entry */
1925 /* append line to callbackauth
1928 void append_callbackauth(char *number, struct caller_info *callerinfo)
1933 SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
1935 if (callerinfo->id[0]=='\0')
1937 PERROR("caller has no id.\n");
1940 if (!(fp = fopen(filename, "a")))
1942 PERROR("Cannot open callbackauth: \"%s\"\n", filename);
1946 fprintf(fp, "%6d %s\n", callerinfo->ntype, callerinfo->id);