17 #include <sipwitch-config.h>
22 #define INDEX_SIZE 177
66 bool announce(
MappedRegistry *rr,
const char *msgtype,
const char *event,
const char *expires,
const char *body);
67 bool authenticate(
int id,
const char *remote_realm);
68 char *referLocal(
MappedRegistry *rr,
const char *target,
char *buffer,
size_t size);
76 shell::log(shell::INFO,
"%s\n",
77 _TEXT(
"server forward plugin loaded"));
82 realm = (
char *)
"GNU Telephony";
98 bool activeflag =
false;
100 linked_pointer<regmap> mp;
117 linked_pointer<regmap> mp;
122 if(mp->entry->rid ==
id)
132 linked_pointer<regmap> mp;
137 if(mp->entry->rid ==
id) {
148 linked_pointer<regmap> mp;
153 if(mp->entry->rid ==
id) {
165 linked_pointer<regmap> mp;
170 if(mp->entry->rid ==
id) {
172 prior->Next = mp->Next;
177 shell::debug(3,
"forward unmap %s from %d", mp->entry->userid,
id);
185 shell::debug(3,
"forward map %d not found",
id);
202 map->Next = index[path];
205 shell::debug(3,
"forward mapped %s as %d", rr->userid, rr->rid);
214 bool refering =
false;
217 char *tmp_realm = (
char *)realm, *tmp_digest = cfg->dup((
char *)digest);
218 char *tmp_schema = (
char *)
"sip";
220 linked_pointer<service::keynode> fp = cfg->
getList(
"forward");
221 linked_pointer<service::keynode> sp = cfg->
getList(
"registry");
225 value = sp->getPointer();
227 if(String::equal(key,
"digest"))
228 tmp_digest = cfg->dup(value);
229 else if(String::equal(key,
"realm"))
230 tmp_realm = cfg->dup(value);
239 value = fp->getPointer();
241 if(String::equal(key,
"refer")) {
242 if(resolver.
route(value, buffer,
sizeof(buffer))) {
243 refer = cfg->dup(buffer);
245 shell::debug(2,
"forward refer resolved as %s", buffer);
248 shell::log(shell::ERR,
"forward: %s: cannot resolve", value);
252 else if(String::equal(key,
"server")) {
253 tmp_context = resolver.
route(value, buffer,
sizeof(buffer));
255 server = cfg->dup(buffer);
256 shell::debug(2,
"forward server resolved as %s", buffer);
259 shell::log(shell::ERR,
"forward: %s: cannot resolve", value);
264 service::dialmode = service::EXT_DIALING;
267 else if(String::equal(key,
"expires"))
268 expires = atoi(value);
269 else if(String::equal(key,
"digest"))
270 tmp_digest = cfg->dup(value);
271 else if(String::equal(key,
"realm"))
272 tmp_realm = cfg->dup(value);
280 String::upper(tmp_digest);
282 context = tmp_context;
287 if(enable && !enabled)
288 shell::log(shell::INFO,
"server forward plugin activated");
289 else if(!enable && enabled)
290 shell::log(shell::INFO,
"server forward plugin disabled");
306 if(!enabled || rr->
rid != -1)
310 if(rr->
remote[0] && rr->
ext && rr->
type == MappedRegistry::USER) {
311 snprintf(uri,
sizeof(uri),
"%s:%s@%s", schema, rr->
userid,
server);
312 snprintf(reg,
sizeof(reg),
"%s:%s", schema,
server);
313 snprintf(contact,
sizeof(contact),
"%s:%s@", schema, rr->
remote);
314 len = strlen(contact);
315 Socket::query((
struct sockaddr *)&rr->
contact, contact + len,
sizeof(contact) - len);
316 len = strlen(contact);
317 snprintf(contact + len,
sizeof(contact) - len,
":%d", Socket::address::getPort((
struct sockaddr *)&rr->
contact));
318 shell::debug(3,
"registering %s with %s", contact,
server);
320 rr->
rid = voip::make_registry_request(context, uri, reg, contact, (
unsigned)expires, &msg);
321 if(rr->
rid != -1 && msg) {
322 voip::server_supports(msg,
"100rel");
323 voip::header(msg,
"Event",
"Registration");
324 voip::header(msg,
"Allow-Events",
"presence");
325 voip::send_registry_request(context, rr->
rid, msg);
331 bool forward::announce(
MappedRegistry *rr,
const char *msgtype,
const char *event,
const char *expiration,
const char *body)
340 snprintf(uri_to,
sizeof(uri_to),
"sip:%s@%s", rr->
userid,
server);
341 snprintf(contact,
sizeof(contact),
"sip:%s@", rr->
remote);
342 len = strlen(contact);
343 Socket::query((
struct sockaddr *)&rr->
contact, contact + len,
sizeof(contact) - len);
344 len = strlen(contact);
345 snprintf(contact + len,
sizeof(contact) - len,
":%d", Socket::address::getPort((
struct sockaddr *)&rr->
contact));
346 shell::debug(3,
"publishing %s with %s", contact,
server);
348 voip::publish(context, uri_to, contact, event, expiration, msgtype, body);
364 voip::release_registry(context,
id);
367 char *forward::referLocal(
MappedRegistry *rr,
const char *target,
char *buffer,
size_t size)
372 if(!isActive(rr->
rid))
376 snprintf(buffer, size,
"sips:%s@%s", target, refer);
378 snprintf(buffer, size,
"sip:%s@%s", target, refer);
382 bool forward::authenticate(
int id,
const char *remote_realm)
386 const char *secret = NULL;
395 node = service::getUser(rr->
userid);
397 leaf = node->leaf(
"secret");
399 secret = leaf->getPointer();
402 if(secret && *secret)
403 shell::debug(3,
"authorizing %s for %s", rr->
userid, remote_realm);
405 shell::debug(3,
"cannot authorize %s for %s", rr->
userid, remote_realm);
406 service::release(node);
411 voip::add_authentication(context, rr->
userid, secret, remote_realm,
true);
412 service::release(node);
420 case modules::REG_FAILED:
423 case modules::REG_SUCCESS:
Structure for SIP Message (REQUEST and RESPONSE).
void activate(voip::reg_t id)
Some convenience methods for manipulating SIP uri's.
void add(MappedRegistry *rr)
Representation of a mapped active user record.
sockaddr_internet contact
keynode * getList(const char *path)
bool isActive(voip::reg_t id)
void releaseMap(MappedRegistry *rr)
Top level include directory for GNU Telephony SIP Witch Server.
void remove(voip::reg_t id)
voip::context_t route(const char *uri, char *buf, size_t size)
System configuration instance and service functions.
Common interfaces and clases for plugins.
Common base class for sipwitch plugin services.
treemap< char * > keynode
Definition of a xml node.
MappedRegistry * find(voip::reg_t id)
enum sipwitch::MappedRegistry::@5 type
void disable(voip::reg_t id)