Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

indications.c File Reference

#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_item
struct  playtones_def
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_zoneast_get_indication_zone (const char *country)
tone_zone_soundast_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_zonetone_zones
ast_mutex_t tzlock = AST_MUTEX_INITIALIZER


Function Documentation

struct tone_zone_sound* ast_get_indication_tone const struct tone_zone zone,
const char *  indication
 

Definition at line 286 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().

00287 {
00288    struct tone_zone_sound *ts;
00289 
00290    /* we need some tonezone, pick the first */
00291    if (zone == NULL && current_tonezone)
00292       zone = current_tonezone;   /* default country? */
00293    if (zone == NULL && tone_zones)
00294       zone = tone_zones;      /* any country? */
00295    if (zone == NULL)
00296       return 0;   /* not a single country insight */
00297 
00298    if (ast_mutex_lock(&tzlock)) {
00299       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00300       return 0;
00301    }
00302    for (ts=zone->tones; ts; ts=ts->next) {
00303       if (strcasecmp(indication,ts->name)==0) {
00304          /* found indication! */
00305          ast_mutex_unlock(&tzlock);
00306          return ts;
00307       }
00308    }
00309    /* nothing found, sorry */
00310    ast_mutex_unlock(&tzlock);
00311    return 0;
00312 }

struct tone_zone* ast_get_indication_zone const char *  country  ) 
 

Definition at line 248 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().

00249 {
00250    struct tone_zone *tz;
00251    int alias_loop = 0;
00252 
00253    /* we need some tonezone, pick the first */
00254    if (country == NULL && current_tonezone)
00255       return current_tonezone;   /* default country? */
00256    if (country == NULL && tone_zones)
00257       return tone_zones;      /* any country? */
00258    if (country == NULL)
00259       return 0;   /* not a single country insight */
00260 
00261    if (ast_mutex_lock(&tzlock)) {
00262       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00263       return 0;
00264    }
00265    do {
00266       for (tz=tone_zones; tz; tz=tz->next) {
00267          if (strcasecmp(country,tz->country)==0) {
00268             /* tone_zone found */
00269             if (tz->alias && tz->alias[0]) {
00270                country = tz->alias;
00271                break;
00272             }
00273             ast_mutex_unlock(&tzlock);
00274             return tz;
00275          }
00276       }
00277    } while (++alias_loop<20 && tz);
00278    ast_mutex_unlock(&tzlock);
00279    if (alias_loop==20)
00280       ast_log(LOG_NOTICE,"Alias loop for '%s' forcefull broken\n",country);
00281    /* nothing found, sorry */
00282    return 0;
00283 }

int ast_playtones_start struct ast_channel chan,
int  vol,
const char *  playlst,
int  interruptible
 

Definition at line 147 of file indications.c.

References ast_activate_generator(), ast_log(), playtones_item::duration, free, playtones_item::freq1, playtones_item::freq2, playtones_def::interruptible, playtones_def::items, LOG_WARNING, playtones_item::modulate, ast_channel::name, playtones_def::nitems, realloc, playtones_def::reppos, s, and playtones_def::vol.

Referenced by ast_indicate().

