LCR now runs as a user.
[lcr.git] / port.h
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** port header file                                                          **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #ifndef PORT_HEADER
13 #define PORT_HEADER
14
15 /* type of port */
16 #define PORT_TYPE_NULL          0x0000
17 #define PORT_CLASS_mISDN        0x0100
18 #define PORT_CLASS_MASK         0xff00
19 #define PORT_CLASS_mISDN_DSS1   0x0110
20 #define PORT_CLASS_mISDN_MASK   0xfff0
21         /* nt-mode */
22 #define PORT_TYPE_DSS1_NT_IN    0x0111
23 #define PORT_TYPE_DSS1_NT_OUT   0x0112
24         /* te-mode */
25 #define PORT_TYPE_DSS1_TE_IN    0x0113
26 #define PORT_TYPE_DSS1_TE_OUT   0x0114
27         /* answering machine */
28 #define PORT_TYPE_VBOX_OUT      0x0311
29
30
31 enum { /* states of call */
32         PORT_STATE_IDLE,        /* no call */
33         PORT_STATE_IN_SETUP,    /* incoming connection */
34         PORT_STATE_OUT_SETUP,   /* outgoing connection */
35         PORT_STATE_IN_OVERLAP,  /* more informatiopn needed */
36         PORT_STATE_OUT_OVERLAP, /* more informatiopn needed */
37         PORT_STATE_IN_PROCEEDING,/* call is proceeding */
38         PORT_STATE_OUT_PROCEEDING,/* call is proceeding */
39         PORT_STATE_IN_ALERTING, /* call is ringing */
40         PORT_STATE_OUT_ALERTING,/* call is ringing */
41         PORT_STATE_CONNECT_WAITING,/* connect is sent to the network, waiting for acknowledge */
42         PORT_STATE_CONNECT,     /* call is connected and transmission is enabled */
43         PORT_STATE_IN_DISCONNECT,/* incoming disconnected */
44         PORT_STATE_OUT_DISCONNECT,/* outgoing disconnected */
45         PORT_STATE_RELEASE,     /* call released */
46 };
47
48 #define PORT_STATE_NAMES \
49 static char *state_name[] = { \
50         "PORT_STATE_IDLE", \
51         "PORT_STATE_IN_SETUP", \
52         "PORT_STATE_OUT_SETUP", \
53         "PORT_STATE_IN_OVERLAP", \
54         "PORT_STATE_OUT_OVERLAP", \
55         "PORT_STATE_IN_PROCEEDING", \
56         "PORT_STATE_OUT_PROCEEDING", \
57         "PORT_STATE_IN_ALERTING", \
58         "PORT_STATE_OUT_ALERTING", \
59         "PORT_STATE_CONNECT_WAITING", \
60         "PORT_STATE_CONNECT", \
61         "PORT_STATE_IN_DISCONNECT", \
62         "PORT_STATE_OUT_DISCONNECT", \
63         "PORT_STATE_RELEASE", \
64 };
65
66
67 enum { /* event list from listening to tty */
68         TTYI_EVENT_nodata,      /* no data was received nor processed */
69         TTYI_EVENT_NONE,        /* nothing happens */
70         TTYI_EVENT_CONNECT,     /* a connection is made */
71         TTYI_EVENT_RING,        /* incoming call */
72         TTYI_EVENT_CALLER,      /* caller id information */
73         TTYI_EVENT_INFO,        /* dialing information */
74         TTYI_EVENT_OVERLAP,     /* setup complete, awaiting more dialing info */
75         TTYI_EVENT_PROC,        /* proceeding */
76         TTYI_EVENT_ALRT,        /* alerting */
77         TTYI_EVENT_CONN,        /* connect */
78         TTYI_EVENT_DISC,        /* disconnect */
79         TTYI_EVENT_RELE,        /* release signal */
80         TTYI_EVENT_BUSY,        /* channel unavailable */
81 };
82
83 #define RECORD_BUFFER_LENGTH    1024 // must be a binary border & must be greater 256, because 256 will be written if buffer overflows
84 #define RECORD_BUFFER_MASK      1023
85
86 /* structure of epoint_list */
87 struct epoint_list {
88         struct epoint_list      *next;
89         unsigned int            epoint_id;
90         int                     active;
91 };
92
93 inline unsigned int ACTIVE_EPOINT(struct epoint_list *epointlist)
94 {
95         while(epointlist)
96         {
97                 if (epointlist->active)
98                         return(epointlist->epoint_id);
99                 epointlist = epointlist->next;
100         }
101         return(0);
102 }
103
104 inline unsigned int INACTIVE_EPOINT(struct epoint_list *epointlist)
105 {
106         while(epointlist)
107         {
108                 if (!epointlist->active)
109                         return(epointlist->epoint_id);
110                 epointlist = epointlist->next;
111         }
112         return(0);
113 }
114
115
116 /* structure of port settings */
117 struct port_settings {
118         char tones_dir[256];                    /* directory of current tone */
119         int no_seconds;
120 };
121
122 /* generic port class */
123 class Port
124 {
125         public:
126         /* methods */
127         Port(int type, char *portname, struct port_settings *settings);
128         virtual ~Port();
129         class Port *next;                       /* next port in list */
130         int p_type;                             /* type of port */
131         virtual int handler(void);
132         virtual int message_epoint(unsigned int epoint_id, int message, union parameter *param);
133         virtual void set_echotest(int echotest);
134         virtual void set_tone(char *dir, char *name);
135         virtual int read_audio(unsigned char *buffer, int length);
136
137         struct port_settings p_settings;
138         
139         /* tone */
140         char p_tone_dir[256];                   /* name of current directory */
141         char p_tone_name[256];                  /* name of current tone */
142         char p_tone_fh;                         /* file descriptor of current tone or -1 if not open */
143         void *p_tone_fetched;                   /* pointer to fetched data */
144         int p_tone_codec;                       /* codec that the tone is made of */
145         signed int p_tone_size, p_tone_left;    /* size of tone in bytes (not samples), bytes left */
146         signed int p_tone_eof;                  /* flag that makes the use of eof message */
147         signed int p_tone_counter;              /* flag that makes the use of counter message */
148         signed int p_tone_speed;                /* speed of current tone, 1=normal, may also be negative */
149 //      char p_knock_fh;                        /* file descriptor of knocking tone or -1 if not open */
150 //      void *p_knock_fetched;                  /* pointer to fetched data */
151 //      int p_knock_codec;
152 //      signed int p_knock_size, p_knock_left;
153         void set_vbox_tone(char *dir, char *name);/* tone of answering machine */
154         void set_vbox_play(char *name, int offset); /* sample of answ. */
155         void set_vbox_speed(int speed); /* speed of answ. */
156
157         /* identification */
158         unsigned int p_serial;                  /* serial unique id of port */
159         char p_name[128];                       /* name of port or token (h323) */
160
161         /* endpoint relation */
162         struct epoint_list *p_epointlist;       /* endpoint relation */
163
164         /* state */
165         int p_state;                            /* state of port */
166         void new_state(int state);              /* set new state */
167         struct caller_info p_callerinfo;        /* information about the caller */
168         struct dialing_info p_dialinginfo;      /* information about dialing */
169         struct connect_info p_connectinfo;      /* information about connected line */
170         struct redir_info p_redirinfo;          /* info on redirection (to the calling user) */
171         struct capa_info p_capainfo;    /* info on l2,l3 capacity */
172         int p_echotest;                         /* set to echo audio data FROM port back to port's mixer */
173
174         /* recording */
175         int open_record(int type, int mode, int skip, char *terminal, int anon_ignore, char *vbox_email, int vbox_email_file);
176         void close_record(int beep, int mute);
177         void record(unsigned char *data, int length, int dir_fromup);
178         FILE *p_record;                         /* recording fp: if not NULL, recording is enabled */
179         int p_record_type;                      /* codec to use: RECORD_MONO, RECORD_STEREO, ... */
180         int p_record_skip;                      /* skip bytes before writing the sample */
181         unsigned int p_record_length;           /* size of what's written so far */
182
183         signed short p_record_buffer[RECORD_BUFFER_LENGTH];
184         unsigned int p_record_buffer_readp;
185         unsigned int p_record_buffer_writep;
186         int p_record_buffer_dir;                /* current direction in buffer */
187
188         char p_record_filename[256];            /* record filename */
189         int p_record_vbox;                      /* 0= normal recording, 1= announcement, 2= record to vbox dir */
190         int p_record_vbox_year;                 /* time when vbox recording started */
191         int p_record_vbox_mon;
192         int p_record_vbox_mday;
193         int p_record_vbox_hour;
194         int p_record_vbox_min;
195         char p_record_extension[32];            /* current name (digits) of extension */
196         int p_record_anon_ignore;
197         char p_record_vbox_email[128];
198         int p_record_vbox_email_file;
199
200         void free_epointlist(struct epoint_list *epointlist);
201         void free_epointid(unsigned int epoint_id);
202         struct epoint_list *epointlist_new(unsigned int epoint_id);
203 };
204
205
206 extern Port *port_first;
207 extern unsigned int port_serial;
208
209 class Port *find_port_with_token(char *name);
210 class Port *find_port_id(unsigned int port_id);
211
212
213 #endif // PORT_HEADER
214
215