CHANGED: does no more use the external touch command to create a new

file, use perls open() instead.
CHANGED:        excluded some of the help texts from the usage message and the
                interactive help command to a manpage.
ADDED:          new commandline flag "--encrypt" which one can use to encrypt
                the mysql database password. This will be decrypted before
                connecting to the db. There is also a new config file option
                "encrypt_passwd" which indicates an encrypted db-password.
ADDED:          another new config option "ShortCd", which can be set to "yes"
                or 1 and if set, then a command like "cd 13" would jump
                directly to the topic of the note with the number 13.
ADDED:          now you can at any time cd back to the "root" of the
                topic-structure using the command "cd /".
CHANGED:        mysql.pm does now only do a table-lock on single write
                accesses, no more on the whole session. This allows one to
                access the same db twice or more.
FIXED:          Changed README and Changelog for readability on 80 by 25
                displays. And changed indentation of the note script itself.
ADDED:          NOTEDB.pm - a generic module, which holds some methods, which
                are used by binary.pm, mysql.pm and dbm.pm.
ADDED:          NOTEDB.pm generate_search(), which allows one to
                use AND, OR and various combinations of them using ( and ).
ADDED:          a search does now return the 2nd line of a note if a matching
                note's first line is a topic.
CHANGED:        use "unshift" instead of push to add $libpath to @INC.
ADDED:          a new feature, Caching of notes. supported by binary.pm and
                mysql.pm. To turn it on, one need to set "Cache" in the config
                to a true value.
This commit is contained in:
TLINDEN
2012-02-10 20:22:49 +01:00
parent 788902c69d
commit 9cf564ffe4
67 changed files with 6310 additions and 1604 deletions

5
NOTEDB/CVS/Entries Normal file
View File

@@ -0,0 +1,5 @@
/README/1.1.1.1/Sat Jul 1 14:40:52 2000//
/binary.pm/1.1.1.1/Sat Jul 1 14:40:52 2000//
/dbm.pm/1.1.1.1/Sat Jul 1 14:40:52 2000//
/mysql.pm/1.1.1.1/Sat Jul 1 14:40:52 2000//
D

1
NOTEDB/CVS/Repository Normal file
View File

@@ -0,0 +1 @@
NOTE/NOTEDB

1
NOTEDB/CVS/Root Normal file
View File

@@ -0,0 +1 @@
zarahg@cvs.htnews.sourceforge.net:/cvsroot/htnews

View File

