Skip to content

Commit

Permalink
Changed meaning of remote.connect value to allow for non-Bonjour RTP …
Browse files Browse the repository at this point in the history
…MIDI servers
  • Loading branch information
Dave Kelly committed May 27, 2019
1 parent 9af06bc commit d1c6d77
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 12 deletions.
2 changes: 1 addition & 1 deletion raveloxmidi/configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([raveloxmidi],[0.7.2])
AC_INIT([raveloxmidi],[0.7.99])
AC_CANONICAL_HOST
AC_CANONICAL_BUILD
AC_CANONICAL_TARGET
Expand Down
1 change: 1 addition & 0 deletions raveloxmidi/include/remote_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ void remote_connect_teardown( void );
void remote_connect_sync_start( void );
void remote_connect_wait_for_thread( void );

#define DEFAULT_CONTROL_PORT 5004
#endif
2 changes: 2 additions & 0 deletions raveloxmidi/src/net_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ void net_socket_loop_init()
logging_printf(LOGGING_DEBUG, "net_socket_loop_init: pipe0=%d pipe1=%d\n", pipe_fd[0], pipe_fd[1]);
FD_SET( pipe_fd[1], &read_fds );
}
fcntl(pipe_fd[0], F_SETFL, O_NONBLOCK);
fcntl(pipe_fd[1], F_SETFL, O_NONBLOCK);
}

void net_socket_loop_teardown()
Expand Down
7 changes: 5 additions & 2 deletions raveloxmidi/src/raveloxmidi_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void config_set_defaults( void )
config_add_item("inbound_midi","/dev/sequencer");
config_add_item("file_mode", "0640");
config_add_item("discover.timeout","5");
config_add_item("sync.interval","60");
config_add_item("sync.interval","10");
#ifdef HAVE_ALSA
config_add_item("alsa.input_buffer_size", "4096" );
#endif
Expand Down Expand Up @@ -254,7 +254,10 @@ long config_long_get( char *key )

int config_is_set( char *key )
{
return ( kv_find_item( config_items, key ) != NULL );
kv_item_t *item = NULL;

item = kv_find_item( config_items, key );
return ( ( item != NULL ) && ( item->value != NULL ) && ( strlen(item->value) > 0 ) );
}

void config_add_item(char *key, char *value )
Expand Down
88 changes: 79 additions & 9 deletions raveloxmidi/src/remote_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,97 @@ void remote_connect_init( void )
net_ctx_t *ctx;
int use_ipv4, use_ipv6;
uint32_t initiator = 0, ssrc = 0;
char *p1 = NULL;
char *p2 = NULL;
int remote_port_number = 0;

remote_service_name = config_string_get("remote.connect");

if( (! remote_service_name) || ( strlen( remote_service_name ) <=0 ) )
if( ! config_is_set( "remote.connect" ) )
{
logging_printf(LOGGING_WARN, "remote_connect_init: remote.connect option is present but not set\n");
logging_printf(LOGGING_WARN, "remote_connect_init: Called with no remote.connect value\n");
return;
}

remote_service_name = (char *) strdup( config_string_get("remote.connect") );

logging_printf(LOGGING_DEBUG, "remote_connect_init: Looking for [%s]\n", remote_service_name);

use_ipv4 = is_yes( config_string_get("service.ipv4") ) ;
use_ipv6 = is_yes( config_string_get("service.ipv6") ) ;
p1 = remote_service_name;
p2 = p1 + strlen( remote_service_name );

if( dns_discover_services( use_ipv4, use_ipv6 ) <= 0 )
/* Work backwards to find a colon ':' */
/* If a ']' character is found first, we'll assume this is going to be an direct connect address */

while( p2 > p1 )
{
logging_printf(LOGGING_WARN, "remote_connect_init: No services available\n");
return;
if( *p2 == ']' ) break;
if( *p2 == ':' ) break;
p2--;
}



/* If no colon ':' or ']' was found, we'll assume this is a service name to be located */
if( p2 == p1 )
{
use_ipv4 = is_yes( config_string_get("service.ipv4") ) ;
use_ipv6 = is_yes( config_string_get("service.ipv6") ) ;

if( dns_discover_services( use_ipv4, use_ipv6 ) <= 0 )
{
logging_printf(LOGGING_WARN, "remote_connect_init: No services available\n");
free( remote_service_name );
return;
}

found_service = dns_discover_by_name( remote_service_name );
goto make_remote_connection;
} else {
/* If there is a colon ':', split the string to determine the port number */
if( *p2 == ':' )
{
*p2='\0';
p2++;
remote_port_number = atoi( p2 );
p2 = remote_service_name + strlen( remote_service_name ) - 1;
}

/* If there is a ']', work forwards from the start of the string to remove the '[' */
if ( *p2 == ']' )
{
*p2='\0';
while( p1 < p2 )
{
if( *p1 == '[' ) break;
p1++;
}

}
if( p1 == p2 )
{
p1 = remote_service_name;
} else {
*p1='\0';
p1++;
}

if( remote_port_number == 0 )
{
logging_printf( LOGGING_ERROR, "remote_connect_init: No port number specified\n");
free( remote_service_name );
return;
}

logging_printf( LOGGING_DEBUG, "remote_connect_init: connect_string=>%s<\n", config_string_get("remote.connect") );
logging_printf( LOGGING_DEBUG, "remote_connect_init: connect_address=>%s<, connect_port=%d\n", p1, remote_port_number );

dns_discover_add( config_string_get("remote.connect"), p1, remote_port_number );
found_service = dns_discover_by_name( config_string_get("remote.connect") );
}


found_service = dns_discover_by_name( remote_service_name );
make_remote_connection:
free( remote_service_name );

if( ! found_service )
{
Expand Down

0 comments on commit d1c6d77

Please sign in to comment.