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_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 private:
01666         unsigned pidcount;
01667         int pids[32];
01668 
01669 public:
01673         Plugins();
01674 
01678         ~Plugins();
01679 
01685         char *getDriverName(void);
01686 
01690         void loadXML(void);
01691 
01695         void loadDebug(void);
01696 
01701         DSO *loadDriver(void);
01702 
01706         void loadExtensions(void);
01707 
01711         void loadPreload(void);
01712 
01716         void loadMaps(void);
01717 
01721         void loadModules(void);
01722 
01726         void loadServices(void);
01727 
01731         void loadFeeds(void);
01732 
01736         void loadTGI(void);
01737 
01741         void loadManagers(void);
01742 
01746         void loadTranslators(void);
01747 
01751         void loadAuditing(void);
01752 };
01753 
01762 class aaScript : public ScriptCommand 
01763 {
01764 private:
01765         friend class Functions;
01766 
01767 #pragma pack(1)
01768         typedef struct _functions
01769         {
01770                 struct _functions *next;
01771                 functioncall_t function;
01772                 char name[1];
01773         }       functions_t;
01774 #pragma pack()
01775 
01776         functions_t *functions[KEYWORD_INDEX_SIZE];
01777 
01778 protected:
01786         unsigned long getTrapMask(const char *trapname);
01787 
01795         void addFunction(char *name, functioncall_t function);
01796 
01797 public:
01804         functioncall_t getFunction(char *name);
01805 
01809         aaScript();
01810 
01816         void addModule(Module *module);
01817 
01823         void addDummy(const char *names);
01824 };
01825 
01835 class aaImage : public ScriptImage
01836 {
01837 protected:
01845         virtual bool isScript(char *scriptname);
01846 
01853         void scanDir(char *path);
01854 
01855 public:
01859         aaImage(aaScript *script);
01860 };
01861 
01868 class Mixer : protected Mutex
01869 {
01870 private:
01871         friend class Conference;
01872         void addGroup(void);
01873         void delGroup(void);
01874 
01875 protected:
01876         Mixer();
01877         unsigned avail, members, groups;
01878 
01879 public:
01880         unsigned getAvail(void)
01881                 {return avail;};
01882 
01883         unsigned getMembers(void)
01884                 {return members;};
01885 
01886         unsigned getGroups(void)
01887                 {return groups;};
01888 
01889         virtual bool setMixer(int groups, int members) = 0;
01890 
01891         virtual Conference *getConference(int group) = 0;
01892 };
01893 
01902 class Conference : protected Mutex
01903 {
01904 protected:
01905         Mixer *mixer;
01906         unsigned limit;
01907         unsigned members;
01908         int *membership;
01909 
01910         virtual ~Conference();
01911 
01912         Conference(Mixer *m);
01913 public:
01914         inline virtual Mixer *getMixer(void)
01915                 {return mixer;};
01916 
01917         int *getMembership(void)
01918                 {return membership;};
01919 
01920         Trunk *getTrunk(unsigned member);
01921 
01922         unsigned getMembers(void)
01923                 {return members;};
01924 
01925         unsigned getLimit(void)
01926                 {return limit;};
01927 
01928         virtual bool setConference(unsigned max) = 0;
01929 };
01930 
01938 class TrunkImage : public ScriptImage, protected URLStream, protected XMLStream
01939 {
01940 private:
01941         char *attrib[65];
01942 
01943         int Read(unsigned char *buffer, int len);
01944 
01945 protected:
01946         void Close(void)
01947                 {return URLStream::Close();};
01948 
01949         typedef struct
01950         {
01951                 scriptname_t *script;
01952                 scriptline_t *last;
01953                 unsigned line;
01954                 unsigned long addmask, submask, trapmask;
01955                 unsigned char loopid[65], looplevel[65];
01956                 unsigned trap;
01957                 void *data;     // extra state data in derived use
01958         } compile_t;
01959 
01960         compile_t *main, *current;
01961 
01967         void getCompile(const char *name = "#");
01968 
01974         void setCompile(unsigned trap);
01975 
01981         void putCompile(compile_t *cc);
01982 
01990         void addCompile(unsigned long mask, const char *cmd, const char **args);
01991 
01997         void setToken(const unsigned char **attrib);
01998 
02004         const char *getToken(void);
02005 
02011         virtual unsigned long getDefaultMask(void)
02012                 {return 3;};
02013 
02022         const char *getAttribute(const char *key, const char *value = NULL);
02023         
02024 public:
02028         TrunkImage();
02029 
02030         virtual ~TrunkImage()
02031                 {Purge();};
02032 
02039         void setProxy(const char *addr, tpport_t port)
02040                 {URLStream::setProxy(addr, port);};
02041 
02050         virtual bool Loader(trunkdata_t *data) = 0;
02051 
02055         void Purge(void);
02056 
02063         void *alloc(unsigned size) 
02064                 {return MemPager::alloc(size);};
02065 };
02066 
02076 class Trunk : public ScriptInterp
02077 {
02078 private:
02079         friend class TestDebug;
02080         friend class aaScript;
02081         friend class Translator;
02082         friend class ScriptInterface;
02083         friend class Service;
02084         friend class AudioService;
02085         friend class Fifo;
02086         friend class PortManager;
02087 
02088         unsigned member;
02089         char *cdrv[33];
02090         int cdrc;
02091         numbersymbol_t numbers[5];
02092         TrunkImage *altimage;
02093 
02094         bool scrStart(void);
02095         bool scrRequest(void);
02096         bool scrLibexec(void);
02097         bool scrHangup(void);
02098         bool scrDebug(void);
02099         bool scrImport(void);
02100         bool scrExport(void);
02101         bool scrFunction(void);
02102         bool scrAlog(void);
02103         bool scrAudit(void);
02104         bool scrPause(void);
02105         bool scrSleep(void);
02106         bool scrSync(void);
02107         bool scrTone(void);
02108         bool scrAnswer(void);
02109         bool scrCollect(void);
02110         bool scrFlash(void);
02111         bool scrSay(void);
02112         bool scrCleardigits(void);
02113         bool scrAssign(void);
02114         bool scrInsert(void);
02115         bool scrDelete(void);
02116         bool scrReplace(void);
02117         bool scrPrefix(void);
02118         bool scrChop(void);
02119         bool scrTrim(void);
02120         bool scrPlay(void);
02121         bool scrSend(void);
02122         bool scrLoad(void);
02123         bool scrRecord(void);
02124         bool scrDial(void);
02125         bool scrDTMF(void);
02126         bool scrTransfer(void);
02127         bool scrHold(void);
02128         bool scrSpeak(void);
02129         bool scrMap(void);
02130         bool scrModule(void);
02131         bool scrDummy(void);
02132         bool scrSchedule(void);
02133         bool scrSignal(void);
02134         bool scrIdle(void);
02135 
02136         scriptname_t *getScriptImage(const char *name);
02137 
02138 protected:
02139         static ScriptSymbol globals;
02140         static char digit[16];
02141         ScriptInterface *script;
02142         TrunkGroup *group;
02143         PortManager *manager;
02144         int id;
02145         time_t start, idle;
02146 
02147         int idle_timer;
02148         int rings;
02149         int digits;
02150 
02151         Service *thread;
02152         trunkdata_t data;
02153         execdata_t tgi;
02154         digitsymbol_t dtmf;
02155         char buffer[65];
02156 
02157         struct
02158         {
02159                 bool offhook: 1;
02160                 bool dtmf: 1;
02161                 bool script: 1;
02162                 bool reset: 1;
02163                 bool timer : 1;
02164                 bool audio: 1;
02165                 bool once : 1;
02166                 bool ready : 1;
02167                 bool echo : 1;
02168                 unsigned temp : 1;
02169                 trunkmode_t trunk: 2;
02170                 dspmode_t dsp: 4;
02171         } flags;
02172 
02178         unsigned long getTrapDefault(void)
02179                 {return 0x00000007;};
02180 
02189         void setConstant(const char *id, const char *data);
02190 
02197         void repSymbol(const char *id, const char *data);
02198 
02206         scriptsymbol_t *getEntry(const char *symname, int size);
02207 
02213         void Commit(scriptsymbol_t *sym);
02214 
02224         timeout_t getTimeout(void);
02225 
02232         timeout_t getInterdigit(void);
02233 
02239         unsigned short getDigitMask(void);
02240 
02246         bool TrunkSignal(trunksignal_t);
02247 
02254         virtual void setDTMFDetect(void);
02255 
02264         virtual void setDTMFDetect(bool enable)
02265                 {flags.dtmf = enable;};
02266 
02272         virtual void stopServices(void);
02273 
02284         virtual void TrunkStep(trunkstep_t step) = 0;
02285 
02291         bool idleHangup();
02292 
02299         virtual unsigned long getIdleTime(void) = 0;
02300 
02304         bool ScriptStep(void);
02305 
02314         bool Attach(const char *scrname);
02315 
02320         void Detach(void);
02321 
02325         unsigned long getMask(void);
02326 
02333         char **getInitial(char **args);
02334 
02341         void setList(char **list);
02342 
02343         Trunk(int port);
02344 public:
02350         virtual unsigned long getCapabilities(void)
02351                 {return TRUNK_CAP_VOICE | TRUNK_CAP_DIAL;};
02352 
02358         virtual void getName(char *buffer) = 0;
02359 
02367         virtual bool postEvent(TrunkEvent *event) = 0;
02368 
02374         int getDigit(char digit);
02375 
02381         bool isReady(void);
02382 
02390         void libexec(char **argv, unsigned timeout);
02391 
02399         void libtts(const char *msg, ttsmode_t mode);
02400 
02404         inline bool getOnce(void)
02405                 {return ScriptInterp::getOnce();};
02406 
02412         inline unsigned getMemberId(void)
02413                 {return member;};
02414 
02415 };
02416 
02425 class PortManager
02426 {
02427 private:
02428         Trunk *trunk;
02429 
02430 protected:
02431         ~PortManager()
02432                 {trunk->manager = NULL;};
02433 
02439         PortManager(Trunk *trk);
02440 
02446         inline void postStep(trunkstep_t step)
02447                 {trunk->TrunkStep(step);};
02448 
02455         inline bool postEvent(TrunkEvent *event)
02456                 {return trunk->postEvent(event);};
02457 
02463         inline trunkdata_t *getData(void)
02464                 {return &trunk->data;};
02465 
02471         inline execdata_t *getExec(void)
02472                 {return &trunk->tgi;};
02473 public:
02477         virtual bool Step(void) = 0;
02478 
02484         virtual unsigned long getMask(void) = 0;
02485         
02492         virtual bool postSignal(trunksignal_t signal) = 0;
02493 
02500         virtual bool postAccept(const char *name) = 0;
02501 
02505         virtual void postDetach(void) = 0;
02506 };
02507 
02517 class Fifo : public fifostream, public Mutex
02518 {
02519 protected:
02520         char schedule[33];
02521 
02522         bool exitPid(char **args);
02523         bool waitPid(char **args);
02524         bool setSymbol(char **argv);
02525         bool putSymbol(char **argv);
02526 
02527         bool login(char **argv);
02528         bool startScript(char **argv);
02529         bool ringScript(char **argv);
02530         bool redirectScript(char **argv);
02531         bool busyLine(char **argv);
02532         bool idleLine(char **argv);
02533         bool hangupLine(char **argv);
02534         bool reqScript(char **argv);
02535         bool setSchedule(char **argv);
02536         bool postKey(char **argv);
02537         bool setMixer(char **argv);
02538         bool setLimit(char **argv);
02539         bool mapFiles(char **argv);
02540         bool submit(char **argv);
02541         bool reload(char **argv);
02542 
02543 public:
02552         bool Command(const char *cmdstring, ostream *fd = NULL);
02553 };
02554 
02568 class Audit : public Mutex
02569 {
02570 private:
02571         friend void audit(Trunk *trunk, char *detail);
02572         friend void alog(Trunk *trunk, char *detail);
02573         friend class Scheduler;
02574 
02575         static Audit *first;
02576         Audit *next;
02577 
02578 protected:
02579         static Auditdata keys;
02580 
02586         virtual void ReportAudit(Trunk *trunk, char *detail) = 0;
02587 
02593         virtual void ReportCDR(Trunk *trunk, char *detail)
02594                 {ReportAudit(trunk, detail);};
02595 
02599         virtual void ReportStats(void)
02600                 {return;};
02601 
02607         inline TrunkGroup *getFirst(void)
02608                 {return TrunkGroup::first;};
02609 
02616         inline TrunkGroup *getNext(TrunkGroup *grp)
02617                 {return grp->next;};
02618 
02622         Audit();
02623 };
02624 
02632 class Driver : public aaScript
02633 {
02634 protected:
02635         friend class TrunkGroup;
02636 
02637         TrunkGroup **groups;
02638         char *status;
02639         bool active;
02640 
02641 public:
02645         Driver();
02646 
02653         virtual int Start(void) = 0;
02654 
02658         virtual void Stop(void) = 0;
02659 
02665         void getStatus(char *buffer);
02666 
02673         virtual aaImage *getImage(void);
02674 
02681         virtual int getTrunkCount(void) = 0;
02682 
02689         virtual int getTrunkUsed(void) 
02690                 {return getTrunkCount();};
02691 
02698         TrunkGroup *getTrunkGroup(int id)
02699                 {return groups[id];}; 
02700 
02708         int getTrunkMember(TrunkGroup *grp, unsigned member);
02709         
02715         virtual Trunk *getTrunkPort(int id) = 0;
02716 
02722         virtual Conference *getConference(int id)
02723                 {return NULL;};
02724 
02730         virtual Mixer *getMixer(int id)
02731                 {return NULL;};
02732 
02738         virtual unsigned getMixers(void)
02739                 {return 0;};
02740 
02746         virtual unsigned getGroups(void)
02747                 {return 0;};
02748 };
02749 
02756 class Debug : protected Mutex
02757 {
02758 public:
02762         Debug();
02763 
02769         virtual bool DebugTest(void)
02770                 {return false;};
02771 
02775         virtual void DebugEvent(Trunk *trunk, TrunkEvent *event)
02776                 {return;};
02777 
02781         virtual void DebugState(Trunk *trunk, char *state)
02782                 {return;};
02783 
02787         virtual void DebugService(Trunk *trunk, char *msg)
02788                 {return;};
02789 
02793         virtual void DebugScript(Trunk *trunk, char *msg)
02794                 {return;};
02795 
02799         virtual void DebugStep(Trunk *trunk, scriptline_t *line)
02800                 {DebugState(trunk, "step");};
02801 
02805         virtual bool DebugFifo(char **argv)
02806                 {return true;};
02807 };
02808 
02815 class AudioService
02816 {
02817 private: 
02818         char filename[256];
02819 
02820 protected:
02821         Trunk *trunk;
02828         char *getPrompt(char *name);
02829 
02835         char *getPlayfile(void);
02836 
02840         AudioService(void);
02841 };
02842 
02850 class Service : public Semaphore, public Thread, public AudioService
02851 {
02852 protected:
02853         volatile bool stopped;
02854         trunkdata_t *data;
02855         TrunkGroup *group;
02856 
02860         void Success(void);
02861 
02865         void Failure(void);
02866 
02870         inline void dspReset(void)
02871                 {trunk->flags.reset = true;};
02872 
02876         inline void setAudio(void)
02877                 {trunk->flags.audio = true;};
02878 
02882         inline void clrAudio(void)
02883                 {trunk->flags.audio = false;};
02884 
02885 public:
02892         Service(Trunk *trunk, int pri);
02893 
02900         virtual timeout_t Stop(void);
02901 
02909         virtual bool isExiting(void)
02910                 {return true;};
02911 
02915         void endService(void)
02916                 {Terminate();};
02917 
02921         virtual ~Service()
02922                 {Terminate();}
02923 };
02924 
02932 class XMLService : public Service
02933 {
02934 private:
02935         void Run(void);
02936 
02937 public:
02938         XMLService(Trunk *trk);
02939         ~XMLService();
02940 };
02941 
02951 class Server : public Thread
02952 {
02953 private:
02954         static Server *first;
02955         Server *next;
02956         friend void startServers(void);
02957         friend void stopServers(void);
02958 
02959 protected:
02960         Server(int pri);
02961 
02965         virtual void Stop(void)
02966                 {Terminate();};
02967 };
02968 
02975 class Sync
02976 {
02977 private:
02978         friend class Scheduler;
02979 
02980         static Sync *first;
02981         Sync *next;
02982         time_t runtime;
02983 
02984 protected:
02988         Sync(void);
02989 
02994         virtual bool isScheduled(void)
02995                 {return true;};
02996 
03001         virtual unsigned getInterval(void)
03002                 {return 10;};
03003 
03007         virtual void Schedule(void) = 0;
03008 
03012         virtual char *getSyncName(void) = 0;
03013 };
03014 
03023 class phTone
03024 {
03025 private:
03026         friend phTone *getphTone(const char *name);
03027         static phTone *first;
03028         static int ulaw[256];
03029         phTone *next;
03030         char name[33];
03031         unsigned char *samples;
03032         timeout_t duration;
03033         unsigned freq1, freq2;
03034 
03035         static unsigned char linear2ulaw(int sample);
03036 
03037 public:
03045         phTone(const char *name, timeout_t duration, unsigned f);
03046 
03055         phTone(const char *name, timeout_t duration, unsigned f1, unsigned f2);
03056 
03057         ~phTone();
03058 
03064         void Clear(void);
03065 
03071         inline unsigned char *getSamples(void)
03072                 {return samples;};
03073 
03079         inline timeout_t getDuration(void)
03080                 {return duration;};
03081 };
03082 
03089 class TGI
03090 {
03091 private:
03092         static TGI *first;
03093         TGI *next;
03094 
03095 protected:
03096         TGI();
03097 
03105         virtual bool getExtension(char *ext)
03106                 {return false;};
03107 
03108 public:
03118         virtual void Script(char *cmd, char **args)
03119                 {return;};
03120 
03129         virtual int Parse(int fd, int port, char *cmd)
03130                 {return -1;};   
03131 
03132         friend void getInterp(char *cmd, char **args);
03133         friend TGI *getInterp(char *cmd);
03134 };
03135 
03136 extern Module *tts, *asr;
03137 
03147 class Module
03148 {
03149 private:
03150         friend class Fifo;
03151         friend class AudioService;
03152         friend class TrunkGroup;
03153         friend class Network;
03154         friend class aaImage;
03155 
03156         static Module *modFirst, *sesFirst, *cmdFirst, *urlFirst, *reqFirst, *netFirst;
03157         Module *modNext, *sesNext, *cmdNext, *urlNext, *reqNext, *netNext;
03158 
03159 protected:
03160         Module();
03161 
03162         inline Module *getFirst(void)
03163                 {return modFirst;};
03164 
03170         virtual const char *getExtension(void)
03171                 {return NULL;};
03172 
03178         virtual modtype_t getType(void) = 0;
03179 
03183         void addSession(void);
03184 
03188         void addCommand(void);
03189 
03193         void addPrompts(void);
03194 
03198         void addNetwork(void);
03199 
03203         void addRequest(void);
03204         
03208         inline void enableTTS(void)
03209                 {tts = this;};
03210 
03214         inline void enableASR(void)
03215                 {asr = this;};
03216 
03217 
03218 
03222         virtual char *getPrompt(const char *original)
03223                 {return NULL;};
03224 
03228         virtual void Expires(Request *request)
03229                 {return;};
03230 
03234         virtual void Running(Request *request)
03235                 {return;};
03236 
03240         virtual void Cancelled(Request *request)
03241                 {return;};
03242 
03252         virtual int Accept(char *buffer, socklen_t len, statnode_t *node)
03253                 {return 0;};
03254 
03260         virtual void Failover(statnode_t *node)
03261                 {return;};
03262 
03266         virtual void Broadcast(void)
03267                 {return;};
03268 
03269         friend void broadcast(char *msgbuf, unsigned msglen);
03270         friend void cancel(TrunkGroup *grp, const char *tag);
03271 public:
03272         inline Module *getNext(void)
03273                 {return modNext;};
03274 
03280         virtual char *getName(void) = 0;
03281 
03289         virtual char *Dispatch(Trunk *trunk)
03290                 {return NULL;};
03291 
03299         virtual unsigned Sleep(Trunk *trunk)
03300                 {return 0;};
03301 
03308         virtual void Detach(Trunk *trunk)
03309                 {return;};
03310 
03318         virtual void Attach(Trunk *trunk)
03319                 {return;};
03320 
03327         virtual TrunkImage *getXML(void)
03328                 {return NULL;};
03329 
03337         virtual AudioSample *getPhrase(Trunk *trunk, const char *phrase)
03338                 {return NULL;};
03339 
03350         virtual const char *getSpeech(Trunk *trunk, char **domain, unsigned long mask, AudioSample *sample)
03351                 {return NULL;};
03352 
03356         virtual void Reload(void)
03357                 {return;};
03358 
03362         virtual bool Command(char **argv, ostream *out)
03363                 {return false;};
03364 
03365         friend Module *getModule(modtype_t mod, const char *name = NULL);
03366         friend void detachModules(Trunk *trunk);
03367         friend void attachModules(Trunk *trunk);
03368 };
03369 
03379 class Session
03380 {
03381 private:
03382         friend class Scheduler;
03383         static Mutex mutex;
03384         static Session *first;
03385         static Session *last;
03386         Session *next, *prev;
03387         static void Clean(void);
03388 
03389 protected:
03390         Session();
03391         virtual ~Session()
03392                 {Unlink();};
03393 
03397         void Unlink(void);
03398 
03405         virtual time_t getExpires(void) = 0;
03406 };
03407 
03416 class AudioFeed : private ThreadLock
03417 {
03418 private:
03419         static AudioFeed *first;
03420         AudioFeed *next;
03421         unsigned char *buffers;
03422         volatile unsigned char *current;
03423         size_t feedsize, bufsize;
03424         bool active;
03425 
03426 protected:
03427         const char *name;
03428 
03429 public:
03430         AudioFeed(const char *name, unsigned buffers);
03431         ~AudioFeed();
03432         bool Enable(void);
03433         void Disable(void);
03434         unsigned char *getBuffer(unsigned char *prior = NULL, unsigned size = 120);
03435         void putBuffer(unsigned char *buffer, unsigned size = 120);
03436 
03437         friend AudioFeed *getAudioFeed(const char *name);
03438 };
03439 
03448 class Map : private MemPager
03449 {
03450 private:
03451         static ThreadLock lock;
03452         static Map *first, *last;
03453 
03454         typedef struct _sym
03455         {
03456                 struct _sym *next;
03457                 char *key;
03458                 char **values;
03459         }       mapsym_t;
03460 
03461         typedef struct
03462         {
03463                 mapsym_t *keys[127];
03464         } mapkey_t;
03465 
03466         mapkey_t *digits[32];
03467 
03468         Map *next, *prev;
03469         char *name;
03470 
03471         unsigned getKey(const char *key, unsigned len = 0);
03472         char **getList(const char *key, unsigned len);
03473         ~Map();
03474 
03475 public:
03476         Map(const char *path, const char *name);
03477 
03478         friend char **getMap(const char *map, const char *key, mapmode_t  mode);
03479         friend void endMaps(void);
03480 };
03481 
03490 class Protocol : public Keydata, public InetHostAddress, public ThreadLock
03491 {
03492 private:
03493         friend class Resolver;
03494         static Protocol *first;
03495         Protocol *next;
03496         Semaphore *sessions;
03497         tpport_t port;
03498 
03499         void Update(InetHostAddress addr);
03500 public:
03501         Protocol(const char *keypath, tpport_t port);
03502         ~Protocol();
03503 
03509         InetHostAddress getAddress(void);
03510 
03516         inline tpport_t getPort(void)
03517                 {return port;};
03518 
03525         inline Semaphore *getSessions(void)
03526                 {return sessions;};
03527 };
03528 
03529 statnode_t *getNodes(const char *name);
03530 timeout_t getTimeout(const char *string);
03531 
03532 extern bool aliases;
03533 extern bool running;
03534 extern Keydata application;
03535 extern KeyServer keyserver;
03536 extern KeyThreads keythreads;
03537 extern KeyMemory keymemory;
03538 extern KeyPaths keypaths;
03539 extern KeyImports keyimports;
03540 extern KeyLocal keylocal;
03541 extern KeyNetwork keynetwork;
03542 extern KeyMailbox keymailbox;
03543 extern KeyProxy keyproxy;
03544 extern KeyTones keytones;
03545 extern KeyFeed keyfeed;
03546 extern KeyHandlers keyhandlers;
03547 extern Plugins plugins;
03548 extern Driver *driver;
03549 extern Debug *debug;
03550 extern Module *asr, *tts;
03551 extern Fifo fifo;
03552 #endif
03553 

Generated at Sat Nov 3 09:50:20 2001 for Bayonne by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001