@@ -1,26 +1,19 @@
#!/usr/bin/perl
# $Id: binary.pm,v 1.6 2000/06/25 19:48:00 scip Exp scip $
# $Id: binary.pm,v 1.1.1.1 2000/07/01 14:40:52 zarahg Exp $
# Perl module for note
# binary database backend. see docu: perldoc NOTEDB::binary
#
package NOTEDB;
use strict;
use Data::Dumper;
use IO::Seekable;
package NOTEDB;
use NOTEDB;
use Fcntl qw(LOCK_EX LOCK_UN);
BEGIN {
# make sure, it works, although encryption
# not supported on this system!
eval { require Crypt::CBC; };
if($@) {
$NOTEDB::crypt_supported = 0;
}
else {
$NOTEDB::crypt_supported = 1;
}
}
# Globals:
my ($NOTEDB, $sizeof, $typedef,$version);
my ($cipher);
@@ -48,12 +41,12 @@ sub new
exit(1);
}
my $TYPEDEF = "i a$MAX_NOTE a$MAX_TIME";
my $TYPEDEF = "i a$MAX_NOTE a$MAX_TIME";
my $SIZEOF = length pack($TYPEDEF, () );
$sizeof = $SIZEOF;
$typedef = $TYPEDEF;
return $self;
}
@@ -67,24 +60,7 @@ sub version {
return $version;
}
sub no_crypt {
$NOTEDB::crypt_supported = 0;
}
sub use_crypt {
my($this,$key,$method) = @_;
if($NOTEDB::crypt_supported == 1) {
eval {
$cipher = new Crypt::CBC($key, $method);
};
if($@) {
$NOTEDB::crypt_supported == 0;
}
}
else{
print "warning: Crypt::CBC not supported by system!\n";
}
}
sub set_del_all
{
@@ -94,8 +70,7 @@ sub set_del_all
}
sub get_single
{
sub get_single {
my($this, $num) = @_;
my($address, $note, $date, $buffer, $n, $t, $buffer, );
@@ -112,20 +87,24 @@ sub get_single
flock NOTE, LOCK_UN;
close NOTE;
return $note, $date;
}
sub get_all
{
my($this, $num, $note, $date, %res);
my $this = shift;
my($num, $note, $date, %res);
if ($this->unchanged) {
return %{$this->{cache}};
}
open NOTE, "+<$NOTEDB" or die "could not open $NOTEDB\n";
flock NOTE, LOCK_EX;
my($buffer, $t, $n);
flock NOTE, LOCK_EX;
my($buffer, $t, $n);
seek(NOTE, 0, 0); # START FROM BEGINNING
while(read(NOTE, $buffer, $sizeof)) {
while(read(NOTE, $buffer, $sizeof)) {
($num, $note, $date) = unpack($typedef, $buffer);
$t = ude($date);
$n = ude($note);
@@ -135,18 +114,27 @@ sub get_all
flock NOTE, LOCK_UN;
close NOTE;
$this->cache(%res);
return %res;
}
sub get_nextnum
{
my($this, $num, $te, $me, $buffer);
my $this = shift;
my($num, $te, $me, $buffer);
if ($this->unchanged) {
$num = 1;
foreach (keys %{$this->{cache}}) {
$num++;
}
return $num;
}
open NOTE, "+<$NOTEDB" or die "could not open $NOTEDB\n";
flock NOTE, LOCK_EX;
seek(NOTE, 0, 0); # START FROM BEGINNING
flock NOTE, LOCK_EX;
seek(NOTE, 0, 0); # START FROM BEGINNING
while(read(NOTE, $buffer, $sizeof)) {
($num, $te, $me) = unpack($typedef, $buffer);
}
@@ -160,10 +148,31 @@ sub get_nextnum
sub get_search
{
my($this, $searchstring) = @_;
my($buffer, $num, $note, $date, %res, $t, $n);
my($buffer, $num, $note, $date, %res, $t, $n, $match);
my $regex = $this->generate_search($searchstring);
eval $regex;
if ($@) {
print "invalid expression: \"$searchstring\"!\n";
return;
}
$match = 0;
if ($this->unchanged) {
foreach my $num (keys %{$this->{cache}}) {
$_ = $this->{cache}{$num}->{note};
eval $regex;
if ($match) {
$res{$num}->{note} = $this->{cache}{$num}->{note};
$res{$num}->{date} = $this->{cache}{$num}->{date}
}
$match = 0;
}
return %res;
}
open NOTE, "+<$NOTEDB" or die "could not open $NOTEDB\n";
flock NOTE, LOCK_EX;
flock NOTE, LOCK_EX;
seek(NOTE, 0, 0); # START FROM BEGINNING
while(read(NOTE, $buffer, $sizeof))
@@ -171,11 +180,14 @@ sub get_search
($num, $note, $date) = unpack($typedef, $buffer);
$n = ude($note);
$t = ude($date);
if($n =~ /\Q$searchstring\E/i)
$_ = $n;
eval $regex;
if($match)
{
$res{$num}->{'note'} = $n;
$res{$num}->{'date'} = $t;
}
$match = 0;
}
flock NOTE, LOCK_UN;
close NOTE;
@@ -192,7 +204,7 @@ sub set_edit
my $address = ($num -1 ) * $sizeof;
open NOTE, "+<$NOTEDB" or die "could not open $NOTEDB\n";
flock NOTE, LOCK_EX;
flock NOTE, LOCK_EX;
seek(NOTE, $address, IO::Seekable::SEEK_SET);
my $n = uen($note);
@@ -203,6 +215,8 @@ sub set_edit
flock NOTE, LOCK_UN;
close NOTE;
$this->changed;
}
@@ -220,6 +234,8 @@ sub set_new
flock NOTE, LOCK_UN;
close NOTE;
$this->changed;
}
@@ -249,6 +265,9 @@ sub set_del
}
flock NOTE, LOCK_UN;
close NOTE;
$this->changed;
return;
}
@@ -256,14 +275,14 @@ sub set_recountnums
{
my($this) = @_;
my(%orig, $note, $date, $T, $setnum, $buffer, $n, $N, $t);
$setnum = 1;
%orig = $this->get_all();
open NOTE, ">$NOTEDB" or die "could not open $NOTEDB\n";
flock NOTE, LOCK_EX;
seek(NOTE, 0, 0); # START FROM BEGINNING
foreach $N (sort {$a <=> $b} keys %orig) {
$n = uen($orig{$N}->{'note'});
$t = uen($orig{$N}->{'date'});
@@ -274,6 +293,9 @@ sub set_recountnums
}
flock NOTE, LOCK_UN;
close NOTE;
$this->changed;
return;
}
@@ -306,6 +328,10 @@ sub ude
return $T;
}
1; # keep this!
__END__
@@ -318,7 +344,7 @@ NOTEDB::binary - module lib for accessing a notedb from perl
# include the module
use NOTEDB;
# create a new NOTEDB object
$db = new NOTEDB("binary", "/home/tom/.notedb", 4096, 24);

