17 #include <sipwitch-config.h>
19 #include <ucommon/secure.h>
24 static class __LOCAL subscriber :
private modules::sipwitch
27 static subscriber _sub;
30 bool authenticate(
voip::reg_t id,
const char *remote_realm);
36 void reload(service *cfg);
37 void start(service *cfg);
38 void stop(service *cfg);
39 void snapshot(FILE *fp);
42 static volatile bool changed =
false;
43 static volatile timeout_t interval = 50;
44 static volatile time_t refresh = 60;
45 static volatile time_t updated = 0;
46 static int priority = 0;
47 static const char *iface = NULL;
48 static char *server = NULL;
49 static char *proxy = NULL;
50 static char *userid = NULL;
51 static char *schema = (
char *)
"sip";
52 static char *
volatile secret = NULL;
53 static char *identity = NULL;
55 static MappedRegistry provider;
56 static unsigned short port = 9000;
58 subscriber::subscriber() :
61 zero_unsafe<MappedRegistry>(provider);
68 void subscriber::update(
void)
74 Socket::address dest = server;
76 Random::uuid(provider.
remote);
77 snprintf(uri,
sizeof(uri),
"%s:%s@%s", schema, userid, server);
78 snprintf(reg,
sizeof(reg),
"%s:%s", schema, server);
79 snprintf(contact,
sizeof(contact),
"%s:%s@", schema, provider.
remote);
82 len = strlen(contact);
83 Socket::via((
struct sockaddr *)&provider.
contact, dest.getAddr());
84 Socket::query((
struct sockaddr *)&provider.
contact, contact + len,
sizeof(contact) - len);
85 len = strlen(contact);
86 snprintf(contact + len,
sizeof(contact) - len,
":%u", sip_port);
87 shell::debug(3,
"registering %s with %s", contact, server);
91 if(provider.
rid == -1 || !msg)
102 void subscriber::start(service *cfg)
114 void subscriber::stop(service *cfg)
116 if(provider.
rid != -1)
122 void subscriber::snapshot(FILE *fp)
126 fprintf(fp,
"subscriber:\n");
129 void subscriber::reload(service *cfg)
134 const char *key = NULL, *
value;
135 linked_pointer<service::keynode> sp = cfg->getList(
"subscriber");
144 value = sp->getPointer();
146 if(!stricmp(key,
"count") && !is_configured())
148 else if(!stricmp(key,
"interface") && !is_configured())
149 iface = strdup(value);
150 else if(!stricmp(key,
"interval"))
151 interval = atol(value);
152 else if(!stricmp(key,
"priority") && !is_configured())
153 priority = atoi(value);
154 else if(!stricmp(key,
"port") && !is_configured())
157 else if(!stricmp(key,
"network"))
159 else if(!stricmp(key,
"refresh"))
160 refresh = atoi(value);
161 else if(!stricmp(key,
"registrar") || !stricmp(key,
"server")) {
162 tmp_context = resolver.route(value, buffer,
sizeof(buffer));
165 server = cfg->dup(buffer);
166 shell::debug(2,
"subscriber provider is %s", buffer);
170 shell::log(shell::ERR,
"subscriber: %s: cannot resolve", value);
173 else if(!stricmp(key,
"proxy")) {
175 proxy = strdup(value);
179 else if(!stricmp(key,
"userid")) {
181 userid = strdup(value);
185 else if(!stricmp(key,
"secret")) {
187 secret = strdup(value);
191 else if(!stricmp(key,
"identity")) {
193 identity = strdup(value);
202 context = tmp_context;
204 if(!is_configured() &&
count)
210 if(
id == -1 ||
id != provider.
rid)
215 shell::log(shell::ERR,
"service provider failed");
222 shell::log(shell::NOTIFY,
"service provider active");
228 bool subscriber::authenticate(
voip::reg_t id,
const char *remote_realm)
230 if(
id == -1 ||
id != provider.
rid)
233 if(secret && *secret)
234 shell::debug(3,
"authorizing %s for %s", userid, remote_realm);
236 shell::debug(3,
"cannot authorize %s for %s", userid, remote_realm);
static void add_authentication(context_t ctx, const char *user, const char *secret, const char *realm, bool automatic=false)
sockaddr_internet contact
static void send_registry_request(context_t ctx, reg_t rid, msg_t msg)
union sipwitch::MappedRegistry::@6 source
Top level include directory for GNU Telephony SIP Witch Server.
static stats * request(const char *id)
Request a stat node from the memory pool by id.
static void server_supports(voip::msg_t msg, const char *txt)
struct sipwitch::MappedRegistry::@6::@7 external
static reg_t make_registry_request(context_t ctx, const char *uri, const char *s, const char *c, unsigned exp, msg_t *msg)
static void allocate(unsigned count)
Server allocate x number of stat nodes at startup.
static void header(msg_t msg, const char *key, const char *value)
enum sipwitch::MappedRegistry::@5 type
static bool release_registry(context_t ctx, reg_t rid)