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_BAYONNESCRIPT_H_
00021 #include <cc++/bayonnescript.h>
00022 #endif
00023
00024 #ifndef CCXX_BAYONNESYMBOLS_H_
00025 #include <cc++/bayonnesymbols.h>
00026 #endif
00027
00028 #ifdef COMMON_XML_PARSING
00029 #ifndef CCXX_XML_H_
00030 #include <cc++/xml.h>
00031 #endif
00032 #endif
00033
00034 #ifndef CCXX_URL_H_
00035 #include <cc++/url.h>
00036 #endif
00037
00038 #ifndef CCXX_SLOG_H_
00039 #include <cc++/slog.h>
00040 #endif
00041
00042 #ifndef CCXX_DSO_H_
00043 #include <cc++/file.h>
00044 #endif
00045
00046 #ifndef CCXX_SOCKET_H_
00047 #include <cc++/socket.h>
00048 #endif
00049
00050 #ifndef CCXX_BUFFER_H_
00051 #include <cc++/buffer.h>
00052 #endif
00053
00054 #ifndef CCXX_BAYONNEAUDIO_H_
00055 #include <cc++/bayonneaudio.h>
00056 #endif
00057
00058 #include <iostream>
00059 #include <fstream>
00060 #include <cstdlib>
00061 #include <climits>
00062
00063
00064
00065
00066 #ifndef PIPE_BUF
00067 #define PIPE_BUF 512
00068 #endif
00069
00070 #ifdef __FreeBSD__
00071 #undef read
00072 #undef write
00073 #undef readv
00074 #undef writev
00075 #endif
00076
00077 #ifdef CCXX_NAMESPACES
00078 namespace ost {
00079 #endif
00080
00081
00082
00083
00084
00085
00086
00087 class __EXPORT Trunk;
00088 class __EXPORT TrunkImage;
00089 class __EXPORT Service;
00090 class __EXPORT phTone;
00091 class __EXPORT TrunkGroup;
00092 class __EXPORT AudioBuffer;
00093 class __EXPORT Conference;
00094
00095 class Trunk;
00096 class Driver;
00097 class KeyServer;
00098 class Request;
00099 class Policy;
00100 class MappedStats;
00101 class Route;
00102 class ThreadModule;
00103 class MappedCalls;
00104 class aaScript;
00105 class Translator;
00106 class ScriptInterface;
00107 class Service;
00108 class AudioService;
00109 class Fifo;
00110 class TrunkGroup;
00111 class MappedDrivers;
00112 class Conference;
00113 class KeyTones;
00114 class Plugins;
00115
00116 #define MAX_DIGITS 48 // maximum dtmf receive digit buffer size
00117 #define MAX_NAME_LEN 64
00118
00119 struct callrec_t;
00120
00121
00122
00123
00124 typedef enum
00125 {
00126 SELECT_FIRST,
00127 SELECT_LAST
00128 } seltype_t;
00129
00130
00131
00132
00133
00134 typedef enum
00135 {
00136 JOIN_RECV,
00137 JOIN_XMIT,
00138 JOIN_FULL
00139 } joinmode_t;
00140
00141
00142
00143
00144 typedef enum
00145 {
00146 PULSE_DIALER,
00147 DTMF_DIALER,
00148 MF_DIALER
00149 } dialmode_t;
00150
00151
00152
00153
00154
00155
00156 typedef enum {
00157
00158 TRUNK_STEP_HANGUP = 0,
00159 TRUNK_STEP_SLEEP,
00160 TRUNK_STEP_ACCEPT,
00161 TRUNK_STEP_REJECT,
00162 TRUNK_STEP_ANSWER,
00163 TRUNK_STEP_COLLECT,
00164 TRUNK_STEP_PLAY,
00165 TRUNK_STEP_PLAYWAIT,
00166 TRUNK_STEP_RECORD,
00167 TRUNK_STEP_TONE,
00168 TRUNK_STEP_DIALXFER,
00169 TRUNK_STEP_SOFTDIAL,
00170 TRUNK_STEP_FLASH,
00171 TRUNK_STEP_JOIN,
00172 TRUNK_STEP_LISTEN,
00173 TRUNK_STEP_RTP,
00174 TRUNK_STEP_DUPLEX,
00175 TRUNK_STEP_DETECT,
00176 TRUNK_STEP_REQUIRES,
00177 TRUNK_STEP_THREAD,
00178 TRUNK_STEP_SENDFAX,
00179 TRUNK_STEP_RECVFAX,
00180 TRUNK_STEP_ENTER,
00181 TRUNK_STEP_SOFTJOIN,
00182 TRUNK_STEP_DRIVER,
00183 TRUNK_STEP_EXIT = TRUNK_STEP_HANGUP
00184 } trunkstep_t;
00185
00186
00187
00188
00189
00190
00191 typedef enum {
00192
00193 TRUNK_SIGNAL_STEP = 0,
00194
00195 TRUNK_SIGNAL_EXIT,
00196 TRUNK_SIGNAL_HANGUP=TRUNK_SIGNAL_EXIT,
00197 TRUNK_SIGNAL_ERROR,
00198 TRUNK_SIGNAL_TIMEOUT,
00199 TRUNK_SIGNAL_DTMF,
00200
00201 TRUNK_SIGNAL_0,
00202 TRUNK_SIGNAL_1,
00203 TRUNK_SIGNAL_2,
00204 TRUNK_SIGNAL_3,
00205
00206 TRUNK_SIGNAL_4,
00207 TRUNK_SIGNAL_5,
00208 TRUNK_SIGNAL_6,
00209 TRUNK_SIGNAL_7,
00210
00211 TRUNK_SIGNAL_8,
00212 TRUNK_SIGNAL_9,
00213 TRUNK_SIGNAL_STAR,
00214 TRUNK_SIGNAL_POUND,
00215
00216 TRUNK_SIGNAL_A,
00217 TRUNK_SIGNAL_OVERRIDE = TRUNK_SIGNAL_A,
00218 TRUNK_SIGNAL_B,
00219 TRUNK_SIGNAL_FLASH = TRUNK_SIGNAL_B,
00220 TRUNK_SIGNAL_C,
00221 TRUNK_SIGNAL_IMMEDIATE = TRUNK_SIGNAL_C,
00222 TRUNK_SIGNAL_D,
00223 TRUNK_SIGNAL_PRIORITY = TRUNK_SIGNAL_D,
00224
00225 TRUNK_SIGNAL_SILENCE,
00226 TRUNK_SIGNAL_BUSY,
00227 TRUNK_SIGNAL_CANCEL,
00228 TRUNK_SIGNAL_FAIL = TRUNK_SIGNAL_CANCEL,
00229 TRUNK_SIGNAL_INVALID = TRUNK_SIGNAL_CANCEL,
00230 TRUNK_SIGNAL_NOTIFY,
00231
00232 TRUNK_SIGNAL_NOANSWER,
00233 TRUNK_SIGNAL_RING,
00234 TRUNK_SIGNAL_ANSWER = TRUNK_SIGNAL_RING,
00235 TRUNK_SIGNAL_PICKUP = TRUNK_SIGNAL_RING,
00236 TRUNK_SIGNAL_TONE,
00237 TRUNK_SIGNAL_EVENT,
00238
00239 TRUNK_SIGNAL_TIME,
00240 TRUNK_SIGNAL_MAXTIME = TRUNK_SIGNAL_TIME,
00241 TRUNK_SIGNAL_CHILD,
00242 TRUNK_SIGNAL_DRIVER,
00243
00244 TRUNK_SIGNAL_GOTO = 65
00245
00246 } trunksignal_t;
00247
00248
00249
00250
00251
00252
00253 typedef enum {
00254
00255
00256 TRUNK_ENTER_STATE = 100,
00257 TRUNK_EXIT_STATE,
00258 TRUNK_STOP_STATE,
00259 TRUNK_NOTIFICATION,
00260 TRUNK_SERVICE_SUCCESS,
00261 TRUNK_SERVICE_FAILURE,
00262 TRUNK_SERVICE_LOGIN,
00263 TRUNK_SIGNAL_TEXT,
00264 TRUNK_SEND_MESSAGE,
00265 TRUNK_JOIN_TRUNKS,
00266 TRUNK_PART_TRUNKS,
00267 TRUNK_NULL_EVENT,
00268 TRUNK_CHILD_START,
00269 TRUNK_CHILD_FAIL,
00270 TRUNK_CHILD_EXIT,
00271 TRUNK_SIGNAL_JOIN,
00272 TRUNK_FAX_EVENT,
00273
00274
00275
00276 TRUNK_EXIT_SHELL = 200,
00277 TRUNK_START_DIAL,
00278 TRUNK_START_SCRIPT,
00279 TRUNK_RING_START,
00280 TRUNK_RING_REDIRECT,
00281 TRUNK_STOP_DISCONNECT,
00282 TRUNK_SHELL_START,
00283 TRUNK_WAIT_SHELL,
00284 TRUNK_ASR_START,
00285 TRUNK_ASR_TEXT,
00286 TRUNK_ASR_PARTIAL,
00287 TRUNK_ASR_VOICE,
00288 TRUNK_SYNC_PARENT,
00289 TRUNK_SYNC_NOTIFY,
00290
00291
00292
00293 TRUNK_START_INCOMING = TRUNK_RING_START,
00294 TRUNK_START_OUTGOING = TRUNK_START_SCRIPT,
00295
00296
00297
00298 TRUNK_MAKE_TEST = 300,
00299 TRUNK_MAKE_BUSY,
00300 TRUNK_MAKE_IDLE,
00301 TRUNK_MAKE_STEP,
00302 TRUNK_MAKE_STANDBY,
00303
00304
00305
00306 TRUNK_LINE_WINK = 400,
00307 TRUNK_TIMER_EXPIRED,
00308 TRUNK_TIMER_EXIT,
00309 TRUNK_TIMER_SYNC,
00310 TRUNK_RINGING_ON,
00311 TRUNK_RINGING_OFF,
00312 TRUNK_TEST_IDLE,
00313 TRUNK_TEST_FAILURE,
00314 TRUNK_ON_HOOK,
00315 TRUNK_OFF_HOOK,
00316 TRUNK_CALLER_ID,
00317 TRUNK_RINGING_DID,
00318 TRUNK_CALL_DETECT,
00319 TRUNK_CALL_CONNECT,
00320 TRUNK_CALL_RELEASE,
00321 TRUNK_CALL_ACCEPT,
00322 TRUNK_CALL_ANSWERED,
00323 TRUNK_CALL_HOLD,
00324 TRUNK_CALL_NOHOLD,
00325 TRUNK_CALL_DIGITS,
00326 TRUNK_CALL_OFFER,
00327 TRUNK_CALL_ANI,
00328 TRUNK_CALL_ACTIVE,
00329 TRUNK_CALL_NOACTIVE,
00330 TRUNK_CALL_BILLING,
00331 TRUNK_CALL_RESTART,
00332 TRUNK_CALL_SETSTATE,
00333 TRUNK_CALL_FAILURE,
00334 TRUNK_CALL_ALERTING,
00335 TRUNK_CALL_INFO,
00336 TRUNK_CALL_BUSY,
00337 TRUNK_CALL_DIVERT,
00338 TRUNK_CALL_FACILITY,
00339 TRUNK_CALL_FRAME,
00340 TRUNK_CALL_NOTIFY,
00341 TRUNK_CALL_NSI,
00342 TRUNK_CALL_RINGING,
00343 TRUNK_CALL_DISCONNECT,
00344 TRUNK_DEVICE_OPEN,
00345 TRUNK_DEVICE_CLOSE,
00346 TRUNK_DEVICE_BLOCKED,
00347 TRUNK_DEVICE_UNBLOCKED,
00348 TRUNK_CALL_OUTGOING,
00349 TRUNK_CALL_INCOMING,
00350
00351
00352
00353 TRUNK_AUDIO_IDLE = 500,
00354 TRUNK_INPUT_PENDING,
00355 TRUNK_OUTPUT_PENDING,
00356 TRUNK_AUDIO_BUFFER,
00357 TRUNK_TONE_IDLE,
00358 TRUNK_DTMF_KEYDOWN,
00359 TRUNK_DTMF_KEYUP,
00360 TRUNK_TONE_START,
00361 TRUNK_TONE_STOP,
00362 TRUNK_VOX_DETECT,
00363 TRUNK_VOX_SILENCE,
00364 TRUNK_AUDIO_START,
00365 TRUNK_AUDIO_STOP,
00366 TRUNK_CPA_DIALTONE,
00367 TRUNK_CPA_BUSYTONE,
00368 TRUNK_CPA_RINGING,
00369 TRUNK_CPA_RINGBACK = TRUNK_CPA_RINGING,
00370 TRUNK_CPA_INTERCEPT,
00371 TRUNK_CPA_NODIALTONE,
00372 TRUNK_CPA_NORINGBACK,
00373 TRUNK_CPA_NOANSWER,
00374 TRUNK_CPA_CONNECT,
00375 TRUNK_CPA_FAILURE,
00376 TRUNK_CPA_GRUNT,
00377 TRUNK_CPA_REORDER,
00378 TRUNK_DSP_READY,
00379 TRUNK_CPA_STOPPED,
00380 TRUNK_CPA_SIT,
00381 TRUNK_CPA_WAITING,
00382
00383
00384
00385 TRUNK_START_RINGING = 600,
00386 TRUNK_START_TRANSFER,
00387 TRUNK_START_INTERCOM,
00388 TRUNK_START_RECALL,
00389 TRUNK_START_DIALING,
00390 TRUNK_STOP_RINGING,
00391 TRUNK_STATION_OFFHOOK,
00392 TRUNK_STATION_ONHOOK,
00393 TRUNK_STATION_FLASH,
00394 TRUNK_STATION_ANSWER,
00395 TRUNK_STATION_PICKUP,
00396 TRUNK_STATION_CONNECT,
00397
00398
00399
00400 TRUNK_DRIVER_SPECIFIC=8000
00401 } trunkevent_t;
00402
00403
00404
00405
00406
00407 typedef enum
00408 {
00409 DSP_MODE_INACTIVE = 0,
00410 DSP_MODE_VOICE,
00411 DSP_MODE_CALLERID,
00412 DSP_MODE_DATA,
00413 DSP_MODE_FAX,
00414 DSP_MODE_TDM,
00415 DSP_MODE_RTP,
00416 DSP_MODE_DUPLEX,
00417 DSP_MODE_JOIN,
00418 DSP_MODE_CONF,
00419 DSP_MODE_TONE
00420 } dspmode_t;
00421
00422
00423
00424
00425
00426 typedef enum
00427 {
00428 TRUNK_MODE_INCOMING = 0,
00429 TRUNK_MODE_OUTGOING,
00430 TRUNK_MODE_INACTIVE,
00431 TRUNK_MODE_UNAVAILABLE
00432 } trunkmode_t;
00433
00434
00435
00436
00437
00438 typedef enum
00439 {
00440 STAT_MAX_INCOMING,
00441 STAT_MAX_OUTGOING,
00442 STAT_TOT_INCOMING,
00443 STAT_TOT_OUTGOING,
00444 STAT_ACTIVE_CALLS,
00445 STAT_NOW_INCOMING,
00446 STAT_NOW_OUTGOING,
00447 STAT_SYS_INCOMING,
00448 STAT_SYS_OUTGOING,
00449 STAT_SYS_UPTIME,
00450 STAT_SYS_ACTIVITY,
00451 STAT_CURRENT_CALLS,
00452 STAT_CMAX_INCOMING,
00453 STAT_CMAX_OUTGOING,
00454 STAT_AVAIL_CALLS
00455 } statitem_t;
00456
00457
00458
00459 typedef enum
00460 {
00461 PLAY_MODE_NORMAL,
00462 PLAY_MODE_ONE,
00463 PLAY_MODE_ANY,
00464 PLAY_MODE_TEMP,
00465 PLAY_MODE_TEXT,
00466 PLAY_MODE_FILE,
00467 PLAY_MODE_MOH,
00468 PLAY_MODE_NONE
00469 } playmode_t;
00470
00471
00472
00473
00474 typedef enum
00475 {
00476 WRITE_MODE_NONE,
00477 WRITE_MODE_REPLACE,
00478 WRITE_MODE_APPEND,
00479 WRITE_MODE_INITIAL
00480 } writemode_t;
00481
00482
00483
00484 typedef enum
00485 {
00486 TTS_GATEWAY_TEXT,
00487 TTS_GATEWAY_FILE
00488 } ttsmode_t;
00489
00490
00491
00492
00493 #define TRUNK_CAP_VOICE 0x00000001 // supports voice telephone calls
00494 #define TRUNK_CAP_DIAL 0x00000002 // supports dialing
00495 #define TRUNK_CAP_SENDFAX 0x00000004 // supports sending of faxes
00496 #define TRUNK_CAP_RECVFAX 0x00000008 // supports receipt of faxes
00497 #define TRUNK_CAP_DATA 0x00000010 // supports fsk modem
00498 #define TRUNK_CAP_TTS 0x00000020 // supports text to speech directly
00499 #define TRUNK_CAP_ASR 0x00000040 // supports asr (listen command)
00500 #define TRUNK_CAP_STATION 0x00000080 // is pots to plugin telephone
00501 #define TRUNK_CAP_TIE 0x00000160 // is a tie line
00502 #define TRUNK_CAP_TRUNK 0x00002000 // is a trunk port
00503
00504
00505
00506 typedef struct
00507 {
00508 bool dtmf;
00509 int pid;
00510 unsigned short seq;
00511 void *data;
00512 } execdata_t;
00513
00514
00515
00516 typedef enum
00517 {
00518 SPEED_FAST,
00519 SPEED_SLOW,
00520 SPEED_NORMAL
00521 } trunkspeed_t;
00522
00523
00524
00525
00526
00527
00528 typedef union
00529 {
00530
00531
00532 struct
00533 {
00534 unsigned rings;
00535 timeout_t timeout;
00536 const char *transfer;
00537 Trunk *intercom;
00538 const char *station;
00539 const char *fax;
00540 } answer;
00541
00542
00543
00544 struct
00545 {
00546 char pathname[256];
00547 const char *station;
00548 } fax;
00549
00550
00551
00552 struct
00553 {
00554 char list[256];
00555 char *name;
00556 const char *extension;
00557 unsigned long offset;
00558 unsigned long limit;
00559 unsigned short term;
00560 playmode_t mode;
00561 writemode_t write;
00562 timeout_t timeout, maxtime;
00563 timeout_t position;
00564 unsigned repeat;
00565 unsigned volume;
00566 float gain, pitch;
00567 trunkspeed_t speed;
00568 const char *voice;
00569 const char *text;
00570 const char *cache;
00571 bool lock;
00572 unsigned channel;
00573 } play;
00574
00575
00576
00577 struct
00578 {
00579 char *name, *save;
00580
00581 const char *encoding;
00582 const char *annotation;
00583 const char *extension;
00584 const char *text;
00585 timeout_t timeout;
00586 timeout_t position;
00587 unsigned long offset;
00588 unsigned short term;
00589 unsigned long silence;
00590 unsigned long trim;
00591 unsigned long minsize;
00592 unsigned volume;
00593 float gain;
00594 short frames;
00595 bool append;
00596 bool info;
00597 char filepath[65];
00598 char savepath[65];
00599 char altinfo[128];
00600 } record;
00601
00602
00603
00604 struct
00605 {
00606 char digits[65];
00607 char *digit;
00608 char *callingdigit;
00609 bool exit;
00610 dialmode_t dialer;
00611 timeout_t interdigit;
00612 timeout_t digittimer;
00613 timeout_t timeout;
00614 timeout_t offhook;
00615 timeout_t onhook;
00616 unsigned pulsecount;
00617 bool sync;
00618 } dialxfer;
00619
00620
00621
00622 struct
00623 {
00624 timeout_t timeout, first;
00625 unsigned count;
00626 unsigned short term;
00627 unsigned short ignore;
00628 void *map;
00629 void *var;
00630 } collect;
00631
00632
00633
00634 struct
00635 {
00636 timeout_t first;
00637 timeout_t next;
00638 unsigned short term, count;
00639 float gain, pitch;
00640 unsigned volume;
00641 void *save;
00642 char *wordlist[32];
00643 char buffer[256];
00644 } listen;
00645
00646
00647
00648 struct
00649 {
00650 timeout_t wakeup;
00651 unsigned rings;
00652 unsigned loops;
00653 const char *save;
00654 unsigned short term;
00655 unsigned count;
00656 } sleep;
00657
00658
00659
00660 struct
00661 {
00662 timeout_t wakeup, duration;
00663 unsigned loops;
00664 phTone *tone;
00665 unsigned freq1, freq2;
00666 int ampl1, ampl2;
00667 Trunk *dialing;
00668 bool recall;
00669 } tone;
00670 struct
00671 {
00672 Trunk *src;
00673 const char *msg;
00674 unsigned seq;
00675 } send;
00676
00677
00678
00679 struct
00680 {
00681 timeout_t wakeup, maxwait;
00682 bool hangup;
00683 joinmode_t direction;
00684 Trunk *trunk, *waiting;
00685 phTone *tone;
00686 float inpgain, outgain;
00687 char *recfn;
00688 const char *encoding;
00689 const char *annotation;
00690 const char *extension;
00691 unsigned count;
00692 unsigned seq;
00693 trunkevent_t reason;
00694 bool local;
00695 time_t start;
00696 } join;
00697
00698
00699
00700 struct
00701 {
00702 Conference *resource;
00703 timeout_t maxtime;
00704 unsigned volume;
00705 float input, output;
00706 } enter;
00707
00708
00709
00710 struct
00711 {
00712 TrunkImage *image;
00713 const char *url;
00714 const char *section;
00715 const char *parent;
00716 const char *fail;
00717 const char *database;
00718 char **vars;
00719 bool post, attach, gosub;
00720 timeout_t timeout;
00721 char userid[64];
00722 char filepath[256];
00723 } load;
00724
00725
00726
00727 struct
00728 {
00729 Trunk *answer;
00730 const char *transfer;
00731 } intercom;
00732 } trunkdata_t;
00733
00734
00735
00736
00737
00738 typedef struct
00739 {
00740
00741
00742 trunkevent_t id;
00743
00744
00745
00746 union
00747 {
00748
00749
00750 struct
00751 {
00752 unsigned digit: 4;
00753 unsigned duration: 12;
00754 unsigned e1: 8;
00755 unsigned e2: 8;
00756 } dtmf;
00757
00758
00759
00760 struct
00761 {
00762 unsigned tone: 8;
00763 unsigned energy: 8;
00764 unsigned duration: 16;
00765 char *name;
00766 } tone;
00767
00768
00769
00770
00771 struct
00772 {
00773 unsigned seq;
00774 Trunk *src;
00775 const char *msg;
00776 } send;
00777
00778
00779
00780 struct
00781 {
00782 unsigned digit: 4;
00783 unsigned duration: 24;
00784 } ring;
00785
00786
00787
00788 struct
00789 {
00790 unsigned seq;
00791 bool result;
00792 char *data;
00793 } lookup;
00794
00795
00796
00797 struct
00798 {
00799 unsigned tid;
00800 const char *transfer;
00801 } intercom;
00802
00803
00804
00805 struct
00806 {
00807 int type;
00808 int param0;
00809 int param1;
00810 int channel;
00811 } fax;
00812
00813
00814
00815 struct
00816 {
00817 unsigned status;
00818 unsigned short seq;
00819 } exitpid;
00820
00821
00822
00823 struct
00824 {
00825 int pid;
00826 unsigned short seq;
00827 } waitpid;
00828
00829 struct
00830 {
00831 const char *msg;
00832 const char *id;
00833 } sync;
00834
00835 trunkevent_t reason;
00836 unsigned span;
00837 unsigned card;
00838 unsigned tid;
00839 bool ok;
00840 int status, fd, pid;
00841 Trunk *trunk;
00842 void *data;
00843 char **argv;
00844 char *error;
00845 timeout_t duration;
00846 trunkstep_t step;
00847 char dn[8];
00848 dspmode_t dsp;
00849 } parm;
00850 } TrunkEvent;
00851
00852 #pragma pack(1)
00853
00854
00855
00856
00857 typedef struct {
00858 time_t update;
00859 char name[16];
00860 struct in_addr addr;
00861 unsigned long uptime;
00862 unsigned long calls;
00863 unsigned char version;
00864 unsigned char buddies;
00865 unsigned char spansize;
00866 unsigned short ports;
00867 unsigned char service;
00868 unsigned char dialing;
00869 char schedule[16];
00870 char stat[960];
00871 } statnode_t;
00872
00873 #pragma pack()
00874
00875
00876
00877
00878
00879 __EXPORT bool getLogical(const char *string);
00880 __EXPORT timeout_t getSecTimeout(const char *string);
00881 __EXPORT timeout_t getMSTimeout(const char *string);
00882 __EXPORT timeout_t getTimePosition(const char *string);
00883 class __EXPORT UsageStat;
00884
00892 class __EXPORT CallStat : public Mutex
00893 {
00894 protected:
00895 static unsigned long upincoming;
00896 static unsigned long upoutgoing;
00897 static time_t uptime;
00898 volatile bool dirty;
00899
00900 time_t updated, prior, idled;
00901
00902 int capacity;
00903 struct
00904 {
00905 int incoming;
00906 int outgoing;
00907 } active, max, lastmax;
00908
00909 struct
00910 {
00911 long incoming;
00912 long outgoing;
00913 } total, lasttotal;
00914
00915 public:
00916 CallStat();
00917
00923 inline int getCapacity(void)
00924 {return capacity;};
00925
00932 long getStat(statitem_t item);
00933
00939 void getStat(unsigned long *save);
00940
00944 void incIncoming(void);
00945
00949 void decIncoming(void);
00950
00954 void incOutgoing(void);
00955
00959 void decOutgoing(void);
00960
00964 long getIdleTime();
00965
00969 void update(void);
00970 };
00971
00984 class __EXPORT Translator : protected Keydata
00985 {
00986 private:
00987 friend __EXPORT Translator *getTranslator(const char *name);
00988 static Translator *first;
00989 Translator *next;
00990
00991 protected:
00997 virtual char *getName(void) = 0;
00998
01005 char *getPlayBuffer(Trunk *trunk);
01006
01007 Translator(const char *conf);
01008
01009 public:
01017 virtual char *speak(Trunk *trunk) = 0;
01018 };
01019
01020
01021
01022
01023
01024
01031 class __EXPORT KeyTones : protected Keydata
01032 {
01033 public:
01037 KeyTones();
01038 };
01039
01047 class __EXPORT KeyLocal : public Keydata
01048 {
01049 public:
01053 KeyLocal();
01054 };
01055
01063 class __EXPORT KeyVoices : public Keydata
01064 {
01065 public:
01069 KeyVoices();
01070 };
01071
01072
01080 class __EXPORT KeyPaths : public Keydata
01081 {
01082 public:
01086 KeyPaths();
01087
01091 inline const char *getLibexec(void)
01092 {return getLast("libexec");};
01093
01097 inline const char *getTgipath(void)
01098 {return getLast("tgipath");};
01099
01103 inline const char *getLibpath(void)
01104 {return getLast("libpath");};
01105
01109 inline const char *getDatafiles(void)
01110 {return getLast("datafiles");};
01111
01115 inline const char *getWrappers(void)
01116 {return getLast("wrappers");};
01117
01121 inline const char *getRunfiles(void)
01122 {return getLast("runfiles");};
01123
01127 inline const char *getSpool(void)
01128 {return getLast("spool");};
01129
01133 inline const char *getLogpath(void)
01134 {return getLast("logpath");};
01135
01139 inline const char *getScriptFiles(void)
01140 {return getLast("scripts");};
01141
01145 inline const char *getPromptFiles(void)
01146 {return getLast("prompts");};
01147
01151 inline const char *getCache(void)
01152 {return getLast("cache");};
01153
01154 #ifndef WIN32
01155
01158 void setPrefix(char *path);
01159 #endif
01160 };
01161
01169 class __EXPORT KeyNetwork : public Keydata
01170 {
01171 public:
01175 KeyNetwork();
01176
01182 unsigned getRefresh(void)
01183 {return atoi(getLast("refresh"));};
01184
01190 unsigned getTimeToLive(void)
01191 {return atoi(getLast("live"));};
01192
01198 unsigned getTimeToElect(void)
01199 {return atoi(getLast("elect"));};
01200
01206 unsigned getTimeToExpire(void)
01207 {return atoi(getLast("expire"));};
01208
01214 InetHostAddress getBroadcast(void);
01215
01221 InetAddress getAddress(void);
01222
01228 InetAddress getMonitorAddress(void);
01229
01235 tpport_t getPort(void);
01236
01242 tpport_t getMonitorPort(void);
01243 };
01244
01251 class __EXPORT KeyProxy : public Keydata
01252 {
01253 public:
01257 KeyProxy();
01258
01264 const char *getHTTPServer(void);
01265
01271 tpport_t getHTTPPort(void);
01272
01279 timeout_t getTimeout(void);
01280 };
01281
01290 class __EXPORT KeyMemory : public Keydata
01291 {
01292 public:
01296 KeyMemory();
01297
01303 inline int getSymbolSize(void)
01304 {return atoi(getLast("symbols"));};
01305
01312 inline int getPageSize(void)
01313 {return atoi(getLast("page"));};
01314
01320 inline size_t getUserCount(void)
01321 {return atoi(getLast("users"));};
01322
01328 inline size_t getPrefCount(void)
01329 {return atoi(getLast("prefs"));};
01330 };
01331
01339 class __EXPORT KeyThreads : public Keydata
01340 {
01341 public:
01345 KeyThreads();
01346
01352 inline int priService(void)
01353 {return atoi(getLast("services"));};
01354
01360 inline int priGUI(void)
01361 {return atoi(getLast("gui"));};
01362
01368 inline int priRTP(void)
01369 {return atoi(getLast("rtp"));};
01370
01376 inline int getStepDelay(void)
01377 {return atoi(getLast("stepdelay"));};
01378
01384 inline int getStepInterval(void)
01385 {return atoi(getLast("stepinterval"));};
01386
01392 inline int getResetDelay(void)
01393 {return atoi(getLast("resetdelay"));};
01394
01400 size_t getStack(void);
01401
01402
01408 size_t getAudioStack(void);
01409
01415 size_t getDriverStack(void);
01416
01422 int getServices(void);
01423
01429 inline int priAudio(void)
01430 {return atoi(getLast("audio"));};
01431
01437 inline bool getAudit(void)
01438 {return getLogical(getLast("audit"));};
01444 inline int priGateway(void)
01445 {return atoi(getLast("gateways"));};
01446
01452 inline int priManager(void)
01453 {return atoi(getLast("managers"));};
01454
01460 inline int priNetwork(void)
01461 {return atoi(getLast("network"));};
01462
01468 inline int priSwitch(void)
01469 {return atoi(getLast("switch"));};
01470
01471
01477 inline int getRefresh(void)
01478 {return atoi(getLast("refresh"));};
01479
01485 int getGateways(void);
01486
01493 inline int getPriority(void)
01494 {return atoi(getLast("priority"));};
01495
01501 int getPolicy(void);
01502
01508 inline int getPages(void)
01509 {return atoi(getLast("pages"));};
01510 };
01511
01512 extern __EXPORT KeyThreads keythreads;
01513
01521 class __EXPORT Conference
01522 {
01523 private:
01524 friend class Trunk;
01525 friend class Driver;
01526
01527 Conference *next, *prev;
01528 Driver *driver;
01529 char name[16];
01530 unsigned size, used;
01531 bool reuse;
01532 bool ready;
01533
01534 protected:
01535 Conference(Driver *driver, const char *id, unsigned size);
01536
01537 virtual bool enter(Trunk *trunk) = 0;
01538 virtual void leave(Trunk *trunk) = 0;
01539 void unlink(void);
01540 void drop(void);
01541 void enterMutex(void);
01542 void leaveMutex(void);
01543
01544 public:
01545 virtual ~Conference()
01546 {unlink();};
01547
01548 void release(void);
01549 };
01550
01560 class __EXPORT Keyroute : public String
01561 {
01562 protected:
01563 friend class KeyServer;
01564
01565 class key
01566 {
01567 public:
01568 key *next;
01569 char id[33];
01570 String value;
01571 };
01572
01573 key *idx[32];
01574 key *fre;
01575
01576 public:
01580 Keyroute();
01581
01588 void set(const char *id, const char *data);
01589
01595 void clear(const char *id);
01596
01603 const char *first(const char *id);
01604
01611 const char *last(const char *id);
01612
01620 unsigned getIndex(char **list, unsigned max);
01621 };
01622
01633 class __EXPORT TrunkGroup : public Keydata, public CallStat
01634 {
01635 private:
01636 friend class KeyServer;
01637 friend class Request;
01638 friend class Policy;
01639 friend class Trunk;
01640 friend class MappedStats;
01641 static TrunkGroup *first;
01642 TrunkGroup *next;
01643 unsigned trump;
01644 Request *reqfirst, *reqlast;
01645 Policy *polFirst;
01646 unsigned members;
01647
01648 friend inline const char *getGroups(void)
01649 {return TrunkGroup::first->getLast("groups");};
01650
01651 friend __EXPORT void cancel(TrunkGroup *group, const char *tag);
01652 friend __EXPORT Request *locate(TrunkGroup *group, const char *tag, int *pos = NULL);
01653
01654 public:
01660 TrunkGroup(char *name = NULL);
01661
01667 inline const char *getName(void)
01668 {return getLast("name");};
01669
01673 static void logStats(void);
01674
01680 inline unsigned getAnswer(void)
01681 {return atoi(getLast("answer"));};
01682
01688 bool getAccept(void);
01689
01695 bool getDetect(void);
01696
01702 inline timeout_t getCallerid(void)
01703 {return getMSTimeout(getLast("callerid"));};
01704
01710 inline timeout_t getPickup(void)
01711 {return getMSTimeout(getLast("pickup"));};
01712
01718 inline const char *chkRequest(void)
01719 {return getLast("requests");};
01720
01726 seltype_t getSelect(void);
01727
01733 inline unsigned getThreashold(void)
01734 {return atoi(getLast("threashold"));};
01735
01741 inline unsigned getAnalysis(void)
01742 {return atoi(getLast("analysis"));};
01743
01750 inline timeout_t getReady(void)
01751 {return getMSTimeout(getLast("ready"));};
01752
01758 inline timeout_t getIdleTime(void)
01759 {return getMSTimeout(getLast("idletime"));};
01760
01766 inline unsigned getSiezeTime(void)
01767 {return atoi(getLast("siezetime"));};
01768
01774 inline unsigned getRingTime(void)
01775 {return atoi(getLast("ringtime"));};
01776
01782 inline unsigned getMinDigits(void)
01783 {return atoi(getLast("mindigits"));};
01784
01790 inline unsigned getMDigTimeOut(void)
01791 {return atoi(getLast("mdigtimeout"));};
01792
01798 inline timeout_t getHangup(void)
01799 {return getMSTimeout(getLast("hangup"));};
01800
01806 inline timeout_t getFlash(void)
01807 {return getMSTimeout(getLast("flash"));};
01808
01814 inline timeout_t getDialtone(void)
01815 {return getMSTimeout(getLast("dialtone"));};
01816
01822 inline timeout_t getDialspeed(void)
01823 {return getMSTimeout(getLast("dialspeed"));};
01824
01831 const char *getNumber(void);
01832
01836 inline void incCapacity(void)
01837 {++capacity;};
01838
01844 Request *getRequest(void);
01845
01851 static TrunkGroup *getGroup(const char *name = NULL);
01852
01859 static TrunkGroup *assign(Trunk *trunk);
01860
01866 inline TrunkGroup *getNext(void)
01867 {return next;};
01868 };
01869
01877 class __EXPORT KeyServer : public Keydata, public ThreadLock
01878 {
01879 private:
01880 friend class Fifo;
01881
01882 Keyroute incoming, outgoing;
01883
01884 public:
01888 KeyServer();
01889
01895 inline const char *getNode(void)
01896 {return getLast("node");};
01897
01903 inline const char *getLogin(void)
01904 {return getLast("login");};
01905
01911 inline const char *getPolicyOrder(void)
01912 {return getLast("policy");};
01913
01919 inline const char *getPassword(void)
01920 {return getLast("password");};
01921
01927 inline const char *getToken(void)
01928 {return getLast("token");};
01929
01933 void loadGroups(bool test);
01934
01940 inline int getNodeCount(void)
01941 {return atoi(getLast("nodes"));};
01942
01943 const char *getIncoming(Trunk *trunk);
01944
01948 void printRoutes(void);
01949 };
01950
01958 class __EXPORT Plugins : public Keydata
01959 {
01960 private:
01961 unsigned pidcount;
01962 int pids[32];
01963
01964 public:
01968 Plugins();
01969
01973 ~Plugins();
01974
01980 char *getDriverName(void);
01981
01985 void loadDebug(void);
01986
01990 void loadDatabase(void);
01991
01996 void loadDriver(void);
01997
01998 #ifndef WIN32
01999
02002 void loadSQL(void);
02003 #endif
02004
02008 void loadCodecs(void);
02009
02013 void loadModules(void);
02014
02018 void loadTTS(void);
02019
02023 void loadExtensions(void);
02024
02028 void loadTranslators(const char *lcp = NULL);
02029
02034 void loadTGI(void);
02035
02036 };
02037
02046 class __EXPORT aaScript : public ScriptCommand
02047 {
02048 protected:
02056 unsigned long getTrapMask(const char *trapname);
02057
02061 aaScript *next;
02062
02063 public:
02067 aaScript();
02068
02072 aaScript(aaScript *ini);
02073
02077 static aaScript *get(const char *id, aaScript *base = NULL);
02078
02084 void addDummy(const char *names);
02085 };
02086
02096 class __EXPORT aaImage : public ScriptImage
02097 {
02098 protected:
02106 virtual bool isScript(const char *scriptname, const char *ext);
02107
02114 void scanDir(char *path, const char *ext, size_t size);
02115
02116
02117 public:
02121 aaImage(aaScript *script);
02122 };
02123
02135 class __EXPORT PortNotify : private Buffer
02136 {
02137 private:
02138
02139 unsigned char buffer[256];
02140
02141 #ifdef COMMON_64_CLEAN
02142 size_t head, tail;
02143
02144 size_t onPeek(void *buffer);
02145 size_t onWait(void *buffer);
02146 size_t onPost(void *buffer);
02147
02148 #else
02149 unsigned head, tail;
02150
02151 int onPeek(void *buffer);
02152 int onWait(void *buffer);
02153 int onPost(void *buffer);
02154 #endif
02155
02156 public:
02164 void update(unsigned char port=0xff);
02165
02166 protected:
02174 unsigned char fetch(timeout_t timeout);
02175
02180 PortNotify();
02181 };
02182
02194 class __EXPORT EventBuffer : private Buffer
02195 {
02196 private:
02197 TrunkEvent *buffer;
02198
02199 #ifdef COMMON_64_CLEAN
02200 size_t head, tail;
02201 size_t onPeek(void *buffer);
02202 size_t onWait(void *buffer);
02203 size_t onPost(void *buffer);
02204 #else
02205 unsigned head, tail;
02206
02207 int onPeek(void *buffer);
02208 int onWait(void *buffer);
02209 int onPost(void *buffer);
02210 #endif
02211
02212 public:
02219 void update(TrunkEvent *event = NULL);
02220
02221 protected:
02230 void fetch(timeout_t timeout, TrunkEvent *event);
02231
02238 EventBuffer(unsigned count);
02239 };
02240
02248 class __EXPORT AudioBuffer : protected Mutex
02249 {
02250 public:
02251 AudioBuffer();
02252 ~AudioBuffer();
02253
02254 void getBuffer(char *data, unsigned amount);
02255 void putBuffer(const char *data, unsigned amount);
02256 private:
02257 char *buf;
02258 unsigned len;
02259 unsigned start;
02260 unsigned size;
02261 };
02262
02272 class __EXPORT Trunk : public ScriptInterp
02273 {
02274 public:
02275 class __EXPORT Threaded : public ScriptModule
02276 {
02277 protected:
02278 Threaded(const char *id);
02279 public:
02280 virtual Service *getService(Trunk *trunk, Line *line, trunkdata_t *data) = 0;
02281 virtual timeout_t getTimeout(Trunk *trunk, trunkdata_t *data)
02282 {return data->sleep.wakeup;};
02283 };
02284
02285 class __EXPORT Database : protected Threaded, protected ScriptData, protected Keydata
02286 {
02287 public:
02288 Database();
02289 virtual bool header(ScriptInterp *interp) = 0;
02290 char *parseScript(ScriptInterp *interp, Line *line);
02291 void moduleAttach(ScriptInterp *interp);
02292 bool isId(const char *id);
02293 timeout_t getTimeout(Trunk *trunk, trunkdata_t *data);
02294 };
02295
02296 private:
02297 friend class Request;
02298 friend class Route;
02299 friend class ThreadModule;
02300 friend class MappedCalls;
02301 friend class aaScript;
02302 friend class Translator;
02303 friend class ScriptInterface;
02304 friend class Service;
02305 friend class AudioService;
02306 friend class Fifo;
02307 friend class Driver;
02308 friend class TrunkGroup;
02309
02310 typedef union
02311 {
02312 Symbol sym;
02313 char data[sizeof(Symbol) + 12];
02314 } Number;
02315
02316 typedef union
02317 {
02318 Symbol bin;
02319 char data[sizeof(Symbol) + MAX_DIGITS];
02320 } Digit;
02321
02322 char _dbgname[33];
02323 const char *_genName(Driver *drv, int port);
02324
02325 protected:
02326
02327 const char *volatile trunkgid;
02328 UsageStat *use;
02329 static char status[];
02330 phTone *tonetmp;
02331 int tsid;
02332 static struct callrec_t *callrec;
02333 Trunk *ctx;
02334
02335 void setAudioPosition(timeout_t pos);
02336 void incIncoming(void);
02337 void decIncoming(void);
02338 void incOutgoing(void);
02339 void decOutgoing(void);
02340 void setUsage(UsageStat *us);
02341
02342 public:
02343 bool scrThread(void);
02344
02345 private:
02346 unsigned member;
02347 char apppath[64];
02348
02349 bool scrSession(void);
02350 bool scrPolicy(void);
02351 bool scrConfig(void);
02352 bool scrSend(void);
02353 bool scrStart(void);
02354 bool scrLibexec(void);
02355 bool scrControl(void);
02356 bool scrHangup(void);
02357 bool scrDebug(void);
02358 bool scrAlog(void);
02359 bool scrAudit(void);
02360 bool scrSleep(void);
02361
02362 public:
02363 static bool hasDriver(ScriptInterp *interp, const char *v);
02364 static bool hasVoice(ScriptInterp *interp, const char *v);
02365 static bool hasAppVoice(ScriptInterp *interp, const char *v);
02366 static bool hasSysVoice(ScriptInterp *interp, const char *v);
02367 static bool hasAltVoice(ScriptInterp *interp, const char *v);
02368 static bool hasGroup(ScriptInterp *interp, const char *v);
02369 static bool hasPlugin(ScriptInterp *interp, const char *v);
02370 static bool hasSysPrompt(ScriptInterp *interp, const char *v);
02371 static bool hasVarPrompt(ScriptInterp *interp, const char *v);
02372 static bool isNode(ScriptInterp *interp, const char *v);
02373 static bool isService(ScriptInterp *interp, const char *v);
02374 static bool isSchedule(ScriptInterp *interp, const char *v);
02375 static bool ifDTMF(ScriptInterp *interp, const char *v);
02376 static bool ifFeature(ScriptInterp *interp, const char *v);
02377 static bool isExtension(ScriptInterp *interp, const char *v);
02378 static bool isStationPort(ScriptInterp *interp, const char *v);
02379 static bool isVirtual(ScriptInterp *interp, const char *v);
02380 static bool isHunt(ScriptInterp *interp, const char *v);
02381 static bool isActiveUser(ScriptInterp *interp, const char *v);
02382 static bool isDnd(ScriptInterp *interp, const char *v);
02383 static bool ifRinging(ScriptInterp *interp, const char *v);
02384 static bool ifRunning(ScriptInterp *interp, const char *v);
02385 static bool ifPort(ScriptInterp *interp, const char *v);
02386
02387 protected:
02388 bool scrCommit(void);
02389 bool scrChange(void);
02390 bool scrPassword(void);
02391 bool scrLogin(void);
02392 bool scrLogout(void);
02393 bool scrSync(void);
02394 bool scrAnswer(void);
02395 bool scrDial(void);
02396 bool scrTransfer(void);
02397 bool scrHold(void);
02398 bool scrOptions(void);
02399 bool scrRoute(void);
02400
02401 private:
02402 bool scrTone(void);
02403 bool scrAccept(void);
02404 bool scrReject(void);
02405 bool scrCollect(void);
02406 bool scrFlash(void);
02407 bool scrEcho(void);
02408 bool scrSlog(void);
02409 bool scrSay(void);
02410 bool scrAsr(void);
02411 bool scrListen(void);
02412 bool scrAssign(void);
02413 bool scrAltPlay(void);
02414 bool scrAltSpeak(void);
02415 bool scrPlay(void);
02416 bool scrSendFax(void);
02417 bool scrRecvFax(void);
02418 bool scrExiting(void);
02419 bool scrCount(void);
02420 bool scrScan(void);
02421 bool scrCopy(void);
02422 bool scrBuild(void);
02423 bool scrCreate(void);
02424 bool scrDelete(void);
02425 bool scrMove(void);
02426 bool scrErase(void);
02427 bool scrRecord(void);
02428 bool scrSpeak(void);
02429 bool scrDummy(void);
02430 bool scrSchedule(void);
02431 bool scrSignal(void);
02432 bool scrIdle(void);
02433 bool scrBusy(void);
02434 bool scrExamine(void);
02435 bool scrService(void);
02436 bool scrUserinfo(void);
02437 bool scrHuntinfo(void);
02438 bool scrStatinfo(void);
02439 bool scrConference(void);
02440 bool scrEnter(void);
02441 bool scrRelease(void);
02442 bool scrJoin(void);
02443 bool scrWait(void);
02444 bool scrRing(void);
02445 bool scrPickup(void);
02446 bool altDial(void);
02447
02448 protected:
02449
02450 void setExclusive(bool enable)
02451 {globals.setExclusive(enable);};
02452
02453 Number numbers[6];
02454 static ScriptSymbol globals;
02455 static char digit[16];
02456 ScriptInterface *script;
02457 TrunkGroup *group;
02458 int id;
02459 unsigned spanid, cardid;
02460 time_t starttime, idletime, synctimer, exittimer;
02461
02462 int exitfd;
02463 char exitmsg[128];
02464 volatile unsigned seq;
02465 int idle_timer;
02466 unsigned rings, digits, counts;
02467
02468 Driver *driver;
02469
02470 public:
02471 AudioBuffer *softJoin;
02472 unsigned long eventmask;
02473
02474 protected:
02475 Trunk *joined;
02476
02477 Service *thread;
02478 trunkdata_t data;
02479 execdata_t tgi;
02480 Digit dtmf;
02481 char buffer[65];
02482
02483 struct
02484 {
02485 bool offhook: 1;
02486 bool dtmf: 1;
02487 bool script: 1;
02488 bool reset: 1;
02489 bool timer : 1;
02490 bool audio: 1;
02491 bool once : 1;
02492 bool ready : 1;
02493 bool echo : 1;
02494 unsigned onexit : 1;
02495 trunkmode_t trunk: 2;
02496 dspmode_t dsp: 4;
02497 bool dnd : 1;
02498 bool cid : 1;
02499 bool sent : 1;
02500 bool listen : 1;
02501 bool bgm : 1;
02502 } flags;
02503
02507 void setIdle(bool mode);
02508
02512 virtual void initSyms(void) = 0;
02513
02519 unsigned long getTrapDefault(void)
02520 {return 0x00000007;};
02521
02528 void repSymbol(const char *id, const char *data);
02529
02530 public:
02536 inline int getExitFd(void)
02537 {return exitfd;};
02538
02539 void clearExitFd(void);
02540
02546 inline const char *getTrunkGid(void)
02547 {return trunkgid;};
02548
02556 Symbol *getEntry(const char *symname, unsigned size);
02557
02563 void commit(Symbol *sym);
02564
02570 void cleardigits(bool all);
02571
02577 char getdigit(void);
02578
02586 bool getExitkey(unsigned short mask, unsigned keycode);
02587
02591 void setExitkey(void);
02592
02593 bool isStation, isRinging;
02594
02598 bool isAdmin(void);
02599
02605 const char *getStation(void);
02606
02616 timeout_t getTimeout(const char *keyword = NULL);
02617
02624 timeout_t getInterdigit(const char *keyword = NULL);
02625
02631 unsigned short getDigitMask(const char *keyword = NULL);
02632
02639 bool hasExitMask(unsigned short mask);
02640
02646 unsigned short getExitMask(void);
02647
02653 bool trunkSignal(trunksignal_t);
02654
02660 void trunkError(const char *errmsg = NULL);
02661
02668 bool event(const char *event, bool inheret = true);
02669
02670 protected:
02677 void dialRewrite(const char *dialstring);
02678
02685 virtual void setDTMFDetect(void);
02686
02695 virtual void setDTMFDetect(bool enable)
02696 {flags.dtmf = enable;};
02697
02703 virtual void stopServices(void);
02704
02715 virtual void trunkStep(trunkstep_t step) = 0;
02716
02722 bool idleHangup();
02723
02730 virtual unsigned long getIdleTime(void) = 0;
02731
02732 public:
02738 const char *getPrefixPath(void);
02739
02740 protected:
02744 inline bool scriptStep(void)
02745 {return ScriptInterp::step();};
02746
02755 bool attach(const char *scrname);
02756
02761 void initialize(void);
02762
02767 void detach(void);
02768
02775 char **getInitial(char **args);
02776
02783 void setList(char **list);
02784
02788 virtual void accept(void)
02789 {return;};
02790
02794 virtual const char *getLibexec(void)
02795 {return ".au";};
02796
02801 virtual bool setListen(bool on)
02802 {return false;};
02803
02807 virtual bool setBMG(bool on)
02808 {return false;};
02809
02810 public:
02814 virtual const char *getDefaultEncoding(void)
02815 {return "ulaw";};
02816
02820 static const char *getEncodingName(Audio::Encoding e);
02821
02822 protected:
02826 virtual void reject(void)
02827 {return;};
02828
02832 void enterState(const char *state);
02833
02834 Trunk(int port, Driver *drv, int card = 0, int span = 0);
02835
02836 ~Trunk();
02837 public:
02843 unsigned getId(void)
02844 {return id;};
02850 inline unsigned getSequence(void)
02851 {return seq;};
02852
02853 inline Driver *getDriver(void)
02854 {return driver;};
02855
02861 inline void setSave(const char *save)
02862 {data.sleep.save = save;};
02863
02869 virtual unsigned long getCapabilities(void)
02870 {return TRUNK_CAP_VOICE | TRUNK_CAP_DIAL;};
02871
02877 static inline ScriptSymbol *getGlobals(void)
02878 {return &globals;};
02879
02880
02886 virtual void getName(char *buffer) = 0;
02887
02895 virtual bool postEvent(TrunkEvent *event) = 0;
02896
02897 protected:
02904 bool recvEvent(TrunkEvent *event);
02905
02911 bool syncParent(const char *msg);
02912
02918 void setCalls(const char *mode);
02919
02927 void setField(char *field, const char *str, unsigned len);
02928
02929 public:
02935 int getDigit(char digit);
02936
02942 bool isReady(void);
02943
02944 #ifdef HAVE_TGI
02945
02952 void libtts(const char *msg, ttsmode_t mode);
02953
02964 bool librun(const char *prog, timeout_t timeout = 0, const char
02965 *query = "", const char *voice = NULL, const char *ext = NULL,
02966 const char *lang = NULL);
02967 #endif
02968
02972 inline bool getOnce(void)
02973 {return ScriptInterp::getOnce();};
02974
02980 inline unsigned getMemberId(void)
02981 {return member;};
02982
02988 phTone *getTone(void);
02989
02995 inline ScriptCommand *getCommand(void)
02996 {return ScriptInterp::getCommand();};
02997
03003 inline trunkmode_t getTrunkMode(void)
03004 {return flags.trunk;};
03005
03006 inline Trunk *getJoined(void)
03007 {return joined;};
03008
03009 inline void setJoined(Trunk *trk)
03010 {joined = trk;};
03011 };
03012
03022 class __EXPORT Fifo : public Mutex, public Script
03023 {
03024 private:
03025 int fd;
03026 Thread *main;
03027
03028 protected:
03029 char schedule[33];
03030
03031 Trunk *logResult(char **args);
03032 Trunk *assignRing(char **args);
03033 Trunk *assignDial(char **args);
03034 Trunk *sendEvent(char **args);
03035 Trunk *clearRing(char **args);
03036 Trunk *clearDial(char **args);
03037 Trunk *clearRDGroup(char **args);
03038 Trunk *exitPid(char **args);
03039 Trunk *waitPid(char **args);
03040 Trunk *setSymbol(char **argv);
03041 Trunk *putSymbol(char **argv);
03042 Trunk *setGlobal(char **argv);
03043 Trunk *addSymbol(char **argv);
03044 Trunk *setSize(char **argv);
03045 Trunk *addRoute(char **argv);
03046 Trunk *delRoute(char **argv);
03047
03048 Trunk *login(char **argv);
03049 Trunk *runScript(char **argv);
03050 Trunk *startScript(char **argv, bool lock = false);
03051 Trunk *testScript(char **argv);
03052 Trunk *ringScript(char **argv);
03053 Trunk *redirectScript(char **argv);
03054 Trunk *setSpan(char **argv);
03055 Trunk *setCard(char **argv);
03056 Trunk *busyLine(char **argv);
03057 Trunk *idleLine(char **argv);
03058 Trunk *hangupLine(char **argv);
03059 Trunk *reqScript(char **argv);
03060 Trunk *setSchedule(char **argv);
03061 Trunk *postKey(char **argv);
03062 Trunk *sync(char **argv);
03063 Trunk *setMixer(char **argv);
03064 Trunk *setLimit(char **argv);
03065 Trunk *mapFiles(char **argv);
03066 Trunk *submit(char **argv);
03067 Trunk *reload(char **argv);
03068 Trunk *saveId(char **argv);
03069 Trunk *createId(char **argv);
03070 Trunk *deleteId(char **argv);
03071 Trunk *shellStart(char **argv);
03072 Trunk *stop(char **argv);
03073 Trunk *collectCmd(char **argv);
03074 Trunk *optionCmd(char **argv);
03075 Trunk *getSymbol(char **argv);
03076 Trunk *run(char **argv);
03077 Trunk *asr(char **argv);
03078 Trunk *text(char **argv);
03079 Trunk *notify(char **argv);
03080 Trunk *attach(char **argv);
03081 Trunk *detach(char **argv);
03082
03083 public:
03092 Trunk *command(const char *cmdstring, std::ostream *fd = NULL);
03093
03099 void setControl(int fd);
03100
03101 void control(const char *ctrl);
03102
03103 Fifo();
03104 };
03105
03106 #define MAX_SPANS 64
03107 #define MAX_CARDS 64
03108
03116 class __EXPORT Driver : public Mutex
03117 {
03118 protected:
03119 friend class TrunkGroup;
03120 friend class Trunk;
03121 friend class MappedDrivers;
03122 friend class Conference;
03123
03124 Conference *first, *last;
03125 bool active;
03126 unsigned portCount, downCount;
03127 volatile unsigned idleCount;
03128 AtomicCounter refTimer;
03129 time_t nextTimer;
03130
03131 unsigned tsid;
03132 int index;
03133
03134 inline Driver *getFirst(void)
03135 {return drvFirst;};
03136
03137 virtual Conference *getConference(const char *id, unsigned size = 0)
03138 {return NULL;};
03139
03140 public:
03141 friend __EXPORT Driver *getDriver(const char *name);
03142 static Driver *drvFirst;
03143 static unsigned drvIndex;
03144 Driver *drvNext;
03145 static void setNodes();
03146
03147 enum { capDaemon = 0x0001,
03148 capPSTN = 0x0002,
03149 capJoin = 0x00004,
03150 capSpans = 0x0008,
03151 capSpeed = 0x0010,
03152 capPitch = 0x0020,
03153 capGain = 0x0040,
03154 capListen = 0x0080,
03155 capIP = 0x00160,
03156 capDynamic = 0x1000,
03157 capSwitch = 0x2000,
03158 capConference = 0x4000,
03159 capOffline = 0x8000};
03160
03164 inline void ticTimer(void)
03165 {++refTimer;};
03166
03170 virtual void secTick(void);
03171
03175 virtual unsigned getCaps(void)
03176 {return capDaemon | capPSTN;};
03177
03181 Driver();
03182
03186 virtual char *getName(void)
03187 {return "Default";};
03188
03192 bool isIdle(void);
03193
03197 bool isDown(void);
03198
03205 virtual int start(void) = 0;
03206
03210 virtual void stop(void) = 0;
03211
03217 static void getStatus(char *buffer);
03218
03224 static unsigned getCount(void);
03225
03232 virtual aaImage *getImage(void);
03233
03240 virtual unsigned getTrunkCount(void) = 0;
03241
03248 virtual unsigned getTrunkUsed(void)
03249 {return getTrunkCount();};
03250
03258 int getTrunkMember(TrunkGroup *grp, unsigned member);
03259
03265 virtual Trunk *getTrunkPort(int id) = 0;
03266
03272 virtual bool isTrunkClass(int id, const char *name);
03273
03274 enum {
03275 TRUNK_URI = 0x0001,
03276 TRUNK_EXTENSION = 0x0002,
03277 TRUNK_GROUP = 0x0004,
03278 TRUNK_TIE = 0x0008,
03279 TRUNK_LOCAL = 0x0032,
03280 TRUNK_START = 0x0160
03281 };
03282
03283 static Trunk *getTrunk(const char *name, bool create = false,
03284 Driver *driver = NULL);
03285 static Driver *getIndexedDriver(int idx);
03286
03294 virtual Trunk *getOutboundTrunk(int id)
03295 { return getTrunkPort(id); };
03296
03303 Trunk *getTrunkId(const char *id);
03304
03312 virtual bool spanEvent(unsigned span, TrunkEvent *event);
03313
03323 virtual bool cardEvent(unsigned card, TrunkEvent *event)
03324 {return false;};
03325
03326 int getDriverIndex(void)
03327 {return index;};
03328 };
03329
03336 class __EXPORT Debug : protected Mutex, protected Script
03337 {
03338 public:
03342 Debug();
03343
03347 static void stackTrace(int signo);
03348
03354 virtual bool debugTrace(void)
03355 {return false;};
03356
03362 virtual bool debugFinal(int signo)
03363 {return false;};
03364
03368 virtual void debugEvent(Trunk *trunk, TrunkEvent *event)
03369 {return;};
03370
03374 virtual void debugState(Trunk *trunk, char *state)
03375 {return;};
03376
03380 virtual void debugService(Trunk *trunk, char *msg)
03381 {return;};
03382
03386 virtual void debugScript(Trunk *trunk, char *msg)
03387 {return;};
03388
03392 virtual void debugStep(Trunk *trunk, Line *line)
03393 {debugState(trunk, "step");};
03394
03398 virtual bool debugFifo(char **argv)
03399 {return true;};
03400
03404 virtual void debugLogin(Trunk *trunk)
03405 {return;};
03406 };
03407
03414 class __EXPORT AudioService
03415 {
03416 private:
03417 char filename[256];
03418
03419 protected:
03420 Trunk *trunk;
03427 char *getPrompt(char *name, const char *voice = NULL);
03428
03434 char *getPlayfile(void);
03435
03439 AudioService(void);
03440 };
03441
03449 class __EXPORT Service : public Semaphore, public Thread, public AudioService
03450 {
03451 protected:
03452 volatile bool stopped;
03453 trunkdata_t *data;
03454 TrunkGroup *group;
03455
03459 void success(void);
03460
03464 void failure(void);
03465
03469 inline void dspReset(void)
03470 {trunk->flags.reset = true;};
03471
03475 inline void setAudio(void)
03476 {trunk->flags.audio = true;};
03477
03481 inline void clrAudio(void)
03482 {trunk->flags.audio = false;};
03483
03484 public:
03491 Service(Trunk *trunk, int pri, size_t stack = keythreads.getStack());
03492
03499 virtual timeout_t stop(void);
03500
03508 virtual bool isExiting(void)
03509 {return true;};
03510
03514 void endService(void)
03515 {terminate();};
03516
03520 virtual ~Service()
03521 {terminate();}
03522 };
03523
03533 class __EXPORT Server : public Thread
03534 {
03535 private:
03536 static Server *first;
03537 Server *next;
03538 friend __EXPORT void startServers(void);
03539 friend __EXPORT void stopServers(void);
03540
03541 protected:
03542 Server(int pri);
03543
03547 virtual void stop(void)
03548 {terminate();};
03549 };
03550
03557 class __EXPORT Sync
03558 {
03559 private:
03560 static Sync *first;
03561 Sync *next;
03562 time_t runtime;
03563
03564 protected:
03568 Sync(void);
03569
03574 virtual bool isScheduled(void)
03575 {return true;};
03576
03581 virtual unsigned getInterval(void)
03582 {return 10;};
03583
03587 virtual void schedule(void) = 0;
03588
03592 virtual char *getSyncName(void) = 0;
03593
03594 public:
03595 static void check(void);
03596 };
03597
03606 class __EXPORT phTone
03607 {
03608 private:
03609 friend class KeyTones;
03610 friend __EXPORT phTone *getphTone(const char *name);
03611 static phTone *first;
03612 static int ulaw[256];
03613 static unsigned char alaw[256];
03614 static unsigned char a2u[128];
03615 phTone *next;
03616
03617 protected:
03618 char name[33];
03619 unsigned char *samples;
03620 timeout_t duration, playtime;
03621 unsigned freq1, freq2;
03622
03623 public:
03624 static unsigned char linear2ulaw(int sample);
03625 static inline unsigned char linear2alaw(int sample)
03626 {return alaw[linear2ulaw(sample)];};
03627
03628 static unsigned char alaw2ulaw(unsigned char al);
03629
03630 static inline unsigned char ulaw2alaw(unsigned char ul)
03631 {return alaw[ul];};
03632
03633 static short ulaw2linear(unsigned char ul);
03634 static short alaw2linear(unsigned char al);
03635
03643 phTone(const char *name, timeout_t duration, unsigned f);
03644
03653 phTone(const char *name, timeout_t duration, unsigned f1, unsigned f2);
03654
03655 ~phTone();
03656
03662 void clear(void);
03663
03669 inline unsigned char *getSamples(void)
03670 {return samples;};
03671
03677 inline timeout_t getDuration(void)
03678 {return duration;};
03679
03685 inline timeout_t getPlaytime(void)
03686 {return playtime;};
03687 };
03688
03695 class __EXPORT TGI
03696 {
03697 private:
03698 static TGI *first;
03699 TGI *next;
03700
03701 protected:
03702 TGI();
03703
03711 virtual bool getExtension(const char *ext)
03712 {return false;};
03713
03714 public:
03724 virtual void script(char *cmd, char **args)
03725 {return;};
03726
03735 virtual int parse(int fd, char port[64], char *cmd)
03736 {return -1;};
03737
03738 friend __EXPORT void getInterp(char *cmd, char **args);
03739 friend __EXPORT TGI *getInterp(char *cmd);
03740 };
03741
03747 class __EXPORT TTS
03748 {
03749 protected:
03750 friend class Plugins;
03751
03752 TTS();
03753
03754 public:
03755 virtual const char *getName(void) = 0;
03756
03757 virtual const char *getVoices(void)
03758 {return "none";};
03759
03760 virtual bool synth(unsigned id, trunkdata_t *data) = 0;
03761
03762 friend TTS *getTTS(const char *name);
03763 static TTS *ttsFirst;
03764 TTS *ttsNext;
03765 };
03766
03767
03777 class __EXPORT Session
03778 {
03779 private:
03780 static Mutex mutex;
03781 static Session *first;
03782 static Session *last;
03783 Session *next, *prev;
03784
03785 public:
03786 static void clean(void);
03787
03788 protected:
03789 Session();
03790 virtual ~Session()
03791 {unlink();};
03792
03796 void unlink(void);
03797
03804 virtual time_t getExpires(void) = 0;
03805 };
03806
03807 __EXPORT void setReply(const char *sym, const char *value);
03808 __EXPORT void errlog(const char *level, const char *fmt, ...);
03809 __EXPORT statnode_t *getNodes(const char *name);
03810 __EXPORT bool hasTTS(void);
03811 __EXPORT bool permitAudioAccess(const char *path, bool write);
03812 __EXPORT bool permitFileAccess(const char *path);
03813 __EXPORT void initScripting(void);
03814
03815 extern __EXPORT unsigned numbering;
03816 extern __EXPORT bool aliases;
03817 extern __EXPORT bool running;
03818 extern __EXPORT KeyServer keyserver;
03819 extern __EXPORT KeyThreads keythreads;
03820 extern __EXPORT KeyMemory keymemory;
03821 extern __EXPORT KeyPaths keypaths;
03822 extern __EXPORT KeyVoices keyvoices;
03823 extern __EXPORT KeyLocal keylocal;
03824 extern __EXPORT KeyNetwork keynetwork;
03825 extern __EXPORT KeyProxy keyproxy;
03826 extern __EXPORT Plugins plugins;
03827
03828 extern __EXPORT Debug *debug;
03829 extern __EXPORT Fifo fifo;
03830 extern __EXPORT ThreadLock cachelock;
03831 extern __EXPORT aaScript *aascript;
03832
03833 #ifdef CCXX_NAMESPACES
03834 }
03835 #endif
03836
03837 #endif