Code cleanup
This commit is contained in:
parent
786e786557
commit
15bc0fcc93
@ -103,10 +103,8 @@ void receiver(struct servent *);
|
|||||||
void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd)
|
void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd)
|
||||||
{
|
{
|
||||||
ncs_list *tmp, *ta;
|
ncs_list *tmp, *ta;
|
||||||
int rc;
|
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
pthread_mutex_lock(&b_mutex);
|
||||||
Syslog('!', "fill_ncslist() mutex_lock failed rc=%d", rc);
|
|
||||||
|
|
||||||
tmp = (ncs_list *)malloc(sizeof(ncs_list));
|
tmp = (ncs_list *)malloc(sizeof(ncs_list));
|
||||||
memset(tmp, 0, sizeof(tmp));
|
memset(tmp, 0, sizeof(tmp));
|
||||||
@ -127,15 +125,15 @@ void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd)
|
|||||||
if (*fdp == NULL) {
|
if (*fdp == NULL) {
|
||||||
*fdp = tmp;
|
*fdp = tmp;
|
||||||
} else {
|
} else {
|
||||||
for (ta = *fdp; ta; ta = ta->next)
|
for (ta = *fdp; ta; ta = ta->next) {
|
||||||
if (ta->next == NULL) {
|
if (ta->next == NULL) {
|
||||||
ta->next = (ncs_list *)tmp;
|
ta->next = (ncs_list *)tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
pthread_mutex_unlock(&b_mutex);
|
||||||
Syslog('!', "fill_ncslist() mutex_unlock failed rc=%d", rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -223,7 +221,6 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
|
|||||||
{
|
{
|
||||||
usr_list *tmp, *ta;
|
usr_list *tmp, *ta;
|
||||||
srv_list *sl;
|
srv_list *sl;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('r', "add_user %s %s %s", server, name, realname);
|
Syslog('r', "add_user %s %s %s", server, name, realname);
|
||||||
|
|
||||||
@ -234,8 +231,7 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
pthread_mutex_lock(&b_mutex);
|
||||||
Syslog('!', "add_user() mutex_lock failed rc=%d", rc);
|
|
||||||
|
|
||||||
tmp = (usr_list *)malloc(sizeof(usr_list));
|
tmp = (usr_list *)malloc(sizeof(usr_list));
|
||||||
memset(tmp, 0, sizeof(usr_list));
|
memset(tmp, 0, sizeof(usr_list));
|
||||||
@ -249,12 +245,13 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
|
|||||||
if (*fap == NULL) {
|
if (*fap == NULL) {
|
||||||
*fap = tmp;
|
*fap = tmp;
|
||||||
} else {
|
} else {
|
||||||
for (ta = *fap; ta; ta = ta->next)
|
for (ta = *fap; ta; ta = ta->next) {
|
||||||
if (ta->next == NULL) {
|
if (ta->next == NULL) {
|
||||||
ta->next = (usr_list *)tmp;
|
ta->next = (usr_list *)tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (sl = servers; sl; sl = sl->next) {
|
for (sl = servers; sl; sl = sl->next) {
|
||||||
if (strcmp(sl->server, server) == 0) {
|
if (strcmp(sl->server, server) == 0) {
|
||||||
@ -263,8 +260,7 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
pthread_mutex_unlock(&b_mutex);
|
||||||
Syslog('!', "add_user() mutex_unlock failed rc=%d", rc);
|
|
||||||
|
|
||||||
usrchg = TRUE;
|
usrchg = TRUE;
|
||||||
return 0;
|
return 0;
|
||||||
@ -279,7 +275,6 @@ void del_user(usr_list **fap, char *server, char *name)
|
|||||||
{
|
{
|
||||||
usr_list **tmp, *tmpa;
|
usr_list **tmp, *tmpa;
|
||||||
srv_list *sl;
|
srv_list *sl;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('r', "deluser %s %s", server, printable(name, 0));
|
Syslog('r', "deluser %s %s", server, printable(name, 0));
|
||||||
|
|
||||||
@ -287,8 +282,7 @@ void del_user(usr_list **fap, char *server, char *name)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
pthread_mutex_lock(&b_mutex);
|
||||||
Syslog('!', "del_user() mutex_lock failed rc=%d", rc);
|
|
||||||
|
|
||||||
tmp = fap;
|
tmp = fap;
|
||||||
while (*tmp) {
|
while (*tmp) {
|
||||||
@ -316,8 +310,7 @@ void del_user(usr_list **fap, char *server, char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
pthread_mutex_unlock(&b_mutex);
|
||||||
Syslog('!', "del_user() mutex_unlock failed rc=%d", rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -328,7 +321,6 @@ void del_user(usr_list **fap, char *server, char *name)
|
|||||||
int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
||||||
{
|
{
|
||||||
chn_list *tmp, *ta;
|
chn_list *tmp, *ta;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('r', "add_channel %s %s %s", name, owner, server);
|
Syslog('r', "add_channel %s %s %s", name, owner, server);
|
||||||
|
|
||||||
@ -339,8 +331,7 @@ int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
pthread_mutex_lock(&b_mutex);
|
||||||
Syslog('!', "add_channel() mutex_lock failed rc=%d", rc);
|
|
||||||
|
|
||||||
tmp = (chn_list *)malloc(sizeof(chn_list));
|
tmp = (chn_list *)malloc(sizeof(chn_list));
|
||||||
memset(tmp, 0, sizeof(chn_list));
|
memset(tmp, 0, sizeof(chn_list));
|
||||||
@ -354,15 +345,15 @@ int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
|||||||
if (*fap == NULL) {
|
if (*fap == NULL) {
|
||||||
*fap = tmp;
|
*fap = tmp;
|
||||||
} else {
|
} else {
|
||||||
for (ta = *fap; ta; ta = ta->next)
|
for (ta = *fap; ta; ta = ta->next) {
|
||||||
if (ta->next == NULL) {
|
if (ta->next == NULL) {
|
||||||
ta->next = (chn_list *)tmp;
|
ta->next = (chn_list *)tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
pthread_mutex_unlock(&b_mutex);
|
||||||
Syslog('!', "add_channel() mutex_unlock failed rc=%d", rc);
|
|
||||||
|
|
||||||
chnchg = TRUE;
|
chnchg = TRUE;
|
||||||
return 0;
|
return 0;
|
||||||
@ -373,15 +364,13 @@ int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
|||||||
void del_channel(chn_list **fap, char *name)
|
void del_channel(chn_list **fap, char *name)
|
||||||
{
|
{
|
||||||
chn_list **tmp, *tmpa;
|
chn_list **tmp, *tmpa;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('r', "del_channel %s", name);
|
Syslog('r', "del_channel %s", name);
|
||||||
|
|
||||||
if (*fap == NULL)
|
if (*fap == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
pthread_mutex_lock(&b_mutex);
|
||||||
Syslog('!', "del_channel() mutex_lock failed rc=%d", rc);
|
|
||||||
|
|
||||||
tmp = fap;
|
tmp = fap;
|
||||||
while (*tmp) {
|
while (*tmp) {
|
||||||
@ -395,8 +384,7 @@ void del_channel(chn_list **fap, char *name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
pthread_mutex_unlock(&b_mutex);
|
||||||
Syslog('!', "del_channel() mutex_unlock failed rc=%d", rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -404,7 +392,6 @@ void del_channel(chn_list **fap, char *name)
|
|||||||
void add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, char *fullname, char *router)
|
void add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, char *fullname, char *router)
|
||||||
{
|
{
|
||||||
srv_list *tmp, *ta;
|
srv_list *tmp, *ta;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('r', "add_server %s %d %s %s %s", name, hops, prod, vers, fullname);
|
Syslog('r', "add_server %s %d %s %s %s", name, hops, prod, vers, fullname);
|
||||||
|
|
||||||
@ -415,8 +402,7 @@ void add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
pthread_mutex_lock(&b_mutex);
|
||||||
Syslog('!', "add_server() mutex_lock failed rc=%d", rc);
|
|
||||||
|
|
||||||
tmp = (srv_list *)malloc(sizeof(srv_list));
|
tmp = (srv_list *)malloc(sizeof(srv_list));
|
||||||
memset(tmp, 0, sizeof(tmp));
|
memset(tmp, 0, sizeof(tmp));
|
||||||
@ -433,16 +419,15 @@ void add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, ch
|
|||||||
if (*fdp == NULL) {
|
if (*fdp == NULL) {
|
||||||
*fdp = tmp;
|
*fdp = tmp;
|
||||||
} else {
|
} else {
|
||||||
for (ta = *fdp; ta; ta = ta->next)
|
for (ta = *fdp; ta; ta = ta->next) {
|
||||||
if (ta->next == NULL) {
|
if (ta->next == NULL) {
|
||||||
ta->next = (srv_list *)tmp;
|
ta->next = (srv_list *)tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
pthread_mutex_unlock(&b_mutex);
|
||||||
Syslog('!', "add_server() mutex_unlock failed rc=%d", rc);
|
|
||||||
|
|
||||||
srvchg = TRUE;
|
srvchg = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,15 +439,13 @@ void add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, ch
|
|||||||
void del_server(srv_list **fap, char *name)
|
void del_server(srv_list **fap, char *name)
|
||||||
{
|
{
|
||||||
srv_list *ta, *tan;
|
srv_list *ta, *tan;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('r', "delserver %s", name);
|
Syslog('r', "delserver %s", name);
|
||||||
|
|
||||||
if (*fap == NULL)
|
if (*fap == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
pthread_mutex_lock(&b_mutex);
|
||||||
Syslog('!', "del_server() mutex_lock failed rc=%d", rc);
|
|
||||||
|
|
||||||
for (ta = *fap; ta; ta = ta->next) {
|
for (ta = *fap; ta; ta = ta->next) {
|
||||||
while ((tan = ta->next) && (strcmp(tan->server, name) == 0)) {
|
while ((tan = ta->next) && (strcmp(tan->server, name) == 0)) {
|
||||||
@ -473,8 +456,7 @@ void del_server(srv_list **fap, char *name)
|
|||||||
ta->next = tan;
|
ta->next = tan;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
pthread_mutex_unlock(&b_mutex);
|
||||||
Syslog('!', "del_server() mutex_unlock failed rc=%d", rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -485,15 +467,13 @@ void del_server(srv_list **fap, char *name)
|
|||||||
void del_router(srv_list **fap, char *name)
|
void del_router(srv_list **fap, char *name)
|
||||||
{
|
{
|
||||||
srv_list *ta, *tan;
|
srv_list *ta, *tan;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('r', "delrouter %s", name);
|
Syslog('r', "delrouter %s", name);
|
||||||
|
|
||||||
if (*fap == NULL)
|
if (*fap == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
pthread_mutex_lock(&b_mutex);
|
||||||
Syslog('!', "del_router() mutex_lock failed rc=%d", rc);
|
|
||||||
|
|
||||||
for (ta = *fap; ta; ta = ta->next) {
|
for (ta = *fap; ta; ta = ta->next) {
|
||||||
while ((tan = ta->next) && (strcmp(tan->router, name) == 0)) {
|
while ((tan = ta->next) && (strcmp(tan->router, name) == 0)) {
|
||||||
@ -505,8 +485,7 @@ void del_router(srv_list **fap, char *name)
|
|||||||
ta->next = tan;
|
ta->next = tan;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
pthread_mutex_unlock(&b_mutex);
|
||||||
Syslog('!', "del_router() mutex_unlock failed rc=%d", rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -570,7 +549,7 @@ int send_msg(ncs_list *tnsl, const char *format, ...)
|
|||||||
Syslog('r', "> %s: %s", tnsl->server, printable(buf, 0));
|
Syslog('r', "> %s: %s", tnsl->server, printable(buf, 0));
|
||||||
|
|
||||||
if (sendto(tnsl->socket, buf, strlen(buf), 0, (struct sockaddr *)&tnsl->servaddr_in, sizeof(struct sockaddr_in)) == -1) {
|
if (sendto(tnsl->socket, buf, strlen(buf), 0, (struct sockaddr *)&tnsl->servaddr_in, sizeof(struct sockaddr_in)) == -1) {
|
||||||
Syslog('r', "$IBC: can't send message");
|
Syslog('!', "$IBC: can't send message");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -607,7 +586,6 @@ void check_servers(void)
|
|||||||
fread(&ibcsrvhdr, sizeof(ibcsrvhdr), 1, fp);
|
fread(&ibcsrvhdr, sizeof(ibcsrvhdr), 1, fp);
|
||||||
|
|
||||||
while (fread(&ibcsrv, ibcsrvhdr.recsize, 1, fp)) {
|
while (fread(&ibcsrv, ibcsrvhdr.recsize, 1, fp)) {
|
||||||
Syslog('r', "IBC server \"%s\", Active %s", ibcsrv.server, ibcsrv.Active ?"Yes":"No");
|
|
||||||
if (ibcsrv.Active) {
|
if (ibcsrv.Active) {
|
||||||
inlist = FALSE;
|
inlist = FALSE;
|
||||||
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
|
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
|
||||||
@ -616,10 +594,9 @@ void check_servers(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!inlist ) {
|
if (!inlist ) {
|
||||||
Syslog('r', " not in neighbour list, add");
|
|
||||||
fill_ncslist(&ncsl, ibcsrv.server, ibcsrv.myname, ibcsrv.passwd);
|
fill_ncslist(&ncsl, ibcsrv.server, ibcsrv.myname, ibcsrv.passwd);
|
||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
Syslog('+', "IBC: added Internet BBS Chatserver %s", ibcsrv.server);
|
Syslog('+', "IBC: new configured Internet BBS Chatserver: %s", ibcsrv.server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -630,7 +607,6 @@ void check_servers(void)
|
|||||||
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
|
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
|
||||||
fseek(fp, ibcsrvhdr.hdrsize, SEEK_SET);
|
fseek(fp, ibcsrvhdr.hdrsize, SEEK_SET);
|
||||||
inlist = FALSE;
|
inlist = FALSE;
|
||||||
Syslog('r', "IBC server \"%s\"", ibcsrv.server);
|
|
||||||
|
|
||||||
while (fread(&ibcsrv, ibcsrvhdr.recsize, 1, fp)) {
|
while (fread(&ibcsrv, ibcsrvhdr.recsize, 1, fp)) {
|
||||||
if ((strcmp(tnsl->server, ibcsrv.server) == 0) && ibcsrv.Active) {
|
if ((strcmp(tnsl->server, ibcsrv.server) == 0) && ibcsrv.Active) {
|
||||||
@ -638,7 +614,7 @@ void check_servers(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!inlist) {
|
if (!inlist) {
|
||||||
Syslog('r', " not in configuration, remove");
|
Syslog('+', "IBC: server %s removed from configuration", tnsl->server);
|
||||||
tnsl->remove = TRUE;
|
tnsl->remove = TRUE;
|
||||||
tnsl->action = now;
|
tnsl->action = now;
|
||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
@ -994,7 +970,7 @@ int command_squit(char *hostname, char *parameters)
|
|||||||
message = strtok(NULL, "\0");
|
message = strtok(NULL, "\0");
|
||||||
|
|
||||||
if (strcmp(name, tnsl->server) == 0) {
|
if (strcmp(name, tnsl->server) == 0) {
|
||||||
Syslog('+', "IBC: disconnect server %s: %s", name, message);
|
Syslog('+', "IBC: disconnect neighbour server %s: %s", name, message);
|
||||||
tnsl->state = NCS_HANGUP;
|
tnsl->state = NCS_HANGUP;
|
||||||
tnsl->action = now + (time_t)120; // 2 minutes delay before calling again.
|
tnsl->action = now + (time_t)120; // 2 minutes delay before calling again.
|
||||||
tnsl->gotpass = FALSE;
|
tnsl->gotpass = FALSE;
|
||||||
@ -1002,7 +978,7 @@ int command_squit(char *hostname, char *parameters)
|
|||||||
tnsl->token = 0;
|
tnsl->token = 0;
|
||||||
del_router(&servers, name);
|
del_router(&servers, name);
|
||||||
} else {
|
} else {
|
||||||
Syslog('r', "IBC: disconnect server %s: message is not for us, but update database", name);
|
Syslog('+', "IBC: disconnect relay server %s: %s", name, message);
|
||||||
del_server(&servers, name);
|
del_server(&servers, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1064,10 +1040,8 @@ int command_quit(char *hostname, char *parameters)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
send_all("NOTICE * ** %s is leaving: %s\r\n", name, message);
|
|
||||||
system_shout("* User %s is leaving: %s", name, message);
|
system_shout("* User %s is leaving: %s", name, message);
|
||||||
} else {
|
} else {
|
||||||
send_all("NOTICE * ** %s is leaving: Quit\r\n", name);
|
|
||||||
system_shout("* User %s is leaving", name);
|
system_shout("* User %s is leaving", name);
|
||||||
}
|
}
|
||||||
del_user(&users, server, name);
|
del_user(&users, server, name);
|
||||||
@ -1438,7 +1412,7 @@ void receiver(struct servent *se)
|
|||||||
hostname = hp->h_name;
|
hostname = hp->h_name;
|
||||||
|
|
||||||
if ((crbuf[strlen(crbuf) -2] != '\r') && (crbuf[strlen(crbuf) -1] != '\n')) {
|
if ((crbuf[strlen(crbuf) -2] != '\r') && (crbuf[strlen(crbuf) -1] != '\n')) {
|
||||||
Syslog('r', "Message not terminated with CR-LF, dropped");
|
Syslog('!', "IBC: got message not terminated with CR-LF, dropped");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user