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-2001 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_XML_H__
00025 #include <cc++/xml.h>
00026 #endif
00027 
00028 #ifndef __CCXX_URL_H__
00029 #include <cc++/url.h>
00030 #endif
00031 
00032 #ifndef __CCXX_SLOG_H__
00033 #include <cc++/slog.h>
00034 #endif
00035 
00036 #ifndef __CCXX_DSO_H__
00037 #include <cc++/file.h>
00038 #endif
00039 
00040 #ifndef __CCXX_SOCKET_H__
00041 #include <cc++/socket.h>
00042 #endif
00043 
00044 #ifndef __CCXX_AUDIO_H__
00045 #include <cc++/audio.h>
00046 #endif
00047 
00048 #include <iostream>
00049 #include <fstream>
00050 #include <cstdlib>
00051 
00052 #ifdef  __FreeBSD__
00053 #undef  read
00054 #undef  write
00055 #undef  readv
00056 #undef  writev
00057 #endif
00058 
00059 #ifdef  COMMON_OST_NAMESPACE
00060 using namespace ost;
00061 #endif
00062 
00063 /* Bayonne uses a universal event record for all driver plugins and
00064    state handlers.  Not all drivers impliment the entire set of events
00065    and some drivers have specific events associated with their unique
00066    characteristcs.  However, most events are considered "universal".
00067 */
00068 
00069 class Trunk;
00070 class TrunkImage;
00071 class Service;
00072 class phTone;
00073 class TrunkGroup;
00074 class Module;
00075 class Request;
00076 
00077 typedef enum
00078 {
00079         SELECT_FIRST,
00080         SELECT_LAST
00081 } seltype_t;
00082 
00083 typedef enum
00084 {
00085         MAP_PREFIX,
00086         MAP_SUFFIX,
00087         MAP_ABSOLUTE
00088 } mapmode_t;
00089 
00090 typedef enum {
00091         MODULE_GENERIC,
00092         MODULE_DELIVERY,
00093         MODULE_SENDFILE,
00094         MODULE_SENDFAX,
00095         MODULE_NOTIFY,
00096         MODULE_FIFO,
00097         MODULE_TGI,
00098         MODULE_URL,
00099         MODULE_NET,
00100         MODULE_REPLY,
00101         MODULE_ASR,
00102         MODULE_TTS,
00103         MODULE_XML,
00104         MODULE_ANY
00105 }       modtype_t;
00106 
00107 typedef enum {
00108         // step change requests
00109         TRUNK_STEP_HANGUP = 0,
00110         TRUNK_STEP_SLEEP,
00111         TRUNK_STEP_ANSWER,
00112         TRUNK_STEP_COLLECT,
00113         TRUNK_STEP_PLAY,
00114         TRUNK_STEP_PLAYWAIT,
00115         TRUNK_STEP_RECORD,
00116         TRUNK_STEP_TONE,
00117         TRUNK_STEP_DIALXFER,
00118         TRUNK_STEP_FLASH,
00119         TRUNK_STEP_JOIN,
00120         TRUNK_STEP_RTP,
00121         TRUNK_STEP_DUPLEX,
00122         TRUNK_STEP_DETECT,
00123         TRUNK_STEP_REQUIRES,
00124         TRUNK_STEP_LOADER,
00125         TRUNK_STEP_EXIT = TRUNK_STEP_HANGUP,
00126         TRUNK_STEP_DRIVER
00127 } trunkstep_t;
00128 
00129 typedef enum {
00130         // notify script from state handler
00131         TRUNK_SIGNAL_STEP = 0,
00132         TRUNK_SIGNAL_EXIT,
00133         TRUNK_SIGNAL_HANGUP=TRUNK_SIGNAL_EXIT,
00134         TRUNK_SIGNAL_ERROR,
00135         TRUNK_SIGNAL_TIMEOUT,
00136         TRUNK_SIGNAL_DTMF,
00137         TRUNK_SIGNAL_0,
00138         TRUNK_SIGNAL_1,
00139         TRUNK_SIGNAL_2,
00140         TRUNK_SIGNAL_3,
00141         TRUNK_SIGNAL_4,
00142         TRUNK_SIGNAL_5,
00143         TRUNK_SIGNAL_6,
00144         TRUNK_SIGNAL_7,
00145         TRUNK_SIGNAL_8,
00146         TRUNK_SIGNAL_9,
00147         TRUNK_SIGNAL_STAR,
00148         TRUNK_SIGNAL_POUND,
00149         TRUNK_SIGNAL_A,
00150         TRUNK_SIGNAL_B,
00151         TRUNK_SIGNAL_C,
00152         TRUNK_SIGNAL_D,
00153         TRUNK_SIGNAL_DIALTONE,
00154         TRUNK_SIGNAL_BUSY,
00155         TRUNK_SIGNAL_CANCEL,
00156         TRUNK_SIGNAL_SIGNAL,
00157         TRUNK_SIGNAL_NOANSWER,
00158         TRUNK_SIGNAL_DRIVER
00159 }       trunksignal_t;
00160 
00161 typedef enum {
00162         // primary state handlers
00163 
00164         TRUNK_ENTER_STATE = 100,// newly entered handler state
00165         TRUNK_EXIT_STATE,       // exiting prior state (unused)
00166         TRUNK_STOP_STATE,       // request state termination
00167         TRUNK_NOTIFICATION,     // death notify event
00168         TRUNK_SERVICE_SUCCESS,  // service completion successful
00169         TRUNK_SERVICE_FAILURE,  // service completion failed
00170         TRUNK_SERVICE_LOOKUP,   // lookup transaction
00171         TRUNK_SERVICE_LOGIN,    // login transaction
00172         TRUNK_SIGNAL_NOTIFY,    // signal between trunks
00173         TRUNK_JOIN_TRUNKS,      // join two trunks together
00174         TRUNK_PART_TRUNKS,      // split two trunks that were joined
00175         TRUNK_NULL_EVENT,       // used to push pipe driven systems
00176 
00177         // tgi/integration control state handlers
00178 
00179         TRUNK_EXIT_SHELL = 200, // tgi completion event
00180         TRUNK_START_SCRIPT,     // start of script
00181         TRUNK_RING_START,       // smdi/integrated answer
00182         TRUNK_RING_REDIRECT,    // smdi/integrated answer options
00183         TRUNK_STOP_DISCONNECT,  // integrated hangup notification
00184 
00185         // in the future these will be used
00186 
00187         TRUNK_START_INCOMING = TRUNK_RING_START,
00188         TRUNK_START_OUTGOING = TRUNK_START_SCRIPT,
00189 
00190         // primary "mode" selection controls
00191 
00192         TRUNK_MAKE_TEST =  300, // request driver perform line test
00193         TRUNK_MAKE_BUSY,        // request driver lockout line
00194         TRUNK_MAKE_IDLE,        // request driver reset line
00195         TRUNK_MAKE_STEP,        // pass step event internally
00196 
00197         // basic trunk events
00198 
00199         TRUNK_LINE_WINK = 400,  // used for line disconnect notification
00200         TRUNK_TIMER_EXPIRED,    // driver specific port timer expired
00201         TRUNK_RINGING_ON,       // some drivers distinguish start/stop
00202         TRUNK_RINGING_OFF,      // default ring event
00203         TRUNK_TEST_IDLE,        // some drivers have line test completion
00204         TRUNK_TEST_FAILURE,     // some drivers notify errors
00205         TRUNK_ON_HOOK,          // some drivers notify on hook
00206         TRUNK_OFF_HOOK,         // some drivers notify off hook
00207         TRUNK_CALLER_ID,        // caller id parse request
00208         TRUNK_RINGING_DID,      // did digit ring signal
00209         TRUNK_CALL_DETECT,      // ISDN call detected notification
00210         TRUNK_CALL_CONNECT,     // ISDN call connection notification
00211         TRUNK_CALL_RELEASE,     // ISDN call release notification
00212         TRUNK_CALL_ACCEPT,      // ISDN incoming call accepted
00213         TRUNK_CALL_ANSWERED,    // ISDN connect sent to the network
00214         TRUNK_CALL_HOLD,        // ISDN call placed on hold
00215         TRUNK_CALL_NOHOLD,      // ISDN call hold was rejected
00216         TRUNK_CALL_DIGITS,      // requested digits received
00217         TRUNK_CALL_OFFER,       // ISDN call offered
00218         TRUNK_CALL_ANI,         // ANI received
00219         TRUNK_CALL_ACTIVE,      // ISDN call taken off hold
00220         TRUNK_CALL_NOACTIVE,    // ISDN call hold retrieve failed
00221         TRUNK_CALL_BILLING,     // ISDN call billing acknowledge
00222         TRUNK_CALL_RESTART,     // ISDN call restart, success or failure
00223         TRUNK_CALL_SETSTATE,    // ISDN acknowledge state change
00224         TRUNK_CALL_FAILURE,     // ISDN midcall failure
00225         TRUNK_CALL_ALERTING,    // ISDN call alerting
00226         TRUNK_CALL_INFO,        // ISDN call info message
00227         TRUNK_CALL_BUSY,        // ISDN conjestion message
00228         TRUNK_CALL_DIVERT,      // ISDN call diversion notification
00229         TRUNK_CALL_FACILITY,    // ISDN call facility
00230         TRUNK_CALL_FRAME,       // ISDN call frame
00231         TRUNK_CALL_NOTIFY,      // ISDN call notify
00232         TRUNK_CALL_NSI,         // ISDN call nsi message
00233         TRUNK_CALL_RINGING,     // digital T1 incoming call
00234         TRUNK_CALL_DISCONNECT,  // digital T1 circuit break
00235 
00236         // basic audio processing events
00237 
00238         TRUNK_AUDIO_IDLE = 500, // audio reset or completion event
00239         TRUNK_INPUT_PENDING,    // some drivers monitor audio i/o status
00240         TRUNK_OUTPUT_PENDING,   // some drivers monitor audio i/p status
00241         TRUNK_AUDIO_BUFFER,     // some drivers return audio buffers
00242         TRUNK_TONE_IDLE,        // tone generator completion event
00243         TRUNK_DTMF_KEYDOWN,     // some drivers distinguish tone down
00244         TRUNK_DTMF_KEYUP,       // default dtmf event
00245         TRUNK_TONE_START,       // tone detected
00246         TRUNK_TONE_STOP,        // some drivers have tone completion event
00247         TRUNK_FSK_DETECT,       // fsk tone detect
00248         TRUNK_FAX_DETECT,       // fax tone detect
00249         TRUNK_VOX_DETECT,       // speaker detected
00250         TRUNK_AUDIO_START,      // some drivers may "vox" compress
00251         TRUNK_AUDIO_STOP,       // some drivers may "vox" compress
00252         TRUNK_CPA_DIALTONE,     // dialtone heard on the line
00253         TRUNK_CPA_BUSYTONE,
00254         TRUNK_CPA_RINGING,
00255         TRUNK_CPA_RINGBACK = TRUNK_CPA_RINGING,
00256         TRUNK_CPA_INTERCEPT,
00257         TRUNK_CPA_NODIALTONE,
00258         TRUNK_CPA_NORINGBACK,
00259         TRUNK_CPA_NOANSWER,
00260         TRUNK_CPA_CONNECT,
00261         TRUNK_CPA_FAILURE,
00262         TRUNK_DSP_READY,        // dsp resource became available
00263 
00264         // driver specific events and anomolies
00265 
00266         TRUNK_DRIVER_SPECIFIC=8000      // very oddball events
00267 } trunkevent_t;
00268 
00269 typedef enum
00270 {
00271         DSP_MODE_INACTIVE = 0,  // dsp is idle
00272         DSP_MODE_VOICE,         // standard voice processing
00273         DSP_MODE_CALLERID,      // caller id support
00274         DSP_MODE_DATA,          // fsk modem mode
00275         DSP_MODE_FAX,           // fax support
00276         DSP_MODE_TDM,           // TDM bus with echo cancellation
00277         DSP_MODE_RTP,           // VoIP full duplex
00278         DSP_MODE_DUPLEX,        // mixed play/record
00279         DSP_MODE_JOIN,          // support of joined channels
00280         DSP_MODE_CONF,          // in conference
00281         DSP_MODE_TONE           // tone processing
00282 } dspmode_t;
00283 
00284 typedef enum
00285 {
00286         TRUNK_MODE_INCOMING = 0,
00287         TRUNK_MODE_OUTGOING,
00288         TRUNK_MODE_INACTIVE,
00289         TRUNK_MODE_UNAVAILABLE
00290 } trunkmode_t;
00291  
00292 typedef enum
00293 {
00294         STAT_MAX_INCOMING,
00295         STAT_MAX_OUTGOING,
00296         STAT_TOT_INCOMING,
00297         STAT_TOT_OUTGOING,
00298         STAT_ACTIVE_CALLS
00299 } statitem_t;
00300 
00301 typedef enum
00302 {
00303         PLAY_MODE_NORMAL,
00304         PLAY_MODE_ONE,
00305         PLAY_MODE_ANY,
00306         PLAY_MODE_TEMP
00307 } playmode_t;
00308 
00309 typedef enum
00310 {
00311         TTS_GATEWAY_TEXT,
00312         TTS_GATEWAY_FILE
00313 } ttsmode_t;
00314 
00315 #define TRUNK_CAP_VOICE         0x00000001
00316 #define TRUNK_CAP_DIAL          0x00000002
00317 #define TRUNK_CAP_SENDFAX       0x00000004
00318 #define TRUNK_CAP_RECVFAX       0x00000008
00319 #define TRUNK_CAP_DATA          0x00000010
00320 #define TRUNK_CAP_TTS           0x00000020
00321 #define TRUNK_CAP_ASR           0x00000040
00322 
00323 typedef union
00324 {
00325         scriptsymbol_t sym;
00326         char data[sizeof(scriptsymbol_t) + 12];
00327 }       numbersymbol_t;
00328 
00329 typedef union
00330 {
00331         scriptsymbol_t bin;
00332         char data[sizeof(scriptsymbol_t) + 32];
00333 }       digitsymbol_t;
00334 
00335 typedef struct
00336 {
00337         
00338         int pid;
00339         unsigned seq;
00340         void *data;
00341 }       execdata_t;
00342 
00343 typedef union
00344 {
00345         struct
00346         {
00347                 int rings;
00348                 int timeout;
00349         }       answer;
00350         struct
00351         {
00352                 char list[256];
00353                 char *name;
00354                 unsigned long offset;
00355                 unsigned long limit;
00356                 unsigned char volume;
00357                 unsigned short term;
00358                 playmode_t mode;
00359                 timeout_t timeout;
00360                 unsigned repeat;
00361         }       play;
00362         struct
00363         {
00364                 char *name;
00365                 timeout_t timeout;
00366                 unsigned long offset;
00367                 unsigned short term;
00368                 unsigned char volume;
00369                 unsigned long trim;
00370                 bool append;
00371         }       record;
00372         struct
00373         {
00374                 char digits[65];
00375                 char *digit;
00376                 timeout_t interdigit;
00377                 bool exit;
00378                 timeout_t timeout;
00379                 timeout_t offhook;
00380                 timeout_t onhook;
00381         }       dialxfer;
00382         struct
00383         {
00384                 timeout_t timeout;
00385                 unsigned count;
00386                 unsigned short term;
00387                 unsigned short ignore;
00388         }       collect;
00389         struct
00390         {
00391                 timeout_t wakeup;
00392                 unsigned rings;
00393                 unsigned loops;
00394         }       sleep;
00395         struct
00396         {
00397                 timeout_t wakeup;
00398                 unsigned loops;
00399                 phTone *tone;
00400         }       tone;
00401         struct
00402         {
00403                 timeout_t wakeup;
00404                 Trunk *trunk;
00405                 phTone *tone;
00406         }       join;
00407         struct
00408         {
00409                 struct in_addr addr;
00410                 unsigned short bind, port, term;
00411                 audioencoding_t codec;
00412         }       rtp;
00413         struct
00414         {
00415                 TrunkImage *image;
00416                 const char *url;
00417                 const char *section;
00418                 char **vars;
00419                 bool post;
00420                 timeout_t timeout;
00421         }       load;
00422 }       trunkdata_t;
00423 
00424 typedef struct
00425 {
00426         trunkevent_t id;        // event id
00427         union
00428         {
00429                 struct
00430                 {
00431                         unsigned digit: 4;
00432                         unsigned duration: 12;
00433                         unsigned e1: 8;
00434                         unsigned e2: 8;
00435                 } dtmf;
00436                 struct
00437                 {
00438                         unsigned tone: 8;
00439                         unsigned energy: 8;
00440                         unsigned duration: 16;
00441                 } tone;
00442                 struct
00443                 {
00444                         unsigned digit:  4;
00445                         unsigned duration: 24;
00446                 } ring;
00447                 struct
00448                 {
00449                         unsigned seq;
00450                         bool result;
00451                         char *data;
00452                 } lookup;
00453                 bool ok;
00454                 int status;
00455                 Trunk *trunk;
00456                 void *data;
00457                 char **argv;
00458                 char *error;
00459                 timeout_t duration;
00460                 trunkstep_t step;
00461                 char dn[8];
00462                 dspmode_t dsp;
00463                 long crn;
00464         } parm;
00465 } TrunkEvent;
00466 
00467 #pragma pack(1)
00468 
00469 typedef struct {
00470         time_t  update;
00471         char name[16];
00472         struct in_addr addr;
00473         unsigned char version;
00474         unsigned char buddies;
00475         unsigned char ports;
00476         char stat[255];
00477 }       statnode_t;
00478 
00479 #pragma pack()
00480 
00481 /* This is used to bind user defined "functions" which may be loaded
00482    in a DSO module.
00483 */
00484 
00485 typedef char *(*functioncall_t)(scriptsymbol_t *sym, char **args);
00486 
00487 typedef struct
00488 {
00489         char *name;
00490         functioncall_t function;
00491 } FUNCTIONS;
00492 
00493 
00494 bool getLogical(const char *string);
00495 
00503 class CallStat : public Mutex
00504 {
00505 protected:
00506         int capacity;
00507         struct
00508         {
00509                 int incoming;
00510                 int outgoing;
00511         }       active, max, lastmax;
00512 
00513         struct
00514         {
00515                 long incoming;
00516                 long outgoing;
00517         }       total, lasttotal;
00518 
00519 public:
00520         CallStat();
00521 
00527         inline int getCapacity(void)
00528                 {return capacity;};
00529 
00536         long getStat(statitem_t item);
00537 
00541         void incIncoming(void);
00542 
00546         void decIncoming(void);
00547 
00551         void incOutgoing(void);
00552 
00556         void decOutgoing(void);
00557 
00561         void Update(void);
00562 };
00563 
00576 class Translator : protected Keydata
00577 {
00578 private:
00579         friend Translator *getTranslator(char *name);
00580         static Translator *first;
00581         Translator *next;
00582 
00583 protected:
00589         virtual char *getName(void) = 0;
00590 
00597         char *getPlayBuffer(Trunk *trunk);
00598 
00599         void scanDir(const char *etcdir, const char *language, const char *lib);
00600 
00601         Translator(const char *conf, const char *lib);
00602 
00603 public:
00611         virtual char *Speak(Trunk *trunk) = 0;
00612 };
00613 
00627 class Functions
00628 {
00629 protected:
00635         virtual char *getName(void) = 0;
00636 
00642         void Load(FUNCTIONS *map);
00643 };
00644 
00645 /* Bayonne config file istanciation classes.  In Bayonne these are
00646    created as keydata objects out of bayonne.conf during process
00647    startup automatically.  This is Bayonne runtime configuration magic.
00648 */
00649 
00656 class KeyTones : protected Keydata
00657 {
00658 public:
00662         KeyTones();
00663 };
00664 
00672 class KeyLocal : public Keydata
00673 {
00674 public:
00678         KeyLocal();
00679 };
00680 
00687 class KeyHandlers : public Keydata
00688 {
00689 public:
00693         KeyHandlers();
00694 };
00695 
00703 class KeyImports : public Keydata
00704 {
00705 public:
00709         KeyImports();
00710 };
00711 
00719 class KeyPaths : public Keydata
00720 {
00721 public:
00725         KeyPaths();
00726 
00730         inline const char *getLibexec(void)
00731                 {return getLast("libexec");};
00732 
00736         inline const char *getTgipath(void)
00737                 {return getLast("tgipath");};
00738 
00742         inline const char *getLibpath(void)
00743                 {return getLast("libpath");};
00744 
00748         inline const char *getDatafiles(void)
00749                 {return getLast("datafiles");};
00750 
00754         inline const char *getWrappers(void)
00755                 {return getLast("wrappers");};
00756 
00760         inline const char *getRunfiles(void)
00761                 {return getLast("runfiles");};
00762 
00766         inline const char *getSpool(void)
00767                 {return getLast("spool");};
00768 
00772         inline const char *getScriptFiles(void)
00773                 {return getLast("scripts");};
00774 
00778         inline const char *getPromptFiles(void)
00779                 {return getLast("prompts");};
00780 
00784         inline const char *getCache(void)
00785                 {return getLast("precache");};
00786 };
00787 
00795 class KeyNetwork : public Keydata
00796 {
00797 public:
00801         KeyNetwork();
00802 
00808         unsigned getRefresh(void)
00809                 {return atoi(getLast("refresh"));};
00810 
00816         unsigned getTimeToLive(void)
00817                 {return atoi(getLast("live"));};
00818 
00824         unsigned getTimeToElect(void)
00825                 {return atoi(getLast("elect"));};
00826 
00832         unsigned getTimeToExpire(void)
00833                 {return atoi(getLast("expire"));};
00834 
00840         InetHostAddress getBroadcast(void);
00841 
00847         InetAddress getAddress(void);
00848 
00854         tpport_t getPort(void);
00855 
00861         InetHostAddress getDBHost(void);
00862 
00868         tpport_t getDBPort(void);
00869 };
00870 
00877 class KeyProxy : public Keydata
00878 {
00879 public:
00883         KeyProxy();
00884 
00890         const char *getHTTPServer(void);
00891 
00897         tpport_t getHTTPPort(void);
00898 
00905         timeout_t getTimeout(void);
00906 };      
00907 
00915 class KeyMailbox : public Keydata
00916 {
00917 public:
00921         KeyMailbox();
00922 
00928         inline unsigned getCount(void)
00929                 {return atoi(getLast("count"));};
00930 
00936         inline unsigned getLimit(void)
00937                 {return atoi(getLast("limit"));};
00938 
00945         inline unsigned getQuota(void)
00946                 {return atoi(getLast("quota"));};
00947 
00953         inline unsigned getMinimum(void)
00954                 {return atoi(getLast("minimum"));};
00955 
00961         inline unsigned getMaximum(void)
00962                 {return atoi(getLast("maximum"));};
00963 
00969         inline const char *getPassword(void)
00970                 {return getLast("password");};
00971 };
00972 
00981 class KeyMemory : public Keydata
00982 {
00983 public:
00987         KeyMemory();
00988 
00994         inline int getSymbolSize(void)
00995                 {return atoi(getLast("symbols"));};
00996 
01003         inline int getPageSize(void)
01004                 {return atoi(getLast("page"));};
01005 };
01006 
01014 class KeyFeed : public Keydata
01015 {
01016 public:
01020         KeyFeed();
01021 
01027         inline unsigned getBuffers(void)
01028                 {return atoi(getLast("buffers"));};
01029 };
01030 
01031 
01039 class KeyThreads : public Keydata
01040 {
01041 public:
01045         KeyThreads();
01046 
01052         inline int priService(void)
01053                 {return atoi(getLast("services"));};
01054 
01060         inline int priScheduler(void)
01061                 {return atoi(getLast("scheduler"));};
01062 
01068         inline int priGUI(void)
01069                 {return atoi(getLast("gui"));};
01070 
01076         inline int priRTP(void)
01077                 {return atoi(getLast("rtp"));};
01078 
01084         inline int getStepDelay(void)
01085                 {return atoi(getLast("stepdelay"));};
01086 
01092         inline int getStepInterval(void)
01093                 {return atoi(getLast("stepinterval"));};
01094 
01100         inline int getResetDelay(void)
01101                 {return atoi(getLast("resetdelay"));};
01102 
01108         size_t getStack(void);
01109 
01115         int getServices(void);
01116 
01122         int priResolver(void);
01123 
01130         int getResolver(void);
01131 
01137         inline int priAudio(void)
01138                 {return atoi(getLast("audio"));};
01139 
01145         inline int priFeed(void)
01146                 {return atoi(getLast("feed"));};
01147 
01153         inline bool getAudit(void)
01154                 {return getLogical(getLast("audit"));};
01160         inline int priGateway(void)
01161                 {return atoi(getLast("gateways"));};
01162 
01168         inline int priManager(void)
01169                 {return atoi(getLast("managers"));};
01170 
01176         inline int priNetwork(void)
01177                 {return atoi(getLast("network"));};
01178 
01184         inline int priXML(void)
01185                 {return atoi(getLast("xml"));};
01186 
01192         inline int getInterval(void)
01193                 {return atoi(getLast("interval"));};
01194 
01200         inline int getRefresh(void)
01201                 {return atoi(getLast("refresh"));};
01202 
01208         int getGateways(void);
01209         
01216         inline int getPriority(void)
01217                 {return atoi(getLast("priority"));};
01218 
01224         int getPolicy(void);
01225 
01231         inline int getPages(void)
01232                 {return atoi(getLast("pages"));};
01233 };
01234 
01242 class Auditdata : public Keydata
01243 {
01244 private:
01245         friend class Audit;
01246 
01247         Auditdata();
01248 };
01249 
01258 class Policy
01259 {
01260 private:
01261         friend class TrunkGroup;
01262 
01263         Policy *next;
01264         TrunkGroup *group;
01265 
01266 protected:
01267         Policy(TrunkGroup *grp);
01268         
01269         virtual Request *loPriority(void)
01270                 {return NULL;};
01271 
01272         virtual Request *hiPriority(void)
01273                 {return NULL;};
01274 };
01275 
01285 class Request
01286 {
01287 private:
01288         friend class TrunkGroup;
01289 
01290         static unsigned seq;
01291 
01292         unsigned id;
01293         Request *next;
01294         time_t expires;
01295         TrunkGroup *group;
01296 
01297         char *argv[33];
01298         char buffer[512];
01299         char tagid[65];
01300 
01301         void Detach(void);
01302 
01303 public:
01304         Request(TrunkGroup *grp, const char *text, unsigned expire, const char *tag = NULL);
01305         ~Request()
01306                 {Detach();};
01307 
01308         inline char **getList(void)
01309                 {return argv;};
01310 
01311         inline char *getTag(void)
01312                 {return tagid;};
01313 
01314         bool isExpired(void);
01315 
01316         friend void cancel(TrunkGroup *group, const char *tag);
01317         friend Request *request(TrunkGroup *group, char **argv, unsigned timeout, const char *tag = NULL);
01318         friend Request *locate(TrunkGroup *group, const char *tag, int *pos);
01319 };
01320 
01331 class TrunkGroup : public Keydata, public CallStat
01332 {
01333 private:
01334         friend class KeyServer;
01335         friend class Scheduler;
01336         friend class Audit;
01337         friend class TestDebug;
01338         friend class Request;
01339         friend class Policy;
01340         friend class Trunk;
01341         static TrunkGroup *first;
01342         TrunkGroup *next;
01343         char schedule[65];
01344         char planned[65];
01345         unsigned trump;
01346         Request *reqfirst, *reqlast;
01347         Policy *polFirst;
01348         unsigned members;
01349 
01350         void setSchedule(const char *str);
01351 
01352         friend inline const char *getGroups(void)
01353                 {return TrunkGroup::first->getLast("groups");};
01354 
01355         friend void cancel(TrunkGroup *group, const char *tag);
01356         friend Request *locate(TrunkGroup *group, const char *tag, int *pos = NULL);
01357 
01358 
01359 public:
01365         TrunkGroup(char *name = NULL);
01366 
01372         inline const char *getName(void)
01373                 {return getLast("name");};
01374 
01380         inline unsigned getAnswer(void)
01381                 {return atoi(getLast("answer"));};
01382 
01388         bool getAccept(void);
01389 
01395         bool getDetect(void);
01396 
01402         inline unsigned getCallerid(void)
01403                 {return atoi(getLast("callerid"));};
01404 
01410         inline unsigned getPickup(void)
01411                 {return atoi(getLast("pickup"));};
01412 
01418         inline const char *chkRequest(void)
01419                 {return getLast("requests");};
01420 
01426         seltype_t getSelect(void);
01427 
01433         inline unsigned getThreashold(void)
01434                 {return atoi(getLast("threashold"));};
01435 
01441         inline unsigned getAnalysis(void)
01442                 {return atoi(getLast("analysis"));};
01443 
01450         inline timeout_t getReady(void)
01451                 {return atol(getLast("ready"));};
01452         
01458         inline unsigned getIdleTime(void)
01459                 {return atoi(getLast("idletime"));};
01460 
01466         inline unsigned getSiezeTime(void)
01467                 {return atoi(getLast("siezetime"));};
01468 
01474         inline unsigned getRingTime(void)
01475                 {return atoi(getLast("ringtime"));};
01476 
01482         inline int getHangup(void)
01483                 {return atoi(getLast("hangup"));};
01484 
01490         inline timeout_t getFlash(void)
01491                 {return atol(getLast("flash"));};
01492 
01498         inline timeout_t getDialtone(void)
01499                 {return atol(getLast("dialtone"));};
01500 
01506         inline timeout_t getDialspeed(void)
01507                 {return atol(getLast("dialspeed"));};
01508 
01515         const char *getNumber(void);
01516 
01523         const char *getSchedule(char *buf);
01524 
01534         const char *getRedirect(const char *redirect, char *buf);
01535 
01539         inline void incCapacity(void)
01540                 {++capacity;};
01541 
01547         Request *getRequest(void);
01548 
01554         friend TrunkGroup *getGroup(const char *name);
01555 };
01556 
01564 class KeyServer : public Keydata
01565 {
01566 private:
01567         unsigned uid, gid;
01568         const char *altdir;
01569         const char *phrdir;
01570 
01571 public:
01575         KeyServer();
01576 
01582         inline const char *getNode(void)
01583                 {return getLast("node");};
01584 
01590         inline const char *getPassword(void)
01591                 {return getLast("password");};
01592 
01598         inline const char *getToken(void)
01599                 {return getLast("token");};
01600 
01604         void loadGroups(bool test);
01605 
01611         inline const char *getDefault(void)
01612                 {return getLast("default");};
01613 
01619         inline unsigned getGid(void)
01620                 {return gid;};
01621 
01627         inline unsigned getUid(void)
01628                 {return uid;};
01629 
01633         void setUid(void);
01634 
01638         void setGid(void);
01639 
01645         inline int getNodeCount(void)
01646                 {return atoi(getLast("nodes"));};
01647 
01653         inline const char *getPrefix(void)
01654                 {return altdir;};
01655 
01661         inline const char *getPhrases(void)
01662                 {return phrdir;};
01663 };
01664 
01672 class Plugins : public Keydata
01673 {
01674 private:
01675         unsigned pidcount;
01676         int pids[32];
01677 
01678 public:
01682         Plugins();
01683 
01687         ~Plugins();
01688 
01694         char *getDriverName(void);
01695 
01699         void loadXML(void);
01700 
01704         void loadDebug(void);
01705 
01710         DSO *loadDriver(void);
01711 
01715         void loadExtensions(void);
01716 
01720         void loadPreload(void);
01721 
01725         void loadMaps(void);
01726 
01730         void loadModules(void);
01731 
01735         void loadServices(void);
01736 
01740         void loadFeeds(void);
01741 
01745         void loadTGI(void);
01746 
01750         void loadManagers(void);
01751 
01755         void loadTranslators(void);
01756 
01760         void loadAuditing(void);
01761 };
01762 
01771 class aaScript : public ScriptCommand 
01772 {
01773 private:
01774         friend class Functions;
01775 
01776 #pragma pack(1)
01777         typedef struct _functions
01778         {
01779                 struct _functions *next;
01780                 functioncall_t function;
01781                 char name[1];
01782         }       functions_t;
01783 #pragma pack()
01784 
01785         functions_t *functions[KEYWORD_INDEX_SIZE];
01786 
01787 protected:
01795         unsigned long getTrapMask(const char *trapname);
01796 
01804         void addFunction(char *name, functioncall_t function);
01805 
01806 public:
01813         functioncall_t getFunction(char *name);
01814 
01818         aaScript();
01819 
01825         void addModule(Module *module);
01826 
01832         void addDummy(const char *names);
01833 };
01834 
01844 class aaImage : public ScriptImage
01845 {
01846 protected:
01854         virtual bool isScript(char *scriptname);
01855 
01862         void scanDir(char *path);
01863 
01864 public:
01868         aaImage(aaScript *script);
01869 };
01870 
01877 class Mixer : protected Mutex
01878 {
01879 private:
01880         friend class Conference;
01881         void addGroup(void);
01882         void delGroup(void);
01883 
01884 protected:
01885         Mixer();
01886         unsigned avail, members, groups;
01887 
01888 public:
01889         unsigned getAvail(void)
01890                 {return avail;};
01891 
01892         unsigned getMembers(void)
01893                 {return members;};
01894 
01895         unsigned getGroups(void)
01896                 {return groups;};
01897 
01898         virtual bool setMixer(int groups, int members) = 0;
01899 
01900         virtual Conference *getConference(int group) = 0;
01901 };
01902 
01911 class Conference : protected Mutex
01912 {
01913 protected:
01914         Mixer *mixer;
01915         unsigned limit;
01916         unsigned members;
01917         int *membership;
01918 
01919         virtual ~Conference();
01920 
01921         Conference(Mixer *m);
01922 public:
01923         inline virtual Mixer *getMixer(void)
01924                 {return mixer;};
01925 
01926         int *getMembership(void)
01927                 {return membership;};
01928 
01929         Trunk *getTrunk(unsigned member);
01930 
01931         unsigned getMembers(void)
01932                 {return members;};
01933 
01934         unsigned getLimit(void)
01935                 {return limit;};
01936 
01937         virtual bool setConference(unsigned max) = 0;
01938 };
01939 
01947 class TrunkImage : public ScriptImage, protected URLStream, protected XMLStream
01948 {
01949 private:
01950         char *attrib[65];
01951 
01952         int Read(unsigned char *buffer, int len);
01953 
01954 protected:
01955         void Close(void)
01956                 {return URLStream::Close();};
01957 
01958         typedef struct
01959         {
01960                 scriptname_t *script;
01961                 scriptline_t *last;
01962                 unsigned line;
01963                 unsigned long addmask, submask, trapmask;
01964                 unsigned char loopid[65], looplevel[65];
01965                 unsigned trap;
01966                 void *data;     // extra state data in derived use
01967         } compile_t;
01968 
01969         compile_t *main, *current;
01970 
01976         void getCompile(const char *name = "#");
01977 
01983         void setCompile(unsigned trap);
01984 
01990         void putCompile(compile_t *cc);
01991 
01999         void addCompile(unsigned long mask, const char *cmd, const char **args);
02000 
02006         void setToken(const unsigned char **attrib);
02007 
02013         const char *getToken(void);
02014 
02020         virtual unsigned long getDefaultMask(void)
02021                 {return 3;};
02022 
02031         const char *getAttribute(const char *key, const char *value = NULL);
02032         
02033 public:
02037         TrunkImage();
02038 
02039         virtual ~TrunkImage()
02040                 {Purge();};
02041 
02048         void setProxy(const char *addr, tpport_t port)
02049                 {URLStream::setProxy(addr, port);};
02050 
02059         virtual bool Loader(trunkdata_t *data) = 0;
02060 
02064         void Purge(void);
02065 
02072         void *alloc(unsigned size) 
02073                 {return MemPager::alloc(size);};
02074 };
02075 
02085 class Trunk : public ScriptInterp
02086 {
02087 private:
02088         friend class TestDebug;
02089         friend class aaScript;
02090         friend class Translator;
02091         friend class ScriptInterface;
02092         friend class Service;
02093         friend class AudioService;
02094         friend class Fifo;
02095         friend class PortManager;
02096 
02097         unsigned member;
02098         char *cdrv[33];
02099         int cdrc;
02100         numbersymbol_t numbers[5];
02101         TrunkImage *altimage;
02102 
02103         bool scrStart(void);
02104         bool scrRequest(void);
02105         bool scrLibexec(void);
02106         bool scrHangup(void);
02107         bool scrDebug(void);
02108         bool scrImport(void);
02109         bool scrExport(void);
02110         bool scrFunction(void);
02111         bool scrAlog(void);
02112         bool scrAudit(void);
02113         bool scrPause(void);
02114         bool scrSleep(void);
02115         bool scrSync(void);
02116         bool scrTone(void);
02117         bool scrAnswer(void);
02118         bool scrAccept(void);
02119         bool scrReject(void);
02120         bool scrCollect(void);
02121         bool scrFlash(void);
02122         bool scrSay(void);
02123         bool scrCleardigits(void);
02124         bool scrAssign(void);
02125         bool scrInsert(void);
02126         bool scrDelete(void);
02127         bool scrReplace(void);
02128         bool scrPrefix(void);
02129         bool scrChop(void);
02130         bool scrTrim(void);
02131         bool scrPlay(void);
02132         bool scrSend(void);
02133         bool scrLoad(void);
02134         bool scrRecord(void);
02135         bool scrDial(void);
02136         bool scrDTMF(void);
02137         bool scrTransfer(void);
02138         bool scrHold(void);
02139         bool scrSpeak(void);
02140         bool scrMap(void);
02141         bool scrModule(void);
02142         bool scrDummy(void);
02143         bool scrSchedule(void);
02144         bool scrSignal(void);
02145         bool scrIdle(void);
02146 
02147         scriptname_t *getScriptImage(const char *name);
02148 
02149 protected:
02150         static ScriptSymbol globals;
02151         static char digit[16];
02152         ScriptInterface *script;
02153         TrunkGroup *group;
02154         PortManager *manager;
02155         int id;
02156         time_t start, idle;
02157 
02158         int idle_timer;
02159         int rings;
02160         int digits;
02161 
02162         Service *thread;
02163         trunkdata_t data;
02164         execdata_t tgi;
02165         digitsymbol_t dtmf;
02166         char buffer[65];
02167 
02168         struct
02169         {
02170                 bool offhook: 1;
02171                 bool dtmf: 1;
02172                 bool script: 1;
02173                 bool reset: 1;
02174                 bool timer : 1;
02175                 bool audio: 1;
02176                 bool once : 1;
02177                 bool ready : 1;
02178                 bool echo : 1;
02179                 unsigned temp : 1;
02180                 trunkmode_t trunk: 2;
02181                 dspmode_t dsp: 4;
02182         } flags;
02183 
02189         unsigned long getTrapDefault(void)
02190                 {return 0x00000007;};
02191 
02200         void setConstant(const char *id, const char *data);
02201 
02208         void repSymbol(const char *id, const char *data);
02209 
02217         scriptsymbol_t *getEntry(const char *symname, int size);
02218 
02224         void Commit(scriptsymbol_t *sym);
02225 
02235         timeout_t getTimeout(void);
02236 
02243         timeout_t getInterdigit(void);
02244 
02250         unsigned short getDigitMask(void);
02251 
02257         bool TrunkSignal(trunksignal_t);
02258 
02265         virtual void setDTMFDetect(void);
02266 
02275         virtual void setDTMFDetect(bool enable)
02276                 {flags.dtmf = enable;};
02277 
02283         virtual void stopServices(void);
02284 
02295         virtual void TrunkStep(trunkstep_t step) = 0;
02296 
02302         bool idleHangup();
02303 
02310         virtual unsigned long getIdleTime(void) = 0;
02311 
02315         bool ScriptStep(void);
02316 
02325         bool Attach(const char *scrname);
02326 
02331         void Detach(void);
02332 
02336         unsigned long getMask(void);
02337 
02344         char **getInitial(char **args);
02345 
02352         void setList(char **list);
02353 
02357         virtual void Accept(void)
02358                 {return;};
02359 
02363         virtual void Reject(void)
02364                 {return;};
02365 
02366         Trunk(int port);
02367 public:
02373         virtual unsigned long getCapabilities(void)
02374                 {return TRUNK_CAP_VOICE | TRUNK_CAP_DIAL;};
02375 
02381         virtual void getName(char *buffer) = 0;
02382 
02390         virtual bool postEvent(TrunkEvent *event) = 0;
02391 
02397         int getDigit(char digit);
02398 
02404         bool isReady(void);
02405 
02413         void libexec(char **argv, unsigned timeout);
02414 
02422         void libtts(const char *msg, ttsmode_t mode);
02423 
02427         inline bool getOnce(void)
02428                 {return ScriptInterp::getOnce();};
02429 
02435         inline unsigned getMemberId(void)
02436                 {return member;};
02437 
02438 };
02439 
02448 class PortManager
02449 {
02450 private:
02451         Trunk *trunk;
02452 
02453 protected:
02454         ~PortManager()
02455                 {trunk->manager = NULL;};
02456 
02462         PortManager(Trunk *trk);
02463 
02469         inline void postStep(trunkstep_t step)
02470                 {trunk->TrunkStep(step);};
02471 
02478         inline bool postEvent(TrunkEvent *event)
02479                 {return trunk->postEvent(event);};
02480 
02486         inline trunkdata_t *getData(void)
02487                 {return &trunk->data;};
02488 
02494         inline execdata_t *getExec(void)
02495                 {return &trunk->tgi;};
02496 public:
02500         virtual bool Step(void) = 0;
02501 
02507         virtual unsigned long getMask(void) = 0;
02508         
02515         virtual bool postSignal(trunksignal_t signal) = 0;
02516 
02523         virtual bool postAccept(const char *name) = 0;
02524 
02528         virtual void postDetach(void) = 0;
02529 };
02530 
02540 class Fifo : public fifostream, public Mutex
02541 {
02542 protected:
02543         char schedule[33];
02544 
02545         bool exitPid(char **args);
02546         bool waitPid(char **args);
02547         bool setSymbol(char **argv);
02548         bool putSymbol(char **argv);
02549 
02550         bool login(char **argv);
02551         bool startScript(char **argv);
02552         bool ringScript(char **argv);
02553         bool redirectScript(char **argv);
02554         bool busyLine(char **argv);
02555         bool idleLine(char **argv);
02556         bool hangupLine(char **argv);
02557         bool reqScript(char **argv);
02558         bool setSchedule(char **argv);
02559         bool postKey(char **argv);
02560         bool setMixer(char **argv);
02561         bool setLimit(char **argv);
02562         bool mapFiles(char **argv);
02563         bool submit(char **argv);
02564         bool reload(char **argv);
02565 
02566 public:
02575         bool Command(const char *cmdstring, ostream *fd = NULL);
02576 };
02577 
02591 class Audit : public Mutex
02592 {
02593 private:
02594         friend void audit(Trunk *trunk, char *detail);
02595         friend void alog(Trunk *trunk, char *detail);
02596         friend class Scheduler;
02597 
02598         static Audit *first;
02599         Audit *next;
02600 
02601 protected:
02602         static Auditdata keys;
02603 
02609         virtual void ReportAudit(Trunk *trunk, char *detail) = 0;
02610 
02616         virtual void ReportCDR(Trunk *trunk, char *detail)
02617                 {ReportAudit(trunk, detail);};
02618 
02622         virtual void ReportStats(void)
02623                 {return;};
02624 
02630         inline TrunkGroup *getFirst(void)
02631                 {return TrunkGroup::first;};
02632 
02639         inline TrunkGroup *getNext(TrunkGroup *grp)
02640                 {return grp->next;};
02641 
02645         Audit();
02646 };
02647 
02655 class Driver : public aaScript
02656 {
02657 protected:
02658         friend class TrunkGroup;
02659 
02660         TrunkGroup **groups;
02661         char *status;
02662         bool active;
02663 
02664 public:
02668         Driver();
02669 
02676         virtual int Start(void) = 0;
02677 
02681         virtual void Stop(void) = 0;
02682 
02688         void getStatus(char *buffer);
02689 
02696         virtual aaImage *getImage(void);
02697 
02704         virtual int getTrunkCount(void) = 0;
02705 
02712         virtual int getTrunkUsed(void) 
02713                 {return getTrunkCount();};
02714 
02721         TrunkGroup *getTrunkGroup(int id)
02722                 {return groups[id];}; 
02723 
02731         int getTrunkMember(TrunkGroup *grp, unsigned member);
02732         
02738         virtual Trunk *getTrunkPort(int id) = 0;
02739 
02745         virtual Conference *getConference(int id)
02746                 {return NULL;};
02747 
02753         virtual Mixer *getMixer(int id)
02754                 {return NULL;};
02755 
02761         virtual unsigned getMixers(void)
02762                 {return 0;};
02763 
02769         virtual unsigned getGroups(void)
02770                 {return 0;};
02771 };
02772 
02779 class Debug : protected Mutex
02780 {
02781 public:
02785         Debug();
02786 
02792         virtual bool DebugTest(void)
02793                 {return false;};
02794 
02798         virtual void DebugEvent(Trunk *trunk, TrunkEvent *event)
02799                 {return;};
02800 
02804         virtual void DebugState(Trunk *trunk, char *state)
02805                 {return;};
02806 
02810         virtual void DebugService(Trunk *trunk, char *msg)
02811                 {return;};
02812 
02816         virtual void DebugScript(Trunk *trunk, char *msg)
02817                 {return;};
02818 
02822         virtual void DebugStep(Trunk *trunk, scriptline_t *line)
02823                 {DebugState(trunk, "step");};
02824 
02828         virtual bool DebugFifo(char **argv)
02829                 {return true;};
02830 };
02831 
02838 class AudioService
02839 {
02840 private: 
02841         char filename[256];
02842 
02843 protected:
02844         Trunk *trunk;
02851         char *getPrompt(char *name);
02852 
02858         char *getPlayfile(void);
02859 
02863         AudioService(void);
02864 };
02865 
02873 class Service : public Semaphore, public Thread, public AudioService
02874 {
02875 protected:
02876         volatile bool stopped;
02877         trunkdata_t *data;
02878         TrunkGroup *group;
02879 
02883         void Success(void);
02884 
02888         void Failure(void);
02889 
02893         inline void dspReset(void)
02894                 {trunk->flags.reset = true;};
02895 
02899         inline void setAudio(void)
02900                 {trunk->flags.audio = true;};
02901 
02905         inline void clrAudio(void)
02906                 {trunk->flags.audio = false;};
02907 
02908 public:
02915         Service(Trunk *trunk, int pri);
02916 
02923         virtual timeout_t Stop(void);
02924 
02932         virtual bool isExiting(void)
02933                 {return true;};
02934 
02938         void endService(void)
02939                 {Terminate();};
02940 
02944         virtual ~Service()
02945                 {Terminate();}
02946 };
02947 
02955 class XMLService : public Service
02956 {
02957 private:
02958         void Run(void);
02959 
02960 public:
02961         XMLService(Trunk *trk);
02962         ~XMLService();
02963 };
02964 
02974 class Server : public Thread
02975 {
02976 private:
02977         static Server *first;
02978         Server *next;
02979         friend void startServers(void);
02980         friend void stopServers(void);
02981 
02982 protected:
02983         Server(int pri);
02984 
02988         virtual void Stop(void)
02989                 {Terminate();};
02990 };
02991 
02998 class Sync
02999 {
03000 private:
03001         friend class Scheduler;
03002 
03003         static Sync *first;
03004         Sync *next;
03005         time_t runtime;
03006 
03007 protected:
03011         Sync(void);
03012 
03017         virtual bool isScheduled(void)
03018                 {return true;};
03019 
03024         virtual unsigned getInterval(void)
03025                 {return 10;};
03026 
03030         virtual void Schedule(void) = 0;
03031 
03035         virtual char *getSyncName(void) = 0;
03036 };
03037 
03046 class phTone
03047 {
03048 private:
03049         friend phTone *getphTone(const char *name);
03050         static phTone *first;
03051         static int ulaw[256];
03052         phTone *next;
03053         char name[33];
03054         unsigned char *samples;
03055         timeout_t duration;
03056         unsigned freq1, freq2;
03057 
03058         static unsigned char linear2ulaw(int sample);
03059 
03060 public:
03068         phTone(const char *name, timeout_t duration, unsigned f);
03069 
03078         phTone(const char *name, timeout_t duration, unsigned f1, unsigned f2);
03079 
03080         ~phTone();
03081 
03087         void Clear(void);
03088 
03094         inline unsigned char *getSamples(void)
03095                 {return samples;};
03096 
03102         inline timeout_t getDuration(void)
03103                 {return duration;};
03104 };
03105 
03112 class TGI
03113 {
03114 private:
03115         static TGI *first;
03116         TGI *next;
03117 
03118 protected:
03119         TGI();
03120 
03128         virtual bool getExtension(char *ext)
03129                 {return false;};
03130 
03131 public:
03141         virtual void Script(char *cmd, char **args)
03142                 {return;};
03143 
03152         virtual int Parse(int fd, int port, char *cmd)
03153                 {return -1;};   
03154 
03155         friend void getInterp(char *cmd, char **args);
03156         friend TGI *getInterp(char *cmd);
03157 };
03158 
03159 extern Module *tts, *asr;
03160 
03170 class Module
03171 {
03172 private:
03173         friend class Fifo;
03174         friend class AudioService;
03175         friend class TrunkGroup;
03176         friend class Network;
03177         friend class aaImage;
03178 
03179         static Module *modFirst, *sesFirst, *cmdFirst, *urlFirst, *reqFirst, *netFirst;
03180         Module *modNext, *sesNext, *cmdNext, *urlNext, *reqNext, *netNext;
03181 
03182 protected:
03183         Module();
03184 
03185         inline Module *getFirst(void)
03186                 {return modFirst;};
03187 
03193         virtual const char *getExtension(void)
03194                 {return NULL;};
03195 
03201         virtual modtype_t getType(void) = 0;
03202 
03206         void addSession(void);
03207 
03211         void addCommand(void);
03212 
03216         void addPrompts(void);
03217 
03221         void addNetwork(void);
03222 
03226         void addRequest(void);
03227         
03231         inline void enableTTS(void)
03232                 {tts = this;};
03233 
03237         inline void enableASR(void)
03238                 {asr = this;};
03239 
03240 
03241 
03245         virtual char *getPrompt(const char *original)
03246                 {return NULL;};
03247 
03251         virtual void Expires(Request *request)
03252                 {return;};
03253 
03257         virtual void Running(Request *request)
03258                 {return;};
03259 
03263         virtual void Cancelled(Request *request)
03264                 {return;};
03265 
03275         virtual int Accept(char *buffer, socklen_t len, statnode_t *node)
03276                 {return 0;};
03277 
03283         virtual void Failover(statnode_t *node)
03284                 {return;};
03285 
03289         virtual void Broadcast(void)
03290                 {return;};
03291 
03292         friend void broadcast(char *msgbuf, unsigned msglen);
03293         friend void cancel(TrunkGroup *grp, const char *tag);
03294 public:
03295         inline Module *getNext(void)
03296                 {return modNext;};
03297 
03303         virtual char *getName(void) = 0;
03304 
03312         virtual char *Dispatch(Trunk *trunk)
03313                 {return NULL;};
03314 
03322         virtual unsigned Sleep(Trunk *trunk)
03323                 {return 0;};
03324 
03331         virtual void Detach(Trunk *trunk)
03332                 {return;};
03333 
03341         virtual void Attach(Trunk *trunk)
03342                 {return;};
03343 
03350         virtual TrunkImage *getXML(void)
03351                 {return NULL;};
03352 
03360         virtual AudioSample *getPhrase(Trunk *trunk, const char *phrase)
03361                 {return NULL;};
03362 
03373         virtual const char *getSpeech(Trunk *trunk, char **domain, unsigned long mask, AudioSample *sample)
03374                 {return NULL;};
03375 
03379         virtual void Reload(void)
03380                 {return;};
03381 
03385         virtual bool Command(char **argv, ostream *out)
03386                 {return false;};
03387 
03388         friend Module *getModule(modtype_t mod, const char *name = NULL);
03389         friend void detachModules(Trunk *trunk);
03390         friend void attachModules(Trunk *trunk);
03391 };
03392 
03402 class Session
03403 {
03404 private:
03405         friend class Scheduler;
03406         static Mutex mutex;
03407         static Session *first;
03408         static Session *last;
03409         Session *next, *prev;
03410         static void Clean(void);
03411 
03412 protected:
03413         Session();
03414         virtual ~Session()
03415                 {Unlink();};
03416 
03420         void Unlink(void);
03421 
03428         virtual time_t getExpires(void) = 0;
03429 };
03430 
03439 class AudioFeed : private ThreadLock
03440 {
03441 private:
03442         static AudioFeed *first;
03443         AudioFeed *next;
03444         unsigned char *buffers;
03445         volatile unsigned char *current;
03446         size_t feedsize, bufsize;
03447         bool active;
03448 
03449 protected:
03450         const char *name;
03451 
03452 public:
03453         AudioFeed(const char *name, unsigned buffers);
03454         ~AudioFeed();
03455         bool Enable(void);
03456         void Disable(void);
03457         unsigned char *getBuffer(unsigned char *prior = NULL, unsigned size = 120);
03458         void putBuffer(unsigned char *buffer, unsigned size = 120);
03459 
03460         friend AudioFeed *getAudioFeed(const char *name);
03461 };
03462 
03471 class Map : private MemPager
03472 {
03473 private:
03474         static ThreadLock lock;
03475         static Map *first, *last;
03476 
03477         typedef struct _sym
03478         {
03479                 struct _sym *next;
03480                 char *key;
03481                 char **values;
03482         }       mapsym_t;
03483 
03484         typedef struct
03485         {
03486                 mapsym_t *keys[127];
03487         } mapkey_t;
03488 
03489         mapkey_t *digits[32];
03490 
03491         Map *next, *prev;
03492         char *name;
03493 
03494         unsigned getKey(const char *key, unsigned len = 0);
03495         char **getList(const char *key, unsigned len);
03496         ~Map();
03497 
03498 public:
03499         Map(const char *path, const char *name);
03500 
03501         friend char **getMap(const char *map, const char *key, mapmode_t  mode);
03502         friend void endMaps(void);
03503 };
03504 
03513 class Protocol : public Keydata, public InetHostAddress, public ThreadLock
03514 {
03515 private:
03516         friend class Resolver;
03517         static Protocol *first;
03518         Protocol *next;
03519         Semaphore *sessions;
03520         tpport_t port;
03521 
03522         void Update(InetHostAddress addr);
03523 public:
03524         Protocol(const char *keypath, tpport_t port);
03525         ~Protocol();
03526 
03532         InetHostAddress getAddress(void);
03533 
03539         inline tpport_t getPort(void)
03540                 {return port;};
03541 
03548         inline Semaphore *getSessions(void)
03549                 {return sessions;};
03550 };
03551 
03552 statnode_t *getNodes(const char *name);
03553 timeout_t getTimeout(const char *string);
03554 
03555 extern bool aliases;
03556 extern bool running;
03557 extern Keydata application;
03558 extern KeyServer keyserver;
03559 extern KeyThreads keythreads;
03560 extern KeyMemory keymemory;
03561 extern KeyPaths keypaths;
03562 extern KeyImports keyimports;
03563 extern KeyLocal keylocal;
03564 extern KeyNetwork keynetwork;
03565 extern KeyMailbox keymailbox;
03566 extern KeyProxy keyproxy;
03567 extern KeyTones keytones;
03568 extern KeyFeed keyfeed;
03569 extern KeyHandlers keyhandlers;
03570 extern Plugins plugins;
03571 extern Driver *driver;
03572 extern Debug *debug;
03573 extern Module *asr, *tts;
03574 extern Fifo fifo;
03575 #endif
03576 

Generated at Wed Dec 5 09:13:29 2001 for Bayonne by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001