all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api] pmgdb dump: encode ruledata before printing
Date: Wed, 30 Nov 2022 14:21:29 +0100	[thread overview]
Message-ID: <20221130132129.66108-1-s.ivanov@proxmox.com> (raw)

was overlooked with the utf-8 support for rules and objects

this patch prevents a "Wide character in print at .." when dumping the
ruledata

Reported-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 src/PMG/CLI/pmgdb.pm | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/PMG/CLI/pmgdb.pm b/src/PMG/CLI/pmgdb.pm
index 417e008..8368af8 100644
--- a/src/PMG/CLI/pmgdb.pm
+++ b/src/PMG/CLI/pmgdb.pm
@@ -3,6 +3,7 @@ package PMG::CLI::pmgdb;
 use strict;
 use warnings;
 use Data::Dumper;
+use Encode qw(encode);
 
 use PVE::SafeSyslog;
 use PVE::Tools qw(extract_param);
@@ -31,7 +32,7 @@ sub print_objects {
     my $objects = $ruledb->load_group_objects ($og->{id});
 
     foreach my $obj (@$objects) {
-	my $desc = $obj->short_desc ();
+	my $desc = encode('UTF-8', $obj->short_desc());
 	print "    OBJECT $obj->{id}: $desc\n";
     }
 }
@@ -46,31 +47,34 @@ sub print_rule {
     };
     my $active = $rule->{active} ? 'active' : 'inactive';
     my $dir = $direction->{$rule->{direction}};
+    my $rulename = encode('UTF-8', $rule->{name});
 
-    print "Found RULE $rule->{id} (prio: $rule->{priority}, $dir, $active): $rule->{name}\n";
+    print "Found RULE $rule->{id} (prio: $rule->{priority}, $dir, $active): $rulename\n";
+
+    my $print_group = sub {
+	my ($type, $og) = @_;
+	my $oname = encode('UTF-8', $og->{name});
+	print "  FOUND $type GROUP $og->{id}: $oname\n";
+	print_objects($ruledb, $og);
+    };
 
     my ($from, $to, $when, $what, $action) =
 	$ruledb->load_groups($rule);
 
     foreach my $og (@$from) {
-	print "  FOUND FROM GROUP $og->{id}: $og->{name}\n";
-	print_objects($ruledb, $og);
+	$print_group->("FROM", $og);
     }
     foreach my $og (@$to) {
-	print "  FOUND TO GROUP $og->{id}: $og->{name}\n";
-	print_objects($ruledb, $og);
+	$print_group->("TO", $og);
     }
     foreach my $og (@$when) {
-	print "  FOUND WHEN GROUP $og->{id}: $og->{name}\n";
-	print_objects($ruledb, $og);
+	$print_group->("WHEN", $og);
     }
     foreach my $og (@$what) {
-	print "  FOUND WHAT GROUP $og->{id}: $og->{name}\n";
-	print_objects($ruledb, $og);
+	$print_group->("WHAT", $og);
     }
     foreach my $og (@$action) {
-	print "  FOUND ACTION GROUP $og->{id}: $og->{name}\n";
-	print_objects($ruledb, $og);
+	$print_group->("ACTION", $og);
     }
 }
 
-- 
2.30.2





             reply	other threads:[~2022-11-30 13:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-30 13:21 Stoiko Ivanov [this message]
2022-12-15 11:10 ` Dominik Csapak
2022-12-30 14:18 ` [pmg-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221130132129.66108-1-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal