From bb5aeedae8d9176d3fe93e2bf2a7d200d3b27780 Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 28 Feb 2024 22:11:52 +0100 Subject: [PATCH 01/16] --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ee2216c..0c1d9e2 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ *.out *.app +.vscode/ libhttpd-1.4/ simple_entry entry From ed42b2c04db7fa7da2a1bc189c46cb76143d70f3 Mon Sep 17 00:00:00 2001 From: silver Date: Fri, 1 Mar 2024 21:09:20 +0100 Subject: [PATCH 02/16] add mod_flac --- src/pre/modules/mod_flac.c | 238 +++++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 src/pre/modules/mod_flac.c diff --git a/src/pre/modules/mod_flac.c b/src/pre/modules/mod_flac.c new file mode 100644 index 0000000..1e92971 --- /dev/null +++ b/src/pre/modules/mod_flac.c @@ -0,0 +1,238 @@ + +/* + * foo-tools, a collection of utilities for glftpd users. + * Copyright (C) 2003 Tanesha FTPD Project, www.tanesha.net + * + * This file is part of foo-tools. + * + * foo-tools is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * foo-tools is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with foo-tools; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +/* + * Module to extract mp3info from a pred release + * Author, Soren. + * $Id: mod_idmp3.c,v 1.5 2003/06/23 14:32:18 sorend Exp $ + */ + +#include +#include +#include + +// project includes +#include "mod_flac.h" +#include "../foo-pre.h" + +// footools includes +#include + +// in foo-pre +hashtable_t *_mod_flac_cfg = 0; + +void set_config(hashtable_t *cfg) { + _mod_flac_cfg = cfg; +} +hashtable_t *get_config() { + return _mod_flac_cfg; +} + +// prototype for file handling function. +int mod_flac_file_func(char *filepath, char *argv[]); + +module_list_t mod_flac_info = { + // module name + "flac id extractor", + + // moduel dir func + 0, + + // module file func + mod_flac_file_func, + + // module rel func + 0, + + // struct module_list entry + 0 +}; + + +// module global, checks number of mp3s checked (only handle first). +int mod_flac_count = 0; + +// function to return module info of this module. +module_list_t *module_loader() { + return &mod_flac_info; +} + +// replace function +int mod_flac_replace(char *b, char *n, char *r) { + char *t, *save; + int i=0; + + while (t=strstr(b, n)) { + save=(char*)malloc(strlen(t)-strlen(n)+1); + strcpy(save, t+strlen(n)); + *t=0; + strcat(b, r); + strcat(b, save); + free(save); + i++; + } +} + + +// format output using mp3info. +void mod_flac_format_output(char *format_string, FLAC__StreamMetadata *flac_info, char *year, char *genre, int kbps, char *relname) { + char tmp[255]=""; + char mod[1000],*percent,*pos,*code; + char *format=format_string; + int modlen; + + strcpy(mod, format_string); + +// mod_flac_replace(mod, "%a", mp3->id3.artist); +// mod_flac_replace(mod, "%l", mp3->id3.album); + mod_flac_replace(mod, "%y", year); + mod_flac_replace(mod, "%g", genre); + + sprintf(tmp, "%u", flac_info->data.stream_info.sample_rate); + mod_flac_replace(mod, "%Q", tmp); + +// mod_flac_replace(mod, "%L", mod_idmp3_layer_text[header_layer(&mp3->header)-1]); + + sprintf(tmp, "%u", flac_info->data.stream_info.channels); + mod_flac_replace(mod, "%o", tmp); + +// sprintf(tmp, "%u", flac_info->data.stream_info.bits_per_sample); + sprintf(tmp, "%d", kbps); + mod_flac_replace(mod, "%r", tmp); + + mod_flac_replace(mod, "%R", relname); + +// mod_flac_replace(mod, "%S", "NYI"); +// mod_flac_replace(mod, "%m", "NYI"); +// mod_flac_replace(mod, "%s", "NYI"); + + gl_gllog_add(mod); + +// printf(" .. flac module says: Logged information to glftpd.log\n .. %s\n", mod); + + printf("%s\n", mod); +} + + +// file func. +int mod_flac_file_func(char *filepath, char *argv[]) { + + char *tmp; +// FILE *fh; + char genre[255]; + char year[255]; + int seconds; + struct stat st; + + if (mod_flac_count > 0) { + // printf("already got the flac, break\n"); + return 0; + } + + tmp = strrchr(filepath, '.'); + + if (tmp) + tmp++; + else + tmp = filepath; + + if (strcasecmp(tmp, "flac")) { + // printf(" .. %s -> not flac, continue\n", tmp); + return 1; + } + +// fh = fopen(filepath, "r"); + + // could not open file +// if (!fh) +// return 1; + + FLAC__StreamMetadata *temp_meta = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); + + if (FLAC__metadata_get_tags(filepath, &temp_meta)) { + FLAC__uint32 i; + + for (i = 0; i < temp_meta->data.vorbis_comment.num_comments; i++) { + char t_field[255]; + char t_args[255]; + char t[255]; + int idx = 0; + FLAC__uint32 j; + + + for (j = 0; j < temp_meta->data.vorbis_comment.comments[i].length; j++) { + if (temp_meta->data.vorbis_comment.comments[i].entry[j] == '=') { + t[idx] = '\0'; + strcpy(t_field, t); + idx = 0; + continue; + } + t[idx++] = temp_meta->data.vorbis_comment.comments[i].entry[j]; + } + t[idx] = '\0'; + strcpy(t_args, t); + +// for (j = 0; j < strlen(t_field); j++) { +// t_field[j] = toupper(t_field[j]); +// } + + if (strcasecmp("DATE", t_field) == 0) { + if (t_field != NULL) { + strcpy(year, t_args); + } else { + strcpy(year, "EUnknown"); + } + } else if (strcasecmp("GENRE", t_field) == 0) { + if (t_field != NULL) { + strcpy(genre, t_args); + } else { + strcpy(genre, "EUnknown"); + } + } + + t_field[0] = '\0'; + t_args[0] = '\0'; + } + } + FLAC__metadata_object_delete(temp_meta); + + temp_meta = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO); + if (false == FLAC__metadata_get_streaminfo(filepath, temp_meta)) { + return 1; + } + FLAC__metadata_object_delete(temp_meta); + + seconds = (temp_meta->data.stream_info.total_samples / temp_meta->data.stream_info.sample_rate); + stat(filepath, &st); + + mod_flac_count++; + + tmp = ht_get(get_config(), PROPERTY_MOD_FLAC_OUTPUT); + + if (!tmp) + tmp = strdup(DEFAULT_OUTPUT); + else + tmp = strdup(tmp); + + mod_flac_format_output(tmp, temp_meta, year, genre, (((st.st_size/seconds) * 8) / 1000), argv[1]); + + return 1; +} \ No newline at end of file From f065eb23f85922c686823c48f624a8ba5c8e220b Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 20:45:18 +0100 Subject: [PATCH 03/16] --- src/pre/modules/mod_idmp3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pre/modules/mod_idmp3.c b/src/pre/modules/mod_idmp3.c index fc84d2d..d7d6c49 100644 --- a/src/pre/modules/mod_idmp3.c +++ b/src/pre/modules/mod_idmp3.c @@ -169,7 +169,7 @@ int mod_idmp3_file_func(char *filepath, char *argv[]) { FILE *fh; if (mod_idmp3_count > 0) { - // printf("already got the mp3, break\n"); + // printf(" .. already got .mp3, break\n"); return 0; } @@ -181,7 +181,7 @@ int mod_idmp3_file_func(char *filepath, char *argv[]) { tmp = filepath; if (strcasecmp(tmp, "mp3")) { - // printf(" .. %s -> not mp3, continue\n", tmp); + // printf(" .. %s -> not .mp3, continue\n", tmp); return 1; } From 7e6534076d1a7fb686357f704429b04428161b3e Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 20:37:30 +0100 Subject: [PATCH 04/16] --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0c1d9e2..1cb790e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,13 +17,13 @@ *.out *.app -.vscode/ libhttpd-1.4/ simple_entry entry datanode *.pid nfocleaner +foobnc foo-nukes foo-pre mp3info @@ -46,6 +46,9 @@ config.log autom4te.cache/ *.swp +.vscode/ +test/ +tmp/ *.bak *.log *.debug From 5a27780dc6b0aceb8b65ce4e64afb55f204be681 Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 20:36:33 +0100 Subject: [PATCH 05/16] ci: add create release job --- .github/workflows/build.yml | 63 ++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 275da80..63ef74f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,24 +9,49 @@ on: jobs: build: + name: Compile foo-tools runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: configure - working-directory: ./src - run: ./configure - - name: make build (all) - working-directory: ./src - run: make build - - name: make foobnc - working-directory: ./src/bouncer - run: make - - name: make webspy - working-directory: ./src/who - run: make webspy - - name: make foopre modules - working-directory: ./src/pre/modules - run: make && size *.so - - name: make show - working-directory: ./src - run: make show + - uses: actions/checkout@v3 + - name: configure + working-directory: ./src + run: ./configure + - name: make build (all) + working-directory: ./src + run: make build + - name: make foobnc + working-directory: ./src/bouncer + run: make + - name: make webspy + working-directory: ./src/who + run: make webspy + - name: make foopre modules + working-directory: ./src/pre/modules + run: make && size *.so + - name: make show + working-directory: ./src + run: make show + + release: + name: Create Release + runs-on: ubuntu-latest + if: ${{ github.event_name == 'workflow_dispatch' }} + needs: build + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: foo-tools + body: | + Includes foo-pre, mp3genre and modules + + See [CHANGES](src/CHANGES) + + draft: false + prerelease: false From 6ddeb81f4a8d924994505f294e8cf7bd1ba2042f Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 20:43:15 +0100 Subject: [PATCH 06/16] docs: add ngbot details for mod_idmp3 --- src/pre/modules/README.mod_idmp3 | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/pre/modules/README.mod_idmp3 b/src/pre/modules/README.mod_idmp3 index 2c8e9bf..b24496a 100644 --- a/src/pre/modules/README.mod_idmp3 +++ b/src/pre/modules/README.mod_idmp3 @@ -1,4 +1,4 @@ - +MP3INFO Building: --------- @@ -40,7 +40,7 @@ output from mod_idmp3 can be configured using the setting: mod_idmp3.output=output string -in the pre.cfg, default output string is: +in pre.cfg, default output string is: PRE-MP3INFO: "%R" "%a" "%l" "%y" "%g" "%G" "%r" "%Q" "%o" "%m" "%s" "%S" "%L" @@ -62,3 +62,20 @@ if you know that program, you should be familiar with this too. %L - mpeg layer NYI = not yet implemented. + + +Sitebot: +-------- + +pzs-ng's ngBot.conf: + +set redirect(PRE-MP3INFO) $mainchan +set disable(PRE-MP3INFO) 0 +set chanlist(PRE-MP3INFO) $mainchan +set variables(PRE-MP3INFO) "%releasename %artist %album %year %genre %genre_id %bitrate %sampling %mode %none %none %none %mpeglayer" +lappend msgtypes(DEFAULT) "PRE-MP3INFO" + +default theme: + +announce.PRE-MP3INFO = "[%b{%c1{pre-mp3info}}] %artist - %album :: %b{%genre}(genre_id) from %year at %b{%sampling}Hz in %b{%mode} %b{%bitrate}kbps (%mpeglayer)" + From 72cc0253f867fd6a01b1091f9641c2e31254d394 Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 20:42:16 +0100 Subject: [PATCH 07/16] docs: add mod_flac --- src/CHANGES | 7 ++++ src/pre/modules/README.md | 1 + src/pre/modules/README.mod_flac | 62 +++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 src/pre/modules/README.mod_flac diff --git a/src/CHANGES b/src/CHANGES index 1b4bb1a..b84c0d8 100644 --- a/src/CHANGES +++ b/src/CHANGES @@ -61,6 +61,8 @@ Sep 28 2004: * Added WOY to the SECTION dir as a macro for Week of Year. Cheers, Tanesha Team . +-------------------- + //PCFiL Jul 27 2011: * Fixed dirlog damage on x64 OS for foo-pre * Fixed foo-spy (spy) with new glftpd headers. (remember to set key in who.cfg) @@ -110,3 +112,8 @@ Mar 03 2022: + added mod_prebw Jun 28 2023: * changed date macros for 'dir' property to %MM %DD etc * changed prebw module to run bin without any output + +Feb 29 2024: + added flac module, thanks to an anonymous 'donor' +Mar 02 2024: * cleaned up mod_flac a bit and added artist/album tags, vendor_string +Mar 03 2024: * fixed module tester + diff --git a/src/pre/modules/README.md b/src/pre/modules/README.md index 6c39129..ec0f1b3 100644 --- a/src/pre/modules/README.md +++ b/src/pre/modules/README.md @@ -4,6 +4,7 @@ Addons for foo-pre; modules add functions but are not build into foo-pre binary [README.modules](../README.modules) +- [README.mod_flac](README.mod_flac) - [README.mod_prebw](README.mod_prebw) - [README.mod_audiosort](README.mod_audiosort) - [README.mod_chmod](README.mod_chmod) diff --git a/src/pre/modules/README.mod_flac b/src/pre/modules/README.mod_flac new file mode 100644 index 0000000..97f9f2b --- /dev/null +++ b/src/pre/modules/README.mod_flac @@ -0,0 +1,62 @@ +FLACINFO + +Building: +--------- +mod_flac depends on the libflac package (libflac-dev) + +Run 'make' in this dir to build mod_flac.so +Copy it to /glftpd/bin/premodules and make sure libflac.so is in glftpd's lib dir + +Add it to the modules list in pre.cfg like this: + +modules=/bin/premodules/mod_flac.so + +If you have more modules already loaded, it will look like this + +modules=/bin/premodules/mod_other.so|/bin/premodules/mod_whatever.so|/bin/premodules/mod_flac.so + + +Output: +------- + +output from mod_flac can be configured using the setting: + +mod_flac.output=output string + +in pre.cfg, default output string is: + +PRE-FLACINFO: "%R" "%a" "%l" "%y" "%g" "" "%r" "%Q" "%o" "" "" "" "" "%v" + +The variables are similar to mp3: + +%R - release name, eg. Me_and_Myself-My_Leet_Tracks-FLAC-2013-Whatever +%a - artist +%l - album name +%y - year +%g - genre (string) +%G - UNUSED +%r - bitrate in Kbit/s +%Q - sampling frequency in Hz +%o - channelmode +%m - UNUSED +%s - UNUSED +%S - UNUSED +%L - UNUSED +%v - vendor version string + + +Sitebot: +-------- + +pzs-ng's ngBot.conf: + +set redirect(PRE-FLACINFO) $mainchan +set disable(PRE-FLACINFO) 0 +set chanlist(PRE-FLACINFO) $mainchan +set variables(PRE-FLACINFO) "%releasename %artist %album %year %genre %none %bitrate %sampling %mode %none %none %none %none %version" +lappend msgtypes(DEFAULT) "PRE-FLACINFO" + +add to theme: + +announce.PRE-FLACINFO = "[%b{%c1{pre-flacinfo}}] %artist - %album :: %b{%genre} from %year at %b{%sampling}Hz in %b{%mode} channels %b{%bitrate}kbps (%version)" + From 1a67f538d29bd98d5294cd4a760d849605cff021 Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 20:38:00 +0100 Subject: [PATCH 08/16] tester: fix mod tester and add wrapper script --- src/pre/modules/test.sh | 95 +++++++++++++++++++++++++------ src/pre/modules/tester.c | 108 ++++++++++++++++++++++++++---------- src/pre/modules/testpre.cfg | 34 +++++++++--- 3 files changed, 183 insertions(+), 54 deletions(-) diff --git a/src/pre/modules/test.sh b/src/pre/modules/test.sh index 7a2a493..1038ce3 100755 --- a/src/pre/modules/test.sh +++ b/src/pre/modules/test.sh @@ -1,25 +1,86 @@ -#!/bin/sh - +#!/bin/bash +# # wrapper for module tester +# +# usage: ./test.sh [path] [arg] +# +# options +# $1: module.so +# $2: file|dir|rel +# file: /path/to/reldir/foo.mp3 +# path: /path/to/reldir +# last arg: 'strace' 'gdb' to debug +# +# scripts check module for mod_func_file/mod_func_dir/mod_func_rel +# +if [ -z "$1" ]; then + echo "usage: ./test.sh [func] [path]" + echo "see script comments" + exit 0 +fi -mod="mod_audiosort.so" -path="/jail/glftpd/site/incoming/mp3/Whatever-REL" -file="01-test.mp3" +module="$1" +func="file" # set to 'file', 'dir' or 'rel' +test="test_module" # set 'test_module' or 'do_module' -{ make clean && make ${mod}.debug && make tester; } || { echo "make failed, exiting"; exit 1; } -cp ${mod}.debug $mod -echo +echo "$2" | grep -Eq "^file|dir|rel$" && func="$2" + +test -n "$module" || { + echo "ERROR: module not specified" + exit 1 +} + +{ make clean && make tester; } || { + echo "make tester failed, exiting" + exit 1 +} + +if grep -q "$(basename "$module")" Makefile; then + make "$module" || { echo "make module failed, exiting"; exit 1; } +else + echo "module not in Makefile, exiting" + exit 1 +fi -# test_module : ./tester mod_name.so -if [ "$1" = "strace" ]; then - strace ./tester testpre.cfg "./$mod" "$file" "$path" -elif [ "$1" = "gdb" ]; then - gdb --args ./tester testpre.cfg "./$mod" "$file" "$path" +test -s "${module}_debug.so" && cp -v "${module}_debug.so" "${module}.so" + +# func test_module +# tester testpre.cfg +# example: ./tester testpre.cfg file ./mod_flac.so /path/to/01-foo.fla +# +# func do_module +# tester +# example: ./tester file ./mod_flac.so /path/to/01-foo.fla +# +# func_mode 1:file 2:dir 3:rel 4:do_module +# + +CMD="./tester" + +echo "$*" | grep -q "strace" && CMD="strace ./tester" +echo "$*" | grep -q "gdb" && CMD="gdb --args ./tester" + +ARGS+="testpre.cfg ./$(basename "${module}")" + +if [ "$test" = "test_module" ]; then + _mod="${module/%.so/.c}" + echo "$module" | grep -q "_debug.so" && _mod="${module/%_debug.so/.c}" + grep -m1 -q "_${func}_func(" "$_mod" || \ + { echo "ERROR: module doesnt support func"; exit 1; } + case $func in + file) ARGS+=" 1 $3 " ;; + dir|rel) ARGS+=" 1 $3 $4" ;; + *) echo "ERROR: invalid func"; exit 1 ;; + esac else - ./tester testpre.cfg "./$mod" "$file" "$path" + ARGS+=" 4 $3 $4" fi -# FIXME: -# do_module : ./tester -#./tester testpre.cfg $path $file +echo +echo "INFO: [test.sh] running tester cmd $test ..." +echo $CMD $ARGS +echo +$CMD $ARGS +echo "INFO: [test.sh] tester returned code '$?'" +echo diff --git a/src/pre/modules/tester.c b/src/pre/modules/tester.c index 7d37f32..095badf 100644 --- a/src/pre/modules/tester.c +++ b/src/pre/modules/tester.c @@ -29,21 +29,28 @@ #include // test a module. -int test_module(char *module, char *file, char *path) { +int test_module(hashtable_t cfg, char *module, char *mode, char *file, char *path) { void *handle; module_list_t *module_func; module_list_t* (*module_loader)(); - char *args[] = {"", "Whatever-REL", "mp3"}; + + //char *args[] = {"", "Whatever-REL", "mp3"}; + char *args[] = {"", "Whatever-REL", "flac"}; handle = dlopen(module, RTLD_LAZY); + int rc; + + void (*set_config)(hashtable_t *ht); + if (!handle) { printf("Error loading module '%s':\n%s\n", module, dlerror()); return 0; } module_loader = dlsym(handle, MODULE_LOADER_FUNC); + set_config = dlsym(handle, MODULE_SETCONFIG_FUNC); if (!module_loader) { printf("Error loading module %s: No loader func\n"); @@ -51,24 +58,37 @@ int test_module(char *module, char *file, char *path) { return 0; } - printf("DEBUG: file=%s path=%s\n", file, path); + if (!mode) + strcpy(mode, "1"); - // show module name - printf("module name = %s %s\n", module_loader()->mod_name, module); + set_config(&cfg); -/* FIXME - // test module file func - if (module_func->mod_func_file != 0) - module_loader()->mod_func_file(file, args); - - // test module dir func - if (module_func->mod_func_dir != 0) - module_loader()->mod_func_dir(path, args); - - // test module rel func - if (module_func->mod_func_rel != 0) - module_loader()->mod_func_rel(path, args); -*/ + // show module name + printf("INFO: [tester] mod_name is \"%s\"\n", module_loader()->mod_name); + + switch(mode[0]) { + case '1': + // test module file func + if (module_func->mod_func_file != 0) + module_loader()->mod_func_file(file, args); + break; + + case '2': + // test module dir func + if (module_func->mod_func_dir != 0) + module_loader()->mod_func_dir(path, args); + break; + + case '3': + // test module rel func + if (module_func->mod_func_rel != 0) + module_loader()->mod_func_rel(path, args); + break; + + default: + printf("ERROR: specify func num, exiting...\n"); + exit(1); + } dlclose(handle); @@ -80,17 +100,41 @@ hashtable_t *get_config() { return cfg; } -/* FIXME -int do_module(char *path, char *file) { - - //void *handle; +int do_module(hashtable_t cfg, char *module, char *mode, char *file, char *path) { + void *handle; module_list_t *module_func; - //module_list_t* (*module_loader)(); - char *args[] = {"", "Whatever-REL", "mp3"}; + module_list_t* (*module_loader)(); + //char *args[] = {"", "Whatever-REL", "mp3"}; + char *args[] = {"", "Whatever-REL", "flac"}; - module_func = module_loader(); + void (*set_config)(hashtable_t *ht); + + //char *module; + + char *err; - //module_loader = dlsym(handle, MODULE_LOADER_FUNC); + //module = "mod_flac.so"; + + handle = dlopen(module, RTLD_LAZY); + handle = dlopen(module, RTLD_LAZY); + if (!handle) { + err = dlerror(); + printf("ERROR: loading module %s: %s\n", module, err); + return 0; + } + + module_loader = dlsym(handle, MODULE_LOADER_FUNC); + set_config = dlsym(handle, MODULE_SETCONFIG_FUNC); + + if (!module_loader || !set_config) { + printf("ERROR: loading module %s: No loader func found\n"); + dlclose(handle); + return 0; + } + + set_config(&cfg); + + module_func = module_loader(); if (module_func->mod_func_file != 0) module_func->mod_func_file(file, args); @@ -100,8 +144,9 @@ int do_module(char *path, char *file) { if (module_func->mod_func_rel != 0) module_func->mod_func_rel(path, args); + + dlclose(handle); } -*/ int main(int argc, char *argv[]) { @@ -117,10 +162,13 @@ int main(int argc, char *argv[]) { get_config(); //gl_gllog_add(""); - test_module(argv[2], argv[3], argv[4]); + //mode 1:file 2:dir 3:rel + if (argv[3][0] == '1' || argv[3][0] == '2' || argv[3][0] == '3') + test_module(*cfg, argv[2], argv[3], argv[4], argv[5]); - //FIXME - //do_module(argv[2], argv[3]); + // mode 4 + if (argv[3][0] == '4') + do_module(*cfg, argv[2], argv[3], argv[4], argv[5]); } /* vim: set noai tabstop=8 shiftwidth=8 softtabstop=8 noexpandtab: */ diff --git a/src/pre/modules/testpre.cfg b/src/pre/modules/testpre.cfg index c11a0f6..c4cce39 100644 --- a/src/pre/modules/testpre.cfg +++ b/src/pre/modules/testpre.cfg @@ -9,7 +9,8 @@ # define how the group dirs. # group.STAFF.dir=/jail/glftpd/site/private/Staff -group.CoolGroup.dir=/jail/glftpd/site/private/CoolGroup +#group.CoolGroup.dir=/jail/glftpd/site/private/CoolGroup +group.CoolGroup.dir=/jail/glftpd/site/groups/CoolGroup # # a group with two predirs. @@ -146,6 +147,14 @@ section.mp3.dir=/jail/glftpd/site/incoming/mp3 section.mp3.gl_credit_section=0 section.mp3.gl_stat_section=0 +# +# FLAC section, with daily dirs. +# +section.flac.name=FLAC +section.flac.dir=/jail/glftpd/site/incoming/flac +section.flac.gl_credit_section=0 +section.flac.gl_stat_section=0 + ### # misc settings not specific to group or sections. # @@ -156,8 +165,8 @@ section.mp3.gl_stat_section=0 # # shell patterns are used, and multiple are split by '|'. # -countable=*.r??|*.mp3|*.zip|*.0?? -creditable=*.r??|*.mp3|*.zip|*.0??|*.nfo|*.sfv +countable=*.r??|*.mp3|*.zip|*.0??|*.flac +creditable=*.r??|*.mp3|*.zip|*.0??|*.flac|*.nfo|*.sfv # # define dir which is the site root (inside the chrooted glftpd dir). @@ -202,10 +211,9 @@ move.force.ext=0 # module list, path to each module seperated by | # # look at the README.* files in the src/pre/modules/ catalog for -# informatino on how to build these. -#modules=/bin/premodules/mod_idmp3.so|/bin/premodules/mod_sitenfoadd.so|/bin/premodules/mod_nfohandler.so|mod_audiosort.so -modules=mod_audiosort.so -#modules=mod_symlink.so +# information on how to build these. +#modules=mod_idmp3.so|mod_sitenfoadd.so|mod_nfohandler.so|mod_audiosort.so|mod_prebw.so|mod_flac.so +modules=mod_flac.so # # examples of things to extract from an .nfo using regexps. @@ -246,6 +254,18 @@ mod_audiosort.bin=/bin/audiosort # enable audiosort in these sections mod_audiosort.sections=flac|mp3 +# +# properties for prebw module. +# +mod_prebw.bin=/jail/glftpd/bin/slv-prebw.sh +# enable prebw in these sections +mod_prebw.sections=apps|games|flac + +# +# properties for flac module. +# +mod_flac.output=PRE-FLACINFO: "%R" "%a" "%l" "%y" "%g" "" "%r" "%Q" "%o" "" "" "" "" "%v" + # # set etcdir, if your passwd and group are not in /etc, then set this. # From 653f1b6e65270c60f83ce76fb1b3ed1e3ead3f2f Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 20:41:35 +0100 Subject: [PATCH 09/16] add mod_flac target --- README.md | 14 ++++++++++---- TODO.md | 2 +- src/pre/modules/Makefile.in | 23 +++++++++++------------ 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 12ad126..40ab961 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ This software comes without any claims regarding security or support about how t This is a modified and updated version of foo-tools by Tanesha Team: - modification to foo-pre; shows mp3 genre in PRE line (no module needed) +- added modules: mod_audiosort, mod_prebw, mod_flac - added date/time in foo-pre.log -- added mod_audiosort, mod_prebw - updated Makefiles, fixed compiler warnings -- updates/fixes from upstream [glftpd/foo-tools](https://github.com/glftpd/foo-tools) +- includes updates/fixes from upstream [glftpd/foo-tools](https://github.com/glftpd/foo-tools) For more details see [CHANGELOG](src/CHANGES). @@ -34,19 +34,24 @@ The original foo-tools version by Tanesha is available from this branch: [foo-or It does include fixes, but not the mp3genre modification. +There's also [foo-2007](https://github.com/silv3rr/foo-tools/tree/foo-2007) which is 3.1 version by Hujer. + ## Documentation ### Installation +Quick start: + 1) First get this repo with `git clone` 2) Build all tools: `cd src && ./configure && make build` 3) See README for specific tool in [doc](doc) dir -### Detailed instructions ### +### Detailed instructions - [README.1st](README.1st) Original README file -- [src/README.1st](src/README.1st) Building instructions +- [src/README.1st](src/README.1st) Building - [doc/HOWTO](doc/HOWTO) Notes about compiling +- [doc/README.foo-pre](doc/README.foo-pre) foo-pre - [doc](doc) Documentation on installing/running the programs ### Modules @@ -54,6 +59,7 @@ It does include fixes, but not the mp3genre modification. Addons for foo-pre; modules add functions but are not build into foo-pre binary - [src/pre/README.modules](src/pre/README.modules) +- [src/pre/modules/README.mod_flac](src/pre/modules/README.mod_flac) - [src/pre/modules/README.mod_prebw](src/pre/modules/README.mod_prebw) - [src/pre/modules/README.mod_audiosort](src/pre/modules/README.mod_audiosort) - [src/pre/modules/README.mod_chmod](src/pre/modules/README.mod_chmod) diff --git a/TODO.md b/TODO.md index 2833eb7..4ed44f6 100644 --- a/TODO.md +++ b/TODO.md @@ -5,6 +5,6 @@ Things that ~~might eventually~~ never get done.. or not :) ## foo-pre - [ ] replace pre/mp3genre by pzs-ng code or other id3 lib instead (PR welcome) -- [ ] add FLAC support (unlikely but PR's welcome) +- [x] add FLAC support (unlikely but PR's welcome) - [x] add module: prebw after pre (mod_prebw) diff --git a/src/pre/modules/Makefile.in b/src/pre/modules/Makefile.in index 242d2f1..5984bce 100644 --- a/src/pre/modules/Makefile.in +++ b/src/pre/modules/Makefile.in @@ -6,7 +6,11 @@ SRCDIR = ../.. LIBS = $(SRCDIR)/lib/macro.o $(SRCDIR)/lib/gllogs.o $(SRCDIR)/lib/pwdfile.o $(SRCDIR)/util/linefilereader.o $(SRCDIR)/collection/hashtable.o $(SRCDIR)/lib/stringtokenizer.o -all: mod_idmp3.so mod_sitenfoadd.so mod_nfohandler.so mod_chmod.so mod_symlink.so mod_audiosort.so mod_prebw.so +all: mod_idmp3.so mod_sitenfoadd.so mod_nfohandler.so mod_chmod.so mod_symlink.so mod_audiosort.so mod_prebw.so mod_flac.so + +mod_prebw_debug.so: CC += -DDEBUG +mod_audiosort_debug.so: CC += -DDEBUG +mod_flac_debug.so: CC += -DDEBUG mod_idmp3.so: mod_idmp3.o (cd mp3info; make) @@ -24,19 +28,14 @@ mod_nfohandler.so: mod_nfohandler.o mod_symlink.so: mod_symlink.o $(CC) -g -shared -Wl,-soname,mod_symlink.so -o $@ $< $(LIBS) -mod_audiosort.so: mod_audiosort.o - $(CC) $(CFLAGS) -shared -Wl,-soname,mod_audiosort.so -o $@ $< $(LIBS) $(SRCDIR)/collection/strlist.o - -mod_prebw.so: mod_prebw.o - $(CC) $(CFLAGS) -shared -Wl,-soname,mod_prebw.so -o $@ $< $(LIBS) $(SRCDIR)/collection/strlist.o +mod_audiosort.so mod_audiosort_debug.so: mod_audiosort.o + $(CC) $(CFLAGS) -g -shared -Wl,-soname,mod_audiosort.so -o $@ $< $(LIBS) $(SRCDIR)/collection/strlist.o -mod_audiosort_debug.so: - $(CC) -g -DDEBUG -c mod_audiosort.c -I${SRCDIR} - $(CC) -g -shared -Wl,-soname,mod_audiosort.so -o $@ mod_audiosort.o $(LIBS) $(SRCDIR)/collection/strlist.o +mod_prebw.so mod_prebw_debug.so: mod_prebw.o + $(CC) $(CFLAGS) -g -shared -Wl,-soname,mod_prebw.so -o $@ $< $(LIBS) $(SRCDIR)/collection/strlist.o -mod_prebw_debug.so: - $(CC) -g -DDEBUG -c mod_prebw.c -I${SRCDIR} - $(CC) -g -shared -Wl,-soname,mod_prebw.so -o $@ mod_prebw.o $(LIBS) $(SRCDIR)/collection/strlist.o +mod_flac.so mod_flac_debug.so: mod_flac.o + $(CC) $(CFLAGS) -g -shared -Wl,-soname,mod_flac.so -o $@ $< $(LIBS) -lFLAC tester: tester.o $(CC) -g -o $@ $< ../../collection/hashtable.o ../../util/linefilereader.o $(SRCDIR)/lib/gllogs.o -ldl From d1be32a52ebd421c838e74f2ed03f7c7b8d4373a Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 20:45:02 +0100 Subject: [PATCH 10/16] add mod_flac config --- src/pre/pre.cfg | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pre/pre.cfg b/src/pre/pre.cfg index 21d8ffe..8377753 100644 --- a/src/pre/pre.cfg +++ b/src/pre/pre.cfg @@ -156,8 +156,8 @@ section.mp3.gl_stat_section=0 # # shell patterns are used, and multiple are split by '|'. # -countable=*.r??|*.mp3|*.zip|*.0?? -creditable=*.r??|*.mp3|*.zip|*.0??|*.nfo|*.sfv +countable=*.r??|*.mp3|*.zip|*.0??|*.flac +creditable=*.r??|*.mp3|*.zip|*.0??|*.flac|*.nfo|*.sfv # # define dir which is the site root (inside the chrooted glftpd dir). @@ -202,7 +202,7 @@ move.force.ext=0 # # look at the README.* files in the src/pre/modules/ catalog for # information on how to build these. -#modules=/bin/premodules/mod_idmp3.so|/bin/premodules/mod_sitenfoadd.so|/bin/premodules/mod_nfohandler.so|/bin/premodules/mod_audiosort.so|/bin/premodules/mod_prebw.so +#modules=/bin/premodules/mod_idmp3.so|/bin/premodules/mod_sitenfoadd.so|/bin/premodules/mod_nfohandler.so|/bin/premodules/mod_audiosort.so|/bin/premodules/mod_prebw.so|/bin/premodules/mod_flac.so # # examples of things to extract from an .nfo using regexps. @@ -250,6 +250,11 @@ move.force.ext=0 # enable prebw in these sections #mod_prebw.sections=apps|games +# +# output line for mod_flac, check README.mod_flac in modules/ for info. +# +#mod_flac.output=PRE-FLACINFO: "%R" "%a" "%l" "%y" "%g" "" "%r" "%Q" "%o" "" "" "" "" "%v" + # # set etcdir, if your passwd and group are not in /etc, then set this. # From dbfb571052abf58b12ce1f74e0f9e7600400ac12 Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 20:44:40 +0100 Subject: [PATCH 11/16] mod_flac: add tags, header and cleanup --- src/pre/modules/mod_flac.c | 373 ++++++++++++++++++++----------------- src/pre/modules/mod_flac.h | 44 +++++ 2 files changed, 249 insertions(+), 168 deletions(-) create mode 100644 src/pre/modules/mod_flac.h diff --git a/src/pre/modules/mod_flac.c b/src/pre/modules/mod_flac.c index 1e92971..c13a758 100644 --- a/src/pre/modules/mod_flac.c +++ b/src/pre/modules/mod_flac.c @@ -20,12 +20,20 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* - * Module to extract mp3info from a pred release - * Author, Soren. - * $Id: mod_idmp3.c,v 1.5 2003/06/23 14:32:18 sorend Exp $ + * Module to extract flac info from a pred release + * Author, xxx, slv. + * $Id: mod_flac.c,v x.x 2024/03/02 00:00:00 xxx, slv Exp $ */ #include +#include + +#ifdef DEBUG +#include +#include +#endif + +#include #include #include @@ -40,199 +48,228 @@ hashtable_t *_mod_flac_cfg = 0; void set_config(hashtable_t *cfg) { - _mod_flac_cfg = cfg; + _mod_flac_cfg = cfg; } hashtable_t *get_config() { - return _mod_flac_cfg; + return _mod_flac_cfg; } // prototype for file handling function. int mod_flac_file_func(char *filepath, char *argv[]); module_list_t mod_flac_info = { - // module name - "flac id extractor", + // module name + "flac id extractor", - // moduel dir func - 0, + // module dir func + 0, - // module file func - mod_flac_file_func, + // module file func + mod_flac_file_func, - // module rel func - 0, + // module rel func + 0, - // struct module_list entry - 0 + // struct module_list entry + 0 }; -// module global, checks number of mp3s checked (only handle first). +// module global, checks number of flac files checked (only handle first). int mod_flac_count = 0; // function to return module info of this module. module_list_t *module_loader() { - return &mod_flac_info; + return &mod_flac_info; } // replace function int mod_flac_replace(char *b, char *n, char *r) { - char *t, *save; - int i=0; - - while (t=strstr(b, n)) { - save=(char*)malloc(strlen(t)-strlen(n)+1); - strcpy(save, t+strlen(n)); - *t=0; - strcat(b, r); - strcat(b, save); - free(save); - i++; - } + char *t, *save; + int i=0; + + while (t=strstr(b, n)) { + save=(char*)malloc(strlen(t)-strlen(n)+1); + strcpy(save, t+strlen(n)); + *t=0; + strcat(b, r); + strcat(b, save); + free(save); + i++; + } } - -// format output using mp3info. -void mod_flac_format_output(char *format_string, FLAC__StreamMetadata *flac_info, char *year, char *genre, int kbps, char *relname) { - char tmp[255]=""; - char mod[1000],*percent,*pos,*code; - char *format=format_string; - int modlen; - - strcpy(mod, format_string); - -// mod_flac_replace(mod, "%a", mp3->id3.artist); -// mod_flac_replace(mod, "%l", mp3->id3.album); - mod_flac_replace(mod, "%y", year); - mod_flac_replace(mod, "%g", genre); - - sprintf(tmp, "%u", flac_info->data.stream_info.sample_rate); - mod_flac_replace(mod, "%Q", tmp); - -// mod_flac_replace(mod, "%L", mod_idmp3_layer_text[header_layer(&mp3->header)-1]); - - sprintf(tmp, "%u", flac_info->data.stream_info.channels); - mod_flac_replace(mod, "%o", tmp); - -// sprintf(tmp, "%u", flac_info->data.stream_info.bits_per_sample); - sprintf(tmp, "%d", kbps); - mod_flac_replace(mod, "%r", tmp); - - mod_flac_replace(mod, "%R", relname); - -// mod_flac_replace(mod, "%S", "NYI"); -// mod_flac_replace(mod, "%m", "NYI"); -// mod_flac_replace(mod, "%s", "NYI"); - - gl_gllog_add(mod); - -// printf(" .. flac module says: Logged information to glftpd.log\n .. %s\n", mod); - - printf("%s\n", mod); +void gl_gllog_add(char *mod); + +// format output +void mod_flac_format_output(char *format_string, flac_info_t *flac_info, char *relname) { + char mod[1000]; + char *format=format_string; + +#ifdef DEBUG + time_t now; + struct tm *tm_now; + now = time(0); + tm_now = localtime(&now); + printf("MODULE-DEBUG: flac_info->artist=%s flac_info->genre=%s\n", flac_info->artist, flac_info->genre); + printf("MODULE-DEBUG: flac_info->samplingrate=%s\n", flac_info->samplingrate); + FILE *f; + f = fopen("mod_flac.log", "a"); + char fdate[12], ftime[10]; + strftime(fdate, 1024, "%Y-%m-%d", tm_now); + strftime(ftime, 1024, "%H:%M:%S", tm_now); + fprintf(f, "%s %s MODULE-DEBUG: flac_info->artist=%s flac_info->genre=%s\n", fdate, ftime, flac_info->artist, flac_info->genre); + fprintf(f, "%s %s MODULE-DEBUG: flac_info->samplingrate=%s\n", fdate, ftime, flac_info->samplingrate); + //fprintf(f, "%s %s MODULE-DEBUG: format_string=%s\n", fdate, ftime, format_string); + fclose(f); +#endif + + strcpy(mod, format_string); + + mod_flac_replace(mod, "%a", flac_info->artist); + mod_flac_replace(mod, "%l", flac_info->album); + mod_flac_replace(mod, "%y", flac_info->year); + mod_flac_replace(mod, "%g", flac_info->genre); + mod_flac_replace(mod, "%Q", flac_info->samplingrate); + mod_flac_replace(mod, "%o", flac_info->channelmode); + mod_flac_replace(mod, "%r", flac_info->bitrate); + mod_flac_replace(mod, "%R", relname); + mod_flac_replace(mod, "%v", flac_info->vendor_string); + + gl_gllog_add(mod); + //printf(" .. flac module says: Logged information to glftpd.log\n .. %s\n", mod); + printf(" %s\n", mod); } // file func. int mod_flac_file_func(char *filepath, char *argv[]) { - char *tmp; -// FILE *fh; - char genre[255]; - char year[255]; - int seconds; - struct stat st; - - if (mod_flac_count > 0) { - // printf("already got the flac, break\n"); - return 0; - } - - tmp = strrchr(filepath, '.'); - - if (tmp) - tmp++; - else - tmp = filepath; - - if (strcasecmp(tmp, "flac")) { - // printf(" .. %s -> not flac, continue\n", tmp); - return 1; - } - -// fh = fopen(filepath, "r"); - - // could not open file -// if (!fh) -// return 1; - - FLAC__StreamMetadata *temp_meta = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); - - if (FLAC__metadata_get_tags(filepath, &temp_meta)) { - FLAC__uint32 i; - - for (i = 0; i < temp_meta->data.vorbis_comment.num_comments; i++) { - char t_field[255]; - char t_args[255]; - char t[255]; - int idx = 0; - FLAC__uint32 j; - - - for (j = 0; j < temp_meta->data.vorbis_comment.comments[i].length; j++) { - if (temp_meta->data.vorbis_comment.comments[i].entry[j] == '=') { - t[idx] = '\0'; - strcpy(t_field, t); - idx = 0; - continue; - } - t[idx++] = temp_meta->data.vorbis_comment.comments[i].entry[j]; - } - t[idx] = '\0'; - strcpy(t_args, t); - -// for (j = 0; j < strlen(t_field); j++) { -// t_field[j] = toupper(t_field[j]); -// } - - if (strcasecmp("DATE", t_field) == 0) { - if (t_field != NULL) { - strcpy(year, t_args); - } else { - strcpy(year, "EUnknown"); - } - } else if (strcasecmp("GENRE", t_field) == 0) { - if (t_field != NULL) { - strcpy(genre, t_args); - } else { - strcpy(genre, "EUnknown"); - } - } - - t_field[0] = '\0'; - t_args[0] = '\0'; - } - } - FLAC__metadata_object_delete(temp_meta); - - temp_meta = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO); - if (false == FLAC__metadata_get_streaminfo(filepath, temp_meta)) { - return 1; - } - FLAC__metadata_object_delete(temp_meta); - - seconds = (temp_meta->data.stream_info.total_samples / temp_meta->data.stream_info.sample_rate); - stat(filepath, &st); - - mod_flac_count++; - - tmp = ht_get(get_config(), PROPERTY_MOD_FLAC_OUTPUT); - - if (!tmp) - tmp = strdup(DEFAULT_OUTPUT); - else - tmp = strdup(tmp); - - mod_flac_format_output(tmp, temp_meta, year, genre, (((st.st_size/seconds) * 8) / 1000), argv[1]); - - return 1; -} \ No newline at end of file + flac_info_t flac_info; + char *tmp; + FILE *fh; + struct stat st; + + if (mod_flac_count > 0) { + //printf(" .. already got .flac, break\n"); + return 0; + } + + tmp = strrchr(filepath, '.'); + + if (tmp) + tmp++; + else + tmp = filepath; + + if (strcasecmp(tmp, "flac")) { + //printf(" .. %s -> not .flac, continue\n", tmp); + return 1; + } + + fh = fopen(filepath, "rb"); + + // could not open file + if (!fh) { +#ifdef DEBUG + printf(" .. could not open file (%s)\n", filepath); +#endif + return 1; + } + + fclose(fh); + + // defaults + strcpy(flac_info.vendor_string, "Unknown"); + strcpy(flac_info.artist, "Unknown"); + strcpy(flac_info.album, "Unknown"); + strcpy(flac_info.genre, "Unknown"); + strcpy(flac_info.year, "0000"); + strcpy(flac_info.bitrate, "0"); + strcpy(flac_info.samplingrate, "0"); + strcpy(flac_info.channelmode, "0"); + + FLAC__StreamMetadata *temp_meta = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); + + if (FLAC__metadata_get_tags(filepath, &temp_meta)) { + FLAC__uint32 i, j, k; + k = 0; + if (temp_meta->data.vorbis_comment.vendor_string.length > 0) { + if (!strncmp((char *)temp_meta->data.vorbis_comment.vendor_string.entry, "reference libFLAC", 17)) + k = 10; + for (i = 0; i < NAME_MAX - 1 && i < temp_meta->data.vorbis_comment.vendor_string.length; ++i) + flac_info.vendor_string[i] = temp_meta->data.vorbis_comment.vendor_string.entry[i+k]; + flac_info.vendor_string[i] = '\0'; + } + for (i = 0; i < temp_meta->data.vorbis_comment.num_comments; i++) { + char t_field[255]; + char t_args[255]; + char t[255]; + int idx = 0; + for (j = 0; j < temp_meta->data.vorbis_comment.comments[i].length; j++) { + if (temp_meta->data.vorbis_comment.comments[i].entry[j] == '=') { + t[idx] = '\0'; + strcpy(t_field, t); + idx = 0; + continue; + } + t[idx++] = temp_meta->data.vorbis_comment.comments[i].entry[j]; + } + + t[idx] = '\0'; + strcpy(t_args, t); + + if (strcasecmp("ARTIST", t_field) == 0) { + if (t_field != NULL) + strcpy(flac_info.artist, t_args); + } else if (strcasecmp("ALBUM", t_field) == 0) { + if (t_field != NULL) + strcpy(flac_info.album, t_args); + } else if (strcasecmp("DATE", t_field) == 0) { + if (t_field != NULL) + strcpy(flac_info.year, t_args); + } else if (strcasecmp("GENRE", t_field) == 0) { + if (t_field != NULL) + strcpy(flac_info.genre, t_args); + } + + t_field[0] = '\0'; + t_args[0] = '\0'; + } + } else { + return 1; + } + + if(temp_meta != NULL) + FLAC__metadata_object_delete(temp_meta); + + temp_meta = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO); + + if (FLAC__metadata_get_streaminfo(filepath, temp_meta)) { + stat(filepath, &st); + sprintf(flac_info.bitrate, "%d", (st.st_size * temp_meta->data.stream_info.sample_rate) / (125 * temp_meta->data.stream_info.total_samples)); + sprintf(flac_info.samplingrate, "%u", temp_meta->data.stream_info.sample_rate); + sprintf(flac_info.channelmode, "%u", temp_meta->data.stream_info.channels); + //temp_meta->data.stream_info.bits_per_sample + } else { + return 1; + } + + if(temp_meta != NULL) + FLAC__metadata_object_delete(temp_meta); + + mod_flac_count++; + + tmp = ht_get(get_config(), PROPERTY_MOD_FLAC_OUTPUT); + + if (!tmp) + tmp = strdup(DEFAULT_OUTPUT); + else + tmp = strdup(tmp); + + mod_flac_format_output(tmp, &flac_info, argv[1]); + + return 1; +} + +/* vim: set noai tabstop=8 shiftwidth=8 softtabstop=8 noexpandtab: */ diff --git a/src/pre/modules/mod_flac.h b/src/pre/modules/mod_flac.h new file mode 100644 index 0000000..ea195cf --- /dev/null +++ b/src/pre/modules/mod_flac.h @@ -0,0 +1,44 @@ +/* + * foo-tools, a collection of utilities for glftpd users. + * Copyright (C) 2003 Tanesha FTPD Project, www.tanesha.net + * + * This file is part of foo-tools. + * + * foo-tools is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * foo-tools is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with foo-tools; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef mod_flac_h +#define mod_flac_h + +#define PROPERTY_MOD_FLAC_OUTPUT "mod_flac.output" + +// default output mode +#define DEFAULT_OUTPUT "PRE-FLACNFO: \"%R\" \"a\" \"l\" \"%y\" \"%g\" \"\" \"%r\" \"%Q\" \"%o\" \"\" \"\" \"\" \"\" \"%v\"" + +#define NAME_MAX 255 + +typedef struct flac_info { + char vendor_string[NAME_MAX]; + char artist[NAME_MAX]; + char album[NAME_MAX]; + char genre[NAME_MAX]; + char year[5]; + char bitrate[8]; + char samplingrate[10]; + char channelmode[2]; +} flac_info_t; + + +#endif From 7477942c35dc2c9e8f6a26b70bbdeb08dd36b687 Mon Sep 17 00:00:00 2001 From: silver Date: Tue, 23 Jul 2024 21:11:11 +0200 Subject: [PATCH 12/16] mod_flac: use longint for bitrate, moar buf --- src/pre/modules/mod_flac.c | 2 +- src/pre/modules/mod_sitenfoadd.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pre/modules/mod_flac.c b/src/pre/modules/mod_flac.c index c13a758..53a4c21 100644 --- a/src/pre/modules/mod_flac.c +++ b/src/pre/modules/mod_flac.c @@ -247,7 +247,7 @@ int mod_flac_file_func(char *filepath, char *argv[]) { if (FLAC__metadata_get_streaminfo(filepath, temp_meta)) { stat(filepath, &st); - sprintf(flac_info.bitrate, "%d", (st.st_size * temp_meta->data.stream_info.sample_rate) / (125 * temp_meta->data.stream_info.total_samples)); + sprintf(flac_info.bitrate, "%ld", (st.st_size * temp_meta->data.stream_info.sample_rate) / (125 * temp_meta->data.stream_info.total_samples)); sprintf(flac_info.samplingrate, "%u", temp_meta->data.stream_info.sample_rate); sprintf(flac_info.channelmode, "%u", temp_meta->data.stream_info.channels); //temp_meta->data.stream_info.bits_per_sample diff --git a/src/pre/modules/mod_sitenfoadd.c b/src/pre/modules/mod_sitenfoadd.c index 86489a8..8b11846 100644 --- a/src/pre/modules/mod_sitenfoadd.c +++ b/src/pre/modules/mod_sitenfoadd.c @@ -129,7 +129,7 @@ int mod_sitenfoadd_expand(char *buf) { void mod_sitenfoadd_add_nfo(char *path, char *rel) { struct macro_list *ml = 0; - char *tmp, buf[1024], *fn, fbuf[1024]; + char *tmp, buf[1024], *fn, fbuf[2048]; FILE *f; time_t now; From 381f2cff5d402ed0bdc7acbb21e3faf1b73c08be Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 23:01:19 +0100 Subject: [PATCH 13/16] ci: add deps --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 63ef74f..9028944 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: run: make webspy - name: make foopre modules working-directory: ./src/pre/modules - run: make && size *.so + run: apt install libncurses-dev libflac-dev && make && size *.so - name: make show working-directory: ./src run: make show From ca0ddbd16d5481c09dc074f10feec9a4e43b2e7e Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 23:09:52 +0100 Subject: [PATCH 14/16] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9028944..8ebb54b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: run: make webspy - name: make foopre modules working-directory: ./src/pre/modules - run: apt install libncurses-dev libflac-dev && make && size *.so + run: apt-get install -qy libncurses-dev libflac-dev && make && size *.so - name: make show working-directory: ./src run: make show From e27438112060ce06c11c68c520ff258861fce256 Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 6 Mar 2024 23:11:13 +0100 Subject: [PATCH 15/16] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8ebb54b..8ff8fb8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: run: make webspy - name: make foopre modules working-directory: ./src/pre/modules - run: apt-get install -qy libncurses-dev libflac-dev && make && size *.so + run: sudo apt-get install -qy libncurses-dev libflac-dev && make && size *.so - name: make show working-directory: ./src run: make show From 0b6292544f071b0eeadc1ae37338ff1dd425dc3a Mon Sep 17 00:00:00 2001 From: silver Date: Tue, 23 Jul 2024 21:22:34 +0200 Subject: [PATCH 16/16] --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8ff8fb8..9e0de63 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: name: Compile foo-tools runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: configure working-directory: ./src run: ./configure