X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmelted%2Fmelted_unit_commands.c;fp=src%2Fmelted%2Fmelted_unit_commands.c;h=6ce8e6eb785cb650f5776565d15ff326f68eac18;hb=a9b6a4c79c0d3c75955fc92324b510b940351571;hp=a21ab313b9badab78dff9f5dc10e9e2375143fc0;hpb=4745d08d88e2e497a316a7d0ed8a187d73d50882;p=melted diff --git a/src/melted/melted_unit_commands.c b/src/melted/melted_unit_commands.c index a21ab31..6ce8e6e 100644 --- a/src/melted/melted_unit_commands.c +++ b/src/melted/melted_unit_commands.c @@ -34,40 +34,45 @@ #include "melted_commands.h" #include "melted_log.h" -int melted_load( command_argument cmd_arg ) -{ - melted_unit unit = melted_get_unit(cmd_arg->unit); - char *filename = (char*) cmd_arg->argument; - char fullname[1024]; - int flush = 1; - char *service; - if ( filename[0] == '!' ) - { - flush = 0; - filename ++; - } +void get_fullname( command_argument cmd_arg, char *fullname, size_t len, char *filename ) +{ + char *service = strchr( filename, ':' ); - service = strchr( filename, ':' ); if ( service != NULL ) { service = filename; filename = strchr( service, ':' ); *filename ++ = '\0'; - + if ( strlen( cmd_arg->root_dir ) && filename[0] == '/' ) filename++; - - snprintf( fullname, 1023, "%s:%s%s", service, cmd_arg->root_dir, filename ); + + snprintf( fullname, len, "%s:%s%s", service, cmd_arg->root_dir, filename ); } else { if ( strlen( cmd_arg->root_dir ) && filename[0] == '/' ) filename++; - snprintf( fullname, 1023, "%s%s", cmd_arg->root_dir, filename ); + snprintf( fullname, len, "%s%s", cmd_arg->root_dir, filename ); } - +} + +int melted_load( command_argument cmd_arg ) +{ + melted_unit unit = melted_get_unit(cmd_arg->unit); + char *filename = (char*) cmd_arg->argument; + char fullname[1024]; + int flush = 1; + + if ( filename[0] == '!' ) + { + flush = 0; + filename ++; + } + get_fullname( cmd_arg, fullname, sizeof(fullname), filename ); + if (unit == NULL) return RESPONSE_INVALID_UNIT; else @@ -122,11 +127,8 @@ int melted_insert( command_argument cmd_arg ) char *filename = (char*) cmd_arg->argument; char fullname[1024]; - if ( strlen( cmd_arg->root_dir ) && filename[0] == '/' ) - filename++; + get_fullname( cmd_arg, fullname, sizeof(fullname), filename ); - snprintf( fullname, 1023, "%s%s", cmd_arg->root_dir, filename ); - if (unit == NULL) return RESPONSE_INVALID_UNIT; else @@ -242,11 +244,8 @@ int melted_append( command_argument cmd_arg ) char *filename = (char*) cmd_arg->argument; char fullname[1024]; - if ( strlen( cmd_arg->root_dir ) && filename[0] == '/' ) - filename++; + get_fullname( cmd_arg, fullname, sizeof(fullname), filename ); - snprintf( fullname, 1023, "%s%s", cmd_arg->root_dir, filename ); - if (unit == NULL) return RESPONSE_INVALID_UNIT; else