[ce0b0e]: / server / server.h  Maximize  Restore  History

Download this file

277 lines (222 with data), 6.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// Copyright (C) 2006-2007 David Sugar, Tycho Softworks.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <gnutelephony/sipwitch.h>
#include <eXosip2/eXosip.h>
#include <config.h>
NAMESPACE_SIPWITCH
using namespace UCOMMON_NAMESPACE;
#define CONFIG_KEY_SIZE 177
class thread;
class __LOCAL stack : private service::callback, private mapped_reuse<MappedCall>
{
private:
friend class thread;
class call;
class __LOCAL session : public LinkedObject
{
public:
int cid, did;
time_t activates;
call *parent;
unsigned sequence;
sockaddr_internet address, interface;
inline bool isSource(void)
{return (this == parent->source);};
inline bool isTarget(void)
{return (this == parent->target);};
};
class __LOCAL segment : public OrderedObject
{
public:
session sid;
};
class __LOCAL call : public LinkedObject
{
public:
typedef enum
{
DIRECTED,
CIRCULAR,
TERMINAL,
REDIRECTED,
DISTRIBUTED
} mode_t;
call();
OrderedIndex segments;
session *source;
session *target;
session *select;
MappedCall *map;
unsigned count;
mutex_t mutex;
Timer timer;
mode_t mode;
};
bool reload(service *cfg);
void start(service *cfg);
void stop(service *cfg);
void snapshot(FILE *fp);
bool check(void);
static stack sip;
unsigned threading, priority;
size_t stacksize;
volatile int timing;
LinkedObject *hash[CONFIG_KEY_SIZE];
const char *interface;
const char *agent;
short port;
int send101;
int family, tlsmode, protocol;
public:
typedef Socket::address address;
stack();
inline void access(void)
{MappedReuse::access();};
inline void release(void)
{MappedReuse::release();};
__EXPORT static session *createSession(call *cp, int cid);
__EXPORT static session *create(MappedRegistry *rr, int cid);
__EXPORT static void destroy(session *s);
__EXPORT static void release(session *s);
__EXPORT static void commit(session *s);
__EXPORT static session *find(int cid);
__EXPORT static session *modify(int cid);
__EXPORT static char *sipAddress(struct sockaddr_internet *addr, char *buf, size_t size);
__EXPORT static address *getAddress(const char *uri);
};
class __LOCAL config : public service
{
private:
typedef linked_value<profile_t, LinkedObject> profile;
class __LOCAL keymap : public LinkedObject
{
public:
service::keynode *node;
const char *id;
};
LinkedObject *keys[CONFIG_KEY_SIZE];
keynode **extmap;
keynode *provision;
LinkedObject *profiles;
bool create(const char *id, keynode *node);
keynode *find(const char *id);
bool confirm(void);
void dump(FILE *fp);
public:
config(char *id);
__EXPORT static void *allocate(size_t size);
__EXPORT static bool check(void);
__EXPORT static profile_t *getProfile(const char *id);
__EXPORT static keynode *getProvision(const char *id);
__EXPORT static keynode *getExtension(const char *id);
__EXPORT static void release(keynode *node);
__EXPORT static void reload(void);
__EXPORT static void utils(void);
__EXPORT static stack::address *getContact(const char *id);
};
class __LOCAL registry : private service::callback, private mapped_reuse<MappedRegistry>
{
private:
class __LOCAL target : public LinkedObject
{
public:
sockaddr_internet address, interface;
time_t expires;
};
class __LOCAL pattern : public LinkedObject
{
public:
MappedRegistry *registry;
unsigned priority;
char text[16];
};
class __LOCAL route : public LinkedObject
{
public:
pattern entry;
};
bool check(void);
bool reload(service *cfg);
void start(service *cfg);
void stop(service *cfg);
void snapshot(FILE *fp);
static void exclusive(MappedRegistry *rr);
static target *createTarget(void);
static route *createRoute(void);
static void expire(MappedRegistry *rr);
static MappedRegistry *find(const char *id);
static registry reg;
volatile time_t expires;
const char *digest;
const char *realm;
unsigned prefix;
unsigned range;
public:
registry();
inline static const char *getRealm(void)
{return reg.realm;};
inline static const char *getDigest(void)
{return reg.digest;};
inline static time_t getExpires(void)
{return reg.expires;};
inline static unsigned getPrefix(void)
{return reg.prefix;};
inline static unsigned getRange(void)
{return reg.range;};
inline void access(void)
{MappedReuse::access();};
inline void release(void)
{MappedReuse::release();};
__EXPORT static unsigned getEntries(void);
__EXPORT static unsigned getIndex(MappedRegistry *rr);
__EXPORT static unsigned setTargets(MappedRegistry *rr, stack::address *addr);
__EXPORT static unsigned addTarget(MappedRegistry *rr, stack::address *via, time_t expires);
__EXPORT static unsigned setTarget(MappedRegistry *rr, stack::address *via, time_t expires);
__EXPORT static MappedRegistry *extension(const char *id);
__EXPORT static MappedRegistry *create(const char *id);
__EXPORT static MappedRegistry *access(const char *id);
__EXPORT static MappedRegistry *modify(const char *id);
__EXPORT static void release(MappedRegistry *m);
__EXPORT static void update(MappedRegistry *m);
__EXPORT static bool remove(const char *id);
__EXPORT static void cleanup(void);
public:
// __EXPORT static ...
};
class __LOCAL thread : private DetachedThread
{
private:
friend class stack;
unsigned instance;
time_t current;
const char *identity;
service::keynode *config;
MappedRegistry *registry;
eXosip_event_t *sevent;
char buffer[256];
stack::address *via;
thread();
bool authenticate(void);
bool authorize(void);
void registration(void);
void reregister(time_t interval);
void deregister(void);
void challenge(void);
void options(void);
void run(void);
public:
__EXPORT static void shutdown(void);
};
END_NAMESPACE