00148 {
00149    char *s, *data = ast_strdupa(playlst); /* cute */
00150    struct playtones_def d = { vol, -1, 0, 1, NULL};
00151    char *stringp=NULL;
00152    char *separator;
00153    if (!data)
00154       return -1;
00155    if (vol < 1)
00156       d.vol = 8192;
00157 
00158    d.interruptible = interruptible;
00159    
00160    stringp=data;
00161    /* the stringp/data is not null here */
00162    /* check if the data is separated with '|' or with ',' by default */
00163    if (strchr(stringp,'|'))
00164       separator = "|";
00165    else
00166       separator = ",";
00167    s = strsep(&stringp,separator);
00168         while(s && *s) {
00169       int freq1, freq2, time, modulate=0;
00170 
00171       if (s[0]=='!')
00172          s++;
00173       else if (d.reppos == -1)
00174          d.reppos = d.nitems;
00175       if (sscanf(s, "%d+%d/%d", &freq1, &freq2, &time) == 3) {
00176          /* f1+f2/time format */
00177       } else if (sscanf(s, "%d+%d", &freq1, &freq2) == 2) {
00178          /* f1+f2 format */
00179          time = 0;
00180       } else if (sscanf(s, "%d*%d/%d", &freq1, &freq2, &time) == 3) {
00181          /* f1*f2/time format */
00182          modulate = 1;
00183       } else if (sscanf(s, "%d*%d", &freq1, &freq2) == 2) {
00184          /* f1*f2 format */
00185          time = 0;
00186          modulate = 1;
00187       } else if (sscanf(s, "%d/%d", &freq1, &time) == 2) {
00188          /* f1/time format */
00189          freq2 = 0;
00190       } else if (sscanf(s, "%d", &freq1) == 1) {
00191          /* f1 format */
00192          freq2 = 0;
00193          time = 0;
00194       } else {
00195          ast_log(LOG_WARNING,"%s: tone component '%s' of '%s' is no good\n",chan->name,s,playlst);
00196          return -1;
00197       }
00198 
00199       d.items = realloc(d.items,(d.nitems+1)*sizeof(struct playtones_item));
00200       if (d.items == NULL)
00201          return -1;
00202       d.items[d.nitems].freq1    = freq1;
00203       d.items[d.nitems].freq2    = freq2;
00204       d.items[d.nitems].duration = time;
00205       d.items[d.nitems].modulate = modulate;
00206       d.nitems++;
00207 
00208       s = strsep(&stringp,separator);
00209    }
00210 
00211    if (ast_activate_generator(chan, &playtones, &d)) {
00212       free(d.items);
00213       return -1;
00214    }
00215    return 0;
00216 }

void ast_playtones_stop struct ast_channel chan  ) 
 

Stop the tones from playing

Definition at line 218 of file indications.c.

References ast_deactivate_generator().

Referenced by ast_indicate().

00219 {
00220    ast_deactivate_generator(chan);
00221 }

int ast_register_indication struct tone_zone zone,
const char *  indication,
const char *  tonelist
 

Definition at line 417 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.

00418 {
00419    struct tone_zone_sound *ts,*ps;
00420 
00421    /* is it an alias? stop */
00422    if (zone->alias[0])
00423       return -1;
00424 
00425    if (ast_mutex_lock(&tzlock)) {
00426       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00427       return -2;
00428    }
00429    for (ps=NULL,ts=zone->tones; ts; ps=ts,ts=ts->next) {
00430       if (strcasecmp(indication,ts->name)==0) {
00431          /* indication already there, replace */
00432          free((void*)ts->name);
00433          free((void*)ts->data);
00434          break;
00435       }
00436    }
00437    if (!ts) {
00438       /* not there, we have to add */
00439       ts = malloc(sizeof(struct tone_zone_sound));
00440       if (!ts) {
00441          ast_log(LOG_WARNING, "Out of memory\n");
00442          ast_mutex_unlock(&tzlock);
00443          return -2;
00444       }
00445       ts->next = NULL;
00446    }
00447    ts->name = strdup(indication);
00448    ts->data = strdup(tonelist);
00449    if (ts->name==NULL || ts->data==NULL) {
00450       ast_log(LOG_WARNING, "Out of memory\n");
00451       ast_mutex_unlock(&tzlock);
00452       return -2;
00453    }
00454    if (ps)
00455       ps->next = ts;
00456    else
00457       zone->tones = ts;
00458    ast_mutex_unlock(&tzlock);
00459    return 0;
00460 }

int ast_register_indication_country struct tone_zone zone  ) 
 

Definition at line 332 of file indications.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_verbose(), tone_zone::country, LOG_WARNING, tone_zone::next, option_verbose, tone_zones, tzlock, and VERBOSE_PREFIX_3.

00333 {
00334    struct tone_zone *tz,*pz;
00335 
00336    if (ast_mutex_lock(&tzlock)) {
00337       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00338       return -1;
00339    }
00340    for (pz=NULL,tz=tone_zones; tz; pz=tz,tz=tz->next) {
00341       if (strcasecmp(zone->country,tz->country)==0) {
00342          /* tone_zone already there, replace */
00343          zone->next = tz->next;
00344          if (pz)
00345             pz->next = zone;
00346          else
00347             tone_zones = zone;
00348          /* if we are replacing the default zone, re-point it */
00349          if (tz == current_tonezone)
00350             current_tonezone = zone;
00351          /* now free the previous zone */
00352          free_zone(tz);
00353          ast_mutex_unlock(&tzlock);
00354          return 0;
00355       }
00356    }
00357    /* country not there, add */
00358    zone->next = NULL;
00359    if (pz)
00360       pz->next = zone;
00361    else
00362       tone_zones = zone;
00363    ast_mutex_unlock(&tzlock);
00364 
00365    if (option_verbose > 2)
00366       ast_verbose(VERBOSE_PREFIX_3 "Registered indication country '%s'\n",zone->country);
00367    return 0;
00368 }

