rendered paste body/** @brief save_ports
*
*
*
* @param
*
* @return
*/
void save_ports( void )
{
lnode_t *pn;
port_list *pl;
static char ports[512];
static char tmpports[512];
int lasttype = -1;
SET_SEGV_LOCATION();
pn = list_first(opsb.ports);
while (pn) {
pl = lnode_get(pn);
/* if the port is different from the last round, and its not the first round, save it */
if ((pl->type != lasttype) && (lasttype != -1)) {
DBAStoreConfigStr(type_of_proxy(lasttype), ports, 512);
}
if (pl->type != lasttype) {
ircsnprintf(ports, 512, "%d", pl->port);
} else {
ircsnprintf(tmpports, 512, "%s %d", ports, pl->port);
strlcpy(ports, tmpports, 512);
}
lasttype = pl->type;
pn = list_next(opsb.ports, pn);
}
DBAStoreConfigStr(type_of_proxy(lasttype), ports, 512);
}
/** @brief load_port
*
*
*
* @param
*
* @return
*/
static void load_port(int type, const char *portname)
{
static char portlist[512];
char **av;
unsigned int j, ac;
port_list *prtlst;
SET_SEGV_LOCATION();
strlcpy (portlist, portname, 512);
ac = split_buf(portlist, &av);
for (j = 0; j < ac; j++) {
if (atoi(av[j]) == 0) {
nlog (LOG_WARNING, "Invalid port %s for proxy type %s", av[j], type_of_proxy(type));
continue;
}
if (list_isfull(opsb.ports)) {
nlog (LOG_WARNING, "Ports list is full.");
break;
}
prtlst = ns_malloc(sizeof(port_list));
prtlst->type = type;
prtlst->port = atoi(av[j]);
prtlst->numopen = 0;
lnode_create_append (opsb.ports, prtlst);
dlog (DEBUG1, "Added port %d for protocol %s", prtlst->port, type_of_proxy(type));
}
ns_free(av);
}
/** @brief load_ports
*
*
*
* @param
*
* @return
*/
int load_ports( void )
{
static char portname[512];
int i;
int ok = 0;
SET_SEGV_LOCATION();
for (i = 0; proxy_list[i].type != 0; i++) {
if (DBAFetchConfigStr (proxy_list[i].name, portname, 512) != NS_SUCCESS) {
nlog (LOG_WARNING, "Warning, no ports defined for protocol %s, using defaults", proxy_list[i].name);
load_port(proxy_list[i].type, defaultports[i]);
DBAStoreConfigStr(proxy_list[i].name, defaultports[i], 512);
ok = 1;
} else {
load_port(proxy_list[i].type, portname);
ok = 1;
}
}
return ( ok == 1 ) ? NS_SUCCESS : NS_FAILURE;
}