Use AC_CHECK_TYPE and correct quoting for Asterisk struct checks, and add
[lcr.git] / cause.c
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** cause database                                                            **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include <stdio.h>
13 #include <stdarg.h>
14 #include <string.h>
15 #include <stdlib.h>
16 #include "macro.h"
17 #include "cause.h"
18 #include "extension.h"
19
20 struct isdn_cause isdn_cause[128] = {
21                         /********************************* - **/ /*38*/
22         { /*0*/         "<No cause>",
23                         "<Kein Grund>" },
24         { /*1*/         "Unallocated number",
25                         "Nummer nicht vergeben" },
26         { /*2*/         "No route to transit network",
27                         "Keine Verbindung zum Netz" },
28         { /*3*/         "No route to destination",
29                         "Zielnummer nicht erreichbar" },
30         { /*4*/         "<Listen to announcement...>",
31                         "<Ansage hoeren...>" },
32         { /*5*/         "Misdialed trunk prefix.",
33                         "Falscher Carrier-Code" },
34         { /*6*/         "Channel unacceptable",
35                         "Kanal nicht akzeptiert" },
36         { /*7*/         "",
37                         "" },
38         { /*8*/         "Preemption",
39                         "Vorkauf" },
40         { /*9*/         "Preemption - circuit reserved",
41                         "Vorkauf - Gasse reserviert" },
42         { /*10*/        "",
43                         "" },
44         { /*11*/        "",
45                         "" },
46         { /*12*/        "",
47                         "" },
48         { /*13*/        "",
49                         "" },
50         { /*14*/        "",
51                         "" },
52         { /*15*/        "",
53                         "" },
54         { /*16*/        "Normal call clearing",
55                         "Normaler Verbindungsabbau" },
56         { /*17*/        "User busy",
57                         "Teilnehmer besetzt" },
58         { /*18*/        "No user responding",
59                         "Teilnehmer antwortet nicht" },
60         { /*19*/        "No answer from user",
61                         "Teilnehmer nimmt nicht ab" },
62         { /*20*/        "Subscriber absent",
63                         "Teilnehmer nicht anwesend" },
64         { /*21*/        "Call rejected",
65                         "Gespraech abgewiesen" },
66         { /*22*/        "Number changed",
67                         "Rufnummer hat sich geaendert" },
68         { /*23*/        "",
69                         "" },
70         { /*24*/        "",
71                         "" },
72         { /*25*/        "",
73                         "" },
74         { /*26*/        "Non-selected user clearing",
75                         "Gespraech woanders angenommen" },
76         { /*27*/        "Destination out of order",
77                         "Gegenstelle ausser Betrieb" },
78         { /*28*/        "Invalid number (incomplete)",
79                         "Fehlerhafte Nummer (n. komplett)" },
80         { /*29*/        "Facility rejected",
81                         "Funktion nicht verfuegbar" },
82         { /*30*/        "",
83                         "" },
84         { /*31*/        "Normal, unspecified",
85                         "Normal, unspezifisch" },
86         { /*32*/        "",
87                         "" },
88         { /*33*/        "",
89                         "" },
90         { /*34*/        "No circuit/channel available",
91                         "Keine Gasse/Kanal verfuegbar" },
92         { /*35*/        "",
93                         "" },
94         { /*36*/        "",
95                         "" },
96         { /*37*/        "",
97                         "" },
98         { /*38*/        "Network out of order",
99                         "Netz ausser Betrieb" },
100         { /*39*/        "",
101                         "" },
102         { /*40*/        "",
103                         "" },
104         { /*41*/        "Temporary failure",
105                         "Vorruebergehende Fehlfunktion" },
106         { /*42*/        "Switchting equipment congestion",
107                         "Vermittlungstelle ueberlastet" },
108         { /*43*/        "Access informationen discarded",
109                         "Zugriffsinformationen geloescht" },
110         { /*44*/        "No requested circuit/channel",
111                         "Keine angeforderte Gasse/Kanal" },
112         { /*45*/        "",
113                         "" },
114         { /*46*/        "Precedence call blocked",
115                         "Vorverkaufanruf gesperrt" },
116         { /*47*/        "Resource unavailable, unspecified",
117                         "" },
118         { /*48*/        "",
119                         "" },
120         { /*49*/        "Quality of service not available",
121                         "Qualitaetsmerkmal nicht verfuegbar" },
122         { /*50*/        "Requested facility not subscribed",
123                         "Funktion nicht freigeschaltet" },
124         { /*51*/        "",
125                         "" },
126         { /*52*/        "",
127                         "" },
128         { /*53*/        "Outgoing calls barred within CUG",
129                         "CUG erlaubt keine gehenden Rufe" },
130         { /*54*/        "",
131                         "" },
132         { /*55*/        "Incoming calls barred within CUG",
133                         "CUG erlaubt keine kommenden Rufe" },
134         { /*56*/        "",
135                         "" },
136         { /*57*/        "Bearer capability not authorized",
137                         "Verbindungseigenschaft verboten" },
138         { /*58*/        "Bearer capability not present",
139                         "Verb.eigenschaft n. verfuegbar" },
140         { /*59*/        "",
141                         "" },
142         { /*60*/        "",
143                         "" },
144         { /*61*/        "",
145                         "" },
146         { /*62*/        "",
147                         "" },
148         { /*63*/        "Service or option not available",
149                         "Dienst oder Merkmal nicht verf." },
150         { /*64*/        "",
151                         "" },
152         { /*65*/        "Bearer capability not implement.",
153                         "Verb.eigenschaft nicht unterstue." },
154         { /*66*/        "Channel type not implemented",
155                         "Kanalart nicht unterstuetzt" },
156         { /*67*/        "",
157                         "" },
158         { /*68*/        "",
159                         "" },
160         { /*69*/        "Requested facility not implement.",
161                         "Funktion nicht unterstuetzt" },
162         { /*70*/        "restricted digital informat. only",
163                         "Nur eingeschraenkte digitale inf." },
164         { /*71*/        "",
165                         "" },
166         { /*72*/        "",
167                         "" },
168         { /*73*/        "",
169                         "" },
170         { /*74*/        "",
171                         "" },
172         { /*75*/        "",
173                         "" },
174         { /*76*/        "",
175                         "" },
176         { /*77*/        "",
177                         "" },
178         { /*78*/        "",
179                         "" },
180         { /*79*/        "Service or option not implemented",
181                         "Dienst oder Merkmal n. unterstue." },
182         { /*80*/        "",
183                         "" },
184         { /*81*/        "Invalid call reference value",
185                         "Falsche call reference" },
186         { /*82*/        "Identified channel does not exist",
187                         "Erkannter Kanal existiert nicht" },
188         { /*83*/        "No suspended call with this id",
189                         "Kein geparktes Gespr. f. diese ID" },
190         { /*84*/        "Call identity in use",
191                         "ID in gebrauch" },
192         { /*85*/        "No call suspended",
193                         "Kein geparktes Gespraech" },
194         { /*86*/        "Suspended call has been cleared",
195                         "Geparktes Gespraech wurde beendet" },
196         { /*87*/        "User not member of CUG",
197                         "Teilnehmer nicht in der CUG" },
198         { /*88*/        "Incompatibel destination",
199                         "Gegenstelle nicht kompatibel" },
200         { /*89*/        "",
201                         "" },
202         { /*90*/        "Non-existent CUG",
203                         "CUG existiert nicht" },
204         { /*91*/        "Invalid transit network selection",
205                         "Falscher Carrier-Code" },
206         { /*92*/        "",
207                         "" },
208         { /*93*/        "",
209                         "" },
210         { /*94*/        "",
211                         "" },
212         { /*95*/        "Invalid message, unspecified",
213                         "Fehlerhafte Daten, unbekannt" },
214         { /*96*/        "Information element missing",
215                         "Information wird vermisst" },
216         { /*97*/        "Message type non-existent",
217                         "Message exisitiert nicht" },
218         { /*98*/        "Message not compatible with state",
219                         "Message nicht komatibel" },
220         { /*99*/        "Information element not impl.",
221                         "Information nicht implementiert" },
222         { /*100*/       "Invalid info element contents",
223                         "Fehlerhafterhafte Information" },
224         { /*101*/       "Message not compatible with state",
225                         "Message not kompatibel" },
226         { /*102*/       "Recovery on timer expiry",
227                         "Fehler durch Zeitueberschreitung" },
228         { /*103*/       "Parameter non-existent",
229                         "Parameter fehlt" },
230         { /*104*/       "",
231                         "" },
232         { /*105*/       "",
233                         "" },
234         { /*106*/       "",
235                         "" },
236         { /*107*/       "",
237                         "" },
238         { /*108*/       "",
239                         "" },
240         { /*109*/       "",
241                         "" },
242         { /*110*/       "",
243                         "" },
244         { /*111*/       "Protocol error, unspecified",
245                         "Protokollfehler, unbekannt" },
246         { /*112*/       "",
247                         "" },
248         { /*113*/       "",
249                         "" },
250         { /*114*/       "",
251                         "" },
252         { /*115*/       "",
253                         "" },
254         { /*116*/       "",
255                         "" },
256         { /*117*/       "",
257                         "" },
258         { /*118*/       "",
259                         "" },
260         { /*119*/       "",
261                         "" },
262         { /*120*/       "",
263                         "" },
264         { /*121*/       "",
265                         "" },
266         { /*122*/       "",
267                         "" },
268         { /*123*/       "",
269                         "" },
270         { /*124*/       "",
271                         "" },
272         { /*125*/       "",
273                         "" },
274         { /*126*/       "",
275                         "" },
276         { /*127*/       "Interworking, unspecified",
277                         "Zusammenspiel, unbekannt" },
278 };
279
280 struct isdn_cause isdn_cause_class[8] = {
281                         /********************************* - **/ /*38*/
282         { /*0*/         "(Normal class)",
283                         "(Normale Fehlerklasse)" },
284         { /*16*/        "(Normal class)",
285                         "(Normale Fehlerklasse)" },
286         { /*32*/        "(Resource unavailable class)",
287                         "(Ressourcen nicht verfuegbar)" },
288         { /*48*/        "(Service or option unavailable)",
289                         "(Dienst oder Merkmal n. verfueg.)" },
290         { /*64*/        "(Service or option n.implemented)",
291                         "(Dienst oder Merkmal n. vorhand.)" },
292         { /*80*/        "(Invalid message class)",
293                         "(Fehlerhafte Message)" },
294         { /*96*/        "(Protocol error class)",
295                         "(Klasse der Protokollfehler)" },
296         { /*112*/       "(Interworking class)",
297                         "(Klasse des Zusammenspiels)" },
298 };
299
300 struct isdn_location isdn_location[16] = {
301         { /*0*/         "User",
302                         "Endgerät" },
303         { /*1*/         "Private (Local)",
304                         "Anlage (Lokal)" },
305         { /*2*/         "Public (Local)",
306                         "Vermittlung (Lokal)" },
307         { /*3*/         "Transit",
308                         "Knotenvermittlung" },
309         { /*4*/         "Public (Remote)",
310                         "Vermittlung (Gegenstelle)" },
311         { /*5*/         "Private (Remote)",
312                         "Anlage (Gegenstelle)" },
313         { /*6*/         "",
314                         "" },
315         { /*7*/         "International",
316                         "Fernvermittlung" },
317         { /*8*/         "",
318                         "" },
319         { /*9*/         "",
320                         "" },
321         { /*10*/        "Beyond Interworking",
322                         "Nicht verfuegbar" },
323         { /*11*/        "",
324                         "" },
325         { /*12*/        "",
326                         "" },
327         { /*13*/        "",
328                         "" },
329         { /*14*/        "",
330                         "" },
331         { /*15*/        "",
332                         "" },
333 };
334
335 char *get_isdn_cause(int cause, int location, int type)
336 {
337         static char result[128];
338
339         /* protect us */
340         if (cause<0 || cause>127)
341                 cause = 0;
342
343         switch(type) {
344                 case DISPLAY_CAUSE_NUMBER:
345                 SPRINT(result, "Cause %d", cause);
346                 break;
347
348                 case DISPLAY_CAUSE_ENGLISH:
349                 if (isdn_cause[cause].english[0])
350                         SPRINT(result, "%d - %s", cause, isdn_cause[cause].english);
351                 else    SPRINT(result, "%d - %s", cause, isdn_cause_class[cause>>4].english);
352                 break;
353
354                 case DISPLAY_CAUSE_GERMAN:
355                 if (isdn_cause[cause].german[0])
356                         SPRINT(result, "%d - %s", cause, isdn_cause[cause].german);
357                 else    SPRINT(result, "%d - %s", cause, isdn_cause_class[cause>>4].german);
358                 break;
359
360                 case DISPLAY_LOCATION_ENGLISH:
361                 if (isdn_location[location].english[0])
362                         SPRINT(result, "%d - %s", cause, isdn_location[location].english);
363                 else    SPRINT(result, "%d - Location code %d", cause, location);
364                 break;
365
366                 case DISPLAY_LOCATION_GERMAN:
367                 if (isdn_location[location].german[0])
368                         SPRINT(result, "%d - %s", cause, isdn_location[location].german);
369                 else    SPRINT(result, "%d - Lokationscode %d", cause, location);
370                 break;
371
372                 default:
373                 result[0] = '\0';
374         }
375
376         return(result);
377 }
378
379 /*
380  * collect cause for multipoint
381  * used by Process, Endpoint and Join instance when multiplexing
382  */
383 void collect_cause(int *multicause, int *multilocation, int newcause, int newlocation)
384 {
385         if (newcause == CAUSE_REJECTED) { /* call rejected */
386                 *multicause = newcause;
387                 *multilocation = newlocation;
388         } else
389         if (newcause==CAUSE_NORMAL && *multicause!=CAUSE_REJECTED) { /* reject via hangup */
390                 *multicause = newcause;
391                 *multilocation = newlocation;
392         } else
393         if (newcause==CAUSE_BUSY && *multicause!=CAUSE_REJECTED && *multicause!=CAUSE_NORMAL) { /* busy */
394                 *multicause = newcause;
395                 *multilocation = newlocation;
396         } else
397         if (newcause==CAUSE_OUTOFORDER && *multicause!=CAUSE_BUSY && *multicause!=CAUSE_REJECTED && *multicause!=CAUSE_NORMAL) { /* no L1 */
398                 *multicause = newcause;
399                 *multilocation = newlocation;
400         } else
401         if (newcause!=CAUSE_NOUSER && *multicause!=CAUSE_OUTOFORDER && *multicause!=CAUSE_BUSY && *multicause!=CAUSE_REJECTED && *multicause!=CAUSE_NORMAL) { /* anything but not 18 */
402                 *multicause = newcause;
403                 *multilocation = newlocation;
404         } else
405         if (newcause==CAUSE_NOUSER && *multicause==CAUSE_NOUSER) { /* cause 18, use the location */
406                 *multilocation = newlocation;
407         } else
408         if (*multicause==0) { /* no cause yet, use newcause (should be 18) */
409                 *multicause = newcause;
410                 *multilocation = newlocation;
411         }
412 }
413