int ast_set_indication_country const char *  country  ) 
 

Definition at line 233 of file indications.c.

References ast_get_indication_zone(), ast_verbose(), option_verbose, and VERBOSE_PREFIX_3.

00234 {
00235    if (country) {
00236       struct tone_zone *z = ast_get_indication_zone(country);
00237       if (z) {
00238          if (option_verbose > 2)
00239             ast_verbose(VERBOSE_PREFIX_3 "Setting default indication country to '%s'\n",country);
00240          current_tonezone = z;
00241          return 0;
00242       }
00243    }
00244    return 1; /* not found */
00245 }

int ast_unregister_indication struct tone_zone zone,
const char *  indication
 

Definition at line 463 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.

00464 {
00465    struct tone_zone_sound *ts,*ps = NULL, *tmp;
00466    int res = -1;
00467 
00468    /* is it an alias? stop */
00469    if (zone->alias[0])
00470       return -1;
00471 
00472    if (ast_mutex_lock(&tzlock)) {
00473       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00474       return -1;
00475    }
00476    ts = zone->tones;
00477    while (ts) {
00478       if (strcasecmp(indication,ts->name)==0) {
00479          /* indication found */
00480          tmp = ts->next;
00481          if (ps)
00482             ps->next = tmp;
00483          else
00484             zone->tones = tmp;
00485          free((void*)ts->name);
00486          free((void*)ts->data);
00487          free(ts);
00488          ts = tmp;
00489          res = 0;
00490       }
00491       else {
00492          /* next zone please */
00493          ps = ts;
00494          ts = ts->next;
00495       }
00496    }
00497    /* indication not found, goodbye */
00498    ast_mutex_unlock(&tzlock);
00499    return res;
00500 }

int ast_unregister_indication_country const char *  country  ) 
 

Definition at line 372 of file indications.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_verbose(), LOG_NOTICE, LOG_WARNING, tone_zone::next, option_verbose, tone_zones, tzlock, and VERBOSE_PREFIX_3.

00373 {
00374    struct tone_zone *tz, *pz = NULL, *tmp;
00375    int res = -1;
00376 
00377    if (ast_mutex_lock(&tzlock)) {
00378       ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
00379       return -1;
00380    }
00381    tz = tone_zones;
00382    while (tz) {
00383       if (country==NULL ||
00384           (strcasecmp(country, tz->country)==0 ||
00385            strcasecmp(country, tz->alias)==0)) {
00386          /* tone_zone found, remove */
00387          tmp = tz->next;
00388          if (pz)
00389             pz->next = tmp;
00390          else
00391             tone_zones = tmp;
00392          /* if we are unregistering the default country, w'll notice */
00393          if (tz == current_tonezone) {
00394             ast_log(LOG_NOTICE,"Removed default indication country '%s'\n",tz->country);
00395             current_tonezone = NULL;
00396          }
00397          if (option_verbose > 2)
00398             ast_verbose(VERBOSE_PREFIX_3 "Unregistered indication country '%s'\n",tz->country);
00399          free_zone(tz);
00400          if (tone_zones == tz)
00401             tone_zones = tmp;
00402          tz = tmp;
00403          res = 0;
00404       }
00405       else {
00406          /* next zone please */
00407          pz = tz;
00408          tz = tz->next;
00409       }
00410    }
00411    ast_mutex_unlock(&tzlock);
00412    return res;
00413 }


Variable Documentation

struct tone_zone* tone_zones
 

Definition at line 225 of file indications.c.

Referenced by ast_get_indication_tone(), ast_get_indication_zone(), ast_register_indication_country(), and ast_unregister_indication_country().

ast_mutex_t tzlock = AST_MUTEX_INITIALIZER
 

Definition at line 230 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().


Generated on Sun Apr 18 23:34:06 2004 for Asterisk by doxygen 1.3.6-20040222