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"))) {
57 printf("the given extension doesn't exist: \"%s\"\n", filename);
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((GETLINE(buffer, fp))) {
75 while(*p <= 32) { /* skip spaces */
80 if (*p==0 || *p=='#') /* ignore comments and empty line */
84 i=0; /* read option */
86 if (i+1 >= sizeof(option)) {
87 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
94 while(*p <= 32) { /* skip spaces */
102 if (*p!=0 && *p!='#') { /* param */
103 i=0; /* read param */
105 if (i+1 >= sizeof(param)) {
106 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
113 while(*p <= 32) { /* skip spaces */
119 if (*p!=0 && *p!='#') { /* param2 */
120 i=0; /* read param2 */
122 if (i+1 >= sizeof(param2)) {
123 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
132 /* at this point we have option and param */
135 if (!strcmp(option,"name")) {
136 SCPY(ext->name, param);
138 SCAT(ext->name, (char *)" ");
139 SCAT(ext->name, param2);
142 PDEBUG(DEBUG_CONFIG, "name of extension: %s\n",param);
144 if (!strcmp(option,"prefix")) {
145 SCPY(ext->prefix, param);
147 PDEBUG(DEBUG_CONFIG, "dial prefix on pickup: %s\n",param);
149 if (!strcmp(option,"next")) {
150 SCPY(ext->next, param);
152 PDEBUG(DEBUG_CONFIG, "dial next on pickup: %s\n",param);
154 if (!strcmp(option,"alarm")) {
155 SCPY(ext->alarm, param);
157 PDEBUG(DEBUG_CONFIG, "alarm message (if prefix): %s\n",param);
159 if (!strcmp(option,"cfu")) {
160 SCPY(ext->cfu, param);
162 PDEBUG(DEBUG_CONFIG, "call forward unconditional: %s\n",param);
164 if (!strcmp(option,"cfb")) {
165 SCPY(ext->cfb, param);
167 PDEBUG(DEBUG_CONFIG, "call forward when busy: %s\n",param);
169 if (!strcmp(option,"cfnr")) {
170 SCPY(ext->cfnr, param);
172 PDEBUG(DEBUG_CONFIG, "call forward on no response: %s\n",param);
174 if (!strcmp(option,"cfnr_delay")) {
175 ext->cfnr_delay = atoi(param);
176 if (ext->cfnr_delay < 0)
179 PDEBUG(DEBUG_CONFIG, "call forward no response delay: %d\n",ext->cfnr_delay);
181 if (!strcmp(option,"cfp")) {
182 SCPY(ext->cfp, param);
184 PDEBUG(DEBUG_CONFIG, "call forward parallel: %s\n",param);
186 if (!strcmp(option,"change_forward")) {
188 while(ext_yesno[i]) {
189 if (!strcasecmp(param,ext_yesno[i]))
194 ext->change_forward = i;
195 PDEBUG(DEBUG_CONFIG, "allow the change of forwarding: %s\n", ext_yesno[i]);
197 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_forward: %s\n", param);
200 if (!strcmp(option,"interfaces")) {
201 SCPY(ext->interfaces, param);
203 PDEBUG(DEBUG_CONFIG, "interfaces to ring calls to extension: %s %s\n",param,param2);
205 if (!strcmp(option,"callerid")) {
206 ext->callerid_present = INFO_PRESENT_ALLOWED;
207 if (!strncasecmp(param2, "anonymous", 9))
208 ext->callerid_present = INFO_PRESENT_RESTRICTED;
209 if (!strncasecmp(param, "non", 3)) {
210 ext->callerid[0] = '\0';
211 ext->callerid_present = INFO_PRESENT_NOTAVAIL;
212 ext->callerid_type = INFO_NTYPE_UNKNOWN;
213 PDEBUG(DEBUG_CONFIG, "caller id: ID NOT AVAILABLE\n");
218 ext->callerid_type = INFO_NTYPE_INTERNATIONAL;
219 SCPY(ext->callerid, param+1);
220 PDEBUG(DEBUG_CONFIG, "caller id: %s INTERNATIONAL\n",param+1);
224 ext->callerid_type = INFO_NTYPE_NATIONAL;
225 SCPY(ext->callerid, param+1);
226 PDEBUG(DEBUG_CONFIG, "caller id: %s NATIONAL\n",param+1);
230 ext->callerid_type = INFO_NTYPE_SUBSCRIBER;
231 SCPY(ext->callerid, param+1);
232 PDEBUG(DEBUG_CONFIG, "caller id: %s SUBSCRIBER\n",param+1);
235 ext->callerid_type = INFO_NTYPE_UNKNOWN;
236 SCPY(ext->callerid, param);
237 PDEBUG(DEBUG_CONFIG, "caller id: %s UNKNOWN\n",param);
239 ext->callerid[sizeof(ext->callerid)-1] = 0;
241 if (!strcmp(option,"id_next_call")) {
242 ext->id_next_call_present = INFO_PRESENT_ALLOWED;
243 if (!strncasecmp(param2, "anonymous", 9))
244 ext->id_next_call_present = INFO_PRESENT_RESTRICTED;
245 if (param[0] == '\0') {
246 ext->id_next_call_present = -1;
247 PDEBUG(DEBUG_CONFIG, "id next call: no id for next call\n");
249 if (!strncasecmp(param, "none", 3)) {
250 ext->id_next_call[0] = '\0';
251 ext->id_next_call_present = INFO_PRESENT_NOTAVAIL;
252 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
253 PDEBUG(DEBUG_CONFIG, "id next call: ID NOT AVAILABLE\n");
258 ext->id_next_call_type = INFO_NTYPE_INTERNATIONAL;
259 SCPY(ext->id_next_call, param+1);
260 PDEBUG(DEBUG_CONFIG, "id next call: %s INTERNATIONAL\n",param+1);
264 ext->id_next_call_type = INFO_NTYPE_NATIONAL;
265 SCPY(ext->id_next_call, param+1);
266 PDEBUG(DEBUG_CONFIG, "id next call: %s NATIONAL\n",param+1);
270 ext->id_next_call_type = INFO_NTYPE_SUBSCRIBER;
271 SCPY(ext->id_next_call, param+1);
272 PDEBUG(DEBUG_CONFIG, "id next call: %s SUBSCRIBER\n",param+1);
275 ext->id_next_call_type = INFO_NTYPE_UNKNOWN;
276 SCPY(ext->id_next_call, param);
277 PDEBUG(DEBUG_CONFIG, "id next call: %s UNKNOWN\n",param);
283 if (!strcmp(option,"change_callerid")) {
285 while(ext_yesno[i]) {
286 if (!strcasecmp(param,ext_yesno[i]))
291 ext->change_callerid = i;
292 PDEBUG(DEBUG_CONFIG, "allow the change of caller id: %s\n", ext_yesno[i]);
294 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_callerid: %s\n", param);
297 if (!strcmp(option,"anon-ignore")) {
299 while(ext_yesno[i]) {
300 if (!strcasecmp(param,ext_yesno[i]))
305 ext->anon_ignore = i;
306 PDEBUG(DEBUG_CONFIG, "ignore restriction of CLIP & COLP %s\n", ext_yesno[i]);
308 PDEBUG(DEBUG_CONFIG, "unknown parameter given anon-ignore: %s\n", param);
311 if (!strcmp(option,"clip")) {
312 if (!strcasecmp(param, "hide"))
313 ext->clip = CLIP_HIDE;
315 ext->clip = CLIP_ASIS;
317 PDEBUG(DEBUG_CONFIG, "clip: %d\n",ext->clip);
319 if (!strcmp(option,"colp")) {
320 if (!strcasecmp(param, "hide"))
321 ext->colp = COLP_HIDE;
322 else if (!strcasecmp(param, "force"))
323 ext->colp = COLP_FORCE;
325 ext->colp = COLP_ASIS;
327 PDEBUG(DEBUG_CONFIG, "colp: %d\n",ext->colp);
329 if (!strcmp(option,"clip_prefix")) {
330 SCPY(ext->clip_prefix, param);
332 PDEBUG(DEBUG_CONFIG, "clip prefix: %s\n",param);
334 if (!strcmp(option,"keypad")) {
336 while(ext_yesno[i]) {
337 if (!strcasecmp(param,ext_yesno[i]))
343 PDEBUG(DEBUG_CONFIG, "use keypad to do call control %s\n", ext_yesno[i]);
345 PDEBUG(DEBUG_CONFIG, "unknown parameter given keypad: %s\n", param);
348 if (!strcmp(option,"rights")) {
350 while(ext_rights[i]) {
351 if (!strcasecmp(param,ext_rights[i]))
357 PDEBUG(DEBUG_CONFIG, "rights to dial: %s\n", ext_rights[i]);
359 PDEBUG(DEBUG_CONFIG, "given rights unknown: %s\n", param);
362 if (!strcmp(option,"delete_ext")) {
364 while(ext_yesno[i]) {
365 if (!strcasecmp(param,ext_yesno[i]))
371 PDEBUG(DEBUG_CONFIG, "enables the delete key function for external calls: %s\n", ext_yesno[i]);
373 PDEBUG(DEBUG_CONFIG, "unknown parameter given delete: %s\n", param);
376 if (!strcmp(option,"noknocking")) {
378 while(ext_yesno[i]) {
379 if (!strcasecmp(param,ext_yesno[i]))
385 PDEBUG(DEBUG_CONFIG, "noknocking %s\n", ext_yesno[i]);
387 PDEBUG(DEBUG_CONFIG, "given noknocking param unknown: %s\n", param);
390 if (!strcmp(option,"rx_gain")
391 || !strcmp(option,"rxvol")) {
392 ext->rx_gain = atoi(param);
393 if (ext->rx_gain<-8 || ext->rx_gain>8)
396 PDEBUG(DEBUG_CONFIG, "receive volume: %d\n",ext->rx_gain);
398 if (!strcmp(option,"tx_gain")
399 || !strcmp(option,"txvol")) {
400 ext->tx_gain = atoi(param);
401 if (ext->tx_gain<-8 || ext->tx_gain>8)
404 PDEBUG(DEBUG_CONFIG, "transmit volume: %d\n",ext->tx_gain);
406 if (!strcmp(option,"own_setup")) {
408 while(ext_yesno[i]) {
409 if (!strcasecmp(param,ext_yesno[i]))
415 PDEBUG(DEBUG_CONFIG, "own_setup %s\n", ext_yesno[i]);
417 PDEBUG(DEBUG_CONFIG, "given own_setup param unknown: %s\n", param);
420 if (!strcmp(option,"own_proceeding")) {
422 while(ext_yesno[i]) {
423 if (!strcasecmp(param,ext_yesno[i]))
428 ext->own_proceeding = i;
429 PDEBUG(DEBUG_CONFIG, "own_proceeding %s\n", ext_yesno[i]);
431 PDEBUG(DEBUG_CONFIG, "given own_proceeding param unknown: %s\n", param);
434 if (!strcmp(option,"own_alerting")) {
436 while(ext_yesno[i]) {
437 if (!strcasecmp(param,ext_yesno[i]))
442 ext->own_alerting = i;
443 PDEBUG(DEBUG_CONFIG, "own_alerting %s\n", ext_yesno[i]);
445 PDEBUG(DEBUG_CONFIG, "given own_alerting param unknown: %s\n", param);
448 if (!strcmp(option,"own_cause")) {
450 while(ext_yesno[i]) {
451 if (!strcasecmp(param,ext_yesno[i]))
457 PDEBUG(DEBUG_CONFIG, "own_cause %s\n", ext_yesno[i]);
459 PDEBUG(DEBUG_CONFIG, "given own_cause param unknown: %s\n", param);
462 if (!strcmp(option,"facility")) {
464 while(ext_yesno[i]) {
465 if (!strcasecmp(param,ext_yesno[i]))
471 PDEBUG(DEBUG_CONFIG, "facility %s\n", ext_yesno[i]);
473 PDEBUG(DEBUG_CONFIG, "given facility param unknown: %s\n", param);
476 if (!strcmp(option,"display_cause")) {
477 if (!strcasecmp(param, "german"))
478 ext->display_cause = DISPLAY_CAUSE_GERMAN;
479 else if (!strcasecmp(param, "english"))
480 ext->display_cause = DISPLAY_CAUSE_ENGLISH;
481 else if (!strcasecmp(param, "german-location"))
482 ext->display_cause = DISPLAY_LOCATION_GERMAN;
483 else if (!strcasecmp(param, "english-location"))
484 ext->display_cause = DISPLAY_LOCATION_ENGLISH;
485 else if (!strcasecmp(param, "number"))
486 ext->display_cause = DISPLAY_CAUSE_NUMBER;
488 ext->display_cause = DISPLAY_CAUSE_NONE;
490 PDEBUG(DEBUG_CONFIG, "display cause: %d\n",ext->display_cause);
493 if (!strcmp(option,"display_ext")) {
494 if (!strcasecmp(param, "number"))
495 ext->display_ext = DISPLAY_CID_NUMBER;
496 else if (!strcasecmp(param, "abbrev"))
497 ext->display_ext = DISPLAY_CID_ABBREVIATION;
498 else if (!strcasecmp(param, "name"))
499 ext->display_ext = DISPLAY_CID_NAME;
500 else if (!strcasecmp(param, "number-name"))
501 ext->display_ext = DISPLAY_CID_NUMBER_NAME;
502 else if (!strcasecmp(param, "name-number"))
503 ext->display_ext = DISPLAY_CID_NAME_NUMBER;
504 else if (!strcasecmp(param, "abbrev-number"))
505 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER;
506 else if (!strcasecmp(param, "abbrev-name"))
507 ext->display_ext = DISPLAY_CID_ABBREV_NAME;
508 else if (!strcasecmp(param, "abbrev-name-number"))
509 ext->display_ext = DISPLAY_CID_ABBREV_NAME_NUMBER;
510 else if (!strcasecmp(param, "abbrev-number-name"))
511 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER_NAME;
513 ext->display_ext = DISPLAY_CID_ASIS;
515 PDEBUG(DEBUG_CONFIG, "display ext: %d\n",ext->display_ext);
518 if (!strcmp(option,"display_ext")) {
520 while(ext_yesno[i]) {
521 if (!strcasecmp(param,ext_yesno[i]))
526 ext->display_ext = i;
527 PDEBUG(DEBUG_CONFIG, "display ext %s\n", ext_yesno[i]);
529 PDEBUG(DEBUG_CONFIG, "given display_ext param unknown: %s\n", param);
532 if (!strcmp(option,"display_int")) {
534 while(ext_yesno[i]) {
535 if (!strcasecmp(param,ext_yesno[i]))
540 ext->display_int = i;
541 PDEBUG(DEBUG_CONFIG, "display int %s\n", ext_yesno[i]);
543 PDEBUG(DEBUG_CONFIG, "given display_int param unknown: %s\n", param);
546 if (!strcmp(option,"display_fake")) {
548 while(ext_yesno[i]) {
549 if (!strcasecmp(param,ext_yesno[i]))
554 ext->display_fake = i;
555 PDEBUG(DEBUG_CONFIG, "display fake caller ids %s\n", ext_yesno[i]);
557 PDEBUG(DEBUG_CONFIG, "given display_fake param unknown: %s\n", param);
560 if (!strcmp(option,"display_anon")) {
562 while(ext_yesno[i]) {
563 if (!strcasecmp(param,ext_yesno[i]))
568 ext->display_anon = i;
569 PDEBUG(DEBUG_CONFIG, "display anonymouse ids %s\n", ext_yesno[i]);
571 PDEBUG(DEBUG_CONFIG, "given display_anon param unknown: %s\n", param);
574 if (!strcmp(option,"display_menu")) {
576 while(ext_yesno[i]) {
577 if (!strcasecmp(param,ext_yesno[i]))
582 ext->display_menu = i;
583 PDEBUG(DEBUG_CONFIG, "display menu %s\n", ext_yesno[i]);
585 PDEBUG(DEBUG_CONFIG, "given display_menu param unknown: %s\n", param);
588 if (!strcmp(option,"display_dialing")) {
590 while(ext_yesno[i]) {
591 if (!strcasecmp(param,ext_yesno[i]))
596 ext->display_dialing = i;
597 PDEBUG(DEBUG_CONFIG, "display dialing %s\n", ext_yesno[i]);
599 PDEBUG(DEBUG_CONFIG, "given display_dialing param unknown: %s\n", param);
602 if (!strcmp(option,"display_name")) {
604 while(ext_yesno[i]) {
605 if (!strcasecmp(param,ext_yesno[i]))
610 ext->display_name = i;
611 PDEBUG(DEBUG_CONFIG, "display name %s\n", ext_yesno[i]);
613 PDEBUG(DEBUG_CONFIG, "given display_name param unknown: %s\n", param);
616 if (!strcmp(option,"tones_dir")) {
617 if (param[strlen(param)-1] == '/')
618 param[strlen(param)-1]=0;
619 SCPY(ext->tones_dir, param);
621 PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
623 if (!strcmp(option,"record")) {
624 if (!strcasecmp(param, "mono"))
625 ext->record = CODEC_MONO;
626 else if (!strcasecmp(param, "stereo"))
627 ext->record = CODEC_STEREO;
628 else if (!strcasecmp(param, "8bit"))
629 ext->record = CODEC_8BIT;
630 else if (!strcasecmp(param, "law"))
631 ext->record = CODEC_LAW;
633 ext->record = CODEC_OFF;
634 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
636 if (!strcmp(option,"password")) {
637 SCPY(ext->password, param);
639 PDEBUG(DEBUG_CONFIG, "password: %s\n",param);
641 if (!strcmp(option,"vbox_mode")) {
642 if (!strcasecmp(param, "parallel"))
643 ext->vbox_mode = VBOX_MODE_PARALLEL;
644 else if (!strcasecmp(param, "announcement"))
645 ext->vbox_mode = VBOX_MODE_ANNOUNCEMENT;
647 ext->vbox_mode = VBOX_MODE_NORMAL;
648 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
650 if (!strcmp(option,"vbox_codec")) {
651 if (!strcasecmp(param, "stereo"))
652 ext->vbox_codec = CODEC_STEREO;
653 else if (!strcasecmp(param, "8bit"))
654 ext->vbox_codec = CODEC_8BIT;
655 else if (!strcasecmp(param, "law"))
656 ext->vbox_codec = CODEC_LAW;
658 ext->vbox_codec = CODEC_MONO;
659 PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
661 if (!strcmp(option,"vbox_time")) {
662 ext->vbox_time = atoi(param);
663 if (ext->vbox_time < 0)
666 PDEBUG(DEBUG_CONFIG, "vbox time to record: %d\n",ext->vbox_time);
668 if (!strcmp(option,"vbox_display")) {
669 if (!strcasecmp(param, "detailed")
670 || !strcasecmp(param, "detailled"))
671 ext->vbox_display = VBOX_DISPLAY_DETAILED;
672 else if (!strcasecmp(param, "off"))
673 ext->vbox_display = VBOX_DISPLAY_OFF;
675 ext->vbox_display = VBOX_DISPLAY_BRIEF;
676 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
678 if (!strcmp(option,"vbox_language")) {
679 if (!strcasecmp(param, "german"))
680 ext->vbox_language = VBOX_LANGUAGE_GERMAN;
682 ext->vbox_language = VBOX_LANGUAGE_ENGLISH;
683 PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
685 if (!strcmp(option,"vbox_email")) {
686 SCPY(ext->vbox_email, param);
687 PDEBUG(DEBUG_CONFIG, "given vbox email: %s\n", param);
689 if (!strcmp(option,"vbox_email_file")) {
691 while(ext_yesno[i]) {
692 if (!strcasecmp(param,ext_yesno[i]))
697 ext->vbox_email_file = i;
698 PDEBUG(DEBUG_CONFIG, "attach audio file %s\n", ext_yesno[i]);
700 PDEBUG(DEBUG_CONFIG, "given vbox_email_file param unknown: %s\n", param);
703 if (!strcmp(option,"vbox_free")) {
705 while(ext_yesno[i]) {
706 if (!strcasecmp(param,ext_yesno[i]))
712 PDEBUG(DEBUG_CONFIG, "vbox_free %s\n", ext_yesno[i]);
714 PDEBUG(DEBUG_CONFIG, "given vbox_free param unknown: %s\n", param);
717 if (!strcmp(option,"last_in")) {
718 if (param[0] && last_in_count<MAX_REMEMBER) {
719 SCPY(ext->last_in[last_in_count], param);
722 PDEBUG(DEBUG_CONFIG, "last_in dialed number: %s\n",param);
724 if (!strcmp(option,"last_out")) {
725 if (param[0] && last_out_count<MAX_REMEMBER) {
726 SCPY(ext->last_out[last_out_count], param);
729 PDEBUG(DEBUG_CONFIG, "last_out dialed number: %s\n",param);
731 if (!strcmp(option,"datacall")) {
733 while(ext_yesno[i]) {
734 if (!strcasecmp(param,ext_yesno[i]))
740 PDEBUG(DEBUG_CONFIG, "datacall %s\n", ext_yesno[i]);
742 PDEBUG(DEBUG_CONFIG, "given datacall param unknown: %s\n", param);
745 if (!strcmp(option,"seconds")) {
747 while(ext_yesno[i]) {
748 if (!strcasecmp(param,ext_yesno[i]))
753 ext->no_seconds = 1-i;
754 PDEBUG(DEBUG_CONFIG, "seconds %s\n", ext_yesno[i]);
756 PDEBUG(DEBUG_CONFIG, "unknown param for seconds: %s\n", param);
759 PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n",filename,line,option);
770 * writes extension for given extension number from structure
772 int write_extension(struct extension *ext, char *number)
778 if (number[0] == '\0')
781 SPRINT(filename, "%s/%s/settings", EXTENSION_DATA, number);
783 if (!(fp = fopen(filename, "w"))) {
784 PERROR("Cannot open settings: \"%s\"\n", filename);
788 fprintf(fp,"# Settings of extension %s\n\n", number);
790 fprintf(fp,"# Name of extension:\n");
791 fprintf(fp,"name %s\n\n",ext->name);
793 fprintf(fp,"# Predialed prefix after pick-up of the phone\n");
794 fprintf(fp,"prefix %s\n\n",ext->prefix);
796 fprintf(fp,"# Next prefix to dial pick-up of the phone\n");
797 fprintf(fp,"# This will be cleared on hangup.\n");
798 fprintf(fp,"next %s\n\n",ext->next);
800 // fprintf(fp,"# Set up alarm message after prefix is dialed and connection is established\n");
801 // fprintf(fp,"alarm %s\n\n",ext->alarm);
803 fprintf(fp,"# Interface(s) to ring on calls to extension (as named in interface.conf)\n");
804 fprintf(fp,"# Seperate multiple interfaces by using komma without spaces\n");
805 fprintf(fp,"# Example: Int would ring on the interface with the name \"Int\"\n");
806 fprintf(fp,"# Int1,Int2 would ring incoming calls on both interfaces Int1 and Int2.\n");
807 fprintf(fp,"interfaces %s\n\n",ext->interfaces);
809 fprintf(fp,"# Call Forward Unconditional (CFU)\n");
810 fprintf(fp,"# No port will be called, CFB, CFNR and CFP is ignored.\n");
811 fprintf(fp,"# Use keyword \"vbox\" to forward call directly to answering machine.\n");
812 fprintf(fp,"cfu %s\n\n",ext->cfu);
814 fprintf(fp,"# Call Forward when Busy (CFB)\n");
815 fprintf(fp,"# If the extension is in use at least once, this forward is done.\n");
816 fprintf(fp,"# In case of busy line, CFNR and CFP is ignored.\n");
817 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine when busy.\n");
818 fprintf(fp,"cfb %s\n\n",ext->cfb);
820 fprintf(fp,"# Call Forward on No Response (CFNR)\n");
821 fprintf(fp,"# If noone answers, the call is forwarded, ports and CFP will be released.\n");
822 fprintf(fp,"# The default delay is 20 seconds.\n");
823 fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine on no response.\n");
824 fprintf(fp,"cfnr %s\n",ext->cfnr);
825 fprintf(fp,"cfnr_delay %d\n\n",ext->cfnr_delay);
827 fprintf(fp,"# Call Forward Parallel (CFP)\n");
828 fprintf(fp,"# Call will ring on the forwarded number, simulaniousely with the ports.\n");
829 fprintf(fp,"cfp %s\n\n",ext->cfp);
831 fprintf(fp,"# Allow user to change call forwarding.\n");
832 fprintf(fp,"change_forward %s\n\n", ext_yesno[ext->change_forward]);
834 fprintf(fp,"# Caller id\n# This must be one of the following:\n");
835 fprintf(fp,"# <number> (as dialed from your local area)\n");
836 fprintf(fp,"# <number> anonymous (will only be shown to emergency phones)\n");
837 fprintf(fp,"# none (no number available at all)\n");
838 fprintf(fp,"# by default the number is of type UNKNOWN (for MULTIPOINT lines)\n");
839 fprintf(fp,"# if your caller id is not screened on outgoing calls use one of the following:\n");
840 fprintf(fp,"# use prefix 'i' for TYPE INTERNATIONAL (i<county code><areacode+number>)\n");
841 fprintf(fp,"# use prefix 'n' for TYPE NATIONAL (n<areacode+number>)\n");
842 fprintf(fp,"# use prefix 's' for TYPE SUBSCRIBER (s<local number>)\n");
843 if (ext->callerid_present == INFO_PRESENT_NOTAVAIL)
844 fprintf(fp,"callerid none\n\n");
846 switch(ext->callerid_type) {
847 case INFO_NTYPE_INTERNATIONAL:
848 fprintf(fp,"callerid i%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
850 case INFO_NTYPE_NATIONAL:
851 fprintf(fp,"callerid n%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
853 case INFO_NTYPE_SUBSCRIBER:
854 fprintf(fp,"callerid s%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
857 fprintf(fp,"callerid %s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
861 fprintf(fp,"# Caller id for next call (see caller id)\n");
862 if (ext->id_next_call_present < 0)
863 fprintf(fp,"id_next_call \n\n");
864 else if (ext->id_next_call_present == INFO_PRESENT_NOTAVAIL)
865 fprintf(fp,"id_next_call none\n\n");
867 switch(ext->id_next_call_type) {
868 case INFO_NTYPE_INTERNATIONAL:
869 fprintf(fp,"id_next_call i%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
871 case INFO_NTYPE_NATIONAL:
872 fprintf(fp,"id_next_call n%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
874 case INFO_NTYPE_SUBSCRIBER:
875 fprintf(fp,"id_next_call s%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
878 fprintf(fp,"id_next_call %s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
882 fprintf(fp,"# Allow user to change caller ID.\n");
883 fprintf(fp,"change_callerid %s\n\n", ext_yesno[ext->change_callerid]);
885 fprintf(fp,"# Caller Line Identification Presentation (CLIP)\n");
886 fprintf(fp,"# clip (asis|hide)\n");
887 fprintf(fp,"# asis: On forwarded calls the CLIP is used as presented by the calling party.\n");
888 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
891 fprintf(fp,"clip hide\n\n");
894 fprintf(fp,"clip asis\n\n");
897 fprintf(fp,"# Connected Line Identification Presentation (COLP)\n");
898 fprintf(fp,"# colp (asis|hide|force)\n");
899 fprintf(fp,"# asis: Provides colp as defined by the extension's caller id.\n");
900 fprintf(fp,"# On forwarded calls the COLP is used as presented by the called party.\n");
901 fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
902 fprintf(fp,"# force: If COLP is not presented by forwarded calls the dialed number is used.\n");
905 fprintf(fp,"colp hide\n\n");
908 fprintf(fp,"colp force\n\n");
911 fprintf(fp,"colp asis\n\n");
914 fprintf(fp,"# CLIP Prefix\n");
915 fprintf(fp,"# Adds a prefix to incoming caller IDs, so telephones will be able to respond\n");
916 fprintf(fp,"# to unanswered calls from their list. The prefix must be the digit(s) to get\n");
917 fprintf(fp,"# an external line. The caller ID will then be extendet so that they can be\n");
918 fprintf(fp,"# dialed from internal telephones. Many telephones have this feature, but some\n");
919 fprintf(fp,"# don't.\n");
920 fprintf(fp,"clip_prefix %s\n\n",ext->clip_prefix);
922 fprintf(fp,"# Keypad control\n");
923 fprintf(fp,"# If supported by telephone, pressing a key on the keypad will not result in\n");
924 fprintf(fp,"# DTMF tone, but the digit is transmitted via D-channel diaing info.\n");
925 fprintf(fp,"keypad %s\n\n",(ext->keypad)?"yes":"no");
927 fprintf(fp,"# Ignore restriction of COLP and CLIP\n");
928 fprintf(fp,"# In this case even restricted numbers are presented to this extension.\n");
929 fprintf(fp,"# This also works for incoming external anonymous calls IF:\n");
930 fprintf(fp,"# You have the CLIRIGN feature like POLICE or equivalent.\n");
931 fprintf(fp,"anon-ignore %s\n\n",(ext->anon_ignore)?"yes":"no");
933 fprintf(fp,"# Dialing rights (none|internal|local|national|international)\n");
934 fprintf(fp,"rights %s\n\n",ext_rights[ext->rights]);
936 fprintf(fp,"# Delete function for external calls. '*' will delete the last digit, '#' will\n");
937 fprintf(fp,"# delete the complete number. Also enable 'display_dialing' to see on the\n");
938 fprintf(fp,"# display what actually happens.\n");
939 fprintf(fp,"delete_ext %s\n\n",ext_yesno[ext->delete_ext]);
941 fprintf(fp,"# If noknocking is enabled, the caller will get a busy message when the\n");
942 fprintf(fp,"# extension is doing at least one call.\n");
943 fprintf(fp,"noknocking %s\n\n",ext_yesno[ext->noknocking]);
945 fprintf(fp,"# Transmit volume (-8 .. 8)\n");
946 fprintf(fp,"# 0 = normal\n");
947 fprintf(fp,"# 1 = double, 2 = quadrupel, 8 = 256 times (amplitude)\n");
948 fprintf(fp,"# -1 = half, -2 = quarter, 8 = 1/256th (amplitude)\n");
949 fprintf(fp,"# Audio data is limited to the maximum value when exceeds limit.\n");
950 fprintf(fp,"tx_gain %d\n\n",ext->tx_gain);
952 fprintf(fp,"# Receive volume (-8 .. 8)\n");
953 fprintf(fp,"# (see tx_gain)\n");
954 fprintf(fp,"rx_gain %d\n\n",ext->rx_gain);
957 fprintf(fp,"# Force to use tones and announcements generated by the pbx.\n");
958 fprintf(fp,"# For internal calls always own tones are used. You may specify own tones for\n");
959 fprintf(fp,"# different call states:\n");
960 fprintf(fp,"# own_setup (dialtone and during dialing)\n");
961 fprintf(fp,"# own_proceeding (call in poceeding state)\n");
962 fprintf(fp,"# own_alerting (call is ringing)\n");
963 fprintf(fp,"# own_cause (when the call gets disconnected or failed to be completed)\n");
964 fprintf(fp,"own_setup %s\n",ext_yesno[ext->own_setup]);
965 fprintf(fp,"own_proceeding %s\n",ext_yesno[ext->own_proceeding]);
966 fprintf(fp,"own_alerting %s\n",ext_yesno[ext->own_alerting]);
967 fprintf(fp,"own_cause %s\n\n",ext_yesno[ext->own_cause]);
969 fprintf(fp,"# Allow facility information to be transfered to the telephone.\n");
970 fprintf(fp,"# This is required to receive advice of charge.\n");
971 fprintf(fp,"facility %s\n\n",ext_yesno[ext->facility]);
973 fprintf(fp,"# Display clear causes using display messages (Q.850)\n# This must be one of the following:\n");
974 fprintf(fp,"# none (no displaying of clear causes)\n");
975 fprintf(fp,"# english (display cause text in english)\n");
976 fprintf(fp,"# german (display cause text in german)\n");
977 fprintf(fp,"# number (display cause number only)\n");
978 fprintf(fp,"# english-location (display cause text in english and location)\n");
979 fprintf(fp,"# german-location (display cause text in german and location)\n");
980 switch(ext->display_cause) {
981 case DISPLAY_CAUSE_ENGLISH:
982 fprintf(fp,"display_cause english\n\n");
984 case DISPLAY_CAUSE_GERMAN:
985 fprintf(fp,"display_cause german\n\n");
987 case DISPLAY_LOCATION_ENGLISH:
988 fprintf(fp,"display_cause english-location\n\n");
990 case DISPLAY_LOCATION_GERMAN:
991 fprintf(fp,"display_cause german-location\n\n");
993 case DISPLAY_CAUSE_NUMBER:
994 fprintf(fp,"display_cause number\n\n");
997 fprintf(fp,"display_cause none\n\n");
1000 fprintf(fp,"# Display external caller ids using display override (yes or no)\n");
1001 fprintf(fp,"# example: \"15551212\"\n");
1002 fprintf(fp,"display_ext %s\n\n",(ext->display_ext)?"yes":"no");
1004 fprintf(fp,"# Display internal caller ids using display override (yes or no)\n");
1005 fprintf(fp,"# example: \"200 (int)\"\n");
1006 fprintf(fp,"display_int %s\n\n",(ext->display_int)?"yes":"no");
1008 fprintf(fp,"# Display if calls are anonymous using display override (yes or no)\n");
1009 fprintf(fp,"# This makes only sense if the anon-ignore feature is enabled.\n");
1010 fprintf(fp,"# example: \"15551212 anon\"\n");
1011 fprintf(fp,"display_anon %s\n\n",(ext->display_anon)?"yes":"no");
1013 fprintf(fp,"# Display fake caller ids using display override (yes or no)\n");
1014 fprintf(fp,"# If the caller uses \"clip no screening\", you will see if the number is\n");
1015 fprintf(fp,"# real or fake\n");
1016 fprintf(fp,"# example: \"15551212 fake\"\n");
1017 fprintf(fp,"display_fake %s\n\n",(ext->display_fake)?"yes":"no");
1019 fprintf(fp,"# Display caller's name if available. (yes or no)\n");
1020 fprintf(fp,"# example: \"15551212 Axel\"\n");
1021 fprintf(fp,"display_name %s\n\n",(ext->display_name)?"yes":"no");
1023 fprintf(fp,"# Display menu when '*' and '#' is pressed. The menu shows all prefixes for\n");
1024 fprintf(fp,"# internal dialing by pressing '*' for previous prefix and '#' for next prefix.\n");
1025 fprintf(fp,"# Also the dialed prefix is show on display. (yes or no)\n");
1026 fprintf(fp,"display_menu %s\n\n",(ext->display_menu)?"yes":"no");
1028 fprintf(fp,"# Display digits as they are interpreted by pbx. (yes or no)\n");
1029 fprintf(fp,"display_dialing %s\n\n",(ext->display_dialing)?"yes":"no");
1031 fprintf(fp,"# Tones directory for announcements and patterns\n");
1032 fprintf(fp,"# Enter nothing for default tones as selected by options.conf or interface.conf.\n");
1033 fprintf(fp,"tones_dir %s\n\n",ext->tones_dir);
1035 fprintf(fp,"# Record calls to extension's directory. The file is written as wave.\n");
1036 fprintf(fp,"# This must be one of the following:\n");
1037 fprintf(fp,"# off (no recording)\n");
1038 fprintf(fp,"# mono (records wave 16 bit mono, 128kbits/s)\n");
1039 fprintf(fp,"# stereo (records wave 32 bit stereo, 256kbits/s)\n");
1040 fprintf(fp,"# 8bit (records wave 8 bit mono, 64kbits/s)\n");
1041 fprintf(fp,"# law (records xLaw encoded, as specified in options.conf, 64kbps/s)\n");
1042 switch(ext->record) {
1044 fprintf(fp,"record mono\n\n");
1047 fprintf(fp,"record stereo\n\n");
1050 fprintf(fp,"record 8bit\n\n");
1053 fprintf(fp,"record law\n\n");
1056 fprintf(fp,"record off\n\n");
1059 fprintf(fp,"# Password for callback and login\n");
1060 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1061 fprintf(fp,"password %s\n\n",ext->password);
1063 fprintf(fp,"# The Answering Machine. Enter the mode of answering machine.\n");
1064 fprintf(fp,"# This must be one of the following:\n");
1065 fprintf(fp,"# normal (plays announcement and records after that)\n");
1066 fprintf(fp,"# parallel (plays announcement and records also DURING announcement.)\n");
1067 fprintf(fp,"# announcement (just plays announcement and hangs up)\n");
1068 switch(ext->vbox_mode) {
1069 case VBOX_MODE_PARALLEL:
1070 fprintf(fp,"vbox_mode parallel\n\n");
1072 case VBOX_MODE_ANNOUNCEMENT:
1073 fprintf(fp,"vbox_mode announcement\n\n");
1076 fprintf(fp,"vbox_mode normal\n\n");
1079 fprintf(fp,"# The Answering Machine. Enter the type of codec for recording.\n");
1080 fprintf(fp,"# This must be one of the following:\n");
1081 fprintf(fp,"# law (alaw/ulas codec, as specified in options.conf)\n");
1082 fprintf(fp,"# mono (16 bit mono wave file)\n");
1083 fprintf(fp,"# stereo (16 bit stereo wave file)\n");
1084 fprintf(fp,"# 8bit (8 bit mono wave file)\n");
1085 switch(ext->vbox_codec) {
1087 fprintf(fp,"vbox_codec law\n\n");
1090 fprintf(fp,"vbox_codec stereo\n\n");
1093 fprintf(fp,"vbox_codec 8bit\n\n");
1096 fprintf(fp,"vbox_codec mono\n\n");
1099 fprintf(fp,"# The Answering Machine. Enter maximum time to record after announcement.\n");
1100 fprintf(fp,"# Leave empty, enter \"infinite\" or give time in seconds.\n");
1101 fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1103 fprintf(fp,"vbox_time %d\n\n",ext->vbox_time);
1105 fprintf(fp,"vbox_time infinite\n\n");
1107 fprintf(fp,"# The Answering Machine. Enter mode for display current state.\n");
1108 fprintf(fp,"# This must be one of the following:\n");
1109 fprintf(fp,"# brief (displays brief information, for small displays)\n");
1110 fprintf(fp,"# detailed (displays detailed information, for larger displays)\n");
1111 fprintf(fp,"# off (don't display anything)\n");
1112 switch(ext->vbox_display) {
1113 case VBOX_DISPLAY_OFF:
1114 fprintf(fp,"vbox_display off\n\n");
1116 case VBOX_DISPLAY_DETAILED:
1117 fprintf(fp,"vbox_display detailed\n\n");
1120 fprintf(fp,"vbox_display brief\n\n");
1123 fprintf(fp,"# The Answering Machine. Enter type of language: \"english\" or \"german\"\n");
1124 fprintf(fp,"# Display information of the menu, will be provided as specified.\n");
1125 fprintf(fp,"# The menu's voice is located in \"vbox_english\" and \"vbox_german\".\n");
1126 if (ext->vbox_language)
1127 fprintf(fp,"vbox_language german\n\n");
1129 fprintf(fp,"vbox_language english\n\n");
1131 fprintf(fp,"# The Answering Machine. Enter email to send incoming messages to:\n");
1132 fprintf(fp,"# All incoming message will be send to the given address.\n");
1133 fprintf(fp,"# The audio file is attached if \"vbox_email_file\" is 'yes'\n");
1134 fprintf(fp,"vbox_email %s\n", ext->vbox_email);
1135 fprintf(fp,"vbox_email_file %s\n\n",ext_yesno[ext->vbox_email_file]);
1137 fprintf(fp,"# If audio path is connected prior answering of a call, say 'yes'\n");
1138 fprintf(fp,"# will cause the call to be billed after playing the announcement. (yes or no)\n");
1139 fprintf(fp,"vbox_free %s\n\n",(ext->vbox_free)?"yes":"no");
1141 fprintf(fp,"# Accept incoming data calls as it would be an audio call.\n");
1142 fprintf(fp,"datacall %s\n\n",ext_yesno[ext->datacall]);
1144 fprintf(fp,"# Include seconds (time) in the connect message. (Should be always enabled.)\n");
1145 fprintf(fp,"seconds %s\n\n",ext_yesno[1-ext->no_seconds]);
1147 fprintf(fp,"# Last outgoing and incoming numbers (including prefix)\n");
1149 while(i < MAX_REMEMBER) {
1150 if (ext->last_out[i][0])
1151 fprintf(fp,"last_out %s\n",ext->last_out[i]);
1155 while(i < MAX_REMEMBER) {
1156 if (ext->last_in[i][0])
1157 fprintf(fp,"last_in %s\n",ext->last_in[i]);
1168 /* write log for extension
1171 int write_log(char *number, char *callerid, char *calledid, time_t start, time_t stop, int aoce, int cause, int location)
1173 const char *mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1178 if (callerid[0] == '\0')
1179 callerid = (char *)"<unknown>";
1181 SPRINT(filename, "%s/%s/log", EXTENSION_DATA, number);
1183 if (!(fp = fopen(filename, "a"))) {
1184 PERROR("Cannot open log: \"%s\"\n", filename);
1188 tm = localtime(&start);
1189 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);
1191 fprintf(fp," %2ld:%02d:%02d", (stop-start)/3600, (((unsigned int)(stop-start))/60)%60, ((unsigned int)(stop-start))%60);
1193 fprintf(fp," --:--:--");
1194 fprintf(fp," %s -> %s", callerid, calledid);
1195 if (cause >= 1 && cause <=127 && location>=0 && location<=15)
1196 fprintf(fp," (cause=%d '%s' location=%d '%s')", cause, isdn_cause[cause].german, location, isdn_location[location].german);
1206 * reads phone book of extextension and compares the given elements which
1207 * are: abreviation, phone number, name (name is not compared)
1208 * on success a 1 is returned and the pointers of elements are set to the
1211 int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, char **name_pointer)
1216 static char abbrev[32], phone[256], name[256];
1217 unsigned int line,i;
1219 int found = 0, found_if_more_digits = 0;
1221 SPRINT(filename, "%s/%s/phonebook", EXTENSION_DATA, number);
1223 if (!(fp = fopen(filename, "r"))) {
1224 PERROR("Cannot open phonebook: \"%s\"\n", filename);
1229 while((GETLINE(buffer, fp))) {
1233 while(*p <= 32) { /* skip spaces */
1238 if (*p==0 || *p=='#') /* ignore comments and empty line */
1245 i=0; /* read abbrev */
1247 if (i+1 >= sizeof(abbrev)) {
1248 PERROR_RUNTIME("Error in %s (line %d): abbrev too long.\n",filename,line);
1255 while(*p <= 32) { /* skip spaces */
1261 if (*p!=0 && *p!='#') { /* phone */
1262 i=0; /* read phone */
1264 if (i+1 >= sizeof(phone)) {
1265 PERROR_RUNTIME("Error in %s (line %d): phone too long.\n",filename,line);
1271 while(*p <= 32) { /* skip spaces */
1278 if (*p!=0 && *p!='#') { /* name */
1279 i=0; /* read name */
1281 if (i+1 >= sizeof(name)) {
1282 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1290 if (*abbrev_pointer) {
1291 if (!strncmp(*abbrev_pointer, abbrev, strlen(*abbrev_pointer))) {
1292 /* may match if abbreviation is longer */
1293 found_if_more_digits = 1;
1295 if (!!strcasecmp(*abbrev_pointer, abbrev))
1299 if (!!strcasecmp(*phone_pointer, phone))
1302 if (!!strcasecmp(*name_pointer, name))
1306 break; /* found entry */
1312 *abbrev_pointer = abbrev;
1313 *phone_pointer = phone;
1314 *name_pointer = name;
1318 if (found_if_more_digits)
1324 /* parsing secrets file
1326 * 'number' specifies the externsion number, not the caller id
1327 * 'remote_id' specifies the dialed number, or the caller id for incoming calls
1328 * the result is the auth, crypt and key string, and 1 is returned.
1329 * on failure or not matching number, the 0 is returned
1331 int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **crypt_pointer, char **key_pointer)
1337 static char auth[64], crypt[64], key[4096];
1338 unsigned int line,i;
1342 SPRINT(filename, "%s/%s/secrets", EXTENSION_DATA, number);
1344 if (!(fp = fopen(filename, "r"))) {
1345 PERROR("Cannot open secrets: \"%s\"\n", filename);
1350 while((GETLINE(buffer, fp))) {
1354 while(*p <= 32) { /* skip spaces */
1359 if (*p==0 || *p=='#') /* ignore comments and empty line */
1367 i=0; /* read auth */
1369 if (i+1 >= sizeof(remote)) {
1370 PERROR_RUNTIME("Error in %s (line %d): remote too long.\n",filename,line);
1377 while(*p <= 32) { /* skip spaces */
1383 if (*p!=0 && *p!='#') { /* auth */
1384 i=0; /* read auth */
1386 if (i+1 >= sizeof(auth)) {
1387 PERROR_RUNTIME("Error in %s (line %d): auth too long.\n",filename,line);
1393 while(*p <= 32) { /* skip spaces */
1400 if (*p!=0 && *p!='#') { /* crypt */
1401 i=0; /* read crypt */
1403 if (i+1 >= sizeof(crypt)) {
1404 PERROR_RUNTIME("Error in %s (line %d): crypt too long.\n",filename,line);
1410 while(*p <= 32) { /* skip spaces */
1417 if (*p!=0 && *p!='#') { /* key */
1420 if (i+1 >= sizeof(key)) {
1421 PERROR_RUNTIME("Error in %s (line %d): key too long.\n",filename,line);
1428 //printf("COMPARING: '%s' with '%s' %s %s %s\n", remote_id, remote, auth, crypt, key);
1430 if (!!strcasecmp(remote, remote_id))
1434 break; /* found entry */
1440 *auth_pointer = auth;
1441 *crypt_pointer = crypt;
1450 * the caller id is given and the name is returned. if the name is not found,
1452 * on success a 1 is returned and the pointers of elements are set to the
1455 char *parse_directory(char *number, int type)
1460 static char phone[32], name[64];
1461 unsigned int line,i;
1465 SPRINT(filename, "%s/directory.list", CONFIG_DATA);
1467 if (!(fp = fopen(filename, "r"))) {
1468 PERROR("Cannot open directory: \"%s\"\n", filename);
1473 while((GETLINE(buffer, fp))) {
1477 while(*p <= 32) { /* skip spaces */
1482 if (*p==0 || *p=='#') /* ignore comments and empty line */
1488 i=0; /* read number */
1490 if (i+1 >= sizeof(phone)) {
1491 PERROR_RUNTIME("Error in %s (line %d): number too long.\n",filename,line);
1498 while(*p <= 32) { /* skip spaces */
1504 i=0; /* read name */
1506 if (i+1 >= sizeof(name)) {
1507 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1514 if (phone[0] == 'i') {
1515 if (type != INFO_NTYPE_INTERNATIONAL)
1517 if (!strcmp(number, phone+1)) {
1523 if (phone[0] == 'n') {
1524 if (type != INFO_NTYPE_NATIONAL)
1526 if (!strcmp(number, phone+1)) {
1532 if (phone[0] == 's') {
1533 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1535 if (!strcmp(number, phone+1)) {
1541 if (!strncmp(phone, options.international, strlen(options.international))) {
1542 if (type != INFO_NTYPE_INTERNATIONAL)
1544 if (!strcmp(number, phone+strlen(options.international))) {
1550 if (!options.national[0]) { /* no national prefix */
1551 if (type == INFO_NTYPE_INTERNATIONAL)
1553 if (!strcmp(number, phone)) {
1559 if (!strncmp(phone, options.national, strlen(options.national))) {
1560 if (type != INFO_NTYPE_NATIONAL)
1562 if (!strcmp(number, phone+strlen(options.national))) {
1568 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1570 if (!strcmp(number, phone)) {
1584 /* parse callbackauth
1586 * searches for the given caller id and returns 1 == true or 0 == false
1588 int parse_callbackauth(char *number, struct caller_info *callerinfo)
1593 unsigned int line,i;
1595 static char caller_type[32], caller_id[64];
1598 SPRINT(filename, "%s/%s/callbackauth", EXTENSION_DATA, number);
1600 if (!(fp = fopen(filename, "r"))) {
1601 PDEBUG(DEBUG_EPOINT, "Cannot open callbackauth: \"%s\"\n", filename);
1606 while((GETLINE(buffer, fp))) {
1610 while(*p <= 32) { /* skip spaces */
1615 if (*p==0 || *p=='#') /* ignore comments and empty line */
1621 i=0; /* read caller_type */
1623 if (i+1 >= sizeof(caller_type)) {
1624 PERROR_RUNTIME("Error in %s (line %d): caller_type too long.\n",filename,line);
1627 caller_type[i+1] = '\0';
1628 caller_type[i++] = *p++;
1631 while(*p <= 32) { /* skip spaces */
1637 if (*p!=0 && *p!='#') { /* caller_id */
1638 i=0; /* read caller_id */
1640 if (i+1 >= sizeof(caller_id)) {
1641 PERROR_RUNTIME("Error in %s (line %d): caller_id too long.\n",filename,line);
1644 caller_id[i+1] = '\0';
1645 caller_id[i++] = *p++;
1650 if (caller_type[0]=='\0' && caller_id[0]=='\0')
1653 if (atoi(caller_type) != callerinfo->ntype)
1656 if (!!strcmp(caller_id, callerinfo->id))
1660 break; /* found entry */
1671 /* append line to callbackauth
1674 void append_callbackauth(char *number, struct caller_info *callerinfo)
1679 SPRINT(filename, "%s/%s/callbackauth", EXTENSION_DATA, number);
1681 if (callerinfo->id[0]=='\0') {
1682 PERROR("caller has no id.\n");
1685 if (!(fp = fopen(filename, "a"))) {
1686 PERROR("Cannot open callbackauth: \"%s\"\n", filename);
1690 fprintf(fp, "%6d %s\n", callerinfo->ntype, callerinfo->id);