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_EXIT = TRUNK_STEP_HANGUP,
00096 TRUNK_STEP_DRIVER
00097 } trunkstep_t;
00098
00099 typedef enum {
00100
00101 TRUNK_SIGNAL_STEP = 0,
00102 TRUNK_SIGNAL_EXIT,
00103 TRUNK_SIGNAL_HANGUP=TRUNK_SIGNAL_EXIT,
00104 TRUNK_SIGNAL_ERROR,
00105 TRUNK_SIGNAL_TIMEOUT,
00106 TRUNK_SIGNAL_DTMF,
00107 TRUNK_SIGNAL_0,
00108 TRUNK_SIGNAL_1,
00109 TRUNK_SIGNAL_2,
00110 TRUNK_SIGNAL_3,
00111 TRUNK_SIGNAL_4,
00112 TRUNK_SIGNAL_5,
00113 TRUNK_SIGNAL_6,
00114 TRUNK_SIGNAL_7,
00115 TRUNK_SIGNAL_8,
00116 TRUNK_SIGNAL_9,
00117 TRUNK_SIGNAL_STAR,
00118 TRUNK_SIGNAL_POUND,
00119 TRUNK_SIGNAL_A,
00120 TRUNK_SIGNAL_B,
00121 TRUNK_SIGNAL_C,
00122 TRUNK_SIGNAL_D,
00123 TRUNK_SIGNAL_DIALTONE,
00124 TRUNK_SIGNAL_BUSY,
00125 TRUNK_SIGNAL_CANCEL,
00126 TRUNK_SIGNAL_SIGNAL,
00127 TRUNK_SIGNAL_DRIVER
00128 } trunksignal_t;
00129
00130 typedef enum {
00131
00132
00133 TRUNK_ENTER_STATE = 100,
00134 TRUNK_EXIT_STATE,
00135 TRUNK_STOP_STATE,
00136 TRUNK_NOTIFICATION,
00137 TRUNK_SERVICE_SUCCESS,
00138 TRUNK_SERVICE_FAILURE,
00139 TRUNK_SERVICE_LOOKUP,
00140 TRUNK_SERVICE_LOGIN,
00141 TRUNK_SIGNAL_NOTIFY,
00142 TRUNK_JOIN_TRUNKS,
00143 TRUNK_PART_TRUNKS,
00144 TRUNK_NULL_EVENT,
00145
00146
00147
00148 TRUNK_EXIT_SHELL = 200,
00149 TRUNK_START_SCRIPT,
00150 TRUNK_RING_START,
00151 TRUNK_RING_REDIRECT,
00152 TRUNK_STOP_DISCONNECT,
00153
00154
00155
00156 TRUNK_START_INCOMING = TRUNK_RING_START,
00157 TRUNK_START_OUTGOING = TRUNK_START_SCRIPT,
00158
00159
00160
00161 TRUNK_MAKE_TEST = 300,
00162 TRUNK_MAKE_BUSY,
00163 TRUNK_MAKE_IDLE,
00164 TRUNK_MAKE_STEP,
00165
00166
00167
00168 TRUNK_LINE_WINK = 400,
00169 TRUNK_TIMER_EXPIRED,
00170 TRUNK_RINGING_ON,
00171 TRUNK_RINGING_OFF,
00172 TRUNK_TEST_IDLE,
00173 TRUNK_TEST_FAILURE,
00174 TRUNK_ON_HOOK,
00175 TRUNK_OFF_HOOK,
00176 TRUNK_CALLER_ID,
00177 TRUNK_RINGING_DID,
00178 TRUNK_CALL_DETECT,
00179 TRUNK_CALL_CONNECT,
00180 TRUNK_CALL_RELEASE,
00181 TRUNK_CALL_ACCEPT,
00182 TRUNK_CALL_RINGING,
00183 TRUNK_CALL_DISCONNECT,
00184
00185
00186
00187 TRUNK_AUDIO_IDLE = 500,
00188 TRUNK_INPUT_PENDING,
00189 TRUNK_OUTPUT_PENDING,
00190 TRUNK_AUDIO_BUFFER,
00191 TRUNK_TONE_IDLE,
00192 TRUNK_DTMF_KEYDOWN,
00193 TRUNK_DTMF_KEYUP,
00194 TRUNK_TONE_START,
00195 TRUNK_TONE_STOP,
00196 TRUNK_FSK_DETECT,
00197 TRUNK_FAX_DETECT,
00198 TRUNK_VOX_DETECT,
00199 TRUNK_AUDIO_START,
00200 TRUNK_AUDIO_STOP,
00201 TRUNK_CPA_DIALTONE,
00202 TRUNK_CPA_BUSYTONE,
00203 TRUNK_CPA_RINGING,
00204 TRUNK_CPA_INTERCEPT,
00205 TRUNK_CPA_NODIALTONE,
00206 TRUNK_CPA_NORINGBACK,
00207 TRUNK_CPA_NOANSWER,
00208 TRUNK_CPA_CONNECT,
00209 TRUNK_DSP_READY,
00210
00211
00212
00213 TRUNK_DRIVER_SPECIFIC=8000
00214 } trunkevent_t;
00215
00216 typedef enum
00217 {
00218 DSP_MODE_INACTIVE = 0,
00219 DSP_MODE_VOICE,
00220 DSP_MODE_CALLERID,
00221 DSP_MODE_DATA,
00222 DSP_MODE_FAX,
00223 DSP_MODE_TDM,
00224 DSP_MODE_RTP,
00225 DSP_MODE_DUPLEX,
00226 DSP_MODE_JOIN,
00227 DSP_MODE_CONF,
00228 DSP_MODE_RINGBACK
00229 } dspmode_t;
00230
00231 typedef enum
00232 {
00233 TRUNK_MODE_INCOMING = 0,
00234 TRUNK_MODE_OUTGOING,
00235 TRUNK_MODE_INACTIVE,
00236 TRUNK_MODE_UNAVAILABLE
00237 } trunkmode_t;
00238
00239 typedef enum
00240 {
00241 STAT_MAX_INCOMING,
00242 STAT_MAX_OUTGOING,
00243 STAT_TOT_INCOMING,
00244 STAT_TOT_OUTGOING
00245 } statitem_t;
00246
00247 #define TRUNK_CAP_VOICE 0x00000001
00248 #define TRUNK_CAP_DIAL 0x00000002
00249 #define TRUNK_CAP_SENDFAX 0x00000004
00250 #define TRUNK_CAP_RECVFAX 0x00000008
00251 #define TRUNK_CAP_DATA 0x00000010
00252
00253 typedef union
00254 {
00255 scriptsymbol_t sym;
00256 char data[sizeof(scriptsymbol_t) + 12];
00257 } numbersymbol_t;
00258
00259 typedef union
00260 {
00261 scriptsymbol_t bin;
00262 char data[sizeof(scriptsymbol_t) + 32];
00263 } digitsymbol_t;
00264
00265 typedef struct
00266 {
00267
00268 int pid;
00269 unsigned seq;
00270 void *data;
00271 } execdata_t;
00272
00273 typedef union
00274 {
00275 struct
00276 {
00277 int rings;
00278 int timeout;
00279 } answer;
00280 struct
00281 {
00282 char list[256];
00283 char *name;
00284 unsigned long offset;
00285 unsigned long limit;
00286 unsigned char volume;
00287 } play;
00288 struct
00289 {
00290 char *name;
00291 timeout_t timeout;
00292 unsigned long offset;
00293 unsigned short term;
00294 unsigned char volume;
00295 unsigned long trim;
00296 bool append;
00297 } record;
00298 struct
00299 {
00300 char digits[65];
00301 char *digit;
00302 timeout_t interdigit;
00303 bool exit;
00304 } dialxfer;
00305 struct
00306 {
00307 timeout_t timeout;
00308 unsigned count;
00309 unsigned short term;
00310 unsigned short ignore;
00311 } collect;
00312 struct
00313 {
00314 timeout_t wakeup;
00315 unsigned rings;
00316 unsigned loops;
00317 } sleep;
00318 struct
00319 {
00320 timeout_t wakeup;
00321 unsigned loops;
00322 phTone *tone;
00323 } tone;
00324 struct
00325 {
00326 timeout_t wakeup;
00327 Trunk *trunk;
00328 phTone *tone;
00329 } join;
00330 struct
00331 {
00332 timeout_t offhook;
00333 timeout_t onhook;
00334 } flash;
00335 struct
00336 {
00337 struct in_addr addr;
00338 unsigned short bind, port, term;
00339 audioencoding_t codec;
00340 } rtp;
00341 } trunkdata_t;
00342
00343 typedef struct
00344 {
00345 trunkevent_t id;
00346 union
00347 {
00348 struct
00349 {
00350 unsigned digit: 4;
00351 unsigned duration: 12;
00352 unsigned e1: 8;
00353 unsigned e2: 8;
00354 } dtmf;
00355 struct
00356 {
00357 unsigned tone: 8;
00358 unsigned energy: 8;
00359 unsigned duration: 16;
00360 } tone;
00361 struct
00362 {
00363 unsigned digit: 4;
00364 unsigned duration: 24;
00365 } ring;
00366 struct
00367 {
00368 unsigned seq;
00369 bool result;
00370 char *data;
00371 } lookup;
00372 int status;
00373 Trunk *trunk;
00374 void *data;
00375 char **argv;
00376 char *error;
00377 timeout_t duration;
00378 trunkstep_t step;
00379 char dn[8];
00380 dspmode_t dsp;
00381 } parm;
00382 } TrunkEvent;
00383
00384 00385 00386
00387
00388 typedef char *(*functioncall_t)(scriptsymbol_t *sym, char **args);
00389
00390 typedef struct
00391 {
00392 char *name;
00393 functioncall_t function;
00394 } FUNCTIONS;
00395
00396
00404 class CallStat : public Mutex
00405 {
00406 protected:
00407 int capacity;
00408 struct
00409 {
00410 int incoming;
00411 int outgoing;
00412 } active, max, lastmax;
00413
00414 struct
00415 {
00416 long incoming;
00417 long outgoing;
00418 } total, lasttotal;
00419
00420 public:
00421 CallStat();
00422
00428 inline int getCapacity(void)
00429 {return capacity;};
00430
00437 long getStat(statitem_t item);
00438
00442 void incIncoming(void);
00443
00447 void decIncoming(void);
00448
00452 void incOutgoing(void);
00453
00457 void decOutgoing(void);
00458
00462 void Update(void);
00463 };
00464
00477 class Translator : protected Keydata
00478 {
00479 private:
00480 friend Translator *getTranslator(char *name);
00481 static Translator *first;
00482 Translator *next;
00483
00484 protected:
00490 virtual char *getName(void) = 0;
00491
00498 char *getPlayBuffer(Trunk *trunk);
00499
00500 void scanDir(const char *etcdir, const char *language, const char *lib);
00501
00502 Translator(const char *conf, const char *lib);
00503
00504 public:
00512 virtual char *Speak(Trunk *trunk) = 0;
00513 };
00514
00528 class Functions
00529 {
00530 protected:
00536 virtual char *getName(void) = 0;
00537
00543 void Load(FUNCTIONS *map);
00544 };
00545
00546 00547 00548 00549
00550
00557 class KeyTones : protected Keydata
00558 {
00559 public:
00563 KeyTones();
00564 };
00565
00573 class KeyLocal : public Keydata
00574 {
00575 public:
00579 KeyLocal();
00580 };
00581
00589 class KeyPaths : public Keydata
00590 {
00591 public:
00595 KeyPaths();
00596
00600 inline const char *getLibexec(void)
00601 {return getLast("libexec");};
00602
00606 inline const char *getTgipath(void)
00607 {return getLast("tgipath");};
00608
00612 inline const char *getLibpath(void)
00613 {return getLast("libpath");};
00614
00618 inline const char *getDatafiles(void)
00619 {return getLast("datafiles");};
00620
00624 inline const char *getRunfiles(void)
00625 {return getLast("runfiles");};
00626
00630 inline const char *getSpool(void)
00631 {return getLast("spool");};
00632
00636 inline const char *getScriptFiles(void)
00637 {return getLast("scripts");};
00638
00642 inline const char *getCache(void)
00643 {return getLast("precache");};
00644 };
00645
00653 class KeyNetwork : public Keydata
00654 {
00655 public:
00659 KeyNetwork();
00660
00666 unsigned getRefresh(void)
00667 {return atoi(getLast("refresh"));};
00668
00674 unsigned getTimeToLive(void)
00675 {return atoi(getLast("live"));};
00676
00682 InetHostAddress getBroadcast(void);
00683
00689 InetAddress getAddress(void);
00690
00696 tpport_t getPort(void);
00697 };
00698
00706 class KeyMailbox : public Keydata
00707 {
00708 public:
00712 KeyMailbox();
00713
00719 inline unsigned getCount(void)
00720 {return atoi(getLast("count"));};
00721
00727 inline unsigned getLimit(void)
00728 {return atoi(getLast("limit"));};
00729
00736 inline unsigned getQuota(void)
00737 {return atoi(getLast("quota"));};
00738
00744 inline unsigned getMinimum(void)
00745 {return atoi(getLast("minimum"));};
00746
00752 inline unsigned getMaximum(void)
00753 {return atoi(getLast("maximum"));};
00754
00760 inline const char *getPassword(void)
00761 {return getLast("password");};
00762 };
00763
00772 class KeyMemory : public Keydata
00773 {
00774 public:
00778 KeyMemory();
00779
00785 inline int getSymbolSize(void)
00786 {return atoi(getLast("symbols"));};
00787
00794 inline int getPageSize(void)
00795 {return atoi(getLast("page"));};
00796 };
00797
00805 class KeyFeed : public Keydata
00806 {
00807 public:
00811 KeyFeed();
00812
00818 inline unsigned getBuffers(void)
00819 {return atoi(getLast("buffers"));};
00820 };
00821
00822
00830 class KeyThreads : public Keydata
00831 {
00832 public:
00836 KeyThreads();
00837
00843 inline int priService(void)
00844 {return atoi(getLast("services"));};
00845
00851 inline int priScheduler(void)
00852 {return atoi(getLast("scheduler"));};
00853
00859 inline int priGUI(void)
00860 {return atoi(getLast("gui"));};
00861
00867 inline int priRTP(void)
00868 {return atoi(getLast("rtp"));};
00869
00875 inline int getStepDelay(void)
00876 {return atoi(getLast("stepdelay"));};
00877
00883 inline int getStepInterval(void)
00884 {return atoi(getLast("stepinterval"));};
00885
00891 inline int getResetDelay(void)
00892 {return atoi(getLast("resetdelay"));};
00893
00899 size_t getStack(void);
00900
00906 int getServices(void);
00907
00913 int priResolver(void);
00914
00921 int getResolver(void);
00922
00928 inline int priAudio(void)
00929 {return atoi(getLast("audio"));};
00930
00936 inline int priFeed(void)
00937 {return atoi(getLast("feed"));};
00938
00944 inline int priGateway(void)
00945 {return atoi(getLast("gateways"));};
00946
00952 inline int priManager(void)
00953 {return atoi(getLast("managers"));};
00954
00960 inline int priNetwork(void)
00961 {return atoi(getLast("network"));};
00962
00968 inline int getInterval(void)
00969 {return atoi(getLast("interval"));};
00970
00976 inline int getRefresh(void)
00977 {return atoi(getLast("refresh"));};
00978
00984 int getGateways(void);
00985
00992 inline int getPriority(void)
00993 {return atoi(getLast("priority"));};
00994
01000 int getPolicy(void);
01001
01007 inline int getPages(void)
01008 {return atoi(getLast("pages"));};
01009 };
01010
01018 class Auditdata : public Keydata
01019 {
01020 private:
01021 friend class Audit;
01022
01023 Auditdata();
01024 };
01025
01035 class Request
01036 {
01037 private:
01038 friend class TrunkGroup;
01039
01040 static unsigned seq;
01041
01042 unsigned id;
01043 Request *next;
01044 time_t expires;
01045 TrunkGroup *group;
01046
01047 char *argv[33];
01048 char buffer[512];
01049
01050 void Detach(void);
01051
01052 public:
01053 Request(TrunkGroup *grp, const char *text, unsigned expire);
01054 ~Request()
01055 {Detach();};
01056
01057 inline char **getList(void)
01058 {return argv;};
01059
01060 bool isExpired(void);
01061 };
01062
01073 class TrunkGroup : public Keydata, public CallStat
01074 {
01075 private:
01076 friend class KeyServer;
01077 friend class Scheduler;
01078 friend class Audit;
01079 friend class TestDebug;
01080 friend class Request;
01081 static TrunkGroup *first;
01082 TrunkGroup *next;
01083 char schedule[65];
01084 Request *reqfirst, *reqlast;
01085
01086 void setSchedule(const char *str);
01087
01088 public:
01094 TrunkGroup(char *name = NULL);
01095
01101 inline const char *getName(void)
01102 {return getLast("name");};
01103
01109 inline unsigned getAnswer(void)
01110 {return atoi(getLast("answer"));};
01111
01117 inline unsigned getCallerid(void)
01118 {return atoi(getLast("callerid"));};
01119
01125 inline unsigned getPickup(void)
01126 {return atoi(getLast("pickup"));};
01127
01133 inline const char *chkRequest(void)
01134 {return getLast("requests");};
01135
01141 seltype_t getSelect(void);
01142
01149 inline timeout_t getReady(void)
01150 {return atol(getLast("ready"));};
01151
01157 inline unsigned getIdleTime(void)
01158 {return atoi(getLast("idletime"));};
01159
01165 inline unsigned getRingTime(void)
01166 {return atoi(getLast("ringtime"));};
01167
01173 inline int getHangup(void)
01174 {return atoi(getLast("hangup"));};
01175
01181 inline timeout_t getFlash(void)
01182 {return atol(getLast("flash"));};
01183
01189 inline timeout_t getDialtone(void)
01190 {return atol(getLast("dialtone"));};
01191
01197 inline timeout_t getDialspeed(void)
01198 {return atol(getLast("dialspeed"));};
01199
01206 const char *getNumber(void);
01207
01214 const char *getSchedule(char *buf);
01215
01225 const char *getRedirect(const char *redirect, char *buf);
01226
01230 inline void incCapacity(void)
01231 {++capacity;};
01232
01238 Request *getRequest(void);
01239
01245 friend TrunkGroup *getGroup(const char *name);
01246 };
01247
01255 class KeyServer : public Keydata
01256 {
01257 private:
01258 unsigned uid, gid;
01259 const char *altdir;
01260 const char *phrdir;
01261
01262 public:
01266 KeyServer();
01267
01273 inline const char *getNode(void)
01274 {return getLast("node");};
01275
01281 inline const char *getToken(void)
01282 {return getLast("token");};
01283
01287 void loadGroups(bool test);
01288
01294 inline const char *getDefault(void)
01295 {return getLast("default");};
01296
01302 inline unsigned getGid(void)
01303 {return gid;};
01304
01310 inline unsigned getUid(void)
01311 {return uid;};
01312
01318 inline int getNodeCount(void)
01319 {return atoi(getLast("nodes"));};
01320
01326 inline const char *getPrefix(void)
01327 {return altdir;};
01328
01334 inline const char *getPhrases(void)
01335 {return phrdir;};
01336 };
01337
01345 class Plugins : public Keydata
01346 {
01347 public:
01351 Plugins();
01352
01356 ~Plugins();
01357
01363 char *getDriverName(void);
01364
01368 void loadDebug(void);
01369
01374 DSO *loadDriver(void);
01375
01379 void loadExtensions(void);
01380
01384 void loadFunctions(void);
01385
01389 void loadMaps(void);
01390
01394 void loadModules(void);
01395
01399 void loadFeeds(void);
01400
01404 void loadTGI(void);
01405
01409 void loadManagers(void);
01410
01414 void loadTranslators(void);
01415
01419 void loadAuditing(void);
01420 };
01421
01430 class aaScript : public ScriptCommand
01431 {
01432 private:
01433 friend class Functions;
01434
01435 #pragma pack(1)
01436 typedef struct _functions
01437 {
01438 struct _functions *next;
01439 functioncall_t function;
01440 char name[1];
01441 } functions_t;
01442 #pragma pack()
01443
01444 functions_t *functions[KEYWORD_INDEX_SIZE];
01445
01446 protected:
01454 unsigned long getTrapMask(const char *trapname);
01455
01463 void addFunction(char *name, functioncall_t function);
01464
01465 public:
01472 functioncall_t getFunction(char *name);
01473
01477 aaScript();
01478
01484 void addModule(Module *module);
01485 };
01486
01496 class aaImage : public ScriptImage
01497 {
01498 protected:
01506 virtual bool isScript(char *scriptname);
01507
01514 void scanDir(char *path);
01515
01516 public:
01520 aaImage(aaScript *script);
01521 };
01522
01531 class Conference : protected Mutex
01532 {
01533 protected:
01534 virtual ~Conference()
01535 {};
01536
01537 Conference()
01538 {};
01539 public:
01540 virtual unsigned getMembers(void) = 0;
01541 virtual unsigned getUsed(void) = 0;
01542 virtual unsigned getAvail(void) = 0;
01543 };
01544
01554 class Trunk : public ScriptInterp
01555 {
01556 private:
01557 friend class TestDebug;
01558 friend class aaScript;
01559 friend class Translator;
01560 friend class ScriptInterface;
01561 friend class Service;
01562 friend class AudioService;
01563 friend class Fifo;
01564 friend class PortManager;
01565
01566 char *cdrv[33];
01567 int cdrc;
01568 numbersymbol_t numbers[5];
01569
01570 bool scrStart(void);
01571 bool scrRequest(void);
01572 bool scrLibonce(void);
01573 bool scrLibexec(void);
01574 bool scrHangup(void);
01575 bool scrDebug(void);
01576 bool scrImport(void);
01577 bool scrExport(void);
01578 bool scrFunction(void);
01579 bool scrAlog(void);
01580 bool scrAudit(void);
01581 bool scrPause(void);
01582 bool scrSleep(void);
01583 bool scrSync(void);
01584 bool scrTone(void);
01585 bool scrAnswer(void);
01586 bool scrCollect(void);
01587 bool scrFlash(void);
01588 bool scrPlay(void);
01589 bool scrRecord(void);
01590 bool scrAppend(void);
01591 bool scrDial(void);
01592 bool scrTransfer(void);
01593 bool scrSpeak(void);
01594 bool scrMap(void);
01595 bool scrModule(void);
01596 bool scrSchedule(void);
01597 bool scrSignal(void);
01598 bool scrIdle(void);
01599
01600 protected:
01601 static ScriptSymbol globals;
01602 static char digit[16];
01603 ScriptInterface *script;
01604 TrunkGroup *group;
01605 PortManager *manager;
01606 int id;
01607 time_t start, idle;
01608
01609 int idle_timer;
01610 int rings;
01611 int digits;
01612
01613 Service *thread;
01614 trunkdata_t data;
01615 execdata_t tgi;
01616 digitsymbol_t dtmf;
01617
01618 struct
01619 {
01620 bool offhook: 1;
01621 bool dtmf: 1;
01622 bool script: 1;
01623 bool reset: 1;
01624 bool timer : 1;
01625 bool audio: 1;
01626 bool once : 1;
01627 bool ready : 1;
01628 bool echo : 1;
01629 unsigned temp : 1;
01630 trunkmode_t trunk: 2;
01631 dspmode_t dsp: 4;
01632 } flags;
01633
01639 virtual Conference *getConference(void)
01640 {return NULL;};
01641
01645 virtual void exitConference(void)
01646 {return;};
01647
01653 unsigned long getTrapDefault(void)
01654 {return 0x00000007;};
01655
01664 void setConstant(const char *id, const char *data);
01665
01673 scriptsymbol_t *getEntry(const char *symname, int size);
01674
01680 void Commit(scriptsymbol_t *sym);
01681
01688 int getTimeout(void);
01689
01696 int getInterdigit(void);
01697
01703 unsigned short getDigitMask(void);
01704
01710 bool TrunkSignal(trunksignal_t);
01711
01718 virtual void setDTMFDetect(void);
01719
01728 virtual void setDTMFDetect(bool enable)
01729 {flags.dtmf = enable;};
01730
01736 virtual void stopServices(void);
01737
01748 virtual void TrunkStep(trunkstep_t step) = 0;
01749
01755 bool idleHangup();
01756
01763 virtual unsigned long getIdleTime(void) = 0;
01764
01768 bool ScriptStep(void);
01769
01778 bool Attach(const char *scrname);
01779
01784 void Detach(void);
01785
01789 unsigned long getMask(void);
01790
01797 char **getInitial(char **args);
01798
01805 void setList(char **list);
01806
01807 Trunk(int port);
01808 public:
01814 virtual unsigned long getCapabilities(void)
01815 {return TRUNK_CAP_VOICE | TRUNK_CAP_DIAL;};
01816
01822 virtual void getName(char *buffer) = 0;
01823
01831 virtual bool postEvent(TrunkEvent *event) = 0;
01832
01838 int getDigit(char digit);
01839
01845 bool isReady(void);
01846 };
01847
01856 class PortManager
01857 {
01858 private:
01859 Trunk *trunk;
01860
01861 protected:
01862 ~PortManager()
01863 {trunk->manager = NULL;};
01864
01870 PortManager(Trunk *trk);
01871
01877 inline void postStep(trunkstep_t step)
01878 {trunk->TrunkStep(step);};
01879
01886 inline bool postEvent(TrunkEvent *event)
01887 {return trunk->postEvent(event);};
01888
01894 inline trunkdata_t *getData(void)
01895 {return &trunk->data;};
01896
01902 inline execdata_t *getExec(void)
01903 {return &trunk->tgi;};
01904 public:
01908 virtual bool Step(void) = 0;
01909
01915 virtual unsigned long getMask(void) = 0;
01916
01923 virtual bool postSignal(trunksignal_t signal) = 0;
01924
01931 virtual bool postAccept(const char *name) = 0;
01932
01936 virtual void postDetach(void) = 0;
01937 };
01938
01948 class Fifo : public fifostream, public Mutex
01949 {
01950 protected:
01951 char schedule[33];
01952
01953 bool exitPid(char **args);
01954 bool waitPid(char **args);
01955 bool setSymbol(char **argv);
01956 bool putSymbol(char **argv);
01957 bool submit(char **argv);
01958 bool login(char **argv);
01959 bool mapFiles(char **argv);
01960 bool startScript(char **argv);
01961 bool ringScript(char **argv);
01962 bool redirectScript(char **argv);
01963 bool busyLine(char **argv);
01964 bool idleLine(char **argv);
01965 bool hangupLine(char **argv);
01966 bool reqScript(char **argv);
01967 bool setSchedule(char **argv);
01968
01969 public:
01977 bool Command(const char *cmdstring);
01978 };
01979
01987 class FifoHandler
01988 {
01989 private:
01990 friend class Fifo;
01991
01992 static FifoHandler *first;
01993 FifoHandler *next;
01994 protected:
02001 virtual bool Command(char **argv) = 0;
02002
02006 FifoHandler();
02007 };
02008
02022 class Audit : public Mutex
02023 {
02024 private:
02025 friend void audit(Trunk *trunk, char *detail);
02026 friend void alog(Trunk *trunk, char *detail);
02027 friend class Scheduler;
02028
02029 static Audit *first;
02030 Audit *next;
02031
02032 protected:
02033 static Auditdata keys;
02034
02040 virtual void ReportAudit(Trunk *trunk, char *detail) = 0;
02041
02047 virtual void ReportCDR(Trunk *trunk, char *detail)
02048 {ReportAudit(trunk, detail);};
02049
02053 virtual void ReportStats(void)
02054 {return;};
02055
02061 inline TrunkGroup *getFirst(void)
02062 {return TrunkGroup::first;};
02063
02070 inline TrunkGroup *getNext(TrunkGroup *grp)
02071 {return grp->next;};
02072
02076 Audit();
02077 };
02078
02086 class Driver : public aaScript
02087 {
02088 protected:
02089 friend class TrunkGroup;
02090
02091 TrunkGroup **groups;
02092 char *status;
02093 bool active;
02094
02095 public:
02099 Driver();
02100
02107 virtual int Start(void) = 0;
02108
02112 virtual void Stop(void) = 0;
02113
02119 void getStatus(char *buffer);
02120
02127 virtual aaImage *getImage(void);
02128
02135 virtual int getTrunkCount(void) = 0;
02136
02143 virtual int getTrunkUsed(void)
02144 {return getTrunkCount();};
02145
02152 TrunkGroup *getTrunkGroup(int id)
02153 {return groups[id];};
02154
02160 virtual Trunk *getTrunkPort(int id) = 0;
02161
02167 virtual Conference *getConfPort(const char *name)
02168 {return NULL;};
02169 };
02170
02177 class Debug : protected Mutex
02178 {
02179 public:
02183 Debug();
02184
02190 virtual bool DebugTest(void)
02191 {return false;};
02192
02196 virtual void DebugEvent(Trunk *trunk, TrunkEvent *event)
02197 {return;};
02198
02202 virtual void DebugState(Trunk *trunk, char *state)
02203 {return;};
02204
02208 virtual void DebugService(Trunk *trunk, char *msg)
02209 {return;};
02210
02214 virtual void DebugScript(Trunk *trunk, char *msg)
02215 {return;};
02216
02220 virtual void DebugStep(Trunk *trunk, scriptline_t *line)
02221 {DebugState(trunk, "step");};
02222
02226 virtual bool DebugFifo(char **argv)
02227 {return true;};
02228 };
02229
02236 class AudioService
02237 {
02238 private:
02239 char filename[256];
02240
02241 protected:
02242 Trunk *trunk;
02249 char *getPrompt(char *name);
02250
02256 char *getPlayfile(void);
02257
02261 AudioService(void);
02262 };
02263
02271 class Service : public Semaphore, public Thread, public AudioService
02272 {
02273 protected:
02274 volatile bool stopped;
02275 trunkdata_t *data;
02276 TrunkGroup *group;
02277
02281 void Success(void);
02282
02286 void Failure(void);
02287
02291 inline void dspReset(void)
02292 {trunk->flags.reset = true;};
02293
02297 inline void setAudio(void)
02298 {trunk->flags.audio = true;};
02299
02303 inline void clrAudio(void)
02304 {trunk->flags.audio = false;};
02305
02306 public:
02313 Service(Trunk *trunk, int pri);
02314
02321 virtual timeout_t Stop(void);
02322
02330 virtual bool isExiting(void)
02331 {return true;};
02332
02336 void endService(void)
02337 {Terminate();};
02338
02342 virtual ~Service()
02343 {Terminate();}
02344 };
02345
02355 class Server : public Thread
02356 {
02357 private:
02358 static Server *first;
02359 Server *next;
02360 friend void startServers(void);
02361 friend void stopServers(void);
02362
02363 protected:
02364 Server(int pri);
02365
02369 virtual void Stop(void)
02370 {Terminate();};
02371 };
02372
02379 class Sync
02380 {
02381 private:
02382 friend class Scheduler;
02383
02384 static Sync *first;
02385 Sync *next;
02386 time_t runtime;
02387
02388 protected:
02392 Sync(void);
02393
02398 virtual bool isScheduled(void) = 0;
02399
02404 virtual unsigned getInterval(void)
02405 {return 10;};
02406
02410 virtual void Schedule(void) = 0;
02411
02415 virtual char *getName(void) = 0;
02416 };
02417
02426 class phTone
02427 {
02428 private:
02429 friend phTone *getphTone(const char *name);
02430 static phTone *first;
02431 static int ulaw[256];
02432 phTone *next;
02433 char name[33];
02434 unsigned char *samples;
02435 timeout_t duration;
02436 unsigned freq1, freq2;
02437
02438 public:
02446 phTone(const char *name, timeout_t duration, unsigned f);
02447
02456 phTone(const char *name, timeout_t duration, unsigned f1, unsigned f2);
02457
02458 ~phTone();
02459
02465 void Clear(void);
02466
02472 inline unsigned char *getSamples(void)
02473 {return samples;};
02474
02480 inline timeout_t getDuration(void)
02481 {return duration;};
02482 };
02483
02490 class TGI
02491 {
02492 private:
02493 static TGI *first;
02494 TGI *next;
02495
02496 protected:
02497 TGI();
02498
02506 virtual bool getExtension(char *ext)
02507 {return false;};
02508
02509 public:
02519 virtual void Script(char *cmd, char **args)
02520 {return;};
02521
02530 virtual int Parse(int fd, int port, char *cmd)
02531 {return -1;};
02532
02533 friend void getInterp(char *cmd, char **args);
02534 friend TGI *getInterp(char *cmd);
02535 };
02536
02546 class Module
02547 {
02548 private:
02549 static Module *first;
02550 Module *next;
02551
02552 protected:
02553 Module();
02554
02560 virtual modtype_t getType(void) = 0;
02561
02562 public:
02568 virtual char *getName(void) = 0;
02569
02577 virtual char *Dispatch(Trunk *trunk) = NULL;
02578
02586 virtual unsigned Sleep(Trunk *trunk)
02587 {return 0;};
02588
02595 virtual void Detach(Trunk *trunk)
02596 {return;};
02597
02605 virtual void Attach(Trunk *trunk)
02606 {return;};
02607
02608 friend Module *getModule(modtype_t mod, const char *name = NULL);
02609 friend void detachModules(Trunk *trunk);
02610 friend void attachModules(Trunk *trunk);
02611 };
02612
02622 class Session
02623 {
02624 private:
02625 friend class Scheduler;
02626 static Mutex mutex;
02627 static Session *first;
02628 static Session *last;
02629 Session *next, *prev;
02630 static void Clean(void);
02631
02632 protected:
02633 Session();
02634 virtual ~Session()
02635 {Unlink();};
02636
02640 void Unlink(void);
02641
02648 virtual time_t getExpires(void) = 0;
02649 };
02650
02659 class AudioFeed : private ThreadLock
02660 {
02661 private:
02662 static AudioFeed *first;
02663 AudioFeed *next;
02664 unsigned char *buffers;
02665 volatile unsigned char *current;
02666 size_t feedsize, bufsize;
02667 bool active;
02668
02669 protected:
02670 const char *name;
02671
02672 public:
02673 AudioFeed(const char *name, unsigned buffers);
02674 ~AudioFeed();
02675 bool Enable(void);
02676 void Disable(void);
02677 unsigned char *getBuffer(unsigned char *prior = NULL, unsigned size = 120);
02678 void putBuffer(unsigned char *buffer, unsigned size = 120);
02679
02680 friend AudioFeed *getAudioFeed(const char *name);
02681 };
02682
02691 class Map : private MemPager
02692 {
02693 private:
02694 static ThreadLock lock;
02695 static Map *first, *last;
02696
02697 typedef struct _sym
02698 {
02699 struct _sym *next;
02700 char *key;
02701 char **values;
02702 } mapsym_t;
02703
02704 typedef struct
02705 {
02706 mapsym_t *keys[127];
02707 } mapkey_t;
02708
02709 mapkey_t *digits[32];
02710
02711 Map *next, *prev;
02712 char *name;
02713
02714 unsigned getKey(const char *key, unsigned len = 0);
02715 char **getList(const char *key, unsigned len);
02716 ~Map();
02717
02718 public:
02719 Map(const char *path, const char *name);
02720
02721 friend char **getMap(const char *map, const char *key);
02722 friend void endMaps(void);
02723 };
02724
02733 class Protocol : public Keydata, public InetHostAddress, public ThreadLock
02734 {
02735 private:
02736 friend class Resolver;
02737 static Protocol *first;
02738 Protocol *next;
02739 Semaphore *sessions;
02740 tpport_t port;
02741
02742 void Update(InetHostAddress addr);
02743 public:
02744 Protocol(const char *keypath, tpport_t port);
02745 ~Protocol();
02746
02752 InetHostAddress getAddress(void);
02753
02759 inline tpport_t getPort(void)
02760 {return port;};
02761
02768 inline Semaphore *getSessions(void)
02769 {return sessions;};
02770 };
02771
02772 extern bool running;
02773 extern KeyServer keyserver;
02774 extern KeyThreads keythreads;
02775 extern KeyMemory keymemory;
02776 extern KeyPaths keypaths;
02777 extern KeyLocal keylocal;
02778 extern KeyNetwork keynetwork;
02779 extern KeyMailbox keymailbox;
02780 extern KeyTones keytones;
02781 extern KeyFeed keyfeed;
02782 extern Plugins plugins;
02783 extern Driver *driver;
02784 extern Debug *debug;
02785 extern Fifo fifo;
02786 #endif
02787