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 #include <stdlib.h>
00037 
00038 #ifdef  __FreeBSD__
00039 #undef  read
00040 #undef  write
00041 #undef  readv
00042 #undef  writev
00043 #endif
00044 
00045 #ifndef COMMON_TPPORT_TYPE_DEFINED
00046 typedef short   tpport_t;
00047 #endif
00048 
00049 /* Bayonne uses a universal event record for all driver plugins and
00050    state handlers.  Not all drivers impliment the entire set of events
00051    and some drivers have specific events associated with their unique
00052    characteristcs.  However, most events are considered "universal".
00053 */
00054 
00055 class Trunk;
00056 class Service;
00057 class phTone;
00058 class TrunkGroup;
00059 class Module;
00060 
00061 typedef enum
00062 {
00063         SELECT_FIRST,
00064         SELECT_LAST
00065 } seltype_t;
00066 
00067 typedef enum {
00068         MODULE_GENERIC,
00069         MODULE_DELIVERY,
00070         MODULE_SENDFILE,
00071         MODULE_SENDFAX,
00072         MODULE_NOTIFY,
00073         MODULE_TGI,
00074         MODULE_ANY
00075 }       modtype_t;
00076 
00077 typedef enum {
00078         // step change requests
00079         TRUNK_STEP_HANGUP = 0,
00080         TRUNK_STEP_SLEEP,
00081         TRUNK_STEP_ANSWER,
00082         TRUNK_STEP_COLLECT,
00083         TRUNK_STEP_PLAY,
00084         TRUNK_STEP_RECORD,
00085         TRUNK_STEP_TONE,
00086         TRUNK_STEP_DIALXFER,
00087         TRUNK_STEP_FLASH,
00088         TRUNK_STEP_JOIN,
00089         TRUNK_STEP_EXIT = TRUNK_STEP_HANGUP
00090 } trunkstep_t;
00091 
00092 typedef enum {
00093         // notify script from state handler
00094         TRUNK_SIGNAL_STEP = 0,
00095         TRUNK_SIGNAL_EXIT,
00096         TRUNK_SIGNAL_HANGUP=TRUNK_SIGNAL_EXIT,
00097         TRUNK_SIGNAL_ERROR,
00098         TRUNK_SIGNAL_TIMEOUT,
00099         TRUNK_SIGNAL_DTMF,
00100         TRUNK_SIGNAL_0,
00101         TRUNK_SIGNAL_1,
00102         TRUNK_SIGNAL_2,
00103         TRUNK_SIGNAL_3,
00104         TRUNK_SIGNAL_4,
00105         TRUNK_SIGNAL_5,
00106         TRUNK_SIGNAL_6,
00107         TRUNK_SIGNAL_7,
00108         TRUNK_SIGNAL_8,
00109         TRUNK_SIGNAL_9,
00110         TRUNK_SIGNAL_STAR,
00111         TRUNK_SIGNAL_POUND,
00112         TRUNK_SIGNAL_A,
00113         TRUNK_SIGNAL_B,
00114         TRUNK_SIGNAL_C,
00115         TRUNK_SIGNAL_D,
00116         TRUNK_SIGNAL_DIALTONE,
00117         TRUNK_SIGNAL_BUSY,
00118         TRUNK_SIGNAL_CANCEL,
00119         TRUNK_SIGNAL_DRIVER
00120 }       trunksignal_t;
00121 
00122 typedef enum {
00123         // primary state handlers
00124 
00125         TRUNK_ENTER_STATE = 100,// newly entered handler state
00126         TRUNK_EXIT_STATE,       // exiting prior state (unused)
00127         TRUNK_STOP_STATE,       // request state termination
00128         TRUNK_NOTIFICATION,     // death notify event
00129         TRUNK_SERVICE_SUCCESS,  // service completion successful
00130         TRUNK_SERVICE_FAILURE,  // service completion failed
00131         TRUNK_SERVICE_LOOKUP,   // lookup transaction
00132         TRUNK_SERVICE_LOGIN,    // login transaction
00133         TRUNK_JOIN_REQUEST,     // request a join
00134         TRUNK_JOIN_ACCEPT,      // accept a join
00135         TRUNK_JOIN_CANCEL,      // cancel a join
00136 
00137         // tgi/integration control state handlers
00138 
00139         TRUNK_EXIT_SHELL = 200, // tgi completion event
00140         TRUNK_START_SCRIPT,     // start of script
00141         TRUNK_RING_START,       // smdi/integrated answer
00142         TRUNK_STOP_DISCONNECT,  // integrated hangup notification
00143 
00144         // in the future these will be used
00145 
00146         TRUNK_START_INCOMING = TRUNK_RING_START,
00147         TRUNK_START_OUTGOING = TRUNK_START_SCRIPT,
00148 
00149         // primary "mode" selection controls
00150 
00151         TRUNK_MAKE_TEST =  300, // request driver perform line test
00152         TRUNK_MAKE_BUSY,        // request driver lockout line
00153         TRUNK_MAKE_IDLE,        // request driver reset line
00154         TRUNK_MAKE_STEP,        // pass step event internally
00155 
00156         // basic trunk events
00157 
00158         TRUNK_LINE_WINK = 400,  // used for line disconnect notification
00159         TRUNK_TIMER_EXPIRED,    // driver specific port timer expired
00160         TRUNK_RINGING_ON,       // some drivers distinguish start/stop
00161         TRUNK_RINGING_OFF,      // default ring event
00162         TRUNK_TEST_IDLE,        // some drivers have line test completion
00163         TRUNK_TEST_FAILURE,     // some drivers notify errors
00164         TRUNK_ON_HOOK,          // some drivers notify on hook
00165         TRUNK_OFF_HOOK,         // some drivers notify off hook
00166         TRUNK_CALLER_ID,        // caller id parse request
00167         TRUNK_RINGING_DID,      // did digit ring signal
00168         TRUNK_CALL_DETECT,      // ISDN call detected notification
00169         TRUNK_CALL_CONNECT,     // ISDN call connection notification
00170         TRUNK_CALL_RELEASE,     // ISDN call release notification
00171         TRUNK_CALL_ACCEPT,      // ISDN incoming call accepted
00172         TRUNK_CALL_RINGING,     // digital T1 incoming call
00173         TRUNK_CALL_DISCONNECT,  // digital T1 circuit break
00174 
00175         // basic audio processing events
00176 
00177         TRUNK_AUDIO_IDLE = 500, // audio reset or completion event
00178         TRUNK_INPUT_PENDING,    // some drivers monitor audio i/o status
00179         TRUNK_OUTPUT_PENDING,   // some drivers monitor audio i/p status
00180         TRUNK_AUDIO_BUFFER,     // some drivers return audio buffers
00181         TRUNK_TONE_IDLE,        // tone generator completion event
00182         TRUNK_DTMF_KEYDOWN,     // some drivers distinguish tone down
00183         TRUNK_DTMF_KEYUP,       // default dtmf event
00184         TRUNK_TONE_START,       // tone detected
00185         TRUNK_TONE_STOP,        // some drivers have tone completion event
00186         TRUNK_FSK_DETECT,       // fsk tone detect
00187         TRUNK_FAX_DETECT,       // fax tone detect
00188         TRUNK_VOX_DETECT,       // speaker detected
00189         TRUNK_AUDIO_START,      // some drivers may "vox" compress
00190         TRUNK_AUDIO_STOP,       // some drivers may "vox" compress
00191         TRUNK_CPA_DIALTONE,     // dialtone heard on the line
00192         TRUNK_CPA_BUSYTONE,
00193         TRUNK_CPA_RINGING,
00194         TRUNK_CPA_INTERCEPT,
00195         TRUNK_CPA_NODIALTONE,
00196         TRUNK_CPA_NORINGBACK,
00197         TRUNK_CPA_NOANSWER,
00198         TRUNK_CPA_CONNECT,
00199         TRUNK_DSP_READY,        // dsp resource became available
00200 
00201         // driver specific events and anomolies
00202 
00203         TRUNK_DRIVER_SPECIFIC=8000      // very oddball events
00204 } trunkevent_t;
00205 
00206 typedef enum
00207 {
00208         DSP_MODE_INACTIVE = 0,  // dsp is idle
00209         DSP_MODE_VOICE,         // standard voice processing
00210         DSP_MODE_CALLERID,      // caller id support
00211         DSP_MODE_DATA,          // fsk modem mode
00212         DSP_MODE_FAX,           // fax support
00213         DSP_MODE_TDM,           // TDM bus with echo cancellation
00214         DSP_MODE_VOIP           // VoIP full duplex
00215 } dspmode_t;
00216 
00217 typedef enum
00218 {
00219         TRUNK_MODE_INCOMING = 0,
00220         TRUNK_MODE_OUTGOING,
00221         TRUNK_MODE_INACTIVE,
00222         TRUNK_MODE_UNAVAILABLE
00223 } trunkmode_t;
00224  
00225 typedef enum
00226 {
00227         STAT_MAX_INCOMING,
00228         STAT_MAX_OUTGOING,
00229         STAT_TOT_INCOMING,
00230         STAT_TOT_OUTGOING
00231 } statitem_t;
00232 
00233 #define TRUNK_CAP_VOICE         0x00000001
00234 #define TRUNK_CAP_DIAL          0x00000002
00235 #define TRUNK_CAP_SENDFAX       0x00000004
00236 #define TRUNK_CAP_RECVFAX       0x00000008
00237 #define TRUNK_CAP_DATA          0x00000010
00238 
00239 typedef union
00240 {
00241         scriptsymbol_t sym;
00242         char data[sizeof(scriptsymbol_t) + 12];
00243 }       numbersymbol_t;
00244 
00245 typedef union
00246 {
00247         scriptsymbol_t bin;
00248         char data[sizeof(scriptsymbol_t) + 32];
00249 }       digitsymbol_t;
00250 
00251 typedef struct
00252 {
00253         
00254         int pid;
00255         unsigned seq;
00256         void *data;
00257 }       execdata_t;
00258 
00259 typedef union
00260 {
00261         struct
00262         {
00263                 int rings;
00264                 int timeout;
00265         }       answer;
00266         struct
00267         {
00268                 char list[256];
00269                 char *name;
00270                 unsigned long offset;
00271                 unsigned long limit;
00272                 unsigned char volume;
00273         }       play;
00274         struct
00275         {
00276                 char *name;
00277                 timeout_t timeout;
00278                 unsigned long offset;
00279                 unsigned short term;
00280                 unsigned char volume;
00281                 unsigned long trim;
00282                 bool append;
00283         }       record;
00284         struct
00285         {
00286                 char digits[65];
00287                 char *digit;
00288                 timeout_t interdigit;
00289                 bool exit;
00290         }       dialxfer;
00291         struct
00292         {
00293                 timeout_t timeout;
00294                 unsigned count;
00295                 unsigned short term;
00296                 unsigned short ignore;
00297         }       collect;
00298         struct
00299         {
00300                 timeout_t wakeup;
00301                 unsigned rings;
00302                 unsigned loops;
00303         }       sleep;
00304         struct
00305         {
00306                 timeout_t wakeup;
00307                 unsigned loops;
00308                 phTone *tone;
00309         }       tone;
00310         struct
00311         {
00312                 timeout_t wakeup;
00313                 Trunk *join;
00314                 phTone *tone;
00315         }       join;
00316         struct
00317         {
00318                 timeout_t offhook;
00319                 timeout_t onhook;
00320         }       flash;
00321 }       trunkdata_t;
00322 
00323 typedef struct
00324 {
00325         trunkevent_t id;        // event id
00326         union
00327         {
00328                 struct
00329                 {
00330                         unsigned digit: 4;
00331                         unsigned duration: 12;
00332                         unsigned e1: 8;
00333                         unsigned e2: 8;
00334                 } dtmf;
00335                 struct
00336                 {
00337                         unsigned tone: 8;
00338                         unsigned energy: 8;
00339                         unsigned duration: 16;
00340                 } tone;
00341                 struct
00342                 {
00343                         unsigned digit:  4;
00344                         unsigned duration: 24;
00345                 } ring;
00346                 struct
00347                 {
00348                         unsigned seq;
00349                         bool result;
00350                         char *data;
00351                 } lookup;
00352                 int status;
00353                 Trunk *trunk;
00354                 void *data;
00355                 char **argv;
00356                 timeout_t duration;
00357                 trunkstep_t step;
00358                 char align[8];
00359                 dspmode_t dsp;
00360         } parm;
00361 } TrunkEvent;
00362 
00363 #pragma pack(1)
00364 typedef struct
00365 {
00366         char grp[32];
00367         char scr[32];
00368 }       schedtmp;
00369 
00370 typedef struct
00371 {
00372         time_t update;
00373         char name[16];
00374         unsigned char ports;
00375         char stat[255];
00376 }       statnode_t;
00377 
00378 #pragma pack()  
00379 
00380 /* This is used to bind user defined "functions" which may be loaded
00381    in a DSO module.
00382 */
00383 
00384 typedef char *(*functioncall_t)(scriptsymbol_t *sym, char **args);
00385 
00386 typedef struct
00387 {
00388         char *name;
00389         functioncall_t function;
00390 } FUNCTIONS;
00391 
00392 
00400 class CallStat : public Mutex
00401 {
00402 protected:
00403         int capacity;
00404         struct
00405         {
00406                 int incoming;
00407                 int outgoing;
00408         }       active, max, lastmax;
00409 
00410         struct
00411         {
00412                 long incoming;
00413                 long outgoing;
00414         }       total, lasttotal;
00415 
00416 public:
00417         CallStat();
00418 
00424         inline int getCapacity(void)
00425                 {return capacity;};
00426 
00433         long getStat(statitem_t item);
00434 
00438         void incIncoming(void);
00439 
00443         void decIncoming(void);
00444 
00448         void incOutgoing(void);
00449 
00453         void decOutgoing(void);
00454 
00458         void Update(void);
00459 };
00460 
00473 class Translator : protected Keydata
00474 {
00475 private:
00476         friend Translator *getTranslator(char *name);
00477         static Translator *first;
00478         Translator *next;
00479 
00480 protected:
00486         virtual char *getName(void) = 0;
00487 
00494         char *getPlayBuffer(Trunk *trunk);
00495 
00496         void scanDir(const char *language, const char *lib);
00497 
00498         Translator(const char *conf, const char *lib);
00499 
00500 public:
00508         virtual char *Speak(Trunk *trunk) = 0;
00509 };
00510 
00524 class Functions
00525 {
00526 protected:
00532         virtual char *getName(void) = 0;
00533 
00539         void Load(FUNCTIONS *map);
00540 };
00541 
00542 /* Bayonne config file istanciation classes.  In Bayonne these are
00543    created as keydata objects out of bayonne.conf during process
00544    startup automatically.  This is Bayonne runtime configuration magic.
00545 */
00546 
00553 class KeyTones : protected Keydata
00554 {
00555 public:
00559         KeyTones();
00560 };
00561 
00569 class KeyLocal : public Keydata
00570 {
00571 public:
00575         KeyLocal();
00576 };
00577 
00585 class KeyPaths : public Keydata
00586 {
00587 public:
00591         KeyPaths();
00592 
00596         inline const char *getLibexec(void)
00597                 {return getLast("libexec");};
00598 
00602         inline const char *getTgipath(void)
00603                 {return getLast("tgipath");};
00604 
00608         inline const char *getLibpath(void)
00609                 {return getLast("libpath");};
00610 
00614         inline const char *getDatafiles(void)
00615                 {return getLast("datafiles");};
00616 
00620         inline const char *getRunfiles(void)
00621                 {return getLast("runfiles");};
00622 
00626         inline const char *getSpool(void)
00627                 {return getLast("spool");};
00628 
00632         inline const char *getScriptFiles(void)
00633                 {return getLast("scripts");};
00634 
00638         inline const char *getCache(void)
00639                 {return getLast("precache");};
00640 };
00641 
00649 class KeyNetwork : public Keydata
00650 {
00651 public:
00655         KeyNetwork();
00656 
00662         unsigned getRefresh(void)
00663                 {return atoi(getLast("refresh"));};
00664 
00670         unsigned getDatabaseDelay(void)
00671                 {return atoi(getLast("databasedelay"));};
00672 
00678         InetHostAddress getBroadcast(void);
00679 
00685         InetAddress getAddress(void);
00686 
00692         tpport_t getPort(void);
00693 
00700         InetHostAddress getDatabase(unsigned id);
00701 
00708         tpport_t getDatabasePort(unsigned id);
00709 };
00710 
00718 class KeyMailbox : public Keydata
00719 {
00720 public:
00724         KeyMailbox();
00725 
00731         inline unsigned getCount(void)
00732                 {return atoi(getLast("count"));};
00733 
00739         inline unsigned getLimit(void)
00740                 {return atoi(getLast("limit"));};
00741 
00748         inline unsigned getQuota(void)
00749                 {return atoi(getLast("quota"));};
00750 
00756         inline unsigned getMinimum(void)
00757                 {return atoi(getLast("minimum"));};
00758 
00764         inline unsigned getMaximum(void)
00765                 {return atoi(getLast("maximum"));};
00766 
00772         inline const char *getPassword(void)
00773                 {return getLast("password");};
00774 };
00775 
00784 class KeyMemory : public Keydata
00785 {
00786 public:
00790         KeyMemory();
00791 
00797         inline int getSymbolSize(void)
00798                 {return atoi(getLast("symbols"));};
00799 
00806         inline int getPageSize(void)
00807                 {return atoi(getLast("page"));};
00808 };
00809 
00817 class KeyFeed : public Keydata
00818 {
00819 public:
00823         KeyFeed();
00824 
00830         inline unsigned getBuffers(void)
00831                 {return atoi(getLast("buffers"));};
00832 };
00833 
00834 
00842 class KeyThreads : public Keydata
00843 {
00844 public:
00848         KeyThreads();
00849 
00855         inline int priService(void)
00856                 {return atoi(getLast("services"));};
00857 
00863         inline int priScheduler(void)
00864                 {return atoi(getLast("scheduler"));};
00865 
00871         inline int priGUI(void)
00872                 {return atoi(getLast("gui"));};
00873 
00879         inline int getStepDelay(void)
00880                 {return atoi(getLast("stepdelay"));};
00881 
00887         inline int getStepInterval(void)
00888                 {return atoi(getLast("stepinterval"));};
00889 
00895         inline int getResetDelay(void)
00896                 {return atoi(getLast("resetdelay"));};
00897 
00903         size_t getStack(void);
00904 
00910         int getServices(void);
00911 
00917         int priResolver(void);
00918 
00925         int getResolver(void);
00926 
00932         inline int priAudio(void)
00933                 {return atoi(getLast("audio"));};
00934 
00940         inline int priFeed(void)
00941                 {return atoi(getLast("feed"));};
00942 
00948         inline int priGateway(void)
00949                 {return atoi(getLast("gateways"));};
00950 
00956         inline int priManager(void)
00957                 {return atoi(getLast("managers"));};
00958 
00964         inline int priNetwork(void)
00965                 {return atoi(getLast("network"));};
00966 
00972         inline int getInterval(void)
00973                 {return atoi(getLast("interval"));};
00974 
00980         inline int getRefresh(void)
00981                 {return atoi(getLast("refresh"));};
00982 
00988         int getGateways(void);
00989         
00996         inline int getPriority(void)
00997                 {return atoi(getLast("priority"));};
00998 
01004         int getPolicy(void);
01005 
01011         inline int getPages(void)
01012                 {return atoi(getLast("pages"));};
01013 };
01014 
01022 class Auditdata : public Keydata
01023 {
01024 private:
01025         friend class Audit;
01026 
01027         Auditdata();
01028 };
01029 
01039 class Request
01040 {
01041 private:
01042         friend class TrunkGroup;
01043 
01044         static unsigned seq;
01045 
01046         unsigned id;
01047         Request *next;
01048         time_t expires;
01049         TrunkGroup *group;
01050 
01051         char *argv[33];
01052         char buffer[512];
01053 
01054         void Detach(void);
01055         
01056 public:
01057         Request(TrunkGroup *grp, const char *text, unsigned expire);
01058         ~Request()
01059                 {Detach();};
01060 
01061         inline char **getList(void)
01062                 {return argv;};
01063 
01064         bool isExpired(void);
01065 };
01066 
01077 class TrunkGroup : public Keydata, public CallStat
01078 {
01079 private:
01080         friend class KeyServer;
01081         friend class Scheduler;
01082         friend class Audit;
01083         friend class TestDebug;
01084         friend class Request;
01085         static TrunkGroup *first;
01086         TrunkGroup *next;
01087         char schedule[65];
01088         Request *reqfirst, *reqlast;
01089 
01090         void setSchedule(const char *str);
01091 
01092 public:
01098         TrunkGroup(char *name = NULL);
01099 
01105         inline const char *getName(void)
01106                 {return getLast("name");};
01107 
01113         inline unsigned getAnswer(void)
01114                 {return atoi(getLast("answer"));};
01115 
01121         inline unsigned getCallerid(void)
01122                 {return atoi(getLast("callerid"));};
01123 
01129         inline unsigned getPickup(void)
01130                 {return atoi(getLast("pickup"));};
01131 
01137         inline const char *chkRequest(void)
01138                 {return getLast("requests");};
01139 
01145         seltype_t getSelect(void);
01146 
01153         inline timeout_t getReady(void)
01154                 {return atol(getLast("ready"));};
01155         
01161         inline unsigned getRingTime(void)
01162                 {return atoi(getLast("ringtime"));};
01163 
01169         inline int getHangup(void)
01170                 {return atoi(getLast("hangup"));};
01171 
01177         inline timeout_t getFlash(void)
01178                 {return atol(getLast("flash"));};
01179 
01185         inline timeout_t getDialtone(void)
01186                 {return atol(getLast("dialtone"));};
01187 
01193         inline timeout_t getDialspeed(void)
01194                 {return atol(getLast("dialspeed"));};
01195 
01202         const char *getNumber(void);
01203 
01210         const char *getSchedule(char *buf);
01211 
01215         inline void incCapacity(void)
01216                 {++capacity;};
01217 
01223         Request *getRequest(void);
01224 
01230         friend TrunkGroup *getGroup(const char *name);
01231 };
01232 
01240 class KeyServer : public Keydata
01241 {
01242 private:
01243         unsigned uid, gid;
01244 
01245 public:
01249         KeyServer();
01250 
01256         inline const char *getNode(void)
01257                 {return getLast("node");};
01258 
01264         inline const char *getToken(void)
01265                 {return getLast("token");};
01266 
01270         void loadGroups(void);
01271 
01277         inline const char *getDefault(void)
01278                 {return getLast("default");};
01279 
01285         inline unsigned getGid(void)
01286                 {return gid;};
01287 
01293         inline unsigned getUid(void)
01294                 {return uid;};
01295 
01301         inline int getNodeCount(void)
01302                 {return atoi(getLast("nodes"));};
01303 };
01304 
01312 class Plugins : public Keydata
01313 {
01314 public:
01318         Plugins();
01319 
01323         ~Plugins();
01324 
01330         char *getDriverName(void);
01331 
01335         void loadDebug(void);
01336 
01341         DSO *loadDriver(void);
01342 
01346         void loadExtensions(void);
01347 
01351         void loadFunctions(void);
01352 
01356         void loadMaps(void);
01357 
01361         void loadModules(void);
01362 
01366         void loadFeeds(void);
01367 
01371         void loadTGI(void);
01372 
01376         void loadManagers(void);
01377 
01381         void loadTranslators(void);
01382 
01386         void loadAuditing(void);
01387 };
01388 
01397 class aaScript : public ScriptCommand 
01398 {
01399 private:
01400         friend class Functions;
01401 
01402 #pragma pack(1)
01403         typedef struct _functions
01404         {
01405                 struct _functions *next;
01406                 functioncall_t function;
01407                 char name[1];
01408         }       functions_t;
01409 #pragma pack()
01410 
01411         functions_t *functions[KEYWORD_INDEX_SIZE];
01412 
01413 protected:
01421         unsigned long getTrapMask(const char *trapname);
01422 
01430         void addFunction(char *name, functioncall_t function);
01431 
01432 public:
01439         functioncall_t getFunction(char *name);
01440 
01444         aaScript();
01445 
01451         void addModule(Module *module);
01452 };
01453 
01463 class aaImage : public ScriptImage
01464 {
01465 protected:
01473         virtual bool isScript(char *scriptname);
01474 
01481         void scanDir(char *path);
01482 
01483 public:
01487         aaImage(aaScript *script);
01488 };
01489 
01499 class Trunk : public ScriptInterp
01500 {
01501 private:
01502         friend class TestDebug;
01503         friend class aaScript;
01504         friend class Translator;
01505         friend class ScriptInterface;
01506         friend class Service;
01507         friend class Fifo;
01508         friend class PortManager;
01509 
01510         char *cdrv[33];
01511         int cdrc;
01512         numbersymbol_t numbers[5];
01513 
01514         bool scrRequest(void);
01515         bool scrLibonce(void);
01516         bool scrLibexec(void);
01517         bool scrHangup(void);
01518         bool scrDebug(void);
01519         bool scrImport(void);
01520         bool scrExport(void);
01521         bool scrFunction(void);
01522         bool scrAlog(void);
01523         bool scrAudit(void);
01524         bool scrPause(void);
01525         bool scrSleep(void);
01526         bool scrWait(void);
01527         bool scrTone(void);
01528         bool scrAnswer(void);
01529         bool scrCollect(void);
01530         bool scrFlash(void);
01531         bool scrPlay(void);
01532         bool scrRecord(void);
01533         bool scrAppend(void);
01534         bool scrDial(void);
01535         bool scrTransfer(void);
01536         bool scrSpeak(void);
01537         bool scrMap(void);
01538         bool scrModule(void);
01539 
01540 protected:
01541         static ScriptSymbol globals;
01542         static char digit[16];
01543         ScriptInterface *script;
01544         TrunkGroup *group;
01545         PortManager *manager;
01546         int id;
01547         time_t start, idle;
01548 
01549         int rings;
01550         int digits;
01551 
01552         Service *thread;
01553         trunkdata_t data;
01554         execdata_t tgi;
01555         digitsymbol_t dtmf;
01556 
01557         struct
01558         {
01559                 bool offhook: 1;
01560                 bool dtmf: 1;
01561                 bool script: 1;
01562                 bool reset: 1;
01563                 bool timer : 1;
01564                 bool audio: 1;
01565                 bool once : 1;
01566                 bool ready : 1;
01567                 unsigned temp : 2;
01568                 trunkmode_t trunk: 2;
01569                 dspmode_t dsp: 4;
01570         } flags;
01571 
01577         unsigned long getTrapDefault(void)
01578                 {return 0x00000007;};
01579 
01588         void setConstant(const char *id, const char *data);
01589 
01597         scriptsymbol_t *getEntry(const char *symname, int size);
01598 
01604         void Commit(scriptsymbol_t *sym);
01605 
01612         int getTimeout(void);
01613 
01620         int getInterdigit(void);
01621 
01627         unsigned short getDigitMask(void);
01628 
01634         bool TrunkSignal(trunksignal_t);
01635 
01642         virtual void setDTMFDetect(void);
01643 
01652         virtual void setDTMFDetect(bool enable)
01653                 {flags.dtmf = enable;};
01654 
01660         virtual void stopServices(void);
01661 
01672         virtual void TrunkStep(trunkstep_t step) = 0;
01673 
01680         virtual unsigned long getIdleTime(void) = 0;
01681 
01685         bool ScriptStep(void);
01686 
01695         bool Attach(const char *scrname);
01696 
01701         void Detach(void);
01702 
01706         unsigned long getMask(void);
01707 
01714         char **getInitial(char **args);
01715 
01722         void setList(char **list);
01723 
01724         Trunk(int port);
01725 public:
01731         virtual unsigned long getCapabilities(void)
01732                 {return TRUNK_CAP_VOICE | TRUNK_CAP_DIAL;};
01733 
01739         virtual void getName(char *buffer) = 0;
01740 
01748         virtual bool postEvent(TrunkEvent *event) = 0;
01749 
01755         int getDigit(char digit);
01756 
01762         bool isReady(void);
01763 };
01764 
01773 class PortManager
01774 {
01775 private:
01776         Trunk *trunk;
01777 
01778 protected:
01779         ~PortManager()
01780                 {trunk->manager = NULL;};
01781 
01787         PortManager(Trunk *trk);
01788 
01794         inline void postStep(trunkstep_t step)
01795                 {trunk->TrunkStep(step);};
01796 
01803         inline bool postEvent(TrunkEvent *event)
01804                 {return trunk->postEvent(event);};
01805 
01811         inline trunkdata_t *getData(void)
01812                 {return &trunk->data;};
01813 
01819         inline execdata_t *getExec(void)
01820                 {return &trunk->tgi;};
01821 public:
01825         virtual bool Step(void) = 0;
01826 
01832         virtual unsigned long getMask(void) = 0;
01833         
01840         virtual bool postSignal(trunksignal_t signal) = 0;
01841 
01848         virtual bool postAccept(const char *name) = 0;
01849 
01853         virtual void postDetach(void) = 0;
01854 };
01855 
01865 class Fifo : public fifostream, public Mutex
01866 {
01867 protected:
01868         bool exitPid(char **args);
01869         bool waitPid(char **args);
01870         bool setSymbol(char **argv);
01871         bool putSymbol(char **argv);
01872         bool submit(char **argv);
01873         bool login(char **argv);
01874         bool mapFiles(char **argv);
01875         bool startScript(char **argv);
01876         bool ringScript(char **argv);
01877         bool busyLine(char **argv);
01878         bool idleLine(char **argv);
01879         bool hangupLine(char **argv);
01880         bool reqScript(char **argv);
01881 
01882 public:
01890         bool Command(const char *cmdstring);
01891 };
01892 
01900 class FifoHandler
01901 {
01902 private:
01903         friend class Fifo;
01904 
01905         static FifoHandler *first;
01906         FifoHandler *next;
01907 protected:
01914         virtual bool Command(char **argv) = 0;
01915 
01919         FifoHandler();
01920 };
01921 
01935 class Audit : public Mutex
01936 {
01937 private:
01938         friend void audit(char *detail);
01939         friend class Scheduler;
01940 
01941         static Audit *first;
01942         Audit *next;
01943 
01944 protected:
01945         static Auditdata keys;
01946 
01952         virtual void Report(char *detail) = 0;
01953 
01957         virtual void Stats(void) = 0;
01958 
01964         inline TrunkGroup *getFirst(void)
01965                 {return TrunkGroup::first;};
01966 
01973         inline TrunkGroup *getNext(TrunkGroup *grp)
01974                 {return grp->next;};
01975 
01979         Audit();
01980 };
01981 
01989 class Driver : public aaScript
01990 {
01991 protected:
01992         friend class TrunkGroup;
01993 
01994         TrunkGroup **groups;
01995         char *status;
01996         bool active;
01997 
01998 public:
02002         Driver();
02003 
02010         virtual int Start(void) = 0;
02011 
02015         virtual void Stop(void) = 0;
02016 
02022         void getStatus(char *buffer);
02023 
02030         virtual aaImage *getImage(void);
02031 
02038         virtual int getTrunkCount(void) = 0;
02039 
02046         virtual int getTrunkUsed(void) 
02047                 {return getTrunkCount();};
02048 
02055         TrunkGroup *getTrunkGroup(int id)
02056                 {return groups[id];}; 
02057         
02063         virtual Trunk *getTrunkPort(int id) = 0;
02064 };
02065 
02072 class Debug : protected Mutex
02073 {
02074 public:
02078         Debug();
02079 
02085         virtual bool DebugTest(void)
02086                 {return false;};
02087 
02091         virtual void DebugEvent(Trunk *trunk, TrunkEvent *event)
02092                 {return;};
02093 
02097         virtual void DebugState(Trunk *trunk, char *state)
02098                 {return;};
02099 
02103         virtual void DebugService(Trunk *trunk, char *msg)
02104                 {return;};
02105 
02109         virtual void DebugScript(Trunk *trunk, char *msg)
02110                 {return;};
02111 
02115         virtual void DebugStep(Trunk *trunk, scriptline_t *line)
02116                 {DebugState(trunk, "step");};
02117 
02121         virtual bool DebugFifo(char **argv)
02122                 {return true;};
02123 };
02124 
02132 class Service : public Semaphore, public Thread
02133 {
02134 private:
02135         char filename[256];
02136 
02137 protected:
02138         volatile bool stopped;
02139         Trunk *trunk;
02140         TrunkGroup *group;
02141         trunkdata_t *data;
02142 
02146         void Success(void);
02147 
02151         void Failure(void);
02152 
02159         char *getPrompt(char *name); 
02160 
02166         char *getPlayfile(void);
02167 
02171         inline void dspReset(void)
02172                 {trunk->flags.reset = true;};
02173 
02177         inline void setAudio(void)
02178                 {trunk->flags.audio = true;};
02179 
02183         inline void clrAudio(void)
02184                 {trunk->flags.audio = false;};
02185 
02186 public:
02193         Service(Trunk *trunk, int pri);
02194 
02201         virtual timeout_t Stop(void);
02202 
02210         virtual bool isExiting(void)
02211                 {return true;};
02212 
02216         virtual ~Service()
02217                 {Terminate();}
02218 
02219 };
02220 
02230 class Server : public Thread
02231 {
02232 private:
02233         static Server *first;
02234         Server *next;
02235         friend void startServers(void);
02236         friend void stopServers(void);
02237 
02238 protected:
02239         Server(int pri);
02240 
02244         virtual void Stop(void)
02245                 {Terminate();};
02246 };
02247 
02254 class Sync
02255 {
02256 private:
02257         friend class Scheduler;
02258 
02259         static Sync *first;
02260         Sync *next;
02261         time_t runtime;
02262 
02263 protected:
02267         Sync(void);
02268 
02273         virtual bool isScheduled(void) = 0;
02274 
02279         virtual unsigned getInterval(void)
02280                 {return 10;};
02281 
02285         virtual void Schedule(void) = 0;
02286 
02290         virtual char *getName(void) = 0;
02291 };
02292 
02301 class phTone
02302 {
02303 private:
02304         friend phTone *getphTone(const char *name);
02305         static phTone *first;
02306         static int ulaw[256];
02307         phTone *next;
02308         char name[33];
02309         unsigned char *samples;
02310         timeout_t duration;
02311         unsigned freq1, freq2;
02312 
02313 public:
02321         phTone(const char *name, timeout_t duration, unsigned f);
02322 
02331         phTone(const char *name, timeout_t duration, unsigned f1, unsigned f2);
02332 
02333         ~phTone();
02334 
02340         void Clear(void);
02341 
02347         inline unsigned char *getSamples(void)
02348                 {return samples;};
02349 
02355         inline timeout_t getDuration(void)
02356                 {return duration;};
02357 };
02358 
02365 class TGI
02366 {
02367 private:
02368         static TGI *first;
02369         TGI *next;
02370 
02371 protected:
02372         TGI();
02373 
02381         virtual bool getExtension(char *ext)
02382                 {return false;};
02383 
02384 public:
02394         virtual void Script(char *cmd, char **args)
02395                 {return;};
02396 
02405         virtual int Parse(int fd, int port, char *cmd)
02406                 {return -1;};   
02407 
02408         friend void getInterp(char *cmd, char **args);
02409         friend TGI *getInterp(char *cmd);
02410 };
02411         
02421 class Module
02422 {
02423 private:
02424         static Module *first;
02425         Module *next;
02426 
02427 protected:
02428         Module();
02429 
02435         virtual modtype_t getType(void) = 0;
02436 
02437 public:
02443         virtual char *getName(void) = 0;
02444 
02452         virtual char *Dispatch(Trunk *trunk) = NULL;
02453 
02461         virtual unsigned Sleep(Trunk *trunk)
02462                 {return 0;};
02463 
02468         virtual void Detach(Trunk *trunk)
02469                 {return;};
02470 
02471 public:
02472         friend Module *getModule(modtype_t mod, const char *name = NULL);
02473         friend void detachModules(Trunk *trunk);
02474 };
02475 
02485 class Session
02486 {
02487 private:
02488         friend class Scheduler;
02489         static Mutex mutex;
02490         static Session *first;
02491         static Session *last;
02492         Session *next, *prev;
02493         static void Clean(void);
02494 
02495 protected:
02496         Session();
02497         virtual ~Session()
02498                 {Unlink();};
02499 
02503         void Unlink(void);
02504 
02511         virtual time_t getExpires(void) = 0;
02512 };
02513 
02522 class AudioFeed : private ThreadLock
02523 {
02524 private:
02525         static AudioFeed *first;
02526         AudioFeed *next;
02527         unsigned char *buffers;
02528         volatile unsigned char *current;
02529         size_t feedsize, bufsize;
02530         bool active;
02531 
02532 protected:
02533         const char *name;
02534 
02535 public:
02536         AudioFeed(const char *name, unsigned buffers);
02537         ~AudioFeed();
02538         bool Enable(void);
02539         void Disable(void);
02540         unsigned char *getBuffer(unsigned char *prior = NULL, unsigned size = 120);
02541         void putBuffer(unsigned char *buffer, unsigned size = 120);
02542 
02543         friend AudioFeed *getAudioFeed(const char *name);
02544 };
02545 
02554 class Map : private MemPager
02555 {
02556 private:
02557         static ThreadLock lock;
02558         static Map *first, *last;
02559 
02560         typedef struct _sym
02561         {
02562                 struct _sym *next;
02563                 char *key;
02564                 char **values;
02565         }       mapsym_t;
02566 
02567         typedef struct
02568         {
02569                 mapsym_t *keys[127];
02570         } mapkey_t;
02571 
02572         mapkey_t *digits[32];
02573 
02574         Map *next, *prev;
02575         char *name;
02576 
02577         unsigned getKey(const char *key, unsigned len = 0);
02578         char **getList(const char *key, unsigned len);
02579         ~Map();
02580 
02581 public:
02582         Map(const char *path, const char *name);
02583 
02584         friend char **getMap(const char *map, const char *key);
02585         friend void endMaps(void);
02586 };
02587 
02596 class Protocol : public Keydata, public InetHostAddress, public ThreadLock
02597 {
02598 private:
02599         friend class Resolver;
02600         static Protocol *first;
02601         Protocol *next;
02602         Semaphore *sessions;
02603         tpport_t port;
02604 
02605         void Update(InetHostAddress addr);
02606 public:
02607         Protocol(const char *keypath, tpport_t port);
02608         ~Protocol();
02609 
02615         InetHostAddress getAddress(void);
02616 
02622         inline tpport_t getPort(void)
02623                 {return port;};
02624 
02631         inline Semaphore *getSessions(void)
02632                 {return sessions;};
02633 };
02634 
02635 extern KeyServer keyserver;
02636 extern KeyThreads keythreads;
02637 extern KeyMemory keymemory;
02638 extern KeyPaths keypaths;
02639 extern KeyLocal keylocal;
02640 extern KeyNetwork keynetwork;
02641 extern KeyMailbox keymailbox;
02642 extern KeyTones keytones;
02643 extern KeyFeed keyfeed;
02644 extern Plugins plugins;
02645 extern Driver *driver;
02646 extern Debug *debug;
02647 extern Fifo fifo;
02648 #endif
02649 

Generated at Fri Dec 15 12:35:19 2000 for Bayonne by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000