View File

@@ -1,25 +1,15 @@
#!/usr/bin/perl
# $Id: dbm.pm,v 1.2 2000/06/25 19:51:11 scip Exp scip $
# $Id: dbm.pm,v 1.1.1.1 2000/07/01 14:40:52 zarahg Exp $
# Perl module for note
# DBM database backend. see docu: perldoc NOTEDB::dbm
#
use DB_File;
#use Data::Dumper;
use NOTEDB;
use strict;
package NOTEDB;
BEGIN {
# make sure, it works, although encryption
# not supported on this system!
eval { require Crypt::CBC; };
if($@) {
$NOTEDB::crypt_supported = 0;
}
else {
$NOTEDB::crypt_supported = 1;
}
}
# Globals:
my ($dbm_dir, $notefile, $timefile, $version, $cipher, %note, %date);
@@ -52,25 +42,6 @@ sub version {
return $version;
}
sub no_crypt {
$NOTEDB::crypt_supported = 0;
}
sub use_crypt {
my($this, $key, $method) = @_;
if($NOTEDB::crypt_supported == 1) {
eval {
$cipher = new Crypt::CBC($key, $method);
};
if($@) {
$NOTEDB::crypt_supported == 0;
}
}
else{
print "warning: Crypt::CBC not supported by system!\n";
}
}
sub get_single
{
@@ -104,13 +75,23 @@ sub get_nextnum
sub get_search
{
my($this, $searchstring) = @_;
my($num, $note, $date, %res);
my($num, $note, $date, %res, $match);
my $regex = $this->generate_search($searchstring);
eval $regex;
if ($@) {
print "invalid expression: \"$searchstring\"!\n";
return;
}
$match = 0;
foreach $num (sort {$a <=> $b} keys %date) {
if (ude($note{$num}) =~ /\Q$searchstring\E/i) {
$_ = ude($note{$num});
eval $regex;
if ($match) {
$res{$num}->{'note'} = ude($note{$num});
$res{$num}->{'date'} = ude($date{$num});
}
$match = 0;
}
return %res;
@@ -196,6 +177,8 @@ sub ude
}
}
1; # keep this!
__END__

View File

@@ -1,5 +1,5 @@
#!/usr/bin/perl
# $Id: mysql.pm,v 1.5 2000/06/25 19:50:43 scip Exp scip $
# $Id: mysql.pm,v 1.1.1.1 2000/07/01 14:40:52 zarahg Exp $
# Perl module for note
# mysql database backend. see docu: perldoc NOTEDB::binary
#
@@ -7,21 +7,10 @@
use DBI;
use strict;
use Data::Dumper;
use NOTEDB;
package NOTEDB;
BEGIN {
# make sure, it works, although encryption
# not supported on this system!
eval { require Crypt::CBC; };
if($@) {
$NOTEDB::crypt_supported = 0;
}
else {
$NOTEDB::crypt_supported = 1;
}
}
# Globals:
my ($DB, $table, $fnum, $fnote, $fdate, $version, $cipher);
$table = "note";
@@ -35,7 +24,6 @@ my $sql_getsingle = "SELECT $fnote,$fdate FROM $table WHERE $fnum = ?";
my $sql_all = "SELECT $fnum,$fnote,$fdate FROM $table";
my $sql_nextnum = "SELECT max($fnum) FROM $table";
my $sql_incrnum = "SELECT $fnum FROM $table ORDER BY $fnum";
my $sql_search = "SELECT DISTINCT $fnum,$fnote,$fdate FROM $table WHERE $fnote LIKE ?";
my $sql_setnum = "UPDATE $table SET $fnum = ? WHERE $fnum = ?";
my $sql_edit = "UPDATE $table SET $fnote = ?, $fdate = ? WHERE $fnum = ?";
@@ -57,11 +45,6 @@ sub new
my $database = "DBI:$dbdriver:$dbname;host=$dbhost";
$DB = DBI->connect($database, $dbuser, $dbpasswd) || die DBI->errstr();
# LOCK the database!
my $lock = $DB->prepare("LOCK TABLES $table WRITE") || die $DB->errstr();
$lock->execute() || die $DB->errstr();
return $self;
}
@@ -69,40 +52,36 @@ sub new
sub DESTROY
{
# clean the desk!
my $unlock = $DB->prepare("UNLOCK TABLES") || die $DB->errstr;
$unlock->execute() || die $DB->errstr();
$DB->disconnect || die $DB->errstr;
}
sub lock {
my($this) = @_;
# LOCK the database!
my $lock = $DB->prepare("LOCK TABLES $table WRITE") || die $DB->errstr();
$lock->execute() || die $DB->errstr();
}
sub unlock {
my($this) = @_;
my $unlock = $DB->prepare("UNLOCK TABLES") || die $DB->errstr;
$unlock->execute() || die $DB->errstr();
$DB->disconnect || die $DB->errstr;
}
sub version {
return $version;
}
sub no_crypt {
$NOTEDB::crypt_supported = 0;
}
sub use_crypt {
my($this, $key, $method) = @_;
if($NOTEDB::crypt_supported == 1) {
eval {
$cipher = new Crypt::CBC($key, $method);
};
if($@) {
$NOTEDB::crypt_supported == 0;
}
}
else{
print "warning: Crypt::CBC not supported by system!\n";
}
}
sub get_single
{
sub get_single {
my($this, $num) = @_;
my($note, $date);
my $statement = $DB->prepare($sql_getsingle) || die $DB->errstr();
$statement->execute($num) || die $DB->errstr();
$statement->bind_columns(undef, \($note, $date)) || die $DB->errstr();
@@ -114,7 +93,13 @@ sub get_single
sub get_all
{
my($this, $num, $note, $date, %res);
my $this = shift;
my($num, $note, $date, %res);
if ($this->unchanged) {
return %{$this->{cache}};
}
my $statement = $DB->prepare($sql_all) || die $DB->errstr();
$statement->execute || die $DB->errstr();
@@ -124,6 +109,8 @@ sub get_all
$res{$num}->{'note'} = ude($note);
$res{$num}->{'date'} = ude($date);
}
$this->cache(%res);
return %res;
}
@@ -131,6 +118,14 @@ sub get_all
sub get_nextnum
{
my($this, $num);
if ($this->unchanged) {
$num = 1;
foreach (keys %{$this->{cache}}) {
$num++;
}
return $num;
}
my $statement = $DB->prepare($sql_nextnum) || die $DB->errstr();
$statement->execute || die $DB->errstr();
@@ -144,30 +139,35 @@ sub get_nextnum
sub get_search
{
my($this, $searchstring) = @_;
my($num, $note, $date, %res);
if($NOTEDB::crypt_supported != 1) {
$searchstring = "\%$searchstring\%";
my $statement = $DB->prepare($sql_search) || die $DB->errstr();
$statement->execute($searchstring) || die $DB->errstr();
$statement->bind_columns(undef, \($num, $note, $date))
|| die $DB->errstr();
while($statement->fetch) {
$res{$num}->{'note'} = $note;
$res{$num}->{'date'} = $date;
}
my($num, $note, $date, %res, $match);
my $regex = $this->generate_search($searchstring);
eval $regex;
if ($@) {
print "invalid expression: \"$searchstring\"!\n";
return;
}
$match = 0;
my %data;
if ($this->unchanged) {
%data = %{$this->{cache}};
}
else {
my %res = $this->get_all();
foreach $num (sort { $a <=> $b } keys %res) {
$note = ude($res{$num}->{'note'});
$date = ude($res{$num}->{'date'});
if($note =~ /\Q$searchstring\E/i)
{
$res{$num}->{'note'} = $note;
$res{$num}->{'date'} = $date;
}
}
%data = $this->get_all();
}
foreach $num (sort { $a <=> $b } keys %data) {
$note = ude($data{$num}->{'note'});
$date = ude($data{$num}->{'date'});
$_ = $note;
eval $regex;
if($match) {
$res{$num}->{'note'} = $note;
$res{$num}->{'date'} = $date;
}
$match = 0;
}
return %res;
}
@@ -177,24 +177,28 @@ sub get_search
sub set_edit
{
my($this, $num, $note, $date) = @_;
$this->lock;
my $statement = $DB->prepare($sql_edit) || die $DB->errstr();
$note =~ s/'/\'/g;
$note =~ s/\\/\\\\/g;
$statement->execute(uen($note), uen($date), $num) || die $DB->errstr();
$this->unlock;
$this->changed;
}
sub set_new
{
my($this, $num, $note, $date) = @_;
$this->lock;
my $statement = $DB->prepare($sql_insertnew) || die $DB->errstr();
$note =~ s/'/\'/g;
$note =~ s/\\/\\\\/g;
$note =~ s/\\/\\\\/g;
$statement->execute($num, uen($note), uen($date)) || die $DB->errstr();
$this->unlock;
$this->changed;
}
@@ -202,7 +206,8 @@ sub set_del
{
my($this, $num) = @_;
my($note, $date, $T);
$this->lock;
($note, $date) = $this->get_single($num);
return "ERROR" if ($date !~ /^\d/);
@@ -210,6 +215,8 @@ sub set_del
# delete record!
my $statement = $DB->prepare($sql_del) || die $DB->errstr();
$statement->execute($num) || die $DB->errstr();
$this->unlock;
$this->changed;
return;
}
@@ -217,14 +224,19 @@ sub set_del
sub set_del_all
{
my($this) = @_;
$this->lock;
my $statement = $DB->prepare($sql_del_all) || die $DB->errstr();
$statement->execute() || die $DB->errstr();
$this->unlock;
$this->changed;
return;
}
sub set_recountnums
{
sub set_recountnums {
my $this = shift;
$this->lock;
my(@count, $i, $num, $setnum, $pos);
$setnum = 1;
$pos=0; $i=0; @count = ();
@@ -237,13 +249,14 @@ sub set_recountnums
$count[$i] = $num;
$i++;
}
# now recount them!
my $sub_statement = $DB->prepare($sql_setnum) || die $DB->errstr();
for($pos=0;$pos<$i;$pos++) {
$setnum = $pos +1;
$sub_statement->execute($setnum,$count[$pos]) || die $DB->errstr();
}
$this->unlock;
$this->changed;
}
sub uen
@@ -287,7 +300,7 @@ NOTEDB::mysql - module lib for accessing a notedb from perl
# include the module
use NOTEDB;
# create a new NOTEDB object (the last 4 params are db table/field names)
$db = new NOTEDB("mysql","note","localhost","username","password","note","number","note","date");