#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <string.h>#include <math.h>#include <asterisk/indications.h>#include <asterisk/frame.h>#include <asterisk/options.h>#include <asterisk/channel.h>#include <asterisk/logger.h>Go to the source code of this file.
Data Structures | |
| struct | playtones_def |
| struct | playtones_item |
| struct | playtones_state |
Functions | |
| int | ast_playtones_start (struct ast_channel *chan, int vol, const char *playlst, int interruptible) |
| void | ast_playtones_stop (struct ast_channel *chan) |
| int | ast_set_indication_country (const char *country) |
| tone_zone * | ast_get_indication_zone (const char *country) |
| tone_zone_sound * | ast_get_indication_tone (const struct tone_zone *zone, const char *indication) |
| int | ast_register_indication_country (struct tone_zone *zone) |
| int | ast_unregister_indication_country (const char *country) |
| int | ast_register_indication (struct tone_zone *zone, const char *indication, const char *tonelist) |
| int | ast_unregister_indication (struct tone_zone *zone, const char *indication) |
Variables | |
| tone_zone * | tone_zones |
| ast_mutex_t | tzlock = AST_MUTEX_INITIALIZER |
|
||||||||||||
|
Definition at line 268 of file indications.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, LOG_WARNING, tone_zone_sound::next, tone_zones, tone_zone::tones, and tzlock. Referenced by ast_indicate().
00269 {
00270 struct tone_zone_sound *ts;
00271
00272 /* we need some tonezone, pick the first */
00273 if (zone == NULL && current_tonezone)
00274 zone = current_tonezone; /* default country? */
00275 if (zone == NULL && tone_zones)
00276 zone = tone_zones; /* any country? */
00277 if (zone == NULL)
00278 return 0; /* not a single country insight */
00279
00280 if (ast_mutex_lock(&tzlock)) {
00281 ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00282 return 0;
00283 }
00284 for (ts=zone->tones; ts; ts=ts->next) {
00285 if (strcasecmp(indication,ts->name)==0) {
00286 /* found indication! */
00287 ast_mutex_unlock(&tzlock);
00288 return ts;
00289 }
00290 }
00291 /* nothing found, sorry */
00292 ast_mutex_unlock(&tzlock);
00293 return 0;
00294 }
|
|
|
Definition at line 230 of file indications.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, LOG_NOTICE, LOG_WARNING, tone_zone::next, tone_zones, and tzlock. Referenced by ast_set_indication_country().
00231 {
00232 struct tone_zone *tz;
00233 int alias_loop = 0;
00234
00235 /* we need some tonezone, pick the first */
00236 if (country == NULL && current_tonezone)
00237 return current_tonezone; /* default country? */
00238 if (country == NULL && tone_zones)
00239 return tone_zones; /* any country? */
00240 if (country == NULL)
00241 return 0; /* not a single country insight */
00242
00243 if (ast_mutex_lock(&tzlock)) {
00244 ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00245 return 0;
00246 }
00247 do {
00248 for (tz=tone_zones; tz; tz=tz->next) {
00249 if (strcasecmp(country,tz->country)==0) {
00250 /* tone_zone found */
00251 if (tz->alias && tz->alias[0]) {
00252 country = tz->alias;
00253 break;
00254 }
00255 ast_mutex_unlock(&tzlock);
00256 return tz;
00257 }
00258 }
00259 } while (++alias_loop<20 && tz);
00260 ast_mutex_unlock(&tzlock);
00261 if (alias_loop==20)
00262 ast_log(LOG_NOTICE,"Alias loop for '%s' forcefull broken\n",country);
00263 /* nothing found, sorry */
00264 return 0;
00265 }
|
|
||||||||||||||||||||
|
Definition at line 138 of file indications.c. References ast_activate_generator(), ast_log(), free, playtones_def::interruptible, playtones_def::items, LOG_WARNING, ast_channel::name, playtones_def::nitems, realloc, playtones_def::reppos, and playtones_def::vol. Referenced by ast_indicate().
00139 {
00140 char *s, *data = ast_strdupa(playlst); /* cute */
00141 struct playtones_def d = { vol, -1, 0, 1, NULL};
00142 char *stringp=NULL;
00143 char *separator;
00144 if (!data)
00145 return -1;
00146 if (vol < 1)
00147 d.vol = 8192;
00148
00149 d.interruptible = interruptible;
00150
00151 stringp=data;
00152 /* the stringp/data is not null here */
00153 /* check if the data is separated with '|' or with ',' by default */
00154 if (strchr(stringp,'|'))
00155 separator = "|";
00156 else
00157 separator = ",";
00158 s = strsep(&stringp,separator);
00159 while(s && *s) {
00160 int freq1, freq2, time;
00161
00162 if (s[0]=='!')
00163 s++;
00164 else if (d.reppos == -1)
00165 d.reppos = d.nitems;
00166 if (sscanf(s, "%d+%d/%d", &freq1, &freq2, &time) == 3) {
00167 /* f1+f2/time format */
00168 } else if (sscanf(s, "%d+%d", &freq1, &freq2) == 2) {
00169 /* f1+f2 format */
00170 time = 0;
00171 } else if (sscanf(s, "%d/%d", &freq1, &time) == 2) {
00172 /* f1/time format */
00173 freq2 = 0;
00174 } else if (sscanf(s, "%d", &freq1) == 1) {
00175 /* f1 format */
00176 freq2 = 0;
00177 time = 0;
00178 } else {
00179 ast_log(LOG_WARNING,"%s: tone component '%s' of '%s' is no good\n",chan->name,s,playlst);
00180 return -1;
00181 }
00182
00183 d.items = realloc(d.items,(d.nitems+1)*sizeof(struct playtones_item));
00184 if (d.items == NULL)
00185 return -1;
00186 d.items[d.nitems].freq1 = freq1;
00187 d.items[d.nitems].freq2 = freq2;
00188 d.items[d.nitems].duration = time;
00189 d.nitems++;
00190
00191 s = strsep(&stringp,separator);
00192 }
00193
00194 if (ast_activate_generator(chan, &playtones, &d)) {
00195 free(d.items);
00196 return -1;
00197 }
00198 return 0;
00199 }
|
|
|
Stop the tones from playing Definition at line 201 of file indications.c. References ast_deactivate_generator(). Referenced by ast_indicate().
00202 {
00203 ast_deactivate_generator(chan);
00204 }
|
|
||||||||||||||||
|
Definition at line 393 of file indications.c. References tone_zone::alias, ast_log(), ast_mutex_lock, ast_mutex_unlock, free, LOG_WARNING, malloc, tone_zone_sound::next, strdup, tone_zone::tones, and tzlock.
00394 {
00395 struct tone_zone_sound *ts,*ps;
00396
00397 /* is it an alias? stop */
00398 if (zone->alias[0])
00399 return -1;
00400
00401 if (ast_mutex_lock(&tzlock)) {
00402 ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00403 return -2;
00404 }
00405 for (ps=NULL,ts=zone->tones; ts; ps=ts,ts=ts->next) {
00406 if (strcasecmp(indication,ts->name)==0) {
00407 /* indication already there, replace */
00408 free((void*)ts->name);
00409 free((void*)ts->data);
00410 break;
00411 }
00412 }
00413 if (!ts) {
00414 /* not there, we have to add */
00415 ts = malloc(sizeof(struct tone_zone_sound));
00416 if (!ts) {
00417 ast_log(LOG_WARNING, "Out of memory\n");
00418 ast_mutex_unlock(&tzlock);
00419 return -2;
00420 }
00421 ts->next = NULL;
00422 }
00423 ts->name = strdup(indication);
00424 ts->data = strdup(tonelist);
00425 if (ts->name==NULL || ts->data==NULL) {
00426 ast_log(LOG_WARNING, "Out of memory\n");
00427 ast_mutex_unlock(&tzlock);
00428 return -2;
00429 }
00430 if (ps)
00431 ps->next = ts;
00432 else
00433 zone->tones = ts;
00434 ast_mutex_unlock(&tzlock);
00435 return 0;
00436 }
|
|
|
Definition at line 312 of file indications.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_verbose(), tone_zone::country, LOG_WARNING, tone_zone::next, tone_zones, tzlock, and VERBOSE_PREFIX_3.
00313 {
00314 struct tone_zone *tz,*pz;
00315
00316 if (ast_mutex_lock(&tzlock)) {
00317 ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00318 return -1;
00319 }
00320 for (pz=NULL,tz=tone_zones; tz; pz=tz,tz=tz->next) {
00321 if (strcasecmp(zone->country,tz->country)==0) {
00322 /* tone_zone already there, replace */
00323 zone->next = tz->next;
00324 if (pz)
00325 pz->next = zone;
00326 else
00327 tone_zones = zone;
00328 /* if we are replacing the default zone, re-point it */
00329 if (tz == current_tonezone)
00330 current_tonezone = zone;
00331 /* now free the previous zone */
00332 free_zone(tz);
00333 ast_mutex_unlock(&tzlock);
00334 return 0;
00335 }
00336 }
00337 /* country not there, add */
00338 zone->next = NULL;
00339 if (pz)
00340 pz->next = zone;
00341 else
00342 tone_zones = zone;
00343 ast_mutex_unlock(&tzlock);
00344
00345 ast_verbose(VERBOSE_PREFIX_3 "Registered indication country '%s'\n",zone->country);
00346 return 0;
00347 }
|
|
|
Definition at line 216 of file indications.c. References ast_get_indication_zone(), ast_verbose(), and VERBOSE_PREFIX_3.
00217 {
00218 if (country) {
00219 struct tone_zone *z = ast_get_indication_zone(country);
00220 if (z) {
00221 ast_verbose(VERBOSE_PREFIX_3 "Setting default indication country to '%s'\n",country);
00222 current_tonezone = z;
00223 return 0;
00224 }
00225 }
00226 return 1; /* not found */
00227 }
|
|
||||||||||||
|
Definition at line 439 of file indications.c. References tone_zone::alias, ast_log(), ast_mutex_lock, ast_mutex_unlock, free, LOG_WARNING, tone_zone_sound::next, tone_zone::tones, and tzlock.
00440 {
00441 struct tone_zone_sound *ts,*ps = NULL, *tmp;
00442 int res = -1;
00443
00444 /* is it an alias? stop */
00445 if (zone->alias[0])
00446 return -1;
00447
00448 if (ast_mutex_lock(&tzlock)) {
00449 ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00450 return -1;
00451 }
00452 ts = zone->tones;
00453 while (ts) {
00454 if (strcasecmp(indication,ts->name)==0) {
00455 /* indication found */
00456 tmp = ts->next;
00457 if (ps)
00458 ps->next = tmp;
00459 else
00460 zone->tones = tmp;
00461 free((void*)ts->name);
00462 free((void*)ts->data);
00463 free(ts);
00464 ts = tmp;
00465 res = 0;
00466 }
00467 else {
00468 /* next zone please */
00469 ps = ts;
00470 ts = ts->next;
00471 }
00472 }
00473 /* indication not found, goodbye */
00474 ast_mutex_unlock(&tzlock);
00475 return res;
00476 }
|
|
|
Definition at line 351 of file indications.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_verbose(), LOG_NOTICE, LOG_WARNING, tone_zone::next, tone_zones, tzlock, and VERBOSE_PREFIX_3.
00352 {
00353 struct tone_zone *tz, *pz = NULL, *tmp;
00354 int res = -1;
00355
00356 if (ast_mutex_lock(&tzlock)) {
00357 ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00358 return -1;
00359 }
00360 tz = tone_zones;
00361 while (tz) {
00362 if (country==NULL ||
00363 (strcasecmp(country, tz->country)==0 ||
00364 strcasecmp(country, tz->alias)==0)) {
00365 /* tone_zone found, remove */
00366 tmp = tz->next;
00367 if (pz)
00368 pz->next = tmp;
00369 else
00370 tone_zones = tmp;
00371 /* if we are unregistering the default country, w'll notice */
00372 if (tz == current_tonezone) {
00373 ast_log(LOG_NOTICE,"Removed default indication country '%s'\n",tz->country);
00374 current_tonezone = NULL;
00375 }
00376 ast_verbose(VERBOSE_PREFIX_3 "Unregistered indication country '%s'\n",tz->country);
00377 free_zone(tz);
00378 tz = tmp;
00379 res = 0;
00380 }
00381 else {
00382 /* next zone please */
00383 pz = tz;
00384 tz = tz->next;
00385 }
00386 }
00387 ast_mutex_unlock(&tzlock);
00388 return res;
00389 }
|
|
|
Definition at line 208 of file indications.c. Referenced by ast_get_indication_tone(), ast_get_indication_zone(), ast_register_indication_country(), and ast_unregister_indication_country(). |
|
|
Definition at line 213 of file indications.c. Referenced by ast_get_indication_tone(), ast_get_indication_zone(), ast_register_indication(), ast_register_indication_country(), ast_unregister_indication(), and ast_unregister_indication_country(). |
1.3.4