00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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 00054 00055 00056 00057
00058
00059 class Trunk;
00060 class Service;
00061 class phTone;
00062 class TrunkGroup;
00063 class Module;
00064
00065 typedef enum
00066 {
00067 SELECT_FIRST,
00068 SELECT_LAST
00069 } seltype_t;
00070
00071 typedef enum {
00072 MODULE_GENERIC,
00073 MODULE_DELIVERY,
00074 MODULE_SENDFILE,
00075 MODULE_SENDFAX,
00076 MODULE_NOTIFY,
00077 MODULE_TGI,
00078 MODULE_ANY
00079 } modtype_t;
00080
00081 typedef enum {
00082
00083 TRUNK_STEP_HANGUP = 0,
00084 TRUNK_STEP_SLEEP,
00085 TRUNK_STEP_ANSWER,
00086 TRUNK_STEP_COLLECT,
00087 TRUNK_STEP_PLAY,
00088 TRUNK_STEP_RECORD,
00089 TRUNK_STEP_TONE,
00090 TRUNK_STEP_DIALXFER,
00091 TRUNK_STEP_FLASH,
00092 TRUNK_STEP_JOIN,
00093 TRUNK_STEP_RTP,
00094 TRUNK_STEP_DUPLEX,
00095 TRUNK_STEP_DETECT,
00096 TRUNK_STEP_REQUIRES,
00097 TRUNK_STEP_EXIT = TRUNK_STEP_HANGUP,
00098 TRUNK_STEP_DRIVER
00099 } trunkstep_t;
00100
00101 typedef enum {
00102
00103 TRUNK_SIGNAL_STEP = 0,
00104 TRUNK_SIGNAL_EXIT,
00105 TRUNK_SIGNAL_HANGUP=TRUNK_SIGNAL_EXIT,
00106 TRUNK_SIGNAL_ERROR,
00107 TRUNK_SIGNAL_TIMEOUT,
00108 TRUNK_SIGNAL_DTMF,
00109 TRUNK_SIGNAL_0,
00110 TRUNK_SIGNAL_1,
00111 TRUNK_SIGNAL_2,
00112 TRUNK_SIGNAL_3,
00113 TRUNK_SIGNAL_4,
00114 TRUNK_SIGNAL_5,
00115 TRUNK_SIGNAL_6,
00116 TRUNK_SIGNAL_7,
00117 TRUNK_SIGNAL_8,
00118 TRUNK_SIGNAL_9,
00119 TRUNK_SIGNAL_STAR,
00120 TRUNK_SIGNAL_POUND,
00121 TRUNK_SIGNAL_A,
00122 TRUNK_SIGNAL_B,
00123 TRUNK_SIGNAL_C,
00124 TRUNK_SIGNAL_D,
00125 TRUNK_SIGNAL_DIALTONE,
00126 TRUNK_SIGNAL_BUSY,
00127 TRUNK_SIGNAL_CANCEL,
00128 TRUNK_SIGNAL_SIGNAL,
00129 TRUNK_SIGNAL_DRIVER
00130 } trunksignal_t;
00131
00132 typedef enum {
00133
00134
00135 TRUNK_ENTER_STATE = 100,
00136 TRUNK_EXIT_STATE,
00137 TRUNK_STOP_STATE,
00138 TRUNK_NOTIFICATION,
00139 TRUNK_SERVICE_SUCCESS,
00140 TRUNK_SERVICE_FAILURE,
00141 TRUNK_SERVICE_LOOKUP,
00142 TRUNK_SERVICE_LOGIN,
00143 TRUNK_SIGNAL_NOTIFY,
00144 TRUNK_JOIN_TRUNKS,
00145 TRUNK_PART_TRUNKS,
00146 TRUNK_NULL_EVENT,
00147
00148
00149
00150 TRUNK_EXIT_SHELL = 200,
00151 TRUNK_START_SCRIPT,
00152 TRUNK_RING_START,
00153 TRUNK_RING_REDIRECT,
00154 TRUNK_STOP_DISCONNECT,
00155
00156
00157
00158 TRUNK_START_INCOMING = TRUNK_RING_START,
00159 TRUNK_START_OUTGOING = TRUNK_START_SCRIPT,
00160
00161
00162
00163 TRUNK_MAKE_TEST = 300,
00164 TRUNK_MAKE_BUSY,
00165 TRUNK_MAKE_IDLE,
00166 TRUNK_MAKE_STEP,
00167
00168
00169
00170 TRUNK_LINE_WINK = 400,
00171 TRUNK_TIMER_EXPIRED,
00172 TRUNK_RINGING_ON,
00173 TRUNK_RINGING_OFF,
00174 TRUNK_TEST_IDLE,
00175 TRUNK_TEST_FAILURE,
00176 TRUNK_ON_HOOK,
00177 TRUNK_OFF_HOOK,
00178 TRUNK_CALLER_ID,
00179 TRUNK_RINGING_DID,
00180 TRUNK_CALL_DETECT,
00181 TRUNK_CALL_CONNECT,
00182 TRUNK_CALL_RELEASE,
00183 TRUNK_CALL_ACCEPT,
00184 TRUNK_CALL_RINGING,
00185 TRUNK_CALL_DISCONNECT,
00186
00187
00188
00189 TRUNK_AUDIO_IDLE = 500,
00190 TRUNK_INPUT_PENDING,
00191 TRUNK_OUTPUT_PENDING,
00192 TRUNK_AUDIO_BUFFER,
00193 TRUNK_TONE_IDLE,
00194 TRUNK_DTMF_KEYDOWN,
00195 TRUNK_DTMF_KEYUP,
00196 TRUNK_TONE_START,
00197 TRUNK_TONE_STOP,
00198 TRUNK_FSK_DETECT,
00199 TRUNK_FAX_DETECT,
00200 TRUNK_VOX_DETECT,
00201 TRUNK_AUDIO_START,
00202 TRUNK_AUDIO_STOP,
00203 TRUNK_CPA_DIALTONE,
00204 TRUNK_CPA_BUSYTONE,
00205 TRUNK_CPA_RINGING,
00206 TRUNK_CPA_RINGBACK = TRUNK_CPA_RINGING,
00207 TRUNK_CPA_INTERCEPT,
00208 TRUNK_CPA_NODIALTONE,
00209 TRUNK_CPA_NORINGBACK,
00210 TRUNK_CPA_NOANSWER,
00211 TRUNK_CPA_CONNECT,
00212 TRUNK_CPA_FAILURE,
00213 TRUNK_DSP_READY,
00214
00215
00216
00217 TRUNK_DRIVER_SPECIFIC=8000
00218 } trunkevent_t;
00219
00220 typedef enum
00221 {
00222 DSP_MODE_INACTIVE = 0,
00223 DSP_MODE_VOICE,
00224 DSP_MODE_CALLERID,
00225 DSP_MODE_DATA,
00226 DSP_MODE_FAX,
00227 DSP_MODE_TDM,
00228 DSP_MODE_RTP,
00229 DSP_MODE_DUPLEX,
00230 DSP_MODE_JOIN,
00231 DSP_MODE_CONF,
00232 DSP_MODE_TONE
00233 } dspmode_t;
00234
00235 typedef enum
00236 {
00237 TRUNK_MODE_INCOMING = 0,
00238 TRUNK_MODE_OUTGOING,
00239 TRUNK_MODE_INACTIVE,
00240 TRUNK_MODE_UNAVAILABLE
00241 } trunkmode_t;
00242
00243 typedef enum
00244 {
00245 STAT_MAX_INCOMING,
00246 STAT_MAX_OUTGOING,
00247 STAT_TOT_INCOMING,
00248 STAT_TOT_OUTGOING
00249 } statitem_t;
00250
00251 #define TRUNK_CAP_VOICE 0x00000001
00252 #define TRUNK_CAP_DIAL 0x00000002
00253 #define TRUNK_CAP_SENDFAX 0x00000004
00254 #define TRUNK_CAP_RECVFAX 0x00000008
00255 #define TRUNK_CAP_DATA 0x00000010
00256
00257 typedef union
00258 {
00259 scriptsymbol_t sym;
00260 char data[sizeof(scriptsymbol_t) + 12];
00261 } numbersymbol_t;
00262
00263 typedef union
00264 {
00265 scriptsymbol_t bin;
00266 char data[sizeof(scriptsymbol_t) + 32];
00267 } digitsymbol_t;
00268
00269 typedef struct
00270 {
00271
00272 int pid;
00273 unsigned seq;
00274 void *data;
00275 } execdata_t;
00276
00277 typedef union
00278 {
00279 struct
00280 {
00281 int rings;
00282 int timeout;
00283 } answer;
00284 struct
00285 {
00286 char list[256];
00287 char *name;
00288 unsigned long offset;
00289 unsigned long limit;
00290 unsigned char volume;
00291 } play;
00292 struct
00293 {
00294 char *name;
00295 timeout_t timeout;
00296 unsigned long offset;
00297 unsigned short term;
00298 unsigned char volume;
00299 unsigned long trim;
00300 bool append;
00301 } record;
00302 struct
00303 {
00304 char digits[65];
00305 char *digit;
00306 timeout_t interdigit;
00307 bool exit;
00308 } dialxfer;
00309 struct
00310 {
00311 timeout_t timeout;
00312 } detect;
00313 struct
00314 {
00315 timeout_t timeout;
00316 unsigned count;
00317 unsigned short term;
00318 unsigned short ignore;
00319 } collect;
00320 struct
00321 {
00322 timeout_t wakeup;
00323 unsigned rings;
00324 unsigned loops;
00325 } sleep;
00326 struct
00327 {
00328 timeout_t wakeup;
00329 unsigned loops;
00330 phTone *tone;
00331 } tone;
00332 struct
00333 {
00334 timeout_t wakeup;
00335 Trunk *trunk;
00336 phTone *tone;
00337 } join;
00338 struct
00339 {
00340 timeout_t offhook;
00341 timeout_t onhook;
00342 } flash;
00343 struct
00344 {
00345 struct in_addr addr;
00346 unsigned short bind, port, term;
00347 audioencoding_t codec;
00348 } rtp;
00349 } trunkdata_t;
00350
00351 typedef struct
00352 {
00353 trunkevent_t id;
00354 union
00355 {
00356 struct
00357 {
00358 unsigned digit: 4;
00359 unsigned duration: 12;
00360 unsigned e1: 8;
00361 unsigned e2: 8;
00362 } dtmf;
00363 struct
00364 {
00365 unsigned tone: 8;
00366 unsigned energy: 8;
00367 unsigned duration: 16;
00368 } tone;
00369 struct
00370 {
00371 unsigned digit: 4;
00372 unsigned duration: 24;
00373 } ring;
00374 struct
00375 {
00376 unsigned seq;
00377 bool result;
00378 char *data;
00379 } lookup;
00380 int status;
00381 Trunk *trunk;
00382 void *data;
00383 char **argv;
00384 char *error;
00385 timeout_t duration;
00386 trunkstep_t step;
00387 char dn[8];
00388 dspmode_t dsp;
00389 } parm;
00390 } TrunkEvent;
00391
00392 00393 00394
00395
00396 typedef char *(*functioncall_t)(scriptsymbol_t *sym, char **args);
00397
00398 typedef struct
00399 {
00400 char *name;
00401 functioncall_t function;
00402 } FUNCTIONS;
00403
00404
00412 class CallStat : public Mutex
00413 {
00414 protected:
00415 int capacity;
00416 struct
00417 {
00418 int incoming;
00419 int outgoing;
00420 } active, max, lastmax;
00421
00422 struct
00423 {
00424 long incoming;
00425 long outgoing;
00426 } total, lasttotal;
00427
00428 public:
00429 CallStat();
00430
00436 inline int getCapacity(void)
00437 {return capacity;};
00438
00445 long getStat(statitem_t item);
00446
00450 void incIncoming(void);
00451
00455 void decIncoming(void);
00456
00460 void incOutgoing(void);
00461
00465 void decOutgoing(void);
00466
00470 void Update(void);
00471 };
00472
00485 class Translator : protected Keydata
00486 {
00487 private:
00488 friend Translator *getTranslator(char *name);
00489 static Translator *first;
00490 Translator *next;
00491
00492 protected:
00498 virtual char *getName(void) = 0;
00499
00506 char *getPlayBuffer(Trunk *trunk);
00507
00508 void scanDir(const char *etcdir, const char *language, const char *lib);
00509
00510 Translator(const char *conf, const char *lib);
00511
00512 public:
00520 virtual char *Speak(Trunk *trunk) = 0;
00521 };
00522
00536 class Functions
00537 {
00538 protected:
00544 virtual char *getName(void) = 0;
00545
00551 void Load(FUNCTIONS *map);
00552 };
00553
00554 00555 00556 00557
00558
00565 class KeyTones : protected Keydata
00566 {
00567 public:
00571 KeyTones();
00572 };
00573
00581 class KeyLocal : public Keydata
00582 {
00583 public:
00587 KeyLocal();
00588 };
00589
00597 class KeyPaths : public Keydata
00598 {
00599 public:
00603 KeyPaths();
00604
00608 inline const char *getLibexec(void)
00609 {return getLast("libexec");};
00610
00614 inline const char *getTgipath(void)
00615 {return getLast("tgipath");};
00616
00620 inline const char *getLibpath(void)
00621 {return getLast("libpath");};
00622
00626 inline const char *getDatafiles(void)
00627 {return getLast("datafiles");};
00628
00632 inline const char *getRunfiles(void)
00633 {return getLast("runfiles");};
00634
00638 inline const char *getSpool(void)
00639 {return getLast("spool");};
00640
00644 inline const char *getScriptFiles(void)
00645 {return getLast("scripts");};
00646
00650 inline const char *getCache(void)
00651 {return getLast("precache");};
00652 };
00653
00661 class KeyNetwork : public Keydata
00662 {
00663 public:
00667 KeyNetwork();
00668
00674 unsigned getRefresh(void)
00675 {return atoi(getLast("refresh"));};
00676
00682 unsigned getTimeToLive(void)
00683 {return atoi(getLast("live"));};
00684
00690 InetHostAddress getBroadcast(void);
00691
00697 InetAddress getAddress(void);
00698
00704 tpport_t getPort(void);
00705
00711 InetHostAddress getDBHost(void);
00712
00718 tpport_t getDBPort(void);
00719 };
00720
00728 class KeyMailbox : public Keydata
00729 {
00730 public:
00734 KeyMailbox();
00735
00741 inline unsigned getCount(void)
00742 {return atoi(getLast("count"));};
00743
00749 inline unsigned getLimit(void)
00750 {return atoi(getLast("limit"));};
00751
00758 inline unsigned getQuota(void)
00759 {return atoi(getLast("quota"));};
00760
00766 inline unsigned getMinimum(void)
00767 {return atoi(getLast("minimum"));};
00768
00774 inline unsigned getMaximum(void)
00775 {return atoi(getLast("maximum"));};
00776
00782 inline const char *getPassword(void)
00783 {return getLast("password");};
00784 };
00785
00794 class KeyMemory : public Keydata
00795 {
00796 public:
00800 KeyMemory();
00801
00807 inline int getSymbolSize(void)
00808 {return atoi(getLast("symbols"));};
00809
00816 inline int getPageSize(void)
00817 {return atoi(getLast("page"));};
00818 };
00819
00827 class KeyFeed : public Keydata
00828 {
00829 public:
00833 KeyFeed();
00834
00840 inline unsigned getBuffers(void)
00841 {return atoi(getLast("buffers"));};
00842 };
00843
00844
00852 class KeyThreads : public Keydata
00853 {
00854 public:
00858 KeyThreads();
00859
00865 inline int priService(void)
00866 {return atoi(getLast("services"));};
00867
00873 inline int priScheduler(void)
00874 {return atoi(getLast("scheduler"));};
00875
00881 inline int priGUI(void)
00882 {return atoi(getLast("gui"));};
00883
00889 inline int priRTP(void)
00890 {return atoi(getLast("rtp"));};
00891
00897 inline int getStepDelay(void)
00898 {return atoi(getLast("stepdelay"));};
00899
00905 inline int getStepInterval(void)
00906 {return atoi(getLast("stepinterval"));};
00907
00913 inline int getResetDelay(void)
00914 {return atoi(getLast("resetdelay"));};
00915
00921 size_t getStack(void);
00922
00928 int getServices(void);
00929
00935 int priResolver(void);
00936
00943 int getResolver(void);
00944
00950 inline int priAudio(void)
00951 {return atoi(getLast("audio"));};
00952
00958 inline int priFeed(void)
00959 {return atoi(getLast("feed"));};
00960
00966 inline int priGateway(void)
00967 {return atoi(getLast("gateways"));};
00968
00974 inline int priManager(void)
00975 {return atoi(getLast("managers"));};
00976
00982 inline int priNetwork(void)
00983 {return atoi(getLast("network"));};
00984
00990 inline int getInterval(void)
00991 {return atoi(getLast("interval"));};
00992
00998 inline int getRefresh(void)
00999 {return atoi(getLast("refresh"));};
01000
01006 int getGateways(void);
01007
01014 inline int getPriority(void)
01015 {return atoi(getLast("priority"));};
01016
01022 int getPolicy(void);
01023
01029 inline int getPages(void)
01030 {return atoi(getLast("pages"));};
01031 };
01032
01040 class Auditdata : public Keydata
01041 {
01042 private:
01043 friend class Audit;
01044
01045 Auditdata();
01046 };
01047
01057 class Request
01058 {
01059 private:
01060 friend class TrunkGroup;
01061
01062 static unsigned seq;
01063
01064 unsigned id;
01065 Request *next;
01066 time_t expires;
01067 TrunkGroup *group;
01068
01069 char *argv[33];
01070 char buffer[512];
01071
01072 void Detach(void);
01073
01074 public:
01075 Request(TrunkGroup *grp, const char *text, unsigned expire);
01076 ~Request()
01077 {Detach();};
01078
01079 inline char **getList(void)
01080 {return argv;};
01081
01082 bool isExpired(void);
01083 };
01084
01095 class TrunkGroup : public Keydata, public CallStat
01096 {
01097 private:
01098 friend class KeyServer;
01099 friend class Scheduler;
01100 friend class Audit;
01101 friend class TestDebug;
01102 friend class Request;
01103 static TrunkGroup *first;
01104 TrunkGroup *next;
01105 char schedule[65];
01106 char planned[65];
01107 unsigned trump;
01108 Request *reqfirst, *reqlast;
01109
01110 void setSchedule(const char *str);
01111
01112 public:
01118 TrunkGroup(char *name = NULL);
01119
01125 inline const char *getName(void)
01126 {return getLast("name");};
01127
01133 inline unsigned getAnswer(void)
01134 {return atoi(getLast("answer"));};
01135
01141 inline unsigned getCallerid(void)
01142 {return atoi(getLast("callerid"));};
01143
01149 inline unsigned getPickup(void)
01150 {return atoi(getLast("pickup"));};
01151
01157 inline const char *chkRequest(void)
01158 {return getLast("requests");};
01159
01165 seltype_t getSelect(void);
01166
01173 inline timeout_t getReady(void)
01174 {return atol(getLast("ready"));};
01175
01181 inline unsigned getIdleTime(void)
01182 {return atoi(getLast("idletime"));};
01183
01189 inline unsigned getSiezeTime(void)
01190 {return atoi(getLast("siezetime"));};
01191
01197 inline unsigned getRingTime(void)
01198 {return atoi(getLast("ringtime"));};
01199
01205 inline int getHangup(void)
01206 {return atoi(getLast("hangup"));};
01207
01213 inline timeout_t getFlash(void)
01214 {return atol(getLast("flash"));};
01215
01221 inline timeout_t getDialtone(void)
01222 {return atol(getLast("dialtone"));};
01223
01229 inline timeout_t getDialspeed(void)
01230 {return atol(getLast("dialspeed"));};
01231
01238 const char *getNumber(void);
01239
01246 const char *getSchedule(char *buf);
01247
01257 const char *getRedirect(const char *redirect, char *buf);
01258
01262 inline void incCapacity(void)
01263 {++capacity;};
01264
01270 Request *getRequest(void);
01271
01277 friend TrunkGroup *getGroup(const char *name);
01278 };
01279
01287 class KeyServer : public Keydata
01288 {
01289 private:
01290 unsigned uid, gid;
01291 const char *altdir;
01292 const char *phrdir;
01293
01294 public:
01298 KeyServer();
01299
01305 inline const char *getNode(void)
01306 {return getLast("node");};
01307
01313 inline const char *getToken(void)
01314 {return getLast("token");};
01315
01319 void loadGroups(bool test);
01320
01326 inline const char *getDefault(void)
01327 {return getLast("default");};
01328
01334 inline unsigned getGid(void)
01335 {return gid;};
01336
01342 inline unsigned getUid(void)
01343 {return uid;};
01344
01348 void setUid(void);
01349
01353 void setGid(void);
01354
01360 inline int getNodeCount(void)
01361 {return atoi(getLast("nodes"));};
01362
01368 inline const char *getPrefix(void)
01369 {return altdir;};
01370
01376 inline const char *getPhrases(void)
01377 {return phrdir;};
01378 };
01379
01387 class Plugins : public Keydata
01388 {
01389 public:
01393 Plugins();
01394
01398 ~Plugins();
01399
01405 char *getDriverName(void);
01406
01410 void loadDebug(void);
01411
01416 DSO *loadDriver(void);
01417
01421 void loadExtensions(void);
01422
01426 void loadFunctions(void);
01427
01431 void loadMaps(void);
01432
01436 void loadModules(void);
01437
01441 void loadFeeds(void);
01442
01446 void loadTGI(void);
01447
01451 void loadManagers(void);
01452
01456 void loadTranslators(void);
01457
01461 void loadAuditing(void);
01462 };
01463
01472 class aaScript : public ScriptCommand
01473 {
01474 private:
01475 friend class Functions;
01476
01477 #pragma pack(1)
01478 typedef struct _functions
01479 {
01480 struct _functions *next;
01481 functioncall_t function;
01482 char name[1];
01483 } functions_t;
01484 #pragma pack()
01485
01486 functions_t *functions[KEYWORD_INDEX_SIZE];
01487
01488 protected:
01496 unsigned long getTrapMask(const char *trapname);
01497
01505 void addFunction(char *name, functioncall_t function);
01506
01507 public:
01514 functioncall_t getFunction(char *name);
01515
01519 aaScript();
01520
01526 void addModule(Module *module);
01527 };
01528
01538 class aaImage : public ScriptImage
01539 {
01540 protected:
01548 virtual bool isScript(char *scriptname);
01549
01556 void scanDir(char *path);
01557
01558 public:
01562 aaImage(aaScript *script);
01563 };
01564
01571 class Mixer : protected Mutex
01572 {
01573 private:
01574 friend class Conference;
01575 void addGroup(void);
01576 void delGroup(void);
01577
01578 protected:
01579 Mixer();
01580 unsigned avail, members, groups;
01581
01582 public:
01583 unsigned getAvail(void)
01584 {return avail;};
01585
01586 unsigned getMembers(void)
01587 {return members;};
01588
01589 unsigned getGroups(void)
01590 {return groups;};
01591
01592 virtual bool setMixer(int groups, int members) = 0;
01593
01594 virtual Conference *getConference(int group) = 0;
01595 };
01596
01605 class Conference : protected Mutex
01606 {
01607 protected:
01608 Mixer *mixer;
01609 unsigned limit;
01610 unsigned members;
01611
01612 virtual ~Conference();
01613
01614 Conference(Mixer *m);
01615 public:
01616 inline virtual Mixer *getMixer(void)
01617 {return mixer;};
01618
01619 unsigned getMembers(void)
01620 {return members;};
01621
01622 unsigned getLimit(void)
01623 {return limit;};
01624
01625 virtual bool setConference(unsigned max) = 0;
01626 };
01627
01637 class Trunk : public ScriptInterp
01638 {
01639 private:
01640 friend class TestDebug;
01641 friend class aaScript;
01642 friend class Translator;
01643 friend class ScriptInterface;
01644 friend class Service;
01645 friend class AudioService;
01646 friend class Fifo;
01647 friend class PortManager;
01648
01649 char *cdrv[33];
01650 int cdrc;
01651 numbersymbol_t numbers[5];
01652
01653 bool scrStart(void);
01654 bool scrRequest(void);
01655 bool scrLibonce(void);
01656 bool scrLibexec(void);
01657 bool scrHangup(void);
01658 bool scrDebug(void);
01659 bool scrImport(void);
01660 bool scrExport(void);
01661 bool scrFunction(void);
01662 bool scrAlog(void);
01663 bool scrAudit(void);
01664 bool scrPause(void);
01665 bool scrSleep(void);
01666 bool scrSync(void);
01667 bool scrTone(void);
01668 bool scrAnswer(void);
01669 bool scrCollect(void);
01670 bool scrFlash(void);
01671 bool scrPlay(void);
01672 bool scrRecord(void);
01673 bool scrAppend(void);
01674 bool scrDial(void);
01675 bool scrTransfer(void);
01676 bool scrSpeak(void);
01677 bool scrMap(void);
01678 bool scrModule(void);
01679 bool scrSchedule(void);
01680 bool scrSignal(void);
01681 bool scrIdle(void);
01682
01683 protected:
01684 static ScriptSymbol globals;
01685 static char digit[16];
01686 ScriptInterface *script;
01687 TrunkGroup *group;
01688 PortManager *manager;
01689 int id;
01690 time_t start, idle;
01691
01692 int idle_timer;
01693 int rings;
01694 int digits;
01695
01696 Service *thread;
01697 trunkdata_t data;
01698 execdata_t tgi;
01699 digitsymbol_t dtmf;
01700
01701 struct
01702 {
01703 bool offhook: 1;
01704 bool dtmf: 1;
01705 bool script: 1;
01706 bool reset: 1;
01707 bool timer : 1;
01708 bool audio: 1;
01709 bool once : 1;
01710 bool ready : 1;
01711 bool echo : 1;
01712 unsigned temp : 1;
01713 trunkmode_t trunk: 2;
01714 dspmode_t dsp: 4;
01715 } flags;
01716
01722 unsigned long getTrapDefault(void)
01723 {return 0x00000007;};
01724
01733 void setConstant(const char *id, const char *data);
01734
01742 scriptsymbol_t *getEntry(const char *symname, int size);
01743
01749 void Commit(scriptsymbol_t *sym);
01750
01757 int getTimeout(void);
01758
01765 int getInterdigit(void);
01766
01772 unsigned short getDigitMask(void);
01773
01779 bool TrunkSignal(trunksignal_t);
01780
01787 virtual void setDTMFDetect(void);
01788
01797 virtual void setDTMFDetect(bool enable)
01798 {flags.dtmf = enable;};
01799
01805 virtual void stopServices(void);
01806
01817 virtual void TrunkStep(trunkstep_t step) = 0;
01818
01824 bool idleHangup();
01825
01832 virtual unsigned long getIdleTime(void) = 0;
01833
01837 bool ScriptStep(void);
01838
01847 bool Attach(const char *scrname);
01848
01853 void Detach(void);
01854
01858 unsigned long getMask(void);
01859
01866 char **getInitial(char **args);
01867
01874 void setList(char **list);
01875
01876 Trunk(int port);
01877 public:
01883 virtual unsigned long getCapabilities(void)
01884 {return TRUNK_CAP_VOICE | TRUNK_CAP_DIAL;};
01885
01891 virtual void getName(char *buffer) = 0;
01892
01900 virtual bool postEvent(TrunkEvent *event) = 0;
01901
01907 int getDigit(char digit);
01908
01914 bool isReady(void);
01915 };
01916
01925 class PortManager
01926 {
01927 private:
01928 Trunk *trunk;
01929
01930 protected:
01931 ~PortManager()
01932 {trunk->manager = NULL;};
01933
01939 PortManager(Trunk *trk);
01940
01946 inline void postStep(trunkstep_t step)
01947 {trunk->TrunkStep(step);};
01948
01955 inline bool postEvent(TrunkEvent *event)
01956 {return trunk->postEvent(event);};
01957
01963 inline trunkdata_t *getData(void)
01964 {return &trunk->data;};
01965
01971 inline execdata_t *getExec(void)
01972 {return &trunk->tgi;};
01973 public:
01977 virtual bool Step(void) = 0;
01978
01984 virtual unsigned long getMask(void) = 0;
01985
01992 virtual bool postSignal(trunksignal_t signal) = 0;
01993
02000 virtual bool postAccept(const char *name) = 0;
02001
02005 virtual void postDetach(void) = 0;
02006 };
02007
02017 class Fifo : public fifostream, public Mutex
02018 {
02019 protected:
02020 char schedule[33];
02021
02022 bool exitPid(char **args);
02023 bool waitPid(char **args);
02024 bool setSymbol(char **argv);
02025 bool putSymbol(char **argv);
02026 bool submit(char **argv);
02027 bool login(char **argv);
02028 bool mapFiles(char **argv);
02029 bool startScript(char **argv);
02030 bool ringScript(char **argv);
02031 bool redirectScript(char **argv);
02032 bool busyLine(char **argv);
02033 bool idleLine(char **argv);
02034 bool hangupLine(char **argv);
02035 bool reqScript(char **argv);
02036 bool setSchedule(char **argv);
02037 bool postKey(char **argv);
02038 bool setMixer(char **argv);
02039 bool setLimit(char **argv);
02040
02041 public:
02049 bool Command(const char *cmdstring);
02050 };
02051
02059 class FifoHandler
02060 {
02061 private:
02062 friend class Fifo;
02063
02064 static FifoHandler *first;
02065 FifoHandler *next;
02066 protected:
02073 virtual bool Command(char **argv) = 0;
02074
02078 FifoHandler();
02079 };
02080
02094 class Audit : public Mutex
02095 {
02096 private:
02097 friend void audit(Trunk *trunk, char *detail);
02098 friend void alog(Trunk *trunk, char *detail);
02099 friend class Scheduler;
02100
02101 static Audit *first;
02102 Audit *next;
02103
02104 protected:
02105 static Auditdata keys;
02106
02112 virtual void ReportAudit(Trunk *trunk, char *detail) = 0;
02113
02119 virtual void ReportCDR(Trunk *trunk, char *detail)
02120 {ReportAudit(trunk, detail);};
02121
02125 virtual void ReportStats(void)
02126 {return;};
02127
02133 inline TrunkGroup *getFirst(void)
02134 {return TrunkGroup::first;};
02135
02142 inline TrunkGroup *getNext(TrunkGroup *grp)
02143 {return grp->next;};
02144
02148 Audit();
02149 };
02150
02158 class Driver : public aaScript
02159 {
02160 protected:
02161 friend class TrunkGroup;
02162
02163 TrunkGroup **groups;
02164 char *status;
02165 bool active;
02166
02167 public:
02171 Driver();
02172
02179 virtual int Start(void) = 0;
02180
02184 virtual void Stop(void) = 0;
02185
02191 void getStatus(char *buffer);
02192
02199 virtual aaImage *getImage(void);
02200
02207 virtual int getTrunkCount(void) = 0;
02208
02215 virtual int getTrunkUsed(void)
02216 {return getTrunkCount();};
02217
02224 TrunkGroup *getTrunkGroup(int id)
02225 {return groups[id];};
02226
02232 virtual Trunk *getTrunkPort(int id) = 0;
02233
02239 virtual Conference *getConference(int id)
02240 {return NULL;};
02241
02247 virtual Mixer *getMixer(int id)
02248 {return NULL;};
02249
02255 virtual unsigned getMixers(void)
02256 {return 0;};
02257
02263 virtual unsigned getGroups(void)
02264 {return 0;};
02265 };
02266
02273 class Debug : protected Mutex
02274 {
02275 public:
02279 Debug();
02280
02286 virtual bool DebugTest(void)
02287 {return false;};
02288
02292 virtual void DebugEvent(Trunk *trunk, TrunkEvent *event)
02293 {return;};
02294
02298 virtual void DebugState(Trunk *trunk, char *state)
02299 {return;};
02300
02304 virtual void DebugService(Trunk *trunk, char *msg)
02305 {return;};
02306
02310 virtual void DebugScript(Trunk *trunk, char *msg)
02311 {return;};
02312
02316 virtual void DebugStep(Trunk *trunk, scriptline_t *line)
02317 {DebugState(trunk, "step");};
02318
02322 virtual bool DebugFifo(char **argv)
02323 {return true;};
02324 };
02325
02332 class AudioService
02333 {
02334 private:
02335 char filename[256];
02336
02337 protected:
02338 Trunk *trunk;
02345 char *getPrompt(char *name);
02346
02352 char *getPlayfile(void);
02353
02357 AudioService(void);
02358 };
02359
02367 class Service : public Semaphore, public Thread, public AudioService
02368 {
02369 protected:
02370 volatile bool stopped;
02371 trunkdata_t *data;
02372 TrunkGroup *group;
02373
02377 void Success(void);
02378
02382 void Failure(void);
02383
02387 inline void dspReset(void)
02388 {trunk->flags.reset = true;};
02389
02393 inline void setAudio(void)
02394 {trunk->flags.audio = true;};
02395
02399 inline void clrAudio(void)
02400 {trunk->flags.audio = false;};
02401
02402 public:
02409 Service(Trunk *trunk, int pri);
02410
02417 virtual timeout_t Stop(void);
02418
02426 virtual bool isExiting(void)
02427 {return true;};
02428
02432 void endService(void)
02433 {Terminate();};
02434
02438 virtual ~Service()
02439 {Terminate();}
02440 };
02441
02451 class Server : public Thread
02452 {
02453 private:
02454 static Server *first;
02455 Server *next;
02456 friend void startServers(void);
02457 friend void stopServers(void);
02458
02459 protected:
02460 Server(int pri);
02461
02465 virtual void Stop(void)
02466 {Terminate();};
02467 };
02468
02475 class Sync
02476 {
02477 private:
02478 friend class Scheduler;
02479
02480 static Sync *first;
02481 Sync *next;
02482 time_t runtime;
02483
02484 protected:
02488 Sync(void);
02489
02494 virtual bool isScheduled(void) = 0;
02495
02500 virtual unsigned getInterval(void)
02501 {return 10;};
02502
02506 virtual void Schedule(void) = 0;
02507
02511 virtual char *getName(void) = 0;
02512 };
02513
02522 class phTone
02523 {
02524 private:
02525 friend phTone *getphTone(const char *name);
02526 static phTone *first;
02527 static int ulaw[256];
02528 phTone *next;
02529 char name[33];
02530 unsigned char *samples;
02531 timeout_t duration;
02532 unsigned freq1, freq2;
02533
02534 public:
02542 phTone(const char *name, timeout_t duration, unsigned f);
02543
02552 phTone(const char *name, timeout_t duration, unsigned f1, unsigned f2);
02553
02554 ~phTone();
02555
02561 void Clear(void);
02562
02568 inline unsigned char *getSamples(void)
02569 {return samples;};
02570
02576 inline timeout_t getDuration(void)
02577 {return duration;};
02578 };
02579
02586 class TGI
02587 {
02588 private:
02589 static TGI *first;
02590 TGI *next;
02591
02592 protected:
02593 TGI();
02594
02602 virtual bool getExtension(char *ext)
02603 {return false;};
02604
02605 public:
02615 virtual void Script(char *cmd, char **args)
02616 {return;};
02617
02626 virtual int Parse(int fd, int port, char *cmd)
02627 {return -1;};
02628
02629 friend void getInterp(char *cmd, char **args);
02630 friend TGI *getInterp(char *cmd);
02631 };
02632
02642 class Module
02643 {
02644 private:
02645 static Module *first;
02646 Module *next;
02647
02648 protected:
02649 Module();
02650
02656 virtual modtype_t getType(void) = 0;
02657
02658 public:
02664 virtual char *getName(void) = 0;
02665
02673 virtual char *Dispatch(Trunk *trunk) = NULL;
02674
02682 virtual unsigned Sleep(Trunk *trunk)
02683 {return 0;};
02684
02691 virtual void Detach(Trunk *trunk)
02692 {return;};
02693
02701 virtual void Attach(Trunk *trunk)
02702 {return;};
02703
02704 friend Module *getModule(modtype_t mod, const char *name = NULL);
02705 friend void detachModules(Trunk *trunk);
02706 friend void attachModules(Trunk *trunk);
02707 };
02708
02718 class Session
02719 {
02720 private:
02721 friend class Scheduler;
02722 static Mutex mutex;
02723 static Session *first;
02724 static Session *last;
02725 Session *next, *prev;
02726 static void Clean(void);
02727
02728 protected:
02729 Session();
02730 virtual ~Session()
02731 {Unlink();};
02732
02736 void Unlink(void);
02737
02744 virtual time_t getExpires(void) = 0;
02745 };
02746
02755 class AudioFeed : private ThreadLock
02756 {
02757 private:
02758 static AudioFeed *first;
02759 AudioFeed *next;
02760 unsigned char *buffers;
02761 volatile unsigned char *current;
02762 size_t feedsize, bufsize;
02763 bool active;
02764
02765 protected:
02766 const char *name;
02767
02768 public:
02769 AudioFeed(const char *name, unsigned buffers);
02770 ~AudioFeed();
02771 bool Enable(void);
02772 void Disable(void);
02773 unsigned char *getBuffer(unsigned char *prior = NULL, unsigned size = 120);
02774 void putBuffer(unsigned char *buffer, unsigned size = 120);
02775
02776 friend AudioFeed *getAudioFeed(const char *name);
02777 };
02778
02787 class Map : private MemPager
02788 {
02789 private:
02790 static ThreadLock lock;
02791 static Map *first, *last;
02792
02793 typedef struct _sym
02794 {
02795 struct _sym *next;
02796 char *key;
02797 char **values;
02798 } mapsym_t;
02799
02800 typedef struct
02801 {
02802 mapsym_t *keys[127];
02803 } mapkey_t;
02804
02805 mapkey_t *digits[32];
02806
02807 Map *next, *prev;
02808 char *name;
02809
02810 unsigned getKey(const char *key, unsigned len = 0);
02811 char **getList(const char *key, unsigned len);
02812 ~Map();
02813
02814 public:
02815 Map(const char *path, const char *name);
02816
02817 friend char **getMap(const char *map, const char *key);
02818 friend void endMaps(void);
02819 };
02820
02829 class Protocol : public Keydata, public InetHostAddress, public ThreadLock
02830 {
02831 private:
02832 friend class Resolver;
02833 static Protocol *first;
02834 Protocol *next;
02835 Semaphore *sessions;
02836 tpport_t port;
02837
02838 void Update(InetHostAddress addr);
02839 public:
02840 Protocol(const char *keypath, tpport_t port);
02841 ~Protocol();
02842
02848 InetHostAddress getAddress(void);
02849
02855 inline tpport_t getPort(void)
02856 {return port;};
02857
02864 inline Semaphore *getSessions(void)
02865 {return sessions;};
02866 };
02867
02868 extern bool running;
02869 extern KeyServer keyserver;
02870 extern KeyThreads keythreads;
02871 extern KeyMemory keymemory;
02872 extern KeyPaths keypaths;
02873 extern KeyLocal keylocal;
02874 extern KeyNetwork keynetwork;
02875 extern KeyMailbox keymailbox;
02876 extern KeyTones keytones;
02877 extern KeyFeed keyfeed;
02878 extern Plugins plugins;
02879 extern Driver *driver;
02880 extern Debug *debug;
02881 extern Fifo fifo;
02882 #endif
02883