- have registrations persistent across restarts of

the daemon ('registration_file' config option)
This commit is contained in:
Thomas Ries
2003-12-04 21:18:19 +00:00
parent d92bc2b711
commit 0170015955
7 changed files with 118 additions and 11 deletions
+2
View File
@@ -1,5 +1,7 @@
0.5.1
=====
04-Dec-2003: - have registrations persistent across restarts of
the daemon ('registration_file' config option)
29-Nov-2003: - some documentation & FAQ updates
0.5.0
+7 -1
View File
@@ -67,6 +67,12 @@ silence_log = 0
user = nobody
#chrootjail = /var/lib/siproxd/
######################################################################
# Registration file:
# Where to store the current registrations
# empty means we do not save registrations
registration_file = /var/lib/siproxd/siproxd_registrations
######################################################################
# global switch to control the RTP proxy behaviour
# 0 - RTP proxy disabled
@@ -152,7 +158,7 @@ debug_level = 0x00000000
#
# Siproxd itself can be told to send all traffic to another
# outbound proxy.
# You can use this feature to 'chain' multiple siproxd proxys
# You can use this feature to 'chain' multiple siproxd proxies
# if you have several masquerading firewalls to cross.
#
# outbound_proxy_host = my.outboundproxy.org
+2 -2
View File
@@ -662,9 +662,9 @@ if (configuration.debuglevel)
/*
* PROXY_REWRITE_INVITATION_BODY
* PROXY_REWRITE_REQUEST_URI
*
* rewrites the outgoing INVITATION packet
* rewrites the incoming Request URI
*
* RETURNS
* STS_SUCCESS on success
+1
View File
@@ -147,6 +147,7 @@ static int parse_config (FILE *configfile) {
{ "masked_host", TYP_STRINGA,&configuration.masked_host },
{ "outbound_proxy_host", TYP_STRING, &configuration.outbound_proxy_host },
{ "outbound_proxy_port", TYP_INT4, &configuration.outbound_proxy_port },
{ "registration_file", TYP_STRING ,&configuration.registrationfile },
{0, 0, 0}
};
+98 -4
View File
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
@@ -45,13 +46,106 @@ static char const ident[]="$Id: " __FILE__ ": " PACKAGE "-" VERSION "-"\
extern struct siproxd_config configuration;
struct urlmap_s urlmap[URLMAP_SIZE]; /* URL mapping table */
extern int sip_socket; /* sending SIP datagrams */
extern int errno;
/*
* initialize the URL mapping table
*/
void register_init(void) {
memset (urlmap, 0, sizeof(urlmap));
FILE *stream;
int sts, size, i;
char buff[128];
memset(urlmap, 0, sizeof(urlmap));
if (configuration.registrationfile) {
stream = fopen(configuration.registrationfile, "r");
if (!stream) {
/*
* the file does not exist, or the size was incorrect,
* delete it and start from scratch
*/
unlink(configuration.registrationfile);
WARN("registration file not found, starting with empty table");
} else {
/* read the url table from file */
for (i=0;i < URLMAP_SIZE; i++) {
fgets(buff, sizeof(buff), stream);
sts=sscanf(buff, "***:%i:%i", &urlmap[i].active, &urlmap[i].expires);
if (urlmap[i].active) {
osip_uri_init(&urlmap[i].true_url);
osip_uri_init(&urlmap[i].masq_url);
osip_uri_init(&urlmap[i].reg_url);
#define R(X) {\
fgets(buff, sizeof(buff), stream);\
buff[sizeof(buff)-1]='\0';\
if (strchr(buff, 10)) *strchr(buff, 10)='\0';\
if (strchr(buff, 13)) *strchr(buff, 13)='\0';\
if (strlen(buff) > 0) {\
size = strnlen(buff, sizeof(buff));\
X =(char*)malloc(size);\
sts=sscanf(buff,"%s",X);\
} else {\
X = NULL;\
}\
}
R(urlmap[i].true_url->scheme);
R(urlmap[i].true_url->username);
R(urlmap[i].true_url->host);
R(urlmap[i].true_url->port);
R(urlmap[i].masq_url->scheme);
R(urlmap[i].masq_url->username);
R(urlmap[i].masq_url->host);
R(urlmap[i].masq_url->port);
R(urlmap[i].reg_url->scheme);
R(urlmap[i].reg_url->username);
R(urlmap[i].reg_url->host);
R(urlmap[i].reg_url->port);
}
}
}
}
return;
}
/*
* shut down the URL mapping table
*/
void register_shut(void) {
int i;
FILE *stream;
if (configuration.registrationfile) {
/* write urlmap back to file */
stream = fopen(configuration.registrationfile, "w+");
for (i=0;i < URLMAP_SIZE; i++) {
fprintf(stream, "***:%i:%i\n", urlmap[i].active, urlmap[i].expires);
if (urlmap[i].active) {
#define W(X) fprintf(stream, "%s\n", (X)? X:"");
W(urlmap[i].true_url->scheme);
W(urlmap[i].true_url->username);
W(urlmap[i].true_url->host);
W(urlmap[i].true_url->port);
W(urlmap[i].masq_url->scheme);
W(urlmap[i].masq_url->username);
W(urlmap[i].masq_url->host);
W(urlmap[i].masq_url->port);
W(urlmap[i].reg_url->scheme);
W(urlmap[i].reg_url->username);
W(urlmap[i].reg_url->host);
W(urlmap[i].reg_url->port);
}
}
fclose(stream);
}
return;
}
@@ -226,8 +320,8 @@ int register_client(osip_message_t *my_msg, int force_lcl_masq) {
}
/* remember the VIA for later use */
osip_via_clone( ((osip_via_t*)(my_msg->vias->node->element)),
&urlmap[i].via);
// osip_via_clone( ((osip_via_t*)(my_msg->vias->node->element)),
// &urlmap[i].via);
} /* if new entry */
/* give some safety margin for the next update */
@@ -259,7 +353,7 @@ void register_agemap(void) {
osip_uri_free(urlmap[i].true_url);
osip_uri_free(urlmap[i].masq_url);
osip_uri_free(urlmap[i].reg_url);
osip_via_free(urlmap[i].via);
// osip_via_free(urlmap[i].via);
}
}
return;
+5 -3
View File
@@ -202,9 +202,6 @@ INFO("daemonizing done (pid=%i)", getpid());
/* init the oSIP parser */
parser_init();
/* initialize the registration facility */
register_init();
/* listen for incoming messages */
sts=sipsock_listen();
if (sts == STS_FAILURE) {
@@ -213,6 +210,9 @@ INFO("daemonizing done (pid=%i)", getpid());
exit(1);
}
/* initialize the registration facility */
register_init();
INFO(PACKAGE"-"VERSION"-"BUILDSTR" started");
/*
* silence the log - if so required...
@@ -382,6 +382,8 @@ INFO("got packet [%i bytes]from %s [%s]", i,
} /* while TRUE */
exit_prg:
register_shut();
INFO("properly terminating siproxd");
return 0;
+3 -1
View File
@@ -34,6 +34,7 @@ int sockbind(struct in_addr ipaddr, int localport, int errflg);
/* register.c */
void register_init(void);
void register_shut(void);
int register_client(osip_message_t *request, int force_lcl_masq); /*X*/
void register_agemap(void);
int register_response(osip_message_t *request, int flag); /*X*/
@@ -98,7 +99,7 @@ struct urlmap_s {
osip_uri_t *true_url; // true URL of UA (inbound URL)
osip_uri_t *masq_url; // masqueraded URL (outbound URL)
osip_uri_t *reg_url; // registered URL (masq URL as wished by UA)
osip_via_t *via;
// osip_via_t *via;
};
/*
* the difference between masq_url and reg_url is,
@@ -143,6 +144,7 @@ struct siproxd_config {
stringa_t masked_host;
char *outbound_proxy_host;
int outbound_proxy_port;
char *registrationfile;
};