return buf;
}
+/*
+ This accepts a pointer to a nil terminated string, and ensures that there is a
+ newline as the last character. If there is not, a new buffer is allocated and
+ the newline is added. If a new buffer is allocated, the buffer passed in is
+ freed. The function returns a pointer which the caller should use, and must
+ free. In the event of an error, a nil pointer is returned.
+*/
+static char* ensure_nlterm( char* buf ) {
+ char* nb = NULL;
+ int len = 1;
+
+
+ nb = buf;
+ if( buf == NULL || (len = strlen( buf )) < 2 ) {
+ if( (nb = (char *) malloc( sizeof( char ) * 2 )) != NULL ) {
+ *nb = '\n';
+ *(nb+1) = 0;
+ }
+ } else {
+ if( buf[len-1] != '\n' ) {
+ fprintf( stderr, "[WRN] rmr buf_check: input buffer was not newline terminated (file missing final \\n?)\n" );
+ if( (nb = (char *) malloc( sizeof( char ) * (len + 2) )) != NULL ) {
+ memcpy( nb, buf, len );
+ *(nb+len) = '\n'; // insert \n and nil into the two extra bytes we allocated
+ *(nb+len+1) = 0;
+ free( buf );
+ }
+ }
+ }
+
+ return nb;
+}
/*
Given a message type create a route table entry and add to the hash keyed on the
rte = uta_add_rte( ctx->new_rtable, key, ngtoks ); // get/create entry for this key
for( grp = 0; grp < ngtoks; grp++ ) {
- if( (ntoks = uta_tokenise( gtokens[grp], tokens, 64, ',' )) > 0 ) {
+ if( (ntoks = uta_rmip_tokenise( gtokens[grp], ctx->ip_list, tokens, 64, ',' )) > 0 ) { // remove any referneces to our ip addrs
for( i = 0; i < ntoks; i++ ) {
- if( DEBUG > 1 || (vlevel > 1)) fprintf( stderr, "[DBUG] add endpoint %s\n", ts_field );
- uta_add_ep( ctx->new_rtable, rte, tokens[i], grp );
+ if( strcmp( tokens[i], ctx->my_name ) != 0 ) { // don't add if it is us -- cannot send to ourself
+ if( DEBUG > 1 || (vlevel > 1)) fprintf( stderr, "[DBUG] add endpoint ts=%s %s\n", ts_field, tokens[i] );
+ uta_add_ep( ctx->new_rtable, rte, tokens[i], grp );
+ }
}
}
}
}
} else {
- if( DEBUG || (vlevel > 2) )
+ if( DEBUG || (vlevel > 2) ) {
fprintf( stderr, "entry not included, sender not matched: %s\n", tokens[1] );
+ }
}
}
return;
}
- if( (fbuf = uta_fib( fname ) ) == NULL ) { // read file into a single buffer
- fprintf( stderr, "[WRN] seed route table could not be opened: %s: %s\n", fname, strerror( errno ) );
+ if( (fbuf = ensure_nlterm( uta_fib( fname ) ) ) == NULL ) { // read file into a single buffer (nil terminated string)
+ fprintf( stderr, "[WRN] rmr read_static: seed route table could not be opened: %s: %s\n", fname, strerror( errno ) );
return;
}
- if( DEBUG ) fprintf( stderr, "[INFO] seed route table successfully opened: %s\n", fname );
+ if( DEBUG ) fprintf( stderr, "[DBUG] rmr: seed route table successfully opened: %s\n", fname );
+ for( eor = fbuf; *eor; eor++ ) { // fix broken systems that use \r or \r\n to terminate records
+ if( *eor == '\r' ) {
+ *eor = '\n'; // will look like a blank line which is ok
+ }
+ }
+
for( rec = fbuf; rec && *rec; rec = eor+1 ) {
rcount++;
if( (eor = strchr( rec, '\n' )) != NULL ) {
*eor = 0;
+ } else {
+ fprintf( stderr, "[WRN] rmr read_static: seed route table had malformed records (missing newline): %s\n", fname );
+ fprintf( stderr, "[WRN] rmr read_static: seed route table not used: %s\n", fname );
+ free( fbuf );
+ return;
}
parse_rt_rec( ctx, rec, vlevel );
}
- if( DEBUG ) fprintf( stderr, "[INFO] seed route table successfully parsed: %d records\n", rcount );
+ if( DEBUG ) fprintf( stderr, "[DBUG] rmr: seed route table successfully parsed: %d records\n", rcount );
free( fbuf );
}
endpoint_t* ep;
if( !rt || !ep_name || ! *ep_name ) {
- fprintf( stderr, "[WARN] rmr: rt_ensure: internal mishap, something undefined rt=%p ep_name=%p\n", rt, ep_name );
+ fprintf( stderr, "[WRN] rmr: rt_ensure: internal mishap, something undefined rt=%p ep_name=%p\n", rt, ep_name );
errno = EINVAL;
return NULL;
}
if( (ep = uta_get_ep( rt, ep_name )) == NULL ) { // not there yet, make
if( (ep = (endpoint_t *) malloc( sizeof( *ep ) )) == NULL ) {
- fprintf( stderr, "[WARN] rmr: rt_ensure: malloc failed for endpoint creation: %s\n", ep_name );
+ fprintf( stderr, "[WRN] rmr: rt_ensure: malloc failed for endpoint creation: %s\n", ep_name );
errno = ENOMEM;
return NULL;
}