Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

bayonne.h

Go to the documentation of this file.
00001 // Copyright (C) 2000 Open Source Telecom Corporation.
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 // 
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 
00017 #ifndef __CCXX_BAYONNE_H__
00018 #define __CCXX_BAYONNE_H__
00019 
00020 #ifndef __CCXX_SCRIPT_H__
00021 #include <cc++/script.h>
00022 #endif
00023 
00024 #ifndef __CCXX_SLOG_H__
00025 #include <cc++/slog.h>
00026 #endif
00027 
00028 #ifndef __CCXX_DSO_H__
00029 #include <cc++/file.h>
00030 #endif
00031 
00032 #ifndef __CCXX_SOCKET_H__
00033 #include <cc++/socket.h>
00034 #endif
00035 
00036 #ifndef __CCXX_AUDIO_H__
00037 #include <cc++/audio.h>
00038 #endif
00039 
00040 #include <stdlib.h>
00041 
00042 #ifdef  __FreeBSD__
00043 #undef  read
00044 #undef  write
00045 #undef  readv
00046 #undef  writev
00047 #endif
00048 
00049 #ifndef COMMON_TPPORT_TYPE_DEFINED
00050 typedef short   tpport_t;
00051 #endif
00052 
00053 /* Bayonne uses a universal event record for all driver plugins and
00054    state handlers.  Not all drivers impliment the entire set of events
00055    and some drivers have specific events associated with their unique
00056    characteristcs.  However, most events are considered "universal".
00057 */
00058 
00059 class Trunk;
00060 class Service;
00061 class phTone;
00062 class TrunkGroup;
00063 class Module;
00064 
00065 typedef enum
00066 {
00067         SELECT_FIRST,
00068         SELECT_LAST
00069 } seltype_t;
00070 
00071 typedef enum {
00072         MODULE_GENERIC,
00073         MODULE_DELIVERY,
00074         MODULE_SENDFILE,
00075         MODULE_SENDFAX,
00076         MODULE_NOTIFY,
00077         MODULE_TGI,
00078         MODULE_ANY
00079 }       modtype_t;
00080 
00081 typedef enum {
00082         // step change requests
00083         TRUNK_STEP_HANGUP = 0,
00084         TRUNK_STEP_SLEEP,
00085         TRUNK_STEP_ANSWER,
00086         TRUNK_STEP_COLLECT,
00087         TRUNK_STEP_PLAY,
00088         TRUNK_STEP_RECORD,
00089         TRUNK_STEP_TONE,
00090         TRUNK_STEP_DIALXFER,
00091         TRUNK_STEP_FLASH,
00092         TRUNK_STEP_JOIN,
00093         TRUNK_STEP_RTP,
00094         TRUNK_STEP_DUPLEX,
00095         TRUNK_STEP_DETECT,
00096         TRUNK_STEP_REQUIRES,
00097         TRUNK_STEP_EXIT = TRUNK_STEP_HANGUP,
00098         TRUNK_STEP_DRIVER
00099 } trunkstep_t;
00100 
00101 typedef enum {
00102         // notify script from state handler
00103         TRUNK_SIGNAL_STEP = 0,
00104         TRUNK_SIGNAL_EXIT,
00105         TRUNK_SIGNAL_HANGUP=TRUNK_SIGNAL_EXIT,
00106         TRUNK_SIGNAL_ERROR,
00107         TRUNK_SIGNAL_TIMEOUT,
00108         TRUNK_SIGNAL_DTMF,
00109         TRUNK_SIGNAL_0,
00110         TRUNK_SIGNAL_1,
00111         TRUNK_SIGNAL_2,
00112         TRUNK_SIGNAL_3,
00113         TRUNK_SIGNAL_4,
00114         TRUNK_SIGNAL_5,
00115         TRUNK_SIGNAL_6,
00116         TRUNK_SIGNAL_7,
00117         TRUNK_SIGNAL_8,
00118         TRUNK_SIGNAL_9,
00119         TRUNK_SIGNAL_STAR,
00120         TRUNK_SIGNAL_POUND,
00121         TRUNK_SIGNAL_A,
00122         TRUNK_SIGNAL_B,
00123         TRUNK_SIGNAL_C,
00124         TRUNK_SIGNAL_D,
00125         TRUNK_SIGNAL_DIALTONE,
00126         TRUNK_SIGNAL_BUSY,
00127         TRUNK_SIGNAL_CANCEL,
00128         TRUNK_SIGNAL_SIGNAL,
00129         TRUNK_SIGNAL_DRIVER
00130 }       trunksignal_t;
00131 
00132 typedef enum {
00133         // primary state handlers
00134 
00135         TRUNK_ENTER_STATE = 100,// newly entered handler state
00136         TRUNK_EXIT_STATE,       // exiting prior state (unused)
00137         TRUNK_STOP_STATE,       // request state termination
00138         TRUNK_NOTIFICATION,     // death notify event
00139         TRUNK_SERVICE_SUCCESS,  // service completion successful
00140         TRUNK_SERVICE_FAILURE,  // service completion failed
00141         TRUNK_SERVICE_LOOKUP,   // lookup transaction
00142         TRUNK_SERVICE_LOGIN,    // login transaction
00143         TRUNK_SIGNAL_NOTIFY,    // signal between trunks
00144         TRUNK_JOIN_TRUNKS,      // join two trunks together
00145         TRUNK_PART_TRUNKS,      // split two trunks that were joined
00146         TRUNK_NULL_EVENT,       // used to push pipe driven systems
00147 
00148         // tgi/integration control state handlers
00149 
00150         TRUNK_EXIT_SHELL = 200, // tgi completion event
00151         TRUNK_START_SCRIPT,     // start of script
00152         TRUNK_RING_START,       // smdi/integrated answer
00153         TRUNK_RING_REDIRECT,    // smdi/integrated answer options
00154         TRUNK_STOP_DISCONNECT,  // integrated hangup notification
00155 
00156         // in the future these will be used
00157 
00158         TRUNK_START_INCOMING = TRUNK_RING_START,
00159         TRUNK_START_OUTGOING = TRUNK_START_SCRIPT,
00160 
00161         // primary "mode" selection controls
00162 
00163         TRUNK_MAKE_TEST =  300, // request driver perform line test
00164         TRUNK_MAKE_BUSY,        // request driver lockout line
00165         TRUNK_MAKE_IDLE,        // request driver reset line
00166         TRUNK_MAKE_STEP,        // pass step event internally
00167 
00168         // basic trunk events
00169 
00170         TRUNK_LINE_WINK = 400,  // used for line disconnect notification
00171         TRUNK_TIMER_EXPIRED,    // driver specific port timer expired
00172         TRUNK_RINGING_ON,       // some drivers distinguish start/stop
00173         TRUNK_RINGING_OFF,      // default ring event
00174         TRUNK_TEST_IDLE,        // some drivers have line test completion
00175         TRUNK_TEST_FAILURE,     // some drivers notify errors
00176         TRUNK_ON_HOOK,          // some drivers notify on hook
00177         TRUNK_OFF_HOOK,         // some drivers notify off hook
00178         TRUNK_CALLER_ID,        // caller id parse request
00179         TRUNK_RINGING_DID,      // did digit ring signal
00180         TRUNK_CALL_DETECT,      // ISDN call detected notification
00181         TRUNK_CALL_CONNECT,     // ISDN call connection notification
00182         TRUNK_CALL_RELEASE,     // ISDN call release notification
00183         TRUNK_CALL_ACCEPT,      // ISDN incoming call accepted
00184         TRUNK_CALL_RINGING,     // digital T1 incoming call
00185         TRUNK_CALL_DISCONNECT,  // digital T1 circuit break
00186 
00187         // basic audio processing events
00188 
00189         TRUNK_AUDIO_IDLE = 500, // audio reset or completion event
00190         TRUNK_INPUT_PENDING,    // some drivers monitor audio i/o status
00191         TRUNK_OUTPUT_PENDING,   // some drivers monitor audio i/p status
00192         TRUNK_AUDIO_BUFFER,     // some drivers return audio buffers
00193         TRUNK_TONE_IDLE,        // tone generator completion event
00194         TRUNK_DTMF_KEYDOWN,     // some drivers distinguish tone down
00195         TRUNK_DTMF_KEYUP,       // default dtmf event
00196         TRUNK_TONE_START,       // tone detected
00197         TRUNK_TONE_STOP,        // some drivers have tone completion event
00198         TRUNK_FSK_DETECT,       // fsk tone detect
00199         TRUNK_FAX_DETECT,       // fax tone detect
00200         TRUNK_VOX_DETECT,       // speaker detected
00201         TRUNK_AUDIO_START,      // some drivers may "vox" compress
00202         TRUNK_AUDIO_STOP,       // some drivers may "vox" compress
00203         TRUNK_CPA_DIALTONE,     // dialtone heard on the line
00204         TRUNK_CPA_BUSYTONE,
00205         TRUNK_CPA_RINGING,
00206         TRUNK_CPA_RINGBACK = TRUNK_CPA_RINGING,
00207         TRUNK_CPA_INTERCEPT,
00208         TRUNK_CPA_NODIALTONE,
00209         TRUNK_CPA_NORINGBACK,
00210         TRUNK_CPA_NOANSWER,
00211         TRUNK_CPA_CONNECT,
00212         TRUNK_CPA_FAILURE,
00213         TRUNK_DSP_READY,        // dsp resource became available
00214 
00215         // driver specific events and anomolies
00216 
00217         TRUNK_DRIVER_SPECIFIC=8000      // very oddball events
00218 } trunkevent_t;
00219 
00220 typedef enum
00221 {
00222         DSP_MODE_INACTIVE = 0,  // dsp is idle
00223         DSP_MODE_VOICE,         // standard voice processing
00224         DSP_MODE_CALLERID,      // caller id support
00225         DSP_MODE_DATA,          // fsk modem mode
00226         DSP_MODE_FAX,           // fax support
00227         DSP_MODE_TDM,           // TDM bus with echo cancellation
00228         DSP_MODE_RTP,           // VoIP full duplex
00229         DSP_MODE_DUPLEX,        // mixed play/record
00230         DSP_MODE_JOIN,          // support of joined channels
00231         DSP_MODE_CONF,          // in conference
00232         DSP_MODE_TONE           // tone processing
00233 } dspmode_t;
00234 
00235 typedef enum
00236 {
00237         TRUNK_MODE_INCOMING = 0,
00238         TRUNK_MODE_OUTGOING,
00239         TRUNK_MODE_INACTIVE,
00240         TRUNK_MODE_UNAVAILABLE
00241 } trunkmode_t;
00242  
00243 typedef enum
00244 {
00245         STAT_MAX_INCOMING,
00246         STAT_MAX_OUTGOING,
00247         STAT_TOT_INCOMING,
00248         STAT_TOT_OUTGOING,
00249         STAT_ACTIVE_CALLS
00250 } statitem_t;
00251 
00252 #define TRUNK_CAP_VOICE         0x00000001
00253 #define TRUNK_CAP_DIAL          0x00000002
00254 #define TRUNK_CAP_SENDFAX       0x00000004
00255 #define TRUNK_CAP_RECVFAX       0x00000008
00256 #define TRUNK_CAP_DATA          0x00000010
00257 
00258 typedef union
00259 {
00260         scriptsymbol_t sym;
00261         char data[sizeof(scriptsymbol_t) + 12];
00262 }       numbersymbol_t;
00263 
00264 typedef union
00265 {
00266         scriptsymbol_t bin;
00267         char data[sizeof(scriptsymbol_t) + 32];
00268 }       digitsymbol_t;
00269 
00270 typedef struct
00271 {
00272         
00273         int pid;
00274         unsigned seq;
00275         void *data;
00276 }       execdata_t;
00277 
00278 typedef union
00279 {
00280         struct
00281         {
00282                 int rings;
00283                 int timeout;
00284         }       answer;
00285         struct
00286         {
00287                 char list[256];
00288                 char *name;
00289                 unsigned long offset;
00290                 unsigned long limit;
00291                 unsigned char volume;
00292         }       play;
00293         struct
00294         {
00295                 char *name;
00296                 timeout_t timeout;
00297                 unsigned long offset;
00298                 unsigned short term;
00299                 unsigned char volume;
00300                 unsigned long trim;
00301                 bool append;
00302         }       record;
00303         struct
00304         {
00305                 char digits[65];
00306                 char *digit;
00307                 timeout_t interdigit;
00308                 bool exit;
00309                 timeout_t timeout;
00310         }       dialxfer;
00311         struct
00312         {
00313                 timeout_t timeout;
00314                 unsigned count;
00315                 unsigned short term;
00316                 unsigned short ignore;
00317         }       collect;
00318         struct
00319         {
00320                 timeout_t wakeup;
00321                 unsigned rings;
00322                 unsigned loops;
00323         }       sleep;
00324         struct
00325         {
00326                 timeout_t wakeup;
00327                 unsigned loops;
00328                 phTone *tone;
00329         }       tone;
00330         struct
00331         {
00332                 timeout_t wakeup;
00333                 Trunk *trunk;
00334                 phTone *tone;
00335         }       join;
00336         struct
00337         {
00338                 timeout_t offhook;
00339                 timeout_t onhook;
00340         }       flash;
00341         struct
00342         {
00343                 struct in_addr addr;
00344                 unsigned short bind, port, term;
00345                 audioencoding_t codec;
00346         }       rtp;
00347 }       trunkdata_t;
00348 
00349 typedef struct
00350 {
00351         trunkevent_t id;        // event id
00352         union
00353         {
00354                 struct
00355                 {
00356                         unsigned digit: 4;
00357                         unsigned duration: 12;
00358                         unsigned e1: 8;
00359                         unsigned e2: 8;
00360                 } dtmf;
00361                 struct
00362                 {
00363                         unsigned tone: 8;
00364                         unsigned energy: 8;
00365                         unsigned duration: 16;
00366                 } tone;
00367                 struct
00368                 {
00369                         unsigned digit:  4;
00370                         unsigned duration: 24;
00371                 } ring;
00372                 struct
00373                 {
00374                         unsigned seq;
00375                         bool result;
00376                         char *data;
00377                 } lookup;
00378                 int status;
00379                 Trunk *trunk;
00380                 void *data;
00381                 char **argv;
00382                 char *error;
00383                 timeout_t duration;
00384                 trunkstep_t step;
00385                 char dn[8];
00386                 dspmode_t dsp;
00387         } parm;
00388 } TrunkEvent;
00389 
00390 /* This is used to bind user defined "functions" which may be loaded
00391    in a DSO module.
00392 */
00393 
00394 typedef char *(*functioncall_t)(scriptsymbol_t *sym, char **args);
00395 
00396 typedef struct
00397 {
00398         char *name;
00399         functioncall_t function;
00400 } FUNCTIONS;
00401 
00402 
00410 class CallStat : public Mutex
00411 {
00412 protected:
00413         int capacity;
00414         struct
00415         {
00416                 int incoming;
00417                 int outgoing;
00418         }       active, max, lastmax;
00419 
00420         struct
00421         {
00422                 long incoming;
00423                 long outgoing;
00424         }       total, lasttotal;
00425 
00426 public:
00427         CallStat();
00428 
00434         inline int getCapacity(void)
00435                 {return capacity;};
00436 
00443         long getStat(statitem_t item);
00444 
00448         void incIncoming(void);
00449 
00453         void decIncoming(void);
00454 
00458         void incOutgoing(void);
00459 
00463         void decOutgoing(void);
00464 
00468         void Update(void);
00469 };
00470 
00483 class Translator : protected Keydata
00484 {
00485 private:
00486         friend Translator *getTranslator(char *name);
00487         static Translator *first;
00488         Translator *next;
00489 
00490 protected:
00496         virtual char *getName(void) = 0;
00497 
00504         char *getPlayBuffer(Trunk *trunk);
00505 
00506         void scanDir(const char *etcdir, const char *language, const char *lib);
00507 
00508         Translator(const char *conf, const char *lib);
00509 
00510 public:
00518         virtual char *Speak(Trunk *trunk) = 0;
00519 };
00520 
00534 class Functions
00535 {
00536 protected:
00542         virtual char *getName(void) = 0;
00543 
00549         void Load(FUNCTIONS *map);
00550 };
00551 
00552 /* Bayonne config file istanciation classes.  In Bayonne these are
00553    created as keydata objects out of bayonne.conf during process
00554    startup automatically.  This is Bayonne runtime configuration magic.
00555 */
00556 
00563 class KeyTones : protected Keydata
00564 {
00565 public:
00569         KeyTones();
00570 };
00571 
00579 class KeyLocal : public Keydata
00580 {
00581 public:
00585         KeyLocal();
00586 };
00587 
00595 class KeyPaths : public Keydata
00596 {
00597 public:
00601         KeyPaths();
00602 
00606         inline const char *getLibexec(void)
00607                 {return getLast("libexec");};
00608 
00612         inline const char *getTgipath(void)
00613                 {return getLast("tgipath");};
00614 
00618         inline const char *getLibpath(void)
00619                 {return getLast("libpath");};
00620 
00624         inline const char *getDatafiles(void)
00625                 {return getLast("datafiles");};
00626 
00630         inline const char *getRunfiles(void)
00631                 {return getLast("runfiles");};
00632 
00636         inline const char *getSpool(void)
00637                 {return getLast("spool");};
00638 
00642         inline const char *getScriptFiles(void)
00643                 {return getLast("scripts");};
00644 
00648         inline const char *getCache(void)
00649                 {return getLast("precache");};
00650 };
00651 
00659 class KeyNetwork : public Keydata
00660 {
00661 public:
00665         KeyNetwork();
00666 
00672         unsigned getRefresh(void)
00673                 {return atoi(getLast("refresh"));};
00674 
00680         unsigned getTimeToLive(void)
00681                 {return atoi(getLast("live"));};
00682 
00688         InetHostAddress getBroadcast(void);
00689 
00695         InetAddress getAddress(void);
00696 
00702         tpport_t getPort(void);
00703 
00709         InetHostAddress getDBHost(void);
00710 
00716         tpport_t getDBPort(void);
00717 };
00718 
00726 class KeyMailbox : public Keydata
00727 {
00728 public:
00732         KeyMailbox();
00733 
00739         inline unsigned getCount(void)
00740                 {return atoi(getLast("count"));};
00741 
00747         inline unsigned getLimit(void)
00748                 {return atoi(getLast("limit"));};
00749 
00756         inline unsigned getQuota(void)
00757                 {return atoi(getLast("quota"));};
00758 
00764         inline unsigned getMinimum(void)
00765                 {return atoi(getLast("minimum"));};
00766 
00772         inline unsigned getMaximum(void)
00773                 {return atoi(getLast("maximum"));};
00774 
00780         inline const char *getPassword(void)
00781                 {return getLast("password");};
00782 };
00783 
00792 class KeyMemory : public Keydata
00793 {
00794 public:
00798         KeyMemory();
00799 
00805         inline int getSymbolSize(void)
00806                 {return atoi(getLast("symbols"));};
00807 
00814         inline int getPageSize(void)
00815                 {return atoi(getLast("page"));};
00816 };
00817 
00825 class KeyFeed : public Keydata
00826 {
00827 public:
00831         KeyFeed();
00832 
00838         inline unsigned getBuffers(void)
00839                 {return atoi(getLast("buffers"));};
00840 };
00841 
00842 
00850 class KeyThreads : public Keydata
00851 {
00852 public:
00856         KeyThreads();
00857 
00863         inline int priService(void)
00864                 {return atoi(getLast("services"));};
00865 
00871         inline int priScheduler(void)
00872                 {return atoi(getLast("scheduler"));};
00873 
00879         inline int priGUI(void)
00880                 {return atoi(getLast("gui"));};
00881 
00887         inline int priRTP(void)
00888                 {return atoi(getLast("rtp"));};
00889 
00895         inline int getStepDelay(void)
00896                 {return atoi(getLast("stepdelay"));};
00897 
00903         inline int getStepInterval(void)
00904                 {return atoi(getLast("stepinterval"));};
00905 
00911         inline int getResetDelay(void)
00912                 {return atoi(getLast("resetdelay"));};
00913 
00919         size_t getStack(void);
00920 
00926         int getServices(void);
00927 
00933         int priResolver(void);
00934 
00941         int getResolver(void);
00942 
00948         inline int priAudio(void)
00949                 {return atoi(getLast("audio"));};
00950 
00956         inline int priFeed(void)
00957                 {return atoi(getLast("feed"));};
00958 
00964         inline int priGateway(void)
00965                 {return atoi(getLast("gateways"));};
00966 
00972         inline int priManager(void)
00973                 {return atoi(getLast("managers"));};
00974 
00980         inline int priNetwork(void)
00981                 {return atoi(getLast("network"));};
00982 
00988         inline int getInterval(void)
00989                 {return atoi(getLast("interval"));};
00990 
00996         inline int getRefresh(void)
00997                 {return atoi(getLast("refresh"));};
00998 
01004         int getGateways(void);
01005         
01012         inline int getPriority(void)
01013                 {return atoi(getLast("priority"));};
01014 
01020         int getPolicy(void);
01021 
01027         inline int getPages(void)
01028                 {return atoi(getLast("pages"));};
01029 };
01030 
01038 class Auditdata : public Keydata
01039 {
01040 private:
01041         friend class Audit;
01042 
01043         Auditdata();
01044 };
01045 
01055 class Request
01056 {
01057 private:
01058         friend class TrunkGroup;
01059 
01060         static unsigned seq;
01061 
01062         unsigned id;
01063         Request *next;
01064         time_t expires;
01065         TrunkGroup *group;
01066 
01067         char *argv[33];
01068         char buffer[512];
01069         char tagid[65];
01070 
01071         void Detach(void);
01072 
01073 public:
01074         Request(TrunkGroup *grp, const char *text, unsigned expire, const char *tag = NULL);
01075         ~Request()
01076                 {Detach();};
01077 
01078         inline char **getList(void)
01079                 {return argv;};
01080 
01081         inline char *getTag(void)
01082                 {return tagid;};
01083 
01084         bool isExpired(void);
01085 
01086         friend void cancel(TrunkGroup *group, const char *tag);
01087         friend Request *request(TrunkGroup *group, char **argv, unsigned timeout, const char *tag = NULL);
01088 };
01089 
01100 class TrunkGroup : public Keydata, public CallStat
01101 {
01102 private:
01103         friend class KeyServer;
01104         friend class Scheduler;
01105         friend class Audit;
01106         friend class TestDebug;
01107         friend class Request;
01108         static TrunkGroup *first;
01109         TrunkGroup *next;
01110         char schedule[65];
01111         char planned[65];
01112         unsigned trump;
01113         Request *reqfirst, *reqlast;
01114 
01115         void setSchedule(const char *str);
01116 
01117         friend inline const char *getGroups(void)
01118                 {return TrunkGroup::first->getLast("groups");};
01119 
01120         friend void cancel(TrunkGroup *group, const char *tag);
01121 
01122 public:
01128         TrunkGroup(char *name = NULL);
01129 
01135         inline const char *getName(void)
01136                 {return getLast("name");};
01137 
01143         inline unsigned getAnswer(void)
01144                 {return atoi(getLast("answer"));};
01145 
01151         inline unsigned getCallerid(void)
01152                 {return atoi(getLast("callerid"));};
01153 
01159         inline unsigned getPickup(void)
01160                 {return atoi(getLast("pickup"));};
01161 
01167         inline const char *chkRequest(void)
01168                 {return getLast("requests");};
01169 
01175         seltype_t getSelect(void);
01176 
01182         inline unsigned getThreashold(void)
01183                 {return atoi(getLast("threashold"));};
01184 
01190         inline unsigned getAnalysis(void)
01191                 {return atoi(getLast("analysis"));};
01192 
01199         inline timeout_t getReady(void)
01200                 {return atol(getLast("ready"));};
01201         
01207         inline unsigned getIdleTime(void)
01208                 {return atoi(getLast("idletime"));};
01209 
01215         inline unsigned getSiezeTime(void)
01216                 {return atoi(getLast("siezetime"));};
01217 
01223         inline unsigned getRingTime(void)
01224                 {return atoi(getLast("ringtime"));};
01225 
01231         inline int getHangup(void)
01232                 {return atoi(getLast("hangup"));};
01233 
01239         inline timeout_t getFlash(void)
01240                 {return atol(getLast("flash"));};
01241 
01247         inline timeout_t getDialtone(void)
01248                 {return atol(getLast("dialtone"));};
01249 
01255         inline timeout_t getDialspeed(void)
01256                 {return atol(getLast("dialspeed"));};
01257 
01264         const char *getNumber(void);
01265 
01272         const char *getSchedule(char *buf);
01273 
01283         const char *getRedirect(const char *redirect, char *buf);
01284 
01288         inline void incCapacity(void)
01289                 {++capacity;};
01290 
01296         Request *getRequest(void);
01297 
01303         friend TrunkGroup *getGroup(const char *name);
01304 };
01305 
01313 class KeyServer : public Keydata
01314 {
01315 private:
01316         unsigned uid, gid;
01317         const char *altdir;
01318         const char *phrdir;
01319 
01320 public:
01324         KeyServer();
01325 
01331         inline const char *getNode(void)
01332                 {return getLast("node");};
01333 
01339         inline const char *getToken(void)
01340                 {return getLast("token");};
01341 
01345         void loadGroups(bool test);
01346 
01352         inline const char *getDefault(void)
01353                 {return getLast("default");};
01354 
01360         inline unsigned getGid(void)
01361                 {return gid;};
01362 
01368         inline unsigned getUid(void)
01369                 {return uid;};
01370 
01374         void setUid(void);
01375 
01379         void setGid(void);
01380 
01386         inline int getNodeCount(void)
01387                 {return atoi(getLast("nodes"));};
01388 
01394         inline const char *getPrefix(void)
01395                 {return altdir;};
01396 
01402         inline const char *getPhrases(void)
01403                 {return phrdir;};
01404 };
01405 
01413 class Plugins : public Keydata
01414 {
01415 public:
01419         Plugins();
01420 
01424         ~Plugins();
01425 
01431         char *getDriverName(void);
01432 
01436         void loadDebug(void);
01437 
01442         DSO *loadDriver(void);
01443 
01447         void loadExtensions(void);
01448 
01452         void loadFunctions(void);
01453 
01457         void loadMaps(void);
01458 
01462         void loadModules(void);
01463 
01467         void loadFeeds(void);
01468 
01472         void loadTGI(void);
01473 
01477         void loadManagers(void);
01478 
01482         void loadTranslators(void);
01483 
01487         void loadAuditing(void);
01488 };
01489 
01498 class aaScript : public ScriptCommand 
01499 {
01500 private:
01501         friend class Functions;
01502 
01503 #pragma pack(1)
01504         typedef struct _functions
01505         {
01506                 struct _functions *next;
01507                 functioncall_t function;
01508                 char name[1];
01509         }       functions_t;
01510 #pragma pack()
01511 
01512         functions_t *functions[KEYWORD_INDEX_SIZE];
01513 
01514 protected:
01522         unsigned long getTrapMask(const char *trapname);
01523 
01531         void addFunction(char *name, functioncall_t function);
01532 
01533 public:
01540         functioncall_t getFunction(char *name);
01541 
01545         aaScript();
01546 
01552         void addModule(Module *module);
01553 };
01554 
01564 class aaImage : public ScriptImage
01565 {
01566 protected:
01574         virtual bool isScript(char *scriptname);
01575 
01582         void scanDir(char *path);
01583 
01584 public:
01588         aaImage(aaScript *script);
01589 };
01590 
01597 class Mixer : protected Mutex
01598 {
01599 private:
01600         friend class Conference;
01601         void addGroup(void);
01602         void delGroup(void);
01603 
01604 protected:
01605         Mixer();
01606         unsigned avail, members, groups;
01607 
01608 public:
01609         unsigned getAvail(void)
01610                 {return avail;};
01611 
01612         unsigned getMembers(void)
01613                 {return members;};
01614 
01615         unsigned getGroups(void)
01616                 {return groups;};
01617 
01618         virtual bool setMixer(int groups, int members) = 0;
01619 
01620         virtual Conference *getConference(int group) = 0;
01621 };
01622 
01631 class Conference : protected Mutex
01632 {
01633 protected:
01634         Mixer *mixer;
01635         unsigned limit;
01636         unsigned members;
01637 
01638         virtual ~Conference();
01639 
01640         Conference(Mixer *m);
01641 public:
01642         inline virtual Mixer *getMixer(void)
01643                 {return mixer;};
01644 
01645         unsigned getMembers(void)
01646                 {return members;};
01647 
01648         unsigned getLimit(void)
01649                 {return limit;};
01650 
01651         virtual bool setConference(unsigned max) = 0;
01652 };
01653 
01663 class Trunk : public ScriptInterp
01664 {
01665 private:
01666         friend class TestDebug;
01667         friend class aaScript;
01668         friend class Translator;
01669         friend class ScriptInterface;
01670         friend class Service;
01671         friend class AudioService;
01672         friend class Fifo;
01673         friend class PortManager;
01674 
01675         char *cdrv[33];
01676         int cdrc;
01677         numbersymbol_t numbers[5];
01678 
01679         bool scrStart(void);
01680         bool scrRequest(void);
01681         bool scrLibonce(void);
01682         bool scrLibexec(void);
01683         bool scrHangup(void);
01684         bool scrDebug(void);
01685         bool scrImport(void);
01686         bool scrExport(void);
01687         bool scrFunction(void);
01688         bool scrAlog(void);
01689         bool scrAudit(void);
01690         bool scrPause(void);
01691         bool scrSleep(void);
01692         bool scrSync(void);
01693         bool scrTone(void);
01694         bool scrAnswer(void);
01695         bool scrCollect(void);
01696         bool scrFlash(void);
01697         bool scrPlay(void);
01698         bool scrRecord(void);
01699         bool scrAppend(void);
01700         bool scrDial(void);
01701         bool scrDTMF(void);
01702         bool scrTransfer(void);
01703         bool scrSpeak(void);
01704         bool scrMap(void);
01705         bool scrModule(void);
01706         bool scrSchedule(void);
01707         bool scrSignal(void);
01708         bool scrIdle(void);
01709 
01710 protected:
01711         static ScriptSymbol globals;
01712         static char digit[16];
01713         ScriptInterface *script;
01714         TrunkGroup *group;
01715         PortManager *manager;
01716         int id;
01717         time_t start, idle;
01718 
01719         int idle_timer;
01720         int rings;
01721         int digits;
01722 
01723         Service *thread;
01724         trunkdata_t data;
01725         execdata_t tgi;
01726         digitsymbol_t dtmf;
01727         char buffer[65];
01728 
01729         struct
01730         {
01731                 bool offhook: 1;
01732                 bool dtmf: 1;
01733                 bool script: 1;
01734                 bool reset: 1;
01735                 bool timer : 1;
01736                 bool audio: 1;
01737                 bool once : 1;
01738                 bool ready : 1;
01739                 bool echo : 1;
01740                 unsigned temp : 1;
01741                 trunkmode_t trunk: 2;
01742                 dspmode_t dsp: 4;
01743         } flags;
01744 
01750         unsigned long getTrapDefault(void)
01751                 {return 0x00000007;};
01752 
01761         void setConstant(const char *id, const char *data);
01762 
01769         void repSymbol(const char *id, const char *data);
01770 
01778         scriptsymbol_t *getEntry(const char *symname, int size);
01779 
01785         void Commit(scriptsymbol_t *sym);
01786 
01793         int getTimeout(void);
01794 
01801         int getInterdigit(void);
01802 
01808         unsigned short getDigitMask(void);
01809 
01815         bool TrunkSignal(trunksignal_t);
01816 
01823         virtual void setDTMFDetect(void);
01824 
01833         virtual void setDTMFDetect(bool enable)
01834                 {flags.dtmf = enable;};
01835 
01841         virtual void stopServices(void);
01842 
01853         virtual void TrunkStep(trunkstep_t step) = 0;
01854 
01860         bool idleHangup();
01861 
01868         virtual unsigned long getIdleTime(void) = 0;
01869 
01873         bool ScriptStep(void);
01874 
01883         bool Attach(const char *scrname);
01884 
01889         void Detach(void);
01890 
01894         unsigned long getMask(void);
01895 
01902         char **getInitial(char **args);
01903 
01910         void setList(char **list);
01911 
01912         Trunk(int port);
01913 public:
01919         virtual unsigned long getCapabilities(void)
01920                 {return TRUNK_CAP_VOICE | TRUNK_CAP_DIAL;};
01921 
01927         virtual void getName(char *buffer) = 0;
01928 
01936         virtual bool postEvent(TrunkEvent *event) = 0;
01937 
01943         int getDigit(char digit);
01944 
01950         bool isReady(void);
01951 };
01952 
01961 class PortManager
01962 {
01963 private:
01964         Trunk *trunk;
01965 
01966 protected:
01967         ~PortManager()
01968                 {trunk->manager = NULL;};
01969 
01975         PortManager(Trunk *trk);
01976 
01982         inline void postStep(trunkstep_t step)
01983                 {trunk->TrunkStep(step);};
01984 
01991         inline bool postEvent(TrunkEvent *event)
01992                 {return trunk->postEvent(event);};
01993 
01999         inline trunkdata_t *getData(void)
02000                 {return &trunk->data;};
02001 
02007         inline execdata_t *getExec(void)
02008                 {return &trunk->tgi;};
02009 public:
02013         virtual bool Step(void) = 0;
02014 
02020         virtual unsigned long getMask(void) = 0;
02021         
02028         virtual bool postSignal(trunksignal_t signal) = 0;
02029 
02036         virtual bool postAccept(const char *name) = 0;
02037 
02041         virtual void postDetach(void) = 0;
02042 };
02043 
02053 class Fifo : public fifostream, public Mutex
02054 {
02055 protected:
02056         char schedule[33];
02057 
02058         bool exitPid(char **args);
02059         bool waitPid(char **args);
02060         bool setSymbol(char **argv);
02061         bool putSymbol(char **argv);
02062         bool submit(char **argv);
02063         bool login(char **argv);
02064         bool mapFiles(char **argv);
02065         bool startScript(char **argv);
02066         bool ringScript(char **argv);
02067         bool redirectScript(char **argv);
02068         bool busyLine(char **argv);
02069         bool idleLine(char **argv);
02070         bool hangupLine(char **argv);
02071         bool reqScript(char **argv);
02072         bool setSchedule(char **argv);
02073         bool postKey(char **argv);
02074         bool setMixer(char **argv);
02075         bool setLimit(char **argv);
02076 
02077 public:
02086         bool Command(const char *cmdstring, ostream *fd = NULL);
02087 };
02088 
02096 class FifoHandler
02097 {
02098 private:
02099         friend class Fifo;
02100 
02101         static FifoHandler *first;
02102         FifoHandler *next;
02103 protected:
02111         virtual bool Command(char **argv, ostream *fd) = 0;
02112 
02116         FifoHandler();
02117 };
02118 
02132 class Audit : public Mutex
02133 {
02134 private:
02135         friend void audit(Trunk *trunk, char *detail);
02136         friend void alog(Trunk *trunk, char *detail);
02137         friend class Scheduler;
02138 
02139         static Audit *first;
02140         Audit *next;
02141 
02142 protected:
02143         static Auditdata keys;
02144 
02150         virtual void ReportAudit(Trunk *trunk, char *detail) = 0;
02151 
02157         virtual void ReportCDR(Trunk *trunk, char *detail)
02158                 {ReportAudit(trunk, detail);};
02159 
02163         virtual void ReportStats(void)
02164                 {return;};
02165 
02171         inline TrunkGroup *getFirst(void)
02172                 {return TrunkGroup::first;};
02173 
02180         inline TrunkGroup *getNext(TrunkGroup *grp)
02181                 {return grp->next;};
02182 
02186         Audit();
02187 };
02188 
02196 class Driver : public aaScript
02197 {
02198 protected:
02199         friend class TrunkGroup;
02200 
02201         TrunkGroup **groups;
02202         char *status;
02203         bool active;
02204 
02205 public:
02209         Driver();
02210 
02217         virtual int Start(void) = 0;
02218 
02222         virtual void Stop(void) = 0;
02223 
02229         void getStatus(char *buffer);
02230 
02237         virtual aaImage *getImage(void);
02238 
02245         virtual int getTrunkCount(void) = 0;
02246 
02253         virtual int getTrunkUsed(void) 
02254                 {return getTrunkCount();};
02255 
02262         TrunkGroup *getTrunkGroup(int id)
02263                 {return groups[id];}; 
02264         
02270         virtual Trunk *getTrunkPort(int id) = 0;
02271 
02277         virtual Conference *getConference(int id)
02278                 {return NULL;};
02279 
02285         virtual Mixer *getMixer(int id)
02286                 {return NULL;};
02287 
02293         virtual unsigned getMixers(void)
02294                 {return 0;};
02295 
02301         virtual unsigned getGroups(void)
02302                 {return 0;};
02303 };
02304 
02311 class Debug : protected Mutex
02312 {
02313 public:
02317         Debug();
02318 
02324         virtual bool DebugTest(void)
02325                 {return false;};
02326 
02330         virtual void DebugEvent(Trunk *trunk, TrunkEvent *event)
02331                 {return;};
02332 
02336         virtual void DebugState(Trunk *trunk, char *state)
02337                 {return;};
02338 
02342         virtual void DebugService(Trunk *trunk, char *msg)
02343                 {return;};
02344 
02348         virtual void DebugScript(Trunk *trunk, char *msg)
02349                 {return;};
02350 
02354         virtual void DebugStep(Trunk *trunk, scriptline_t *line)
02355                 {DebugState(trunk, "step");};
02356 
02360         virtual bool DebugFifo(char **argv)
02361                 {return true;};
02362 };
02363 
02370 class AudioService
02371 {
02372 private: 
02373         char filename[256];
02374 
02375 protected:
02376         Trunk *trunk;
02383         char *getPrompt(char *name);
02384 
02390         char *getPlayfile(void);
02391 
02395         AudioService(void);
02396 };
02397 
02405 class Service : public Semaphore, public Thread, public AudioService
02406 {
02407 protected:
02408         volatile bool stopped;
02409         trunkdata_t *data;
02410         TrunkGroup *group;
02411 
02415         void Success(void);
02416 
02420         void Failure(void);
02421 
02425         inline void dspReset(void)
02426                 {trunk->flags.reset = true;};
02427 
02431         inline void setAudio(void)
02432                 {trunk->flags.audio = true;};
02433 
02437         inline void clrAudio(void)
02438                 {trunk->flags.audio = false;};
02439 
02440 public:
02447         Service(Trunk *trunk, int pri);
02448 
02455         virtual timeout_t Stop(void);
02456 
02464         virtual bool isExiting(void)
02465                 {return true;};
02466 
02470         void endService(void)
02471                 {Terminate();};
02472 
02476         virtual ~Service()
02477                 {Terminate();}
02478 };
02479 
02489 class Server : public Thread
02490 {
02491 private:
02492         static Server *first;
02493         Server *next;
02494         friend void startServers(void);
02495         friend void stopServers(void);
02496 
02497 protected:
02498         Server(int pri);
02499 
02503         virtual void Stop(void)
02504                 {Terminate();};
02505 };
02506 
02513 class Sync
02514 {
02515 private:
02516         friend class Scheduler;
02517 
02518         static Sync *first;
02519         Sync *next;
02520         time_t runtime;
02521 
02522 protected:
02526         Sync(void);
02527 
02532         virtual bool isScheduled(void) = 0;
02533 
02538         virtual unsigned getInterval(void)
02539                 {return 10;};
02540 
02544         virtual void Schedule(void) = 0;
02545 
02549         virtual char *getName(void) = 0;
02550 };
02551 
02560 class phTone
02561 {
02562 private:
02563         friend phTone *getphTone(const char *name);
02564         static phTone *first;
02565         static int ulaw[256];
02566         phTone *next;
02567         char name[33];
02568         unsigned char *samples;
02569         timeout_t duration;
02570         unsigned freq1, freq2;
02571 
02572 public:
02580         phTone(const char *name, timeout_t duration, unsigned f);
02581 
02590         phTone(const char *name, timeout_t duration, unsigned f1, unsigned f2);
02591 
02592         ~phTone();
02593 
02599         void Clear(void);
02600 
02606         inline unsigned char *getSamples(void)
02607                 {return samples;};
02608 
02614         inline timeout_t getDuration(void)
02615                 {return duration;};
02616 };
02617 
02624 class TGI
02625 {
02626 private:
02627         static TGI *first;
02628         TGI *next;
02629 
02630 protected:
02631         TGI();
02632 
02640         virtual bool getExtension(char *ext)
02641                 {return false;};
02642 
02643 public:
02653         virtual void Script(char *cmd, char **args)
02654                 {return;};
02655 
02664         virtual int Parse(int fd, int port, char *cmd)
02665                 {return -1;};   
02666 
02667         friend void getInterp(char *cmd, char **args);
02668         friend TGI *getInterp(char *cmd);
02669 };
02670         
02680 class Module
02681 {
02682 private:
02683         static Module *first;
02684         Module *next;
02685 
02686 protected:
02687         Module();
02688 
02694         virtual modtype_t getType(void) = 0;
02695 
02696 public:
02702         virtual char *getName(void) = 0;
02703 
02711         virtual char *Dispatch(Trunk *trunk) = NULL;
02712 
02720         virtual unsigned Sleep(Trunk *trunk)
02721                 {return 0;};
02722 
02729         virtual void Detach(Trunk *trunk)
02730                 {return;};
02731 
02739         virtual void Attach(Trunk *trunk)
02740                 {return;};
02741 
02742         friend Module *getModule(modtype_t mod, const char *name = NULL);
02743         friend void detachModules(Trunk *trunk);
02744         friend void attachModules(Trunk *trunk);
02745 };
02746 
02756 class Session
02757 {
02758 private:
02759         friend class Scheduler;
02760         static Mutex mutex;
02761         static Session *first;
02762         static Session *last;
02763         Session *next, *prev;
02764         static void Clean(void);
02765 
02766 protected:
02767         Session();
02768         virtual ~Session()
02769                 {Unlink();};
02770 
02774         void Unlink(void);
02775 
02782         virtual time_t getExpires(void) = 0;
02783 };
02784 
02793 class AudioFeed : private ThreadLock
02794 {
02795 private:
02796         static AudioFeed *first;
02797         AudioFeed *next;
02798         unsigned char *buffers;
02799         volatile unsigned char *current;
02800         size_t feedsize, bufsize;
02801         bool active;
02802 
02803 protected:
02804         const char *name;
02805 
02806 public:
02807         AudioFeed(const char *name, unsigned buffers);
02808         ~AudioFeed();
02809         bool Enable(void);
02810         void Disable(void);
02811         unsigned char *getBuffer(unsigned char *prior = NULL, unsigned size = 120);
02812         void putBuffer(unsigned char *buffer, unsigned size = 120);
02813 
02814         friend AudioFeed *getAudioFeed(const char *name);
02815 };
02816 
02825 class Map : private MemPager
02826 {
02827 private:
02828         static ThreadLock lock;
02829         static Map *first, *last;
02830 
02831         typedef struct _sym
02832         {
02833                 struct _sym *next;
02834                 char *key;
02835                 char **values;
02836         }       mapsym_t;
02837 
02838         typedef struct
02839         {
02840                 mapsym_t *keys[127];
02841         } mapkey_t;
02842 
02843         mapkey_t *digits[32];
02844 
02845         Map *next, *prev;
02846         char *name;
02847 
02848         unsigned getKey(const char *key, unsigned len = 0);
02849         char **getList(const char *key, unsigned len);
02850         ~Map();
02851 
02852 public:
02853         Map(const char *path, const char *name);
02854 
02855         friend char **getMap(const char *map, const char *key);
02856         friend void endMaps(void);
02857 };
02858 
02867 class Protocol : public Keydata, public InetHostAddress, public ThreadLock
02868 {
02869 private:
02870         friend class Resolver;
02871         static Protocol *first;
02872         Protocol *next;
02873         Semaphore *sessions;
02874         tpport_t port;
02875 
02876         void Update(InetHostAddress addr);
02877 public:
02878         Protocol(const char *keypath, tpport_t port);
02879         ~Protocol();
02880 
02886         InetHostAddress getAddress(void);
02887 
02893         inline tpport_t getPort(void)
02894                 {return port;};
02895 
02902         inline Semaphore *getSessions(void)
02903                 {return sessions;};
02904 };
02905 
02906 extern bool running;
02907 extern KeyServer keyserver;
02908 extern KeyThreads keythreads;
02909 extern KeyMemory keymemory;
02910 extern KeyPaths keypaths;
02911 extern KeyLocal keylocal;
02912 extern KeyNetwork keynetwork;
02913 extern KeyMailbox keymailbox;
02914 extern KeyTones keytones;
02915 extern KeyFeed keyfeed;
02916 extern Plugins plugins;
02917 extern Driver *driver;
02918 extern Debug *debug;
02919 extern Fifo fifo;
02920 #endif
02921 

Generated at Sat Feb 3 09:41:23 2001 for Bayonne by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000