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_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 #ifndef COMMON_TPPORT_TYPE_DEFINED
00060 typedef short   tpport_t;
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_DRIVER
00158 }       trunksignal_t;
00159 
00160 typedef enum {
00161         // primary state handlers
00162 
00163         TRUNK_ENTER_STATE = 100,// newly entered handler state
00164         TRUNK_EXIT_STATE,       // exiting prior state (unused)
00165         TRUNK_STOP_STATE,       // request state termination
00166         TRUNK_NOTIFICATION,     // death notify event
00167         TRUNK_SERVICE_SUCCESS,  // service completion successful
00168         TRUNK_SERVICE_FAILURE,  // service completion failed
00169         TRUNK_SERVICE_LOOKUP,   // lookup transaction
00170         TRUNK_SERVICE_LOGIN,    // login transaction
00171         TRUNK_SIGNAL_NOTIFY,    // signal between trunks
00172         TRUNK_JOIN_TRUNKS,      // join two trunks together
00173         TRUNK_PART_TRUNKS,      // split two trunks that were joined
00174         TRUNK_NULL_EVENT,       // used to push pipe driven systems
00175 
00176         // tgi/integration control state handlers
00177 
00178         TRUNK_EXIT_SHELL = 200, // tgi completion event
00179         TRUNK_START_SCRIPT,     // start of script
00180         TRUNK_RING_START,       // smdi/integrated answer
00181         TRUNK_RING_REDIRECT,    // smdi/integrated answer options
00182         TRUNK_STOP_DISCONNECT,  // integrated hangup notification
00183 
00184         // in the future these will be used
00185 
00186         TRUNK_START_INCOMING = TRUNK_RING_START,
00187         TRUNK_START_OUTGOING = TRUNK_START_SCRIPT,
00188 
00189         // primary "mode" selection controls
00190 
00191         TRUNK_MAKE_TEST =  300, // request driver perform line test
00192         TRUNK_MAKE_BUSY,        // request driver lockout line
00193         TRUNK_MAKE_IDLE,        // request driver reset line
00194         TRUNK_MAKE_STEP,        // pass step event internally
00195 
00196         // basic trunk events
00197 
00198         TRUNK_LINE_WINK = 400,  // used for line disconnect notification
00199         TRUNK_TIMER_EXPIRED,    // driver specific port timer expired
00200         TRUNK_RINGING_ON,       // some drivers distinguish start/stop
00201         TRUNK_RINGING_OFF,      // default ring event
00202         TRUNK_TEST_IDLE,        // some drivers have line test completion
00203         TRUNK_TEST_FAILURE,     // some drivers notify errors
00204         TRUNK_ON_HOOK,          // some drivers notify on hook
00205         TRUNK_OFF_HOOK,         // some drivers notify off hook
00206         TRUNK_CALLER_ID,        // caller id parse request
00207         TRUNK_RINGING_DID,      // did digit ring signal
00208         TRUNK_CALL_DETECT,      // ISDN call detected notification
00209         TRUNK_CALL_CONNECT,     // ISDN call connection notification
00210         TRUNK_CALL_RELEASE,     // ISDN call release notification
00211         TRUNK_CALL_ACCEPT,      // ISDN incoming call accepted
00212         TRUNK_CALL_ANSWERED,    // ISDN connect sent to the network
00213         TRUNK_CALL_HOLD,        // ISDN call placed on hold
00214         TRUNK_CALL_NOHOLD,      // ISDN call hold was rejected
00215         TRUNK_CALL_DIGITS,      // requested digits received
00216         TRUNK_CALL_OFFER,       // ISDN call offered
00217         TRUNK_CALL_ANI,         // ANI received
00218         TRUNK_CALL_ACTIVE,      // ISDN call taken off hold
00219         TRUNK_CALL_NOACTIVE,    // ISDN call hold retrieve failed
00220         TRUNK_CALL_BILLING,     // ISDN call billing acknowledge
00221         TRUNK_CALL_RESTART,     // ISDN call restart, success or failure
00222         TRUNK_CALL_SETSTATE,    // ISDN acknowledge state change
00223         TRUNK_CALL_FAILURE,     // ISDN midcall failure
00224         TRUNK_CALL_ALERTING,    // ISDN call alerting
00225         TRUNK_CALL_INFO,        // ISDN call info message
00226         TRUNK_CALL_BUSY,        // ISDN conjestion message
00227         TRUNK_CALL_DIVERT,      // ISDN call diversion notification
00228         TRUNK_CALL_FACILITY,    // ISDN call facility
00229         TRUNK_CALL_FRAME,       // ISDN call frame
00230         TRUNK_CALL_NOTIFY,      // ISDN call notify
00231         TRUNK_CALL_NSI,         // ISDN call nsi message
00232         TRUNK_CALL_RINGING,     // digital T1 incoming call
00233         TRUNK_CALL_DISCONNECT,  // digital T1 circuit break
00234 
00235         // basic audio processing events
00236 
00237         TRUNK_AUDIO_IDLE = 500, // audio reset or completion event
00238         TRUNK_INPUT_PENDING,    // some drivers monitor audio i/o status
00239         TRUNK_OUTPUT_PENDING,   // some drivers monitor audio i/p status
00240         TRUNK_AUDIO_BUFFER,     // some drivers return audio buffers
00241         TRUNK_TONE_IDLE,        // tone generator completion event
00242         TRUNK_DTMF_KEYDOWN,     // some drivers distinguish tone down
00243         TRUNK_DTMF_KEYUP,       // default dtmf event
00244         TRUNK_TONE_START,       // tone detected
00245         TRUNK_TONE_STOP,        // some drivers have tone completion event
00246         TRUNK_FSK_DETECT,       // fsk tone detect
00247         TRUNK_FAX_DETECT,       // fax tone detect
00248         TRUNK_VOX_DETECT,       // speaker detected
00249         TRUNK_AUDIO_START,      // some drivers may "vox" compress
00250         TRUNK_AUDIO_STOP,       // some drivers may "vox" compress
00251         TRUNK_CPA_DIALTONE,     // dialtone heard on the line
00252         TRUNK_CPA_BUSYTONE,
00253         TRUNK_CPA_RINGING,
00254         TRUNK_CPA_RINGBACK = TRUNK_CPA_RINGING,
00255         TRUNK_CPA_INTERCEPT,
00256         TRUNK_CPA_NODIALTONE,
00257         TRUNK_CPA_NORINGBACK,
00258         TRUNK_CPA_NOANSWER,
00259         TRUNK_CPA_CONNECT,
00260         TRUNK_CPA_FAILURE,
00261         TRUNK_DSP_READY,        // dsp resource became available
00262 
00263         // driver specific events and anomolies
00264 
00265         TRUNK_DRIVER_SPECIFIC=8000      // very oddball events
00266 } trunkevent_t;
00267 
00268 typedef enum
00269 {
00270         DSP_MODE_INACTIVE = 0,  // dsp is idle
00271         DSP_MODE_VOICE,         // standard voice processing
00272         DSP_MODE_CALLERID,      // caller id support
00273         DSP_MODE_DATA,          // fsk modem mode
00274         DSP_MODE_FAX,           // fax support
00275         DSP_MODE_TDM,           // TDM bus with echo cancellation
00276         DSP_MODE_RTP,           // VoIP full duplex
00277         DSP_MODE_DUPLEX,        // mixed play/record
00278         DSP_MODE_JOIN,          // support of joined channels
00279         DSP_MODE_CONF,          // in conference
00280         DSP_MODE_TONE           // tone processing
00281 } dspmode_t;
00282 
00283 typedef enum
00284 {
00285         TRUNK_MODE_INCOMING = 0,
00286         TRUNK_MODE_OUTGOING,
00287         TRUNK_MODE_INACTIVE,
00288         TRUNK_MODE_UNAVAILABLE
00289 } trunkmode_t;
00290  
00291 typedef enum
00292 {
00293         STAT_MAX_INCOMING,
00294         STAT_MAX_OUTGOING,
00295         STAT_TOT_INCOMING,
00296         STAT_TOT_OUTGOING,
00297         STAT_ACTIVE_CALLS
00298 } statitem_t;
00299 
00300 typedef enum
00301 {
00302         PLAY_MODE_NORMAL,
00303         PLAY_MODE_ONE,
00304         PLAY_MODE_ANY,
00305         PLAY_MODE_TEMP
00306 } playmode_t;
00307 
00308 typedef enum
00309 {
00310         TTS_GATEWAY_TEXT,
00311         TTS_GATEWAY_FILE
00312 } ttsmode_t;
00313 
00314 #define TRUNK_CAP_VOICE         0x00000001
00315 #define TRUNK_CAP_DIAL          0x00000002
00316 #define TRUNK_CAP_SENDFAX       0x00000004
00317 #define TRUNK_CAP_RECVFAX       0x00000008
00318 #define TRUNK_CAP_DATA          0x00000010
00319 #define TRUNK_CAP_TTS           0x00000020
00320 #define TRUNK_CAP_ASR           0x00000040
00321 
00322 typedef union
00323 {
00324         scriptsymbol_t sym;
00325         char data[sizeof(scriptsymbol_t) + 12];
00326 }       numbersymbol_t;
00327 
00328 typedef union
00329 {
00330         scriptsymbol_t bin;
00331         char data[sizeof(scriptsymbol_t) + 32];
00332 }       digitsymbol_t;
00333 
00334 typedef struct
00335 {
00336         
00337         int pid;
00338         unsigned seq;
00339         void *data;
00340 }       execdata_t;
00341 
00342 typedef union
00343 {
00344         struct
00345         {
00346                 int rings;
00347                 int timeout;
00348         }       answer;
00349         struct
00350         {
00351                 char list[256];
00352                 char *name;
00353                 unsigned long offset;
00354                 unsigned long limit;
00355                 unsigned char volume;
00356                 unsigned short term;
00357                 playmode_t mode;
00358                 timeout_t timeout;
00359                 unsigned repeat;
00360         }       play;
00361         struct
00362         {
00363                 char *name;
00364                 timeout_t timeout;
00365                 unsigned long offset;
00366                 unsigned short term;
00367                 unsigned char volume;
00368                 unsigned long trim;
00369                 bool append;
00370         }       record;
00371         struct
00372         {
00373                 char digits[65];
00374                 char *digit;
00375                 timeout_t interdigit;
00376                 bool exit;
00377                 timeout_t timeout;
00378                 timeout_t offhook;
00379                 timeout_t onhook;
00380         }       dialxfer;
00381         struct
00382         {
00383                 timeout_t timeout;
00384                 unsigned count;
00385                 unsigned short term;
00386                 unsigned short ignore;
00387         }       collect;
00388         struct
00389         {
00390                 timeout_t wakeup;
00391                 unsigned rings;
00392                 unsigned loops;
00393         }       sleep;
00394         struct
00395         {
00396                 timeout_t wakeup;
00397                 unsigned loops;
00398                 phTone *tone;
00399         }       tone;
00400         struct
00401         {
00402                 timeout_t wakeup;
00403                 Trunk *trunk;
00404                 phTone *tone;
00405         }       join;
00406         struct
00407         {
00408                 struct in_addr addr;
00409                 unsigned short bind, port, term;
00410                 audioencoding_t codec;
00411         }       rtp;
00412         struct
00413         {
00414                 TrunkImage *image;
00415                 const char *url;
00416                 const char *section;
00417                 char **vars;
00418                 bool post;
00419                 timeout_t timeout;
00420         }       load;
00421 }       trunkdata_t;
00422 
00423 typedef struct
00424 {
00425         trunkevent_t id;        // event id
00426         union
00427         {
00428                 struct
00429                 {
00430                         unsigned digit: 4;
00431                         unsigned duration: 12;
00432                         unsigned e1: 8;
00433                         unsigned e2: 8;
00434                 } dtmf;
00435                 struct
00436                 {
00437                         unsigned tone: 8;
00438                         unsigned energy: 8;
00439                         unsigned duration: 16;
00440                 } tone;
00441                 struct
00442                 {
00443                         unsigned digit:  4;
00444                         unsigned duration: 24;
00445                 } ring;
00446                 struct
00447                 {
00448                         unsigned seq;
00449                         bool result;
00450                         char *data;
00451                 } lookup;
00452                 bool ok;
00453                 int status;
00454                 Trunk *trunk;
00455                 void *data;
00456                 char **argv;
00457                 char *error;
00458                 timeout_t duration;
00459                 trunkstep_t step;
00460                 char dn[8];
00461                 dspmode_t dsp;
00462         } parm;
00463 } TrunkEvent;
00464 
00465 #pragma pack(1)
00466 
00467 typedef struct {
00468         time_t  update;
00469         char name[16];
00470         struct in_addr addr;
00471         unsigned char version;
00472         unsigned char buddies;
00473         unsigned char ports;
00474         char stat[255];
00475 }       statnode_t;
00476 
00477 #pragma pack()
00478 
00479 /* This is used to bind user defined "functions" which may be loaded
00480    in a DSO module.
00481 */
00482 
00483 typedef char *(*functioncall_t)(scriptsymbol_t *sym, char **args);
00484 
00485 typedef struct
00486 {
00487         char *name;
00488         functioncall_t function;
00489 } FUNCTIONS;
00490 
00491 
00492 bool getLogical(const char *string);
00493 
00501 class CallStat : public Mutex
00502 {
00503 protected:
00504         int capacity;
00505         struct
00506         {
00507                 int incoming;
00508                 int outgoing;
00509         }       active, max, lastmax;
00510 
00511         struct
00512         {
00513                 long incoming;
00514                 long outgoing;
00515         }       total, lasttotal;
00516 
00517 public:
00518         CallStat();
00519 
00525         inline int getCapacity(void)
00526                 {return capacity;};
00527 
00534         long getStat(statitem_t item);
00535 
00539         void incIncoming(void);
00540 
00544         void decIncoming(void);
00545 
00549         void incOutgoing(void);
00550 
00554         void decOutgoing(void);
00555 
00559         void Update(void);
00560 };
00561 
00574 class Translator : protected Keydata
00575 {
00576 private:
00577         friend Translator *getTranslator(char *name);
00578         static Translator *first;
00579         Translator *next;
00580 
00581 protected:
00587         virtual char *getName(void) = 0;
00588 
00595         char *getPlayBuffer(Trunk *trunk);
00596 
00597         void scanDir(const char *etcdir, const char *language, const char *lib);
00598 
00599         Translator(const char *conf, const char *lib);
00600 
00601 public:
00609         virtual char *Speak(Trunk *trunk) = 0;
00610 };
00611 
00625 class Functions
00626 {
00627 protected:
00633         virtual char *getName(void) = 0;
00634 
00640         void Load(FUNCTIONS *map);
00641 };
00642 
00643 /* Bayonne config file istanciation classes.  In Bayonne these are
00644    created as keydata objects out of bayonne.conf during process
00645    startup automatically.  This is Bayonne runtime configuration magic.
00646 */
00647 
00654 class KeyTones : protected Keydata
00655 {
00656 public:
00660         KeyTones();
00661 };
00662 
00670 class KeyLocal : public Keydata
00671 {
00672 public:
00676         KeyLocal();
00677 };
00678 
00685 class KeyHandlers : public Keydata
00686 {
00687 public:
00691         KeyHandlers();
00692 };
00693 
00701 class KeyImports : public Keydata
00702 {
00703 public:
00707         KeyImports();
00708 };
00709 
00717 class KeyPaths : public Keydata
00718 {
00719 public:
00723         KeyPaths();
00724 
00728         inline const char *getLibexec(void)
00729                 {return getLast("libexec");};
00730 
00734         inline const char *getTgipath(void)
00735                 {return getLast("tgipath");};
00736 
00740         inline const char *getLibpath(void)
00741                 {return getLast("libpath");};
00742 
00746         inline const char *getDatafiles(void)
00747                 {return getLast("datafiles");};
00748 
00752         inline const char *getWrappers(void)
00753                 {return getLast("wrappers");};
00754 
00758         inline const char *getRunfiles(void)
00759                 {return getLast("runfiles");};
00760 
00764         inline const char *getSpool(void)
00765                 {return getLast("spool");};
00766 
00770         inline const char *getScriptFiles(void)
00771                 {return getLast("scripts");};
00772 
00776         inline const char *getPromptFiles(void)
00777                 {return getLast("prompts");};
00778 
00782         inline const char *getCache(void)
00783                 {return getLast("precache");};
00784 };
00785 
00793 class KeyNetwork : public Keydata
00794 {
00795 public:
00799         KeyNetwork();
00800 
00806         unsigned getRefresh(void)
00807                 {return atoi(getLast("refresh"));};
00808 
00814         unsigned getTimeToLive(void)
00815                 {return atoi(getLast("live"));};
00816 
00822         unsigned getTimeToElect(void)
00823                 {return atoi(getLast("elect"));};
00824 
00830         unsigned getTimeToExpire(void)
00831                 {return atoi(getLast("expire"));};
00832 
00838         InetHostAddress getBroadcast(void);
00839 
00845         InetAddress getAddress(void);
00846 
00852         tpport_t getPort(void);
00853 
00859         InetHostAddress getDBHost(void);
00860 
00866         tpport_t getDBPort(void);
00867 };
00868 
00875 class KeyProxy : public Keydata
00876 {
00877 public:
00881         KeyProxy();
00882 
00888         const char *getHTTPServer(void);
00889 
00895         tpport_t getHTTPPort(void);
00896 
00903         timeout_t getTimeout(void);
00904 };      
00905 
00913 class KeyMailbox : public Keydata
00914 {
00915 public:
00919         KeyMailbox();
00920 
00926         inline unsigned getCount(void)
00927                 {return atoi(getLast("count"));};
00928 
00934         inline unsigned getLimit(void)
00935                 {return atoi(getLast("limit"));};
00936 
00943         inline unsigned getQuota(void)
00944                 {return atoi(getLast("quota"));};
00945 
00951         inline unsigned getMinimum(void)
00952                 {return atoi(getLast("minimum"));};
00953 
00959         inline unsigned getMaximum(void)
00960                 {return atoi(getLast("maximum"));};
00961 
00967         inline const char *getPassword(void)
00968                 {return getLast("password");};
00969 };
00970 
00979 class KeyMemory : public Keydata
00980 {
00981 public:
00985         KeyMemory();
00986 
00992         inline int getSymbolSize(void)
00993                 {return atoi(getLast("symbols"));};
00994 
01001         inline int getPageSize(void)
01002                 {return atoi(getLast("page"));};
01003 };
01004 
01012 class KeyFeed : public Keydata
01013 {
01014 public:
01018         KeyFeed();
01019 
01025         inline unsigned getBuffers(void)
01026                 {return atoi(getLast("buffers"));};
01027 };
01028 
01029 
01037 class KeyThreads : public Keydata
01038 {
01039 public:
01043         KeyThreads();
01044 
01050         inline int priService(void)
01051                 {return atoi(getLast("services"));};
01052 
01058         inline int priScheduler(void)
01059                 {return atoi(getLast("scheduler"));};
01060 
01066         inline int priGUI(void)
01067                 {return atoi(getLast("gui"));};
01068 
01074         inline int priRTP(void)
01075                 {return atoi(getLast("rtp"));};
01076 
01082         inline int getStepDelay(void)
01083                 {return atoi(getLast("stepdelay"));};
01084 
01090         inline int getStepInterval(void)
01091                 {return atoi(getLast("stepinterval"));};
01092 
01098         inline int getResetDelay(void)
01099                 {return atoi(getLast("resetdelay"));};
01100 
01106         size_t getStack(void);
01107 
01113         int getServices(void);
01114 
01120         int priResolver(void);
01121 
01128         int getResolver(void);
01129 
01135         inline int priAudio(void)
01136                 {return atoi(getLast("audio"));};
01137 
01143         inline int priFeed(void)
01144                 {return atoi(getLast("feed"));};
01145 
01151         inline bool getAudit(void)
01152                 {return getLogical(getLast("audit"));};
01158         inline int priGateway(void)
01159                 {return atoi(getLast("gateways"));};
01160 
01166         inline int priManager(void)
01167                 {return atoi(getLast("managers"));};
01168 
01174         inline int priNetwork(void)
01175                 {return atoi(getLast("network"));};
01176 
01182         inline int priXML(void)
01183                 {return atoi(getLast("xml"));};
01184 
01190         inline int getInterval(void)
01191                 {return atoi(getLast("interval"));};
01192 
01198         inline int getRefresh(void)
01199                 {return atoi(getLast("refresh"));};
01200 
01206         int getGateways(void);
01207         
01214         inline int getPriority(void)
01215                 {return atoi(getLast("priority"));};
01216 
01222         int getPolicy(void);
01223 
01229         inline int getPages(void)
01230                 {return atoi(getLast("pages"));};
01231 };
01232 
01240 class Auditdata : public Keydata
01241 {
01242 private:
01243         friend class Audit;
01244 
01245         Auditdata();
01246 };
01247 
01256 class Policy
01257 {
01258 private:
01259         friend class TrunkGroup;
01260 
01261         Policy *next;
01262         TrunkGroup *group;
01263 
01264 protected:
01265         Policy(TrunkGroup *grp);
01266         
01267         virtual Request *loPriority(void)
01268                 {return NULL;};
01269 
01270         virtual Request *hiPriority(void)
01271                 {return NULL;};
01272 };
01273 
01283 class Request
01284 {
01285 private:
01286         friend class TrunkGroup;
01287 
01288         static unsigned seq;
01289 
01290         unsigned id;
01291         Request *next;
01292         time_t expires;
01293         TrunkGroup *group;
01294 
01295         char *argv[33];
01296         char buffer[512];
01297         char tagid[65];
01298 
01299         void Detach(void);
01300 
01301 public:
01302         Request(TrunkGroup *grp, const char *text, unsigned expire, const char *tag = NULL);
01303         ~Request()
01304                 {Detach();};
01305 
01306         inline char **getList(void)
01307                 {return argv;};
01308 
01309         inline char *getTag(void)
01310                 {return tagid;};
01311 
01312         bool isExpired(void);
01313 
01314         friend void cancel(TrunkGroup *group, const char *tag);
01315         friend Request *request(TrunkGroup *group, char **argv, unsigned timeout, const char *tag = NULL);
01316         friend Request *locate(TrunkGroup *group, const char *tag, int *pos);
01317 };
01318 
01329 class TrunkGroup : public Keydata, public CallStat
01330 {
01331 private:
01332         friend class KeyServer;
01333         friend class Scheduler;
01334         friend class Audit;
01335         friend class TestDebug;
01336         friend class Request;
01337         friend class Policy;
01338         friend class Trunk;
01339         static TrunkGroup *first;
01340         TrunkGroup *next;
01341         char schedule[65];
01342         char planned[65];
01343         unsigned trump;
01344         Request *reqfirst, *reqlast;
01345         Policy *polFirst;
01346         unsigned members;
01347 
01348         void setSchedule(const char *str);
01349 
01350         friend inline const char *getGroups(void)
01351                 {return TrunkGroup::first->getLast("groups");};
01352 
01353         friend void cancel(TrunkGroup *group, const char *tag);
01354         friend Request *locate(TrunkGroup *group, const char *tag, int *pos = NULL);
01355 
01356 
01357 public:
01363         TrunkGroup(char *name = NULL);
01364 
01370         inline const char *getName(void)
01371                 {return getLast("name");};
01372 
01378         inline unsigned getAnswer(void)
01379                 {return atoi(getLast("answer"));};
01380 
01386         bool getDetect(void);
01387 
01393         inline unsigned getCallerid(void)
01394                 {return atoi(getLast("callerid"));};
01395 
01401         inline unsigned getPickup(void)
01402                 {return atoi(getLast("pickup"));};
01403 
01409         inline const char *chkRequest(void)
01410                 {return getLast("requests");};
01411 
01417         seltype_t getSelect(void);
01418 
01424         inline unsigned getThreashold(void)
01425                 {return atoi(getLast("threashold"));};
01426 
01432         inline unsigned getAnalysis(void)
01433                 {return atoi(getLast("analysis"));};
01434 
01441         inline timeout_t getReady(void)
01442                 {return atol(getLast("ready"));};
01443         
01449         inline unsigned getIdleTime(void)
01450                 {return atoi(getLast("idletime"));};
01451 
01457         inline unsigned getSiezeTime(void)
01458                 {return atoi(getLast("siezetime"));};
01459 
01465         inline unsigned getRingTime(void)
01466                 {return atoi(getLast("ringtime"));};
01467 
01473         inline int getHangup(void)
01474                 {return atoi(getLast("hangup"));};
01475 
01481         inline timeout_t getFlash(void)
01482                 {return atol(getLast("flash"));};
01483 
01489         inline timeout_t getDialtone(void)
01490                 {return atol(getLast("dialtone"));};
01491 
01497         inline timeout_t getDialspeed(void)
01498                 {return atol(getLast("dialspeed"));};
01499 
01506         const char *getNumber(void);
01507 
01514         const char *getSchedule(char *buf);
01515 
01525         const char *getRedirect(const char *redirect, char *buf);
01526 
01530         inline void incCapacity(void)
01531                 {++capacity;};
01532 
01538         Request *getRequest(void);
01539 
01545         friend TrunkGroup *getGroup(const char *name);
01546 };
01547 
01555 class KeyServer : public Keydata
01556 {
01557 private:
01558         unsigned uid, gid;
01559         const char *altdir;
01560         const char *phrdir;
01561 
01562 public:
01566         KeyServer();
01567 
01573         inline const char *getNode(void)
01574                 {return getLast("node");};
01575 
01581         inline const char *getPassword(void)
01582                 {return getLast("password");};
01583 
01589         inline const char *getToken(void)
01590                 {return getLast("token");};
01591 
01595         void loadGroups(bool test);
01596 
01602         inline const char *getDefault(void)
01603                 {return getLast("default");};
01604 
01610         inline unsigned getGid(void)
01611                 {return gid;};
01612 
01618         inline unsigned getUid(void)
01619                 {return uid;};
01620 
01624         void setUid(void);
01625 
01629         void setGid(void);
01630 
01636         inline int getNodeCount(void)
01637                 {return atoi(getLast("nodes"));};
01638 
01644         inline const char *getPrefix(void)
01645                 {return altdir;};
01646 
01652         inline const char *getPhrases(void)
01653                 {return phrdir;};
01654 };
01655 
01663 class Plugins : public Keydata
01664 {
01665 public:
01669         Plugins();
01670 
01674         ~Plugins();
01675 
01681         char *getDriverName(void);
01682 
01686         void loadXML(void);
01687 
01691         void loadDebug(void);
01692 
01697         DSO *loadDriver(void);
01698 
01702         void loadExtensions(void);
01703 
01707         void loadPreload(void);
01708 
01712         void loadMaps(void);
01713 
01717         void loadModules(void);
01718 
01722         void loadServices(void);
01723 
01727         void loadFeeds(void);
01728 
01732         void loadTGI(void);
01733 
01737         void loadManagers(void);
01738 
01742         void loadTranslators(void);
01743 
01747         void loadAuditing(void);
01748 };
01749 
01758 class aaScript : public ScriptCommand 
01759 {
01760 private:
01761         friend class Functions;
01762 
01763 #pragma pack(1)
01764         typedef struct _functions
01765         {
01766                 struct _functions *next;
01767                 functioncall_t function;
01768                 char name[1];
01769         }       functions_t;
01770 #pragma pack()
01771 
01772         functions_t *functions[KEYWORD_INDEX_SIZE];
01773 
01774 protected:
01782         unsigned long getTrapMask(const char *trapname);
01783 
01791         void addFunction(char *name, functioncall_t function);
01792 
01793 public:
01800         functioncall_t getFunction(char *name);
01801 
01805         aaScript();
01806 
01812         void addModule(Module *module);
01813 
01819         void addDummy(const char *names);
01820 };
01821 
01831 class aaImage : public ScriptImage
01832 {
01833 protected:
01841         virtual bool isScript(char *scriptname);
01842 
01849         void scanDir(char *path);
01850 
01851 public:
01855         aaImage(aaScript *script);
01856 };
01857 
01864 class Mixer : protected Mutex
01865 {
01866 private:
01867         friend class Conference;
01868         void addGroup(void);
01869         void delGroup(void);
01870 
01871 protected:
01872         Mixer();
01873         unsigned avail, members, groups;
01874 
01875 public:
01876         unsigned getAvail(void)
01877                 {return avail;};
01878 
01879         unsigned getMembers(void)
01880                 {return members;};
01881 
01882         unsigned getGroups(void)
01883                 {return groups;};
01884 
01885         virtual bool setMixer(int groups, int members) = 0;
01886 
01887         virtual Conference *getConference(int group) = 0;
01888 };
01889 
01898 class Conference : protected Mutex
01899 {
01900 protected:
01901         Mixer *mixer;
01902         unsigned limit;
01903         unsigned members;
01904         int *membership;
01905 
01906         virtual ~Conference();
01907 
01908         Conference(Mixer *m);
01909 public:
01910         inline virtual Mixer *getMixer(void)
01911                 {return mixer;};
01912 
01913         int *getMembership(void)
01914                 {return membership;};
01915 
01916         Trunk *getTrunk(unsigned member);
01917 
01918         unsigned getMembers(void)
01919                 {return members;};
01920 
01921         unsigned getLimit(void)
01922                 {return limit;};
01923 
01924         virtual bool setConference(unsigned max) = 0;
01925 };
01926 
01934 class TrunkImage : public ScriptImage, protected URLStream, protected XMLStream
01935 {
01936 private:
01937         char *attrib[65];
01938 
01939         int Read(unsigned char *buffer, int len);
01940 
01941 protected:
01942         void Close(void)
01943                 {return URLStream::Close();};
01944 
01945         typedef struct
01946         {
01947                 scriptname_t *script;
01948                 scriptline_t *last;
01949                 unsigned line;
01950                 unsigned long addmask, submask, trapmask;
01951                 unsigned char loopid[65], looplevel[65];
01952                 unsigned trap;
01953                 void *data;     // extra state data in derived use
01954         } compile_t;
01955 
01956         compile_t *main, *current;
01957 
01963         void getCompile(const char *name = "#");
01964 
01970         void setCompile(unsigned trap);
01971 
01977         void putCompile(compile_t *cc);
01978 
01986         void addCompile(unsigned long mask, const char *cmd, const char **args);
01987 
01993         void setToken(const unsigned char **attrib);
01994 
02000         const char *getToken(void);
02001 
02007         virtual unsigned long getDefaultMask(void)
02008                 {return 3;};
02009 
02018         const char *getAttribute(const char *key, const char *value = NULL);
02019         
02020 public:
02024         TrunkImage();
02025 
02026         virtual ~TrunkImage()
02027                 {Purge();};
02028 
02035         void setProxy(const char *addr, tpport_t port)
02036                 {URLStream::setProxy(addr, port);};
02037 
02046         virtual bool Loader(trunkdata_t *data) = 0;
02047 
02051         void Purge(void);
02052 
02059         void *alloc(unsigned size) 
02060                 {return MemPager::alloc(size);};
02061 };
02062 
02072 class Trunk : public ScriptInterp
02073 {
02074 private:
02075         friend class TestDebug;
02076         friend class aaScript;
02077         friend class Translator;
02078         friend class ScriptInterface;
02079         friend class Service;
02080         friend class AudioService;
02081         friend class Fifo;
02082         friend class PortManager;
02083 
02084         unsigned member;
02085         char *cdrv[33];
02086         int cdrc;
02087         numbersymbol_t numbers[5];
02088         TrunkImage *altimage;
02089 
02090         bool scrStart(void);
02091         bool scrRequest(void);
02092         bool scrLibexec(void);
02093         bool scrHangup(void);
02094         bool scrDebug(void);
02095         bool scrImport(void);
02096         bool scrExport(void);
02097         bool scrFunction(void);
02098         bool scrAlog(void);
02099         bool scrAudit(void);
02100         bool scrPause(void);
02101         bool scrSleep(void);
02102         bool scrSync(void);
02103         bool scrTone(void);
02104         bool scrAnswer(void);
02105         bool scrCollect(void);
02106         bool scrFlash(void);
02107         bool scrSay(void);
02108         bool scrCleardigits(void);
02109         bool scrAssign(void);
02110         bool scrInsert(void);
02111         bool scrDelete(void);
02112         bool scrReplace(void);
02113         bool scrPrefix(void);
02114         bool scrChop(void);
02115         bool scrTrim(void);
02116         bool scrPlay(void);
02117         bool scrSend(void);
02118         bool scrLoad(void);
02119         bool scrRecord(void);
02120         bool scrDial(void);
02121         bool scrDTMF(void);
02122         bool scrTransfer(void);
02123         bool scrHold(void);
02124         bool scrSpeak(void);
02125         bool scrMap(void);
02126         bool scrModule(void);
02127         bool scrDummy(void);
02128         bool scrSchedule(void);
02129         bool scrSignal(void);
02130         bool scrIdle(void);
02131 
02132         scriptname_t *getScriptImage(const char *name);
02133 
02134 protected:
02135         static ScriptSymbol globals;
02136         static char digit[16];
02137         ScriptInterface *script;
02138         TrunkGroup *group;
02139         PortManager *manager;
02140         int id;
02141         time_t start, idle;
02142 
02143         int idle_timer;
02144         int rings;
02145         int digits;
02146 
02147         Service *thread;
02148         trunkdata_t data;
02149         execdata_t tgi;
02150         digitsymbol_t dtmf;
02151         char buffer[65];
02152 
02153         struct
02154         {
02155                 bool offhook: 1;
02156                 bool dtmf: 1;
02157                 bool script: 1;
02158                 bool reset: 1;
02159                 bool timer : 1;
02160                 bool audio: 1;
02161                 bool once : 1;
02162                 bool ready : 1;
02163                 bool echo : 1;
02164                 unsigned temp : 1;
02165                 trunkmode_t trunk: 2;
02166                 dspmode_t dsp: 4;
02167         } flags;
02168 
02174         unsigned long getTrapDefault(void)
02175                 {return 0x00000007;};
02176 
02185         void setConstant(const char *id, const char *data);
02186 
02193         void repSymbol(const char *id, const char *data);
02194 
02202         scriptsymbol_t *getEntry(const char *symname, int size);
02203 
02209         void Commit(scriptsymbol_t *sym);
02210 
02220         timeout_t getTimeout(void);
02221 
02228         timeout_t getInterdigit(void);
02229 
02235         unsigned short getDigitMask(void);
02236 
02242         bool TrunkSignal(trunksignal_t);
02243 
02250         virtual void setDTMFDetect(void);
02251 
02260         virtual void setDTMFDetect(bool enable)
02261                 {flags.dtmf = enable;};
02262 
02268         virtual void stopServices(void);
02269 
02280         virtual void TrunkStep(trunkstep_t step) = 0;
02281 
02287         bool idleHangup();
02288 
02295         virtual unsigned long getIdleTime(void) = 0;
02296 
02300         bool ScriptStep(void);
02301 
02310         bool Attach(const char *scrname);
02311 
02316         void Detach(void);
02317 
02321         unsigned long getMask(void);
02322 
02329         char **getInitial(char **args);
02330 
02337         void setList(char **list);
02338 
02339         Trunk(int port);
02340 public:
02346         virtual unsigned long getCapabilities(void)
02347                 {return TRUNK_CAP_VOICE | TRUNK_CAP_DIAL;};
02348 
02354         virtual void getName(char *buffer) = 0;
02355 
02363         virtual bool postEvent(TrunkEvent *event) = 0;
02364 
02370         int getDigit(char digit);
02371 
02377         bool isReady(void);
02378 
02386         void libexec(char **argv, unsigned timeout);
02387 
02395         void libtts(const char *msg, ttsmode_t mode);
02396 
02400         inline bool getOnce(void)
02401                 {return ScriptInterp::getOnce();};
02402 
02408         inline unsigned getMemberId(void)
02409                 {return member;};
02410 
02411 };
02412 
02421 class PortManager
02422 {
02423 private:
02424         Trunk *trunk;
02425 
02426 protected:
02427         ~PortManager()
02428                 {trunk->manager = NULL;};
02429 
02435         PortManager(Trunk *trk);
02436 
02442         inline void postStep(trunkstep_t step)
02443                 {trunk->TrunkStep(step);};
02444 
02451         inline bool postEvent(TrunkEvent *event)
02452                 {return trunk->postEvent(event);};
02453 
02459         inline trunkdata_t *getData(void)
02460                 {return &trunk->data;};
02461 
02467         inline execdata_t *getExec(void)
02468                 {return &trunk->tgi;};
02469 public:
02473         virtual bool Step(void) = 0;
02474 
02480         virtual unsigned long getMask(void) = 0;
02481         
02488         virtual bool postSignal(trunksignal_t signal) = 0;
02489 
02496         virtual bool postAccept(const char *name) = 0;
02497 
02501         virtual void postDetach(void) = 0;
02502 };
02503 
02513 class Fifo : public fifostream, public Mutex
02514 {
02515 protected:
02516         char schedule[33];
02517 
02518         bool exitPid(char **args);
02519         bool waitPid(char **args);
02520         bool setSymbol(char **argv);
02521         bool putSymbol(char **argv);
02522 
02523         bool login(char **argv);
02524         bool startScript(char **argv);
02525         bool ringScript(char **argv);
02526         bool redirectScript(char **argv);
02527         bool busyLine(char **argv);
02528         bool idleLine(char **argv);
02529         bool hangupLine(char **argv);
02530         bool reqScript(char **argv);
02531         bool setSchedule(char **argv);
02532         bool postKey(char **argv);
02533         bool setMixer(char **argv);
02534         bool setLimit(char **argv);
02535         bool mapFiles(char **argv);
02536         bool submit(char **argv);
02537         bool reload(char **argv);
02538 
02539 public:
02548         bool Command(const char *cmdstring, ostream *fd = NULL);
02549 };
02550 
02564 class Audit : public Mutex
02565 {
02566 private:
02567         friend void audit(Trunk *trunk, char *detail);
02568         friend void alog(Trunk *trunk, char *detail);
02569         friend class Scheduler;
02570 
02571         static Audit *first;
02572         Audit *next;
02573 
02574 protected:
02575         static Auditdata keys;
02576 
02582         virtual void ReportAudit(Trunk *trunk, char *detail) = 0;
02583 
02589         virtual void ReportCDR(Trunk *trunk, char *detail)
02590                 {ReportAudit(trunk, detail);};
02591 
02595         virtual void ReportStats(void)
02596                 {return;};
02597 
02603         inline TrunkGroup *getFirst(void)
02604                 {return TrunkGroup::first;};
02605 
02612         inline TrunkGroup *getNext(TrunkGroup *grp)
02613                 {return grp->next;};
02614 
02618         Audit();
02619 };
02620 
02628 class Driver : public aaScript
02629 {
02630 protected:
02631         friend class TrunkGroup;
02632 
02633         TrunkGroup **groups;
02634         char *status;
02635         bool active;
02636 
02637 public:
02641         Driver();
02642 
02649         virtual int Start(void) = 0;
02650 
02654         virtual void Stop(void) = 0;
02655 
02661         void getStatus(char *buffer);
02662 
02669         virtual aaImage *getImage(void);
02670 
02677         virtual int getTrunkCount(void) = 0;
02678 
02685         virtual int getTrunkUsed(void) 
02686                 {return getTrunkCount();};
02687 
02694         TrunkGroup *getTrunkGroup(int id)
02695                 {return groups[id];}; 
02696 
02704         int getTrunkMember(TrunkGroup *grp, unsigned member);
02705         
02711         virtual Trunk *getTrunkPort(int id) = 0;
02712 
02718         virtual Conference *getConference(int id)
02719                 {return NULL;};
02720 
02726         virtual Mixer *getMixer(int id)
02727                 {return NULL;};
02728 
02734         virtual unsigned getMixers(void)
02735                 {return 0;};
02736 
02742         virtual unsigned getGroups(void)
02743                 {return 0;};
02744 };
02745 
02752 class Debug : protected Mutex
02753 {
02754 public:
02758         Debug();
02759 
02765         virtual bool DebugTest(void)
02766                 {return false;};
02767 
02771         virtual void DebugEvent(Trunk *trunk, TrunkEvent *event)
02772                 {return;};
02773 
02777         virtual void DebugState(Trunk *trunk, char *state)
02778                 {return;};
02779 
02783         virtual void DebugService(Trunk *trunk, char *msg)
02784                 {return;};
02785 
02789         virtual void DebugScript(Trunk *trunk, char *msg)
02790                 {return;};
02791 
02795         virtual void DebugStep(Trunk *trunk, scriptline_t *line)
02796                 {DebugState(trunk, "step");};
02797 
02801         virtual bool DebugFifo(char **argv)
02802                 {return true;};
02803 };
02804 
02811 class AudioService
02812 {
02813 private: 
02814         char filename[256];
02815 
02816 protected:
02817         Trunk *trunk;
02824         char *getPrompt(char *name);
02825 
02831         char *getPlayfile(void);
02832 
02836         AudioService(void);
02837 };
02838 
02846 class Service : public Semaphore, public Thread, public AudioService
02847 {
02848 protected:
02849         volatile bool stopped;
02850         trunkdata_t *data;
02851         TrunkGroup *group;
02852 
02856         void Success(void);
02857 
02861         void Failure(void);
02862 
02866         inline void dspReset(void)
02867                 {trunk->flags.reset = true;};
02868 
02872         inline void setAudio(void)
02873                 {trunk->flags.audio = true;};
02874 
02878         inline void clrAudio(void)
02879                 {trunk->flags.audio = false;};
02880 
02881 public:
02888         Service(Trunk *trunk, int pri);
02889 
02896         virtual timeout_t Stop(void);
02897 
02905         virtual bool isExiting(void)
02906                 {return true;};
02907 
02911         void endService(void)
02912                 {Terminate();};
02913 
02917         virtual ~Service()
02918                 {Terminate();}
02919 };
02920 
02928 class XMLService : public Service
02929 {
02930 private:
02931         void Run(void);
02932 
02933 public:
02934         XMLService(Trunk *trk);
02935         ~XMLService();
02936 };
02937 
02947 class Server : public Thread
02948 {
02949 private:
02950         static Server *first;
02951         Server *next;
02952         friend void startServers(void);
02953         friend void stopServers(void);
02954 
02955 protected:
02956         Server(int pri);
02957 
02961         virtual void Stop(void)
02962                 {Terminate();};
02963 };
02964 
02971 class Sync
02972 {
02973 private:
02974         friend class Scheduler;
02975 
02976         static Sync *first;
02977         Sync *next;
02978         time_t runtime;
02979 
02980 protected:
02984         Sync(void);
02985 
02990         virtual bool isScheduled(void)
02991                 {return true;};
02992 
02997         virtual unsigned getInterval(void)
02998                 {return 10;};
02999 
03003         virtual void Schedule(void) = 0;
03004 
03008         virtual char *getSyncName(void) = 0;
03009 };
03010 
03019 class phTone
03020 {
03021 private:
03022         friend phTone *getphTone(const char *name);
03023         static phTone *first;
03024         static int ulaw[256];
03025         phTone *next;
03026         char name[33];
03027         unsigned char *samples;
03028         timeout_t duration;
03029         unsigned freq1, freq2;
03030 
03031         static unsigned char linear2ulaw(int sample);
03032 
03033 public:
03041         phTone(const char *name, timeout_t duration, unsigned f);
03042 
03051         phTone(const char *name, timeout_t duration, unsigned f1, unsigned f2);
03052 
03053         ~phTone();
03054 
03060         void Clear(void);
03061 
03067         inline unsigned char *getSamples(void)
03068                 {return samples;};
03069 
03075         inline timeout_t getDuration(void)
03076                 {return duration;};
03077 };
03078 
03085 class TGI
03086 {
03087 private:
03088         static TGI *first;
03089         TGI *next;
03090 
03091 protected:
03092         TGI();
03093 
03101         virtual bool getExtension(char *ext)
03102                 {return false;};
03103 
03104 public:
03114         virtual void Script(char *cmd, char **args)
03115                 {return;};
03116 
03125         virtual int Parse(int fd, int port, char *cmd)
03126                 {return -1;};   
03127 
03128         friend void getInterp(char *cmd, char **args);
03129         friend TGI *getInterp(char *cmd);
03130 };
03131 
03132 extern Module *tts, *asr;
03133 
03143 class Module
03144 {
03145 private:
03146         friend class Fifo;
03147         friend class AudioService;
03148         friend class TrunkGroup;
03149         friend class Network;
03150         friend class aaImage;
03151 
03152         static Module *modFirst, *sesFirst, *cmdFirst, *urlFirst, *reqFirst, *netFirst;
03153         Module *modNext, *sesNext, *cmdNext, *urlNext, *reqNext, *netNext;
03154 
03155 protected:
03156         Module();
03157 
03158         inline Module *getFirst(void)
03159                 {return modFirst;};
03160 
03166         virtual const char *getExtension(void)
03167                 {return NULL;};
03168 
03174         virtual modtype_t getType(void) = 0;
03175 
03179         void addSession(void);
03180 
03184         void addCommand(void);
03185 
03189         void addPrompts(void);
03190 
03194         void addNetwork(void);
03195 
03199         void addRequest(void);
03200         
03204         inline void enableTTS(void)
03205                 {tts = this;};
03206 
03210         inline void enableASR(void)
03211                 {asr = this;};
03212 
03213 
03214 
03218         virtual char *getPrompt(const char *original)
03219                 {return NULL;};
03220 
03224         virtual void Expires(Request *request)
03225                 {return;};
03226 
03230         virtual void Running(Request *request)
03231                 {return;};
03232 
03236         virtual void Cancelled(Request *request)
03237                 {return;};
03238 
03248         virtual int Accept(char *buffer, socklen_t len, statnode_t *node)
03249                 {return 0;};
03250 
03256         virtual void Failover(statnode_t *node)
03257                 {return;};
03258 
03262         virtual void Broadcast(void)
03263                 {return;};
03264 
03265         friend void broadcast(char *msgbuf, unsigned msglen);
03266         friend void cancel(TrunkGroup *grp, const char *tag);
03267 public:
03268         inline Module *getNext(void)
03269                 {return modNext;};
03270 
03276         virtual char *getName(void) = 0;
03277 
03285         virtual char *Dispatch(Trunk *trunk)
03286                 {return NULL;};
03287 
03295         virtual unsigned Sleep(Trunk *trunk)
03296                 {return 0;};
03297 
03304         virtual void Detach(Trunk *trunk)
03305                 {return;};
03306 
03314         virtual void Attach(Trunk *trunk)
03315                 {return;};
03316 
03323         virtual TrunkImage *getXML(void)
03324                 {return NULL;};
03325 
03333         virtual AudioSample *getPhrase(Trunk *trunk, const char *phrase)
03334                 {return NULL;};
03335 
03346         virtual const char *getSpeech(Trunk *trunk, char **domain, unsigned long mask, AudioSample *sample)
03347                 {return NULL;};
03348 
03352         virtual void Reload(void)
03353                 {return;};
03354 
03358         virtual bool Command(char **argv, ostream *out)
03359                 {return false;};
03360 
03361         friend Module *getModule(modtype_t mod, const char *name = NULL);
03362         friend void detachModules(Trunk *trunk);
03363         friend void attachModules(Trunk *trunk);
03364 };
03365 
03375 class Session
03376 {
03377 private:
03378         friend class Scheduler;
03379         static Mutex mutex;
03380         static Session *first;
03381         static Session *last;
03382         Session *next, *prev;
03383         static void Clean(void);
03384 
03385 protected:
03386         Session();
03387         virtual ~Session()
03388                 {Unlink();};
03389 
03393         void Unlink(void);
03394 
03401         virtual time_t getExpires(void) = 0;
03402 };
03403 
03412 class AudioFeed : private ThreadLock
03413 {
03414 private:
03415         static AudioFeed *first;
03416         AudioFeed *next;
03417         unsigned char *buffers;
03418         volatile unsigned char *current;
03419         size_t feedsize, bufsize;
03420         bool active;
03421 
03422 protected:
03423         const char *name;
03424 
03425 public:
03426         AudioFeed(const char *name, unsigned buffers);
03427         ~AudioFeed();
03428         bool Enable(void);
03429         void Disable(void);
03430         unsigned char *getBuffer(unsigned char *prior = NULL, unsigned size = 120);
03431         void putBuffer(unsigned char *buffer, unsigned size = 120);
03432 
03433         friend AudioFeed *getAudioFeed(const char *name);
03434 };
03435 
03444 class Map : private MemPager
03445 {
03446 private:
03447         static ThreadLock lock;
03448         static Map *first, *last;
03449 
03450         typedef struct _sym
03451         {
03452                 struct _sym *next;
03453                 char *key;
03454                 char **values;
03455         }       mapsym_t;
03456 
03457         typedef struct
03458         {
03459                 mapsym_t *keys[127];
03460         } mapkey_t;
03461 
03462         mapkey_t *digits[32];
03463 
03464         Map *next, *prev;
03465         char *name;
03466 
03467         unsigned getKey(const char *key, unsigned len = 0);
03468         char **getList(const char *key, unsigned len);
03469         ~Map();
03470 
03471 public:
03472         Map(const char *path, const char *name);
03473 
03474         friend char **getMap(const char *map, const char *key, mapmode_t  mode);
03475         friend void endMaps(void);
03476 };
03477 
03486 class Protocol : public Keydata, public InetHostAddress, public ThreadLock
03487 {
03488 private:
03489         friend class Resolver;
03490         static Protocol *first;
03491         Protocol *next;
03492         Semaphore *sessions;
03493         tpport_t port;
03494 
03495         void Update(InetHostAddress addr);
03496 public:
03497         Protocol(const char *keypath, tpport_t port);
03498         ~Protocol();
03499 
03505         InetHostAddress getAddress(void);
03506 
03512         inline tpport_t getPort(void)
03513                 {return port;};
03514 
03521         inline Semaphore *getSessions(void)
03522                 {return sessions;};
03523 };
03524 
03525 statnode_t *getNodes(const char *name);
03526 timeout_t getTimeout(const char *string);
03527 
03528 extern bool aliases;
03529 extern bool running;
03530 extern Keydata application;
03531 extern KeyServer keyserver;
03532 extern KeyThreads keythreads;
03533 extern KeyMemory keymemory;
03534 extern KeyPaths keypaths;
03535 extern KeyImports keyimports;
03536 extern KeyLocal keylocal;
03537 extern KeyNetwork keynetwork;
03538 extern KeyMailbox keymailbox;
03539 extern KeyProxy keyproxy;
03540 extern KeyTones keytones;
03541 extern KeyFeed keyfeed;
03542 extern KeyHandlers keyhandlers;
03543 extern Plugins plugins;
03544 extern Driver *driver;
03545 extern Debug *debug;
03546 extern Module *asr, *tts;
03547 extern Fifo fifo;
03548 #endif
03549 

Generated at Mon Oct 1 10:26:05 2001 for Bayonne by doxygen1.2.5 written by Dimitri van Heesch, © 1997-2001