#include "asterisk.h"
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/logger.h"
#include "asterisk/config.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/indications.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Functions | |
AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS,"Indications Resource",.load=load_module,.unload=unload_module,.reload=reload,) | |
static int | handle_add_indication (int fd, int argc, char *argv[]) |
static int | handle_playtones (struct ast_channel *chan, void *data) |
static int | handle_remove_indication (int fd, int argc, char *argv[]) |
static int | handle_show_indications (int fd, int argc, char *argv[]) |
static int | handle_stopplaytones (struct ast_channel *chan, void *data) |
static int | ind_load_module (void) |
static int | load_module (void) |
static int | reload (void) |
static int | unload_module (void) |
Variables | |
static struct ast_cli_entry | cli_indications [] |
static struct ast_cli_entry | cli_show_indications_deprecated |
static const char | config [] = "indications.conf" |
static char | help_add_indication [] |
static char | help_remove_indication [] |
static char | help_show_indications [] |
char * | playtones_desc |
Load the country specific dialtones into the asterisk PBX.
Definition in file res_indications.c.
AST_MODULE_INFO | ( | ASTERISK_GPL_KEY | , | |
AST_MODFLAG_GLOBAL_SYMBOLS | , | |||
"Indications Resource" | , | |||
. | load = load_module , |
|||
. | unload = unload_module , |
|||
. | reload = reload | |||
) |
static int handle_add_indication | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 86 of file res_indications.c.
References ast_calloc, ast_get_indication_zone(), ast_log(), ast_register_indication(), ast_register_indication_country(), ast_unregister_indication_country(), tone_zone::country, free, LOG_NOTICE, LOG_WARNING, and RESULT_SHOWUSAGE.
00087 { 00088 struct tone_zone *tz; 00089 int created_country = 0; 00090 if (argc != 5) return RESULT_SHOWUSAGE; 00091 00092 tz = ast_get_indication_zone(argv[2]); 00093 if (!tz) { 00094 /* country does not exist, create it */ 00095 ast_log(LOG_NOTICE, "Country '%s' does not exist, creating it.\n",argv[2]); 00096 00097 if (!(tz = ast_calloc(1, sizeof(*tz)))) { 00098 return -1; 00099 } 00100 ast_copy_string(tz->country,argv[2],sizeof(tz->country)); 00101 if (ast_register_indication_country(tz)) { 00102 ast_log(LOG_WARNING, "Unable to register new country\n"); 00103 free(tz); 00104 return -1; 00105 } 00106 created_country = 1; 00107 } 00108 if (ast_register_indication(tz,argv[3],argv[4])) { 00109 ast_log(LOG_WARNING, "Unable to register indication %s/%s\n",argv[2],argv[3]); 00110 if (created_country) 00111 ast_unregister_indication_country(argv[2]); 00112 return -1; 00113 } 00114 return 0; 00115 }
static int handle_playtones | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 197 of file res_indications.c.
References ast_get_indication_tone(), ast_log(), ast_playtones_start(), tone_zone_sound::data, LOG_NOTICE, and ast_channel::zone.
Referenced by load_module().
00198 { 00199 struct tone_zone_sound *ts; 00200 int res; 00201 00202 if (!data || !((char*)data)[0]) { 00203 ast_log(LOG_NOTICE,"Nothing to play\n"); 00204 return -1; 00205 } 00206 ts = ast_get_indication_tone(chan->zone, (const char*)data); 00207 if (ts && ts->data[0]) 00208 res = ast_playtones_start(chan, 0, ts->data, 0); 00209 else 00210 res = ast_playtones_start(chan, 0, (const char*)data, 0); 00211 if (res) 00212 ast_log(LOG_NOTICE,"Unable to start playtones\n"); 00213 return res; 00214 }
static int handle_remove_indication | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 120 of file res_indications.c.
References ast_get_indication_zone(), ast_log(), ast_unregister_indication(), ast_unregister_indication_country(), LOG_WARNING, and RESULT_SHOWUSAGE.
00121 { 00122 struct tone_zone *tz; 00123 if (argc != 3 && argc != 4) return RESULT_SHOWUSAGE; 00124 00125 if (argc == 3) { 00126 /* remove entiry country */ 00127 if (ast_unregister_indication_country(argv[2])) { 00128 ast_log(LOG_WARNING, "Unable to unregister indication country %s\n",argv[2]); 00129 return -1; 00130 } 00131 return 0; 00132 } 00133 00134 tz = ast_get_indication_zone(argv[2]); 00135 if (!tz) { 00136 ast_log(LOG_WARNING, "Unable to unregister indication %s/%s, country does not exists\n",argv[2],argv[3]); 00137 return -1; 00138 } 00139 if (ast_unregister_indication(tz,argv[3])) { 00140 ast_log(LOG_WARNING, "Unable to unregister indication %s/%s\n",argv[2],argv[3]); 00141 return -1; 00142 } 00143 return 0; 00144 }
static int handle_show_indications | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 149 of file res_indications.c.
References tone_zone::alias, ast_cli(), ast_walk_indications(), tone_zone::country, tone_zone_sound::data, tone_zone::description, tone_zone_sound::name, tone_zone_sound::next, tone_zone::nrringcadence, tone_zone::ringcadence, and tone_zone::tones.
00150 { 00151 struct tone_zone *tz = NULL; 00152 char buf[256]; 00153 int found_country = 0; 00154 00155 if (argc == 2) { 00156 /* no arguments, show a list of countries */ 00157 ast_cli(fd,"Country Alias Description\n" 00158 "===========================\n"); 00159 while ( (tz = ast_walk_indications(tz) ) ) 00160 ast_cli(fd,"%-7.7s %-7.7s %s\n", tz->country, tz->alias, tz->description); 00161 return 0; 00162 } 00163 /* there was a request for specific country(ies), lets humor them */ 00164 while ( (tz = ast_walk_indications(tz) ) ) { 00165 int i,j; 00166 for (i=2; i<argc; i++) { 00167 if (strcasecmp(tz->country,argv[i])==0 && 00168 !tz->alias[0]) { 00169 struct tone_zone_sound* ts; 00170 if (!found_country) { 00171 found_country = 1; 00172 ast_cli(fd,"Country Indication PlayList\n" 00173 "=====================================\n"); 00174 } 00175 j = snprintf(buf,sizeof(buf),"%-7.7s %-15.15s ",tz->country,"<ringcadence>"); 00176 for (i=0; i<tz->nrringcadence; i++) { 00177 j += snprintf(buf+j,sizeof(buf)-j,"%d,",tz->ringcadence[i]); 00178 } 00179 if (tz->nrringcadence) 00180 j--; 00181 ast_copy_string(buf+j,"\n",sizeof(buf)-j); 00182 ast_cli(fd,buf); 00183 for (ts=tz->tones; ts; ts=ts->next) 00184 ast_cli(fd,"%-7.7s %-15.15s %s\n",tz->country,ts->name,ts->data); 00185 break; 00186 } 00187 } 00188 } 00189 if (!found_country) 00190 ast_cli(fd,"No countries matched your criteria.\n"); 00191 return -1; 00192 }
static int handle_stopplaytones | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 219 of file res_indications.c.
References ast_playtones_stop().
Referenced by load_module().
00220 { 00221 ast_playtones_stop(chan); 00222 return 0; 00223 }
static int ind_load_module | ( | void | ) | [static] |
Definition at line 228 of file res_indications.c.
References tone_zone::alias, ast_calloc, ast_category_browse(), ast_config_destroy(), ast_config_load(), ast_log(), ast_malloc, ast_realloc, ast_register_indication_country(), ast_set_indication_country(), ast_strdupa, ast_variable_browse(), ast_variable_retrieve(), tone_zone::country, country, tone_zone_sound::data, tone_zone::description, free, ast_variable::lineno, LOG_NOTICE, LOG_WARNING, tone_zone_sound::name, ast_variable::name, ast_variable::next, tone_zone_sound::next, tone_zone::nrringcadence, ring(), tone_zone::ringcadence, strdup, strsep(), tone_zone::tones, and ast_variable::value.
Referenced by load_module(), and reload().
00229 { 00230 struct ast_config *cfg; 00231 struct ast_variable *v; 00232 char *cxt; 00233 char *c; 00234 struct tone_zone *tones; 00235 const char *country = NULL; 00236 00237 /* that the following cast is needed, is yuk! */ 00238 /* yup, checked it out. It is NOT written to. */ 00239 cfg = ast_config_load((char *)config); 00240 if (!cfg) 00241 return -1; 00242 00243 /* Use existing config to populate the Indication table */ 00244 cxt = ast_category_browse(cfg, NULL); 00245 while(cxt) { 00246 /* All categories but "general" are considered countries */ 00247 if (!strcasecmp(cxt, "general")) { 00248 cxt = ast_category_browse(cfg, cxt); 00249 continue; 00250 } 00251 if (!(tones = ast_calloc(1, sizeof(*tones)))) { 00252 ast_config_destroy(cfg); 00253 return -1; 00254 } 00255 ast_copy_string(tones->country,cxt,sizeof(tones->country)); 00256 00257 v = ast_variable_browse(cfg, cxt); 00258 while(v) { 00259 if (!strcasecmp(v->name, "description")) { 00260 ast_copy_string(tones->description, v->value, sizeof(tones->description)); 00261 } else if ((!strcasecmp(v->name,"ringcadence"))||(!strcasecmp(v->name,"ringcadance"))) { 00262 char *ring,*rings = ast_strdupa(v->value); 00263 c = rings; 00264 ring = strsep(&c,","); 00265 while (ring) { 00266 int *tmp, val; 00267 if (!isdigit(ring[0]) || (val=atoi(ring))==-1) { 00268 ast_log(LOG_WARNING,"Invalid ringcadence given '%s' at line %d.\n",ring,v->lineno); 00269 ring = strsep(&c,","); 00270 continue; 00271 } 00272 if (!(tmp = ast_realloc(tones->ringcadence, (tones->nrringcadence + 1) * sizeof(int)))) { 00273 ast_config_destroy(cfg); 00274 return -1; 00275 } 00276 tones->ringcadence = tmp; 00277 tmp[tones->nrringcadence] = val; 00278 tones->nrringcadence++; 00279 /* next item */ 00280 ring = strsep(&c,","); 00281 } 00282 } else if (!strcasecmp(v->name,"alias")) { 00283 char *countries = ast_strdupa(v->value); 00284 c = countries; 00285 country = strsep(&c,","); 00286 while (country) { 00287 struct tone_zone* azone; 00288 if (!(azone = ast_calloc(1, sizeof(*azone)))) { 00289 ast_config_destroy(cfg); 00290 return -1; 00291 } 00292 ast_copy_string(azone->country, country, sizeof(azone->country)); 00293 ast_copy_string(azone->alias, cxt, sizeof(azone->alias)); 00294 if (ast_register_indication_country(azone)) { 00295 ast_log(LOG_WARNING, "Unable to register indication alias at line %d.\n",v->lineno); 00296 free(tones); 00297 } 00298 /* next item */ 00299 country = strsep(&c,","); 00300 } 00301 } else { 00302 /* add tone to country */ 00303 struct tone_zone_sound *ps,*ts; 00304 for (ps=NULL,ts=tones->tones; ts; ps=ts, ts=ts->next) { 00305 if (strcasecmp(v->name,ts->name)==0) { 00306 /* already there */ 00307 ast_log(LOG_NOTICE,"Duplicate entry '%s', skipped.\n",v->name); 00308 goto out; 00309 } 00310 } 00311 /* not there, add it to the back */ 00312 if (!(ts = ast_malloc(sizeof(*ts)))) { 00313 ast_config_destroy(cfg); 00314 return -1; 00315 } 00316 ts->next = NULL; 00317 ts->name = strdup(v->name); 00318 ts->data = strdup(v->value); 00319 if (ps) 00320 ps->next = ts; 00321 else 00322 tones->tones = ts; 00323 } 00324 out: v = v->next; 00325 } 00326 if (tones->description[0] || tones->alias[0] || tones->tones) { 00327 if (ast_register_indication_country(tones)) { 00328 ast_log(LOG_WARNING, "Unable to register indication at line %d.\n",v->lineno); 00329 free(tones); 00330 } 00331 } else free(tones); 00332 00333 cxt = ast_category_browse(cfg, cxt); 00334 } 00335 00336 /* determine which country is the default */ 00337 country = ast_variable_retrieve(cfg,"general","country"); 00338 if (!country || !*country || ast_set_indication_country(country)) 00339 ast_log(LOG_WARNING,"Unable to set the default country (for indication tones)\n"); 00340 00341 ast_config_destroy(cfg); 00342 return 0; 00343 }
static int load_module | ( | void | ) | [static] |
Definition at line 383 of file res_indications.c.
References ast_cli_register_multiple(), AST_MODULE_LOAD_DECLINE, ast_register_application(), handle_playtones(), handle_stopplaytones(), and ind_load_module().
00384 { 00385 if (ind_load_module()) 00386 return AST_MODULE_LOAD_DECLINE; 00387 ast_cli_register_multiple(cli_indications, sizeof(cli_indications) / sizeof(struct ast_cli_entry)); 00388 ast_register_application("PlayTones", handle_playtones, "Play a tone list", playtones_desc); 00389 ast_register_application("StopPlayTones", handle_stopplaytones, "Stop playing a tone list","Stop playing a tone list"); 00390 00391 return 0; 00392 }
static int reload | ( | void | ) | [static] |
Definition at line 394 of file res_indications.c.
References ast_unregister_indication_country(), and ind_load_module().
00395 { 00396 /* remove the registed indications... */ 00397 ast_unregister_indication_country(NULL); 00398 00399 return ind_load_module(); 00400 }
static int unload_module | ( | void | ) | [static] |
Definition at line 370 of file res_indications.c.
References ast_cli_unregister_multiple(), ast_unregister_application(), and ast_unregister_indication_country().
00371 { 00372 /* remove the registed indications... */ 00373 ast_unregister_indication_country(NULL); 00374 00375 /* and the functions */ 00376 ast_cli_unregister_multiple(cli_indications, sizeof(cli_indications) / sizeof(struct ast_cli_entry)); 00377 ast_unregister_application("PlayTones"); 00378 ast_unregister_application("StopPlayTones"); 00379 return 0; 00380 }
struct ast_cli_entry cli_indications[] [static] |
Definition at line 353 of file res_indications.c.
struct ast_cli_entry cli_show_indications_deprecated [static] |
Initial value:
{ { "show", "indications", NULL }, handle_show_indications, NULL, NULL }
Definition at line 348 of file res_indications.c.
const char config[] = "indications.conf" [static] |
Definition at line 53 of file res_indications.c.
char help_add_indication[] [static] |
Initial value:
"Usage: indication add <country> <indication> \"<tonelist>\"\n" " Add the given indication to the country.\n"
Definition at line 58 of file res_indications.c.
char help_remove_indication[] [static] |
Initial value:
"Usage: indication remove <country> <indication>\n" " Remove the given indication from the country.\n"
Definition at line 62 of file res_indications.c.
char help_show_indications[] [static] |
Initial value:
"Usage: indication show [<country> ...]\n" " Display either a condensed for of all country/indications, or the\n" " indications for the specified countries.\n"
Definition at line 66 of file res_indications.c.
char* playtones_desc |
Definition at line 71 of file res_indications.c.