Asterisk - The Open Source Telephony Project
GIT-master-b023714
Loading...
Searching...
No Matches
contrib
utils
zones2indications.c
Go to the documentation of this file.
1
/*
2
* Asterisk -- An open source telephony toolkit.
3
*
4
* Copyright (C) 1999 - 2006, Digium, Inc.
5
*
6
* Tzafrir Cohen <tzafrir.cohen@xorcom.com>
7
*
8
* See http://www.asterisk.org for more information about
9
* the Asterisk project. Please do not directly contact
10
* any of the maintainers of this project for assistance;
11
* the project provides a web site, mailing lists and IRC
12
* channels for your use.
13
*
14
* This program is free software, distributed under the terms of
15
* the GNU General Public License Version 2. See the LICENSE file
16
* at the top of the source tree.
17
*/
18
19
/*! \file
20
* \brief print libtonezone data as Asterisk indications.conf
21
*/
22
23
#include <stdio.h>
24
#include <stdlib.h>
25
#include <dahdi/tonezone.h>
26
#include <unistd.h>
27
28
#define PROGRAM "zones2indication"
29
30
void
print_tone_zone_sound
(
struct
ind_tone_zone *zone_data,
const
char
*
name
,
31
int
toneid) {
32
int
i;
33
for
(i=0; i<DAHDI_TONE_MAX; i++) {
34
if
(zone_data->tones[i].toneid == toneid){
35
printf(
"%s = %s\n"
,
name
, zone_data->tones[i].data);
36
break
;
37
}
38
}
39
}
40
41
void
print_indications
(
struct
ind_tone_zone *zone_data) {
42
int
i;
43
44
printf (
45
"[%s]\n"
46
"; Source: libtonezone.\n"
47
"description = %s\n"
48
"\n"
,
49
zone_data->country, zone_data->description
50
);
51
52
printf(
53
"ringcadence = "
54
);
55
for
(i=0; ; i++) {
56
if
(zone_data->ringcadence[i] == 0)
57
break
;
58
if
(i != 0)
59
putchar(
','
);
60
printf(
"%d"
,zone_data->ringcadence[i]);
61
}
62
putchar(
'\n'
);
63
64
print_tone_zone_sound
(zone_data,
"dial"
, DAHDI_TONE_DIALTONE);
65
print_tone_zone_sound
(zone_data,
"busy"
, DAHDI_TONE_BUSY);
66
print_tone_zone_sound
(zone_data,
"ring"
, DAHDI_TONE_RINGTONE);
67
print_tone_zone_sound
(zone_data,
"congestion"
, DAHDI_TONE_CONGESTION);
68
print_tone_zone_sound
(zone_data,
"callwaiting"
, DAHDI_TONE_CALLWAIT);
69
print_tone_zone_sound
(zone_data,
"dialrecall"
, DAHDI_TONE_DIALRECALL);
70
print_tone_zone_sound
(zone_data,
"record"
, DAHDI_TONE_RECORDTONE);
71
print_tone_zone_sound
(zone_data,
"info"
, DAHDI_TONE_INFO);
72
print_tone_zone_sound
(zone_data,
"stutter"
, DAHDI_TONE_STUTTER);
73
printf(
"\n\n"
);
74
}
75
76
int
print_zone_by_id
(
int
zone_num) {
77
struct
tone_zone *zone_data = tone_zone_find_by_num(zone_num);
78
79
if
(zone_data ==
NULL
)
80
return
1;
81
82
print_indications
(zone_data);
83
84
return
0;
85
}
86
87
int
print_zone_by_country
(
char
*
country
) {
88
struct
tone_zone *zone_data = tone_zone_find(
country
);
89
90
if
(zone_data ==
NULL
)
91
return
1;
92
93
print_indications
(zone_data);
94
95
return
0;
96
}
97
98
int
print_all
() {
99
int
i;
100
/* loop over all possible zones */
101
for
(i=0; ; i++) {
102
if
(
print_zone_by_id
(i))
103
break
;
104
}
105
return
0;
106
}
107
108
void
usage
() {
109
fprintf(stderr,
110
PROGRAM
": print libtonezone data as Asterisk indications.conf\n"
111
"\n"
112
"Usage:\n"
113
" "
PROGRAM
" -a Print all countries\n"
114
" "
PROGRAM
" -c <code> Select country by two-letter country code\n"
115
" "
PROGRAM
" -n <num> Select country by its internal libtonezone number\n"
116
" "
PROGRAM
" -h Print this text.\n"
117
);
118
}
119
120
int
main
(
int
argc,
char
* argv[]){
121
int
country_code = -1;
122
int
opt_print_all = 0;
123
int
opt;
124
char
* endptr =
NULL
;
125
126
while
((opt = getopt(argc, argv,
"ac:hn:"
)) != -1) {
127
switch
(opt) {
128
case
'a'
:
129
return
print_all
();
130
case
'c'
:
131
return
print_zone_by_country
(optarg);
132
case
'h'
:
133
usage
();
134
return
0;
135
case
'n'
:
136
printf(
"number is %s.\n"
, optarg);
137
country_code = strtol(optarg, &endptr, 10);
138
return
print_zone_by_id
(country_code);
139
/* FIXME: what if this is not a number?
140
if (endptr != NULL) {
141
fprintf(stderr, "Error: Invalid country code %s, %d.\n",optarg, country_code);
142
usage();
143
exit(1);
144
}
145
*/
146
break
;
147
}
148
}
149
150
/* If we got here, the user selected no option */
151
usage
();
152
return
2;
153
}
main
int main()
Definition
eagi_proxy.c:107
name
static const char name[]
Definition
format_mp3.c:68
country
static char country[80]
Definition
pbx_dundi.c:214
NULL
#define NULL
Definition
resample.c:96
print_all
int print_all()
Definition
zones2indications.c:98
print_indications
void print_indications(struct ind_tone_zone *zone_data)
Definition
zones2indications.c:41
usage
void usage()
Definition
zones2indications.c:108
print_tone_zone_sound
void print_tone_zone_sound(struct ind_tone_zone *zone_data, const char *name, int toneid)
Definition
zones2indications.c:30
PROGRAM
#define PROGRAM
Definition
zones2indications.c:28
print_zone_by_id
int print_zone_by_id(int zone_num)
Definition
zones2indications.c:76
print_zone_by_country
int print_zone_by_country(char *country)
Definition
zones2indications.c:87
Generated on Wed Oct 15 2025 20:04:17 for Asterisk - The Open Source Telephony Project by
1.9.8