Added crc32 value to server state table

This commit is contained in:
Michiel Broek 2005-12-17 16:35:10 +00:00
parent f9d1614e2d
commit 42a5043091
3 changed files with 29 additions and 3 deletions

View File

@ -119,3 +119,19 @@ unsigned int StringCRC32(char *str)
/*
* Update CRC32, first initialize crc with 0xffffffff
*/
unsigned int upd_crc32(char *buf, unsigned int crc, int len)
{
int i;
unsigned int cr;
cr = crc;
for (i = 0; i < len; i++) {
cr = (crc32tab[((int)cr ^ ((int)buf[i])) & 0xff] ^ ((((unsigned int)cr) >> 8) & 0x00ffffffL));
}
return cr;
}

View File

@ -60,6 +60,7 @@ int chnchg = FALSE; /* Is channellist changed */
int banchg = FALSE; /* Is banned users changed */
int nickchg = FALSE; /* Is nicknames changed */
#define PING_PONG_LOG 1
pthread_mutex_t b_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -78,7 +79,7 @@ static char *ncsstate[] = {
/*
* Internal prototypes
*/
void fill_ncslist(ncs_list **, char *, char *, char *, int);
void fill_ncslist(ncs_list **, char *, char *, char *, int, unsigned int);
void dump_ncslist(void);
void tidy_servers(srv_list **);
int add_server(srv_list **, char *, int, char *, char *, char *, char *);
@ -104,7 +105,7 @@ void receiver(struct servent *);
/*
* Add a server to the serverlist
*/
void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int dyndns)
void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int dyndns, unsigned int crc)
{
ncs_list *tmp, *ta;
@ -128,6 +129,7 @@ void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int
tmp->gotserver = FALSE;
tmp->dyndns = dyndns;
tmp->halfdead = 0;
tmp->crc = crc;
if (*fdp == NULL) {
*fdp = tmp;
@ -608,6 +610,7 @@ void check_servers(void)
srv_list *srv;
int j, inlist, Remove;
int a1, a2, a3, a4;
unsigned int crc;
struct servent *se;
struct hostent *he;
@ -630,6 +633,12 @@ void check_servers(void)
fread(&ibcsrvhdr, sizeof(ibcsrvhdr), 1, fp);
while (fread(&ibcsrv, ibcsrvhdr.recsize, 1, fp)) {
crc = 0xffffffff;
crc = upd_crc32((char *)&ibcsrv, crc, sizeof(ibcsrv));
/*
* Check for new configured servers
*/
if (ibcsrv.Active) {
inlist = FALSE;
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
@ -645,7 +654,7 @@ void check_servers(void)
}
}
if (!inlist ) {
fill_ncslist(&ncsl, ibcsrv.server, ibcsrv.myname, ibcsrv.passwd, ibcsrv.Dyndns);
fill_ncslist(&ncsl, ibcsrv.server, ibcsrv.myname, ibcsrv.passwd, ibcsrv.Dyndns, crc);
srvchg = TRUE;
callchg = TRUE;
Syslog('+', "IBC: new configured Internet BBS Chatserver: %s", ibcsrv.server);

View File

@ -26,6 +26,7 @@ typedef struct _ncs_list {
int socket; /* Peer socket */
unsigned int token; /* Server token */
int halfdead; /* Halfdead connect count */
unsigned int crc; /* CRC value of record */
} ncs_list;