bayonne.h

Go to the documentation of this file.
00001 // Copyright (C) 2005 Open Source Telecom Corp.
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 // 
00017 // As a special exception, you may use this file as part of a free software
00018 // library without restriction.  Specifically, if other files instantiate
00019 // templates or use macros or inline functions from this file, or you compile
00020 // this file and link it with other files to produce an executable, this
00021 // file does not by itself cause the resulting executable to be covered by
00022 // the GNU General Public License.  This exception does not however
00023 // invalidate any other reasons why the executable file might be covered by
00024 // the GNU General Public License.
00025 //
00026 // This exception applies only to the code released under the name GNU
00027 // ccScript.  If you copy code from other releases into a copy of GNU
00028 // ccScript, as the General Public License permits, the exception does
00029 // not apply to the code that you add in this way.  To avoid misleading
00030 // anyone as to the status of such modified files, you must delete
00031 // this exception notice from them.
00032 //
00033 // If you write modifications of your own for GNU ccScript, it is your choice
00034 // whether to permit this exception to apply to your modifications.
00035 // If you do not wish that, delete this exception notice.
00036 //
00037 
00038 #ifndef CCXX_BAYONNE_H_
00039 #define CCXX_BAYONNE_H_
00040 
00041 #ifndef CCXX_SCRIPT3_H_
00042 #include <cc++/script3.h>
00043 #endif
00044 
00045 #ifndef CCXX_CCAUDIO2_H_
00046 #include <cc++/audio2.h>
00047 #endif
00048 
00049 #ifndef CCXX_SOCKET_H_
00050 #include <cc++/socket.h>
00051 #endif
00052 
00053 #define BAYONNE_RELEASE 1               // release check sequence
00054 #define NO_TIMESLOT     0xffff
00055 #define MAX_DTMF        32
00056 #define MAX_LIST        256
00057 #define MAX_LIBINPUT    256
00058 #define MAX_PATHNAME    256
00059 #define MIN_AUDIOFEED   (120 * 8)       // 120 millisecond starting
00060 #define MAX_AUDIOFEED   (600 * 8)       // 600 millisecond buffer
00061 #define RPC_MAX_PARAMS  96
00062 
00063 #ifdef  WIN32
00064 #define PFD_INVALID     INVALID_HANDLE_VALUE
00065 #else
00066 #define PFD_INVALID     -1
00067 #endif
00068 
00069 #if SCRIPT_RIPPLE_LEVEL < 2
00070 #error "ccscript 3 0.8.0 or later required"
00071 #endif
00072 
00073 #ifdef  DEBUG
00074 #define SLOG_DEBUG(x, ...)      slog.debug(x, __VA_ARGS__)
00075 #else
00076 #define SLOG_DEBUG(x, ...)
00077 #endif
00078 
00079 namespace ost {
00080 
00081 class __EXPORT BayonneMsgport;
00082 class __EXPORT BayonneDriver;
00083 class __EXPORT BayonneSession;
00084 class __EXPORT BayonneSpan;
00085 class __EXPORT BayonneService;
00086 class __EXPORT BayonneTranslator;
00087 class __EXPORT BayonneRPC;
00088 class __EXPORT ScriptEngine;
00089 
00096 class __EXPORT StreamingBuffer : public Audio
00097 {
00098 private:
00099         static StreamingBuffer *first;
00100         StreamingBuffer *next;
00101         const char *id;
00102         Rate rate;
00103 
00104 protected:
00105         unsigned long position, count;
00106         Linear data;
00107 
00108         void cleanup();
00109 
00110         StreamingBuffer(const char *id, timeout_t size = 600, Rate rate = rate8khz);
00111         virtual ~StreamingBuffer();
00112 
00113     virtual Linear putBuffer(timeout_t duration);
00114         virtual void clearBuffer(timeout_t duration);
00115 
00116 public:
00124         static StreamingBuffer *get(const char *id, Rate rate);
00125 
00131         virtual bool isActive(void);
00132 
00139         virtual unsigned long getPosition(timeout_t framing);
00140 
00148         virtual Linear getBuffer(unsigned long *mark, timeout_t duration);
00149 };
00150         
00151 
00159 class __EXPORT StaticKeydata : public Keydata
00160 {
00161 public:
00162         StaticKeydata(const char *path, Keydata::Define *defkeys = NULL, const char *homepath = NULL);
00163 
00164         inline const char *getString(const char *id)
00165                 {return getLast(id);};
00166 
00167         inline long getValue(const char *id)
00168                 {return getLong(id);};
00169 
00170         inline bool getBoolean(const char *id)
00171                 {return getBool(id);};
00172 };
00173 
00183 class __EXPORT DynamicKeydata : public ThreadLock
00184 {
00185 private:
00186         friend class __EXPORT BayonneConfig;
00187         friend class __EXPORT ReconfigKeydata;
00188         static DynamicKeydata *firstConfig;
00189         DynamicKeydata *nextConfig;
00190         const char *keypath;
00191         const char *homepath;
00192         Keydata *keys;
00193         Keydata::Define *defkeys;
00194         void loadConfig(void);
00195 
00196 protected:
00197         virtual void updateConfig(Keydata *keydata);
00198 
00199 public:
00200         DynamicKeydata(const char *keypath, Keydata::Define *def = NULL, const char *homepath = NULL);
00201 
00202         const char *getString(const char *key, char *buf, size_t size);
00203         long getValue(const char *key);
00204         bool isKey(const char *key);
00205         bool getBoolean(const char *key);
00206 
00207         static void reload(void);
00208 };
00209 
00218 class __EXPORT ReconfigKeydata : public StaticKeydata, protected DynamicKeydata
00219 {
00220 protected:
00221         // use only in updateConfig method...
00222         const char *updatedString(const char *id);
00223         long updatedValue(const char *id);
00224         timeout_t updatedSecTimer(const char *id);
00225         timeout_t updatedMsecTimer(const char *id);
00226         bool updatedBoolean(const char *id);
00227 
00228 public:
00229         inline const char *getInitial(const char *id)
00230                 {return StaticKeydata::getString(id);};
00231         inline void setInitial(const char *id, const char *val)
00232                 {StaticKeydata::setValue(id, val);};
00233 
00234         ReconfigKeydata(const char *keypath, Keydata::Define *def = NULL);
00235 
00236         const char *getString(const char *key, char *buf, size_t size);
00237         timeout_t getSecTimer(const char *key);
00238         timeout_t getMsecTimer(const char *key);
00239         long getValue(const char *key);
00240         bool isKey(const char *key);
00241         bool getBoolean(const char *key);
00242 };
00243           
00251 class __EXPORT Bayonne : public Script
00252 {
00253 private:
00254         static SOCKET trap_so4;
00255         static unsigned trap_count4;
00256         static struct sockaddr_in trap_addr4[8];
00257 
00258 #ifdef  CCXX_IPV6
00259         static SOCKET trap_so6;
00260         static unsigned trap_count6;
00261         static struct sockaddr_in6 trap_addr6[8];
00262 #endif
00263 
00264 public:
00265         static char dtmf_keymap[256];
00266 
00267         static void snmptrap(unsigned id, const char *descr = NULL);
00268 
00269 #ifdef  WIN32
00270         typedef WORD    timeslot_t;
00271         typedef DWORD   rpcint_t;
00272 #else
00273         typedef uint16_t timeslot_t;
00274         typedef int32_t rpcint_t;
00275 #endif
00276         typedef rpcint_t rpcbool_t;
00277 
00278 protected:
00279         static BayonneSession **timeslots;
00280         static ScriptImage **localimages;
00281         static char *status;
00282         static ScriptCommand *server;
00283         static unsigned ts_trk;
00284         static unsigned ts_ext;
00285         static timeslot_t ts_limit;
00286         static timeslot_t ts_count;
00287         static timeslot_t ts_used;
00288         static std::ostream *logging;
00289         static const char *path_prompts;
00290         static const char *path_tmpfs;
00291         static const char *path_tmp;
00292         static unsigned idle_count;
00293         static unsigned idle_limit;
00294         static bool shutdown_flag;
00295         static char sla[64];
00296         static time_t start_time;
00297         static time_t reload_time;
00298 
00299 public:
00300         static timeout_t step_timer;
00301         static timeout_t reset_timer;
00302         static timeout_t exec_timer;
00303         static unsigned compile_count;
00304         static volatile bool image_loaded;
00305 
00306         static BayonneTranslator *init_translator;
00307         static const char *init_voicelib;
00308         static const char *trap_community;
00309         static AtomicCounter libexec_count;
00310 
00314         typedef enum
00315         {
00316                 IF_PSTN,
00317                 IF_SPAN,
00318                 IF_ISDN,
00319                 IF_SS7,
00320                 IF_INET,
00321                 IF_NONE,
00322                 IF_POTS=IF_PSTN
00323         }       interface_t;
00324 
00328         typedef enum
00329         {
00330                 NONE,           /* idle */
00331                 INCOMING,       /* inbound call */
00332                 OUTGOING,       /* outbound call */
00333                 PICKUP,         /* station pickup */
00334                 FORWARDED,      /* inbound forwarded call */
00335                 RECALL,         /* inbound hold recall */
00336                 DIRECT,         /* node/endpoint direct */
00337                 RINGING,        /* ringing incoming join */
00338                 VIRTUAL         /* virtual channel driver */
00339         }       calltype_t;
00340 
00344         typedef enum
00345         {
00346                 BR_TDM,
00347                 BR_INET,
00348                 BR_SOFT,
00349                 BR_GATE,
00350                 BR_NONE
00351         }       bridge_t;
00352 
00358         typedef enum
00359         {
00360                 STATE_INITIAL = 0,
00361                 STATE_IDLE,
00362                 STATE_RESET,
00363                 STATE_RELEASE,
00364                 STATE_BUSY,
00365                 STATE_DOWN,
00366                 STATE_RING,
00367                 STATE_PICKUP,
00368                 STATE_SEIZE,
00369                 STATE_ANSWER,
00370                 STATE_STEP,
00371                 STATE_EXEC,
00372                 STATE_THREAD,
00373                 STATE_CLEAR,
00374                 STATE_INKEY,
00375                 STATE_INPUT,
00376                 STATE_READ,
00377                 STATE_COLLECT,
00378                 STATE_DIAL,
00379                 STATE_XFER,
00380                 STATE_REFER,
00381                 STATE_HOLD,
00382                 STATE_RECALL,
00383                 STATE_TONE,
00384                 STATE_DTMF,
00385                 STATE_PLAY,
00386                 STATE_RECORD,
00387                 STATE_JOIN,
00388                 STATE_WAIT,
00389                 STATE_CALLING,
00390                 STATE_CONNECT,
00391                 STATE_RECONNECT,
00392                 STATE_HUNTING,
00393                 STATE_SLEEP,
00394                 STATE_START,
00395                 STATE_HANGUP,
00396                 STATE_LIBRESET,
00397                 STATE_WAITKEY,
00398                 STATE_LIBWAIT,
00399                 STATE_IRESET,
00400                 STATE_FINAL,
00401 
00402                 STATE_SUSPEND = STATE_DOWN,
00403                 STATE_STANDBY = STATE_DOWN,
00404                 STATE_LIBEXEC = STATE_EXEC,
00405                 STATE_RINGING = STATE_RING,
00406                 STATE_RUNNING = STATE_STEP,
00407                 STATE_THREADING = STATE_THREAD
00408         } state_t;
00409 
00414         typedef enum
00415         {
00416                 SIGNAL_EXIT = 0,
00417                 SIGNAL_ERROR,
00418                 SIGNAL_TIMEOUT,
00419                 SIGNAL_DTMF,
00420         
00421                 SIGNAL_0,
00422                 SIGNAL_1,
00423                 SIGNAL_2,
00424                 SIGNAL_3,
00425                 SIGNAL_4,
00426                 SIGNAL_5,
00427                 SIGNAL_6,
00428                 SIGNAL_7,
00429                 SIGNAL_8,
00430                 SIGNAL_9,
00431                 SIGNAL_STAR,
00432                 SIGNAL_POUND,
00433                 SIGNAL_A,
00434                 SIGNAL_OVERRIDE = SIGNAL_A,
00435                 SIGNAL_B,
00436                 SIGNAL_FLASH = SIGNAL_B,
00437                 SIGNAL_C,
00438                 SIGNAL_IMMEDIATE = SIGNAL_C,
00439                 SIGNAL_D,
00440                 SIGNAL_PRIORITY = SIGNAL_D,
00441 
00442                 SIGNAL_RING,
00443                 SIGNAL_TONE,
00444                 SIGNAL_EVENT,
00445                 SIGNAL_WINK,
00446 
00447                 SIGNAL_CHILD,
00448                 SIGNAL_FAIL,
00449                 SIGNAL_PICKUP,
00450                 SIGNAL_PART,
00451 
00452                 SIGNAL_INVALID,
00453                 SIGNAL_PARENT,
00454                 SIGNAL_WAIT,
00455 
00456                 SIGNAL_HANGUP = SIGNAL_EXIT
00457         } signal_t;
00458 
00464         typedef enum 
00465         {
00466                 // msgport management events, server control...
00467 
00468                 MSGPORT_WAKEUP = 0,     // wakeup a waiting message port
00469                 MSGPORT_SHUTDOWN,       // notify msgport of server shutdown
00470                 MSGPORT_LOGGING,        // enable driver event logging
00471                 MSGPORT_REGISTER,       // update registrations
00472 
00473                 // primary event identifiers
00474 
00475                 ENTER_STATE = 100,      // newly entered state handler
00476                 EXIT_STATE,
00477                 EXIT_THREAD,            // thread death notify
00478                 EXIT_TIMER,             // timer notified exit
00479                 EXIT_PARTING,           // exit a join...
00480                 NULL_EVENT,             // generic null event pusher
00481                 ERROR_STATE,            // generic enter with error
00482                 ENTER_HUNTING,
00483                 EXIT_HUNTING,
00484                 ENTER_RECONNECT,
00485                 EXIT_RECONNECT,
00486                 RECALL_RECONNECT,
00487                 EXIT_SCRIPT,
00488                 STEP_SCRIPT,
00489 
00490                 // primary session control events
00491 
00492                 START_DIRECT = 200,     // start a script, directed
00493                 START_INCOMING,         // start an incoming script
00494                 START_OUTGOING,         // start selected script, outbound
00495                 START_RECALL,           // start a recalled call
00496                 START_FORWARDED,        // start a forwarded call
00497                 START_RINGING,          // start a ringing call
00498                 START_HUNTING,          // start a hunting call
00499                 START_REFER,            // start a refer session
00500                 STOP_SCRIPT,
00501                 STOP_DISCONNECT,
00502                 STOP_PARENT,
00503                 CANCEL_CHILD,
00504                 DETACH_CHILD,
00505                 CHILD_RUNNING,
00506                 CHILD_FAILED,
00507                 CHILD_INVALID,
00508                 CHILD_EXPIRED,
00509                 CHILD_BUSY,
00510                 CHILD_FAX,
00511                 CHILD_DND,
00512                 CHILD_AWAY,
00513                 CHILD_NOCODEC,
00514                 CHILD_OFFLINE,
00515 
00516                 START_SCRIPT = START_INCOMING,
00517                 START_SELECTED = START_OUTGOING,
00518                 START_TRANSFER = START_REFER,
00519 
00520                 // libexec specific events
00521 
00522                 ENTER_LIBEXEC = 300,
00523                 EXIT_LIBEXEC,
00524                 HEAD_LIBEXEC,
00525                 ARGS_LIBEXEC,
00526                 GOT_LIBEXEC,
00527                 READ_LIBEXEC,
00528                 DROP_LIBEXEC,
00529                 STAT_LIBEXEC,
00530                 PROMPT_LIBEXEC,
00531                 CLEAR_LIBEXEC,
00532                 WAIT_LIBEXEC,
00533                 RECORD_LIBEXEC,
00534                 REPLAY_LIBEXEC,
00535                 RESTART_LIBEXEC,
00536                 TONE_LIBEXEC,
00537                 XFER_LIBEXEC,
00538                 POST_LIBEXEC,
00539                 ERROR_LIBEXEC,
00540 
00541                 // primary driver events
00542 
00543                 TIMER_EXPIRED = 400,    // trunk timer expired
00544                 LINE_WINK,
00545                 LINE_PICKUP,
00546                 LINE_HANGUP,
00547                 LINE_DISCONNECT,
00548                 LINE_ON_HOOK,
00549                 LINE_OFF_HOOK,
00550                 RING_ON,
00551                 RING_OFF,
00552                 RING_STOP,
00553                 LINE_CALLER_ID,
00554                 RINGING_DID,
00555                 DEVICE_BLOCKED,
00556                 DEVICE_UNBLOCKED,
00557                 DEVICE_OPEN,
00558                 DEVICE_CLOSE,
00559                 DSP_READY,
00560                 RING_SYNC,
00561 
00562                 // primary call processing events
00563 
00564                 CALL_DETECT = 500,
00565                 CALL_CONNECTED,
00566                 CALL_RELEASED,
00567                 CALL_ACCEPTED,
00568                 CALL_ANSWERED,
00569                 CALL_HOLD,
00570                 CALL_HOLDING=CALL_HOLD,
00571                 CALL_NOHOLD,
00572                 CALL_DIGITS,
00573                 CALL_OFFERED,
00574                 CALL_ANI,
00575                 CALL_ACTIVE,
00576                 CALL_NOACTIVE,
00577                 CALL_BILLING,
00578                 CALL_RESTART,
00579                 CALL_SETSTATE,
00580                 CALL_FAILURE,
00581                 CALL_ALERTING,
00582                 CALL_INFO,
00583                 CALL_BUSY,
00584                 CALL_DIVERT,
00585                 CALL_FACILITY,
00586                 CALL_FRAME,
00587                 CALL_NOTIFY,
00588                 CALL_NSI,
00589                 CALL_RINGING,
00590                 CALL_DISCONNECT,
00591                 CALL_CLEARED,
00592                 CALL_PROCEEDING,
00593                 RESTART_FAILED,
00594                 RELEASE_FAILED,
00595 
00596                 // some timeslot specific control and dial events
00597 
00598                 START_RING = 600,
00599                 STOP_RING,
00600                 CLEAR_TIMESLOT, // garbage collect
00601                 START_FLASH,
00602                 STOP_FLASH,
00603                 DIAL_CONNECT,
00604                 DIAL_TIMEOUT,
00605                 DIAL_FAILED,
00606                 DIAL_INVALID,
00607                 DIAL_BUSY,
00608                 DIAL_FAX,
00609                 DIAL_PAM,
00610                 DIAL_DND,
00611                 DIAL_AWAY,
00612                 DIAL_OFFLINE,
00613                 DIAL_NOCODEC,
00614 
00615                 DIAL_MACHINE = DIAL_PAM,
00616 
00617                 // basic audio stuff
00618 
00619                 AUDIO_IDLE = 700,
00620                 AUDIO_ACTIVE,
00621                 AUDIO_EXPIRED,
00622                 INPUT_PENDING,
00623                 OUTPUT_PENDING,
00624                 AUDIO_BUFFER,
00625                 TONE_IDLE,
00626                 DTMF_KEYDOWN,
00627                 DTMF_KEYSYNC,   /* timing sync event */
00628                 DTMF_KEYUP,
00629                 TONE_START,
00630                 TONE_STOP,
00631                 AUDIO_START,
00632                 AUDIO_STOP,
00633                 DTMF_GENDOWN,   /* peer */
00634                 DTMF_GENUP,     /* peer */
00635                 AUDIO_SYNC,     /* peer */
00636                 AUDIO_RECONNECT,        /* re-invite event... */
00637                 AUDIO_DISCONNECT,       /* audio holding re-invite */
00638                 PEER_RECONNECT,         /* peer re-invite notice */
00639                 PEER_DISCONNECT,        /* peer holding notice */
00640                 PEER_REFER,             /* referred by peer */
00641                 DTMF_GENTONE = DTMF_GENUP,
00642 
00643                 // make modes and special timeslot stuff
00644 
00645                 MAKE_TEST = 800,
00646                 MAKE_BUSY,
00647                 MAKE_IDLE,
00648                 MAKE_DOWN,
00649                 MAKE_UP,
00650                 MAKE_EXPIRED,
00651                 ENABLE_LOGGING,
00652                 DISABLE_LOGGING,
00653                 PART_EXPIRED,
00654                 PART_EXITING,
00655                 PART_DISCONNECT,
00656                 JOIN_PEER,
00657                 PEER_WAITING,
00658                 RELOCATE_REQUEST,       // queued event
00659                 RELOCATE_ACCEPT,        // hunting reply
00660                 RELOCATE_REJECT,        // a kind of disconnect
00661                 START_RELOCATE,         // start timeslot for relocation
00662                 STREAM_ACTIVE,
00663                 STREAM_PASSIVE,
00664                 JOIN_RECALL,
00665                 DROP_RECALL,
00666                 DROP_REFER,
00667 
00668                 // aliasing
00669 
00670                 ENTER_RESUME = MAKE_UP,
00671                 ENTER_SUSPEND = MAKE_DOWN, 
00672 
00673                 // master control events
00674 
00675                 SYSTEM_DOWN = 900,      
00676 
00677                 // driver specific events and anomalies
00678 
00679                 DRIVER_SPECIFIC = 1000  // oddball events
00680 
00681         } event_t;
00682 
00683         typedef enum
00684         {
00685                 RESULT_SUCCESS = 0,
00686                 RESULT_TIMEOUT,
00687                 RESULT_INVALID,
00688                 RESULT_PENDING,
00689                 RESULT_COMPLETE,
00690                 RESULT_FAILED,
00691                 RESULT_BADPATH = 254,
00692                 RESULT_OFFLINE = 255
00693         }       result_t;
00694 
00695         typedef struct
00696         {
00697                 Line line;
00698                 char text[MAX_LIBINPUT];
00699                 const char *list[MAX_LIBINPUT / 2];
00700         }       libaudio_t;
00701 
00702         typedef struct
00703         {
00704                 const char *remote;
00705                 const char *userid;
00706                 const char *type;
00707                 const char *status;
00708                 unsigned short active_calls, call_limit;
00709                 unsigned long attempts_iCount, attempts_oCount;
00710                 unsigned long complete_iCount, complete_oCount;
00711                 time_t updated;
00712         }       regauth_t;
00713 
00721         typedef struct
00722         {
00723                 event_t id;
00724                 timeslot_t timeslot;
00725                 uint16 seq;
00726 
00727                 union
00728                 {
00729                         // used to invoke attach.  The image refcount
00730                         // is assumed to already be inc'd!  If no
00731                         // scr is passed, then uses default or search
00732                         // vars passed in sym, value pairs
00733                         struct
00734                         {
00735                                 ScriptImage *img;
00736                                 Script::Name *scr;
00737                                 BayonneSession *parent;
00738                                 const char *dialing;
00739                         }       start;
00740 
00741                         struct
00742                         {
00743                                 ScriptImage *img;
00744                                 Script::Name *scr;
00745                                 BayonneSession *parent;
00746                                 Line *select;
00747                         }       hunt;
00748 
00749                         struct
00750                         {
00751                                 BayonneSession *current;
00752                                 BayonneSession *replace;
00753                         }       relocate;
00754 
00755                         struct
00756                         {
00757                                 const char *tid;
00758 #ifdef  WIN32
00759                                 HANDLE  pfd;
00760 #else
00761                                 const char *fname;
00762 #endif
00763                                 int pid, result;
00764                         }       libexec;
00765 
00766                         struct
00767                         {
00768                                 const char *tid;
00769                                 const char *errmsg;
00770                         }       liberror;
00771 
00772                         struct
00773                         {
00774                                 timeout_t duration;
00775                                 int digit;
00776                         }       dtmf;
00777 
00778                         struct
00779                         {
00780                                 const char *err;
00781                                 const char *msg;
00782                         }       cpa;
00783 
00784                         struct
00785                         {
00786                                 const char *name;
00787                                 bool exit;
00788                         }       tone;
00789 
00790                         struct
00791                         {
00792                                 std::ostream *output;
00793                                 const char *logstate;
00794                         }       debug;
00795 
00796                         struct
00797                         {
00798                                 const char *encoding;
00799                                 timeout_t framing;
00800                         }       reconnect;
00801 
00802                         const char *dialing;
00803                         const char *name;
00804                         const char *errmsg;
00805                         BayonneSession *pid;
00806                         BayonneSession *peer;
00807                         BayonneSession *child;
00808                         void *data;
00809                 };
00810 
00811         }       Event;
00812 
00816         class __EXPORT Ring
00817         {
00818         private:
00819                 static Mutex locker;
00820                 static Ring *free;
00821                 Ring *next;
00822 
00823                 Ring() {};
00824         public:
00825                 BayonneDriver *driver;
00826                 const char *ring_id;
00827                 unsigned count;
00828                 BayonneSession *session;
00829                 Script::Name *script;
00830 
00831                 static Ring *attach(BayonneDriver *d, const char *id, Ring *list);
00832                 static void detach(Ring *list);
00833                 static Ring *find(Ring *list, BayonneSession *s);
00834                 static void start(Ring *list, BayonneSession *s);
00835         };
00836 
00841         class __EXPORT Traffic
00842         {
00843         private:
00844                 static unsigned long stamp;
00845 
00846         public:
00847                 Traffic();
00848 
00849                 static inline unsigned long getStamp(void)
00850                         {return stamp;};
00851 
00852                 volatile unsigned long iCount, oCount;
00853         };
00854 
00858         typedef void (*rpcmethod_t)(BayonneRPC *rpc);
00859 
00863         typedef struct
00864         {
00865                 const char *name;
00866                 rpcmethod_t method;
00867                 const char *help;
00868                 const char *signature;
00869         }       RPCDefine;
00870 
00875         class __EXPORT RPCNode
00876         {
00877         private:
00878                 friend class __EXPORT BayonneRPC;
00879                 static RPCNode *first;
00880                 static unsigned count;
00881                 RPCNode *next;
00882                 RPCDefine *methods;
00883                 const char *prefix;
00884 
00885         public:
00886                 static inline RPCNode *getFirst(void)
00887                         {return first;};
00888 
00889                 inline RPCNode *getNext(void)
00890                         {return next;};
00891 
00892                 inline const char *getPrefix(void)
00893                         {return prefix;};
00894 
00895                 inline RPCDefine *getMethods(void)
00896                         {return methods;};
00897 
00898                 static inline unsigned getCount(void)
00899                         {return count;};
00900 
00901                 RPCNode(const char *prefix, RPCDefine *dispatch);
00902         };
00903 
00909         typedef bool (BayonneSession::*Handler)(Event *event);
00910 
00915         typedef struct
00916         {
00917                 const char *name;
00918                 Handler handler;
00919                 char flag;
00920         }       statetab;
00921 
00929         typedef struct
00930         {
00931                 Handler handler, logstate;
00932                 const char *name;
00933                 timeout_t timeout;
00934                 bool peering;
00935                 Name *menu;
00936                 unsigned stack;
00937                 Line *lib;
00938 #ifdef  WIN32
00939                 HANDLE pfd;
00940 #else
00941                 int pfd;
00942 #endif
00943                 result_t result;
00944                 int pid;
00945                 libaudio_t *libaudio;
00946                 bool refer;
00947 
00948                 union
00949                 {
00950                         struct
00951                         {
00952                                 unsigned count;
00953                                 timeout_t interval;
00954                         }       wait;
00955 
00956                         struct
00957                         {
00958                                 Audio::Mode mode;
00959                                 Audio::Level level;
00960                                 timeout_t total, silence, intersilence;
00961                                 long lastnum;
00962                                 bool exitkey;
00963                                 bool compress;
00964                                 bool trigger;
00965                                 const char *pos;
00966                                 const char *exit;
00967                                 const char *menu;
00968                                 const char *note;
00969                                 union {
00970                                         const char *list[MAX_LIST];
00971                                         struct {
00972                                                 const char *pathv[4];
00973                                                 char path1[128];
00974                                                 char path2[128];
00975                                                 char meta[MAX_LIST * 2];
00976                                         };
00977                                 };
00978                         }       audio;
00979                                 
00980                         struct
00981                         {
00982                                 timeout_t interdigit;
00983                                 timeout_t lastdigit;
00984                                 const char *var;
00985                                 const char *exit;
00986                                 const char *format;
00987                                 const char *ignore;
00988                                 const char *route;
00989                                 unsigned count, size, required;
00990                         }       input;
00991 
00992                         struct
00993                         {
00994                                 const char *var;
00995                                 const char *menu;
00996                         }       inkey;
00997 
00998                         struct
00999                         {
01000                                 const char *sequence;
01001                                 bool flashing;
01002                                 bool dialing, exiting, hangup, dtmf, refer;
01003                                 char *syncdigit;
01004                                 timeout_t synctimer;
01005                                 timeout_t duration;
01006                                 char digits[64];
01007                                 char sessionid[16];
01008                         }       tone;
01009 
01010                         struct
01011                         {
01012                                 timeout_t on, off, interdigit;
01013                                 unsigned pos;
01014                                 bool flashing;
01015                                 bool dialing;
01016                                 unsigned char digits[64];
01017                         }       pulse;  
01018 
01019                         struct
01020                         {
01021                                 const char *dial;
01022                                 const char *exit;
01023                                 bool dtmf, drop, hangup, refer;
01024                                 BayonneSession *peer;
01025                                 timeout_t answer_timer, hunt_timer;
01026                                 Line *select;
01027                                 unsigned index;
01028                                 char digits[64];
01029                         }       join;
01030 
01031                         struct
01032                         {
01033                                 const char *ref;
01034                                 char buf[MAX_LIST * sizeof(char *)];
01035                         }       url;
01036                 };
01037                 
01038         }       State;
01039         
01043         static statetab states[];
01044 
01049         static Mutex serialize;
01050 
01054         static ThreadLock reloading;
01055 
01059         static Traffic total_call_attempts;
01060         static Traffic total_call_complete;
01061         static volatile unsigned short total_active_calls;
01062 
01070         static void allocate(timeslot_t timeslots, ScriptCommand *pointer = NULL, timeslot_t overdraft = 0);
01071 
01072         static const char *getRegistryId(const char *id);
01073 
01074         static BayonneDriver *getDriverTag(const char *id);
01075 
01076         static Audio::Encoding getEncoding(const char *cp);
01077 
01081         static void allocateLocal(void);
01082 
01086         static void addConfig(const char *cfgfile);
01087 
01094         void md5_hash(char *out, const char *source);
01095 
01099         static void waitLoaded(void);
01100         
01106         static unsigned long uptime(void);
01107 
01113         static ScriptCompiler *reload(void);
01114 
01118         static void down(void);
01119 
01126         static bool service(const char *service);
01127 
01133         static const char *getRunLevel(void);
01134 
01142         static BayonneSession *getSession(timeslot_t timeslot);
01143 
01150         static ScriptImage **getLocalImage(timeslot_t timeslot);
01151 
01163         static BayonneSession *startDialing(const char *dial, 
01164                 const char *name, const char *caller, const char *display, 
01165                 BayonneSession *parent = NULL, const char *manager = NULL,
01166                 const char *secret = NULL);
01167 
01176         static BayonneSession *getSid(const char *id);
01177 
01185         static timeslot_t toTimeslot(const char *id);
01186 
01192         static inline timeslot_t getTimeslotsUsed(void)
01193                 {return Bayonne::ts_used;};
01194 
01200         static inline timeslot_t getTimeslotCount(void)
01201                 {return Bayonne::ts_count;};    
01202 
01209         static inline timeslot_t getAvailTimeslots(void)
01210                 {return Bayonne::ts_count - Bayonne::ts_used;};
01211 
01219         static Handler getState(const char *name);
01220 
01227         static int getDigit(char dtmf);
01228 
01235         static char getChar(int dtmf);
01236 
01247         static bool matchDigits(const char *digits, const char *match, bool partial = false);
01248 
01254         static ScriptImage *useImage(void);
01255 
01262         static void endImage(ScriptImage *image);
01263 
01270         static bool loadPlugin(const char *path);
01271 
01278         static bool loadMonitor(const char *path);  
01279 
01286         static bool loadAudio(const char *path);
01287 
01288         static void errlog(const char *level, const char *fmt, ...); 
01289 
01290         static bool getUserdata(void);
01291 
01292         static void addTrap4(const char *addr);
01293 #ifdef  CCXX_IPV6
01294         static void addTrap6(const char *addr);
01295 #endif
01296 };
01297 
01305 class __EXPORT BayonneZeroconf
01306 {
01307 protected:
01308         static BayonneZeroconf *zeroconf_first;
01309         BayonneZeroconf *zeroconf_next;
01310         const char *zeroconf_type;
01311         tpport_t zeroconf_port;
01312 
01313 public:
01314         typedef enum 
01315         {
01316                 ZEROCONF_IPANY,
01317                 ZEROCONF_IPV6,
01318                 ZEROCONF_IPV4
01319         }       zeroconf_family_t;
01320 
01321 protected:
01322         zeroconf_family_t zeroconf_family;
01323 
01324         BayonneZeroconf(const char *type, zeroconf_family_t family = ZEROCONF_IPANY);
01325 
01326 public:
01332         static inline BayonneZeroconf *getFirst(void)
01333                 {return zeroconf_first;};
01334 
01340         inline BayonneZeroconf *getNext(void)
01341                 {return zeroconf_next;};
01342 
01348         inline const char *getType(void)
01349                 {return zeroconf_type;};
01350 
01356         inline tpport_t getPort(void)
01357                 {return zeroconf_port;};
01358 
01359         inline zeroconf_family_t getFamily(void)
01360                 {return zeroconf_family;};
01361 };
01362 
01370 class __EXPORT BayonneConfig : public DynamicKeydata
01371 {
01372 private:
01373         static BayonneConfig *first;
01374 
01375         BayonneConfig *next;
01376         const char *id;
01377 
01378 public:
01379         BayonneConfig(const char *id, Keydata::Define *def, const char *path);
01380         BayonneConfig(const char *id, const char *path);
01381         void setEnv(const char *id);
01382         static BayonneConfig *get(const char *id);
01383         static void rebuild(ScriptImage *img);
01384 };
01385 
01393 class __EXPORT BayonneTranslator : public Bayonne
01394 {
01395 protected:
01396         static BayonneTranslator *first;
01397         BayonneTranslator *next;
01398         const char *id;
01399 
01400         static const char *getToken(BayonneSession *s, Line *l, unsigned *idx);
01401         static unsigned addItem(BayonneSession *s, unsigned count, const char *text);
01402         static const char *getLast(BayonneSession *s, unsigned count);
01403 
01404 public:
01412         BayonneTranslator(const char *iso);
01413 
01414         virtual ~BayonneTranslator();
01415 
01422         static BayonneTranslator *get(const char *name);
01423 
01428         static inline BayonneTranslator *getFirst(void)
01429                 {return first;};
01430 
01436         inline BayonneTranslator *getNext()
01437                 {return next;};
01438         
01446         static BayonneTranslator *loadTranslator(const char *iso);
01447 
01456         virtual unsigned digits(BayonneSession *sessiob, unsigned count, const char *string);
01457 
01466         virtual unsigned spell(BayonneSession *session, unsigned count, const char *string);
01467 
01476         virtual unsigned sayorder(BayonneSession *session, unsigned count, const char *string);
01477 
01486         virtual unsigned number(BayonneSession *session, unsigned count, const char *string);
01487 
01497         virtual unsigned saynumber(BayonneSession *session, unsigned count, const char *string);
01498 
01507         virtual unsigned saycount(BayonneSession *session, unsigned count, const char *string);
01508 
01517         virtual unsigned sayhour(BayonneSession *session, unsigned count, const char *string);
01518 
01527         virtual unsigned saytime(BayonneSession *session, unsigned count, const char *string);
01528 
01537         virtual unsigned weekday(BayonneSession *session, unsigned count, const char *string);
01538 
01539         /*
01540          * Translate a string with a date into spoken date without year.
01541          *
01542          * @param session to save list of prompts.
01543          * @param count of current prompts used.
01544          * @param string to be processed.
01545          * @return new count of prompts used.
01546          */
01547         virtual unsigned sayday(BayonneSession *session, unsigned count, const char *string);
01548 
01557         virtual unsigned saydate(BayonneSession *session, unsigned count, const char *string);
01558 
01567         virtual unsigned saybool(BayonneSession *session, unsigned count, const char *string);
01568 
01577         virtual unsigned phone(BayonneSession *session, unsigned count, const char *string);
01578 
01587         virtual unsigned extension(BayonneSession *session, unsigned count, const char *string);
01588 
01596         virtual const char *speak(BayonneSession *session, Line *line = NULL);
01597 
01603         inline const char *getId(void)
01604                 {return id;};
01605 };
01606 
01607 
01615 class __EXPORT BayonneAudio : public AudioStream, public Bayonne
01616 {
01617 protected:
01618         char filename[MAX_PATHNAME];
01619         const char **list;
01620         char *getContinuation(void);
01621 
01622 public:
01627         AudioTone *tone;
01628 
01633         BayonneTranslator *translator;
01634 
01638         char vlib[60];
01639 
01640         const char *extension, *voicelib, *libext, *prefixdir, *offset;
01641         Encoding encoding;
01642         timeout_t framing;
01643         char var_position[14];
01644 
01648         BayonneAudio();
01649 
01657         const char *getFilename(const char *name, bool write = false);
01658 
01663         void cleanup(void);
01664         
01671         void play(const char **list, Mode mode = modeRead);
01672 
01680         void record(const char *name, Mode mode = modeCreate, const char *annotation = NULL);
01681 
01688         const char *getVoicelib(const char *iso);
01689 
01695         inline AudioCodec *getCodec(void)
01696                 {return codec;};
01697 };              
01698 
01709 class __EXPORT BayonneMsgport : public Thread, public Buffer, public Bayonne
01710 {
01711 public:
01715         virtual ~BayonneMsgport();
01716 
01722         BayonneMsgport(BayonneDriver *driver);
01723 
01729         void update(void); 
01730 
01735         void initial(void);
01736 
01737 protected:
01738         BayonneDriver *msgdriver;
01739         Event *msglist;
01740         unsigned msgsize, msghead, msgtail;
01741         timeslot_t tsfirst, tscount;
01742         char msgname[16];
01743 
01747         void shutdown(void);
01748 
01756         virtual timeout_t getTimeout(Event *event);
01757         
01758         void run(void);
01759 
01760         size_t onWait(void *buf);
01761         size_t onPost(void *buf);
01762         size_t onPeek(void *buf);
01763 };
01764 
01772 class __EXPORT BayonneDriver : public Bayonne, public ReconfigKeydata, public Mutex
01773 {
01774 protected:
01775         friend class __EXPORT BayonneSession;
01776         friend class __EXPORT BayonneMsgport;
01777         static BayonneDriver *firstDriver;
01778         static BayonneDriver *lastDriver;
01779         static BayonneDriver *trunkDriver;
01780         static BayonneDriver *protoDriver;
01781         static Semaphore oink;  // the pig has been kicked!
01782         static bool protocols;
01783 
01784         BayonneSession *firstIdle, *lastIdle, *highIdle;
01785         BayonneMsgport *msgport;
01786         BayonneDriver *nextDriver;
01787         const char *name;
01788         timeslot_t timeslot, count;
01789         unsigned avail;
01790         unsigned span, spans;   
01791         bool running;
01792         static bool stopping;
01793         std::ostream *logevents;
01794 
01795         int audio_priority;
01796         size_t audio_stack;
01797         Audio::Level audio_level;
01798 
01799         timeout_t pickup_timer, hangup_timer, seize_timer, ring_timer, hunt_timer;
01800         timeout_t reset_timer, release_timer, flash_timer, interdigit_timer;
01801         unsigned answer_count;
01802 
01807         virtual void reloadDriver(void);
01808 
01813         virtual void startDriver(void);
01814 
01818         virtual void stopDriver(void);
01819 
01824         void relistIdle(void);
01825 
01826 public:
01835         virtual bool isAuthorized(const char *userid, const char *secret);
01836 
01837         virtual bool deregister(const char *id);
01838         virtual bool reregister(const char *id, const char *uri, const char *secret, timeout_t expires);
01839 
01840         Traffic call_attempts, call_complete;
01841         volatile unsigned short active_calls;
01842 
01851         BayonneDriver(Keydata::Define *pairs, const char *key, const char *id, bool virt = false);
01852 
01856         ~BayonneDriver();
01857 
01861         static inline bool useProtocols(void)
01862                 {return protocols;}
01863 
01867         static bool isStopping(void)
01868                 {return stopping;};
01869 
01873         static inline BayonneDriver *getTrunking(void)
01874                 {return trunkDriver;}
01875 
01879         static inline BayonneDriver *getPrimary(void)
01880                 {return firstDriver;}
01881 
01889         static BayonneDriver *authorize(const char *userid, const char *secret);
01890         
01894         inline BayonneDriver *getNext(void)
01895                 {return nextDriver;};
01896 
01897         static inline BayonneDriver *getRoot(void)
01898                 {return firstDriver;};
01899 
01903         static inline BayonneDriver *getProtocol(void)
01904                 {return protoDriver;}
01905 
01911         BayonneSession *getIdle(void);
01912 
01918         virtual bool suspend(void);
01919 
01925         virtual bool resume(void);
01926 
01930         virtual void reregister(void);
01931 
01939         virtual const char *registerScript(ScriptImage *image, Line *line);
01940 
01948         virtual const char *assignScript(ScriptImage *image, Line *line);
01949 
01956         static BayonneDriver *get(const char *id);
01957 
01964         static BayonneDriver *loadDriver(const char *id);
01965 
01972         static BayonneDriver *loadTrunking(const char *id);
01973 
01981         static BayonneDriver *loadProtocol(const char *id, unsigned timeslots = 0);
01982 
01990         static unsigned list(char **items, unsigned max);
01991 
01995         static void start(void);
01996         
02000         static void stop(void);
02001 
02005         static void reload(void);
02006 
02013         static void add(BayonneSession *session);
02014 
02021         static void del(BayonneSession *session);
02022 
02028         inline timeslot_t getFirst(void)
02029                 {return timeslot;};
02030 
02036         inline timeslot_t getCount(void)
02037                 {return count;};
02038 
02044         inline unsigned getSpanFirst(void)
02045                 {return span;};
02046 
02052         inline unsigned getSpansUsed(void)
02053                 {return spans;};
02054 
02060         inline const char *getName(void)
02061                 {return name;};
02062 
02069         inline timeout_t getResetTimer(void)
02070                 {return reset_timer;};
02071 
02077         inline timeout_t getReleaseTimer(void)
02078                 {return release_timer;};
02079 
02085         inline timeout_t getHangupTimer(void)
02086                 {return hangup_timer;};
02087 
02093         inline timeout_t getPickupTimer(void)
02094                 {return pickup_timer;};
02095 
02101         inline timeout_t getSeizeTimer(void)
02102                 {return seize_timer;};
02103 
02109         inline timeout_t getHuntTimer(void)
02110                 {return hunt_timer;};
02111 
02117         inline timeout_t getFlashTimer(void)
02118                 {return flash_timer;};
02119 
02125         inline timeout_t getInterdigit(void)
02126                 {return interdigit_timer;};
02127 
02135         inline timeout_t getRingTimer(void)
02136                 {return ring_timer;};
02137 
02143         inline unsigned getAnswerCount(void)
02144                 {return answer_count;};
02145 
02152         BayonneSpan *getSpan(unsigned id);
02153 
02161         BayonneSession *getTimeslot(timeslot_t id);
02162 
02168         inline BayonneMsgport *getMsgport(void)
02169                 {return msgport;};
02170 
02176         inline size_t getAudioStack(void)
02177                 {return audio_stack;};
02178 
02184         inline int getAudioPriority(void)
02185                 {return audio_priority;};
02186 
02192         inline Audio::Level getAudioLevel(void)
02193                 {return audio_level;};
02194 
02200         inline void setLogging(std::ostream *output)
02201                 {logevents = output;};
02202 
02209         inline bool isSpanable(unsigned span);
02210 
02221         virtual bool getDestination(const char *target, const char *dial, char *output, size_t size);
02222 
02228         inline unsigned getAvail(void)
02229                 {return avail;}
02230 
02238         virtual bool isExternal(const char *dest);
02239 
02246         virtual bool isRegistered(const char *dest);
02247 
02254         virtual bool isAvailable(const char *dest);
02255 
02263         virtual bool isReachable(const char *proxy);
02264 
02274         virtual unsigned getRegistration(regauth_t *data, unsigned count, const char *id = NULL);
02275 };      
02276 
02284 class __EXPORT BayonneSpan : public Bayonne, public Keydata
02285 {
02286 protected:
02287         friend class __EXPORT BayonneSession;
02288         friend class __EXPORT BayonneDriver;
02289 
02290         static BayonneSpan *first;
02291         static BayonneSpan *last;
02292         static unsigned spans;
02293         static BayonneSpan **index;
02294         
02295         unsigned id;
02296         BayonneDriver *driver;
02297         BayonneSpan *next;
02298         timeslot_t timeslot, count, used;       // timeslots
02299 
02300 public:
02301         Traffic call_attempts, call_complete;
02302         volatile unsigned short active_calls;
02303 
02310         BayonneSpan(BayonneDriver *driver, timeslot_t timeslots);
02311 
02318         static BayonneSpan *get(unsigned id);
02319         
02326         BayonneSession *getTimeslot(timeslot_t id);
02327 
02333         static void allocate(unsigned total = 0);
02334 
02340         static inline unsigned getSpans(void)
02341                 {return spans;};
02342 
02348         inline timeslot_t getFirst(void)
02349                 {return timeslot;};
02350 
02356         inline timeslot_t getCount(void)
02357                 {return count;};
02358 
02364         inline unsigned getId(void)
02365                 {return id;};
02366 
02372         inline BayonneDriver *getDriver(void)
02373                 {return driver;};
02374 
02380         inline unsigned getAvail(void)
02381                 {return count - used;}
02382 
02388         virtual bool suspend(void);
02389 
02395         virtual bool resume(void);
02396 
02402         virtual bool reset(void);
02403 };
02404 
02411 class __EXPORT BayonneBinder : public ScriptBinder, public Bayonne
02412 {
02413 private:
02414         friend class __EXPORT BayonneSession;
02415         static BayonneBinder *binder;
02416 
02417         class Image : public ScriptImage
02418         {
02419         public:
02420                 inline Image() : ScriptImage(NULL, NULL) {};
02421                 unsigned gatherPrefix(const char *prefix, const char **list, unsigned max);
02422         };
02423 
02424 protected:
02425         virtual const char *submit(const char **data);
02426 
02427         virtual ScriptCompiler *compiler(void);
02428         
02429         virtual unsigned destinations(Image *img, const char **array, unsigned max);
02430 
02431         virtual bool isDestination(Image *img, const char *name);
02432 
02433         BayonneSession *session(ScriptInterp *interp);
02434 
02435         bool scriptEvent(ScriptInterp *interp, const char *evt);
02436 
02437         bool digitEvent(ScriptInterp *interp, const char *evt);
02438 
02439         BayonneBinder(const char *id);
02440 
02441         virtual void makeCall(BayonneSession *child);
02442 
02443         virtual void dropCall(BayonneSession *child);
02444 
02445         virtual Name *getIncoming(ScriptImage *img, BayonneSession *s, Event *event);
02446 
02447 public:
02448         static const char *submitRequest(const char **data);
02449 
02450         static ScriptCompiler *getCompiler(void);
02451 
02452         static unsigned gatherDestinations(ScriptImage *img, const char **index, unsigned max);
02453 
02454         static bool isDestination(const char *name);
02455 };
02456 
02464 class __EXPORT BayonneSession : public ScriptInterp, public Bayonne
02465 {
02466 private:
02467         friend class __EXPORT ScriptEngine;
02468         friend class __EXPORT BayonneMsgport;
02469         friend class __EXPORT BayonneTranslator;
02470         friend class __EXPORT BayonneDriver;
02471         friend class __EXPORT Bayonne;
02472 
02473         BayonneSession() {};
02474 
02475         BayonneSession *nextIdle, *prevIdle;
02476         bool isAvail;
02477 
02478 protected:
02479         static BayonneTranslator langNone;
02480         static ScriptSymbols *globalSyms;
02481         static Mutex globalLock;        
02482 
02483         std::ostream *logevents, *logtrace;
02484         Ring *ring;
02485         BayonneDriver *driver;
02486         BayonneMsgport *msgport;
02487         BayonneSession *peer;
02488         BayonneSpan *span;
02489         timeslot_t timeslot;
02490         uint8 seq;
02491         uint16 evseq;
02492         uint32 tseq;
02493         bool offhook, dtmf, answered, starting, holding, connecting, referring;
02494         time_t audiotimer, starttime;
02495         interface_t iface;
02496         bridge_t bridge;
02497         calltype_t type;
02498         event_t seizure;
02499         ScriptEngine *vm;
02500 
02501 //      Name *getScript(const char *scr);
02502 
02510         bool requiresDTMF(void);
02511 
02516         void enterCall(void);
02517 
02525         void exitCall(const char *reason);
02526 
02532         virtual bool enableDTMF(void);
02533 
02537         virtual void disableDTMF(void);
02538 
02547         virtual const char *checkAudio(bool live);
02548 
02555         virtual bool filterPosting(Event *event);
02556 
02557         virtual bool enterCommon(Event *event);
02558         virtual bool enterInitial(Event *event);
02559         virtual bool enterFinal(Event *event);
02560         virtual bool enterIdle(Event *event);
02561         virtual bool enterReset(Event *event);
02562         virtual bool enterRelease(Event *event);
02563         virtual bool enterRinging(Event *event);
02564         virtual bool enterPickup(Event *event);
02565         virtual bool enterAnswer(Event *event);
02566         virtual bool enterSeize(Event *event);
02567         virtual bool enterHunting(Event *event);
02568         virtual bool enterHangup(Event *event);
02569         virtual bool enterTone(Event *event);
02570         virtual bool enterReconnect(Event *event);
02571         virtual bool enterDTMF(Event *event);
02572         virtual bool enterPlay(Event *event);
02573         virtual bool enterRecord(Event *event);
02574         virtual bool enterJoin(Event *event);
02575         virtual bool enterWait(Event *event);
02576         virtual bool enterDial(Event *event);
02577         virtual bool enterBusy(Event *event);
02578         virtual bool enterStandby(Event *event);
02579         virtual bool enterXfer(Event *event);
02580         virtual bool enterRefer(Event *event);
02581         virtual bool enterHold(Event *event);
02582         virtual bool enterRecall(Event *event);
02583 
02588         void check(void);
02589 
02590         void renameRecord(void);
02591         bool stateInitial(Event *event);
02592         bool stateFinal(Event *event);
02593         bool stateIdle(Event *event);
02594         bool stateIdleReset(Event *event);
02595         bool stateReset(Event *event);
02596         bool stateRelease(Event *event);
02597         bool stateBusy(Event *event);
02598         bool stateStandby(Event *event);
02599         bool stateRinging(Event *event);
02600         bool statePickup(Event *event);
02601         bool stateAnswer(Event *event);
02602         bool stateSeize(Event *event);
02603         bool stateHunting(Event *event);
02604         bool stateRunning(Event *event);
02605         bool stateLibexec(Event *event);
02606         bool stateLibreset(Event *event);
02607         bool stateLibwait(Event *event);
02608         bool stateWaitkey(Event *event);
02609         bool stateThreading(Event *event);
02610         bool stateHangup(Event *event);
02611         bool stateCollect(Event *event);
02612         bool stateSleep(Event *event);
02613         bool stateStart(Event *event);
02614         bool stateClear(Event *event);
02615         bool stateInkey(Event *event);
02616         bool stateInput(Event *event);
02617         bool stateRead(Event *event);
02618         bool stateDial(Event *event);
02619         bool stateXfer(Event *event);
02620         bool stateRefer(Event *event);
02621         bool stateHold(Event *event);
02622         bool stateRecall(Event *event);
02623         bool stateTone(Event *event);
02624         bool stateDTMF(Event *event);
02625         bool statePlay(Event *event);
02626         bool stateRecord(Event *event);
02627         bool stateJoin(Event *event);
02628         bool stateWait(Event *event);
02629         bool stateConnect(Event *event);
02630         bool stateReconnect(Event *event);
02631         bool stateCalling(Event *event);
02632 
02639         bool putEvent(Event *event);
02640 
02646         void libWrite(const char *string);
02647 
02648         void libClose(const char *string);
02649 
02650         bool isLibexec(const char *tsid);
02651 
02652         timeout_t getLibexecTimeout(void);
02653 
02654         const char *getWritepath(char *buf = NULL, size_t len = 0);
02655 
02656         void incIncomingAttempts(void);
02657 
02658         void incOutgoingAttempts(void);
02659 
02660         void incIncomingComplete(void);
02661 
02662         void incOutgoingComplete(void);
02663 
02664         void incActiveCalls(void);
02665 
02666         void decActiveCalls(void);
02667 
02668 public:
02669         Traffic call_attempts, call_complete;
02670 
02671         inline bool isDTMF(void)
02672                 {return dtmf;};
02673 
02674         inline bool isPeering(void)
02675                 {return state.peering;};
02676 
02677         inline BayonneSpan *getSpan(void)
02678                 {return span;};
02679 
02680         inline timeslot_t getTimeslot(void)
02681                 {return timeslot;};
02682 
02683         inline ScriptEngine *getEngine(void)
02684                 {return vm;};
02685 
02692         const char *getExternal(const char *option);
02693 
02701         bool addSymbol(const char *id, const char *value);
02702 
02709     bool clearSymbol(const char *id);
02710 
02716         inline uint16 getEventSequence(void)
02717                 {return evseq;};
02718 
02719         static const char *getGlobal(const char *id);
02720         static bool setGlobal(const char *id, const char *value);
02721         static bool sizeGlobal(const char *id, unsigned size);
02722         static bool addGlobal(const char *id, const char *value);
02723         static bool clearGlobal(const char *id);
02724 
02725 protected:
02732         ScriptInterp *getInterp(const char *id);
02733 
02740         ScriptSymbols *getSymbols(const char *id);
02741 
02745         BayonneTranslator *translator;
02746 
02754         Name *attachStart(Event *event);
02755 
02759         unsigned getId(void);
02760 
02765         void setSid(void);
02766 
02770         void setState(state_t);
02771 
02776         void setRunning(void);
02777 
02784         bool setReconnect(const char *enc, timeout_t framing);
02785 
02786 
02790         bool recallReconnect(void);
02791 
02796         void setConnecting(const char *evname = NULL);
02797 
02806         bool setLibexec(result_t result);
02807 
02816         bool setLibreset(result_t result);
02817 
02818 public:
02824         inline BayonneTranslator *getTranslator(void)
02825                 {return translator;};
02826 
02830         inline void startConnecting(void)
02831                 {connecting = true;};
02832 
02833 protected:
02840         inline libaudio_t *getLibaudio(void)
02841                 {return state.libaudio;};
02842 
02846         void finalize(void);
02847 
02853         bool exit(void);
02854 
02855         char var_date[12];
02856         char var_time[12];
02857         char var_duration[12];
02858         char var_callid[12];
02859         char var_tid[14];
02860         char var_sid[16];
02861         char var_pid[16];
02862         char var_recall[16];
02863         char var_joined[16];
02864         char var_rings[4];
02865         char var_timeslot[8];
02866         char var_spanid[8];
02867         char var_bankid[4];
02868         char var_spantsid[12];
02869         const char *voicelib;
02870         char *dtmf_digits;              // dtmf sym space;
02871         unsigned digit_count, ring_count;
02872         time_t time_joined;
02873 
02874         State state;
02875 
02876 public:
02884         BayonneSession(BayonneDriver *driver, timeslot_t timeslot, BayonneSpan *span = NULL);
02885 
02889         virtual ~BayonneSession();
02890 
02891         const char *getDigits(void);
02892 
02893         inline const char *defVoicelib(void)
02894                 {return voicelib;}
02895 
02896         inline const char *getSessionId(void)
02897                 {return var_sid;};
02898 
02899         inline const char *getSessionParent(void)
02900                 {return var_pid;};
02901 
02902         inline const char *getSessionJoined(void)
02903                 {return var_joined;};
02904 
02905         inline time_t getSessionStart(void)
02906                 {return starttime;};
02907 
02911         void initialevent(void);
02912 
02916         void initialize(void);
02917 
02921         void detach(void);
02922 
02926         inline time_t getJoined(void)
02927                 {return time_joined;};
02928 
02934         inline BayonneDriver *getDriver(void)
02935                 {return driver;}
02936 
02943         virtual timeout_t getRemaining(void) = 0;
02944 
02951         virtual void startTimer(timeout_t timer) = 0;
02952 
02957         virtual void stopTimer(void) = 0;
02958 
02964         virtual void setOffhook(bool state);
02965 
02969         virtual void makeIdle(void);
02970 
02976         void part(event_t reason);
02977 
02984         virtual bool postEvent(Event *event);
02985 
02986 
02987         bool matchLine(Line *line);
02988 
02994         virtual void queEvent(Event *event);
02995 
02999         virtual void startThread(void);
03000 
03004         virtual void enterThread(ScriptThread *thr);
03005 
03009         virtual void exitThread(const char *msg);
03010 
03014         virtual void clrAudio(void);
03015 
03019         virtual timeout_t getToneFraming(void);
03020 
03024         virtual const char *audioEncoding(void);
03025 
03029         virtual const char *audioExtension(void);
03030         
03034         virtual timeout_t audioFraming(void);
03035 
03042         const char *getAudio(bool live = true);
03043 
03048         void branching(void);
03049 
03055         inline bool isOffhook(void)
03056                 {return offhook;};
03057 
03063         inline interface_t getInterface(void)
03064                 {return iface;};
03065 
03071         inline bridge_t getBridge(void)
03072                 {return bridge;};
03073 
03079         inline calltype_t getType(void)
03080                 {return type;};
03081 
03087         inline timeslot_t getSlot(void)
03088                 {return timeslot;};
03089 
03095         inline bool isIdle(void)
03096                 {return isAvail;};
03097 
03103         bool isRefer(void);
03104 
03110         bool isJoined(void);
03111 
03117         bool isAssociated(void);
03118 
03124         void associate(BayonneSession *s);
03125 
03126         inline bool isHolding(void)
03127                 {return holding;};
03128 
03132         bool isDisconnecting(void);
03133 
03139         timeout_t getJoinTimer(void);
03140 
03147         bool signalScript(signal_t signal);
03148 
03154         virtual bool peerLinear(void);
03155 
03165         virtual bool peerAudio(Audio::Encoded encoded);
03166 
03176         virtual bool setPeering(Audio::Encoding encoding, timeout_t framing);
03177 
03178         const char *getKeyString(const char *id);
03179         bool getKeyBool(const char *id);
03180         long getKeyValue(const char *id);
03181         timeout_t getSecTimeout(const char *id);
03182         timeout_t getMSecTimeout(const char *id);
03183         timeout_t getTimeoutValue(const char *opt = NULL);
03184         timeout_t getTimeoutKeyword(const char *kw);
03185         const char *getExitKeyword(const char *def);
03186         const char *getMenuKeyword(const char *def);
03187 
03188         unsigned getInputCount(const char *digits, unsigned max);
03189 
03197         uint32 newTid(void);
03198 
03204         inline const char *getTid(void)
03205                 {return var_tid;};
03206 
03213         bool digitEvent(const char *event);
03214 
03215         inline bool stringEvent(const char *evt)
03216                 {return scriptEvent(evt);}
03217 
03223         char getDigit(void);
03224 
03225         BayonneAudio audio;
03226 };
03227 
03235 class __EXPORT BayonneRPC : public Bayonne
03236 {
03237 protected:
03238         BayonneRPC();
03239         virtual ~BayonneRPC();
03240 
03241         struct params
03242         {
03243                 char *name[RPC_MAX_PARAMS];
03244                 char *map[RPC_MAX_PARAMS];
03245                 char *value[RPC_MAX_PARAMS];
03246                 unsigned short param[RPC_MAX_PARAMS];
03247                 unsigned count;
03248                 short argc;
03249         }       params;
03250 
03251         bool parseCall(char *cp);
03252 
03253 public:
03254         virtual void setComplete(BayonneSession *s);
03255 
03256         struct {
03257                 char *buffer;
03258                 size_t bufsize;
03259                 size_t bufused;
03260                 const char *agent_id;
03261                 const char *protocol;
03262                 bool authorized;                // transport authorized
03263                 const char *userid;             // null if anonymous
03264                 BayonneDriver *driver;          // authorizing driver
03265         }       transport;
03266 
03267         struct {
03268                 unsigned code;
03269                 const char *string;
03270         }       result;
03271 
03272         struct {
03273                 const char *prefix;     // xmlrpc has prefix, soap NULL
03274                 const char *method;
03275                 const char *tranid;
03276                 const char *action;
03277                 const char *resuri;
03278         }       header;
03279 
03280         inline unsigned getCount(void)
03281                 {return params.argc;};
03282 
03283         const char *getParamId(unsigned short param, unsigned short offset); 
03284         const char *getIndexed(unsigned short param, unsigned short offset = 0);
03285         const char *getNamed(unsigned short param, const char *member);
03286         const char *getMapped(const char *map, const char *member);
03287 
03288         friend size_t xmlwrite(char **buf, size_t *max, const char *fmt, ...);
03289         bool buildResponse(const char *fmt, ...);
03290         void sendSuccess(void);
03291         void sendFault(int code, const char *string);
03292         
03293         inline void transportFault(unsigned code, const char *string)
03294                 {result.code = code; result.string = string;};
03295 
03296         bool invokeXMLRPC(void);
03297 };      
03298 
03299 size_t xmlwrite(char **buf, size_t *max, const char *fmt, ...);
03300          
03309 class __EXPORT BayonneService : public Thread                
03310 {          
03311 private:            
03312         friend class __EXPORT BayonneSession;
03313 
03314         static BayonneService *first;
03315         static BayonneService *last;
03316         BayonneService *next;
03317         friend void startServices(void);        
03318         friend void stopServices(void);
03319 
03320 protected:
03321         BayonneService(int pri, size_t stack);
03322 
03326         virtual void stopService(void);
03327 
03331         virtual void startService(void);
03332 
03336         virtual void detachSession(BayonneSession *s);
03337 
03341         virtual void attachSession(BayonneSession *s);
03342 
03346         virtual void enteringCall(BayonneSession *child);
03347 
03351         virtual void exitingCall(BayonneSession *child);
03352 
03353 public:
03357         static void start(void);
03358         
03362         static void stop(void); 
03363 };
03364 
03373 class __EXPORT ScriptEngine
03374 {
03375 protected:
03376         friend class __EXPORT BayonneSession;
03377 
03384         virtual bool signalEngine(Bayonne::signal_t signal) = 0;
03385 
03390         virtual void releaseEngine(void) = 0;
03391 
03396         virtual void disconnectEngine(void) = 0;
03397 
03406         virtual bool stepEngine(void) = 0;
03407 
03411         virtual ~ScriptEngine() = 0;
03412 
03413         /*
03414          * Clears vm session.
03415          */
03416         inline void clearEngine(BayonneSession *s)
03417                 {s->vm = NULL;};
03418 
03422         inline void setEngine(BayonneSession *s)
03423                 {s->vm = this;};
03424 };
03425 
03426 
03427 } // namespace
03428 
03429 #endif

Generated on Wed Jan 16 04:45:26 2008 for Bayonne by  doxygen 1.5.4