From e2cac3e27bbe3668874b3b300494859f1fb73e73 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 1 Nov 2017 12:11:12 -0700 Subject: [PATCH] Start adding hust contacts and list-specific config files, since that seems forward-thinking TM --- bin/hushlist | 27 +++++++++++++++++++-------- lib/Hush/List.pm | 31 +++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/bin/hushlist b/bin/hushlist index 9158fca..cdbe7e1 100755 --- a/bin/hushlist +++ b/bin/hushlist @@ -6,26 +6,37 @@ use lib 'lib'; use Hush::List; use Data::Dumper; -my $command = shift || help(); # we only need one -my $list = Hush::List->new; +my $list = Hush::List->new; +my $command = shift || help(); my $COMMANDS = { - "add" => \&add, - "new" => \&new, - "remove" => \&remove, - "send" => \&send, + "add" => \&add, + "contact" => \&contact, + "new" => \&new, + "remove" => \&remove, + "send" => \&send, }; run(); - sub help { print "It would be nice to give some help\n"; } +sub contact { + my $cmd = shift || ''; + if ($cmd eq 'new') { + # add a hust contact, yay + my ($name,$zaddr) = @ARGV; + die Dumper [ $name, $zaddr ]; + } +} + sub new { my $name = shift || ''; - die "Invalid hushlist name '$name' !" unless $name; + #TODO: better validation and allow safe unicode stuff + die "Invalid hushlist name '$name' !" unless $name && ($name =~ m/^[A-z0-9_-]{0,64}/); + $list->new_list($name); print "hushlist '$name' created, enjoy your private comms :)\n"; } diff --git a/lib/Hush/List.pm b/lib/Hush/List.pm index af3129f..9aae37c 100644 --- a/lib/Hush/List.pm +++ b/lib/Hush/List.pm @@ -4,6 +4,9 @@ use warnings; use Hush::RPC; use Try::Tiny; use File::Spec::Functions; +use Carp qw/longmess/; + +sub barf { die longmess(@_) } our $VERSION = 20171031; @@ -68,13 +71,37 @@ sub new { } sub new_list { - my ($self,$name) = @_; - my $lists = $self->{lists}; + my ($self,$name) = @_; + my $lists = $self->{lists}; # a list is simply a list of addresses, which can be looked up by name, and maybe some other metadata $lists->{$name} = { recipients => {} }; + my $list_dir = catdir($HUSHLIST_CONFIG_DIR,$name); + if (!-e $list_dir) { + # create the config dir for the list for the first time + mkdir $list_dir; + if ($!) { + barf "Could not create directory $list_dir !"; + } + } + my $list_specific_conf = catfile($HUSHLIST_CONFIG_DIR,$name,'list.conf'); + my $time = time; + + open my $fh, '>', $list_specific_conf or barf "Could not open $list_specific_conf for writing"; + print $fh "# hushlist $name config\n"; + print $fh "generated=$time\n"; + print $fh "generated_by=Hush::List $Hush::List::VERSION\n"; + close $fh; + + # We consider members.txt the oracle, so users can simply maintain a list + # of zaddrs into a file, if they want. We sync/serialize to list.json + # each time we run + # hust list contacts? + + # TODO: still in flux # ~/.hush/list/LIST_NAME/ # ~/.hush/list/LIST_NAME/list.conf - list-specific config items + # ~/.hush/list/LIST_NAME/members.txt - list member zaddrs, one per line # ~/.hush/list/LIST_NAME/list.json - list data, in JSON # ~/.hush/list/LIST_NAME/list.png - user-specified image for list return $self;