Hi,

it looks like you are reading from an LDIF file.

perl-ldap currently has the issue that it can only read correctly LDIF files
that have the correct line ending for the operating system the script is 
running on (i.e. CR+LF on Win, LF only on Unix).

To check whether this is the cause of the problem, please convert your LDIF 
file to Unix file end convention and try to re-run your cript against this 
modified LDIF file.

If the script works with this modified input file you may want to 
apply the attached patch against the LDIF.pm version 0.16 and 
retry the script again with the original input file.

Note: this patch is not extensively tested, so you better keep a backup copy 
of your LDIDF.pm file ;-)

Please report feedback about success / failure.

Yours
Peter

On Friday 29 July 2005 10:49, Lionel HELOU wrote:
> Hi everybody,
>
> I have a problem with this script, it works perfectly on windows XP but it
> blocks on Linux Red Hat 7.3 (2.4.20-28.8smp).
> It seems to be on the "read_entry()" function.
>
> Do you have an idea ?
>
>
> #!/usr/bin/perl -w
>
> use Net::LDAP::LDIF;
>
> open(RES, "+>/home/lhelou/scripts/test.log") or die "Impossible d'ouvrir
> le fichier test.log $! ..!! \n";
>
> $ldif = Net::LDAP::LDIF->new( "/home/lhelou/scripts/index.ldif", "r",
> encode =>"base64", onerror => 'undef' );
>
> while( not $ldif->eof ( ) ) {
>   $entry = $ldif->read_entry ( );
>   if ( $ldif->error ( ) ) {
>      print "Error msg: ", $ldif->error ( ), "\n";
>      print "Error lines:\n", $ldif->error_lines ( ), "\n";
>   } else {
>      print "$entry\n";
>   }
> }
> $ldif->done ( );
> close(RES);
>
>
> Thanks in advance.
>
> Lionel

-- 
Peter Marschall
eMail: [EMAIL PROTECTED]
--- LDIF.pm
+++ 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);

Reply via email to