diff --git a/bean-query-daemon-lib.pl b/bean-query-daemon-lib.pl index 006d5ef..ef3eafa 100644 --- a/bean-query-daemon-lib.pl +++ b/bean-query-daemon-lib.pl @@ -15,8 +15,8 @@ sub BeancountQueryInitialize { die "BEANCOUNT_QUERY: tie failed: is the goffy beancount server running?\n"; } -sub BeancountQuerySubmit($) { - my($question) = @_; +sub BeancountQuerySubmit($;$) { + my($question, $format) = @_; while (defined $BEANCOUNT_QUERY{fifoName} or defined $BEANCOUNT_QUERY{question}) { sleep 1; } (tied %BEANCOUNT_QUERY)->shlock; if (defined $BEANCOUNT_QUERY{fifoName} or defined $BEANCOUNT_QUERY{question}) { @@ -27,6 +27,7 @@ sub BeancountQuerySubmit($) { "fifoName: \"$BEANCOUNT_QUERY{fifoName}\" question: \"$BEANCOUNT_QUERY{question}\"!"); } $BEANCOUNT_QUERY{question} = $question; + $BEANCOUNT_QUERY{format} = $format if defined $format; (tied %BEANCOUNT_QUERY)->shunlock; while (not defined $BEANCOUNT_QUERY{fifoName}) { sleep 1; } die "Ceci n'est pas une pipe: BEANCOUNT_QUERY{fifoName}, $BEANCOUNT_QUERY{fifoName}:$!" diff --git a/bean-query-goofy-daemon.plx b/bean-query-goofy-daemon.plx index 3484d1a..3bd2bea 100755 --- a/bean-query-goofy-daemon.plx +++ b/bean-query-goofy-daemon.plx @@ -87,11 +87,19 @@ while (1) { } elsif ($query{question} !~ /^[\-\@\w.\s\"\'\_\(\)]+$/) { print STDERR "Query string $query{question} looks suspicious, not running beancount query!\n"; (tied %query)->shlock; - $query{question} = undef; + $query{question} = $query{format} = undef; + $query{fifoName} = mktemp("REJECTED_beancount-query-fifo-this-file-does-not-exist_${$}_XXXXXXXXX"); + (tied %query)->shunlock; + } elsif (defined $query{format} and $query{format} !~ /^(?:csv|text)$/) { + print STDERR "format string $query{format} is not text or csv, not running beancount query!\n"; + (tied %query)->shlock; + $query{question} = $query{format} = undef; $query{fifoName} = mktemp("REJECTED_beancount-query-fifo-this-file-does-not-exist_${$}_XXXXXXXXX"); (tied %query)->shunlock; } elsif (not defined $query{fifoName}) { - my @cmd = ($BEANCOUNT_QUERY_CMD, '-f', 'text', $LOAD_FILE, $query{question}); + my @cmd = ($BEANCOUNT_QUERY_CMD); + push(@cmd, '-f', $query{format}) if defined $query{format}; + push(@cmd, $LOAD_FILE, $query{question}); print STDERR "Running query: $query{question}\n" if $VERBOSE > 0; open(my $beancountFH, "-|", @cmd); print STDERR "Running ", join(" ", @cmd), "\n" if $VERBOSE > 1;