Asterisk - The Open Source Telephony Project GIT-master-7921072
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
30void 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
41void 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
76int 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
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
98int 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
108void 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
120int 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}
static const char name[]
Definition: format_mp3.c:68
static char country[80]
Definition: pbx_dundi.c:205
#define NULL
Definition: resample.c:96
int main(int argc, char *argv[])
int print_all()
void print_indications(struct ind_tone_zone *zone_data)
void usage()
void print_tone_zone_sound(struct ind_tone_zone *zone_data, const char *name, int toneid)
#define PROGRAM
int print_zone_by_id(int zone_num)
int print_zone_by_country(char *country)