error inside information elements are now reported inside trace and main log,
[lcr.git] / extension.c
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** reading and writing files for extensions                                  **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include "main.h"
13
14 /* extension */
15
16 char *ext_rights[] = {
17         "none",
18         "internal",
19         "local",
20         "national",
21         "international",
22         NULL
23 };
24
25 char *ext_yesno[] = {
26         "no",
27         "yes",
28         NULL
29 };
30
31
32 /* read extension
33  *
34  * reads extension from given extension number and fills structure
35  */
36 int read_extension(struct extension *ext, char *num)
37 {
38         FILE *fp=NULL;
39         char number[32];
40         char filename[256];
41         char *p;
42         char option[32];
43         char param[256],param2[256];
44         unsigned int line,i;
45         char buffer[1024];
46         int last_in_count = 0, last_out_count = 0;
47
48         /* save number, so &ext and ext.number can be given as parameters - without overwriting itself */
49         SCPY(number, num);
50         
51         if (number[0] == '\0')
52                 return(0);
53
54         SPRINT(filename, "%s/%s/%s/settings", INSTALL_DATA, options.extensions_dir, number);
55
56         if (!(fp = fopen(filename, "r")))
57         {
58                 PDEBUG(DEBUG_CONFIG, "the given extension doesn't exist: \"%s\"\n", filename);
59                 return(0);
60         }
61
62         /* default values */
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 */
67         ext->cfnr_delay = 20;
68         ext->vbox_codec = CODEC_MONO;
69
70         line=0;
71         while((fgets(buffer, sizeof(buffer), fp)))
72         {
73                 line++;
74                 buffer[sizeof(buffer)-1] = '\0';
75                 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
76                 p = buffer;
77
78                 while(*p <= 32) /* skip spaces */
79                 {
80                         if (*p == 0)
81                                 break;
82                         p++;
83                 }
84                 if (*p==0 || *p=='#') /* ignore comments and empty line */
85                         continue;
86
87                 option[0]=0;
88                 i=0; /* read option */
89                 while(*p > 32)
90                 {
91                         if (i+1 >= sizeof(option))
92                         {
93                                 PERROR_RUNTIME("Error in %s (line %d): option too long.\n",filename,line);
94                                 break;
95                         }
96                         option[i+1] = '\0';
97                         option[i++] = *p++;
98                 }
99
100                 while(*p <= 32) /* skip spaces */
101                 {
102                         if (*p == 0)
103                                 break;
104                         p++;
105                 }
106
107                 param[0]=0;
108                 param2[0]=0;
109                 if (*p!=0 && *p!='#') /* param */
110                 {
111                         i=0; /* read param */
112                         while(*p > 32)
113                         {
114                                 if (i+1 >= sizeof(param))
115                                 {
116                                         PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
117                                         break;
118                                 }
119                                 param[i+1] = '\0';
120                                 param[i++] = *p++;
121                         }
122
123                         while(*p <= 32) /* skip spaces */
124                         {
125                                 if (*p == 0)
126                                         break;
127                                 p++;
128                         }
129
130                         if (*p!=0 && *p!='#') /* param2 */
131                         {
132                                 i=0; /* read param2 */
133                                 while(*p >= 32)
134                                 {
135                                         if (i+1 >= sizeof(param2))
136                                         {
137                                                 PERROR_RUNTIME("Error in %s (line %d): param too long.\n",filename,line);
138                                                 break;
139                                         }
140                                         param2[i+1] = '\0';
141                                         param2[i++] = *p++;
142                                 }
143                         }
144                 }
145
146                 /* at this point we have option and param */
147
148                 /* check option */
149                 if (!strcmp(option,"name"))
150                 {
151                         SCPY(ext->name, param);
152                         if (param2[0])
153                         {
154                                 SCAT(ext->name, " ");
155                                 SCAT(ext->name, param2);
156                         }
157
158                         PDEBUG(DEBUG_CONFIG, "name of extension: %s\n",param);
159                 } else
160                 if (!strcmp(option,"prefix"))
161                 {
162                         SCPY(ext->prefix, param);
163
164                         PDEBUG(DEBUG_CONFIG, "dial prefix on pickup: %s\n",param);
165                 } else
166                 if (!strcmp(option,"next"))
167                 {
168                         SCPY(ext->next, param);
169
170                         PDEBUG(DEBUG_CONFIG, "dial next on pickup: %s\n",param);
171                 } else
172                 if (!strcmp(option,"alarm"))
173                 {
174                         SCPY(ext->alarm, param);
175
176                         PDEBUG(DEBUG_CONFIG, "alarm message (if prefix): %s\n",param);
177                 } else
178                 if (!strcmp(option,"cfu"))
179                 {
180                         SCPY(ext->cfu, param);
181
182                         PDEBUG(DEBUG_CONFIG, "call forward unconditional: %s\n",param);
183                 } else
184                 if (!strcmp(option,"cfb"))
185                 {
186                         SCPY(ext->cfb, param);
187
188                         PDEBUG(DEBUG_CONFIG, "call forward when busy: %s\n",param);
189                 } else
190                 if (!strcmp(option,"cfnr"))
191                 {
192                         SCPY(ext->cfnr, param);
193
194                         PDEBUG(DEBUG_CONFIG, "call forward on no response: %s\n",param);
195                 } else
196                 if (!strcmp(option,"cfnr_delay"))
197                 {
198                         ext->cfnr_delay = atoi(param);
199                         if (ext->cfnr_delay < 0)
200                                 ext->cfnr_delay = 1;
201
202                         PDEBUG(DEBUG_CONFIG, "call forward no response delay: %d\n",ext->cfnr_delay);
203                 } else
204                 if (!strcmp(option,"cfp"))
205                 {
206                         SCPY(ext->cfp, param);
207
208                         PDEBUG(DEBUG_CONFIG, "call forward parallel: %s\n",param);
209                 } else
210                 if (!strcmp(option,"change_forward"))
211                 {
212                         i=0;
213                         while(ext_yesno[i])
214                         {
215                                 if (!strcasecmp(param,ext_yesno[i]))
216                                         break;
217                                 i++;
218                         }
219                         if (ext_yesno[i])
220                         {
221                                 ext->change_forward = i;
222                                 PDEBUG(DEBUG_CONFIG, "allow the change of forwarding: %s\n", ext_yesno[i]);
223                         } else
224                         {
225                                 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_forward: %s\n", param);
226                         }
227                 } else
228                 if (!strcmp(option,"interfaces"))
229                 {
230                         SCPY(ext->interfaces, param);
231
232                         PDEBUG(DEBUG_CONFIG, "interfaces to ring calls to extension: %s %s\n",param,param2);
233                 } else
234                 if (!strcmp(option,"callerid"))
235                 {
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))
240                         {
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");
245                         } else
246                         switch(param[0])
247                         {
248                                 case 'i':
249                                 case 'I':
250                                 ext->callerid_type = INFO_NTYPE_INTERNATIONAL;
251                                 SCPY(ext->callerid, param+1);
252                                 PDEBUG(DEBUG_CONFIG, "caller id: %s INTERNATIONAL\n",param+1);
253                                 break;
254                                 case 'n':
255                                 case 'N':
256                                 ext->callerid_type = INFO_NTYPE_NATIONAL;
257                                 SCPY(ext->callerid, param+1);
258                                 PDEBUG(DEBUG_CONFIG, "caller id: %s NATIONAL\n",param+1);
259                                 break;
260                                 case 's':
261                                 case 'S':
262                                 ext->callerid_type = INFO_NTYPE_SUBSCRIBER;
263                                 SCPY(ext->callerid, param+1);
264                                 PDEBUG(DEBUG_CONFIG, "caller id: %s SUBSCRIBER\n",param+1);
265                                 break;
266                                 default:
267                                 ext->callerid_type = INFO_NTYPE_UNKNOWN;
268                                 SCPY(ext->callerid, param);
269                                 PDEBUG(DEBUG_CONFIG, "caller id: %s UNKNOWN\n",param);
270                         }
271                         ext->callerid[sizeof(ext->callerid)-1] = 0;
272                 } else
273                 if (!strcmp(option,"id_next_call"))
274                 {
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')
279                         {
280                                 ext->id_next_call_present = -1;
281                                 PDEBUG(DEBUG_CONFIG, "id next call: no id for next call\n");
282                         } else
283                         if (!strncasecmp(param, "none", 3))
284                         {
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");
289                         } else
290                         switch(param[0])
291                         {
292                                 case 'i':
293                                 case 'I':
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);
297                                 break;
298                                 case 'n':
299                                 case 'N':
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);
303                                 break;
304                                 case 's':
305                                 case 'S':
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);
309                                 break;
310                                 default:
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);
314                         }
315
316
317
318                 } else
319                 if (!strcmp(option,"change_callerid"))
320                 {
321                         i=0;
322                         while(ext_yesno[i])
323                         {
324                                 if (!strcasecmp(param,ext_yesno[i]))
325                                         break;
326                                 i++;
327                         }
328                         if (ext_yesno[i])
329                         {
330                                 ext->change_callerid = i;
331                                 PDEBUG(DEBUG_CONFIG, "allow the change of caller id: %s\n", ext_yesno[i]);
332                         } else
333                         {
334                                 PDEBUG(DEBUG_CONFIG, "unknown parameter for change_callerid: %s\n", param);
335                         }
336                 } else
337                 if (!strcmp(option,"anon-ignore"))
338                 {
339                         i=0;
340                         while(ext_yesno[i])
341                         {
342                                 if (!strcasecmp(param,ext_yesno[i]))
343                                         break;
344                                 i++;
345                         }
346                         if (ext_yesno[i])
347                         {
348                                 ext->anon_ignore = i;
349                                 PDEBUG(DEBUG_CONFIG, "ignore restriction of CLIP & COLP %s\n", ext_yesno[i]);
350                         } else
351                         {
352                                 PDEBUG(DEBUG_CONFIG, "unknown parameter given anon-ignore: %s\n", param);
353                         }
354                 } else
355                 if (!strcmp(option,"clip"))
356                 {
357                         if (!strcasecmp(param, "hide"))
358                                 ext->clip = CLIP_HIDE;
359                         else
360                                 ext->clip = CLIP_ASIS;
361
362                         PDEBUG(DEBUG_CONFIG, "clip: %d\n",ext->clip);
363                 } else
364                 if (!strcmp(option,"colp"))
365                 {
366                         if (!strcasecmp(param, "hide"))
367                                 ext->colp = COLP_HIDE;
368                         else if (!strcasecmp(param, "force"))
369                                 ext->colp = COLP_FORCE;
370                         else
371                                 ext->colp = COLP_ASIS;
372
373                         PDEBUG(DEBUG_CONFIG, "colp: %d\n",ext->colp);
374                 } else
375                 if (!strcmp(option,"clip_prefix"))
376                 {
377                         SCPY(ext->clip_prefix, param);
378
379                         PDEBUG(DEBUG_CONFIG, "clip prefix: %s\n",param);
380                 } else
381                 if (!strcmp(option,"keypad"))
382                 {
383                         i=0;
384                         while(ext_yesno[i])
385                         {
386                                 if (!strcasecmp(param,ext_yesno[i]))
387                                         break;
388                                 i++;
389                         }
390                         if (ext_yesno[i])
391                         {
392                                 ext->keypad = i;
393                                 PDEBUG(DEBUG_CONFIG, "use keypad to do call control %s\n", ext_yesno[i]);
394                         } else
395                         {
396                                 PDEBUG(DEBUG_CONFIG, "unknown parameter given keypad: %s\n", param);
397                         }
398                 } else
399                 if (!strcmp(option,"rights"))
400                 {
401                         i=0;
402                         while(ext_rights[i])
403                         {
404                                 if (!strcasecmp(param,ext_rights[i]))
405                                         break;
406                                 i++;
407                         }
408                         if (ext_rights[i])
409                         {
410                                 ext->rights = i;
411                                 PDEBUG(DEBUG_CONFIG, "rights to dial: %s\n", ext_rights[i]);
412                         } else
413                         {
414                                 PDEBUG(DEBUG_CONFIG, "given rights unknown: %s\n", param);
415                         }
416                 } else
417                 if (!strcmp(option,"delete_ext"))
418                 {
419                         i=0;
420                         while(ext_yesno[i])
421                         {
422                                 if (!strcasecmp(param,ext_yesno[i]))
423                                         break;
424                                 i++;
425                         }
426                         if (ext_yesno[i])
427                         {
428                                 ext->delete_ext = i;
429                                 PDEBUG(DEBUG_CONFIG, "enables the delete key function for external calls: %s\n", ext_yesno[i]);
430                         } else
431                         {
432                                 PDEBUG(DEBUG_CONFIG, "unknown parameter given delete: %s\n", param);
433                         }
434                 } else
435                 if (!strcmp(option,"noknocking"))
436                 {
437                         i=0;
438                         while(ext_yesno[i])
439                         {
440                                 if (!strcasecmp(param,ext_yesno[i]))
441                                         break;
442                                 i++;
443                         }
444                         if (ext_yesno[i])
445                         {
446                                 ext->noknocking = i;
447                                 PDEBUG(DEBUG_CONFIG, "noknocking %s\n", ext_yesno[i]);
448                         } else
449                         {
450                                 PDEBUG(DEBUG_CONFIG, "given noknocking param unknown: %s\n", param);
451                         }
452                 } else
453                 if (!strcmp(option,"rx_gain")
454                  || !strcmp(option,"rxvol"))
455                 {
456                         ext->rx_gain = atoi(param);
457                         if (ext->rx_gain<-8 || ext->rx_gain>8)
458                                 ext->rx_gain = 0;
459
460                         PDEBUG(DEBUG_CONFIG, "receive volume: %d\n",ext->rx_gain);
461                 } else
462                 if (!strcmp(option,"tx_gain")
463                  || !strcmp(option,"txvol"))
464                 {
465                         ext->tx_gain = atoi(param);
466                         if (ext->tx_gain<-8 || ext->tx_gain>8)
467                                 ext->tx_gain = 0;
468
469                         PDEBUG(DEBUG_CONFIG, "transmit volume: %d\n",ext->tx_gain);
470                 } else
471                 if (!strcmp(option,"own_setup"))
472                 {
473                         i=0;
474                         while(ext_yesno[i])
475                         {
476                                 if (!strcasecmp(param,ext_yesno[i]))
477                                         break;
478                                 i++;
479                         }
480                         if (ext_yesno[i])
481                         {
482                                 ext->own_setup = i;
483                                 PDEBUG(DEBUG_CONFIG, "own_setup %s\n", ext_yesno[i]);
484                         } else
485                         {
486                                 PDEBUG(DEBUG_CONFIG, "given own_setup param unknown: %s\n", param);
487                         }
488                 } else
489                 if (!strcmp(option,"own_proceeding"))
490                 {
491                         i=0;
492                         while(ext_yesno[i])
493                         {
494                                 if (!strcasecmp(param,ext_yesno[i]))
495                                         break;
496                                 i++;
497                         }
498                         if (ext_yesno[i])
499                         {
500                                 ext->own_proceeding = i;
501                                 PDEBUG(DEBUG_CONFIG, "own_proceeding %s\n", ext_yesno[i]);
502                         } else
503                         {
504                                 PDEBUG(DEBUG_CONFIG, "given own_proceeding param unknown: %s\n", param);
505                         }
506                 } else
507                 if (!strcmp(option,"own_alerting"))
508                 {
509                         i=0;
510                         while(ext_yesno[i])
511                         {
512                                 if (!strcasecmp(param,ext_yesno[i]))
513                                         break;
514                                 i++;
515                         }
516                         if (ext_yesno[i])
517                         {
518                                 ext->own_alerting = i;
519                                 PDEBUG(DEBUG_CONFIG, "own_alerting %s\n", ext_yesno[i]);
520                         } else
521                         {
522                                 PDEBUG(DEBUG_CONFIG, "given own_alerting param unknown: %s\n", param);
523                         }
524                 } else
525                 if (!strcmp(option,"own_cause"))
526                 {
527                         i=0;
528                         while(ext_yesno[i])
529                         {
530                                 if (!strcasecmp(param,ext_yesno[i]))
531                                         break;
532                                 i++;
533                         }
534                         if (ext_yesno[i])
535                         {
536                                 ext->own_cause = i;
537                                 PDEBUG(DEBUG_CONFIG, "own_cause %s\n", ext_yesno[i]);
538                         } else
539                         {
540                                 PDEBUG(DEBUG_CONFIG, "given own_cause param unknown: %s\n", param);
541                         }
542                 } else
543                 if (!strcmp(option,"facility"))
544                 {
545                         i=0;
546                         while(ext_yesno[i])
547                         {
548                                 if (!strcasecmp(param,ext_yesno[i]))
549                                         break;
550                                 i++;
551                         }
552                         if (ext_yesno[i])
553                         {
554                                 ext->facility = i;
555                                 PDEBUG(DEBUG_CONFIG, "facility %s\n", ext_yesno[i]);
556                         } else
557                         {
558                                 PDEBUG(DEBUG_CONFIG, "given facility param unknown: %s\n", param);
559                         }
560                 } else
561                 if (!strcmp(option,"display_cause"))
562                 {
563                         if (!strcasecmp(param, "german"))
564                                 ext->display_cause = DISPLAY_CAUSE_GERMAN;
565                         else if (!strcasecmp(param, "english"))
566                                 ext->display_cause = DISPLAY_CAUSE_ENGLISH;
567                         else if (!strcasecmp(param, "german-location"))
568                                 ext->display_cause = DISPLAY_LOCATION_GERMAN;
569                         else if (!strcasecmp(param, "english-location"))
570                                 ext->display_cause = DISPLAY_LOCATION_ENGLISH;
571                         else if (!strcasecmp(param, "number"))
572                                 ext->display_cause = DISPLAY_CAUSE_NUMBER;
573                         else
574                                 ext->display_cause = DISPLAY_CAUSE_NONE;
575
576                         PDEBUG(DEBUG_CONFIG, "display cause: %d\n",ext->display_cause);
577                 } else
578 #if 0
579                 if (!strcmp(option,"display_ext"))
580                 {
581                         if (!strcasecmp(param, "number"))
582                                 ext->display_ext = DISPLAY_CID_NUMBER;
583                         else if (!strcasecmp(param, "abbrev"))
584                                 ext->display_ext = DISPLAY_CID_ABBREVIATION;
585                         else if (!strcasecmp(param, "name"))
586                                 ext->display_ext = DISPLAY_CID_NAME;
587                         else if (!strcasecmp(param, "number-name"))
588                                 ext->display_ext = DISPLAY_CID_NUMBER_NAME;
589                         else if (!strcasecmp(param, "name-number"))
590                                 ext->display_ext = DISPLAY_CID_NAME_NUMBER;
591                         else if (!strcasecmp(param, "abbrev-number"))
592                                 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER;
593                         else if (!strcasecmp(param, "abbrev-name"))
594                                 ext->display_ext = DISPLAY_CID_ABBREV_NAME;
595                         else if (!strcasecmp(param, "abbrev-name-number"))
596                                 ext->display_ext = DISPLAY_CID_ABBREV_NAME_NUMBER;
597                         else if (!strcasecmp(param, "abbrev-number-name"))
598                                 ext->display_ext = DISPLAY_CID_ABBREV_NUMBER_NAME;
599                         else
600                                 ext->display_ext = DISPLAY_CID_ASIS;
601
602                         PDEBUG(DEBUG_CONFIG, "display ext: %d\n",ext->display_ext);
603                 } else
604 #endif
605                 if (!strcmp(option,"display_ext"))
606                 {
607                         i=0;
608                         while(ext_yesno[i])
609                         {
610                                 if (!strcasecmp(param,ext_yesno[i]))
611                                         break;
612                                 i++;
613                         }
614                         if (ext_yesno[i])
615                         {
616                                 ext->display_ext = i;
617                                 PDEBUG(DEBUG_CONFIG, "display ext %s\n", ext_yesno[i]);
618                         } else
619                         {
620                                 PDEBUG(DEBUG_CONFIG, "given display_ext param unknown: %s\n", param);
621                         }
622                 } else
623                 if (!strcmp(option,"display_int"))
624                 {
625                         i=0;
626                         while(ext_yesno[i])
627                         {
628                                 if (!strcasecmp(param,ext_yesno[i]))
629                                         break;
630                                 i++;
631                         }
632                         if (ext_yesno[i])
633                         {
634                                 ext->display_int = i;
635                                 PDEBUG(DEBUG_CONFIG, "display int %s\n", ext_yesno[i]);
636                         } else
637                         {
638                                 PDEBUG(DEBUG_CONFIG, "given display_int param unknown: %s\n", param);
639                         }
640                 } else
641                 if (!strcmp(option,"display_fake"))
642                 {
643                         i=0;
644                         while(ext_yesno[i])
645                         {
646                                 if (!strcasecmp(param,ext_yesno[i]))
647                                         break;
648                                 i++;
649                         }
650                         if (ext_yesno[i])
651                         {
652                                 ext->display_fake = i;
653                                 PDEBUG(DEBUG_CONFIG, "display fake caller ids %s\n", ext_yesno[i]);
654                         } else
655                         {
656                                 PDEBUG(DEBUG_CONFIG, "given display_fake param unknown: %s\n", param);
657                         }
658                 } else
659                 if (!strcmp(option,"display_anon"))
660                 {
661                         i=0;
662                         while(ext_yesno[i])
663                         {
664                                 if (!strcasecmp(param,ext_yesno[i]))
665                                         break;
666                                 i++;
667                         }
668                         if (ext_yesno[i])
669                         {
670                                 ext->display_anon = i;
671                                 PDEBUG(DEBUG_CONFIG, "display anonymouse ids %s\n", ext_yesno[i]);
672                         } else
673                         {
674                                 PDEBUG(DEBUG_CONFIG, "given display_anon param unknown: %s\n", param);
675                         }
676                 } else
677                 if (!strcmp(option,"display_menu"))
678                 {
679                         i=0;
680                         while(ext_yesno[i])
681                         {
682                                 if (!strcasecmp(param,ext_yesno[i]))
683                                         break;
684                                 i++;
685                         }
686                         if (ext_yesno[i])
687                         {
688                                 ext->display_menu = i;
689                                 PDEBUG(DEBUG_CONFIG, "display menu %s\n", ext_yesno[i]);
690                         } else
691                         {
692                                 PDEBUG(DEBUG_CONFIG, "given display_menu param unknown: %s\n", param);
693                         }
694                 } else
695                 if (!strcmp(option,"display_dialing"))
696                 {
697                         i=0;
698                         while(ext_yesno[i])
699                         {
700                                 if (!strcasecmp(param,ext_yesno[i]))
701                                         break;
702                                 i++;
703                         }
704                         if (ext_yesno[i])
705                         {
706                                 ext->display_dialing = i;
707                                 PDEBUG(DEBUG_CONFIG, "display dialing %s\n", ext_yesno[i]);
708                         } else
709                         {
710                                 PDEBUG(DEBUG_CONFIG, "given display_dialing param unknown: %s\n", param);
711                         }
712                 } else
713                 if (!strcmp(option,"display_name"))
714                 {
715                         i=0;
716                         while(ext_yesno[i])
717                         {
718                                 if (!strcasecmp(param,ext_yesno[i]))
719                                         break;
720                                 i++;
721                         }
722                         if (ext_yesno[i])
723                         {
724                                 ext->display_name = i;
725                                 PDEBUG(DEBUG_CONFIG, "display name %s\n", ext_yesno[i]);
726                         } else
727                         {
728                                 PDEBUG(DEBUG_CONFIG, "given display_name param unknown: %s\n", param);
729                         }
730                 } else
731                 if (!strcmp(option,"tones_dir"))
732                 {
733                         if (param[strlen(param)-1] == '/')
734                                 param[strlen(param)-1]=0;
735                         SCPY(ext->tones_dir, param);
736
737                         PDEBUG(DEBUG_CONFIG, "directory of tones: %s\n",param);
738                 } else
739                 if (!strcmp(option,"record"))
740                 {
741                         if (!strcasecmp(param, "mono"))
742                                 ext->record = CODEC_MONO;
743                         else if (!strcasecmp(param, "stereo"))
744                                 ext->record = CODEC_STEREO;
745                         else if (!strcasecmp(param, "8bit"))
746                                 ext->record = CODEC_8BIT;
747                         else if (!strcasecmp(param, "law"))
748                                 ext->record = CODEC_LAW;
749                         else
750                                 ext->record = CODEC_OFF;
751                         PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
752                 } else
753                 if (!strcmp(option,"password"))
754                 {
755                         SCPY(ext->password, param);
756
757                         PDEBUG(DEBUG_CONFIG, "password: %s\n",param);
758                 } else
759                 if (!strcmp(option,"vbox_mode"))
760                 {
761                         if (!strcasecmp(param, "parallel"))
762                                 ext->vbox_mode = VBOX_MODE_PARALLEL;
763                         else if (!strcasecmp(param, "announcement"))
764                                 ext->vbox_mode = VBOX_MODE_ANNOUNCEMENT;
765                         else
766                                 ext->vbox_mode = VBOX_MODE_NORMAL;
767                         PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
768                 } else
769                 if (!strcmp(option,"vbox_codec"))
770                 {
771                         if (!strcasecmp(param, "stereo"))
772                                 ext->vbox_codec = CODEC_STEREO;
773                         else if (!strcasecmp(param, "8bit"))
774                                 ext->vbox_codec = CODEC_8BIT;
775                         else if (!strcasecmp(param, "law"))
776                                 ext->vbox_codec = CODEC_LAW;
777                         else
778                                 ext->vbox_codec = CODEC_MONO;
779                         PDEBUG(DEBUG_CONFIG, "given record param: %s\n", param);
780                 } else
781                 if (!strcmp(option,"vbox_time"))
782                 {
783                         ext->vbox_time = atoi(param);
784                         if (ext->vbox_time < 0)
785                                 ext->vbox_time = 0;
786
787                         PDEBUG(DEBUG_CONFIG, "vbox time to record: %d\n",ext->vbox_time);
788                 } else
789                 if (!strcmp(option,"vbox_display"))
790                 {
791                         if (!strcasecmp(param, "detailed")
792                          || !strcasecmp(param, "detailled"))
793                                 ext->vbox_display = VBOX_DISPLAY_DETAILED;
794                         else if (!strcasecmp(param, "off"))
795                                 ext->vbox_display = VBOX_DISPLAY_OFF;
796                         else
797                                 ext->vbox_display = VBOX_DISPLAY_BRIEF;
798                         PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
799                 } else
800                 if (!strcmp(option,"vbox_language"))
801                 {
802                         if (!strcasecmp(param, "german"))
803                                 ext->vbox_language = VBOX_LANGUAGE_GERMAN;
804                         else
805                                 ext->vbox_language = VBOX_LANGUAGE_ENGLISH;
806                         PDEBUG(DEBUG_CONFIG, "given vbox mode: %s\n", param);
807                 } else
808                 if (!strcmp(option,"vbox_email"))
809                 {
810                         SCPY(ext->vbox_email, param);
811                         PDEBUG(DEBUG_CONFIG, "given vbox email: %s\n", param);
812                 } else
813                 if (!strcmp(option,"vbox_email_file"))
814                 {
815                         i=0;
816                         while(ext_yesno[i])
817                         {
818                                 if (!strcasecmp(param,ext_yesno[i]))
819                                         break;
820                                 i++;
821                         }
822                         if (ext_yesno[i])
823                         {
824                                 ext->vbox_email_file = i;
825                                 PDEBUG(DEBUG_CONFIG, "attach audio file %s\n", ext_yesno[i]);
826                         } else
827                         {
828                                 PDEBUG(DEBUG_CONFIG, "given vbox_email_file param unknown: %s\n", param);
829                         }
830                 } else
831                 if (!strcmp(option,"vbox_free"))
832                 {
833                         i=0;
834                         while(ext_yesno[i])
835                         {
836                                 if (!strcasecmp(param,ext_yesno[i]))
837                                         break;
838                                 i++;
839                         }
840                         if (ext_yesno[i])
841                         {
842                                 ext->vbox_free = i;
843                                 PDEBUG(DEBUG_CONFIG, "vbox_free %s\n", ext_yesno[i]);
844                         } else
845                         {
846                                 PDEBUG(DEBUG_CONFIG, "given vbox_free param unknown: %s\n", param);
847                         }
848                 } else
849                 if (!strcmp(option,"last_in"))
850                 {
851                         if (param[0] && last_in_count<MAX_REMEMBER)
852                         {
853                                 SCPY(ext->last_in[last_in_count], param);
854                                 last_in_count++;
855                         }
856                         PDEBUG(DEBUG_CONFIG, "last_in dialed number: %s\n",param);
857                 } else
858                 if (!strcmp(option,"last_out"))
859                 {
860                         if (param[0] && last_out_count<MAX_REMEMBER)
861                         {
862                                 SCPY(ext->last_out[last_out_count], param);
863                                 last_out_count++;
864                         }
865                         PDEBUG(DEBUG_CONFIG, "last_out dialed number: %s\n",param);
866                 } else
867                 if (!strcmp(option,"datacall"))
868                 {
869                         i=0;
870                         while(ext_yesno[i])
871                         {
872                                 if (!strcasecmp(param,ext_yesno[i]))
873                                         break;
874                                 i++;
875                         }
876                         if (ext_yesno[i])
877                         {
878                                 ext->datacall = i;
879                                 PDEBUG(DEBUG_CONFIG, "datacall %s\n", ext_yesno[i]);
880                         } else
881                         {
882                                 PDEBUG(DEBUG_CONFIG, "given datacall param unknown: %s\n", param);
883                         }
884                 } else
885                 if (!strcmp(option,"seconds"))
886                 {
887                         i=0;
888                         while(ext_yesno[i])
889                         {
890                                 if (!strcasecmp(param,ext_yesno[i]))
891                                         break;
892                                 i++;
893                         }
894                         if (ext_yesno[i])
895                         {
896                                 ext->no_seconds = 1-i;
897                                 PDEBUG(DEBUG_CONFIG, "seconds %s\n", ext_yesno[i]);
898                         } else
899                         {
900                                 PDEBUG(DEBUG_CONFIG, "unknown param for seconds: %s\n", param);
901                         }
902                 } else
903                 {
904                         PERROR_RUNTIME("Error in %s (line %d): wrong option keyword %s.\n",filename,line,option);
905                 }
906         }
907
908         if (fp) fclose(fp);
909         return(1);
910 }
911
912
913 /* write extension
914  *
915  * writes extension for given extension number from structure
916  */
917 int write_extension(struct extension *ext, char *number)
918 {
919         FILE *fp=NULL;
920         char filename[256];
921         int i;
922
923         if (number[0] == '\0')
924                 return(0);
925
926         SPRINT(filename, "%s/%s/%s/settings", INSTALL_DATA, options.extensions_dir, number);
927
928         if (!(fp = fopen(filename, "w")))
929         {
930                 PERROR("Cannot open settings: \"%s\"\n", filename);
931                 return(0);
932         }
933
934         fprintf(fp,"# Settings of extension %s\n\n", number);
935
936         fprintf(fp,"# Name of extension:\n");
937         fprintf(fp,"name            %s\n\n",ext->name);
938
939         fprintf(fp,"# Predialed prefix after pick-up of the phone\n");
940         fprintf(fp,"prefix          %s\n\n",ext->prefix);
941
942         fprintf(fp,"# Next prefix to dial pick-up of the phone\n");
943         fprintf(fp,"# This will be cleared on hangup.\n");
944         fprintf(fp,"next            %s\n\n",ext->next);
945
946 //      fprintf(fp,"# Set up alarm message after prefix is dialed and connection is established\n");
947 //      fprintf(fp,"alarm           %s\n\n",ext->alarm);
948
949         fprintf(fp,"# Interface(s) to ring on calls to extension (as named in interface.conf)\n");
950         fprintf(fp,"# Seperate multiple interfaces by using komma without spaces\n");
951         fprintf(fp,"# Example: Int would ring on the interface with the name \"Int\"");
952         fprintf(fp,"#          Int1,Int2 would ring incoming calls on both interfaces Int1 and Int2.\n");
953         fprintf(fp,"interfaces      %s\n\n",ext->interfaces);
954
955         fprintf(fp,"# Call Forward Unconditional (CFU)\n");
956         fprintf(fp,"# No port will be called, CFB, CFNR and CFP is ignored.\n");
957         fprintf(fp,"# Use keyword \"vbox\" to forward call directly to answering machine.\n");
958         fprintf(fp,"cfu             %s\n\n",ext->cfu);
959
960         fprintf(fp,"# Call Forward when Busy (CFB)\n");
961         fprintf(fp,"# If the extension is in use at least once, this forward is done.\n");
962         fprintf(fp,"# In case of busy line, CFNR and CFP is ignored.\n");
963         fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine when busy.\n");
964         fprintf(fp,"cfb             %s\n\n",ext->cfb);
965
966         fprintf(fp,"# Call Forward on No Response (CFNR)\n");
967         fprintf(fp,"# If noone answers, the call is forwarded, ports and CFP will be released.\n");
968         fprintf(fp,"# The default delay is 20 seconds.\n");
969         fprintf(fp,"# Use keyword \"vbox\" to forward call to answering machine on no response.\n");
970         fprintf(fp,"cfnr            %s\n",ext->cfnr);
971         fprintf(fp,"cfnr_delay      %d\n\n",ext->cfnr_delay);
972
973         fprintf(fp,"# Call Forward Parallel (CFP)\n");
974         fprintf(fp,"# Call will ring on the forwarded number, simulaniousely with the ports.\n");
975         fprintf(fp,"cfp             %s\n\n",ext->cfp);
976
977         fprintf(fp,"# Allow user to change call forwarding.\n");
978         fprintf(fp,"change_forward  %s\n\n", ext_yesno[ext->change_forward]);
979
980         fprintf(fp,"# Caller id\n# This must be one of the following:\n");
981         fprintf(fp,"# <number> (as dialed from your local area)\n");
982         fprintf(fp,"# <number> anonymous (will only be shown to emergency phones)\n");
983         fprintf(fp,"# none (no number available at all)\n");
984         fprintf(fp,"# by default the number is of type UNKNOWN (for MULTIPOINT lines)\n");
985         fprintf(fp,"# if your caller id is not screened on outgoing calls use one of the following:\n");
986         fprintf(fp,"# use prefix 'i' for TYPE INTERNATIONAL (i<county code><areacode+number>)\n");
987         fprintf(fp,"# use prefix 'n' for TYPE NATIONAL (n<areacode+number>)\n");
988         fprintf(fp,"# use prefix 's' for TYPE SUBSCRIBER (s<local number>)\n");
989         if (ext->callerid_present == INFO_PRESENT_NOTAVAIL)
990                 fprintf(fp,"callerid        none\n\n");
991         else
992         {
993                 switch(ext->callerid_type)
994                 {
995                         case INFO_NTYPE_INTERNATIONAL:
996                         fprintf(fp,"callerid        i%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
997                         break;
998                         case INFO_NTYPE_NATIONAL:
999                         fprintf(fp,"callerid        n%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1000                         break;
1001                         case INFO_NTYPE_SUBSCRIBER:
1002                         fprintf(fp,"callerid        s%s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1003                         break;
1004                         default:
1005                         fprintf(fp,"callerid        %s%s\n\n",ext->callerid, (ext->callerid_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1006                 }
1007         }
1008
1009         fprintf(fp,"# Caller id for next call (see caller id)\n");
1010         if (ext->id_next_call_present < 0)
1011                 fprintf(fp,"id_next_call    \n\n");
1012         else if (ext->id_next_call_present == INFO_PRESENT_NOTAVAIL)
1013                 fprintf(fp,"id_next_call    none\n\n");
1014         else
1015         {
1016                 switch(ext->id_next_call_type)
1017                 {
1018                         case INFO_NTYPE_INTERNATIONAL:
1019                         fprintf(fp,"id_next_call    i%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1020                         break;
1021                         case INFO_NTYPE_NATIONAL:
1022                         fprintf(fp,"id_next_call    n%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1023                         break;
1024                         case INFO_NTYPE_SUBSCRIBER:
1025                         fprintf(fp,"id_next_call    s%s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1026                         break;
1027                         default:
1028                         fprintf(fp,"id_next_call    %s%s\n\n",ext->id_next_call, (ext->id_next_call_present==INFO_PRESENT_RESTRICTED)?" anonymous":"");
1029                 }
1030         }
1031
1032         fprintf(fp,"# Allow user to change caller ID.\n");
1033         fprintf(fp,"change_callerid %s\n\n", ext_yesno[ext->change_callerid]);
1034
1035         fprintf(fp,"# Caller Line Identification Presentation (CLIP)\n");
1036         fprintf(fp,"# clip (asis|hide)\n");
1037         fprintf(fp,"# asis: On forwarded calls the CLIP is used as presented by the calling party.\n");
1038         fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1039         switch(ext->clip)
1040         {
1041                 case CLIP_HIDE:
1042                 fprintf(fp,"clip            hide\n\n");
1043                 break;
1044                 default:
1045                 fprintf(fp,"clip            asis\n\n");
1046         }
1047
1048         fprintf(fp,"# Connected Line Identification Presentation (COLP)\n");
1049         fprintf(fp,"# colp (asis|hide|force)\n");
1050         fprintf(fp,"# asis: Provides colp as defined by the extension's caller id.\n");
1051         fprintf(fp,"#       On forwarded calls the COLP is used as presented by the called party.\n");
1052         fprintf(fp,"# hide: Always use extension's caller id, even on forwared calls.\n");
1053         fprintf(fp,"# force: If COLP is not presented by forwarded calls the dialed number is used.\n");
1054         switch(ext->colp)
1055         {
1056                 case COLP_HIDE:
1057                 fprintf(fp,"colp            hide\n\n");
1058                 break;
1059                 case COLP_FORCE:
1060                 fprintf(fp,"colp            force\n\n");
1061                 break;
1062                 default:
1063                 fprintf(fp,"colp            asis\n\n");
1064         }
1065
1066         fprintf(fp,"# CLIP Prefix\n");
1067         fprintf(fp,"# Adds a prefix to incoming caller IDs, so telephones will be able to respond\n");
1068         fprintf(fp,"# to unanswered calls from their list. The prefix must be the digit(s) to get\n");
1069         fprintf(fp,"# an external line. The caller ID will then be extendet so that they can be\n");
1070         fprintf(fp,"# dialed from internal telephones. Many telephones have this feature, but some\n");
1071         fprintf(fp,"# don't.\n");
1072         fprintf(fp,"clip_prefix     %s\n\n",ext->clip_prefix);
1073
1074         fprintf(fp,"# Keypad control\n");
1075         fprintf(fp,"# If supported by telephone, pressing a key on the keypad will not result in\n");
1076         fprintf(fp,"# DTMF tone, but the digit is transmitted via D-channel diaing info.\n");
1077         fprintf(fp,"keypad          %s\n\n",(ext->keypad)?"yes":"no");
1078
1079         fprintf(fp,"# Ignore restriction of COLP and CLIP\n");
1080         fprintf(fp,"# In this case even restricted numbers are presented to this extension.\n");
1081         fprintf(fp,"# This also works for incoming external anonymous calls IF:\n");
1082         fprintf(fp,"# You have the CLIRIGN feature like POLICE or equivalent.\n");
1083         fprintf(fp,"anon-ignore     %s\n\n",(ext->anon_ignore)?"yes":"no");
1084
1085         fprintf(fp,"# Dialing rights (none|internal|local|national|international)\n");
1086         fprintf(fp,"rights          %s\n\n",ext_rights[ext->rights]);
1087
1088         fprintf(fp,"# Delete function for external calls. '*' will delete the last digit, '#' will\n");
1089         fprintf(fp,"# delete the complete number. Also enable 'display_dialing' to see on the\n");
1090         fprintf(fp,"# display what actually happens.\n");
1091         fprintf(fp,"delete_ext      %s\n\n",ext_yesno[ext->delete_ext]);
1092
1093         fprintf(fp,"# If noknocking is enabled, the caller will get a busy message when the\n");
1094         fprintf(fp,"# extension is doing at least one call.\n");
1095         fprintf(fp,"noknocking      %s\n\n",ext_yesno[ext->noknocking]);
1096
1097         fprintf(fp,"# Transmit volume (-8 .. 8)\n");
1098         fprintf(fp,"# 0 = normal\n");
1099         fprintf(fp,"# 1 = double, 2 = quadrupel, 8 = 256 times (amplitude)\n");
1100         fprintf(fp,"# -1 = half, -2 = quarter, 8 = 1/256th (amplitude)\n");
1101         fprintf(fp,"# Audio data is limited to the maximum value when exceeds limit.\n");
1102         fprintf(fp,"tx_gain          %d\n\n",ext->tx_gain);
1103
1104         fprintf(fp,"# Receive volume (-8 .. 8)\n");
1105         fprintf(fp,"# (see tx_gain)\n");
1106         fprintf(fp,"rx_gain          %d\n\n",ext->rx_gain);
1107
1108
1109         fprintf(fp,"# Force to use tones and announcements generated by the pbx.\n");
1110         fprintf(fp,"# For internal calls always own tones are used. You may specify own tones for\n");
1111         fprintf(fp,"# different call states:\n");
1112         fprintf(fp,"# own_setup (dialtone and during dialing)\n");
1113         fprintf(fp,"# own_proceeding (call in poceeding state)\n");
1114         fprintf(fp,"# own_alerting (call is ringing)\n");
1115         fprintf(fp,"# own_cause (when the call gets disconnected or failed to be completed)\n");
1116         fprintf(fp,"own_setup       %s\n",ext_yesno[ext->own_setup]);
1117         fprintf(fp,"own_proceeding  %s\n",ext_yesno[ext->own_proceeding]);
1118         fprintf(fp,"own_alerting    %s\n",ext_yesno[ext->own_alerting]);
1119         fprintf(fp,"own_cause       %s\n\n",ext_yesno[ext->own_cause]);
1120
1121         fprintf(fp,"# Allow facility information to be transfered to the telephone.\n");
1122         fprintf(fp,"# This is equired to receive advice of charge.\n");
1123         fprintf(fp,"facility        %s\n\n",ext_yesno[ext->facility]);
1124
1125         fprintf(fp,"# Display clear causes using display messages (Q.850)\n# This must be one of the following:\n");
1126         fprintf(fp,"# none (no displaying of clear causes)\n");
1127         fprintf(fp,"# english (display cause text in english)\n");
1128         fprintf(fp,"# german (display cause text in german)\n");
1129         fprintf(fp,"# number (display cause number only)\n");
1130         fprintf(fp,"# english-location (display cause text in english and location)\n");
1131         fprintf(fp,"# german-location (display cause text in german and location)\n");
1132         switch(ext->display_cause)
1133         {
1134                 case DISPLAY_CAUSE_ENGLISH:
1135                 fprintf(fp,"display_cause   english\n\n");
1136                 break;
1137                 case DISPLAY_CAUSE_GERMAN:
1138                 fprintf(fp,"display_cause   german\n\n");
1139                 break;
1140                 case DISPLAY_LOCATION_ENGLISH:
1141                 fprintf(fp,"display_cause   english-location\n\n");
1142                 break;
1143                 case DISPLAY_LOCATION_GERMAN:
1144                 fprintf(fp,"display_cause   german-location\n\n");
1145                 break;
1146                 case DISPLAY_CAUSE_NUMBER:
1147                 fprintf(fp,"display_cause   number\n\n");
1148                 break;
1149                 default:
1150                 fprintf(fp,"display_cause   none\n\n");
1151         }
1152
1153         fprintf(fp,"# Display external caller ids using display override (yes or no)\n");
1154         fprintf(fp,"# example: \"15551212\"\n");
1155         fprintf(fp,"display_ext     %s\n\n",(ext->display_ext)?"yes":"no");
1156
1157         fprintf(fp,"# Display internal caller ids using display override (yes or no)\n");
1158         fprintf(fp,"# example: \"200 (int)\"\n");
1159         fprintf(fp,"display_int     %s\n\n",(ext->display_int)?"yes":"no");
1160
1161         fprintf(fp,"# Display if calls are anonymous using display override (yes or no)\n");
1162         fprintf(fp,"# This makes only sense if the anon-ignore feature is enabled.\n");
1163         fprintf(fp,"# example: \"15551212 anon\"\n");
1164         fprintf(fp,"display_anon    %s\n\n",(ext->display_anon)?"yes":"no");
1165
1166         fprintf(fp,"# Display fake caller ids using display override (yes or no)\n");
1167         fprintf(fp,"# If the caller uses \"clip no screening\", you will see if the number is\n");
1168         fprintf(fp,"# real or fake\n");
1169         fprintf(fp,"# example: \"15551212 fake\"\n");
1170         fprintf(fp,"display_fake    %s\n\n",(ext->display_fake)?"yes":"no");
1171
1172         fprintf(fp,"# Display caller's name if available. (yes or no)\n");
1173         fprintf(fp,"# example: \"15551212 Axel\"\n");
1174         fprintf(fp,"display_name    %s\n\n",(ext->display_name)?"yes":"no");
1175
1176         fprintf(fp,"# Display menu when '*' and '#' is pressed. The menu shows all prefixes for\n");
1177         fprintf(fp,"# internal dialing by pressing '*' for previous prefix and '#' for next prefix.\n");
1178         fprintf(fp,"# Also the dialed prefix is show on display. (yes or no)\n");
1179         fprintf(fp,"display_menu    %s\n\n",(ext->display_menu)?"yes":"no");
1180
1181         fprintf(fp,"# Display digits as they are interpreted by pbx. (yes or no)\n");
1182         fprintf(fp,"display_dialing %s\n\n",(ext->display_dialing)?"yes":"no");
1183
1184         fprintf(fp,"# Tones directory for announcements and patterns\n");
1185         fprintf(fp,"# Enter nothing for default tones as selected by options.conf.\n");
1186         fprintf(fp,"tones_dir       %s\n\n",ext->tones_dir);
1187
1188         fprintf(fp,"# Record calls to extension's directory. The file is written as wave.\n");
1189         fprintf(fp,"# This must be one of the following:\n");
1190         fprintf(fp,"# off (no recording)\n");
1191         fprintf(fp,"# mono (records wave 16 bit mono, 128kbits/s)\n");
1192         fprintf(fp,"# stereo (records wave 32 bit stereo, 256kbits/s)\n");
1193         fprintf(fp,"# 8bit (records wave 8 bit mono, 64kbits/s)\n");
1194         fprintf(fp,"# law (records xLaw encoded, as specified in options.conf, 64kbps/s)\n");
1195         switch(ext->record)
1196         {
1197                 case CODEC_MONO:
1198                 fprintf(fp,"record          mono\n\n");
1199                 break;
1200                 case CODEC_STEREO:
1201                 fprintf(fp,"record          stereo\n\n");
1202                 break;
1203                 case CODEC_8BIT:
1204                 fprintf(fp,"record          8bit\n\n");
1205                 break;
1206                 case CODEC_LAW:
1207                 fprintf(fp,"record          law\n\n");
1208                 break;
1209                 default:
1210                 fprintf(fp,"record          off\n\n");
1211         }
1212
1213         fprintf(fp,"# Password for callback and login\n");
1214         fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1215         fprintf(fp,"password        %s\n\n",ext->password);
1216
1217         fprintf(fp,"# The Answering Machine. Enter the mode of answering machine.\n");
1218         fprintf(fp,"# This must be one of the following:\n");
1219         fprintf(fp,"# normal (plays announcement and records after that)\n");
1220         fprintf(fp,"# parallel (plays announcement and records also DURING announcement.)\n");
1221         fprintf(fp,"# announcement (just plays announcement and hangs up)\n");
1222         switch(ext->vbox_mode)
1223         {
1224                 case VBOX_MODE_PARALLEL:
1225                 fprintf(fp,"vbox_mode       parallel\n\n");
1226                 break;
1227                 case VBOX_MODE_ANNOUNCEMENT:
1228                 fprintf(fp,"vbox_mode       announcement\n\n");
1229                 break;
1230                 default:
1231                 fprintf(fp,"vbox_mode       normal\n\n");
1232         }
1233
1234         fprintf(fp,"# The Answering Machine. Enter the type of codec for recording.\n");
1235         fprintf(fp,"# This must be one of the following:\n");
1236         fprintf(fp,"# law (alaw/ulas codec, as specified in options.conf)\n");
1237         fprintf(fp,"# mono (16 bit mono wave file)\n");
1238         fprintf(fp,"# stereo (16 bit stereo wave file)\n");
1239         fprintf(fp,"# 8bit (8 bit mono wave file)\n");
1240         switch(ext->vbox_codec)
1241         {
1242                 case CODEC_LAW:
1243                 fprintf(fp,"vbox_codec      law\n\n");
1244                 break;
1245                 case CODEC_STEREO:
1246                 fprintf(fp,"vbox_codec      stereo\n\n");
1247                 break;
1248                 case CODEC_8BIT:
1249                 fprintf(fp,"vbox_codec      8bit\n\n");
1250                 break;
1251                 default:
1252                 fprintf(fp,"vbox_codec      mono\n\n");
1253         }
1254
1255         fprintf(fp,"# The Answering Machine. Enter maximum time to record after announcement.\n");
1256         fprintf(fp,"# Leave empty, enter \"infinite\" or give time in seconds.\n");
1257         fprintf(fp,"# Enter nothing if callback and login should not be possible.\n");
1258         if (ext->vbox_time)
1259                 fprintf(fp,"vbox_time       %d\n\n",ext->vbox_time);
1260         else
1261                 fprintf(fp,"vbox_time       infinite\n\n");
1262
1263         fprintf(fp,"# The Answering Machine. Enter mode for display current state.\n");
1264         fprintf(fp,"# This must be one of the following:\n");
1265         fprintf(fp,"# brief (displays brief information, for small displays)\n");
1266         fprintf(fp,"# detailed (displays detailed information, for larger displays)\n");
1267         fprintf(fp,"# off (don't display anything)\n");
1268         switch(ext->vbox_display)
1269         {
1270                 case VBOX_DISPLAY_OFF:
1271                 fprintf(fp,"vbox_display    off\n\n");
1272                 break;
1273                 case VBOX_DISPLAY_DETAILED:
1274                 fprintf(fp,"vbox_display    detailed\n\n");
1275                 break;
1276                 default:
1277                 fprintf(fp,"vbox_display    brief\n\n");
1278         }
1279
1280         fprintf(fp,"# The Answering Machine. Enter type of language: \"english\" or \"german\"\n");
1281         fprintf(fp,"# Display information of the menu, will be provided as specified.\n");
1282         fprintf(fp,"# The menu's voice is located in \"vbox_english\" and \"vbox_german\".\n");
1283         if (ext->vbox_language)
1284                 fprintf(fp,"vbox_language   german\n\n");
1285         else
1286                 fprintf(fp,"vbox_language   english\n\n");
1287
1288         fprintf(fp,"# The Answering Machine. Enter email to send incoming messages to:\n");
1289         fprintf(fp,"# All incoming message will be send to the given address.\n");
1290         fprintf(fp,"# The audio file is attached if \"vbox_email_file\" is 'yes'\n");
1291         fprintf(fp,"vbox_email      %s\n", ext->vbox_email);
1292         fprintf(fp,"vbox_email_file %s\n\n",ext_yesno[ext->vbox_email_file]);
1293
1294         fprintf(fp,"# If audio path is connected prior answering of a call, say 'yes'\n");
1295         fprintf(fp,"# will cause the call to be billed after playing the announcement. (yes or no)\n");
1296         fprintf(fp,"vbox_free       %s\n\n",(ext->vbox_free)?"yes":"no");
1297
1298         fprintf(fp,"# Accept incoming data calls as it would be an audio call.\n");
1299         fprintf(fp,"datacall        %s\n\n",ext_yesno[ext->datacall]);
1300
1301         fprintf(fp,"# Include seconds (time) in the connect message. (Should be always enabled.)\n");
1302         fprintf(fp,"seconds         %s\n\n",ext_yesno[1-ext->no_seconds]);
1303
1304         fprintf(fp,"# Last outgoing and incoming numbers (including prefix)\n");
1305         i = 0;
1306         while(i < MAX_REMEMBER)
1307         {
1308                 if (ext->last_out[i][0])
1309                         fprintf(fp,"last_out        %s\n",ext->last_out[i]);
1310                 i++;
1311         }
1312         i = 0;
1313         while(i < MAX_REMEMBER)
1314         {
1315                 if (ext->last_in[i][0])
1316                         fprintf(fp,"last_in         %s\n",ext->last_in[i]);
1317                 i++;
1318         }
1319         fprintf(fp,"\n");
1320
1321
1322         if (fp) fclose(fp);
1323         return(1);
1324 }
1325
1326
1327 /* write log for extension
1328  *
1329  */
1330 int write_log(char *number, char *callerid, char *calledid, time_t start, time_t stop, int aoce, int cause, int location)
1331 {
1332         char *mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1333         FILE *fp=NULL;
1334         char filename[256];
1335         struct tm *tm;
1336
1337         if (callerid[0] == '\0')
1338                 callerid = "<unknown>";
1339
1340         SPRINT(filename, "%s/%s/%s/log", INSTALL_DATA, options.extensions_dir, number);
1341
1342         if (!(fp = fopen(filename, "a")))
1343         {
1344                 PERROR("Cannot open log: \"%s\"\n", filename);
1345                 return(0);
1346         }
1347
1348         tm = localtime(&start);
1349         fprintf(fp,"%s %2d %04d %02d:%02d:%02d %s", mon[tm->tm_mon], tm->tm_mday, tm->tm_year+1900, tm->tm_hour, tm->tm_min, tm->tm_sec, number);
1350         if (stop)
1351                 fprintf(fp," %2ld:%02ld:%02ld", (stop-start)/3600, (((unsigned long)(stop-start))/60)%60, ((unsigned long)(stop-start))%60);
1352         else
1353                 fprintf(fp," --:--:--");
1354         fprintf(fp," %s -> %s", callerid, calledid);
1355         if (cause >= 1 && cause <=127 && location>=0 && location<=15)
1356                 fprintf(fp," (cause=%d '%s' location=%d '%s')", cause, isdn_cause[cause].german, location, isdn_location[location].german);
1357         fprintf(fp,"\n");
1358
1359         if (fp) fclose(fp);
1360         return(1);
1361 }
1362
1363
1364 /* parse phonebook
1365  *
1366  * reads phone book of extextension and compares the given elements which
1367  * are: abreviation, phone number, name (name is not compared)
1368  * on success a 1 is returned and the pointers of elements are set to the
1369  * result.
1370  */
1371 int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, char **name_pointer)
1372 {
1373         FILE *fp=NULL;
1374         char filename[256];
1375         char *p;
1376         static char abbrev[32], phone[256], name[256];
1377         unsigned int line,i;
1378         char buffer[1024];
1379         int found = 0, found_if_more_digits = 0;
1380
1381         SPRINT(filename, "%s/%s/%s/phonebook", INSTALL_DATA, options.extensions_dir, number);
1382
1383         if (!(fp = fopen(filename, "r")))
1384         {
1385                 PERROR("Cannot open phonebook: \"%s\"\n", filename);
1386                 return(0);
1387         }
1388
1389         line=0;
1390         while((fgets(buffer, sizeof(buffer), fp)))
1391         {
1392                 line++;
1393                 buffer[sizeof(buffer)-1] = '\0';
1394                 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1395                 p = buffer;
1396
1397                 while(*p <= 32) /* skip spaces */
1398                 {
1399                         if (*p == 0)
1400                                 break;
1401                         p++;
1402                 }
1403                 if (*p==0 || *p=='#') /* ignore comments and empty line */
1404                         continue;
1405
1406                 abbrev[0]=0;
1407                 phone[0]=0;
1408                 name[0]=0;
1409
1410                 i=0; /* read abbrev */
1411                 while(*p > 32)
1412                 {
1413                         if (i+1 >= sizeof(abbrev))
1414                         {
1415                                 PERROR_RUNTIME("Error in %s (line %d): abbrev too long.\n",filename,line);
1416                                 break;
1417                         }
1418                         abbrev[i+1] = '\0';
1419                         abbrev[i++] = *p++;
1420                 }
1421
1422                 while(*p <= 32) /* skip spaces */
1423                 {
1424                         if (*p == 0)
1425                                 break;
1426                         p++;
1427                 }
1428
1429                 if (*p!=0 && *p!='#') /* phone */
1430                 {
1431                         i=0; /* read phone */
1432                         while(*p > 32)
1433                         {
1434                                 if (i+1 >= sizeof(phone))
1435                                 {
1436                                         PERROR_RUNTIME("Error in %s (line %d): phone too long.\n",filename,line);
1437                                         break;
1438                                 }
1439                                 phone[i+1] = '\0';
1440                                 phone[i++] = *p++;
1441                         }
1442                         while(*p <= 32) /* skip spaces */
1443                         {
1444                                 if (*p == 0)
1445                                         break;
1446                                 p++;
1447                         }
1448                 }
1449
1450                 if (*p!=0 && *p!='#') /* name */
1451                 {
1452                         i=0; /* read name */
1453                         while(*p > 0)
1454                         {
1455                                 if (i+1 >= sizeof(name))
1456                                 {
1457                                         PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1458                                         break;
1459                                 }
1460                                 name[i+1] = '\0';
1461                                 name[i++] = *p++;
1462                         }
1463                 }
1464
1465                 if (*abbrev_pointer)
1466                 {
1467                         if (!strncmp(*abbrev_pointer, abbrev, strlen(*abbrev_pointer)))
1468                         {
1469                                 /* may match if abbreviation is longer */
1470                                 found_if_more_digits = 1;
1471                         }
1472                         if (!!strcasecmp(*abbrev_pointer, abbrev))
1473                                 continue;
1474                 }
1475                 if (*phone_pointer)
1476                         if (!!strcasecmp(*phone_pointer, phone))
1477                                 continue;
1478                 if (*name_pointer)
1479                         if (!!strcasecmp(*name_pointer, name))
1480                                 continue;
1481
1482                 found = 1;
1483                 break; /* found entry */
1484         }
1485
1486         if (fp) fclose(fp);
1487
1488         if (found)
1489         {
1490                 *abbrev_pointer = abbrev;
1491                 *phone_pointer = phone;
1492                 *name_pointer = name;
1493         }
1494
1495         if (found == 0)
1496         {
1497                 if (found_if_more_digits)
1498                         found = -1;
1499         }
1500         return(found);
1501 }
1502
1503 /* parsing secrets file
1504  *
1505  * 'number' specifies the externsion number, not the caller id
1506  * 'remote_id' specifies the dialed number, or the caller id for incoming calls
1507  * the result is the auth, crypt and key string, and 1 is returned.
1508  * on failure or not matching number, the 0 is returned
1509  */
1510 int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **crypt_pointer, char **key_pointer)
1511 {
1512         FILE *fp=NULL;
1513         char filename[256];
1514         char *p;
1515         char remote[128];
1516         static char auth[64], crypt[64], key[4096];
1517         unsigned int line,i;
1518         char buffer[4096];
1519         int found = 0;
1520
1521         SPRINT(filename, "%s/%s/%s/secrets", INSTALL_DATA, options.extensions_dir, number);
1522
1523         if (!(fp = fopen(filename, "r")))
1524         {
1525                 PERROR("Cannot open secrets: \"%s\"\n", filename);
1526                 return(0);
1527         }
1528
1529         line=0;
1530         while((fgets(buffer, sizeof(buffer), fp)))
1531         {
1532                 line++;
1533                 buffer[sizeof(buffer)-1] = '\0';
1534                 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1535                 p = buffer;
1536
1537                 while(*p <= 32) /* skip spaces */
1538                 {
1539                         if (*p == 0)
1540                                 break;
1541                         p++;
1542                 }
1543                 if (*p==0 || *p=='#') /* ignore comments and empty line */
1544                         continue;
1545
1546                 remote[0]=0;
1547                 auth[0]=0;
1548                 crypt[0]=0;
1549                 key[0]=0;
1550
1551                 i=0; /* read auth */
1552                 while(*p > 32)
1553                 {
1554                         if (i+1 >= sizeof(remote))
1555                         {
1556                                 PERROR_RUNTIME("Error in %s (line %d): remote too long.\n",filename,line);
1557                                 break;
1558                         }
1559                         remote[i+1] = '\0';
1560                         remote[i++] = *p++;
1561                 }
1562
1563                 while(*p <= 32) /* skip spaces */
1564                 {
1565                         if (*p == 0)
1566                                 break;
1567                         p++;
1568                 }
1569
1570                 if (*p!=0 && *p!='#') /* auth */
1571                 {
1572                         i=0; /* read auth */
1573                         while(*p > 32)
1574                         {
1575                                 if (i+1 >= sizeof(auth))
1576                                 {
1577                                         PERROR_RUNTIME("Error in %s (line %d): auth too long.\n",filename,line);
1578                                         break;
1579                                 }
1580                                 auth[i+1] = '\0';
1581                                 auth[i++] = *p++;
1582                         }
1583                         while(*p <= 32) /* skip spaces */
1584                         {
1585                                 if (*p == 0)
1586                                         break;
1587                                 p++;
1588                         }
1589                 }
1590
1591                 if (*p!=0 && *p!='#') /* crypt */
1592                 {
1593                         i=0; /* read crypt */
1594                         while(*p > 32)
1595                         {
1596                                 if (i+1 >= sizeof(crypt))
1597                                 {
1598                                         PERROR_RUNTIME("Error in %s (line %d): crypt too long.\n",filename,line);
1599                                         break;
1600                                 }
1601                                 crypt[i+1] = '\0';
1602                                 crypt[i++] = *p++;
1603                         }
1604                         while(*p <= 32) /* skip spaces */
1605                         {
1606                                 if (*p == 0)
1607                                         break;
1608                                 p++;
1609                         }
1610                 }
1611
1612                 if (*p!=0 && *p!='#') /* key */
1613                 {
1614                         i=0; /* read key */
1615                         while(*p > 0)
1616                         {
1617                                 if (i+1 >= sizeof(key))
1618                                 {
1619                                         PERROR_RUNTIME("Error in %s (line %d): key too long.\n",filename,line);
1620                                         break;
1621                                 }
1622                                 key[i+1] = '\0';
1623                                 key[i++] = *p++;
1624                         }
1625                 }
1626 //printf("COMPARING: '%s' with '%s' %s %s %s\n", remote_id, remote, auth, crypt, key);
1627
1628                 if (!!strcasecmp(remote, remote_id))
1629                         continue;
1630
1631                 found = 1;
1632                 break; /* found entry */
1633         }
1634
1635         if (fp) fclose(fp);
1636
1637         if (found)
1638         {
1639                 *auth_pointer = auth;
1640                 *crypt_pointer = crypt;
1641                 *key_pointer = key;
1642         }
1643
1644         return(found);
1645 }
1646
1647 /* parse directory
1648  *
1649  * the caller id is given and the name is returned. if the name is not found,
1650  * NULL is returned.
1651  * on success a 1 is returned and the pointers of elements are set to the
1652  * result.
1653  */
1654 char *parse_directory(char *number, int type)
1655 {
1656         FILE *fp=NULL;
1657         char filename[256];
1658         char *p;
1659         static char phone[32], name[64];
1660         unsigned int line,i;
1661         char buffer[256];
1662         int found = 0;
1663
1664         SPRINT(filename, "%s/directory.list", INSTALL_DATA);
1665
1666         if (!(fp = fopen(filename, "r")))
1667         {
1668                 PERROR("Cannot open directory: \"%s\"\n", filename);
1669                 return(NULL);
1670         }
1671
1672         line=0;
1673         while((fgets(buffer, sizeof(buffer), fp)))
1674         {
1675                 line++;
1676                 buffer[sizeof(buffer)-1] = '\0';
1677                 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1678                 p = buffer;
1679
1680                 while(*p <= 32) /* skip spaces */
1681                 {
1682                         if (*p == 0)
1683                                 break;
1684                         p++;
1685                 }
1686                 if (*p==0 || *p=='#') /* ignore comments and empty line */
1687                         continue;
1688
1689                 phone[0]=0;
1690                 name[0]=0;
1691
1692                 i=0; /* read number */
1693                 while(*p > 32)
1694                 {
1695                         if (i+1 >= sizeof(phone))
1696                         {
1697                                 PERROR_RUNTIME("Error in %s (line %d): number too long.\n",filename,line);
1698                                 break;
1699                         }
1700                         phone[i+1] = '\0';
1701                         phone[i++] = *p++;
1702                 }
1703
1704                 while(*p <= 32) /* skip spaces */
1705                 {
1706                         if (*p == 0)
1707                                 break;
1708                         p++;
1709                 }
1710
1711                 i=0; /* read name */
1712                 while(*p >= 32)
1713                 {
1714                         if (i+1 >= sizeof(name))
1715                         {
1716                                 PERROR_RUNTIME("Error in %s (line %d): name too long.\n",filename,line);
1717                                 break;
1718                         }
1719                         name[i+1] = '\0';
1720                         name[i++] = *p++;
1721                 }
1722
1723                 if (phone[0] == 'i')
1724                 {
1725                         if (type != INFO_NTYPE_INTERNATIONAL)
1726                                 continue;
1727                         if (!strcmp(number, phone+1))
1728                         {
1729                                 found = 1;
1730                                 break;
1731                         }
1732                         continue;
1733                 }
1734                 if (phone[0] == 'n')
1735                 {
1736                         if (type != INFO_NTYPE_NATIONAL)
1737                                 continue;
1738                         if (!strcmp(number, phone+1))
1739                         {
1740                                 found = 1;
1741                                 break;
1742                         }
1743                         continue;
1744                 }
1745                 if (phone[0] == 's')
1746                 {
1747                         if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1748                                 continue;
1749                         if (!strcmp(number, phone+1))
1750                         {
1751                                 found = 1;
1752                                 break;
1753                         }
1754                         continue;
1755                 }
1756                 if (!strncmp(phone, options.international, strlen(options.international)))
1757                 {
1758                         if (type != INFO_NTYPE_INTERNATIONAL)
1759                                 continue;
1760                         if (!strcmp(number, phone+strlen(options.international)))
1761                         {
1762                                 found = 1;
1763                                 break;
1764                         }
1765                         continue;
1766                 }
1767                 if (!options.national[0]) /* no national prefix */
1768                 {
1769                         if (type == INFO_NTYPE_INTERNATIONAL)
1770                                 continue;
1771                         if (!strcmp(number, phone))
1772                         {
1773                                 found = 1;
1774                                 break;
1775                         }
1776                         continue;
1777                 }
1778                 if (!strncmp(phone, options.national, strlen(options.national)))
1779                 {
1780                         if (type != INFO_NTYPE_NATIONAL)
1781                                 continue;
1782                         if (!strcmp(number, phone+strlen(options.national)))
1783                         {
1784                                 found = 1;
1785                                 break;
1786                         }
1787                         continue;
1788                 }
1789                 if (type==INFO_NTYPE_NATIONAL || type==INFO_NTYPE_INTERNATIONAL)
1790                         continue;
1791                 if (!strcmp(number, phone))
1792                 {
1793                         found = 1;
1794                         break;
1795                 }
1796         }
1797
1798         if (fp) fclose(fp);
1799
1800         if (found)
1801                 return(name);
1802         else
1803                 return(NULL);
1804 }
1805
1806 /* parse callbackauth
1807  *
1808  * searches for the given caller id and returns 1 == true or 0 == false
1809  */
1810 int parse_callbackauth(char *number, struct caller_info *callerinfo)
1811 {
1812         FILE *fp = NULL;
1813         char filename[256];
1814         char *p;
1815         unsigned int line,i;
1816         char buffer[256];
1817         static char caller_type[32], caller_id[64];
1818         int found = 0;
1819
1820         SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
1821
1822         if (!(fp = fopen(filename, "r")))
1823         {
1824                 PDEBUG(DEBUG_EPOINT, "Cannot open callbackauth: \"%s\"\n", filename);
1825                 return(0);
1826         }
1827
1828         line=0;
1829         while((fgets(buffer, sizeof(buffer), fp)))
1830         {
1831                 line++;
1832                 buffer[sizeof(buffer)-1] = '\0';
1833                 if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
1834                 p = buffer;
1835
1836                 while(*p <= 32) /* skip spaces */
1837                 {
1838                         if (*p == 0)
1839                                 break;
1840                         p++;
1841                 }
1842                 if (*p==0 || *p=='#') /* ignore comments and empty line */
1843                         continue;
1844
1845                 caller_type[0]=0;
1846                 caller_id[0]=0;
1847
1848                 i=0; /* read caller_type */
1849                 while(*p > 32)
1850                 {
1851                         if (i+1 >= sizeof(caller_type))
1852                         {
1853                                 PERROR_RUNTIME("Error in %s (line %d): caller_type too long.\n",filename,line);
1854                                 break;
1855                         }
1856                         caller_type[i+1] = '\0';
1857                         caller_type[i++] = *p++;
1858                 }
1859
1860                 while(*p <= 32) /* skip spaces */
1861                 {
1862                         if (*p == 0)
1863                                 break;
1864                         p++;
1865                 }
1866
1867                 if (*p!=0 && *p!='#') /* caller_id */
1868                 {
1869                         i=0; /* read caller_id */
1870                         while(*p > 32)
1871                         {
1872                                 if (i+1 >= sizeof(caller_id))
1873                                 {
1874                                         PERROR_RUNTIME("Error in %s (line %d): caller_id too long.\n",filename,line);
1875                                         break;
1876                                 }
1877                                 caller_id[i+1] = '\0';
1878                                 caller_id[i++] = *p++;
1879                         }
1880                         // ignoring more
1881                 }
1882
1883                 if (caller_type[0]=='\0' && caller_id[0]=='\0')
1884                         continue;
1885
1886                 if (atoi(caller_type) != callerinfo->ntype)
1887                         continue;
1888
1889                 if (!!strcmp(caller_id, callerinfo->id))
1890                         continue;
1891
1892                 found = 1;
1893                 break; /* found entry */
1894         }
1895
1896         if (fp) fclose(fp);
1897
1898         if (found)
1899                 return(1);
1900         return(0);
1901 }
1902
1903
1904 /* append line to callbackauth
1905  *
1906  */
1907 void append_callbackauth(char *number, struct caller_info *callerinfo)
1908 {
1909         FILE *fp = NULL;
1910         char filename[256];
1911
1912         SPRINT(filename, "%s/%s/%s/callbackauth", INSTALL_DATA, options.extensions_dir, number);
1913
1914         if (callerinfo->id[0]=='\0')
1915         {
1916                 PERROR("caller has no id.\n");
1917                 return;
1918         }
1919         if (!(fp = fopen(filename, "a")))
1920         {
1921                 PERROR("Cannot open callbackauth: \"%s\"\n", filename);
1922                 return;
1923         }
1924
1925         fprintf(fp, "%6d  %s\n", callerinfo->ntype, callerinfo->id);
1926
1927         fclose(fp);
1928
1929 }
1930
1931