Hi Peter,

The patch ran fine this time.


However, if I test with the attached simple test program and test data, I get the following output:

Person1,+1 098 7654321
Person2,+1 123 4567890
Can't call method "exists" on an undefined value at demo.pl line 25, <GEN0> line 25.


With the unpatched LDIF.pm I didn't get the "can't call method ..." error.


Also, recently there was a patch posted to this list to fix the "lowercase" arg to Net::LDAP::LDIF->new and it looks like your patch either doesn't include or rebreaks that fix.


Cheers,

David




Peter Marschall wrote:

Hi,

On Wednesday 27 July 2005 19:12, David Wood wrote:
I'm no patch expert, so the problem might be with me, but I tried to
apply your patch below with:

cat ldif.patch | patch -b LDIF.pm

and got:

patching file LDIF.pm
Hunk #1 FAILED at 79.
1 out of 1 hunk FAILED -- saving rejects to file LDIF.pm.rej

Sorry, my fault.

Here is the correctd version of the patch.

The LDIF.pm getting patched shows:

$VERSION = "0.16";
This is the correct version the patch should be applied against.

Greetings
Peter

------------------------------------------------------------------------

--- lib/Net/LDAP/LDIF.pm
+++ lib/Net/LDAP/LDIF.pm        2005-06-27 13:50:29.000000000 +0200
@@ -9,7 +9,7 @@
require Net::LDAP::Entry;
use vars qw($VERSION);

-$VERSION = "0.16";
+$VERSION = "0.16_01";

my %mode = qw(w > r < a >>);

@@ -79,35 +79,41 @@
sub _read_lines {
  my $self = shift;
-  my @ldif;
-
-  {
-    local $/ = "";
    my $fh = $self->{'fh'};
+  my @ldif = ();
+  my $entry = '';
+  my $in_comment = 0;
    my $ln;
-    do {       # allow comments separated by blank lines
-      $ln = $self->{_next_lines} || scalar <$fh>;
-      unless ($ln) {
-         $self->{_next_lines} = '';
-         $self->{_current_lines} = '';
-         $self->eof(1);
-         return;
-      }
-      $ln =~ s/\n //sg;
-      $ln =~ s/^#.*\n//mg;
-      chomp($ln);
-      $self->{_current_lines} = $ln;
-    } until ($self->{_current_lines} || $self->eof());
-    chomp(@ldif = split(/^/, $ln));
-    do {
-      $ln = scalar <$fh> || '';
-      $self->eof(1) unless $ln;
-      $ln =~ s/\n //sg;
-      $ln =~ s/^#.*\n//mg;
-      chomp($ln);
-      $self->{_next_lines} = $ln;
-    } until ($self->{_next_lines} || $self->eof());
+
+  return @ldif  if ($self->eof());
+ + while (defined($ln = scalar <$fh>)) {
+    if ($ln =~ /^#/o) {                # ignore 1st line of comments
+      $in_comment = 1;
+    }
+    else {
+      if ($ln =~ /^[ \t]/o) {  # append wrapped line (if not in a comment)
+        $entry .= $ln  if (!$in_comment);
+      }
+      else {
+        $in_comment = 0;
+        if ($ln =~ /^\r?\n$/o) {
+          # ignore empty line on start of entry
+          # empty line at non-empty entry indicate entry completion
+          last  if (length($entry));
+       }
+        else {
+          # append non-empty line
+          $entry .= $ln;
+        }      
+      }
+    }
  }
+  $self->eof(1)  if (!defined($ln));
+  $entry =~ s/\r?\n //sgo;     # un-wrap wrapped lines
+  $entry =~ s/\r?\n\t/ /sgo;   # OpenLDAP extension !!!
+  @ldif = split(/^/, $entry);
+  map { s/\r?\n$//; } @ldif;

  @ldif;
}
@@ -177,7 +183,7 @@

  my $dn = shift @ldif;

-  if (length($1)) {
+  if (length($1)) {    # $1 is the optional colon from above
    eval { require MIME::Base64 };
    if ($@) {
      $self->_error($@, @ldif);
use strict;
use warnings;
use Net::LDAP::Entry;
use Net::LDAP::LDIF;

my $LDIF_INPUT_FILE = "./ldif_test_dump.ldif";

my $ldif = Net::LDAP::LDIF->new($LDIF_INPUT_FILE, "r");

my $entry = undef;
my $cn = "";
my $phone_number = "";
while (!($ldif->eof())) {

    $entry = $ldif->read_entry();

    if ($ldif->error()) {

        print("Error msg: " . $ldif->error() . "\n");
        print("Error lines:\n" . $ldif->error_lines() . "\n");

    }
    else {

        $cn = $entry->get_value("cn") if ($entry->exists("cn"));

        if ($entry->exists("homePhone")) {
            $phone_number = $entry->get_value("homePhone");

            print($cn . "," . $phone_number . "\n");
        }

    }

}

$ldif->done();
dn: cn=Person1,mail=whatever
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
objectclass: mozillaAbPersonObsolete
givenName: Person1
cn: Person1
mail: whatever
modifytimestamp: 0Z
homePhone: +1 098 7654321

dn: cn=Person2,mail=whatever
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
objectclass: mozillaAbPersonObsolete
givenName: Person2
sn: Person2
cn: Person2
mail: whatever
modifytimestamp: 0Z
homePhone: +1 123 4567890

Reply via email to