| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 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 |
|
| 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 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
break; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
usage(); |
| 152 |
return 2; |
| 153 |
} |