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

bayonne.h

Go to the documentation of this file.
00001 // Copyright (C) 2000 Open Source Telecom Corporation.
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 // 
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 
00017 #ifndef __CCXX_BAYONNE_H__
00018 #define __CCXX_BAYONNE_H__
00019 
00020 #ifndef __CCXX_SCRIPT_H__
00021 #include <cc++/script.h>
00022 #endif
00023 
00024 #ifndef __CCXX_SLOG_H__
00025 #include <cc++/slog.h>
00026 #endif
00027 
00028 #ifndef __CCXX_DSO_H__
00029 #include <cc++/file.h>
00030 #endif
00031 
00032 #ifndef __CCXX_SOCKET_H__
00033 #include <cc++/socket.h>
00034 #endif
00035 
00036 #ifndef __CCXX_AUDIO_H__
00037 #include <cc++/audio.h>
00038 #endif
00039 
00040 #include <stdlib.h>
00041 
00042 #ifdef  __FreeBSD__
00043 #undef  read
00044 #undef  write
00045 #undef  readv
00046 #undef  writev
00047 #endif
00048 
00049 #ifndef COMMON_TPPORT_TYPE_DEFINED
00050 typedef short   tpport_t;
00051 #endif
00052 
00053 /* Bayonne uses a universal event record for all driver plugins and
00054    state handlers.  Not all drivers impliment the entire set of events
00055    and some drivers have specific events associated with their unique
00056    characteristcs.  However, most events are considered "universal".
00057 */
00058 
00059 class Trunk;
00060 class Service;
00061 class phTone;
00062 class TrunkGroup;
00063 class Module;
00064 class Request;
00065 
00066 typedef enum
00067 {
00068         SELECT_FIRST,
00069         SELECT_LAST
00070 } seltype_t;
00071 
00072 typedef enum {
00073         MODULE_GENERIC,
00074         MODULE_DELIVERY,
00075         MODULE_SENDFILE,
00076         MODULE_SENDFAX,
00077         MODULE_NOTIFY,
00078         MODULE_FIFO,
00079         MODULE_TGI,
00080         MODULE_URL,
00081         MODULE_REPLY,
00082         MODULE_ANY
00083 }       modtype_t;
00084 
00085 typedef enum {
00086         // step change requests
00087         TRUNK_STEP_HANGUP = 0,
00088         TRUNK_STEP_SLEEP,
00089         TRUNK_STEP_ANSWER,
00090         TRUNK_STEP_COLLECT,
00091         TRUNK_STEP_PLAY,
00092         TRUNK_STEP_RECORD,
00093         TRUNK_STEP_TONE,
00094         TRUNK_STEP_DIALXFER,
00095         TRUNK_STEP_FLASH,
00096         TRUNK_STEP_JOIN,
00097         TRUNK_STEP_RTP,
00098         TRUNK_STEP_DUPLEX,
00099         TRUNK_STEP_DETECT,
00100         TRUNK_STEP_REQUIRES,
00101         TRUNK_STEP_EXIT = TRUNK_STEP_HANGUP,
00102         TRUNK_STEP_DRIVER
00103 } trunkstep_t;
00104 
00105 typedef enum {
00106         // notify script from state handler
00107         TRUNK_SIGNAL_STEP = 0,
00108         TRUNK_SIGNAL_EXIT,
00109         TRUNK_SIGNAL_HANGUP=TRUNK_SIGNAL_EXIT,
00110         TRUNK_SIGNAL_ERROR,
00111         TRUNK_SIGNAL_TIMEOUT,
00112         TRUNK_SIGNAL_DTMF,
00113         TRUNK_SIGNAL_0,
00114         TRUNK_SIGNAL_1,
00115         TRUNK_SIGNAL_2,
00116         TRUNK_SIGNAL_3,
00117         TRUNK_SIGNAL_4,
00118         TRUNK_SIGNAL_5,
00119         TRUNK_SIGNAL_6,
00120         TRUNK_SIGNAL_7,
00121         TRUNK_SIGNAL_8,
00122         TRUNK_SIGNAL_9,
00123         TRUNK_SIGNAL_STAR,
00124         TRUNK_SIGNAL_POUND,
00125         TRUNK_SIGNAL_A,
00126         TRUNK_SIGNAL_B,
00127         TRUNK_SIGNAL_C,
00128         TRUNK_SIGNAL_D,
00129         TRUNK_SIGNAL_DIALTONE,
00130         TRUNK_SIGNAL_BUSY,
00131         TRUNK_SIGNAL_CANCEL,
00132         TRUNK_SIGNAL_SIGNAL,
00133         TRUNK_SIGNAL_DRIVER
00134 }       trunksignal_t;
00135 
00136 typedef enum {
00137         // primary state handlers
00138 
00139         TRUNK_ENTER_STATE = 100,// newly entered handler state
00140         TRUNK_EXIT_STATE,       // exiting prior state (unused)
00141         TRUNK_STOP_STATE,       // request state termination
00142         TRUNK_NOTIFICATION,     // death notify event
00143         TRUNK_SERVICE_SUCCESS,  // service completion successful
00144         TRUNK_SERVICE_FAILURE,  // service completion failed
00145         TRUNK_SERVICE_LOOKUP,   // lookup transaction
00146         TRUNK_SERVICE_LOGIN,    // login transaction
00147         TRUNK_SIGNAL_NOTIFY,    // signal between trunks
00148         TRUNK_JOIN_TRUNKS,      // join two trunks together
00149         TRUNK_PART_TRUNKS,      // split two trunks that were joined
00150         TRUNK_NULL_EVENT,       // used to push pipe driven systems
00151 
00152         // tgi/integration control state handlers
00153 
00154         TRUNK_EXIT_SHELL = 200, // tgi completion event
00155         TRUNK_START_SCRIPT,     // start of script
00156         TRUNK_RING_START,       // smdi/integrated answer
00157         TRUNK_RING_REDIRECT,    // smdi/integrated answer options
00158         TRUNK_STOP_DISCONNECT,  // integrated hangup notification
00159 
00160         // in the future these will be used
00161 
00162         TRUNK_START_INCOMING = TRUNK_RING_START,
00163         TRUNK_START_OUTGOING = TRUNK_START_SCRIPT,
00164 
00165         // primary "mode" selection controls
00166 
00167         TRUNK_MAKE_TEST =  300, // request driver perform line test
00168         TRUNK_MAKE_BUSY,        // request driver lockout line
00169         TRUNK_MAKE_IDLE,        // request driver reset line
00170         TRUNK_MAKE_STEP,        // pass step event internally
00171 
00172         // basic trunk events
00173 
00174         TRUNK_LINE_WINK = 400,  // used for line disconnect notification
00175         TRUNK_TIMER_EXPIRED,    // driver specific port timer expired
00176         TRUNK_RINGING_ON,       // some drivers distinguish start/stop
00177         TRUNK_RINGING_OFF,      // default ring event
00178         TRUNK_TEST_IDLE,        // some drivers have line test completion
00179         TRUNK_TEST_FAILURE,     // some drivers notify errors
00180         TRUNK_ON_HOOK,          // some drivers notify on hook
00181         TRUNK_OFF_HOOK,         // some drivers notify off hook
00182         TRUNK_CALLER_ID,        // caller id parse request
00183         TRUNK_RINGING_DID,      // did digit ring signal
00184         TRUNK_CALL_DETECT,      // ISDN call detected notification
00185         TRUNK_CALL_CONNECT,     // ISDN call connection notification
00186         TRUNK_CALL_RELEASE,     // ISDN call release notification
00187         TRUNK_CALL_ACCEPT,      // ISDN incoming call accepted
00188         TRUNK_CALL_RINGING,     // digital T1 incoming call
00189         TRUNK_CALL_DISCONNECT,  // digital T1 circuit break
00190 
00191         // basic audio processing events
00192 
00193         TRUNK_AUDIO_IDLE = 500, // audio reset or completion event
00194         TRUNK_INPUT_PENDING,    // some drivers monitor audio i/o status
00195         TRUNK_OUTPUT_PENDING,   // some drivers monitor audio i/p status
00196         TRUNK_AUDIO_BUFFER,     // some drivers return audio buffers
00197         TRUNK_TONE_IDLE,        // tone generator completion event
00198         TRUNK_DTMF_KEYDOWN,     // some drivers distinguish tone down
00199         TRUNK_DTMF_KEYUP,       // default dtmf event
00200         TRUNK_TONE_START,       // tone detected
00201         TRUNK_TONE_STOP,        // some drivers have tone completion event
00202         TRUNK_FSK_DETECT,       // fsk tone detect
00203         TRUNK_FAX_DETECT,       // fax tone detect
00204         TRUNK_VOX_DETECT,       // speaker detected
00205         TRUNK_AUDIO_START,      // some drivers may "vox" compress
00206         TRUNK_AUDIO_STOP,       // some drivers may "vox" compress
00207         TRUNK_CPA_DIALTONE,     // dialtone heard on the line
00208         TRUNK_CPA_BUSYTONE,
00209         TRUNK_CPA_RINGING,
00210         TRUNK_CPA_RINGBACK = TRUNK_CPA_RINGING,
00211         TRUNK_CPA_INTERCEPT,
00212         TRUNK_CPA_NODIALTONE,
00213         TRUNK_CPA_NORINGBACK,
00214         TRUNK_CPA_NOANSWER,
00215         TRUNK_CPA_CONNECT,
00216         TRUNK_CPA_FAILURE,
00217         TRUNK_DSP_READY,        // dsp resource became available
00218 
00219         // driver specific events and anomolies
00220 
00221         TRUNK_DRIVER_SPECIFIC=8000      // very oddball events
00222 } trunkevent_t;
00223 
00224 typedef enum
00225 {
00226         DSP_MODE_INACTIVE = 0,  // dsp is idle
00227         DSP_MODE_VOICE,         // standard voice processing
00228         DSP_MODE_CALLERID,      // caller id support
00229         DSP_MODE_DATA,          // fsk modem mode
00230         DSP_MODE_FAX,           // fax support
00231         DSP_MODE_TDM,           // TDM bus with echo cancellation
00232         DSP_MODE_RTP,           // VoIP full duplex
00233         DSP_MODE_DUPLEX,        // mixed play/record
00234         DSP_MODE_JOIN,          // support of joined channels
00235         DSP_MODE_CONF,          // in conference
00236         DSP_MODE_TONE           // tone processing
00237 } dspmode_t;
00238 
00239 typedef enum
00240 {
00241         TRUNK_MODE_INCOMING = 0,
00242         TRUNK_MODE_OUTGOING,
00243         TRUNK_MODE_INACTIVE,
00244         TRUNK_MODE_UNAVAILABLE
00245 } trunkmode_t;
00246  
00247 typedef enum
00248 {
00249         STAT_MAX_INCOMING,
00250         STAT_MAX_OUTGOING,
00251         STAT_TOT_INCOMING,
00252         STAT_TOT_OUTGOING,
00253         STAT_ACTIVE_CALLS
00254 } statitem_t;
00255 
00256 #define TRUNK_CAP_VOICE         0x00000001
00257 #define TRUNK_CAP_DIAL          0x00000002
00258 #define TRUNK_CAP_SENDFAX       0x00000004
00259 #define TRUNK_CAP_RECVFAX       0x00000008
00260 #define TRUNK_CAP_DATA          0x00000010
00261 
00262 typedef union
00263 {
00264         scriptsymbol_t sym;
00265         char data[sizeof(scriptsymbol_t) + 12];
00266 }       numbersymbol_t;
00267 
00268 typedef union
00269 {
00270         scriptsymbol_t bin;
00271         char data[sizeof(scriptsymbol_t) + 32];
00272 }       digitsymbol_t;
00273 
00274 typedef struct
00275 {
00276         
00277         int pid;
00278         unsigned seq;
00279         void *data;
00280 }       execdata_t;
00281 
00282 typedef union
00283 {
00284         struct
00285         {
00286                 int rings;
00287                 int timeout;
00288         }       answer;
00289         struct
00290         {
00291                 char list[256];
00292                 char *name;
00293                 unsigned long offset;
00294                 unsigned long limit;
00295                 unsigned char volume;
00296         }       play;
00297         struct
00298         {
00299                 char *name;
00300                 timeout_t timeout;
00301                 unsigned long offset;
00302                 unsigned short term;
00303                 unsigned char volume;
00304                 unsigned long trim;
00305                 bool append;
00306         }       record;
00307         struct
00308         {
00309                 char digits[65];
00310                 char *digit;
00311                 timeout_t interdigit;
00312                 bool exit;
00313                 timeout_t timeout;
00314                 timeout_t offhook;
00315                 timeout_t onhook;
00316         }       dialxfer;
00317         struct
00318         {
00319                 timeout_t timeout;
00320                 unsigned count;
00321                 unsigned short term;
00322                 unsigned short ignore;
00323         }       collect;
00324         struct
00325         {
00326                 timeout_t wakeup;
00327                 unsigned rings;
00328                 unsigned loops;
00329         }       sleep;
00330         struct
00331         {
00332                 timeout_t wakeup;
00333                 unsigned loops;
00334                 phTone *tone;
00335         }       tone;
00336         struct
00337         {
00338                 timeout_t wakeup;
00339                 Trunk *trunk;
00340                 phTone *tone;
00341         }       join;
00342         struct
00343         {
00344                 struct in_addr addr;
00345                 unsigned short bind, port, term;
00346                 audioencoding_t codec;
00347         }       rtp;
00348 }       trunkdata_t;
00349 
00350 typedef struct
00351 {
00352         trunkevent_t id;        // event id
00353         union
00354         {
00355                 struct
00356                 {
00357                         unsigned digit: 4;
00358                         unsigned duration: 12;
00359                         unsigned e1: 8;
00360                         unsigned e2: 8;
00361                 } dtmf;
00362                 struct
00363                 {
00364                         unsigned tone: 8;
00365                         unsigned energy: 8;
00366                         unsigned duration: 16;
00367                 } tone;
00368                 struct
00369                 {
00370                         unsigned digit:  4;
00371                         unsigned duration: 24;
00372                 } ring;
00373                 struct
00374                 {
00375                         unsigned seq;
00376                         bool result;
00377                         char *data;
00378                 } lookup;
00379                 int status;
00380                 Trunk *trunk;
00381                 void *data;
00382                 char **argv;
00383                 char *error;
00384                 timeout_t duration;
00385                 trunkstep_t step;
00386                 char dn[8];
00387                 dspmode_t dsp;
00388         } parm;
00389 } TrunkEvent;
00390 
00391 /* This is used to bind user defined "functions" which may be loaded
00392    in a DSO module.
00393 */
00394 
00395 typedef char *(*functioncall_t)(scriptsymbol_t *sym, char **args);
00396 
00397 typedef struct
00398 {
00399         char *name;
00400         functioncall_t function;
00401 } FUNCTIONS;
00402 
00403 
00411 class CallStat : public Mutex
00412 {
00413 protected:
00414         int capacity;
00415         struct
00416         {
00417                 int incoming;
00418                 int outgoing;
00419         }       active, max, lastmax;
00420 
00421         struct
00422         {
00423                 long incoming;
00424                 long outgoing;
00425         }       total, lasttotal;
00426 
00427 public:
00428         CallStat();
00429 
00435         inline int getCapacity(void)
00436                 {return capacity;};
00437 
00444         long getStat(statitem_t item);
00445 
00449         void incIncoming(void);
00450 
00454         void decIncoming(void);
00455 
00459         void incOutgoing(void);
00460 
00464         void decOutgoing(void);
00465 
00469         void Update(void);
00470 };
00471 
00484 class Translator : protected Keydata
00485 {
00486 private:
00487         friend Translator *getTranslator(char *name);
00488         static Translator *first;
00489         Translator *next;
00490 
00491 protected:
00497         virtual char *getName(void) = 0;
00498 
00505         char *getPlayBuffer(Trunk *trunk);
00506 
00507         void scanDir(const char *etcdir, const char *language, const char *lib);
00508 
00509         Translator(const char *conf, const char *lib);
00510 
00511 public:
00519         virtual char *Speak(Trunk *trunk) = 0;
00520 };
00521 
00535 class Functions
00536 {
00537 protected:
00543         virtual char *getName(void) = 0;
00544 
00550         void Load(FUNCTIONS *map);
00551 };
00552 
00553 /* Bayonne config file istanciation classes.  In Bayonne these are
00554    created as keydata objects out of bayonne.conf during process
00555    startup automatically.  This is Bayonne runtime configuration magic.
00556 */
00557 
00564 class KeyTones : protected Keydata
00565 {
00566 public:
00570         KeyTones();
00571 };
00572 
00580 class KeyLocal : public Keydata
00581 {
00582 public:
00586         KeyLocal();
00587 };
00588 
00596 class KeyPaths : public Keydata
00597 {
00598 public:
00602         KeyPaths();
00603 
00607         inline const char *getLibexec(void)
00608                 {return getLast("libexec");};
00609 
00613         inline const char *getTgipath(void)
00614                 {return getLast("tgipath");};
00615 
00619         inline const char *getLibpath(void)
00620                 {return getLast("libpath");};
00621 
00625         inline const char *getDatafiles(void)
00626                 {return getLast("datafiles");};
00627 
00631         inline const char *getWrappers(void)
00632                 {return getLast("wrappers");};
00633 
00637         inline const char *getRunfiles(void)
00638                 {return getLast("runfiles");};
00639 
00643         inline const char *getSpool(void)
00644                 {return getLast("spool");};
00645 
00649         inline const char *getScriptFiles(void)
00650                 {return getLast("scripts");};
00651 
00655         inline const char *getCache(void)
00656                 {return getLast("precache");};
00657 };
00658 
00666 class KeyNetwork : public Keydata
00667 {
00668 public:
00672         KeyNetwork();
00673 
00679         unsigned getRefresh(void)
00680                 {return atoi(getLast("refresh"));};
00681 
00687         unsigned getTimeToLive(void)
00688                 {return atoi(getLast("live"));};
00689 
00695         InetHostAddress getBroadcast(void);
00696 
00702         InetAddress getAddress(void);
00703 
00709         tpport_t getPort(void);
00710 
00716         InetHostAddress getDBHost(void);
00717 
00723         tpport_t getDBPort(void);
00724 };
00725 
00733 class KeyMailbox : public Keydata
00734 {
00735 public:
00739         KeyMailbox();
00740 
00746         inline unsigned getCount(void)
00747                 {return atoi(getLast("count"));};
00748 
00754         inline unsigned getLimit(void)
00755                 {return atoi(getLast("limit"));};
00756 
00763         inline unsigned getQuota(void)
00764                 {return atoi(getLast("quota"));};
00765 
00771         inline unsigned getMinimum(void)
00772                 {return atoi(getLast("minimum"));};
00773 
00779         inline unsigned getMaximum(void)
00780                 {return atoi(getLast("maximum"));};
00781 
00787         inline const char *getPassword(void)
00788                 {return getLast("password");};
00789 };
00790 
00799 class KeyMemory : public Keydata
00800 {
00801 public:
00805         KeyMemory();
00806 
00812         inline int getSymbolSize(void)
00813                 {return atoi(getLast("symbols"));};
00814 
00821         inline int getPageSize(void)
00822                 {return atoi(getLast("page"));};
00823 };
00824 
00832 class KeyFeed : public Keydata
00833 {
00834 public:
00838         KeyFeed();
00839 
00845         inline unsigned getBuffers(void)
00846                 {return atoi(getLast("buffers"));};
00847 };
00848 
00849 
00857 class KeyThreads : public Keydata
00858 {
00859 public:
00863         KeyThreads();
00864 
00870         inline int priService(void)
00871                 {return atoi(getLast("services"));};
00872 
00878         inline int priScheduler(void)
00879                 {return atoi(getLast("scheduler"));};
00880 
00886         inline int priGUI(void)
00887                 {return atoi(getLast("gui"));};
00888 
00894         inline int priRTP(void)
00895                 {return atoi(getLast("rtp"));};
00896 
00902         inline int getStepDelay(void)
00903                 {return atoi(getLast("stepdelay"));};
00904 
00910         inline int getStepInterval(void)
00911                 {return atoi(getLast("stepinterval"));};
00912 
00918         inline int getResetDelay(void)
00919                 {return atoi(getLast("resetdelay"));};
00920 
00926         size_t getStack(void);
00927 
00933         int getServices(void);
00934 
00940         int priResolver(void);
00941 
00948         int getResolver(void);
00949 
00955         inline int priAudio(void)
00956                 {return atoi(getLast("audio"));};
00957 
00963         inline int priFeed(void)
00964                 {return atoi(getLast("feed"));};
00965 
00971         inline int priGateway(void)
00972                 {return atoi(getLast("gateways"));};
00973 
00979         inline int priManager(void)
00980                 {return atoi(getLast("managers"));};
00981 
00987         inline int priNetwork(void)
00988                 {return atoi(getLast("network"));};
00989 
00995         inline int getInterval(void)
00996                 {return atoi(getLast("interval"));};
00997 
01003         inline int getRefresh(void)
01004                 {return atoi(getLast("refresh"));};
01005 
01011         int getGateways(void);
01012         
01019         inline int getPriority(void)
01020                 {return atoi(getLast("priority"));};
01021 
01027         int getPolicy(void);
01028 
01034         inline int getPages(void)
01035                 {return atoi(getLast("pages"));};
01036 };
01037 
01045 class Auditdata : public Keydata
01046 {
01047 private:
01048         friend class Audit;
01049 
01050         Auditdata();
01051 };
01052 
01061 class Policy
01062 {
01063 private:
01064         friend class TrunkGroup;
01065 
01066         Policy *next;
01067         TrunkGroup *group;
01068 
01069 protected:
01070         Policy(TrunkGroup *grp);
01071         
01072         virtual Request *loPriority(void)
01073                 {return NULL;};
01074 
01075         virtual Request *hiPriority(void)
01076                 {return NULL;};
01077 };
01078 
01088 class Request
01089 {
01090 private:
01091         friend class TrunkGroup;
01092 
01093         static unsigned seq;
01094 
01095         unsigned id;
01096         Request *next;
01097         time_t expires;
01098         TrunkGroup *group;
01099 
01100         char *argv[33];
01101         char buffer[512];
01102         char tagid[65];
01103 
01104         void Detach(void);
01105 
01106 public:
01107         Request(TrunkGroup *grp, const char *text, unsigned expire, const char *tag = NULL);
01108         ~Request()
01109                 {Detach();};
01110 
01111         inline char **getList(void)
01112                 {return argv;};
01113 
01114         inline char *getTag(void)
01115                 {return tagid;};
01116 
01117         bool isExpired(void);
01118 
01119         friend void cancel(TrunkGroup *group, const char *tag);
01120         friend Request *request(TrunkGroup *group, char **argv, unsigned timeout, const char *tag = NULL);
01121         friend Request *locate(TrunkGroup *group, const char *tag, int *pos);
01122 };
01123 
01134 class TrunkGroup : public Keydata, public CallStat
01135 {
01136 private:
01137         friend class KeyServer;
01138         friend class Scheduler;
01139         friend class Audit;
01140         friend class TestDebug;
01141         friend class Request;
01142         friend class Policy;
01143         friend class Trunk;
01144         static TrunkGroup *first;
01145         TrunkGroup *next;
01146         char schedule[65];
01147         char planned[65];
01148         unsigned trump;
01149         Request *reqfirst, *reqlast;
01150         Policy *polFirst;
01151         unsigned members;
01152 
01153         void setSchedule(const char *str);
01154 
01155         friend inline const char *getGroups(void)
01156                 {return TrunkGroup::first->getLast("groups");};
01157 
01158         friend void cancel(TrunkGroup *group, const char *tag);
01159         friend Request *locate(TrunkGroup *group, const char *tag, int *pos = NULL);
01160 
01161 
01162 public:
01168         TrunkGroup(char *name = NULL);
01169 
01175         inline const char *getName(void)
01176                 {return getLast("name");};
01177 
01183         inline unsigned getAnswer(void)
01184                 {return atoi(getLast("answer"));};
01185 
01191         inline unsigned getCallerid(void)
01192                 {return atoi(getLast("callerid"));};
01193 
01199         inline unsigned getPickup(void)
01200                 {return atoi(getLast("pickup"));};
01201 
01207         inline const char *chkRequest(void)
01208                 {return getLast("requests");};
01209 
01215         seltype_t getSelect(void);
01216 
01222         inline unsigned getThreashold(void)
01223                 {return atoi(getLast("threashold"));};
01224 
01230         inline unsigned getAnalysis(void)
01231                 {return atoi(getLast("analysis"));};
01232 
01239         inline timeout_t getReady(void)
01240                 {return atol(getLast("ready"));};
01241         
01247         inline unsigned getIdleTime(void)
01248                 {return atoi(getLast("idletime"));};
01249 
01255         inline unsigned getSiezeTime(void)
01256                 {return atoi(getLast("siezetime"));};
01257 
01263         inline unsigned getRingTime(void)
01264                 {return atoi(getLast("ringtime"));};
01265 
01271         inline int getHangup(void)
01272                 {return atoi(getLast("hangup"));};
01273 
01279         inline timeout_t getFlash(void)
01280                 {return atol(getLast("flash"));};
01281 
01287         inline timeout_t getDialtone(void)
01288                 {return atol(getLast("dialtone"));};
01289 
01295         inline timeout_t getDialspeed(void)
01296                 {return atol(getLast("dialspeed"));};
01297 
01304         const char *getNumber(void);
01305 
01312         const char *getSchedule(char *buf);
01313 
01323         const char *getRedirect(const char *redirect, char *buf);
01324 
01328         inline void incCapacity(void)
01329                 {++capacity;};
01330 
01336         Request *getRequest(void);
01337 
01343         friend TrunkGroup *getGroup(const char *name);
01344 };
01345 
01353 class KeyServer : public Keydata
01354 {
01355 private:
01356         unsigned uid, gid;
01357         const char *altdir;
01358         const char *phrdir;
01359 
01360 public:
01364         KeyServer();
01365 
01371         inline const char *getNode(void)
01372                 {return getLast("node");};
01373 
01379         inline const char *getPassword(void)
01380                 {return getLast("password");};
01381 
01387         inline const char *getToken(void)
01388                 {return getLast("token");};
01389 
01393         void loadGroups(bool test);
01394 
01400         inline const char *getDefault(void)
01401                 {return getLast("default");};
01402 
01408         inline unsigned getGid(void)
01409                 {return gid;};
01410 
01416         inline unsigned getUid(void)
01417                 {return uid;};
01418 
01422         void setUid(void);
01423 
01427         void setGid(void);
01428 
01434         inline int getNodeCount(void)
01435                 {return atoi(getLast("nodes"));};
01436 
01442         inline const char *getPrefix(void)
01443                 {return altdir;};
01444 
01450         inline const char *getPhrases(void)
01451                 {return phrdir;};
01452 };
01453 
01461 class Plugins : public Keydata
01462 {
01463 public:
01467         Plugins();
01468 
01472         ~Plugins();
01473 
01479         char *getDriverName(void);
01480 
01484         void loadDebug(void);
01485 
01490         DSO *loadDriver(void);
01491 
01495         void loadExtensions(void);
01496 
01500         void loadFunctions(void);
01501 
01505         void loadMaps(void);
01506 
01510         void loadModules(void);
01511 
01515         void loadFeeds(void);
01516 
01520         void loadTGI(void);
01521 
01525         void loadManagers(void);
01526 
01530         void loadTranslators(void);
01531 
01535         void loadAuditing(void);
01536 };
01537 
01546 class aaScript : public ScriptCommand 
01547 {
01548 private:
01549         friend class Functions;
01550 
01551 #pragma pack(1)
01552         typedef struct _functions
01553         {
01554                 struct _functions *next;
01555                 functioncall_t function;
01556                 char name[1];
01557         }       functions_t;
01558 #pragma pack()
01559 
01560         functions_t *functions[KEYWORD_INDEX_SIZE];
01561 
01562 protected:
01570         unsigned long getTrapMask(const char *trapname);
01571 
01579         void addFunction(char *name, functioncall_t function);
01580 
01581 public:
01588         functioncall_t getFunction(char *name);
01589 
01593         aaScript();
01594 
01600         void addModule(Module *module);
01601 };
01602 
01612 class aaImage : public ScriptImage
01613 {
01614 protected:
01622         virtual bool isScript(char *scriptname);
01623 
01630         void scanDir(char *path);
01631 
01632 public:
01636         aaImage(aaScript *script);
01637 };
01638 
01645 class Mixer : protected Mutex
01646 {
01647 private:
01648         friend class Conference;
01649         void addGroup(void);
01650         void delGroup(void);
01651 
01652 protected:
01653         Mixer();
01654         unsigned avail, members, groups;
01655 
01656 public:
01657         unsigned getAvail(void)
01658                 {return avail;};
01659 
01660         unsigned getMembers(void)
01661                 {return members;};
01662 
01663         unsigned getGroups(void)
01664                 {return groups;};
01665 
01666         virtual bool setMixer(int groups, int members) = 0;
01667 
01668         virtual Conference *getConference(int group) = 0;
01669 };
01670 
01679 class Conference : protected Mutex
01680 {
01681 protected:
01682         Mixer *mixer;
01683         unsigned limit;
01684         unsigned members;
01685 
01686         virtual ~Conference();
01687 
01688         Conference(Mixer *m);
01689 public:
01690         inline virtual Mixer *getMixer(void)
01691                 {return mixer;};
01692 
01693         unsigned getMembers(void)
01694                 {return members;};
01695 
01696         unsigned getLimit(void)
01697                 {return limit;};
01698 
01699         virtual bool setConference(unsigned max) = 0;
01700 };
01701 
01711 class Trunk : public ScriptInterp
01712 {
01713 private:
01714         friend class TestDebug;
01715         friend class aaScript;
01716         friend class Translator;
01717         friend class ScriptInterface;
01718         friend class Service;
01719         friend class AudioService;
01720         friend class Fifo;
01721         friend class PortManager;
01722 
01723         unsigned member;
01724         char *cdrv[33];
01725         int cdrc;
01726         numbersymbol_t numbers[5];
01727 
01728         bool scrStart(void);
01729         bool scrRequest(void);
01730         bool scrLibonce(void);
01731         bool scrLibexec(void);
01732         bool scrHangup(void);
01733         bool scrDebug(void);
01734         bool scrImport(void);
01735         bool scrExport(void);
01736         bool scrFunction(void);
01737         bool scrAlog(void);
01738         bool scrAudit(void);
01739         bool scrPause(void);
01740         bool scrSleep(void);
01741         bool scrSync(void);
01742         bool scrTone(void);
01743         bool scrAnswer(void);
01744         bool scrCollect(void);
01745         bool scrFlash(void);
01746         bool scrPlay(void);
01747         bool scrRecord(void);
01748         bool scrAppend(void);
01749         bool scrDial(void);
01750         bool scrDTMF(void);
01751         bool scrTransfer(void);
01752         bool scrHold(void);
01753         bool scrSpeak(void);
01754         bool scrMap(void);
01755         bool scrModule(void);
01756         bool scrSchedule(void);
01757         bool scrSignal(void);
01758         bool scrIdle(void);
01759 
01760 protected:
01761         static ScriptSymbol globals;
01762         static char digit[16];
01763         ScriptInterface *script;
01764         TrunkGroup *group;
01765         PortManager *manager;
01766         int id;
01767         time_t start, idle;
01768 
01769         int idle_timer;
01770         int rings;
01771         int digits;
01772 
01773         Service *thread;
01774         trunkdata_t data;
01775         execdata_t tgi;
01776         digitsymbol_t dtmf;
01777         char buffer[65];
01778 
01779         struct
01780         {
01781                 bool offhook: 1;
01782                 bool dtmf: 1;
01783                 bool script: 1;
01784                 bool reset: 1;
01785                 bool timer : 1;
01786                 bool audio: 1;
01787                 bool once : 1;
01788                 bool ready : 1;
01789                 bool echo : 1;
01790                 unsigned temp : 1;
01791                 trunkmode_t trunk: 2;
01792                 dspmode_t dsp: 4;
01793         } flags;
01794 
01800         unsigned long getTrapDefault(void)
01801                 {return 0x00000007;};
01802 
01811         void setConstant(const char *id, const char *data);
01812 
01819         void repSymbol(const char *id, const char *data);
01820 
01828         scriptsymbol_t *getEntry(const char *symname, int size);
01829 
01835         void Commit(scriptsymbol_t *sym);
01836 
01843         int getTimeout(void);
01844 
01851         int getInterdigit(void);
01852 
01858         unsigned short getDigitMask(void);
01859 
01865         bool TrunkSignal(trunksignal_t);
01866 
01873         virtual void setDTMFDetect(void);
01874 
01883         virtual void setDTMFDetect(bool enable)
01884                 {flags.dtmf = enable;};
01885 
01891         virtual void stopServices(void);
01892 
01903         virtual void TrunkStep(trunkstep_t step) = 0;
01904 
01910         bool idleHangup();
01911 
01918         virtual unsigned long getIdleTime(void) = 0;
01919 
01923         bool ScriptStep(void);
01924 
01933         bool Attach(const char *scrname);
01934 
01939         void Detach(void);
01940 
01944         unsigned long getMask(void);
01945 
01952         char **getInitial(char **args);
01953 
01960         void setList(char **list);
01961 
01962         Trunk(int port);
01963 public:
01969         virtual unsigned long getCapabilities(void)
01970                 {return TRUNK_CAP_VOICE | TRUNK_CAP_DIAL;};
01971 
01977         virtual void getName(char *buffer) = 0;
01978 
01986         virtual bool postEvent(TrunkEvent *event) = 0;
01987 
01993         int getDigit(char digit);
01994 
02000         bool isReady(void);
02001 
02009         void libexec(char **argv, unsigned timeout);
02010 
02014         inline bool getOnce(void)
02015                 {return ScriptInterp::getOnce();};
02016 
02022         inline unsigned getMember(void)
02023                 {return member;};
02024 };
02025 
02034 class PortManager
02035 {
02036 private:
02037         Trunk *trunk;
02038 
02039 protected:
02040         ~PortManager()
02041                 {trunk->manager = NULL;};
02042 
02048         PortManager(Trunk *trk);
02049 
02055         inline void postStep(trunkstep_t step)
02056                 {trunk->TrunkStep(step);};
02057 
02064         inline bool postEvent(TrunkEvent *event)
02065                 {return trunk->postEvent(event);};
02066 
02072         inline trunkdata_t *getData(void)
02073                 {return &trunk->data;};
02074 
02080         inline execdata_t *getExec(void)
02081                 {return &trunk->tgi;};
02082 public:
02086         virtual bool Step(void) = 0;
02087 
02093         virtual unsigned long getMask(void) = 0;
02094         
02101         virtual bool postSignal(trunksignal_t signal) = 0;
02102 
02109         virtual bool postAccept(const char *name) = 0;
02110 
02114         virtual void postDetach(void) = 0;
02115 };
02116 
02126 class Fifo : public fifostream, public Mutex
02127 {
02128 protected:
02129         char schedule[33];
02130 
02131         bool exitPid(char **args);
02132         bool waitPid(char **args);
02133         bool setSymbol(char **argv);
02134         bool putSymbol(char **argv);
02135         bool submit(char **argv);
02136         bool login(char **argv);
02137         bool mapFiles(char **argv);
02138         bool startScript(char **argv);
02139         bool ringScript(char **argv);
02140         bool redirectScript(char **argv);
02141         bool busyLine(char **argv);
02142         bool idleLine(char **argv);
02143         bool hangupLine(char **argv);
02144         bool reqScript(char **argv);
02145         bool setSchedule(char **argv);
02146         bool postKey(char **argv);
02147         bool setMixer(char **argv);
02148         bool setLimit(char **argv);
02149         bool reload(char **argv);
02150 
02151 public:
02160         bool Command(const char *cmdstring, ostream *fd = NULL);
02161 };
02162 
02176 class Audit : public Mutex
02177 {
02178 private:
02179         friend void audit(Trunk *trunk, char *detail);
02180         friend void alog(Trunk *trunk, char *detail);
02181         friend class Scheduler;
02182 
02183         static Audit *first;
02184         Audit *next;
02185 
02186 protected:
02187         static Auditdata keys;
02188 
02194         virtual void ReportAudit(Trunk *trunk, char *detail) = 0;
02195 
02201         virtual void ReportCDR(Trunk *trunk, char *detail)
02202                 {ReportAudit(trunk, detail);};
02203 
02207         virtual void ReportStats(void)
02208                 {return;};
02209 
02215         inline TrunkGroup *getFirst(void)
02216                 {return TrunkGroup::first;};
02217 
02224         inline TrunkGroup *getNext(TrunkGroup *grp)
02225                 {return grp->next;};
02226 
02230         Audit();
02231 };
02232 
02240 class Driver : public aaScript
02241 {
02242 protected:
02243         friend class TrunkGroup;
02244 
02245         TrunkGroup **groups;
02246         char *status;
02247         bool active;
02248 
02249 public:
02253         Driver();
02254 
02261         virtual int Start(void) = 0;
02262 
02266         virtual void Stop(void) = 0;
02267 
02273         void getStatus(char *buffer);
02274 
02281         virtual aaImage *getImage(void);
02282 
02289         virtual int getTrunkCount(void) = 0;
02290 
02297         virtual int getTrunkUsed(void) 
02298                 {return getTrunkCount();};
02299 
02306         TrunkGroup *getTrunkGroup(int id)
02307                 {return groups[id];}; 
02308 
02316         int getTrunkMember(TrunkGroup *grp, unsigned member);
02317         
02323         virtual Trunk *getTrunkPort(int id) = 0;
02324 
02330         virtual Conference *getConference(int id)
02331                 {return NULL;};
02332 
02338         virtual Mixer *getMixer(int id)
02339                 {return NULL;};
02340 
02346         virtual unsigned getMixers(void)
02347                 {return 0;};
02348 
02354         virtual unsigned getGroups(void)
02355                 {return 0;};
02356 };
02357 
02364 class Debug : protected Mutex
02365 {
02366 public:
02370         Debug();
02371 
02377         virtual bool DebugTest(void)
02378                 {return false;};
02379 
02383         virtual void DebugEvent(Trunk *trunk, TrunkEvent *event)
02384                 {return;};
02385 
02389         virtual void DebugState(Trunk *trunk, char *state)
02390                 {return;};
02391 
02395         virtual void DebugService(Trunk *trunk, char *msg)
02396                 {return;};
02397 
02401         virtual void DebugScript(Trunk *trunk, char *msg)
02402                 {return;};
02403 
02407         virtual void DebugStep(Trunk *trunk, scriptline_t *line)
02408                 {DebugState(trunk, "step");};
02409 
02413         virtual bool DebugFifo(char **argv)
02414                 {return true;};
02415 };
02416 
02423 class AudioService
02424 {
02425 private: 
02426         char filename[256];
02427 
02428 protected:
02429         Trunk *trunk;
02436         char *getPrompt(char *name);
02437 
02443         char *getPlayfile(void);
02444 
02448         AudioService(void);
02449 };
02450 
02458 class Service : public Semaphore, public Thread, public AudioService
02459 {
02460 protected:
02461         volatile bool stopped;
02462         trunkdata_t *data;
02463         TrunkGroup *group;
02464 
02468         void Success(void);
02469 
02473         void Failure(void);
02474 
02478         inline void dspReset(void)
02479                 {trunk->flags.reset = true;};
02480 
02484         inline void setAudio(void)
02485                 {trunk->flags.audio = true;};
02486 
02490         inline void clrAudio(void)
02491                 {trunk->flags.audio = false;};
02492 
02493 public:
02500         Service(Trunk *trunk, int pri);
02501 
02508         virtual timeout_t Stop(void);
02509 
02517         virtual bool isExiting(void)
02518                 {return true;};
02519 
02523         void endService(void)
02524                 {Terminate();};
02525 
02529         virtual ~Service()
02530                 {Terminate();}
02531 };
02532 
02542 class Server : public Thread
02543 {
02544 private:
02545         static Server *first;
02546         Server *next;
02547         friend void startServers(void);
02548         friend void stopServers(void);
02549 
02550 protected:
02551         Server(int pri);
02552 
02556         virtual void Stop(void)
02557                 {Terminate();};
02558 };
02559 
02566 class Sync
02567 {
02568 private:
02569         friend class Scheduler;
02570 
02571         static Sync *first;
02572         Sync *next;
02573         time_t runtime;
02574 
02575 protected:
02579         Sync(void);
02580 
02585         virtual bool isScheduled(void) = 0;
02586 
02591         virtual unsigned getInterval(void)
02592                 {return 10;};
02593 
02597         virtual void Schedule(void) = 0;
02598 
02602         virtual char *getName(void) = 0;
02603 };
02604 
02613 class phTone
02614 {
02615 private:
02616         friend phTone *getphTone(const char *name);
02617         static phTone *first;
02618         static int ulaw[256];
02619         phTone *next;
02620         char name[33];
02621         unsigned char *samples;
02622         timeout_t duration;
02623         unsigned freq1, freq2;
02624 
02625 public:
02633         phTone(const char *name, timeout_t duration, unsigned f);
02634 
02643         phTone(const char *name, timeout_t duration, unsigned f1, unsigned f2);
02644 
02645         ~phTone();
02646 
02652         void Clear(void);
02653 
02659         inline unsigned char *getSamples(void)
02660                 {return samples;};
02661 
02667         inline timeout_t getDuration(void)
02668                 {return duration;};
02669 };
02670 
02677 class TGI
02678 {
02679 private:
02680         static TGI *first;
02681         TGI *next;
02682 
02683 protected:
02684         TGI();
02685 
02693         virtual bool getExtension(char *ext)
02694                 {return false;};
02695 
02696 public:
02706         virtual void Script(char *cmd, char **args)
02707                 {return;};
02708 
02717         virtual int Parse(int fd, int port, char *cmd)
02718                 {return -1;};   
02719 
02720         friend void getInterp(char *cmd, char **args);
02721         friend TGI *getInterp(char *cmd);
02722 };
02723         
02733 class Module
02734 {
02735 private:
02736         friend class Fifo;
02737         friend class AudioService;
02738         friend class TrunkGroup;
02739 
02740         static Module *modFirst, *sesFirst, *cmdFirst, *urlFirst, *reqFirst;
02741         Module *modNext, *sesNext, *cmdNext, *urlNext, *reqNext;
02742 
02743 protected:
02744         Module();
02745 
02746         inline Module *getFirst(void)
02747                 {return modFirst;};
02748 
02754         virtual modtype_t getType(void) = 0;
02755 
02759         void addSession(void);
02760 
02764         void addCommand(void);
02765 
02769         void addPrompts(void);
02770 
02774         void addRequest(void);
02775         
02779         virtual bool Command(char **argv, ostream *out)
02780                 {return false;};
02781 
02785         virtual void Reload(void)
02786                 {return;};
02787 
02791         virtual char *getPrompt(const char *original)
02792                 {return NULL;};
02793 
02797         virtual void Expires(Request *request)
02798                 {return;};
02799 
02803         virtual void Running(Request *request)
02804                 {return;};
02805 
02809         virtual void Cancelled(Request *request)
02810                 {return;};
02811 
02812         friend void cancel(TrunkGroup *grp, const char *tag);
02813 
02814 public:
02815         inline Module *getNext(void)
02816                 {return modNext;};
02817 
02823         virtual char *getName(void) = 0;
02824 
02832         virtual char *Dispatch(Trunk *trunk)
02833                 {return NULL;};
02834 
02842         virtual unsigned Sleep(Trunk *trunk)
02843                 {return 0;};
02844 
02851         virtual void Detach(Trunk *trunk)
02852                 {return;};
02853 
02861         virtual void Attach(Trunk *trunk)
02862                 {return;};
02863 
02864         friend Module *getModule(modtype_t mod, const char *name = NULL);
02865         friend void detachModules(Trunk *trunk);
02866         friend void attachModules(Trunk *trunk);
02867 };
02868 
02878 class Session
02879 {
02880 private:
02881         friend class Scheduler;
02882         static Mutex mutex;
02883         static Session *first;
02884         static Session *last;
02885         Session *next, *prev;
02886         static void Clean(void);
02887 
02888 protected:
02889         Session();
02890         virtual ~Session()
02891                 {Unlink();};
02892 
02896         void Unlink(void);
02897 
02904         virtual time_t getExpires(void) = 0;
02905 };
02906 
02915 class AudioFeed : private ThreadLock
02916 {
02917 private:
02918         static AudioFeed *first;
02919         AudioFeed *next;
02920         unsigned char *buffers;
02921         volatile unsigned char *current;
02922         size_t feedsize, bufsize;
02923         bool active;
02924 
02925 protected:
02926         const char *name;
02927 
02928 public:
02929         AudioFeed(const char *name, unsigned buffers);
02930         ~AudioFeed();
02931         bool Enable(void);
02932         void Disable(void);
02933         unsigned char *getBuffer(unsigned char *prior = NULL, unsigned size = 120);
02934         void putBuffer(unsigned char *buffer, unsigned size = 120);
02935 
02936         friend AudioFeed *getAudioFeed(const char *name);
02937 };
02938 
02947 class Map : private MemPager
02948 {
02949 private:
02950         static ThreadLock lock;
02951         static Map *first, *last;
02952 
02953         typedef struct _sym
02954         {
02955                 struct _sym *next;
02956                 char *key;
02957                 char **values;
02958         }       mapsym_t;
02959 
02960         typedef struct
02961         {
02962                 mapsym_t *keys[127];
02963         } mapkey_t;
02964 
02965         mapkey_t *digits[32];
02966 
02967         Map *next, *prev;
02968         char *name;
02969 
02970         unsigned getKey(const char *key, unsigned len = 0);
02971         char **getList(const char *key, unsigned len);
02972         ~Map();
02973 
02974 public:
02975         Map(const char *path, const char *name);
02976 
02977         friend char **getMap(const char *map, const char *key);
02978         friend void endMaps(void);
02979 };
02980 
02989 class Protocol : public Keydata, public InetHostAddress, public ThreadLock
02990 {
02991 private:
02992         friend class Resolver;
02993         static Protocol *first;
02994         Protocol *next;
02995         Semaphore *sessions;
02996         tpport_t port;
02997 
02998         void Update(InetHostAddress addr);
02999 public:
03000         Protocol(const char *keypath, tpport_t port);
03001         ~Protocol();
03002 
03008         InetHostAddress getAddress(void);
03009 
03015         inline tpport_t getPort(void)
03016                 {return port;};
03017 
03024         inline Semaphore *getSessions(void)
03025                 {return sessions;};
03026 };
03027 
03028 extern bool running;
03029 extern KeyServer keyserver;
03030 extern KeyThreads keythreads;
03031 extern KeyMemory keymemory;
03032 extern KeyPaths keypaths;
03033 extern KeyLocal keylocal;
03034 extern KeyNetwork keynetwork;
03035 extern KeyMailbox keymailbox;
03036 extern KeyTones keytones;
03037 extern KeyFeed keyfeed;
03038 extern Plugins plugins;
03039 extern Driver *driver;
03040 extern Debug *debug;
03041 extern Fifo fifo;
03042 #endif
03043 

Generated at Sat Feb 10 11:10:48 2001 for Bayonne by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000