Added calllist option to nlookup, fixed bunch of PVS-Studio lint warnings
This commit is contained in:
parent
7903fd08af
commit
81b326ca45
@ -354,6 +354,77 @@ int nodelist_parsestring(s_node *node, char *str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Hidden adresses adder
|
||||
*
|
||||
* Arguments:
|
||||
* node a node for which we add HIDDEN lines with IpAddr
|
||||
* str pointer to the flags string
|
||||
*
|
||||
* Return value:
|
||||
* -1 if error
|
||||
* zero value if string had no hidden INA:, pos - num of INA's above
|
||||
* first
|
||||
*/
|
||||
|
||||
int nodelist_parsehiddenina(s_node *node,s_override *ov) {
|
||||
|
||||
int rc = 0;
|
||||
s_override *ovr;
|
||||
s_override *ovrbase = ov;
|
||||
|
||||
|
||||
char *tmp, *p, *q;
|
||||
const char *searchbase = node->flags;
|
||||
int flaglen = 3;
|
||||
|
||||
tmp = xmalloc(BNI_MAXHOST+1);
|
||||
|
||||
while( p = strstr(searchbase, "INA") )
|
||||
{
|
||||
if( p == node->flags || *(p-1) == ',' ) // match flag
|
||||
{
|
||||
if( *(p+flaglen) == 0 || *(p+flaglen) == ',' )
|
||||
{
|
||||
// empty flag
|
||||
strncpy(tmp, p,'\0');
|
||||
}
|
||||
else
|
||||
{
|
||||
if( *(p+flaglen) == ':' ) {
|
||||
// flag has data
|
||||
p += flaglen + 1; // start of data
|
||||
q = strchrnul(p, ','); // end of data: comma or EOS
|
||||
strncpy(tmp, p, q-p);
|
||||
tmp[q-p]='\0';
|
||||
|
||||
if (!strcmp(tmp, node->host)) {
|
||||
DEB((D_NODELIST, "nodelist: found host INA %s", tmp));
|
||||
|
||||
} else {
|
||||
DEB((D_NODELIST, "nodelist: found hidden INA %s", tmp));
|
||||
rc += 1;
|
||||
// let's find last override to add
|
||||
while (ovrbase->hidden != NULL) ovrbase = ovrbase->hidden;
|
||||
// and add new element to hiddens:
|
||||
ovr = xmalloc(sizeof(s_override));
|
||||
memset(ovr,'\0',sizeof(s_override));
|
||||
ovr->hidden = NULL;
|
||||
ovr->sIpaddr = xstrcpy(tmp);
|
||||
ovr->addr = node->addr;
|
||||
ovrbase->hidden = ovr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
searchbase = p + 1;
|
||||
}
|
||||
free(tmp);
|
||||
return rc;
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Open nodelist, nodelist index, do some checks
|
||||
*
|
||||
|
@ -439,7 +439,7 @@ char *emsi_createdat(s_emsi *emsi)
|
||||
* Write total length of <data_pkt>
|
||||
*/
|
||||
sprintf(buf, "%04hX", (short unsigned)strlen(tmp+14));
|
||||
memcpy(tmp+10, buf, 4);
|
||||
memcpy(tmp+10, buf, 4); //-V1086
|
||||
|
||||
return(tmp);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ static void yoohoo_put_hello(char *buffer, s_yoohoo_sysinfo *myhello)
|
||||
char *q;
|
||||
if( strlen(myhello->system) + strlen(state.localaddrs[0].addr.domain) > 57 )
|
||||
{
|
||||
if( strlen(state.localaddrs[0].addr.domain) < 60 ) //PVS-Suppress V547
|
||||
if( strlen(state.localaddrs[0].addr.domain) < 60 ) //-V0547
|
||||
q = p + (60 - strlen(state.localaddrs[0].addr.domain));
|
||||
else
|
||||
q = p;
|
||||
|
@ -81,13 +81,13 @@ void yoohoo_deinit(s_handshake_protocol *THIS)
|
||||
ASSERT(THIS->remote_data);
|
||||
ASSERT(THIS->local_data);
|
||||
|
||||
if( THIS->remote_data )
|
||||
if( THIS->remote_data ) //-V0547
|
||||
{
|
||||
memset(THIS->remote_data, '\0', sizeof(s_yoohoo_sysinfo));
|
||||
free(THIS->remote_data);
|
||||
}
|
||||
|
||||
if( THIS->local_data )
|
||||
if( THIS->local_data ) //-V0547
|
||||
{
|
||||
memset(THIS->local_data, '\0', sizeof(s_yoohoo_sysinfo));
|
||||
free(THIS->local_data);
|
||||
|
@ -283,15 +283,14 @@ int session_stat_update(s_faddr *addr, s_sess_stat *stat, bool caller, int rc)
|
||||
stat->tries_nodial++;
|
||||
if( BFERR_CANT_CONNECT10 <= rc && rc <= BFERR_CANT_CONNECT19 )
|
||||
stat->tries_noconn++;
|
||||
if( rc >= BFERR_CONNECT_TOOLOW )
|
||||
stat->tries_sessns++;
|
||||
|
||||
/* Reset some counters */
|
||||
if( rc >= BFERR_CONNECT_TOOLOW )
|
||||
{
|
||||
stat->tries_sessns++;
|
||||
/* Reset some counters */
|
||||
stat->tries_noansw = TRIES_RESET;
|
||||
stat->tries_noconn = TRIES_RESET;
|
||||
}
|
||||
|
||||
if( rc > BFERR_HANDSHAKE_ERROR )
|
||||
stat->tries_hshake = TRIES_RESET;
|
||||
}
|
||||
|
@ -178,7 +178,6 @@ char *file_gettmp(void)
|
||||
|
||||
res = string_concat(tmp, chunk, '\0');
|
||||
|
||||
if( chunk )
|
||||
free(chunk);
|
||||
if( !res )
|
||||
free(tmp);
|
||||
|
@ -176,7 +176,7 @@ int strcasemask(const char *str, const char *mask)
|
||||
}
|
||||
}
|
||||
|
||||
return( *s != '\0' || *m != '\0' );
|
||||
return( *s != '\0' || *m != '\0' ); //-V0560 It seems more logical
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
@ -155,7 +155,7 @@ int plock_create(const char *lockname)
|
||||
char *tmpname, *p, *chunk;
|
||||
chunk = xmalloc(7);
|
||||
if (!chunk) {
|
||||
logerr("can't generate unique file name from \"%s\"", tmpname);
|
||||
logerr("can't malloc mem for generation of lock name");
|
||||
DEB((D_FREE, "plock freed"));
|
||||
return PLOCK_ERROR;
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ char *string_chomp(char *str)
|
||||
|
||||
ASSERT(str != NULL);
|
||||
|
||||
if( str && *str )
|
||||
if( *str )
|
||||
{
|
||||
p = str + strlen(str + 1);
|
||||
if( *p == '\n' )
|
||||
@ -383,7 +383,7 @@ char *string_trimright(char *str)
|
||||
|
||||
ASSERT(str != NULL);
|
||||
|
||||
if( str && *str )
|
||||
if( *str )
|
||||
{
|
||||
p = str + strlen(str+1);
|
||||
while( p >= str && isspace(*p) ) *p-- = '\0';
|
||||
@ -407,7 +407,7 @@ char *string_trimleft(char *str)
|
||||
|
||||
ASSERT(str != NULL);
|
||||
|
||||
if( str && *str )
|
||||
if( *str )
|
||||
{
|
||||
p = str;
|
||||
while( isspace(*p) ) p++;
|
||||
@ -433,7 +433,7 @@ char *string_trimboth(char *str)
|
||||
|
||||
ASSERT(str != NULL);
|
||||
|
||||
if( str && *str )
|
||||
if( *str )
|
||||
{
|
||||
/* Remove leading spaces */
|
||||
p = str;
|
||||
|
@ -469,7 +469,7 @@ int timevec_parse(s_timevec *dest, const char *str)
|
||||
|
||||
end_day = beg_day;
|
||||
|
||||
if( beg_day >= DAY_MONDAY && beg_day <= DAY_SUNDAY )
|
||||
if( beg_day <= DAY_SUNDAY )
|
||||
str += 3;
|
||||
else if( beg_day == DAY_ANY )
|
||||
str += 3;
|
||||
|
@ -150,14 +150,14 @@ static int nodelist_makeindex(s_nodelist *nlp, s_faddr addr)
|
||||
modepoint = false;
|
||||
break;
|
||||
case KEYWORD_REGION:
|
||||
case KEYWORD_HOST:
|
||||
case KEYWORD_HOST: //-V1037
|
||||
bni.net = value;
|
||||
bni.node = 0;
|
||||
bni.point = 0;
|
||||
bni.hub = 0;
|
||||
modepoint = false;
|
||||
break;
|
||||
case KEYWORD_HUB:
|
||||
case KEYWORD_HUB: //-V1037
|
||||
bni.node = value;
|
||||
bni.point = 0;
|
||||
bni.hub = value;
|
||||
|
@ -34,6 +34,7 @@ static void usage(void)
|
||||
" -r show nodelist string\n"
|
||||
" -m show email address\n"
|
||||
" -o show overrides\n"
|
||||
" -t show calltable\n"
|
||||
" -h show this help message\n"
|
||||
" -C config use config file\n"
|
||||
"\n"
|
||||
@ -44,7 +45,7 @@ void print_nodemail(const s_node *node)
|
||||
{
|
||||
char abuf[BF_MAXADDRSTR+1];
|
||||
|
||||
if( node->sysop && *node->sysop && strcmp(node->sysop, "<none>") )
|
||||
if( *node->sysop && strcmp(node->sysop, "<none>") )
|
||||
{
|
||||
char username[BNI_MAXSYSOP+1];
|
||||
|
||||
@ -84,7 +85,7 @@ void print_nodeinfo(const s_node *node)
|
||||
timevec_check(&node->worktime, now) ? "false" : "true");
|
||||
}
|
||||
|
||||
if( (node->keyword != KEYWORD_POINT) && node->sysop && *node->sysop && strcmp(node->sysop, "<none>") )
|
||||
if( (node->keyword != KEYWORD_POINT) && *node->sysop && strcmp(node->sysop, "<none>") )
|
||||
{
|
||||
char username[BNI_MAXSYSOP+1];
|
||||
|
||||
@ -138,16 +139,141 @@ void print_overrides(const s_override *override_info)
|
||||
p = override_info->hidden;
|
||||
if (p) {
|
||||
printf("Hidden lines:\n");
|
||||
|
||||
while( p )
|
||||
{
|
||||
printf(" Hidden IpAddr : %s\n", p->sIpaddr);
|
||||
printf(" Hidden Phone : %s\n", p->sPhone);
|
||||
printf(" Hidden Flags : %s\n", p->sFlags);
|
||||
printf(" %5d: ",++lin);
|
||||
if (p->sIpaddr) printf("IpAddr: %s, ", p->sIpaddr);
|
||||
if (p->sPhone) printf("Phone: %s", p->sPhone);
|
||||
if (p->sFlags) printf("Flags: %s", p->sFlags);
|
||||
printf("\n");
|
||||
p = p->hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool check_phone(const char *str)
|
||||
{
|
||||
if( !str || !str[0] )
|
||||
return FALSE;
|
||||
|
||||
if( str[0] == '-' && str[1] == '\0' )
|
||||
return FALSE;
|
||||
|
||||
if( string_casestr(str, "unpublished") )
|
||||
return FALSE;
|
||||
|
||||
if( string_casestr(str, "unknown") )
|
||||
return FALSE;
|
||||
|
||||
if( string_casestr(str, "none") )
|
||||
return FALSE;
|
||||
|
||||
if( string_casestr(str, "00-00-000000") )
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void print_calltable(s_faddr addr){
|
||||
s_node nnode;
|
||||
s_override *ovr, *tmpovr;
|
||||
char *tmphost, *tmpphone;
|
||||
int rc,ln = 0;
|
||||
|
||||
|
||||
if( nodelist_lookup(&nnode, addr) == 0 )
|
||||
{
|
||||
// we got nodelist string
|
||||
ovr = conf_override(cf_override, addr);
|
||||
// be aware - ovr may not be, but second INA may
|
||||
if (ovr) {
|
||||
ovr->addr = addr;
|
||||
if (ovr->sIpaddr) strcpy (nnode.host, ovr->sIpaddr);
|
||||
if (ovr->sPhone) strcpy (nnode.phone, ovr->sPhone);
|
||||
if (ovr->sFlags) strcpy (nnode.flags, ovr->sFlags);
|
||||
} else {
|
||||
ovr = xmalloc(sizeof(s_override));
|
||||
memset(ovr,'\0',sizeof(s_override));
|
||||
ovr->addr=addr;
|
||||
ovr->hidden=NULL;
|
||||
ovr->sIpaddr=NULL;
|
||||
}
|
||||
rc = nodelist_parsehiddenina(&nnode, ovr);
|
||||
|
||||
} else {
|
||||
// we have no nodelist string - only overrides
|
||||
ovr = conf_override(cf_override, addr);
|
||||
if (ovr) {
|
||||
ovr->addr = addr;
|
||||
if (ovr->sIpaddr) strcpy (nnode.host, ovr->sIpaddr);
|
||||
if (ovr->sPhone) strcpy (nnode.phone, ovr->sPhone);
|
||||
if (ovr->sFlags) strcpy (nnode.flags, ovr->sFlags);
|
||||
}
|
||||
}
|
||||
// Let's print this table
|
||||
// begin with HOST itself
|
||||
ln = 0;
|
||||
if (nnode.host) {
|
||||
tmphost = nnode.host;
|
||||
}
|
||||
if (!nodelist_checkflag(nnode.flags, "IBN")) {
|
||||
ln +=1;
|
||||
printf ("%5d. %s:binkp\n", ln, tmphost);
|
||||
}
|
||||
if (!nodelist_checkflag(nnode.flags, "IFC")) {
|
||||
ln +=1;
|
||||
printf ("%5d. %s:ifcico\n", ln, tmphost);
|
||||
}
|
||||
if (!nodelist_checkflag(nnode.flags, "ITN")) {
|
||||
ln +=1;
|
||||
printf ("%5d. %s:telnet\n", ln, tmphost);
|
||||
}
|
||||
if (ovr->hidden) {
|
||||
tmpovr = ovr;
|
||||
while (ovr->hidden != NULL) {
|
||||
ovr = ovr->hidden;
|
||||
if (ovr->sIpaddr) {
|
||||
tmphost = ovr->sIpaddr;
|
||||
if (!nodelist_checkflag(nnode.flags, "IBN")) {
|
||||
ln +=1;
|
||||
printf ("%5d. %s:binkp\n", ln, tmphost);
|
||||
}
|
||||
if (!nodelist_checkflag(nnode.flags, "IFC")) {
|
||||
ln +=1;
|
||||
printf ("%5d. %s:ifcico\n", ln, tmphost);
|
||||
}
|
||||
if (!nodelist_checkflag(nnode.flags, "ITN")) {
|
||||
ln +=1;
|
||||
printf ("%5d. %s:telnet\n", ln, tmphost);
|
||||
}
|
||||
}
|
||||
}
|
||||
ovr = tmpovr;
|
||||
}
|
||||
|
||||
// Calltable for pstn
|
||||
if (nnode.phone && check_phone(nnode.phone) ) {
|
||||
tmpphone = nnode.phone;
|
||||
ln +=1;
|
||||
printf ("%5d. PSTN %s\n", ln, tmpphone);
|
||||
if (ovr->hidden) {
|
||||
tmpovr = ovr;
|
||||
while (ovr->hidden != NULL) {
|
||||
ovr = ovr->hidden;
|
||||
if (ovr->sPhone && check_phone(ovr->sPhone)) {
|
||||
tmpphone = ovr->sPhone;
|
||||
ln +=1;
|
||||
printf ("%5d. PSTN %s\n", ln, tmpphone);
|
||||
}
|
||||
}
|
||||
ovr = tmpovr;
|
||||
}
|
||||
}
|
||||
// free ovr elements
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
s_node node;
|
||||
@ -159,13 +285,14 @@ int main(int argc, char *argv[])
|
||||
bool rawstring = FALSE;
|
||||
bool emailaddr = FALSE;
|
||||
bool overrides = FALSE;
|
||||
bool calltable = FALSE;
|
||||
|
||||
/* Initialise random number generation */
|
||||
(void)srand((unsigned)time(0));
|
||||
/* Initialise current locale */
|
||||
(void)setlocale(LC_ALL, "");
|
||||
|
||||
while( (ch=getopt(argc, argv, "hdrmoC:")) != (char)-1 )
|
||||
while( (ch=getopt(argc, argv, "hdrtmoC:")) != (char)-1 )
|
||||
{
|
||||
switch( ch ) {
|
||||
case 'h':
|
||||
@ -177,6 +304,9 @@ int main(int argc, char *argv[])
|
||||
case 'm':
|
||||
emailaddr = TRUE;
|
||||
break;
|
||||
case 't':
|
||||
calltable = TRUE;
|
||||
break;
|
||||
case 'o':
|
||||
overrides = TRUE;
|
||||
break;
|
||||
@ -234,12 +364,20 @@ int main(int argc, char *argv[])
|
||||
if (overrides && ovr) {
|
||||
print_overrides(ovr);
|
||||
}
|
||||
if (calltable) {
|
||||
printf ("----------- Calltable ------------\n");
|
||||
print_calltable(addr);
|
||||
}
|
||||
} else {
|
||||
if (overrides) {
|
||||
ovr = conf_override(cf_override, addr);
|
||||
if (ovr) {
|
||||
printf ("-- No nodelist info, only overrides --");
|
||||
printf ("-------- No nodelist info --------");
|
||||
print_overrides(ovr);
|
||||
if (calltable) {
|
||||
printf ("----- Calltable-on-overrides -----\n");
|
||||
print_calltable(addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ int nodelist_getstr(s_nodelist *nlp, size_t offset, char *buffer, size_t bufle
|
||||
int nodelist_lookup_string(char *buffer, size_t buflen, s_faddr addr);
|
||||
int nodelist_lookup(s_node *node, s_faddr addr);
|
||||
void nodelist_initnode(s_node *node, s_faddr addr);
|
||||
|
||||
int nodelist_parsehiddenina(s_node *node, s_override *ov);
|
||||
|
||||
|
||||
#endif /* _NODELIST_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user